Thursday, 24 March 2016

Difference between Stack and Heap memory in Java

The difference between stack and heap memory is common programming question asked by beginners learning Java or any other programming language. Stack and heap memory are two terms programmers starts hearing once they started programming but without any clear and definite explanation. Lack of knowledge of what is a heap in Java and what is stack memory in Java results in misconceptions related to stack and heap. To add to this confusion, a stack is also a data structure which is used to store elements in LIFO(Last In First out) order and available in Java API as java.util.Stack. In general, both stack and heap are part of memory, a program is allocated and used for different purposes. Java program runs on JVM which is launched as a process by "java" command. Java also uses both stack and heap memory for different needs. In our last article 10 points on Java heap space, I have touched base on Java heap space and in this article we will see the difference between stack and heap memory in Java.
Read more »

No comments:

Post a Comment