What is Stack and Heap Memory in Java | Core java | Memory Management| Most Asked Interview Question

preview_player
Показать описание
basically when you talking about memory management,
there are two types of memory one is stack and another is heap memory.
When you write A = 10 in programming languages
here A is known as Referance variable which is stored in Stack Memory
and 10 is known as Object which is stored in Heap Memory.
so here reference variable 'A' in stack is pointing towards object '10' in heap memory
Stack is used for static memory allocation meaning memory is allocated at compile time before the program executes.
Heap is used for dynamic memory allocation meaning the memory can be allocated and freed in random order.

compare to stack, objects in the heap are much slower to access.
Stack follows the Last in, first out order whereas Heap does not follow any order.
stack stores items that have a very short life such as methods, variables, and reference variables of the objects.
Heaps stores objects and Java Runtime Environment classes.


stack,heap,java,core java, LIFO, Memory managmenet, Stack Overflow, Stack heap, Object
Рекомендации по теме
Комментарии
Автор

primitive types are stored in the stack unless they're static or a class member

mio
Автор

Please make more videos like this on java and full stack developer interview questions

madhuriw
Автор

a = 10. here 10 will be stored in the stack only right? since 10 is not an object

phoenix__