Skip to content
C

JDK, JRE and JVM

JVM (Java Virtual Machine) is the engine that actually runs your Java program. JRE (Java Runtime Environment) is the JVM plus the libraries needed to run Java applications.


1. What are JDK, JRE, and JVM?

JVM (Java Virtual Machine) is the engine that actually runs your Java program. JRE (Java Runtime Environment) is the JVM plus the libraries needed to run Java applications. JDK (Java Development Kit) is the JRE plus tools needed to write and compile Java code, such as the compiler.

2. Why is it used?

If you only want to run Java applications, you need the JRE. If you want to write and build Java programs yourself, you need the JDK, since it includes everything the JRE has, plus development tools.

3. Real-Life Example

Think of a kitchen. The JVM is like the stove that actually cooks the food. The JRE is the whole kitchen with the stove, utensils, and ingredients needed to cook a finished dish. The JDK is the kitchen plus a recipe book and cooking classes — everything needed to create new dishes from scratch.

4. Syntax

java
// Not code, but a command you run in terminal after installing JDK // javac MyFirstProgram.java -> compiles code (JDK) // java MyFirstProgram -> runs code (JRE + JVM)

5. Example Program

java
public class CheckVersion { public static void main(String[] args) { System.out.println("Java version: " + System.getProperty("java.version")); } }

Output:

Java version: 21.0.1   (this will vary depending on your installed JDK version)

6. Key Points to Remember

  • JVM runs the code; JRE lets you run programs; JDK lets you write and run programs.
  • JDK = JRE + Development Tools. JRE = JVM + Libraries.
  • This is one of the most commonly asked basic interview questions.

Practice Problems

Try each question yourself first, then check the answer.

1. The two equations

Write the two equations that relate JDK, JRE and JVM.

Answer: JDK = JRE + development tools (such as the compiler) and JRE = JVM + libraries.

2. Run only

You only want to run Java apps, not build them. What is the minimum you must install, and why?

Answer: The JRE. It contains the JVM (to execute bytecode) plus the standard libraries — everything needed to run a program. The JDK is only needed to compile.

3. Command to component

Match each command to the component it uses: javac Hello.java and java Hello.

Answer: javac Hello.java uses the JDK's compiler to produce Hello.class. java Hello uses the JRE + JVM to execute that bytecode.

4. Kitchen analogy

In the kitchen analogy, what do the stove, the whole kitchen, and the kitchen-plus-recipe-book represent?

Answer: Stove = JVM (runs the code). Whole kitchen = JRE (everything needed to run a finished dish). Kitchen + recipe book and classes = JDK (everything needed to create new programs).

Mock Test

  • JDK, JRE and JVM - Quick Test

    10 questions on the three pieces you install and use to build and run Java.

    10 questions · 10 min · Easy
    Start Mock Test