Originally posted by Mandar LearningJava:
Now can you explain what you mean by stack ?
Every Method in
Java is associated to a "Frame" (not an AWT frame). Each Frame has it's own stack to store variables and partial computations. If scope is passed to a different Frame the original Frame is still there but the new Frame becomes "current". When the method is over, the Frame (and therefore it's stack) is gone and cleaned up by the JVM. (Just to add confusion, it is possible that SOME JVMs may implement stacks on the heap

. But logically you can ignore this.)
From the Java Virtual Machine Specifications:
3.5.2 Java Virtual Machine Stacks Objects are created on the heap. This is an area of memory reserved for such stuff. Of course in each object there are variables that are not related to methods, and are therefore given the special name of fields.
It is important to take care not to confuse the concept of a variable, with the object that it references.
3.5.3 Heap
Just for fun:
Not all Variables are created Equal