Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / April 2007

Tip: Looking for answers? Try searching our database.

Any sense in using private static final for non-static classes?

Thread view: 
Ricardo Palomares Martinez - 28 Apr 2007 22:05 GMT
Hi,

I'm trying to find out possible memory leaks in a program. While they
are not exactly the cause, I've found myself in front of some code
like this:

public class NonStaticClass {
   private static final String CONSTANT1 = "glossary_version";
   private static final String CONSTANT2 = "5.1";

The class is not used in a static way, and usually there is none or
one instances of it (it is used just while saving data of the
program). I'm thinking that those "constants", of which there are a
lot of them, shouldn't be static, as they are wasting space most part
of the program execution. Am I right?

TIA

Signature

If it's true that we are here to help others,
then what exactly are the OTHERS here for?

Arne Vajhøj - 28 Apr 2007 22:52 GMT
> I'm trying to find out possible memory leaks in a program. While they
> are not exactly the cause, I've found myself in front of some code
[quoted text clipped - 9 lines]
> lot of them, shouldn't be static, as they are wasting space most part
> of the program execution. Am I right?

It is very common to use static final for constants.

If we are talking JSE and not JME then I would assume the
memory used by constants is insignificant.

Arne
david.karr - 28 Apr 2007 23:45 GMT
On Apr 28, 2:05 pm, Ricardo Palomares Martinez <rpm.PU...@iespana.es>
wrote:
> Hi,
>
[quoted text clipped - 11 lines]
> lot of them, shouldn't be static, as they are wasting space most part
> of the program execution. Am I right?

You've gotten way off track if your goal is to investigate memory
leaks.  the space used by statics like this will be insignificant. If
you want to make them use MORE space, then make them non-static (I'm
not suggesting you do this). Defining private constants is a perfectly
reasonably thing to do.


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.