← Back to Home

Java Architecture (JVM, JRE, JDK)

Java architecture explains how Java programs are written, compiled, and executed across different environments. The concepts of JVM, JRE, and JDK form the foundation of Java’s platform independence. Understanding this architecture is essential for real-time projects, debugging production issues, performance tuning, and answering interview questions confidently.

Java’s ability to run the same program on multiple operating systems is not magic—it is the result of this well-designed architecture.

Java architecture with JVM JRE and JDK diagram

High-Level Java Architecture Flow

The execution lifecycle of a Java program follows a structured process:

  1. A developer writes Java source code in a .java file.
  2. The Java compiler (javac) compiles the source code into bytecode (.class file).
  3. The bytecode is executed by the Java Virtual Machine (JVM).
  4. The JVM interacts with the Operating System and underlying hardware.

This separation between compilation and execution is what enables portability.

1. JVM (Java Virtual Machine)

The JVM is the core component of Java architecture. It is responsible for executing Java bytecode. Without the JVM, Java programs cannot run.

The JVM performs several critical responsibilities:

  • Loads class files into memory
  • Verifies bytecode for security
  • Executes bytecode instructions
  • Manages memory
  • Handles garbage collection

The JVM acts as an abstraction layer between Java applications and the operating system.

Internal Components of the JVM

Class Loader Subsystem

The Class Loader loads .class files into memory. It ensures classes are loaded only once and follows a delegation hierarchy:

  • Bootstrap Class Loader
  • Extension Class Loader
  • Application Class Loader

This mechanism prevents duplicate class loading and enhances security by controlling how classes are introduced into memory.

Bytecode Verifier

Before execution, bytecode is verified to ensure it is safe and valid. The verifier checks that:

  • There is no illegal memory access
  • Stack operations are valid
  • Code follows Java language rules

This protects the system from malicious or corrupted code.

Runtime Data Areas (Memory Structure)

The JVM divides memory into different runtime data areas:

  • Method Area stores class metadata and static variables.
  • Heap stores objects and instance variables.
  • Stack stores method calls and local variables.
  • Program Counter (PC) Register tracks the current instruction being executed.
  • Native Method Stack supports native (non-Java) code execution.

Understanding these areas helps diagnose issues such as OutOfMemoryError, StackOverflowError, and performance bottlenecks.

Execution Engine

The Execution Engine runs the bytecode. It includes:

  • An interpreter that executes bytecode line by line.
  • A Just-In-Time (JIT) compiler that converts frequently executed bytecode into native machine code.

The JIT compiler improves runtime performance by optimizing repeated instructions.

Important JVM Point

The JVM is platform dependent. Each operating system has its own JVM implementation. However, the bytecode remains the same across platforms. This distinction is crucial for interviews.

2. JRE (Java Runtime Environment)

The JRE provides the environment required to run Java applications.

The JRE includes:

  • The JVM
  • Core Java class libraries such as java.lang and java.util
  • Supporting runtime files

The JRE allows users to execute Java programs but does not include development tools.

The JRE can:

  • Run Java applications
  • Execute compiled bytecode

The JRE cannot:

  • Compile .java files

This means end users only need the JRE to run Java-based applications.

3. JDK (Java Development Kit)

The JDK is used by developers to build and compile Java applications.

The JDK includes:

  • The JRE
  • The Java compiler (javac)
  • Development tools such as:
  • javac – compiler
  • java – application launcher
  • javadoc – documentation generator
  • jar – packaging tool
  • jdb – debugger

Without the JDK, you cannot develop or compile Java programs.

Relationship Between JVM, JRE, and JDK

The hierarchy can be visualized as:

JDK
 └── JRE
   └── JVM
          
  • JVM executes bytecode.
  • JRE runs Java applications.
  • JDK develops Java applications.

This layered structure clearly separates development from runtime responsibilities.

Comparison Summary

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

In a real-world scenario:

  • A developer machine has the JDK installed.
  • A QA or production server may only require the JRE.
  • The JVM runs the application in each environment.

For example:

  • Writing Selenium automation requires the JDK.
  • Running automation tests on a CI server may only require the runtime environment.

This separation reduces installation overhead and improves deployment flexibility.

Common Mistakes by Beginners

  • Thinking JVM and JRE are the same
  • Believing the JRE can compile Java code
  • Assuming the JVM itself is platform independent
  • Ignoring memory areas when debugging performance issues

Understanding these distinctions is important for both interviews and real-world troubleshooting.

Interview-Ready Explanation

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. The JVM executes bytecode and manages memory. The JRE includes the JVM and required libraries to run Java applications. The JDK includes the JRE along with development tools such as the compiler and debugger to build Java programs.

Key Takeaway

Java’s platform independence is achieved by compiling source code into bytecode and executing it through the JVM. The JRE and JDK clearly separate runtime and development responsibilities, making Java scalable, portable, and suitable for enterprise environments.