Java Programming, JVM Internals · December 2, 2026

Java for Beginners, Lesson 3: JDK, JRE, JVM and WORA Explained

Java for Beginners · Module 1: Getting Started


🎯 Why Do JDK, JRE and JVM Confuse Everyone?

Think of a DVD. The disc holds the movie in a standard format. Any DVD player can play it, whether it is a cheap one or an expensive one. The movie does not change; only the player differs.

Java works the same way. Your compiled program is the disc (bytecode). The JVM is the player. Windows, Linux and macOS each have their own JVM, so the same disc plays on all of them. The JDK and JRE are just packages that bundle the player with other things.

📌 WORA (Write Once, Run Anywhere): compile your program once to bytecode, and run that same bytecode on any computer that has a JVM.

1️⃣ JDK, JRE and JVM: What Is Inside What?

JDK: Java Development Kit (for developers)
javac compiler · javap · jar · debugger · other tools
JRE: Java Runtime Environment (to run programs)
standard class libraries (String, Math, ArrayList …)
JVM: Java Virtual Machine
loads bytecode · checks it · runs it

Figure 1: The JVM sits inside the JRE, and the JRE sits inside the JDK.

  • JVM: the engine. It loads your bytecode, checks it is safe, and runs it.
  • JRE: the JVM plus the standard class libraries (String, Math, ArrayList and many more). It is enough to run a Java program.
  • JDK: the JRE plus developer tools, mainly the compiler javac. You need it to write and compile programs.
💡 Modern note: From Java 11 onwards, most vendors no longer ship a separate JRE download. You install the JDK and get everything. The idea of JDK ⊃ JRE ⊃ JVM is still how Java is explained, so learn it.

2️⃣ From Source Code to Output

Java uses both a compiler and an interpreter. The compiler (javac) translates your code into bytecode once. The JVM then runs that bytecode on your particular computer.

Add.java
source code
⬇ javac (in the JDK)
Add.class
bytecode, starts with CA FE BA BE
⬇ java command starts the JVM
JVM
loads, verifies, then interprets and JIT-compiles
⬇ machine instructions of this computer
Output: 7 + 5 = 12

Figure 2: The journey of a Java program from source file to output.

Program 1: A small program to inspect

public class Add {
    static int add(int a, int b) {
        return a + b;
    }

    public static void main(String[] args) {
        int result = add(7, 5);
        System.out.println("7 + 5 = " + result);
    }
}
🖥️ Output:
7 + 5 = 12
  • The method add returns the sum of two int values.
  • main calls it with 7 and 5 and prints the result.

3️⃣ A Look Inside Bytecode

The JDK includes a tool called javap that shows the bytecode inside a .class file. After compiling Add.java, run javap -c -p Add. This is the part for the add method:

static int add(int, int);
  Code:
     0: iload_0
     1: iload_1
     2: iadd
     3: ireturn
  • iload_0 and iload_1 push the two parameters onto a stack.
  • iadd takes the top two numbers, adds them and pushes the answer.
  • ireturn returns the top value to the caller.
InstructionStack after itWhat happens
iload_0[ 7 ]push parameter a (7)
iload_1[ 7, 5 ]push parameter b (5)
iadd[ 12 ]pop two numbers, push their sum
ireturn[ ]pop 12 and return it to the caller

Figure 3: How the JVM runs add(7, 5): the stack grows and shrinks with each instruction.

The real javap output also lists the constructor and main, which uses more instructions such as invokestatic (call a method) and getstatic (read System.out). You do not need to memorise any of this. The point is that bytecode is simple, neutral and the same on every operating system.

4️⃣ Proof: Every Class File Starts with CAFEBABE

Every .class file begins with the same four bytes, called the magic number. The JVM checks them first. If they are missing, it refuses to load the file. The next program reads those bytes from the file that javac made.

import java.io.FileInputStream;
import java.io.IOException;

public class MagicNumber {
    public static void main(String[] args) throws IOException {
        try (FileInputStream in = new FileInputStream("Add.class")) {
            for (int i = 0; i < 4; i++) {
                int b = in.read();
                System.out.printf("%02X ", b);
            }
            System.out.println();
        }
    }
}
🖥️ Output:
CA FE BA BE
  • FileInputStream opens the file and in.read() reads one byte at a time.
  • %02X prints each byte as two hexadecimal digits.
  • The result CA FE BA BE is the famous “CAFE BABE” marker of every Java class file. Compile and run Add.java first so Add.class exists in the same folder.

5️⃣ What “Run Anywhere” Really Means

  • The bytecode (.class file) is the same everywhere.
  • The JVM is different for each operating system. Oracle, Eclipse Adoptium and others build one for each.
  • So the promise is not “no software needed”. It is “no need to recompile for each system”.

Terms to remember

TermMeaningWho uses it
JDKCompiler plus tools plus runtimeDevelopers
JRELibraries plus JVM to run programsUsers (older packaging)
JVMEngine that runs bytecodeEveryone, automatically
javacCompiler: .java to .classDevelopers
BytecodeNeutral instructions in .class filesJVM
JITTurns hot bytecode into machine code while runningJVM
WORAWrite Once, Run AnywhereThe goal of Java

Figure 4: Terms you will hear again and again.

⚠️ Common Confusions

Wrong ideaTruth
“Java is only interpreted”It is compiled to bytecode first, then run by the JVM
“Java is only compiled”The JVM also interprets bytecode, and compiles hot parts with JIT
“The JVM is the same on every OS”Each OS has its own JVM; the bytecode is what stays the same
“I need the JDK to run someone’s program”Only a Java runtime is needed to run; the JDK is for developing
“The .class file is machine code”It is bytecode, which only the JVM understands

❓ Frequently Asked Questions

Q1. Is the JVM a program?
Yes. When you type java Add, you start a JVM process that runs your class.

Q2. Why did Java choose bytecode?
So one compiled file works on many systems, and so the JVM can check it for safety before running.

Q3. Is Java slower than C because of the JVM?
It can start slower, but the JIT compiler makes long-running Java programs fast. Lesson 4 explains how.

Q4. Can other languages run on the JVM?
Yes. Kotlin, Scala and Groovy also compile to bytecode.

✅ Key Takeaways

  • JVM runs bytecode; JRE = JVM + libraries; JDK = JRE + developer tools.
  • javac turns .java into .class (bytecode). The JVM then runs it.
  • Bytecode is the same on every OS; the JVM is specific to each OS.
  • Every .class file starts with CA FE BA BE.
  • WORA means compile once, run anywhere there is a JVM.
🎓 Practice questions: (1) Draw the JDK, JRE and JVM as nested boxes. (2) What does javac produce? (3) Why is a JVM needed on every computer? (4) Run javap -c -p on your own small program and find the instruction that adds two numbers. (5) Explain “Write Once, Run Anywhere” using the DVD example.
All 30 lessons in this series (open course page)

Module 1 · Getting Started

Module 2 · Building Blocks

Module 3 · Operators

Module 4 · Control Flow

Module 5 · Data and Methods

Module 6 · Objects and Revision