Topic 2. JVM, JDK, JRE

This topic is not about memorizing abbreviations. It is about practical execution flow: install Java correctly, compile code, run code, and quickly diagnose environment issues.

Why JVM, JRE, and JDK are different layers

Java has three execution layers, each with a different responsibility:

  1. JVM executes bytecode (.class) and controls runtime execution.
  2. JRE provides runtime components: JVM + standard libraries required to run applications.
  3. JDK provides development tools: compiler, diagnostics, packaging, and debugging utilities.

Practical rule:

  • If you write and compile Java, you need JDK.
  • If you only run an already built app, you need runtime components.
  • In modern Java setups, teams usually install JDK everywhere for consistency.

What the JVM does in practice

When you run java App, JVM:

  1. loads classes (ClassLoader),
  2. verifies bytecode,
  3. allocates and manages memory,
  4. interprets and JIT-optimizes hot code paths,
  5. bridges Java code with OS-level resources.

This is why the same bytecode can run across different operating systems.

What JRE provides

JRE answers: “What is required to run this app reliably at runtime?” It includes:

  • JVM,
  • core Java libraries (java.lang, java.util, java.io, etc.),
  • runtime support components.

Without correct runtime components, even valid code may fail to launch.

What JDK provides

JDK is for development workflows. Typical tools:

  • javac compiles .java into .class,
  • java launches the app,
  • javadoc generates API docs,
  • jdb, jcmd, jstack, jmap help debug and diagnose runtime behavior.

Layer relationship:

  • JDK includes runtime components.
  • Runtime components include JVM.

JDK JRE JVM

Minimal build-run cycle (beginner flow)

Step 1. Create the file

public class App {
    public static void main(String[] args) {
        System.out.println("Runtime via JVM");
    }
}

Step 2. Compile

javac App.java

Compiler from JDK produces App.class.

Step 3. Run

java App

JVM loads bytecode and executes main.

Step 4. Check environment if it fails

java -version
javac -version
echo $JAVA_HOME
which java
which javac

Common failure patterns

  1. java and javac show different major versions. Cause: mixed binaries in PATH.

  2. JAVA_HOME points to an old installation. Cause: environment variables were not updated.

  3. App is built on Java 21 but runs on Java 17. Cause: inconsistent versions between local, CI, and production.

Team rule: lock one target Java version and enforce it across local dev, CI, and runtime.

Key takeaway

  • JDK is the developer toolkit.
  • JVM executes application code.
  • Most Java startup/build issues are environment consistency problems, not business logic bugs.
Glossary
bytecode
Platform-independent compiled code that the JVM can execute.
class
A blueprint that defines fields and methods for objects in object-oriented programming.
object
A runtime instance of a class with its own state and behavior.
method
A named block of behavior that belongs to a class or object and can be called by code.
field
A variable stored inside a class or object that represents part of its state.
constructor
A special method-like block used to create and initialize a new object.
package
A namespace that groups related Java classes and helps organize code.
interface
A contract that defines methods a class can implement without prescribing all internal details.
generics
A language feature that lets code work with types as parameters while preserving type safety.
type erasure
The Java compiler process that removes most generic type details from runtime bytecode.
collection
A data structure that stores a group of elements and provides operations over them.
list
An ordered collection where elements have positions and duplicates are allowed.
set
A collection that stores unique elements and is commonly used for membership checks.
map
A key-value data structure where each key points to a value.
queue
A collection designed for processing elements in a defined order, often first-in-first-out.
lambda
A compact function-like expression used to pass behavior as data.
functional interface
An interface with one abstract method, suitable for lambdas and method references.
stream
A Java API for processing data sequences with operations such as map, filter, and reduce.
optional
A container object that represents a value that may or may not be present.
thread
An independent path of execution inside a running program.
synchronization
Coordination that protects shared data when multiple threads access it.
heap
The runtime memory area where Java objects are allocated.
stack
The runtime memory area that stores method calls, local variables, and call frames.
garbage collector
A JVM component that automatically frees memory occupied by objects no longer reachable.
memory leak
A situation where memory remains occupied because objects are still referenced but no longer useful.