Cosmic Module

J

Qubits of DPK

March 14, 2026

Core Java

Layman Explanation

You wrote a letter in English. A translator converts it to a universal language. Then a local interpreter in each country converts it to native. JDK = tools to write. JRE = translation environment. JVM = actual translator.

Real World Analogy

JDK = full kitchen (tools + dining area + stove). JRE = dining area (where food is served). JVM = the stove (actual cooking). Chef (developer) needs kitchen. Guest (user) needs dining area only.

The Nesting Structure

javascript
QUBITS OF DPK
1┌─────────────────────────────────────────────┐
2JDK3│  ┌────────────────────────────────────┐  │
4│  │             JRE                    │  │
5│  │  ┌──────────────────────────┐  │  │
6│  │  │          JVM              │  │  │
7│  │  └──────────────────────────┘  │  │
8│  │  + Java Class Libraries           │  │
9│  └────────────────────────────────────┘  │
10+ javac, jar, jdb, javadoc           │
11└─────────────────────────────────────────────┘

JVM Internal Architecture

javascript
QUBITS OF DPK
1JVM
23├── Class Loader          → loads .class files
4├── Memory Areas
5│   ├── Method Areaclass structure, static variables
6│   ├── Heap                → objects, instance variables
7│   ├── Stack               → method calls, local variables
8│   ├── PC Register         → current instruction
9│   └── Native Stack        → native method calls
1011└── Execution Engine
12    ├── Interpreter         → reads bytecode line by line
13    ├── JIT Compiler        → compiles hot code to machine code
14    └── Garbage Collector   → cleans unused heap objects

Write Once Run Anywhere

javascript
QUBITS OF DPK
1JVM is platform DEPENDENT (different per OS)
2Bytecode is platform INDEPENDENT (same .class everywhere)
3
4Windows JVM5Linux JVM    ├─── all run the SAME .class bytecode
6Mac JVM

️ Interview Traps

javascript
QUBITS OF DPK
1Trap 1: JVM is platform DEPENDENT (not independent)
2Trap 2: JDK includes JRE includes JVM (nested)
3Trap 3: .java = source, .class = bytecode (JVM runs .class)
4Trap 4: JIT is INSIDE JVM, not a separate tool
5Trap 5: JRE enough to RUN, JDK needed to DEVELOP

Interview Answer (SDE-2)

"JVM is the Java Virtual Machine — takes bytecode and translates to platform-specific machine code using interpreter and JIT compiler, with GC managing heap. JRE is the runtime environment containing JVM plus Java's built-in class libraries. JDK is the development kit containing JRE plus tools like javac compiler, debugger, and jar. JVM itself is platform dependent — each OS has its own JVM — but bytecode is platform independent, enabling Write Once Run Anywhere."

Interview Questions & MAANG-Level Answers

Q1. What is the difference between JDK, JRE, and JVM?
JVM (Java Virtual Machine) is the engine that executes bytecode — it contains the Class Loader, Execution Engine (Interpreter + JIT), and GC. JRE (Java Runtime Environment) = JVM + Java class libraries — everything needed to RUN Java programs. JDK (Java Development Kit) = JRE + development tools (javac compiler, jdb debugger, jar tool) — everything needed to DEVELOP Java programs. They are nested: JVM inside JRE inside JDK.
Q2. Is JVM platform dependent or independent? Why?
JVM is platform dependent. Each OS (Windows, Linux, Mac) has a different JVM implementation that knows how to translate bytecode into that OS's native machine code. However, bytecode is platform independent — the same .class file can run on any OS as long as it has a JVM. This distinction is critical: WORA (Write Once Run Anywhere) works because bytecode is universal, even though each JVM is OS-specific.
Q3. What does JIT compiler do?
JIT (Just-In-Time) compiler is inside the JVM's Execution Engine. Initially, the Interpreter runs bytecode line by line (slow). JIT monitors execution and detects "hot code" — methods called frequently. It compiles those hot methods to native machine code and caches them. Next invocation uses the native code directly — much faster. This is why Java server applications get faster over time (warmup period) and eventually perform near C++ speeds.
Q4. Who needs JRE vs who needs JDK?
End users who only run Java applications (e.g., running a banking desktop app) need only JRE. Developers who write and compile Java code need JDK (which includes JRE). In modern production, Docker images for Java apps typically use JRE-based images to minimize size. CI/CD pipelines that compile code use JDK images.
Q5. What is bytecode and why is it special?
Bytecode is the compiled output of Java source code — stored in .class files. It's special because it's a universal intermediate language: not tied to any CPU or OS, runs on any JVM. It enables the JVM ecosystem (Kotlin, Scala, Groovy all compile to bytecode), allows JIT optimization at runtime, and enables tools like code analysis and instrumentation (Spring AOP, Hibernate use bytecode manipulation).