JVM, Memory & Garbage Collection Interview Questions
Heap vs stack, GC algorithms, class loaders, Metaspace, and JVM tuning basics.
- 20Questions with answers
- 3Difficulty levels
Questions (20)
Browse beginner, intermediate, and advanced questions with answers — hide them when you want to self-test.
What is JVM architecture?
JVM architecture consists of ClassLoader, Runtime Data Areas, Execution Engine, Garbage Collector, and Native Method Interface.
What are JVM memory areas?
JVM memory areas include Heap, Stack, Method Area, Program Counter Register, and Native Method Stack.
What is Heap memory?
Heap memory stores objects and instance variables and is managed by the Garbage Collector.
What is Stack memory?
Stack memory stores method calls, local variables, and references specific to each thread.
What is the difference between Heap and Stack?
Heap stores objects and is shared among threads, while Stack stores method-specific data and is private to each thread.
What is Garbage Collection?
Garbage Collection is the automatic process of reclaiming memory occupied by unreachable objects.
How does the Garbage Collector work?
The Garbage Collector identifies unreachable objects and frees their memory automatically.
What are common GC algorithms?
Common GC algorithms include Serial GC, Parallel GC, CMS, G1 GC, ZGC, and Shenandoah GC.
What is OutOfMemoryError?
OutOfMemoryError occurs when the JVM cannot allocate sufficient memory for new objects.
What is a Memory Leak in Java?
A memory leak occurs when objects are no longer needed but remain referenced, preventing garbage collection.
What is Metaspace?
Metaspace is the memory area that stores class metadata and replaced PermGen starting from Java 8.
What is a ClassLoader?
A ClassLoader loads Java classes into memory dynamically during runtime.
What are the types of ClassLoaders?
Bootstrap ClassLoader, Platform ClassLoader, and Application ClassLoader are the primary ClassLoaders in Java.
What is the JIT Compiler?
The Just-In-Time Compiler converts frequently executed bytecode into native machine code to improve performance.
What are JVM tuning parameters?
JVM tuning parameters include heap size settings, garbage collection configurations, thread stack size, and metaspace limits to optimize performance.
Which Java language or JDK features are essential when discussing JVM, Memory & Garbage Collection?
Name concrete APIs (collections, concurrency, streams, annotations) tied to JVM, Memory & Garbage Collection. Interviewers want syntax-level clarity plus when you would reach for each feature in production.
How does exception handling typically work around JVM, Memory & Garbage Collection in Java?
Prefer specific checked/unchecked exceptions, wrap lower-level failures with context, and avoid empty catch blocks. For JVM, Memory & Garbage Collection, decide what is recoverable vs fatal to the request thread.
What unit-testing approach would you use for JVM, Memory & Garbage Collection?
JUnit 5 with Arrange-Act-Assert, Mockito for collaborators, and parameterized tests for edge cases. Keep JVM, Memory & Garbage Collection logic pure where possible so tests stay fast.
How do equals/hashCode or identity rules affect JVM, Memory & Garbage Collection?
Incorrect equals/hashCode break HashMap/HashSet behavior. If JVM, Memory & Garbage Collection stores objects in collections, explain the contract and mutability pitfalls.
What memory or GC concern should juniors watch with JVM, Memory & Garbage Collection?
Retain only needed references, prefer streaming for large datasets, and avoid accidental caches. Relate leaks or GC pressure to a concrete JVM, Memory & Garbage Collection scenario.
Practice with AI mock interviews
Run Java mock interviews with AI follow-ups, instant feedback, and analytics on AiLx.
Free to start · No credit card required