Skip to content
C

JVM Interview Questions

The main areas include the Stack (for method calls and local variables), the Heap (for objects), and the Method Area (for class-level data like static fields and method code).


Q1. What are the main memory areas managed by the JVM? The main areas include the Stack (for method calls and local variables), the Heap (for objects), and the Method Area (for class-level data like static fields and method code).

Q2. What is the difference between Stack and Heap memory? Stack memory stores method calls and local variables, and is separate for each thread. Heap memory stores actual objects, and is shared across all threads in the program.

Q3. What causes a `StackOverflowError`? It usually happens due to excessive or infinite recursive method calls, which keep adding new stack frames until the Stack's limited memory is exhausted.

Q4. What is Garbage Collection, and can a programmer force it to run? Garbage Collection automatically removes objects from the Heap that are no longer referenced by the program. A programmer can only request it using System.gc(), but the JVM decides whether and when it actually runs — it cannot be forced directly.

Q5. What is Class Loading? It's the process by which the JVM locates and loads a compiled .class file into memory, done lazily — only when a class is actually first referenced in the running program.

Key Points to Remember

  • JVM questions test whether you understand what actually happens "under the hood" when a Java program runs.
  • Be ready to explain the journey from source code to execution: Compilation → Bytecode → Class Loading → Execution.
  • Understanding Stack vs Heap clearly is one of the most frequently tested JVM concepts.