Vipul J
Vipul J

Reputation: 6691

Where instance variables(primitives) are stored in java? Is anyhow stack related to instance variables storage?

Where instance variables(primitives) are stored in java?

Upvotes: 4

Views: 4692

Answers (3)

David R Tribble
David R Tribble

Reputation: 12214

Primitive variables are stored in the same places all variables are stored (including references):

  • Within objects created (allocated) on the heap, or
  • Within method stack frames as local variables, or
  • Within static areas of their containing class (which are on the heap).

Upvotes: 8

rajan singhal
rajan singhal

Reputation: 43

After class loader loads classes with qualified name into the jvm . JVM parse the binary data from the class and place that info into the Method area. When JVM executes the class it first place the Objects (including instance fields primitive/non primitive) into the heap.

Upvotes: 0

cdhowie
cdhowie

Reputation: 169478

If you mean instance fields declared on a class, they are allocated on the heap as part of the object's own allocation.

Primitive (value type) variables declared as method locals are stored in the method's stack frame.

Upvotes: 2

Related Questions