JDK, JRE, and JVM

Understanding the Java ecosystem components

Interview Relevant: Core concept tested in technical rounds

The Java platform consists of three core components that work together to execute Java programs. Understanding the relationship between JDK, JRE, and JVM is fundamental to Java development.

JVM

Java Virtual Machine

An abstract computing machine that enables a computer to run Java programs and provides platform independence by executing bytecode.

Loads and verifies bytecode
Executes bytecode instructions
Manages memory and garbage collection
JRE

Java Runtime Environment

Implementation of JVM along with libraries and files needed to run Java applications.

Includes:

JVM (Java Virtual Machine)
Core libraries (java.lang, java.util, etc.)
Configuration files and resources

Note: Required to run Java programs, but cannot compile them.

JDK

Java Development Kit

Complete development kit for Java developers containing all tools needed to develop, compile, and run Java applications.

Development Tools:

JRE + JVM
Compiler (javac)
Debugger (jdb)
Documentation (javadoc)
Archive tool (jar)
Other utilities

How They Work Together

JDK ⊃ JRE ⊃ JVM

JDK contains JRE, which in turn contains JVM

To Run Java Programs

Install JRE (includes JVM and libraries)

To Develop Java Programs

Install JDK (includes JRE, JVM, and tools)

Code Examples

Commands to verify Java installation and compile/run programs

java
1# Check JDK version
2java -version
3
4# Check compiler version
5javac -version
6
7# Compile Java file
8javac HelloWorld.java
9
10# Run compiled class
11java HelloWorld

Use Cases

  • JVM: Platform-independent execution of Java bytecode
  • JRE: Running Java applications on end-user machines
  • JDK: Development environment for creating Java applications

Common Mistakes to Avoid

  • Installing JRE when JDK is needed for development
  • Not setting JAVA_HOME environment variable correctly
  • Confusing JVM implementations (HotSpot, OpenJ9, GraalVM)
  • Not understanding that .class files contain bytecode, not machine code