Skip to content
Ameen Abozaid
PublishedBEG-007-L03

JDK vs JRE vs JVM

  • Lesson 3 of 5
  • 10 min read
  • Beginner
On This Lesson 11 topics

Lesson Overview

Three three-letter names appear in nearly every Java conversation: JDK, JRE, and JVM. They look alike, they are often mentioned together, and beginners regularly install the wrong one or use the names as if they meant the same thing. This lesson gives you a clean mental model: they are nested, like boxes inside boxes, each adding something to the one inside.

In the translated-book analogy from L01 and L02: the JVM is the local reader who speaks the neutral book aloud. The JRE is that reader plus the library of ready-made reference books the reader needs. The JDK is all of that plus the translator's office, with the tools to write and translate new books.

Why this matters: in BEG-005 you installed a JDK, and a common mistake in that module was installing a JRE instead. Now you will understand exactly why that does not work for development.

This lesson builds on L02 (bytecode, javac, the JVM) and BEG-005 (installing the JDK).

Learning Objectives

By the end of this lesson you will be able to:

  • Define the JVM, the JRE, and the JDK in one sentence each.
  • Draw the three as nested boxes and say what each outer box adds.
  • Say which of the three a developer needs and which one a machine that only runs programs needs.
  • Explain what "standard libraries" are and why running programs needs them.
  • Explain why a JDK is the right thing to install for this course, and why you may still see the word "JRE".
  • Check what is installed with java -version and javac -version.

Written Explanation

The three boxes

text
+------------------------------------------+
| JDK  (Java Development Kit)              |
|   + development tools: javac, ...        |
|  +------------------------------------+  |
|  | JRE  (Java Runtime Environment)    |  |
|  |   + standard libraries             |  |
|  |  +------------------------------+  |  |
|  |  | JVM (Java Virtual Machine)   |  |  |
|  |  |   runs bytecode              |  |  |
|  |  +------------------------------+  |  |
|  +------------------------------------+  |
+------------------------------------------+

Read it from the inside out.

JVM: runs bytecode

The JVM is the program that loads and runs .class files, as you learned in L02. On its own, though, it is not enough to run a useful Java program, because almost every program relies on ready-made code that Java provides.

JRE: the JVM plus the standard libraries

Your programs do not do everything themselves. A simple line that prints text to the screen uses code you did not write. That ready-made code lives in the standard class libraries: a large collection of classes for text, numbers, dates, files, networking, and more. In your Hello program you will call System.out.println. The class System is provided by the libraries, not by you.

The JRE (Java Runtime Environment) was the package of a JVM plus these libraries, and the supporting files needed to run Java programs. A machine with a JRE can run Java programs, but a JRE has no compiler, so it cannot turn .java into .class.

JDK: the JRE plus development tools

The JDK (Java Development Kit) contains everything the JRE has, and adds the tools you need to build programs. The best-known one is javac, the compiler. Other tools in the JDK include java (the launcher that starts the JVM), and utilities for packaging and documentation. You will meet the other tools later.

So:

NameAdds to what is insideCan run Java programs?Can compile Java programs?
JVM(the core)Yes, if given the standard librariesNo
JREJVM + standard librariesYesNo
JDKJRE + javac and other toolsYesYes

Which one do you install?

  • To write and build Java programs, you install the JDK. Without javac, you cannot compile.
  • A machine that only runs finished programs needs only a runtime, in the older terminology, a JRE.
  • You never install "the JVM" on its own. It always arrives as part of one of the bigger packages.

For this course, and for any developer: install the JDK. BEG-005 already had you install it and confirm it with java -version and javac -version.

A note on the word "JRE" today

You will still see the term JRE in documentation, in older tutorials, and in job posts. But the picture has shifted. According to Oracle's release notes for JDK 11, the separate JRE and Server JRE were dropped from Oracle's offering from that release on, leaving the JDK as the one download, and the jlink tool in the JDK can build a smaller custom runtime that includes only what an application needs. Other vendors that build the OpenJDK may package things differently, so check the vendor's page for what is on offer.

