What is JVM?
The JVM stands for (Java Vitual Machine) and it is an abstract machine that execute the java bytecode.
The main purpose of it is to provide a runtime environment for running java applications.
Java is called platform independent because of
JVM. Why?, the reason is Java comile its code in to
bytecode (.class
files), which JVM interprets and allow it to run on any device
(Write Once, Run Anywhere).
JVM also manage Memory for handling garbage collection like: heap and stack.
JVM only execute bytecode not compile or develope.
What is JRE?
The JRE stands for (Java Runtime Environment) and it is a package that provide a minimum environment for running java application. But it not developement.
This JRE includes JVM and others libraries inside like java.lang and java.util. Those are the most libraries needed in other to run java code.
When you need to run java application like (Jaba games, software), then JRE is enough for you.
The JRE also does not include
javac
compiler and debugging tools inside.
What is JDK?
The JDK stands for (Java Development Kits) is a full developement kits for building java application.
This JDK includes JRE that help to run java code.
The Development Tools like:
javac
compiler that allows you to convert
.javacode in to
.class.
The Development Tools also have:
java
for lunching the code,
javadocfor generating documentation,
jdbfor debugging and other utilities like:
jar
and
jconsole.
The JDK can be use by developer to write, conpile and debug code.
Summary Table of JVM, JRE and JDK
| Feature | JVM | JRE | JDK |
|---|---|---|---|
| Can run Java programs | ✅ | ✅ | ✅ |
| Contains JVM | ✅ | ✅ | ✅ |
| Contains libraries | ❌ | ✅ | ✅ |
| Can compile Java code | ❌ | ❌ | ✅ |
| Used by developers | ✅ (indirectly) | ❌ | ✅ |
Simple Analogy:
Just think of it like:
-
The
JDKis like a factory (it can create and test). -
The
JREis like a test environment (it can only test not create). -
The
JVMis the workers inside the factory that can actually runs the machines (execute the code).