Autocoder

JVM Internals Interview Questions

Last updated 2026-11-19

JVM internals questions probe whether you know what happens between javac and a running program: how classes are found and initialised, where memory lives, how bytecode becomes machine code and why a Java program is slow for its first few seconds. They are common for experienced roles and for performance-focused teams.

The answers refer to the HotSpot JVM in Java 17 and later. Memory reclamation is covered in detail on the garbage collection page.

JVM coveredHotSpot (OpenJDK)
Java version17 and later
Main areasClass loading, memory, execution engine, tools

Big picture

The JVM has three parts that interviewers name: the class loader subsystem, which finds and prepares classes; the runtime data areas, which hold heap, stacks and metadata; and the execution engine, which interprets bytecode, compiles hot methods with the JIT and runs the garbage collector.

JVM Internals Interview Questions: questions with worked answers

  1. 1

    Describe the JVM architecture.

    easy

    The class loader subsystem loads, links and initialises classes. Runtime data areas include the heap and metaspace (shared across threads) and, per thread, a stack, a program counter register and a native method stack. The execution engine contains the bytecode interpreter, the JIT compilers (C1 and C2) and the garbage collector, and calls native code through JNI.

  2. 2

    Explain the class loading phases and the parent delegation model.

    medium

    Loading reads the class file and creates a Class object. Linking has three steps: verification checks the bytecode is well formed and safe, preparation allocates static fields with default values, and resolution turns symbolic references into direct ones. Initialisation then runs static initialisers and assigns real static values. Loaders delegate upward first: a request goes to the application loader, which asks the platform loader, which asks the bootstrap loader, and only if none can find the class does the requester load it. That prevents user code from replacing java.lang.String.

  3. 3

    What are the built-in class loaders?

    medium

    The bootstrap loader, written in native code, loads core modules such as java.base. The platform loader (formerly the extension loader) loads other Java SE and JDK modules. The application (system) loader loads classes from the class path and module path. Frameworks such as Tomcat and OSGi add their own loaders for isolation, which is also where classloader leaks come from.

  4. 4

    Predict the output: when is a class initialised?

    hard

    Initialisation is triggered by new, a static method call, or access to a non-constant static field. Reading a static final field that is a compile-time constant does not trigger it, because the value is inlined into the caller at compile time.

    java
    class K {
        static final int A = 5;                         // compile-time constant
        static final int B = Integer.parseInt("6");     // computed at runtime
        static { System.out.println("K init"); }
    }
    public class Main {
        public static void main(String[] args) {
            System.out.println(K.A);   // 5, K is NOT initialised
            System.out.println(K.B);   // K init, then 6
        }
    }
  5. 5

    ClassNotFoundException versus NoClassDefFoundError.

    medium

    ClassNotFoundException is a checked exception thrown when code explicitly loads a class by name (Class.forName, a loader) and it is not found. NoClassDefFoundError is an Error thrown when a class that was present at compile time cannot be found at runtime, or when its static initialisation failed earlier. The first is a lookup failure you can catch and handle; the second usually indicates a classpath or packaging problem.

  6. 6

    What are the runtime data areas?

    easy

    The heap holds objects and arrays and is shared. Metaspace holds class metadata in native memory and replaced PermGen in Java 8. Each thread has a stack of frames (local variables, operand stack, frame data), a program counter and a native method stack. The code cache holds JIT-compiled machine code, and the string pool lives in the heap since Java 7.

  7. 7

    What is in a stack frame and what causes StackOverflowError?

    medium

    A frame holds the local variable array (including parameters and this), an operand stack for intermediate values, and data for constant pool access and returns. Each method call pushes a frame; returning pops it. StackOverflowError occurs when the stack depth exceeds the thread stack size (default about 1 MB on 64-bit Linux, set with -Xss), typically from unbounded recursion.

  8. 8

    How does the JIT compiler work, and what is tiered compilation?

    medium

    The JVM starts by interpreting bytecode, counts method invocations and loop back-edges and compiles hot code. Tiered compilation uses C1, a fast compiler with light optimisation and profiling, then C2, a slower compiler that applies aggressive optimisations such as inlining, escape analysis and loop unrolling based on the collected profile. If an assumption proves wrong, for example a class is loaded that breaks a monomorphic call site, the JVM deoptimises back to the interpreter. This is why benchmarks need warm-up.

  9. 9

    Why is a naive Java microbenchmark misleading?

    hard

    The first iterations run interpreted, dead code may be eliminated, constants folded and loops removed entirely, and GC or JIT threads add noise. Without warm-up and a sink for the results, you measure the wrong thing. Use JMH, which handles warm-up, forks, Blackhole consumption and statistical reporting.

  10. 10

    What does javap show and what are the main invocation bytecodes?

    medium

    javap -c disassembles class files into bytecode. invokevirtual calls an instance method with virtual dispatch, invokeinterface calls through an interface, invokespecial handles constructors, super and private calls, invokestatic calls static methods and invokedynamic is bound at first use through a bootstrap method, which lambdas and string concatenation use.

    java
    // javac Hello.java && javap -c Hello
    //   0: getstatic     System.out
    //   3: ldc           "hi"
    //   5: invokevirtual PrintStream.println
    //   8: return
  11. 11

    What does an object look like in memory?

    medium

    A HotSpot object has a header and then its fields. The header holds a mark word (identity hash, GC age, lock state) and a class pointer, 12 bytes with compressed class pointers on 64-bit, padded to 8-byte alignment. Compressed ordinary object pointers store references in 32 bits and work for heaps up to roughly 32 GB, which is why a 31 GB heap can hold more objects than a 33 GB one.

  12. 12

    What is metaspace and how does it differ from PermGen?

    medium

    PermGen was a fixed-size region inside the Java heap that held class metadata and interned strings, and it caused java.lang.OutOfMemoryError: PermGen space. Since Java 8 class metadata sits in metaspace, allocated from native memory and growing by default until the OS or -XX:MaxMetaspaceSize stops it. Interned strings moved to the heap. A metaspace OutOfMemoryError usually means classloader leaks from repeated deployments or heavy dynamic class generation.

  13. 13

    What is the Java Memory Model and how does the JVM enforce it?

    medium

    The JMM defines which writes a thread may see from another and in what order, through happens-before rules. The JVM implements them by inserting memory barriers for volatile accesses, monitor enter and exit and final field publication, and by limiting the reorderings the JIT and CPU may do. Details are on the multithreading page.

  14. 14

    Which command-line tools help diagnose a running JVM?

    medium

    jps lists JVM processes. jstack or jcmd Thread.print dumps thread stacks and reports deadlocks. jcmd GC.heap_dump or jmap -dump writes a heap dump for Eclipse MAT. jstat shows GC statistics, jcmd VM.flags shows active flags, and Java Flight Recorder (jcmd JFR.start) records low-overhead events for profiling in JDK Mission Control.

  15. 15

    What are CDS, AOT and GraalVM native image?

    hard

    Class Data Sharing maps a pre-parsed archive of classes into memory to speed up start and share memory between JVMs; the JDK ships a default archive and you can create an application one. GraalVM native image compiles an application ahead of time into a standalone executable with very fast startup and low memory, at the cost of closed-world assumptions, limited reflection (needs configuration) and no runtime JIT peak performance.

  16. 16

    What does the Java module system (JPMS) change at runtime?

    medium

    Since Java 9 the JDK is split into modules, and code declares what it exports and requires in module-info.java. Strong encapsulation means internal packages such as sun.misc are not accessible reflectively unless opened, and Java 17 enforces that by default. jlink can build a minimal runtime image containing only the modules an application needs.

Frequently asked questions

Is JVM internals asked to freshers?

Rarely in depth. Freshers may get JDK versus JRE versus JVM and stack versus heap; class loading and the JIT are for experienced candidates.

What is the difference between the JVM and the JDK?

The JVM runs bytecode; the JDK bundles the JVM with the compiler and tools. See Java interview questions.

Where do static variables live?

Their values are stored with the class in the heap, and the class metadata is in metaspace. Static references keep their objects alive as GC roots.

Do all JVMs behave like HotSpot?

No. OpenJ9, GraalVM and others differ in JIT, memory layout and flags. Most interview answers assume HotSpot.

Related guides

More in Programming Language Interview Questions by Language

See all in this section