in JAVA by
What is the difference between stack and heap in Java?

2 Answers

0 votes
by

Stack and heap are different memory areas in the JVM and they are used for different purposes. The stack is used to hold method frames and local variables while objects are always allocated memory from the heap. The stack is usually much smaller than heap memory and also didn't shared between multiple threads, but heap is shared among all threads in JVM.

0 votes
by
Stack is generally used to store the order of method execution and local variables. In contrast, Heap memory is used to store the objects. After storing, they use dynamic memory allocation and deallocation.

Related questions

+1 vote
asked Jul 27, 2021 in JAVA by SakshiSharma
0 votes
asked Oct 16, 2020 in JAVA by SakshiSharma
+1 vote
asked May 30, 2020 in JAVA by Robindeniel
...