a quick google search on "computer memory heap vs stack" returns many good answers to that very question.
Never ascribe to malice that which can be adequately explained by stupidity.
Anto Telvin
Ranch Hand
Joined: Aug 12, 2008
Posts: 113
posted
0
Stack in java is used to store methods and local variables or stack variable,Automatic variable. It is useful in threading and exception handling. It is LIFO Last In First Out . Elements in the stack depends on each other ie for example void chain() { int a; check(); } here while running program first chain() method will get invoke .after that check() will be called..now check() will be in the top of stack memory.after the execution of check() only chain() will get finish (that is why LIFO) its execution.(If you are a beginner then my humble request to read Head First Java)
On the other hand Heap is mainly used to store Objects.whatever objects you are creating that thing is stored in Heap only.All instance variables are stored in heap only.
hope this will help you
Anto Telvin Mathew<br />Many of the life failures are people who did not realize how close they were to success when they give up. EDISON