What this means for you: the concept of a runtime (JVM plus libraries) is still essential, and the JDK still contains it. When someone says "you need the JRE", it means "you need the Java runtime", and for development you already have it inside your JDK.

Checking what you have

You verified the installation in BEG-005. The check uses two commands in a terminal:

text
java -version
javac -version
  • java -version shows that the launcher and runtime are available and which version they are.
  • javac -version shows that the compiler is available. If this one fails with "command not found" while the first works, you probably have a runtime-only install, or your PATH points to a different install than you expect. Recall from BEG-005 how to check PATH.

The exact output text depends on your vendor and version, so do not worry if yours is not identical to someone else's.

Version numbers matter

The JDK has a version number such as 17 or 21. The javac and java you use should come from the same JDK version, because a class file built by a newer compiler may not run on an older JVM. The class file format has a version number, and a given Java release supports only a range of them. Keeping both commands from one JDK avoids that trouble.

Examples

Example 1: sorting the names (simple)

Match each description to JDK, JRE, or JVM.

  • "Loads .class files and executes the bytecode." JVM
  • "Runtime plus the standard libraries, enough to run a program but not to compile one." JRE
  • "Everything above plus javac." JDK

If you remember only one thing: JVM runs, JRE runs with libraries, JDK runs and builds.

Example 2: two laptops (practical)

Lina's laptop has a JDK. Karim's has only a runtime.

Lina (JDK)Karim (runtime only)
java HelloWorksWorks
javac Hello.javaWorks"command not found" or similar
Can write and build new programsYesNo

Karim can run Lina's finished Hello.class, but cannot compile his own changes. He has to install a JDK to become a developer. The error text varies by operating system and shell, but the cause is that javac does not exist on his machine.

Example 3: build machine versus server (realistic)

A team has two kinds of computer:

  • A build machine that compiles the code and runs automated checks. It needs the JDK, because compiling needs javac.
  • A production server that only runs the finished program. In principle it needs only a runtime. Many teams install a JDK there anyway, or build a trimmed-down runtime with jlink. The reason is practical: some operational tools that come with the JDK are handy when diagnosing a server.

The decision is about trade-offs, such as image size and convenience, not about one right answer. What stays constant is the model: a runtime is needed to run, development tools are needed to build.

Backend Insight

In backend work, "which Java do I need?" comes up at three places:

  • Your laptop: the JDK, so you can build and test.
  • The build system: a JDK, with a version that matches your project's requirements.
  • The server or container: a runtime for the same version, either a full JDK or a trimmed-down runtime.

Many production problems of the form "works on my machine but not on the server" come down to version differences between these places. Writing down the Java version a project needs, and checking it when you set up a new machine, is a simple habit that prevents a lot of confusion. Later modules on build tools and deployment make this routine.

Common Mistakes

Mistake 1: Installing only a runtime and expecting to compile

  • Incorrect: "I installed Java, so javac should work."
  • Correct: "I installed a JDK, which contains javac. A runtime-only install does not."

Check with javac -version. If it fails but java -version works, you likely lack the compiler.

Mistake 2: Using the three names as synonyms

They are not the same. The JVM is a component. The JRE contains the JVM. The JDK contains the JRE. Ask "which one do you mean?" when you hear a vague "I need Java".

Mistake 3: Mixing versions of java and javac

If javac is from one JDK and java from another, class files may be built for a newer version than the JVM supports. Use java -version and javac -version to see whether the two match.

Mistake 4: Thinking the JVM can compile source code

The JVM runs bytecode. Compiling source to bytecode is javac's job.

Exercises

Try each exercise yourself before opening the solutions.

Level A: Foundation

A1. Write one sentence defining each of JVM, JRE, and JDK.

Show solution A1

A1. The JVM is the program that runs bytecode. The JRE is the JVM plus the standard libraries needed to run Java programs. The JDK is the JRE plus development tools such as the javac compiler.

A2. Which of the three contains javac?

Show solution A2

A2. The JDK.

A3. True or false: a JRE can run a .class file but cannot compile a .java file.

Show solution A3

A3. True. A runtime has the JVM and libraries to run bytecode, but no compiler.

Level B: Application

