views:

59

answers:

1

Where objects,variable variables,temporary variable are stored in java? How they are referenced? I know that methods are being stored in stack. where variables are stored heap or stack?

+6  A: 

Where objects,variable variables,temporary variable are stored in java?

  1. Objects are stored on the heap. Always.

  2. Object fields / attributes are parts of their respective objects. I assume that's what you mean by "variable variables".

  3. Local variables and method parameters are stored on the stack.

Note: if a field, variable, parameter has an object or array, the corresponding values will be represented in the "slot" for the object field / local variable / parameter by an object reference.

How they are referenced?

Objects are referenced by object references. How these object references are represented is an implementation detail which is JVM specific and opaque to an application program. However, in most cases, they are plain 32-bit or 64-bit machine (virtual) addresses.

Stephen C
+1 for a coherent answer to a total mess of a question
bemace