Stack vs Heap and Class Loading
40 min · Advanced
The JVM divides memory into areas with different jobs: each thread has its own stack for method calls and local variables, and all threads share one heap for objects. "Explain stack vs heap" and "How does class loading work?" are standard questions for any Java role. Section 11 (JVM Memory Areas, Class Loading) taught these in depth; this lesson is the interview revision.
Topics in this lesson
- JVM memory areas: stack, heap, metaspace, PC register
- Where locals, objects and static fields live: draw it
- StackOverflowError vs OutOfMemoryError
- Class loaders and the delegation model
- JIT in one line
Interview questions this lesson answers
- What are the main memory areas of the JVM?
- What is stored on the stack?
- What is stored on the heap?
- What is the difference between stack and heap memory?
- Where are static variables stored?
- Where are local variables of reference type stored?
- What is metaspace, and why did it replace PermGen?
- What is the PC register?
- What is a TLAB?
- What causes StackOverflowError?
Sign in free to continue this lesson
Create a free account to read every lesson, practise with the exercises and keep track of your progress.