Where are static variables stored? Is there any separate memory for the static variables? I know that they are not a part of the object, are they also not part of the Java heap and store d somewhere?
If so isn't it unsecure?
Static members are part of the class object that instantiated the object. The class object is an object, too - and it resides in the heap. Remember: all classes are instances of the Class
class!
They are stored in the PermGem
part of the JVM.
static Object var= new Object();
var
is in the PermGen
, and the Object instance is in the Heap
.
EDIT:
The permanent generation (or PermGen
) is used for class definitions and associated metadata. Permanent generation is not part of the heap.