JDK vs JRE vs JVM in Java

In the last lesson you installed Java. Three names keep popping up: JDK, JRE, and JVM. They sound alike, and nobody tells you which one you actually need. By the end you’ll know exactly what each is, and which one lets you write Java.

🧩 The three names at a glance

These three are not rivals. They sit inside each other, like a nested toolbox:

  • JVM is the engine that runs your Java program.
  • JRE is the JVM plus the basic libraries needed to run a program.
  • JDK is the JRE plus the tools you need to write and build a program.

So the JDK contains the JRE, and the JRE contains the JVM. You only ever install the biggest box, and the smaller ones come free inside it.

βš™οΈ What is the JVM?

The JVM (Java Virtual Machine) is the part that actually runs your code. Your Java becomes bytecode, and the JVM reads that bytecode and runs it on your real computer. Bytecode is a halfway form: not English-like Java anymore, but not the zeros and ones for a specific chip yet.

What the JVM does for you:

  • Runs the bytecode. Carries out the instructions one by one.
  • Fits your machine. Each OS has its own JVM, and all of them read the same bytecode, so one program runs everywhere. This is the Java promise: write once, run anywhere.
  • Manages memory. It cleans up memory you no longer use, so you do not do it by hand. This cleanup is called garbage collection.
  • Speeds things up. It turns your hot, often-run code into fast machine code while the program runs. This trick is the JIT (Just-In-Time) compiler, so Java ends up near native speed.

Think of the JVM like a music player. The song file (your bytecode) is the same everywhere, and each device’s player handles its own hardware. One song, any speaker.

Why this matters

The JVM is the reason Java code is portable. A C program is usually built for one kind of machine. A Java program is built once into bytecode, then any JVM can run it. So the JVM is not a small detail. It is the whole idea that made Java popular.

πŸ“¦ What is the JRE?

The JRE (Java Runtime Environment) is what you need to run a finished Java program someone already built. Enough to run, not enough to write.

The JRE has two parts:

  • The JVM. The engine we just talked about.
  • The core libraries. Ready-made code for text, dates, lists, and files. Your program uses these while it runs.

The libraries matter because almost no real program is written from scratch. When your code prints a line or sorts a list, it calls code that already exists, and your bytecode leans on these libraries the whole time. A JVM with no libraries could not run most real programs, so the JRE bundles them together.

So the formula is JRE = JVM + libraries. If you only ever ran Java apps, the JRE alone would do the job.

A real-life way to see it

The JRE is like a finished kitchen with a working stove and all the basic ingredients. You can cook any recipe someone hands you. But you cannot design and build a brand new kitchen with it. For that, you need more tools.

πŸ› οΈ What is the JDK?

The JDK (Java Development Kit) is the full package for people who write Java, and the one you installed last lesson. It has everything the JRE has, plus the tools to create programs.

What the JDK adds on top:

  • The compiler (javac). Turns your .java code into bytecode. Without it you cannot build a program at all.
  • The runner (java). Launches your compiled program through the JVM.
  • Other developer tools. Helpers for debugging, packaging your app, and building documentation.

So the formula is JDK = JRE + development tools. The simplest test: to run a Java app the JRE is enough, but to write and build one you need the JDK, because writing means compiling and only the JDK can compile.

πŸ” How they fit together

Here is the boxes-inside-boxes idea as a picture: the JVM inside the JRE, the JRE inside the JDK.

JDK (Java Development Kit)

JRE (Java Runtime Environment)

JVM (Java Virtual Machine)

Runs the bytecode

Core libraries

Developer tools: javac, debugger, packagers

Now follow the compile-then-run flow when you build and run a program:

  • You write code in a .java file. Plain text you can read. You need the JDK to do anything with it.
  • The compiler turns it into bytecode. javac reads your .java file and produces a .class file holding the bytecode.
  • The JVM runs the bytecode. java starts the JVM, which reads the .class file and runs it.

So the path is short and always the same: .java β†’ .class β†’ running program. Here it is as a picture.

Hello.java (your code)

javac (compiler)

Hello.class (bytecode)

JVM (runs it)

Program output

Say Alex writes a tiny program. These two commands show the whole cycle: compile, then run.

Terminal window
javac Hello.java # βœ… turns Hello.java into Hello.class (bytecode)
java Hello # βœ… JVM runs Hello.class and shows the output

Notice the second command says java Hello, not java Hello.class. You give the class name, not the file name. That trips up a lot of beginners.

So the JDK is used at every step: javac builds the result, then the JRE and JVM run it. Not competing tools, just different stages of the same journey.

πŸ“Š Quick comparison

A side-by-side view to lock it in.

Name Full form What it is for Contains When you need it
JVM Java Virtual Machine Runs the bytecode The engine only Always, hidden inside the others
JRE Java Runtime Environment Runs finished Java programs JVM + libraries When you only run Java apps
JDK Java Development Kit Writes and builds Java programs JRE + developer tools When you write Java (you, right now)

⚠️ Common Mistakes

The mix-ups that cause real confusion:

  • Thinking they are three separate downloads. One JDK install already includes the JRE and JVM.
  • Installing the JRE to write code. The JRE cannot compile, so you get a β€œcommand not found” error on javac. To write Java, install the JDK.
  • Saying the JVM and JRE are the same. The JVM is just the engine; the JRE is the JVM plus its libraries.
  • Running the file name instead of the class name. java Hello.class errors. Use java Hello and the JVM finds the .class file for you.
  • Thinking bytecode is machine code. Bytecode is the halfway form and still needs the JVM to run.

βœ… Best Practices

Habits that keep you out of trouble from day one:

  • Install the JDK, not the JRE. It already includes everything the JRE has.
  • Check with java -version and javac -version. If javac is missing, you have a JRE only. Fix that before going further.
  • Pick a long-term support version. Releases like Java 17 or Java 21 get updates for years, a safe choice for learning and real work.
  • Let the JVM manage memory. Garbage collection handles cleanup. Trust it and focus on your code.

🧩 What You’ve Learned

Let’s lock in the three names:

  • βœ… The JVM is the engine that runs your bytecode and fits it to your machine.
  • βœ… The JRE is the JVM plus core libraries. It runs finished Java programs.
  • βœ… The JDK is the JRE plus developer tools. It lets you write and build Java.
  • βœ… They nest: JDK contains JRE, and JRE contains JVM.
  • βœ… The flow is .java β†’ javac β†’ .class bytecode β†’ JVM β†’ output.
  • βœ… To learn and write Java, you need the full JDK, which is what you installed.

Check Your Knowledge

Test what you learned. Pick an answer for each question, then click Check.

  1. 1

    Which part actually runs your Java bytecode?

    Why: The JVM (Java Virtual Machine) reads the bytecode and runs it on your real computer.

  2. 2

    What does the JRE contain?

    Why: JRE = JVM + libraries. It has what you need to run a finished Java program.

  3. 3

    Why do you need the JDK to learn Java, not just the JRE?

    Why: The JDK adds the compiler (javac) and other tools, so you can actually write and build Java.

  4. 4

    How do the three relate to each other?

    Why: They nest like boxes: the JDK holds the JRE, and the JRE holds the JVM.

πŸš€ What’s Next?

You know the tools and how they fit. Enough setup. Time to write and run your first Java program.

Your First Java Program

Share & Connect