This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes Where do Variables live? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Where do Variables live?" Watch "Where do Variables live?" New topic
Author

Where do Variables live?

Jose Campana
Ranch Hand

Joined: May 28, 2007
Posts: 339
Greetings Java Ranchers,

Excuse my ignorance, Could someone please tell me where do Primitive variables live? I understand java puts the binary representation of the value inside a variable, but I want to know where exactly does this variable reside?

Is it on the heap? like the objects do?

and....reference variables live in the same place as primitives, right?

Thank you very much in advance. Hopefully you won't laugh at my question.
-Jose
Kaydell Leavitt
Ranch Hand

Joined: Nov 18, 2006
Posts: 688

Local variables live on the stack. There is a separate stack for each thread.

If a primitive is a local variable, it will be on the stack.

If a primitive is a field of an object, it will be in the heap.

-- Kaydell
Jose Campana
Ranch Hand

Joined: May 28, 2007
Posts: 339
Thanks,
I didn't remember those rules, you have refreshed my mind !

Thank you very much.
 
 
subject: Where do Variables live?
 
Similar Threads
residence of static variable
where do static variables live ?
Reference Variables
Australian Legends
Stack/Heap: the Memory Allocation of Local Variables