0

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?

1
  • Why would it be "unsecure"? Commented Jun 13, 2013 at 19:44

2 Answers 2

4

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!

Sign up to request clarification or add additional context in comments.

2 Comments

+1 "class object that instantiated the object.The class object is an object". We don't see this information in general answers.
JVM never instantiates any object by itself. It makes use of the class loaders to detect the main class and call the main and this is why main is declared to be static.
2

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.

2 Comments

Any reference in this respect? Does it appear in the virtual machine specification?
PermGem is out of the heap.