Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Agile forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Where are these java ...... etc stored

 
Mohan Ramanna
Ranch Hand
Posts: 36
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have read that java objects are stored on the Heap in
the memory can i get a list of reference where
java objects, variables,static,final variables etc, primitive
objects are stored.
A detailed explanation of the above is expected?
Thanks in advance
- MOhan
 
Viswanathan Nachiappan
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Method primitive variables are stored in the Stack.

Static Objects will be stored in the Heap, but where will there reference be stored?

Also Can any one tell where the Static primitive variables are stored???

Thanks in Advance,
viswa
 
vidya sagar
Ranch Hand
Posts: 580
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Viswanathan Nachiappan:
Also Can any one tell where the Static primitive variables are stored???


Its also in heap
 
Douglas Chorpita
Ranch Hand
Posts: 97
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Local variables (primitives and references) are stored on the stack. The stack is a data structure that allows for recursion (when a method calls itself). Local variables need to be created for each level of invokation. So a stack is used.

Pretty much everything else is stored on the heap, which allocates memory for objects and arrays (which are objects).

There is also a String literal pool, which stores String objects (which contain references and integers). The string's char[] array is actually also stored on the heap.

In C++, you can put objects on the stack, which generally results in better performance. This can be dangerous though, as too many objects on the stack can lead to stack overflow, which is fatal. A stack overflow in Java is also possible, if a method calls itself over and over again without stopping.
[ July 27, 2006: Message edited by: Douglas Chorpita ]
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic