Static references only require that the class be loaded, not that an instance of the class be created. When a class is loaded the static variables are set up in the ClassFile area and the methods are loaded into the "Method Area" which is a secured area that you and I can not mess with.
This allows the use of such things as "Math.PI" and "double sqrt = Math.sqrt(someNumber);" without creating any little Maths to do the job.
The location of various items is all described in the
JVM Specification. Mostly in
3.5 Runtime Data Areas. There is some leniancy given to how a specific vendor may choose to implement the specifications of a JVM.
Although the method area is logically part of the garbage-collected heap, simple implementations may choose to neither garbage collect nor compact it.
Also you can see the actual format of a Class File.
4.1 ClassFile
A class file contains a single ClassFile structure:
ClassFile {
u4 magic;
u2 minor_version;
u2 major_version;
u2 constant_pool_count;
cp_info constant_pool[constant_pool_count-1];
u2 access_flags;
u2 this_class;
u2 super_class;
u2 interfaces_count;
u2 interfaces[interfaces_count];
u2 fields_count;
field_info fields[fields_count]; // These are the static fields
u2 methods_count;
method_info methods[methods_count];
u2 attributes_count;
attribute_info attributes[attributes_count];
}
Of course the instance field values are kept with the object which is stored on the garbage collectable heap.
[This message has been edited by Cindy Glass (edited October 28, 2001).]