Historical Context & Motivation
Before Java arrived on the scene, software developers faced a frustrating problem: a program written for one operating system — say Windows — would not run on macOS or Linux without being completely rewritten. In the early 1990s, a team of engineers at Sun Microsystems set out to solve this portability problem. Their creation, the Java programming language, was built on a radical idea: "Write Once, Run Anywhere." To make this vision a reality, Java needed two separate but related toolkits — one for the people who create programs, and one for the people who simply run them.
This timeline shows how the JDK and JRE evolved as two sides of the same coin. The central question this lesson addresses is: What exactly does each package contain, and why does the distinction matter when you're learning to program in Java?
Core Principles & Definitions
To understand the JDK versus JRE distinction, you need to grasp how Java programs move from source code to running software. Unlike languages like C++, where code compiles directly into machine instructions for a specific processor, Java uses an intermediate step. Your source code is first compiled into bytecode, a platform-neutral set of instructions. That bytecode is then executed by the Java Virtual Machine (JVM), which translates it into native machine code on whatever operating system you're using. This two-step process is the reason two separate packages exist.
JDK — Java Development Kit
javac), debugging tools, documentation generators, and — importantly — the entire JRE bundled inside.JRE — Java Runtime Environment
JVM — Java Virtual Machine
Bytecode
.class and can run on any device that has a JVM installed.Visual Explanation — Nesting Diagram
Notice the layered structure in the diagram above. The JVM is the innermost layer — it is the actual engine that runs your bytecode. Wrapped around it, the JRE adds the standard libraries your program needs, such as java.lang for basic classes like String and Math. Finally, the outermost JDK layer wraps everything in the JRE and adds tools like the javac compiler that converts your .java source files into .class bytecode files.
How Java Code Travels from Source to Execution
Understanding why the JDK and JRE exist as separate entities becomes clear when you trace the journey of a Java program from writing it to watching it run. This is not a mathematical process, but rather a mechanical pipeline with distinct stages, and each stage requires different tools.
During the development phase, you write a file called Hello.java. The JDK's javac compiler reads this file and translates it into Hello.class, which contains bytecode. During the runtime phase, the JVM inside the JRE reads that bytecode, verifies it for safety, loads any needed library classes, and executes the program. This is why someone who only wants to run your program never needs the compiler — they only need the runtime environment.
.class file can run on Windows, macOS, Linux, or even a smartphone — as long as a JVM exists for that platform.Detailed Component Breakdown
What's Inside the JDK?
The JDK is the all-in-one package for Java developers. In addition to containing the entire JRE, it ships with several important tools that you'll encounter as you learn Java. Here is a closer look at each major component.
| Tool | Command | Purpose |
|---|---|---|
| Java Compiler | javac | Converts .java source files into .class bytecode files. |
| Java Debugger | jdb | Lets you step through code line-by-line to find and fix bugs. |
| Documentation Generator | javadoc | Creates HTML documentation from special comments in your code. |
| Archive Tool | jar | Packages multiple .class files into a single distributable JAR file. |
| Interactive Shell | jshell | Lets you type and test small snippets of Java code interactively (added in Java 9). |
| Java Launcher | java | Starts the JVM and runs a compiled .class file. (Also included in the JRE.) |
What's Inside the JRE?
The JRE is a leaner package designed for end users. It contains three main components. First, the JVM itself, which does the actual work of running bytecode. Second, the core class libraries — thousands of pre-built classes organized into packages like java.lang, java.util, java.io, and java.net that provide ready-made functionality for things like string manipulation, file reading, and networking. Third, supporting files such as configuration data and security certificates that the JVM needs at startup.
jlink tool, which bundles only the modules your application actually needs.Worked Example — Writing, Compiling, and Running a Program
Let's trace through a complete example so you can see exactly which tools belong to the JDK and which belong to the JRE. We will create a simple "Hello, World!" program and follow each step.
Hello.java. Inside, you write:
public class Hello { public static void main(String[] args) { System.out.println("Hello, World!"); } }
This is plain text — it's human-readable Java source code.Hello.java source file on your hard drive.javac Hello.java. The javac compiler is a JDK-only tool. It checks your code for syntax errors, resolves class references, and generates bytecode.Hello.class file containing platform-independent bytecode.java Hello in the terminal. The java launcher starts the JVM (part of the JRE). The JVM's class loader reads Hello.class and also loads any standard library classes your program references, such as System and PrintStream.main method, and the console prints: Hello, World!Hello.class file to a friend, they do not need the JDK. They only need a JRE (or a JDK, which includes the JRE) installed on their computer. The bytecode runs identically regardless of whether they're on Windows, macOS, or Linux.JDK vs. JRE — Side-by-Side Comparison
Now that you've seen each package in action, let's line them up directly. The table below highlights the key differences and shows where they overlap.
| Feature | JDK | JRE |
|---|---|---|
| Primary purpose | Develop and run Java programs | Run Java programs only |
| Includes JVM? | Yes (inside the bundled JRE) | Yes |
| Includes core libraries? | Yes | Yes |
| Includes compiler (javac)? | Yes | No |
| Includes debugger (jdb)? | Yes | No |
| Includes javadoc? | Yes | No |
| Who needs it? | Developers writing Java code | End users running Java apps |
| Typical download size | ~300 MB (varies by version) | ~60–80 MB (when available) |
Connecting to Advanced Concepts
Once you're comfortable with the JDK/JRE distinction, several advanced topics build directly on this foundation. Modern Java development has introduced new layers of tooling that extend these core ideas.
| Concept You Know | Advanced Concept | How They Connect |
|---|---|---|
| JRE runs bytecode | JIT Compilation | The JVM doesn't just interpret bytecode — it identifies "hot" code paths and compiles them to native machine code at runtime for faster performance. |
| JDK packages apps into JARs | Build Tools (Maven, Gradle) | Real-world projects use build automation tools that call JDK commands for you, manage dependencies, and produce deployable packages. |
| Standalone JRE is deprecated | jlink Custom Runtimes | Since Java 9, the modular system lets you build a custom minimal JRE that contains only the modules your app actually uses, reducing size. |
| JVM is platform-specific | GraalVM & Ahead-of-Time | GraalVM can compile Java bytecode directly to native executables, eliminating the need for a JRE on the target machine entirely. |
You don't need to master these advanced concepts right now. The key point is that the JDK and JRE model is the foundation upon which all modern Java tooling is built. Understanding why the compiler, runtime, and libraries are separated will help you make sense of build systems, deployment strategies, and performance tuning as you advance in your programming journey.
Practice Problems
javac MyApp.java in their terminal and gets the error: 'javac' is not recognized as an internal or external command. They can, however, successfully run java -version. What is the most likely explanation, and how should they fix it?jlink tool for the kiosk.jlink tool addresses the concern raised by the opposing side.Lesson Summary
The Java Development Kit (JDK) is the complete package for building Java software, containing the javac compiler, debugger, documentation tools, and the entire Java Runtime Environment (JRE). The JRE, in turn, provides everything needed to execute Java programs: the Java Virtual Machine (JVM) and the core class libraries. The layered relationship is JVM ⊂ JRE ⊂ JDK.
Java's two-step process — compiling source code (.java) into platform-independent bytecode (.class), then running that bytecode on any JVM — is the foundation of Java's "Write Once, Run Anywhere" philosophy. As a student learning Java, always install the JDK — it gives you every tool you need to write, compile, debug, and run your programs.