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
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 ]