File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

where variable and objects are stored

 
ramchander yshetti
Ranch Hand
Posts: 97
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hai,
in java where variables,methods and objects are stored.
 
Paul Sturrock
Bartender
Posts: 10336
Eclipse IDE Hibernate Java
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Not an advanced question. Moving...
 
Rusty Shackleford
Ranch Hand
Posts: 490
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
objects are stored on the heap

When methods are called they live on the stack.

instance variables are on the heap with its object

local variables(primitive and object references) go on the stack. In the case of an object reference, the object itself of course is on the heap.
 
Stan James
(instanceof Sidekick)
Ranch Hand
Posts: 8791
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The byte-code for the methods, the static variables and the constants in a class only have to be loaded once. So once a class is loaded onto the heap the JVM can use that stuff all day long. There are some conditions under which this stuff is unloaded, but I wouldn't count on it.

When you instantiate an object the JVM allocates the member variables. These go in the heap as well. Objects are created and garbage collected in different orders which can leave holes in the heap. The GC can move things around to close up the holes and make the remaining contiguous chunk bigger.

When you call a method and as the method executes, the JVM allocates the local variables. These go on the stack. Method calls exit in reverse order of how they were called, so the JVM can de-allocate in reverse order. It doesn't get holes in the stack.

Does that make sense?
 
marc weber
Sheriff
Posts: 11343
Java Mac Safari
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
See Where storage lives from Eckel's Thinking in Java.
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic