JDK, JRE and JVM
10 min · Beginner
JDK, JRE and JVM are three short names you will see often. Together they are the parts of Java that build your program and run it.
What each one does
In the last lesson you saw two steps. The compiler turns your code into bytecode, and then the JVM runs the bytecode. The JDK, JRE and JVM are the names for the parts that do these jobs.
One more new word: a library is ready-made code that comes with Java. For example, System.out.println comes from Java's libraries, so you do not have to write it yourself.
- JVM (Java Virtual Machine) – executes your bytecode (the
.classfile) on your computer. - JRE (Java Runtime Environment) – a common name for the Java runtime: the JVM plus Java's libraries. It is what you need to run a Java program. It is not always a separate install.
- JDK (Java Development Kit) – development tools such as the compiler
javac, plus the runtime parts (libraries and JVM). It can build and run programs.
An everyday picture: a kitchen
Think of a ready-to-cook food packet, like instant noodles. First someone makes the packet. Then anyone with a stove and a pot can cook it.
Your .java file is like the raw recipe. The compiler turns it into a packet: the bytecode. The JVM then "cooks" the packet, which means it runs your program.
- JVM = the stove. It does the actual cooking (running).
- JRE = the stove plus pots and spices (the libraries). Enough to cook any packet.
- JDK = the full kitchen. Everything in the JRE, plus the tools to make new packets (the compiler).
How they fit together (a simple model)
A simple way to picture them is boxes inside boxes. The JDK holds the runtime (the JRE), and the runtime holds the JVM. This is a conceptual model: a picture that helps you think. It does not show how the files are laid out on your disk.
Modern JDKs do not install a separate JRE. The runtime parts are simply inside the JDK. So one JDK install gives you the compiler, the libraries and the JVM.
javac + the runtime, and the runtime (JRE) = libraries + JVM.Which one do you install?
Install the JDK. You need javac to build your own programs, and the JDK can also run them.
For new Java versions (Java 11 and later), Oracle offers only the JDK as a download. Some other providers still offer a separate JRE, but you do not need it. One JDK is enough to write and run Java.
Example · From source file to running program
Hello.java source code: the text you write | javac (compiler, a JDK tool) vHello.class bytecode | java (starts the JVM, which uses the libraries) vThe program runs and prints its outputjavac builds. java runs.
What this code does
javac Hello.java– the compiler, a JDK tool, turns the source file into bytecode:Hello.class.java Hello– starts the JVM, which runs the bytecode.System.out.printlncomes from Java's libraries (the runtime).- You will type these two commands yourself in the lesson Your first Java program.
Next step
Check your understanding
5 quick questions