Java JDK, JRE, and JVM

The Java ecosystem is engineered specifically to support the 'Write Once, Run Anywhere' (WORA) philosophy. This ensures that code developed on one platform will function seamlessly on any other without modification.


JVM vs. JRE vs. JDK

JVM — Java Virtual Machine

The JVM is the engine that executes bytecode. It takes the compiled .class files, translates the instructions into the native language of your CPU, manages memory, and enforces security. Although your Java source stays identical across platforms, the JVM itself is platform-specific (there’s one for Windows, macOS, Linux, etc.), and that translation layer is what makes Java portable.

JRE — Java Runtime Environment

The JRE packages the JVM together with the standard class libraries. It supplies everything an end user needs to run Java software. Think of it as a DVD player: it can play the movie (run your app), but it can’t create one.

JDK — Java Development Kit

The JDK contains the entire JRE plus developer tooling such as the compiler (javac), debuggers, and documentation generators. If you are writing or compiling Java code, you install the JDK; when you only need to run an existing program, the JRE is sufficient.


Step-by-Step Workflow

  1. Write the code (`.java`). You author human-readable source files such as HelloWorld.java.
  2. Compile with `javac`. Running javac HelloWorld.java produces HelloWorld.class, a bytecode file designed for the JVM, not for humans or hardware.
  3. Run with `java`. Executing java HelloWorld launches the JVM, which:
  • Uses the Class Loader to pull bytecode into memory.
  • Passes the code through the Bytecode Verifier to ensure it obeys Java’s security rules.
  • Hands the instructions to the Interpreter / JIT compiler so they become fast native machine code.

Note

Modern JVMs use a Just-In-Time (JIT) compiler. Instead of interpreting every instruction one line at a time, the JIT watches for “hot” methods (code that runs frequently) and compiles those sections into native binaries on the fly, dramatically speeding up execution.