JVM.Basics.The Relationship Between JDK, JRE, and JVM

1. Java Virtual Machine (JVM)

  • The JVM is the core component responsible for executing Java bytecode.
  • It provides features like:
    • Bytecode interpretation & execution
    • Just-In-Time (JIT) Compilation for performance optimization
    • Garbage Collection (GC)
    • Security (sandboxing and bytecode verification)
  • The JVM is platform-dependent, meaning each operating system has its own implementation of the JVM (e.g., Windows JVM, Linux JVM).

JVM alone cannot run Java applications—it needs libraries and other components from JRE.


2. Java Runtime Environment (JRE)

  • The JRE is a package that contains everything needed to run Java applications.
  • It includes:
    • The JVM (to execute bytecode)
    • Core Java libraries (e.g., java.lang, java.util, java.io)
    • Runtime tools (e.g., java command to run applications)
  • The JRE does not include development tools like compilers or debuggers.
  • If you only need to run Java programs (not develop them), you only need the JRE.

JRE is enough to run Java applications but does not include development tools like a compiler (javac).


3. Java Development Kit (JDK)

  • The JDK is a superset of the JRE and is used for developing and running Java applications.
  • It includes:
    • The JRE (which includes the JVM)
    • Development tools such as:
      • Java Compiler (javac) – Converts Java source code into bytecode.
      • Debugger (jdb) – Helps debug Java programs.
      • Javadoc (javadoc) – Generates documentation from source code comments.
      • Other utilities like jar (for packaging applications).

How They Work Together

  1. When you develop a Java application:
    • You write Java code (.java file).
    • The JDK’s compiler (javac) compiles it into bytecode (.class file).
    • The compiled bytecode is ready to be executed.
  2. When you run a Java application:
    • The JRE’s JVM loads and executes the compiled bytecode.
    • The JVM converts bytecode into machine-specific instructions and runs the program.
This entry was posted in Без рубрики. Bookmark the permalink.