what is the difference between heap and stack in java?
Difference between Java Heap Space and Stack Memory Heap memory is used by all the parts of the application whereas stack memory is used only by one thread of execution. Whenever an object is created, it's always stored in the Heap space and stack memory contains the reference to it.