Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > Any sense in using private static final for non-static classes?

Reply
Thread Tools

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

 
 
Ricardo Palomares Martinez
Guest
Posts: n/a
 
      04-28-2007
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

--
If it's true that we are here to help others,
then what exactly are the OTHERS here for?
 
Reply With Quote
 
 
 
 
=?ISO-8859-15?Q?Arne_Vajh=F8j?=
Guest
Posts: n/a
 
      04-28-2007
Ricardo Palomares Martinez wrote:
> 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?


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
 
Reply With Quote
 
 
 
 
david.karr
Guest
Posts: n/a
 
      04-28-2007
On Apr 28, 2:05 pm, Ricardo Palomares Martinez <rpm.PU...@iespana.es>
wrote:
> 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?


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.

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Is there any sense in using final keyword in catch block? Royan Java 11 10-25-2008 10:02 PM
501 PIX "deny any any" "allow any any" Any Anybody? Networking Student Cisco 4 11-16-2006 10:40 PM
Difference between static final members and final static members(if any)? JFCM Java 4 02-07-2006 11:32 AM
Does pervasive use of final make sense? Timo Nentwig Java 31 05-13-2004 09:33 PM
private static final fields not removed after compilation??? Henri Java 5 07-22-2003 02:52 AM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57