Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

how primitives and objects are laid in memory?

 
Dez Max
Ranch Hand
Posts: 41
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Folks,
I want to know how java objects and primitives objects are laid out in memory. How static variables and objects are stored. For ex
int a = 12;
how memory allocation happens for variable a.
Thanks in advance.
Fred
 
David O'Meara
Rancher
Posts: 13459
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
"Fred",
The Java Ranch has thousands of visitors every week, many with surprisingly similar names. To avoid confusion we have a naming convention, described at http://www.javaranch.com/name.jsp.
We require names to have at least two words, separated by a space, and strongly recommend that you use your full real name. Please edit your profile and select a new name which meets the requirements.
Please be sure to change your display name soon. Accounts with invalid names get deleted.
Thanks.
Dave
 
Cindy Glass
"The Hood"
Sheriff
Posts: 8521
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Objects are stored on the heap. Static variables are stored with the Classfile. Variable references are stored in the stack related to the Frame. There is a frame for each method invoked. So local variables find themselves on the stack for the method that they are local to.
The example that you gave shows the integer as a constant value. That value would be stored in the Constant Pool, with all the other constants and literals and Strings.
You may enjoy reading the Java Virtual Machine Specifications for details on how such things work. .
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic