☕ Java Foundations · Beginner

JDK vs JRE vs JVM in Java

JDK = tools to build (javac, jshell…), JRE = runtime libraries, JVM = the engine that executes bytecode.

🧩 The mysteryYou install Java, type javac, and get "command not found". Java is installed... so what's missing?

Three nested boxes

The JVM is the engine that executes bytecode. The JRE (Java Runtime Environment) is a JVM plus the standard class libraries: ready-made code for lists, files, math and more. The JDK (Java Development Kit) is a runtime plus developer tools. Engine, car, car plus the workshop that builds cars.

JDK
    tools: javac, jshell, javadoc, jar...
    JRE
        standard libraries
        JVM  (runs bytecode)

The JDK toolbox

javac compiles .java into .class. java launches programs. jshell is an interactive REPL: type a line, see the result. javadoc builds HTML docs. jar packages files. jlink builds custom runtimes. To compile, you need the JDK: a runtime alone has no javac.

🤔 Think first

Who runs your program?

Your program is running. Which piece is executing its bytecode right now: javac, jar or the JVM?

Think about it, then reveal the answer

The JVM. javac's job ends the moment it has produced the .class files. It takes no part when the program runs.

⚠️ The trap

Not everything is in the JDK

Maven and Gradle are hugely popular build tools, but they're third-party: you install them separately. They call JDK tools like javac for you. javac, jshell, javadoc and jar all ship inside the JDK itself.

🔮 Predict it

Your turn

You want to ship your app with a small runtime that contains only the Java modules it actually uses. Which JDK tool builds that?

  1. javac
  2. jlink
  3. jshell
Show the answer

jlink (Java 9+) assembles a custom runtime image from just the modules you list. Smaller download, fewer moving parts.

Where did the JRE go?

Since Java 11, Oracle no longer ships a separate JRE download. Developers install a JDK. Apps that need a runtime build a trimmed one with jlink and bundle it.

💼 In the real world

In real projects

Production containers often ship a jlink-trimmed runtime instead of a full JDK: smaller images, faster deploys, and no compiler lying around for attackers. Build servers, on the other hand, need the full JDK to compile.

Key takeaways

  1. JVM: executes bytecode
  2. JRE: JVM + standard libraries, enough to run programs
  3. JDK: runtime + development tools, needed to compile
  4. Since Java 11 Oracle ships no separate JRE; jlink builds custom runtimes

💡 The JVM is a car engine, the JRE is the whole car, and the JDK is the car plus the workshop that builds cars.

🤯 Did you know?

There isn't just one JVM. HotSpot (from OpenJDK), Eclipse OpenJ9 and GraalVM are different JVMs, and all of them run the same bytecode.

Practice questions

Which component actually executes your program's bytecode?

  1. javac
  2. The jar tool
  3. The JVM
  4. javadoc
Check your answer

The JVM. javac only translates source into bytecode; jar packages files; javadoc builds documentation. The JVM loads and executes the bytecode.

Which of these is NOT a tool that ships with the JDK?

  1. javac
  2. jshell
  3. javadoc
  4. Maven
Check your answer

Maven. Maven is a popular third-party build tool you install separately. javac, jshell and javadoc are all included in the JDK.

Next: follow one file's journey, from Hello.java to bytecode to blazing-fast machine code.