Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Where do Variables live?

 
Jose Campana
Ranch Hand
Posts: 339
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 689
Eclipse IDE Firefox Browser Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 339
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks,
I didn't remember those rules, you have refreshed my mind !

Thank you very much.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic