0

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?

asked Oct 19, 2010 at 4:11
1
  • 1
    is what you've said related with memory management? Plus, please clarify on your term "variable variable" and "temporary variable". In my opinion, there is only "local/stack variable" that is inside a method, which lifespan is from the start to the finish of the method. Commented Oct 19, 2010 at 4:21

1 Answer 1

6

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.

answered Oct 19, 2010 at 4:27
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.