Bird
Raised Fist0
Javaprogramming~10 mins

JDK, JRE, and JVM difference in Java - Step-by-Step Execution

Choose your learning style10 modes available
Concept Flow - JDK, JRE, and JVM difference
Write Java Code
↓
Use JDK to Compile
↓
Bytecode (.class files)
↓
Use JRE to Run
↓
JVM Executes Bytecode
↓
Program Output
Java code is written and compiled by JDK into bytecode, which is run by JRE using JVM to produce output.
Execution Sample
Java
public class Hello {
  public static void main(String[] args) {
    System.out.println("Hello World");
  }
}
This Java program prints 'Hello World' to the screen.
Execution Table
StepComponentActionInputOutput
1DeveloperWrites Java source codeHello.javaJava code text
2JDK (javac)Compiles Java codeHello.javaHello.class (bytecode)
3JREPrepares runtime environmentHello.classReady to run bytecode
4JVMLoads and executes bytecodeHello.classPrints 'Hello World'
5ProgramEnds executionN/AProgram stops
💡 Program ends after printing output.
Variable Tracker
ComponentState BeforeState After
Java Source CodeNot writtenHello.java with code
BytecodeNot compiledHello.class file created
Runtime EnvironmentNot readyJRE ready to run bytecode
ExecutionNot startedProgram output displayed
Key Moments - 3 Insights
Why do we need both JDK and JRE?
JDK includes tools to write and compile code (see Step 2), while JRE only runs compiled code (Step 3). You need JDK to create programs and JRE to run them.
Is JVM part of JDK or JRE?
JVM is inside JRE (Step 4). JRE provides JVM to run bytecode, and JDK includes JRE plus tools to compile.
What does JVM actually do?
JVM reads the bytecode (.class files) and runs it on your computer (Step 4), turning code into actions like printing text.
Visual Quiz - 3 Questions
Test your understanding
Look at the execution table, which component compiles the Java code?
AJVM
BJRE
CJDK
DDeveloper
💡 Hint
Check Step 2 in the execution table where compilation happens.
At which step does the JVM execute the bytecode?
AStep 2
BStep 4
CStep 3
DStep 5
💡 Hint
Look at Step 4 in the execution table where execution happens.
If you only have JRE installed, what can you NOT do?
ACompile Java source code
BExecute bytecode
CRun Java programs
DPrint output
💡 Hint
Refer to key moment about difference between JDK and JRE.
Concept Snapshot
JDK = Java Development Kit: tools to write and compile Java code.
JRE = Java Runtime Environment: runs compiled Java bytecode.
JVM = Java Virtual Machine: part of JRE that executes bytecode.
Write code -> Compile with JDK -> Run with JRE/JVM -> Output.
JDK includes JRE; JRE includes JVM.
Full Transcript
Java programs start as source code written by developers. The JDK compiles this code into bytecode files. The JRE provides the environment to run these bytecode files. Inside the JRE, the JVM executes the bytecode, turning it into actions like printing text. The JDK is needed to create and compile programs, while the JRE is enough to run them. JVM is the engine inside JRE that runs the code.

Practice

(1/5)
1. Which component is responsible for compiling and running Java programs?
easy
A. JDK
B. JRE
C. JVM
D. Java API

Solution

  1. Step 1: Understand the role of JDK

    JDK includes tools to write, compile, and run Java programs.
  2. Step 2: Compare with JRE and JVM

    JRE only runs programs, JVM executes bytecode, but JDK does both compile and run.
  3. Final Answer:

    JDK -> Option A
  4. Quick Check:

    Compile + run = JDK [OK]
Hint: JDK = write + compile + run Java [OK]
Common Mistakes:
  • Confusing JRE as compiling tool
  • Thinking JVM compiles code
  • Mixing JDK with Java API
2. Which of the following is the correct way to describe JVM?
easy
A. It compiles Java source code into bytecode.
B. It is a set of Java libraries.
C. It runs Java bytecode inside the JRE.
D. It provides tools to write Java programs.

Solution

  1. Step 1: Identify JVM's function

    JVM executes Java bytecode, acting as the engine inside JRE.
  2. Step 2: Eliminate other options

    Compiling is done by JDK, tools to write programs are in JDK, libraries are Java API.
  3. Final Answer:

    It runs Java bytecode inside the JRE. -> Option C
  4. Quick Check:

    JVM = runs bytecode [OK]
Hint: JVM runs bytecode inside JRE [OK]
Common Mistakes:
  • Thinking JVM compiles code
  • Confusing JVM with JDK
  • Mixing JVM with Java libraries
3. What will happen if you try to run a Java program with only JRE installed (no JDK)?
medium
A. You can compile and run the program.
B. You cannot run or compile the program.
C. You can compile but not run the program.
D. You can only run the program, not compile it.

Solution

  1. Step 1: Understand JRE capabilities

    JRE allows running Java programs but does not include compiler tools.
  2. Step 2: Understand JDK role

    JDK includes compiler; without it, compilation is not possible.
  3. Final Answer:

    You can only run the program, not compile it. -> Option D
  4. Quick Check:

    JRE = run only [OK]
Hint: JRE runs only, no compile tools [OK]
Common Mistakes:
  • Assuming JRE can compile
  • Confusing JRE with JDK
  • Thinking JRE cannot run programs
4. Identify the error in this statement: "JVM is a part of JDK that compiles Java code."
medium
A. JVM is part of JRE, not JDK, and it runs bytecode, not compiles.
B. JVM compiles Java code, so the statement is correct.
C. JVM is a separate tool outside JDK and JRE.
D. JVM compiles and runs Java code inside JDK.

Solution

  1. Step 1: Clarify JVM's role

    JVM runs Java bytecode; it does not compile source code.
  2. Step 2: Understand JVM's location

    JVM is part of JRE, which is included in JDK, but JVM itself is inside JRE.
  3. Final Answer:

    JVM is part of JRE, not JDK, and it runs bytecode, not compiles. -> Option A
  4. Quick Check:

    JVM runs bytecode inside JRE [OK]
Hint: JVM runs bytecode inside JRE, not compiles [OK]
Common Mistakes:
  • Thinking JVM compiles code
  • Confusing JVM location
  • Mixing JDK and JRE roles
5. You want to develop, compile, and run a Java application on your computer. Which components must you install and why?
hard
A. Only JRE, because it can run and compile Java programs.
B. JDK, because it includes tools to write, compile, and run Java programs.
C. Only JVM, because it compiles and runs Java programs.
D. JRE and JVM separately, because JRE cannot run programs alone.

Solution

  1. Step 1: Identify development needs

    Developing requires writing, compiling, and running Java code.
  2. Step 2: Match components to needs

    JDK includes compiler, runtime (JRE), and JVM engine, covering all needs.
  3. Step 3: Eliminate incorrect options

    JRE cannot compile, JVM is inside JRE, and installing separately is unnecessary.
  4. Final Answer:

    JDK, because it includes tools to write, compile, and run Java programs. -> Option B
  5. Quick Check:

    Develop + compile + run = JDK [OK]
Hint: JDK includes all tools for Java development [OK]
Common Mistakes:
  • Thinking JRE can compile
  • Installing JVM alone
  • Separating JRE and JVM unnecessarily
Recommended

Ready to prove it?

Pass the test and this pattern moves unknown strong while earning +1 Grip toward your certificate.

10 questions~5 mineasy hard