JDK vs JRE vs JVM: How Java Code Runs
Codevity Admin · 10/25/2026
Step 2 of 38 · Java Interview Preparation for Beginners · Stage 1: Roadmap and language fundamentals
Codevity Admin · 10/25/2026
"Why is Java platform-independent?" is very often the first Java interview question, and "What is the difference between the JDK, JRE and JVM?" is usually the second. This article gives you precise answers to both.
Java is a high-level, class-based, object-oriented language. It is platform independent because of its "write once, run anywhere" design: the compiler (javac) does not produce machine code for one specific operating system. It produces bytecode in .class files, and any machine with a Java Virtual Machine (JVM) can run that bytecode.
So: Java (the language and its bytecode) is platform independent. The JVM is platform dependent, because each operating system and CPU needs its own JVM build.
Hello.java --(javac)--> Hello.class --(JVM on Windows, Linux or macOS)--> machine code
(source) (bytecode) class loader, verifier, interpreter + JITjavac Hello.java turns source code into bytecode (Hello.class).javac Hello.java # compile: produces Hello.class
java Hello # run the compiled class
java Hello.java # shortcut since Java 11: compile in memory and run a single source file
javap -c Hello # disassemble the bytecode to see what javac produced| What it is | Contains | |
|---|---|---|
| JVM (Java Virtual Machine) | The engine that executes bytecode | Class loader, bytecode verifier, interpreter, JIT compiler, garbage collector |
| JRE (Java Runtime Environment) | Everything needed to run Java programs | The JVM plus the standard class libraries (java.lang, java.util, and so on) |
| JDK (Java Development Kit) | Everything needed to develop Java programs | The JRE plus the tools: javac, java, jar, javadoc, jshell, javap and more |
A simple way to remember it: JDK contains JRE, and JRE contains JVM.
In practice you install a JDK. Oracle stopped publishing a separate JRE from Java 11 (some vendors still offer JRE packages), and the jlink tool can build a small custom runtime containing only the modules your application needs. "JVM" is a specification with several implementations: HotSpot is the default, and OpenJ9 and GraalVM are alternatives.
The same compiled class prints different operating-system and JVM lines on different machines, while your code never changed.
Every part of that signature has a reason:
Java 25 relaxes this for beginners (instance methods and compact source files), but interviews still use the classic form.
Java releases a new version every six months, and some are marked LTS (long-term support) because companies stay on them for years. The LTS versions are 8, 11, 17, 21 and 25. Java 8 introduced lambdas and streams, and many codebases still run on it. Records arrived in Java 16 and sealed classes in Java 17, Java 21 made virtual threads final, and Java 25 is the newest LTS. The examples in this collection are written for Java 21 and run on later versions.
publicstaticvoidString[] argsmainintcharboolean.classjavacjavap -cpublic class RuntimeInfo {
public static void main(String[] args) {
System.out.println("Language: Java");
System.out.println("Specification version: " + System.getProperty("java.specification.version"));
System.out.println("Operating system: " + System.getProperty("os.name"));
System.out.println("JVM: " + System.getProperty("java.vm.name"));
}
}public class Hello {
public static void main(String[] args) {
System.out.println("Hello, JVM"); // Hello, JVM
}
}