JDK JRE and JVM

Before we discuss about the differences between JDK, JRE, and JVM, let's understand the relationship between JDK, JRE and JVM with the hell of below mentioned diagram

JRE JRE and JVM Difference

Java, a versatile and widely-used programming language, relies on three key components to execute code: the Java Development Kit (JDK), the Java Runtime Environment (JRE), and the Java Virtual Machine (JVM). In this tutorial, we'll explore the roles of these components, their relationships, and how they work together to enable the execution of Java applications.


JVM

Java Virtual Machine is a program that runs pre compiled Java programs, which mean JVM converts each bytecode(.class files) instruction into the machine language instruction that can be executed by the microprocessor.

First, .java source files are compiled into .class files by the javac compiler. This .class file is given to the JVM which has Class Loader Sub System to perform the following instructions:

  • Load the .class file into memory
  • Verify the bytecode. Any suspicious execution is rejected.
  • Executes the bytecode.

It also provides some additional features like memory management, garbage collection, fatal error reporting.

JVM makes Java platform-independent. Because of the JVM, a .class file can be executed in multiple platforms without any platform specific changes. Different platforms have their our JVM's which provides abstraction over platform specific implementation details. There are many JVM implementations developed by different organizations for different platforms.

JVM Implementations

Several vendors provide JVM implementations, each tailored for specific platforms. Notable implementations include Oracle HotSpot, OpenJ9, and GraalVM. These implementations aim to optimize performance, enhance security, and provide additional features beyond the Java standard.


JRE

Full form of JRE is Java Runtime Environment. JRE is an implementation of the JVM which actually executes Java programs. It combines the Java Virtual Machine with core classes and libraries required for running java applications.

JRE is required to execute a Java application, however it doesn't contains necessary modules for development of java applications. Remember, JRE is a superset of JVM but subset of JDK.

Components of JRE

  • JVM : As mentioned earlier, the JVM is a crucial component of the JRE, responsible for executing Java bytecode.

  • Class Libraries : JRE includes a set of class libraries, such as Java Standard Edition (SE) libraries, that provide pre-written code for common tasks. These libraries facilitate the development of Java applications by offering ready-to-use components.

  • Java Archives (JARs) : JRE includes Java Archive files that bundle class files, resources, and metadata into a single file, simplifying the distribution and deployment of Java applications.

JRE Installation

To run a Java application on a system, you need to install the appropriate JRE version. Installation typically involves downloading the JRE distribution from the official Java website or using package managers on some operating systems. Once installed, the JRE provides the necessary runtime environment for Java applications.


JDK

The full form of JDK is Java Development Kit. JDK is a set of java modules required for development and execution of a java application. The JDK provides us with the JAVAC compiler to compile java programs. We require the JDK to convert our source code into a specific format that can be easily executed by the Java Runtime Environment(JRE).

JDK includes the JRE(to execute your java program), Java development tools like compiler, jheap , javadoc etc. JDK is a superset of JRE.

Key Components of JDK

  • JRE :The JDK includes a complete JRE, ensuring that developers have the necessary runtime environment for testing and debugging their applications.

  • Compiler (javac) : The JDK includes the Java compiler, javac, which translates Java source code into bytecode. This step is crucial for converting human-readable code into a format that the JVM can execute.

  • Debugger (jdb) : JDK provides a debugger, jdb, that allows developers to inspect and troubleshoot their code during runtime.

  • JavaDoc : JDK includes the JavaDoc tool for generating documentation from Java source code comments. This documentation is crucial for maintaining code readability and providing insights for other developers.

Setting Up JDK

To develop Java applications, you need to install the JDK on your development machine. The installation process involves downloading the JDK distribution from the official Java website and configuring the system environment variables to point to the JDK installation directory. This setup ensures that development tools are readily available from the command line.


Conclusion: Choosing the Right Components for the Job

In summary, the Java ecosystem relies on the symbiotic relationship between the Java Virtual Machine (JVM), the Java Runtime Environment (JRE), and the Java Development Kit (JDK). The JVM provides the runtime execution environment, the JRE extends it with libraries and essential tools, and the JDK equips developers with everything needed for Java application development.

Whether you are a developer crafting code, a system administrator ensuring proper runtime environments, or an end-user running Java applications, understanding the roles of JVM, JRE, and JDK is fundamental to navigating the world of Java programming. With this knowledge, you can make informed decisions about Java installations, troubleshoot issues effectively, and appreciate the seamless cross-platform capabilities that Java offers.