Back to Study Material Java

JDK JRE and JVM

Three acronyms appear constantly in Java documentation and interviews: JDK, JRE, and JVM. These are not interchangeable terms; each refers to a distinct la...

JDK JRE and JVM

Understanding the Three Layers of the Java Runtime

Three acronyms appear constantly in Java documentation and interviews: JDK, JRE, and JVM. These are not interchangeable terms; each refers to a distinct layer of the Java platform with different responsibilities. Grasping their relationship is essential for understanding how Java code goes from source text to running process.

The Java Virtual Machine (JVM) is the innermost and most fundamental layer. It is an abstract computing machine that defines an instruction set (called bytecodes) and a memory model. The JVM takes .class files containing bytecode and executes them. The JVM handles memory allocation, garbage collection, thread management, and security enforcement. Different vendors provide different JVM implementations (HotSpot, OpenJ9, GraalVM), but all of them conform to the JVM specification and can execute the same bytecode.

The Java Runtime Environment (JRE) bundles the JVM together with the Java Class Library — the standard set of packages like java.lang, java.util, java.io, and many others. The JRE provides everything needed to run a compiled Java application but does not include development tools. End users who only need to run Java programs, not write them, historically installed only the JRE. Since Java 9 and the introduction of the module system, standalone JRE distributions are less common, as custom runtimes can be assembled with only the modules an application needs.

The Java Development Kit (JDK) is the outermost layer and a superset of the JRE. It includes the JRE plus development tools: the compiler (javac), the documentation generator (javadoc), the archiver (jar), the debugger (jdb), and many other utilities. Anyone writing Java programs needs the JDK installed, not just the JRE.

To summarize the containment relationship: JDK contains JRE, and JRE contains JVM. You can think of them as nested boxes. The JDK is the complete toolbox for building Java software, while the JVM is the engine that runs it.

A concrete example: when you run javac HelloWorld.java, you are using a JDK tool. When you run java HelloWorld, you are invoking the JVM inside the JRE to execute the compiled bytecode.

Interview tip: The most common question on this topic is "what is the difference between JDK and JRE?" Answer that JDK is for developers and includes the compiler, while JRE is for running applications and includes only the runtime and standard library. Then mention that the JVM is the component within the JRE that actually executes bytecode.