hi,
1. I got (say 100) java class files.
2. In each there are 1000 "final static String" are defined.
3. Only one\few variable from each of these classes is referred in the
main class.
4. Classloader loads all these class files into memory, because there
is reference in main.
Just because I refer to one variable the whole class file is being
loaded.
Comments about memory usage?
rgds
-Sri
Roedy Green - 22 Sep 2005 11:47 GMT
On 22 Sep 2005 03:10:45 -0700, sriram_kosuri@yahoo.com wrote or quoted
>Just because I refer to one variable the whole class file is being
>loaded.
the static variables will be, but the methods are not necessarily
hooked up or jitted until they are used.
I think though they will be interned, so that if you have the same
string in many classes, there will be only one copy of the string.

Signature
Canadian Mind Products, Roedy Green.
http://mindprod.com Again taking new Java programming contracts.
Thomas Hawtin - 22 Sep 2005 19:23 GMT
> 1. I got (say 100) java class files.
> 2. In each there are 1000 "final static String" are defined.
[quoted text clipped - 7 lines]
>
> Comments about memory usage?
If you make the static final Strings initialisers compile time
expressions (for instance just a literal String), then the value should
be placed into the referring class at compile time.
But I'd be tempted to change the design.
Tom Hawtin

Signature
Unemployed English Java programmer
http://jroller.com/page/tackline/