Java Fundamentals

JVM, JRE & JDK

Prepared By Krishna Srikanth M

1. JRE — Java Runtime Environment

JRE contains the Java Virtual Machine, class libraries, and other supporting files. It does not contain development tools such as a compiler or debugger.

The JVM runs the program and uses the class libraries and other supporting files provided in the JRE. If you want to run a Java program, the source states that JRE needs to be installed in the system.

JRE = JVM + Class Libraries + Other Supporting Files
JRE provides the environment required to run Java applications, but does not provide development tools such as the compiler and debugger.
JDK and JRE diagram from page 1

2. JVM — Java Virtual Machine

Java Virtual Machine is described in the source as a platform-independent execution environment that converts Java bytecode into machine language and executes it.

  • Bytecode is the compiled format for a Java program.
  • The JVM interprets bytecode into machine code depending on the underlying operating system and hardware combination.
  • The source states that the JVM is responsible for things such as garbage collection and array-bounds checking.

To Summarise JVM

The JVM is the virtual machine that runs on the actual computer and executes Java bytecode. It does not understand Java source code directly. The javac compiler compiles *.java files to *.class files containing bytecode understood by the JVM.

Write Once, Run Anywhere: The source explains that each operating system has a different JVM, but the output produced after execution of the bytecode is the same across operating systems.
JVM, JRE and JDK diagram with JVM explanation from page 1

3. JIT Compilation

JIT (Just-In-Time) Compilation allows faster execution by compiling bytecode into native machine code on the fly. The source states that JIT comes along with the JVM.

JIT in Simple Terms

Java bytecode is executed by the JVM, and JIT can compile bytecode into native machine code during execution to improve execution speed.

4. Java Source Code

Java Source Code is the code that you write in the Java programming language.

Java Source Code
      |
      v
   Compiler
      |
      v
 Java Bytecode
    (*.class)
      |
      v
      JVM
      |
      v
Program Execution

5. Java Compiler

The Java Compiler converts Java source code into bytecode.

Typical Flow

Example.java
    |
    | javac
    v
Example.class
    |
    | JVM
    v
Execution

6. Java

The source describes Java execution as follows:

Java: With the help of the JVM, Java bytecode is run.

7. Java Decompiler

A Java Decompiler takes class files as input and produces Java source code.

Java .class file
      |
      | Java Decompiler
      v
Java Source Code

8. JAR File

A JAR file is described as a collection of class files.

The source states that a JAR should contain a file called manifest.mf, which tells the JVM which class file contains the main method.

JAR = collection of class files
The manifest.mf file provides information used to identify the main class.
JDK JRE JVM comparison table page 2

9. Important Differences Between JDK, JRE and JVM

Sr. No. Key JDK JRE JVM
1 Definition JDK (Java Development Kit) is a software development kit to develop applications in Java. In addition to JRE, it contains development tools such as compilers, JavaDoc and Java Debugger. JRE (Java Runtime Environment) is described as the implementation of JVM and a software package providing Java class libraries, JVM and other components needed to run Java applications. JVM (Java Virtual Machine) is an abstract machine. The source describes its specification, implementation and instance, with the instance executing Java bytecode and providing the runtime environment.
2 Prime functionality Primarily used for code execution and has the prime functionality of development. Majorly responsible for creating the environment for code execution. Specifies implementations and is responsible for providing these implementations to JRE.
3 Platform Independence Platform dependent; different platforms require different JDKs. Also described as platform dependent. Platform independent.
4 Tools Contains tools for developing, debugging and monitoring Java applications. Does not contain tools such as compiler or debugger; it contains class libraries and supporting files required by the JVM. Does not include software development tools.
5 Implementation JDK = JRE + Development tools JRE = JVM + Libraries to run the application JVM = Runtime environment for executing Java bytecode
JDK JRE JVM comparison table page 3

Quick Relationship

JDK
├── JRE
│   ├── JVM
│   └── Libraries + Supporting Files
└── Development Tools
    ├── Compiler
    ├── Debugger
    └── Other Development Tools

Quick Revision

TermMain Role
JDKDevelopment kit containing JRE plus development tools.
JRERuntime environment containing JVM, libraries and supporting files.
JVMExecutes Java bytecode.
JITCompiles bytecode into native machine code on the fly for faster execution.
Java CompilerConverts Java source code into bytecode.
Java DecompilerTakes class files and produces Java source code.
JARCollection of class files, with a manifest file used to identify the main class.