What is the difference between JDK, JRE and JVM?
Quick Summary: JVM executes compiled Java bytecode on a host OS, JRE bundles the JVM with core runtime libraries to run programs, and JDK is the complete developer kit containing the JRE, javac compiler, debugger, and packaging tools.
Direct Interview Answer
JVM (Java Virtual Machine) is the abstract execution engine that loads .class bytecode files, verifies safety, manages Heap/Stack/Metaspace memory, runs Garbage Collection, and JIT-compiles hot paths into native CPU instructions.
JRE (Java Runtime Environment) packages the JVM together with standard class libraries (java.base, networking, collections) needed to run compiled applications.
JDK (Java Development Kit) is the superset installed on developer workstations and CI runners, adding javac, jar, jconsole, jmap, and javadoc on top of runtime capabilities.
Detailed Technical Explanation
Notice an important modern evolution since Java 11: Oracle and OpenJDK distributions no longer ship a separate standalone JRE download. Instead, engineers distribute the JDK in development and use jlink inside Docker multi-stage builds to assemble a minimal custom runtime image containing only required JPMS modules (java.base, java.sql).
Inside the JVM, memory is cleanly separated: thread-private JVM Stacks store primitive frames and object references, the shared Heap holds object instances across Young/Old generations, and native OS-backed Metaspace stores loaded class metadata.
Practical Walkthrough
When you run javac App.java (JDK tool), it emits platform-neutral bytecode in App.class. Running java App invokes the JVM runtime launcher, which links classes and JIT-compiles frequently executed loops.
public class RuntimeInspectionDemo {
public static void main(String[] args) {
System.out.println("Java Version : " + System.getProperty("java.version"));
System.out.println("JVM Name : " + System.getProperty("java.vm.name"));
System.out.println("Max Heap MB : " + (Runtime.getRuntime().maxMemory() / (1024 * 1024)));
}
}
Java Version : 21.0.4 JVM Name : OpenJDK 64-Bit Server VM Max Heap MB : 2048
Real-World Production Use Case
Production Spring Boot microservices compile in a Docker builder stage using the full JDK, then copy the layered JAR + minimal jlink runtime into a slim distroless container—shrinking container attack surface and RAM overhead.
Common Interview Mistakes to Avoid
- Assuming JVM bytecode itself is machine code — bytecode is interpreted and JIT-compiled by the JVM at runtime.
- Shipping the entire JDK with javac and debuggers inside security-hardened production containers when a minimal JRE runtime suffices.
- Confusing Heap memory (shared objects) with Metaspace (native memory storing class definitions since Java 8).