• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

where variable and objects are stored

 
Ranch Hand
Posts: 97
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hai,
in java where variables,methods and objects are stored.
 
Bartender
Posts: 10336
Hibernate Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Not an advanced question. Moving...
 
Ranch Hand
Posts: 490
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
(instanceof Sidekick)
Posts: 8791
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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?
 
Sheriff
Posts: 11343
Mac Safari Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
See Where storage lives from Eckel's Thinking in Java.
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic