Question: what is the difference between heap and stack java?
Answer: 1) The main difference between heap and stack is that stack memory is used to store local variables and function calls while heap memory is used to store objects in Java. ... StackOverFlowError, while if there is no more heap space for creating an object, JVM will throw java. lang. OutOfMemoryError: Java Heap Space.