← Back to Java
Java

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.

Question 1
Interview Beginner
Question

What is JVM architecture?

Answer:

JVM architecture consists of ClassLoader, Runtime Data Areas, Execution Engine, Garbage Collector, and Native Method Interface.

Question 2
Interview Beginner
Question

What are JVM memory areas?

Answer:

JVM memory areas include Heap, Stack, Method Area, Program Counter Register, and Native Method Stack.

Question 3
Interview Beginner
Question

What is Heap memory?

Answer:

Heap memory stores objects and instance variables and is managed by the Garbage Collector.

Question 4
Interview Beginner
Question

What is Stack memory?

Answer:

Stack memory stores method calls, local variables, and references specific to each thread.

Question 5
Interview Beginner
Question

What is the difference between Heap and Stack?

Answer:

Heap stores objects and is shared among threads, while Stack stores method-specific data and is private to each thread.

Question 6
Interview Beginner
Question

What is Garbage Collection?

Answer:

Garbage Collection is the automatic process of reclaiming memory occupied by unreachable objects.

Question 7
Interview Beginner
Question

How does the Garbage Collector work?

Answer:

The Garbage Collector identifies unreachable objects and frees their memory automatically.

Question 8
Interview Intermediate
Question

What are common GC algorithms?

Answer:

Common GC algorithms include Serial GC, Parallel GC, CMS, G1 GC, ZGC, and Shenandoah GC.

Question 9
Interview Intermediate
Question

What is OutOfMemoryError?

Answer:

OutOfMemoryError occurs when the JVM cannot allocate sufficient memory for new objects.

Question 10
Interview Intermediate
Question

What is a Memory Leak in Java?

Answer:

A memory leak occurs when objects are no longer needed but remain referenced, preventing garbage collection.

Question 11
Interview Intermediate
Question

What is Metaspace?

Answer:

Metaspace is the memory area that stores class metadata and replaced PermGen starting from Java 8.

Question 12
Interview Intermediate
Question

What is a ClassLoader?

Answer:

A ClassLoader loads Java classes into memory dynamically during runtime.

Question 13
Interview Intermediate
Question

What are the types of ClassLoaders?

Answer:

Bootstrap ClassLoader, Platform ClassLoader, and Application ClassLoader are the primary ClassLoaders in Java.

Question 14
Interview Intermediate
Question

What is the JIT Compiler?

Answer:

The Just-In-Time Compiler converts frequently executed bytecode into native machine code to improve performance.

Question 15
Interview Advanced
Question

What are JVM tuning parameters?

Answer:

JVM tuning parameters include heap size settings, garbage collection configurations, thread stack size, and metaspace limits to optimize performance.

Question 16
Interview Advanced
Question

Which Java language or JDK features are essential when discussing JVM, Memory & Garbage Collection?

Answer:

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.

Question 17
Interview Advanced
Question

How does exception handling typically work around JVM, Memory & Garbage Collection in Java?

Answer:

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.

Question 18
Interview Advanced
Question

What unit-testing approach would you use for JVM, Memory & Garbage Collection?

Answer:

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.

Question 19
Interview Advanced
Question

How do equals/hashCode or identity rules affect JVM, Memory & Garbage Collection?

Answer:

Incorrect equals/hashCode break HashMap/HashSet behavior. If JVM, Memory & Garbage Collection stores objects in collections, explain the contract and mutability pitfalls.

Question 20
Interview Advanced
Question

What memory or GC concern should juniors watch with JVM, Memory & Garbage Collection?

Answer:

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