1. JVM (Java Virtual Machine)
- Definition: JVM is the engine that runs Java bytecode.
- Role: It converts compiled Java bytecode into machine code so your program can run on any device.
- Key Point: JVM is platform-dependent (different JVMs exist for Windows, Linux, Mac).
- Example: You write code once, compile it, and JVM allows it to run anywhere (“Write Once, Run Anywhere”).
2. JRE (Java Runtime Environment)
- Definition: JRE is the environment required to run Java programs.
- Components:
- JVM
- Core libraries (like
java.lang
,java.util
) - Other runtime components
- Key Point: JRE cannot compile Java code; it only runs it.
3. JDK (Java Development Kit)
- Definition: JDK is the full toolkit for developing Java applications.
- Components:
- JRE (so it can run Java programs)
- Java compiler (
javac
) - Tools like
javadoc
,jar
,jdb
- Key Point: If you want to write and compile Java programs, you need the JDK.
4. Java Compiler (javac
)
- Definition: The Java compiler converts Java source code (
.java
files) into bytecode (.class
files). - Key Point: The bytecode is what the JVM executes.
Putting it together:
- You write Java code (
.java
). - Java compiler (
javac
) compiles it →.class
(bytecode). - JVM executes the bytecode.
- JRE provides the environment needed for JVM to run the program.
- JDK includes everything you need to develop + run Java programs.
💡 Analogy:
- JVM = engine of a car
- JRE = car (engine + fuel system, etc.)
- JDK = car factory (everything you need to build & run the car)
- Compiler = assembly line that converts raw materials (source code) into parts the car (JVM) can use