wood burning stoves 2.0*
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 Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Where do Variables live?" Watch "Where do Variables live?" New topic

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.
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
I didn't remember those rules, you have refreshed my mind !

Thank you very much.
It is sorta covered in the JavaRanch Style Guide.
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