Java Architecture (JVM, JRE, JDK)
Java architecture explains how Java programs are developed, compiled, and executed. Understanding JVM, JRE, and JDK is critical for real-time projects and interviews, because Java’s platform independence is built entirely on this architecture.
High-Level Java Architecture Flow
- Developer writes Java source code (.java)
- Java compiler (javac) converts it into bytecode (.class)
- Bytecode is executed by the Java Virtual Machine (JVM)
- JVM interacts with the Operating System and Hardware
1. JVM (Java Virtual Machine)
The JVM is the core component of Java architecture. It is responsible for executing Java bytecode.
Key Responsibilities of JVM
- Loads class files
- Verifies bytecode for security
- Executes bytecode
- Manages memory
- Handles garbage collection
JVM Internal Components
a) Class Loader Subsystem
- Loads .class files into memory
- Ensures classes are loaded only once
- Follows delegation hierarchy:
- Bootstrap Class Loader
- Extension Class Loader
- Application Class Loader
Why it matters:
Prevents duplicate class loading and improves security.
b) Bytecode Verifier
- Verifies bytecode before execution
- Ensures:
- No illegal memory access
- No stack overflow risks
- Code follows Java rules
Why it matters:
Protects the system from malicious or corrupted code.
c) Runtime Data Areas (Memory)
- Method Area – Class metadata, static variables
- Heap – Objects and instance variables
- Stack – Method calls and local variables
- Program Counter (PC) Register – Current instruction
- Native Method Stack – Native (non-Java) code
Why it matters:
Helps understand OutOfMemoryError, StackOverflowError, and performance issues.
d) Execution Engine
- Interprets bytecode line by line
- Uses JIT (Just-In-Time) Compiler for optimization
- Converts frequently used bytecode into native machine code
Why it matters:
Improves runtime performance.
JVM Key Point
- JVM is platform dependent
- Each OS has its own JVM implementation
2. JRE (Java Runtime Environment)
The JRE provides the environment required to run Java applications.
JRE Includes
- JVM
- Core Java class libraries (java.lang, java.util, etc.)
- Supporting runtime files
What JRE Can Do
- Run Java applications
- Execute bytecode
What JRE Cannot Do
- Compile Java source code
Why it matters:
End users only need JRE to run Java programs.
3. JDK (Java Development Kit)
The JDK is used by developers to build Java applications.
JDK Includes
- JRE
- Java compiler (javac)
- Development tools:
- javac – compiler
- java – launcher
- javadoc – documentation tool
- jar – packaging tool
- jdb – debugger
Why it matters:
Without JDK, you cannot develop or compile Java programs.
Relationship Between JVM, JRE, and JDK
JDK
└── JRE
└── JVM
- JVM → Executes bytecode
- JRE → Runs Java programs
- JDK → Develops Java programs
Comparison Table
| Component | Purpose | Contains | Used By |
|---|---|---|---|
| JVM | Executes bytecode | Execution engine & memory | System |
| JRE | Runs Java apps | JVM + libraries | End users |
| JDK | Develops Java apps | JRE + tools | Developers |
Real-Time Example
- Developer machine → JDK installed
- QA / Production server → JRE installed
- JVM runs the application on each environment
Example:
- Writing Selenium automation → JDK required
- Running tests on CI server → JRE sufficient
Common Mistakes by Beginners
- Thinking JVM = JRE
- Believing JRE can compile code
- Assuming JVM is platform independent
- Ignoring memory areas during debugging
Interview-Ready Answers
Short answer:
JVM executes Java bytecode, JRE provides the runtime environment, and JDK provides tools to develop Java applications.
Detailed answer:
Java architecture consists of JVM, JRE, and JDK. JVM executes bytecode and manages memory, JRE includes JVM and libraries to run applications, and JDK includes JRE plus development tools like compiler and debugger to build Java programs.
Key Takeaway
Java’s platform independence is achieved by compiling code into bytecode and executing it on the JVM, while JRE and JDK separate runtime and development responsibilities.