Java
Module 1: Java Introduction & Environment SetupBeginner24 min read

JDK, JRE, JVM & Internal Working of Java

Master the exact differences between JDK, JRE, and JVM, plus how ClassLoader, Bytecode Verifier, Interpreter, and JIT Compiler execute your program.

Key Takeaways & Core Concepts
  • Bootstrap ClassLoader: Loads core JDK classes (java.base).
  • Platform ClassLoader: Loads standard extension modules.
  • Application ClassLoader: Loads your application classes from the classpath/modulepath.
  • Verify: Ensures bytecode does not forge pointers, overflow operand stacks, or violate access modifiers.

Introduction

Understanding how Java executes under the hood is essential for debugging classloading issues, tuning production latency, and acing technical interviews. Every Java program passes through two distinct phases: compile-time bytecode generation and JVM runtime execution.

Inspecting JVM Runtime & OS Properties
1public class Main {
2 public static void main(String[] args) {
3 System.out.println("Java Version: " + System.getProperty("java.version"));
4 System.out.println("JVM Name: " + System.getProperty("java.vm.name"));
5 System.out.println("OS Name: " + System.getProperty("os.name"));
6 System.out.println("Processors: " + Runtime.getRuntime().availableProcessors());
7 }
8}
Click code or "Edit Code" to edit
Interactive Code Block•Tab = 4 spaces•Ctrl + Enter = Run
8 lines
Note: `System.getProperty(...)` reads standard JVM runtime properties, while `Runtime.getRuntime().availableProcessors()` reports CPU cores visible to the JVM.

Learning Objectives

  • Distinguish clearly between JDK, JRE, and JVM.
  • Trace the complete lifecycle of a Java program from .java source to native CPU instructions.
  • Understand the ClassLoader subsystem (Loading, Linking, Initialization), Bytecode Verifier, and JIT Compiler.

JDK vs JRE vs JVM

ComponentFull FormContainsPurpose
JVMJava Virtual MachineClassLoader, Execution Engine, Runtime Data AreasExecutes bytecode on the host OS
JREJava Runtime EnvironmentJVM + Core Class Libraries (java.lang, java.util, java.io)Runs compiled Java applications
JDKJava Development KitJRE + Development Tools (javac, javadoc, jdb, jar, javap)Develops, compiles, packages, and debugs Java apps

Internal Working Step-by-Step

  1. 1
    Write Source: Save code in Main.java.
  2. 2
    Compile: Run javac Main.java to produce Main.class containing JVM bytecode.
  3. 3
    Class Loading: The ClassLoader locates and loads Main.class using a delegation hierarchy:
  • Bootstrap ClassLoader: Loads core JDK classes (java.base).
  • Platform ClassLoader: Loads standard extension modules.
  • Application ClassLoader: Loads your application classes from the classpath/modulepath.
  1. 4
    Linking (Verify, Prepare, Resolve):
  • Verify: Ensures bytecode does not forge pointers, overflow operand stacks, or violate access modifiers.
  • Prepare: Allocates memory for static fields and sets them to default values (0, false, null).
  • Resolve: Replaces symbolic references with direct memory references.
  1. 5
    Initialization: Executes static variable initializers and static { ... } blocks.
  2. 6
    Execution Engine:
  • Interpreter: Reads bytecode line-by-line for fast startup.
  • JIT (Just-In-Time) Compiler: Profiles "hot" methods/loops and compiles them directly into optimized native machine code (inlining, dead-code elimination, escape analysis).

Real-World Application

When a Spring Boot service starts up, the Interpreter handles initialization immediately, and within seconds the C1/C2 JIT compilers optimize your hot REST endpoints to native CPU speed.

Common Mistakes

  • Trying to compile .java files on a server that only has a JRE installed (no javac).
  • Naming a public class differently from the filename, which fails compilation immediately.

Interview Questions & FAQs

  • Q: Is the JVM platform-independent?
  • A: No! Bytecode is platform-independent, but the JVM itself is platform-dependent (Windows, Linux, and macOS each have their own native JVM binary).
  • Q: What is the `javap` tool?
  • A: javap -c Main disassembles .class files so you can inspect the exact JVM bytecode instructions generated by javac.
Practice & AssessmentJava Programming Tutorial

Test Your Understanding

Reinforce core concepts with interactive multiple-choice questions, live coding challenges, and top technical interview questions.

Your Current Score

0 / 0 correct(0 attempted)