JDK, JRE, and JVM


It is very important to understand what JDK, JRE, and JVM are in Java.
In this chapter, we will have a brief discussion about these terms.

There are two principal products in the Java SE platform family:
Java SE Runtime Environment (JRE)
Java Development Kit (JDK)


Java Development Kit (JDK)

prowessapps.com
  • Java Development Kit (JDK) provides the environment to develop and execute (run) Java programs.

  • JDK contains two parts:

    1. Utilities like javac, debugger, jar — used to compile source code (.java files) into bytecode (.class files) and debug programs.

    2. The JRE, which contains utilities like java to run/execute the bytecode.

  • You need JDK if you want to write and compile your own programs. For only running Java programs, JRE is sufficient.

Java Runtime Environment (JRE)

  • The Java Runtime Environment (JRE) provides the libraries, the Java Virtual Machine (JVM), and other components to run (not develop) Java applets and applications.

prowessapps.com

Java Virtual Machine (JVM)

  • A Java Virtual Machine (JVM) is an abstract computing machine that enables a computer to run a Java program.

  • JVMs are available for many hardware and software platforms (i.e., JVM is platform-dependent).

  • prowessapps.com

  • JVM (Java Virtual Machine) is software — a specification that provides the runtime environment to execute Java bytecode. It does not physically exist.

    There are three notions of the JVM:

    1. Specification: A formal document describing what is required of a JVM implementation. Ensures all implementations are interoperable.

    2. Implementation: A computer program that meets the JVM specification.

    3. Instance: A running implementation in a process that executes Java bytecode.


Working of JVM

As shown in the JVM architecture diagram, JVM is divided into three main subsystems:

1. Class Loader Subsystem

2. Runtime Data Area

3. Execution Engine


1. Class Loader Subsystem

The Class Loader loads class files and performs three basic activities in strict order:

1.1. Loading: Finds and imports the binary data for a type.

1.2. Linking: Performs verification, preparation, and (optionally) resolution.

  • Verification: Ensures correctness of the imported type.
  • Preparation: Allocates memory for class variables and initializes them with default values.
  • Resolution: Transforms symbolic references into direct references.

1.3. Initialization: Invokes Java code to initialize class variables to their proper starting values.

There are two types of class loaders: bootstrap class loader and user-defined class loader. Every JVM must have a bootstrap class loader for trusted classes.


2. Runtime Data Area

The Runtime Data Area is divided into 5 major components:

2.1 Method Area – Stores class-level data (including static variables). Shared across JVM, one per JVM.

2.2 Heap Area – Stores objects, instance variables, and arrays. One per JVM. Not thread-safe since it’s shared.

2.3 Stack Area – Each thread gets its own runtime stack. Each method call creates a stack frame containing local variables.

  1. 2.3.1 Local Variable Array: Stores method’s local variables.
  2. 2.3.2 Operand Stack: Workspace for intermediate operations.
  3. 2.3.3 Frame Data: Stores method symbols and exception handling info.

2.4 PC Registers: Each thread has its own PC register holding the address of the current instruction.

2.5 Native Method Stacks: Each thread gets its own stack for native method information.


3. Execution Engine

The Execution Engine executes bytecode assigned to the Runtime Data Area. It contains:

1. A Virtual Processor

2. Interpreter: Reads and executes bytecode instructions.

3. JIT Compiler: Improves performance by compiling frequently used bytecode into native code for faster execution.


Next: Try Online Compiler




🚀 Quick Knowledge Check

Topic: Jdk_jre_jvm | Language: Java

Q1. Which of the following correctly shows the sequence of operations in the Class Loader subsystem?
Q2. Which component is required if you only want to run Java programs, not develop them?
Q3. Looking at the Execution Engine in the diagram, which component executes bytecode one instruction at a time?
Q4. In the Runtime Data Area section of the diagram, which memory area stores static variables and class-level data?
Q5. Which runtime data area stores objects, instance variables, and arrays?
Q6. According to the diagram, which part of the Runtime Data Area is unique for each thread?
Q7. In the JVM architecture diagram, which subsystem is responsible for loading, verifying, and preparing class files?
Q8. Which of the following is included in the JDK but not in the JRE?
Q9. In the JVM architecture diagram, which stack contains native method information?
Q10. Which of the following is NOT a subsystem of the JVM?
Q11. The JVM is considered as:
Q12. In the JVM diagram, which area is shared across the JVM and holds objects and arrays?
Q13. Which component of the JVM improves performance by compiling frequently used bytecode into native code?
Q14. In the Class Loader subsystem, which step ensures correctness of the imported type?
Q15. In the Execution Engine, which component improves performance by converting frequently used bytecode into native code?
Q16. Which part of the Runtime Data Area is unique to each thread?