What is JDK, JRE and JVM in Java - Explained with Diagrams

In this chapter, we will discuss an important definition of JVM, JRE, and JDK in the Java programming language and the difference between them.

Java technology is both a programming language and a platform. The Java programming language is a high-level object-oriented language with a particular syntax and style. A Java platform is a particular environment in which Java programming language applications run.

Let's start with what is JDK?

1. JDK(Java Development Kit)

The JDK is the cornerstone for any Java developer, providing the essential tools needed to develop Java applications and applets. It includes the JRE for running the Java applications you've developed, along with an assortment of development tools such as a compiler (javac), an archiver (jar), and a documentation generator (Javadoc), among others. The JDK allows developers to write Java programs and convert them into a format that can be executed by the JRE and JVM.

Key Features of JDK:

Compiler (javac): Transforms your Java code into bytecode.
JavaDoc: Generates documentation from code comments.
Debugger: Helps in fixing errors in your code efficiently.

The diagram below shows that the JDK (Java Development Kit) is a software development kit that contains everything in the JRE, plus tools such as the compiler, debugger, JavaDoc, keytool, etc., necessary for developing and running Java programs or applications.

2. JRE(Java Runtime Environment)

The JRE is what you need to run Java applications. It's a part of the JDK but can also be distributed separately to run Java applications. The JRE consists of the JVM, core libraries, and other components to run applications written in Java. However, it doesn't include development tools like compilers or debuggers.

What's in the JRE?

Java Virtual Machine (JVM): The engine that runs Java applications.
Core libraries: Provide essential functionalities to Java applications.
Deployment technologies: Java Web Start is used to deploy standalone applications over a network.

3. Java Virtual Machine (JVM)

The JVM is an abstract computing machine that enables a computer to run a Java program. When you run a Java application, the JVM reads the compiled bytecode (generated by the JDK) and interprets it into machine code for execution. The JVM ensures Java applications can run on any device or operating system that has a compatible JVM, embodying Java's write-once, run-anywhere principle.

JVM's Roles:

Loads code: Reads the compiled bytecode from the file system.
Verifies code: Ensures the code is properly formatted and secure to execute.
Executes code: Translates bytecode into machine language.

4. Differences Between JDK, JRE and JVM 

JDK (Java Development Kit)

Primary Purpose: It serves as a comprehensive suite for developing Java applications and applets equipped with compilers, tools, and libraries.

Components: Includes the Java Runtime Environment (JRE), a compiler (javac), tools for debugging and monitoring, libraries, and the Java Virtual Machine (JVM) for executing bytecode.

Use Case: Essential for developers writing Java code, as it provides all necessary tools for code compilation, documentation, and packaging.

Enhanced Capability: Offers tools like javadoc for generating documentation and jarsigner for signing Java Archive (JAR) files, facilitating professional Java application development.

JRE (Java Runtime Environment)

Primary Purpose: Provides the environment to run Java applications and applets on a device, encompassing necessary libraries and the JVM.

Components: This includes the JVM, core libraries, and other components needed to execute applications written in Java. It does not include development tools found in the JDK.

Use Case: Needed to run Java applications. It's essentially a package that allows a computer system to run Java programs.

Simplified Execution: Enables users to run Java applications efficiently and safely without the tools for application creation or debugging.

JVM (Java Virtual Machine)

Heart of Java: Acts as the execution engine that runs Java bytecode, making Java applications platform-independent.

Platform Independence: This feature enables Java’s "write once, run anywhere" (WORA) capability by allowing Java bytecode to be executed on any device equipped with a compatible JVM.

Execution Process: Loads code, verifies code, executes code, and provides the runtime environment. JVM's behavior is specified by the JRE or JDK it's part of.

Advanced Features: Includes Garbage Collection (GC) for memory management and Just-In-Time (JIT) compilation for performance optimization, enhancing the efficiency of Java applications.


Post a Comment

Leave Comment