B1. Draw the three as nested boxes, and label what each outer box adds.

Show solution B1

B1. Outer box JDK (adds javac and other tools), containing the JRE box (adds the standard libraries), containing the JVM box (runs bytecode).

B2. In a terminal java -version works but javac -version says the command is not found. List two possible explanations.

Show solution B2

B2. (1) Only a runtime is installed, so there is no javac. (2) A JDK is installed, but its bin folder is missing from PATH while another install, with only java, is found first. Checking where each command is found, as in BEG-005, shows which.

B3. Rewrite this sentence correctly: "I downloaded the JVM so I can write Java programs."

Show solution B3

B3. "I installed the JDK so I can write and compile Java programs." The JVM is only the part that runs bytecode, and it always comes inside a larger package.

Level C: Challenge

C1. A colleague wants to set up a machine whose only job is to run a finished Java service. Another wants to set up a machine that builds the service every night. For each machine, say what you would install and why.

Show solution C1

C1. Run-only machine: a Java runtime of the right version (a full JDK also works and some teams choose it for diagnosis tools), because it only needs to run bytecode. Build machine: a JDK, because compiling needs javac. The versions should match what the project requires.

C2. A project's build instructions say it needs Java 21. On your laptop, javac -version reports a different major version than java -version. Explain what may be going on and how you would investigate.

Show solution C2

C2. The two commands probably come from different installs, found through PATH: for example an older JDK first on PATH for one command and a newer one for the other. Investigate by checking which install each command resolves to (using the PATH skills from BEG-005 and BEG-006), then fix the order or remove the extra install, and open a new terminal.

Mini Challenge

Make a one-page "install cheat sheet" for a friend who is starting Java. It should contain: (1) one sentence naming which package to install and why; (2) the two verification commands; (3) what each failing result probably means; (4) a three-line nested-box picture of JDK, JRE, and JVM.

Check your work: your sheet says JDK, not JVM or JRE, for developers, and your failure meanings include the missing-javac case.

Summary & Next Lesson

Key takeaways

  • JVM runs bytecode. JRE = JVM + standard libraries. JDK = JRE + development tools such as javac.
  • The three are nested, not synonyms.
  • A developer installs the JDK. A machine that only runs programs needs only a runtime.
  • java -version and javac -version confirm what is installed. Both should come from the same JDK.
  • You will still see the word "JRE", but the JDK is the standard download for current Java releases from Oracle, and it contains a runtime.

Next lesson

You now know which tools you have and what each one does. The next lesson, "Compile and run from the terminal", puts javac and java to work: you will compile and run a real program by hand.

Self-check

  1. Which one contains the compiler?
  2. What does the JRE add to the JVM?
  3. What do you install to write Java?
  4. If javac -version fails but java -version works, what is a likely reason?
  5. Why should java and javac come from the same JDK?
Show answers
  1. The JDK.
  2. The standard libraries (and supporting files) needed to run Java programs.
  3. The JDK.
  4. Only a runtime is installed, or PATH finds a different install that has no javac.
  5. A class file built by a newer compiler may not run on an older JVM, so mismatched versions can cause failures.

References

  • Oracle, JDK 11 release notes: known issues and removals. Search results summarised its statement that the separate JRE and Server JRE are no longer offered by Oracle from JDK 11, leaving the JDK, and that jlink can create smaller custom runtimes. I did not read the page text itself, so treat the exact wording as unverified.
  • Oracle, javac command reference, JDK 21 and java command reference, JDK 21. They describe javac as the compiler that produces class files and java as the launcher that starts the JVM and runs a class.
  • Oracle, The Java Virtual Machine Specification, Java SE 21, chapter 4. It shows that class files carry a version number and that each Java SE release supports a range of versions, which supports the version-matching advice.
  • The nested-box picture and book analogy are this course's own teaching framing. The statement that some teams install a JDK on servers for diagnostic tools is general practice, not sourced here.

Practice

Apply this lesson with the module's lab, exercises and quiz.

Lab and exercises Quiz

Marking a lesson complete is optional and you can undo it any time. Your progress stays in this browser.

Continue to next lesson

Type to search levels, phases, modules and lessons.