By WebNest Studio Engineering Team
Java - Core Tutorial
JVM, JDK, and JRE
JVM, JDK, and JRE are three terms every Java developer must be able to explain clearly, because they describe three different layers of the Java platform. Confusing them is one of the most common mistakes among beginners.
Why it matters
These three terms decide what you install and what breaks when it is missing. A server that only runs your application needs a runtime; your laptop needs the full development kit; and performance tuning, memory errors and garbage collection all happen inside the JVM. Mixing them up is one of the fastest ways to lose credibility in an interview.
Watch: JVM, JDK and JRE Explained
A quick video on the difference between the JVM, JRE and JDK and how they fit together.
JVM — Java Virtual Machine
The JVM is an abstract machine that provides a runtime environment to execute Java bytecode (.class files). It is not a physical machine; it is a specification implemented differently on each operating system. The JVM is responsible for loading class files, verifying bytecode for safety, executing instructions, managing memory through automatic garbage collection, and providing runtime data areas like the heap and stack. Because every platform has its own JVM implementation that understands the same bytecode format, a compiled Java program becomes portable.
JRE — Java Runtime Environment
The JRE is the JVM plus the core class libraries (java.lang, java.util, java.io, and so on) needed to run Java applications. If you only need to run a Java program — not develop one — the JRE is technically sufficient. Think of the JRE as "JVM + libraries needed at runtime."
JDK — Java Development Kit
The JDK is the full development kit: it includes the JRE plus development tools such as the compiler (javac), the debugger, javadoc for documentation generation, and other utilities like jar and jshell. To write and compile Java code, you need the JDK, not just the JRE.
How They Relate
JDK contains JRE, and JRE contains JVM. This is a strict containment relationship: JDK ⊇ JRE ⊇ JVM. When you install "Java" for development today, you install a JDK (for example, JDK 21), and that single installation gives you the compiler, the runtime, and the JVM together.
- JVM: Executes bytecode. Platform-specific implementation, platform-independent bytecode format.
- JRE: JVM + standard class libraries. Enough to run compiled Java programs.
- JDK: JRE + compiler and developer tools. Needed to write and build Java programs.
Example
Compiling and running a program shows the JDK and JVM working together
// Step 1: Compile with the JDK's compiler (javac)
// Terminal: javac HelloJava.java
// This produces HelloJava.class (bytecode)
// Step 2: Run with the JVM (via the "java" launcher, included in JRE/JDK)
// Terminal: java HelloJava
public class HelloJava {
public static void main(String[] args) {
System.out.println("Compiled by JDK, executed by JVM");
}
}
Compiled by JDK, executed by JVM
Common Mistakes
- Installing only a JRE and then being unable to compile code with javac — the JRE has no compiler.
- Saying "JVM and JDK are the same thing" in interviews — the JDK is a full toolkit; the JVM is just the execution engine inside it.
- Forgetting that the JVM specification allows multiple different implementations (HotSpot, OpenJ9, GraalVM) — "the JVM" is not one single piece of software.
Exercise
Ask the running JVM to describe itself. Complete the program so it prints the Java version, the name of the JVM implementation, and the folder Java is installed in.
The output depends on your installation, for example a version such as 21.0.2 and a VM name such as OpenJDK 64-Bit Server VM.
public class RuntimeInfo {
public static void main(String[] args) {
// TODO: print these three system properties, one per line:
// java.version, java.vm.name, java.home
}
}
Show hints
- All three values come from
System.getProperty(key). - The VM name tells you which JVM implementation you are running, such as HotSpot or OpenJ9.
Show solution
public class RuntimeInfo {
public static void main(String[] args) {
System.out.println("Version: " + System.getProperty("java.version"));
System.out.println("VM: " + System.getProperty("java.vm.name"));
System.out.println("Home: " + System.getProperty("java.home"));
}
}
Quick quiz
1. You need to compile Java source code. Which one must be installed?
- A. JVM only
- B. JDK
- C. JRE
- D. Any web browser
Show answer
B. Only the JDK includes the compiler (javac) and other development tools.
2. Which component actually executes bytecode?
- A. JDK
- B. javac
- C. JVM
- D. jar
Show answer
C. The JVM loads .class files and executes their bytecode, interpreting it and compiling hot code to native instructions.
3. What does the JRE consist of?
- A. The compiler and the debugger
- B. The JDK plus an IDE
- C. Only the class libraries
- D. The JVM plus the core class libraries
Show answer
D. JRE = JVM + the standard class libraries needed to run programs. It has no compiler.
Interview questions
What is the JIT compiler and where does it live?
Show answer
The Just-In-Time compiler is part of the JVM. The JVM starts by interpreting bytecode, tracks which methods run often ("hot" code), and compiles those to native machine code while the program is running. This is why long-running Java programs speed up after a warm-up period.
Is there still a separate JRE to download?
Show answer
For current versions, generally no. Since Java 11, Oracle and most OpenJDK distributions ship the JDK as the standard download rather than a separate JRE. For deployment you can either install a JDK or use jlink to build a small custom runtime containing only the modules your application needs. The concepts JVM, JRE and JDK still describe the same three layers.
Key Points to Remember
- JVM executes bytecode and provides platform independence.
- JRE = JVM + standard libraries, enough to run programs.
- JDK = JRE + compiler and development tools, needed to build programs.
- Containment relationship: JDK contains JRE, JRE contains JVM.
Practice in the playground
Write and run your own code for this topic, or start from the exercise or an example. Runs plain Java 17. Frameworks such as Spring, and databases, are not available here. Your code for each topic is kept in this browser.
Run the examples
Change an input, predict the result, then compare it with the output. Explain why the result changes.
Written by
WebNest Studio Engineering Team
Practical lessons from developers working with Java, Python, React, databases and production systems.
Led by Vansh Duggal, Founder, WebNest Studio · Full-stack & software engineering