Java Architecture
Java Architecture defines how the Java programming language works internally — from writing code to running it on any device.
It explains how Java achieves its famous feature:
“Write Once, Run Anywhere” (WORA)
2. Main Components of Java Architecture
Java Architecture mainly consists of three key parts:
A. Java Virtual Machine (JVM)
- JVM is the engine that runs Java programs.
- It converts bytecode (intermediate code) into machine code for the current operating system.
- It makes Java platform-independent.
Functions of JVM:
- Loads code
- Verifies code
- Executes code
- Manages memory (Garbage Collection)
B. Java Runtime Environment (JRE)
- JRE = JVM + Libraries + Other components to run applications.
- It provides all the necessary runtime environments for Java programs.
Think of JRE as:
The setup needed to run a Java program (but not to develop one).
C. Java Development Kit (JDK)
- JDK = JRE + Development tools.
- It’s used by developers to write, compile, and run Java programs.
Includes:
- Compiler (
javac) - Debugger
- JavaDoc tool
- JRE
Think of JDK as:
The complete toolkit for Java developers.
3. Flow of Execution in Java
Here’s how a Java program runs step-by-step:
-
You write code →
MyProgram.java -
Compiler (
javac) → converts code to Bytecode →MyProgram.class -
Classloader → loads
.classfiles into JVM - Bytecode Verifier → checks code safety
- JIT Compiler (Just-In-Time) → converts bytecode to native machine code
- JVM executes the program
4. Diagram: Java Architecture
┌──────────────────────────────┐
│ Java Application │
└──────────────┬───────────────┘
│
(1) Compiled by javac
│
┌──────────────▼───────────────┐
│ Bytecode (.class) │
└──────────────┬───────────────┘
│
(2) Loaded by Classloader
│
┌──────────────▼───────────────┐
│ JVM │
│ ┌────────────────────────┐ │
│ │ Class Loader Subsystem │ │
│ │ Bytecode Verifier │ │
│ │ Interpreter/JIT │ │
│ │ Garbage Collector │ │
│ └────────────────────────┘ │
└──────────────┬───────────────┘
│
(3) Machine Code Executed