☕ Java

JDK, JRE and JVM — What's the Difference?

If you've installed Java and seen 'JDK' and 'JRE' and wondered what on earth the difference is — this clears it up for good. These three aren't interchangeable, and knowing which is which will save you headaches.

The Three Layers of Java

Every time you run a Java program, three components work together: the JVM, the JRE, and (if you're a developer) the JDK. They're nested inside each other like Russian dolls. JDK ⊃ JRE ⊃ JVM Let's break each one down with a real-world analogy.

JVM — Java Virtual Machine

The JVM is the engine that actually runs your Java bytecode. It doesn't care what OS you're on — it takes the .class bytecode files and executes them. Analogy: Think of the JVM as a universal game console emulator. No matter what game (Java program) you load, the emulator knows how to run it on your specific hardware. Key things the JVM does: • Loads and verifies bytecode (security check before running) • Executes instructions • Manages memory — allocates it when you create objects, cleans it up when you're done (Garbage Collection) • The JVM is platform-specific — there's a different JVM for Windows, Mac, and Linux, but they all run the same bytecode

JRE — Java Runtime Environment

The JRE is the JVM + the standard Java class libraries. When you just want to run a Java application (not develop it), you install the JRE. Those libraries (java.lang, java.util, java.io, etc.) are pre-built utilities that come with Java — things like string manipulation, data structures, date/time handling, and more. Analogy: The JRE is like a smartphone with all system apps pre-installed. You can run apps, but you can't build new ones without developer tools.

JDK — Java Development Kit

The JDK is the full package for developers. It includes the JRE (so you can run Java too) plus the tools you need to write and compile Java code: • javac — the Java compiler (converts .java → .class bytecode) • java — the launcher to run your compiled programs • javadoc — generates documentation from your code comments • jar — bundles your .class files into a single distributable .jar file • jdb — a command-line debugger Rule of thumb: If you're learning or building Java — install the JDK. If you're just deploying an already-compiled Java app on a server — the JRE is enough (though many setups just install the JDK everywhere to keep it simple).