Card 04/ 06

ComparisonDifficulty: Intermediate1 min

JDK vs JRE vs JVM

Three acronyms in every installation guide, and the one to install if you want to compile anything.

The JVM runs bytecode, the JRE (Java Runtime Environment) is the JVM plus the standard library, and the JDK (Java Development Kit) is the JRE plus the compiler and other tools. They nest, and only the JDK can compile code.

Installation guides mention all three in the same sentence, as though the difference were obvious. Picking the wrong one leaves you with a machine that can run Java and cannot compile it.

What each of the three is, and what it contains
NameWhat it isContainsYou need it to
JVM, the Java Virtual MachineThe engine that executes bytecodeNothing else; it is the innermost pieceRun bytecode, and nothing more
JRE, the Java Runtime EnvironmentThe JVM plus the standard libraryThe JVM, plus String, List, files, networkingRun a program somebody else compiled
JDK, the Java Development KitThe JRE plus the tools that make bytecodeThe JRE, plus javac, jar, jshell, a debuggerCompile anything at all

They nest. Every JDK contains a JRE, and every JRE contains a JVM. Nothing contains a JDK, which is why installing the smallest one leaves you stuck.

The JDK contains the JRE, which contains the JVM

The decision rule. On any machine where you write code, install the JDK. On a machine that only runs a jar somebody else built, such as a container image or a server, a JRE is enough and is smaller. If you are unsure which of the two a machine is, it is a development machine and it wants the JDK.