In Java, three important terms are JDK, JRE, and JVM.
These three components are closely related, but they have different roles.
Understanding them helps you clearly understand how Java programs are developed,
compiled, and executed.
Java has a layered execution model. When you write a Java program, you use the
JDK. When the program runs, it needs the JRE. Inside the JRE,
the JVM executes the compiled bytecode.
Simple way to remember:
JDK = Develop Java programs
JRE = Run Java programs
JVM = Execute Java bytecode
There are two principal products in the Java SE platform family:
Java SE Runtime Environment (JRE)
Java Development Kit (JDK)
Java Development Kit (JDK)
JDK stands for Java Development Kit.
It provides the environment and tools required to
develop, compile, and run Java programs.
JDK contains:
Development tools like javac, debugger, and jar
JRE for running Java applications
Libraries and supporting files required for development
You need the JDK if you want to write and compile your own Java programs.
Java Runtime Environment (JRE)
JRE stands for Java Runtime Environment.
It provides the libraries, JVM, and other required components
to run Java applications.
JRE is useful when you only want to run Java applications and
do not need to compile or develop Java source code.
JRE contains:
JVM
Core Java libraries
Runtime files required to execute Java applications
Java Virtual Machine (JVM)
JVM stands for Java Virtual Machine.
It is an abstract machine that provides a runtime environment
to execute Java bytecode.
Java source code is first compiled into bytecode. The JVM reads this bytecode
and executes it on the underlying operating system.
JVM executes Java bytecode.
JVM is platform-dependent.
Bytecode is platform-independent.
Different operating systems have different JVM implementations.
Important:
Java is platform independent because compiled Java bytecode can run on any system
that has a compatible JVM.
Difference Between JDK, JRE and JVM
Feature
JDK
JRE
JVM
Full Form
Java Development Kit
Java Runtime Environment
Java Virtual Machine
Purpose
Develop + Compile + Run Java programs
Run Java programs
Execute Java bytecode
Used By
Developers
Users / Applications
JRE internally
Contains
JRE + Development tools
JVM + Libraries
Execution engine only
Includes
JRE
JVM
Does not include others
Example Tools
javac, jar, debugger
java command
Interpreter, JIT Compiler
JVM Architecture and Working
The JVM architecture is divided into important components that work together
to load, verify, and execute Java bytecode.
1. Class Loader Subsystem
The Class Loader loads class files into memory and performs loading,
linking, and initialization.
Loading: Finds and imports class data.
Linking: Performs verification, preparation, and resolution.
Initialization: Assigns proper initial values to class variables.
2. Runtime Data Area
The Runtime Data Area stores data required during program execution.
Method Area: Stores class-level data.
Heap Area: Stores objects and instance variables.
Stack Area: Stores method calls and local variables.
PC Register: Stores the address of the current instruction.
Native Method Stack: Supports native methods.
3. Execution Engine
The Execution Engine executes Java bytecode. It includes the interpreter
and JIT compiler.
Interpreter: Reads and executes bytecode line by line.
JIT Compiler: Converts frequently used bytecode into native machine code for better performance.
Garbage Collector: Removes unused objects from memory.
How JIT Compiler Improves Performance
The Just-In-Time (JIT) Compiler is a part of the JVM execution engine.
It helps improve the performance of Java programs by converting bytecode into
native machine code at runtime.
How JIT Works:
Normally, JVM uses an interpreter to execute bytecode line by line.
This can be slow for frequently used code.
The JIT compiler identifies frequently executed code (hot spots).
It converts this code into native machine code.
Next time, the native code runs directly (much faster).
Performance Benefit:
JIT avoids repeated interpretation and significantly speeds up execution.
Execution Comparison
Without JIT:
Bytecode → Interpreted every time → Slower
With JIT:
Bytecode → Compiled to native code → Cached → Faster execution
Summary:
JDK is used to develop and compile Java programs.
JRE is used to run Java applications.
JVM executes Java bytecode.
JDK contains JRE, and JRE contains JVM.
Java bytecode is platform independent, but JVM is platform dependent.
Next step: Try writing and running Java code online.