Difference between JDK, JRE and JVM — Java Technical Interview Questions & Answers

Difference between JDK, JRE and JVM

Difference between JDK, JRE and JVM

  • Three names that look similar: JVM, JRE, JDK. Freshers mix them. Learn them as three boxes, one inside the other.
  • JVM (Java Virtual Machine) is the engine. It reads bytecode and runs your program. Without JVM, a .class file does nothing.
  • JRE (Java Runtime Environment) is JVM plus the libraries needed to run a ready app. If you only want to run a Java program, JRE is enough.
  • JDK (Java Development Kit) is JRE plus tools for writing code — mainly javac (compiler). If you write programs in college, you install JDK, not only JRE.
  • Picture: JDK contains JRE. JRE contains JVM. Developer → JDK. Only run apps → JRE. Engine inside → JVM.
  • Let's take this on the board with one tiny Main class — no extra files. Difference between JDK, JRE and JVM — output: JVM → runs bytecode / JRE → JVM + libraries / JDK → JRE + javac/tools. Say that nesting in the viva. Start from main, go line by line, and stop at each print. That output is the proof for Difference between JDK, JRE and JVM.
JDK   (write + compile)
    javac + tools
      JRE   (run apps)
        libraries
          JVM   (run bytecode)

Technical Interview Tip: Draw JDK > JRE > JVM. One line each.

Code Examples for Difference between JDK, JRE and JVM

Example

// JDK / JRE / JVM — remember the nesting
public class Main {
  public static void main(String[] args) {
    System.out.println("JVM  → runs bytecode");
    System.out.println("JRE  → JVM + libraries");
    System.out.println("JDK  → JRE + javac/tools");
  }
}

Difference between JDK, JRE and JVM — output: JVM → runs bytecode / JRE → JVM + libraries / JDK → JRE + javac/tools. Say that nesting in the viva.

How to Explain Difference between JDK, JRE and JVM to an Interviewer

What is JVM?

Java Virtual Machine Runs bytecode

What is JRE?

Runtime to run Java apps JVM + libraries

What is JDK?

Development kit JRE + javac and tools

What should a student install?

JDK Because we compile with javac

Is JDK the same as JRE?

No JDK is for building JRE is mainly for running