you will learn about JVM, JRE, and JDK in Java and how they work together while we are working on any Java application.
JRE JVM and JDK In Java
JVM, JRE, and JDK are part of the java ecosystem to develop and run your Java application. In this lesson we will take a look at JRE JVM and JDK In Java. Java is a programming language and also a computing platform that was first released by the Sun Microsystems in the year 1995. It has since grown into the most used technology all over the world. It is the most sought technology for building Enterprise Applications. Java provides a reliable platform which helps in building many services, applications and end-to-end softwares.
Java is a free to download and use for personal use. It is a general-purpose, class-based, object-oriented programming language that has lesser implementation dependencies. James Gosling developed the Java Platform at Sun Microsystems. Now it is basically acquired and maintained by Oracle. Java is a feature-rich language. Following are some of the notable features:
- It is platform independent.
- It is easy to learn and implement.
- Java provides secure features which develop virus-free and secured systems.
- Java provides high-performance with the help of JIT compiler.
- They designed Java for distributed systems.
- Java is robust and supports multi-threading.
1. What is JVM?
JVM, also known as the Java Virtual Machine, is an abstract machine that provides a Runtime environment for executing the Java byte-code. It converts the Java byte-code into machine language. JVM is part of the Java Runtime Environment (JRE).
It calls the main method present in the Java code to actually run the application. Java applications are called as WORA (Write Once Run Anywhere). This means a programmer can basically write this code on any system and can expect it to run on any other system. The only prerequisite for running this code will be to install Java on that system. This is possible with the help of JVM only.
On compiling a .java
file, it generates a .class
file(containing the byte-code) with the same class name. This .class
file goes into various steps and then runs the actual application. Components of JVM are.
- Class Loaders
- Run-Time Data Areas
- Execution Engine
Here is an overview of the JVM working:
2. JRE
A JRE is a Java Runtime Environment that contains a set of components to execute a Java application. JRE is part of the JDK. JRE comprises Java Virtual Machine(JVM), Java class libraries and the Java class loader. Any software needs an environment to run the application on the Operating System(OS). JRE acts as a translator for running the program between the Java programs and the OS. JRE combines the Java code that was created using the JDK with the libraries and then runs it on the JVM. JRE acts as a high level layer on the top of the operating system.
Core components of JRE include:
- An implementation of a Java Virtual Machine (JVM)
- Classes required to run the Java programs
- Property Files
Also, the JVM makes Java portable and easy to integrate. All the Operating Systems having different JVM. But regardless of the JVM versions, it will produce the same output after the execution of the byte code across all the operating systems.
3. JDK
JDK, also known as the Java Development Kit, is a cross-platform software development environment. It provides a collection of tools and libraries that are necessary for developing the Java-based software application. JDK provides the core package that is used in Java along with the JVM and the JRE. If someone wants to only run an application, we can achieve easily it by installing JRE on your system. Though you would require the complete java kit, i.e. JDK, for developing Java-based software applications. The code developed using JDK is executed in the JRE and JVM.
Core components of JDK include:
- JRE
- Development Tools
4. Relationship between JVM, JRE and JDK
The JVM, JRE and JDK are not interconnected. Basically, JRE is part of JDK and JVM is part of JRE. On installing JRE in the system, we can run a Java program but we cannot compile it. We developed applications using JDK. JRE executes these applications using the JVM and Native Libraries. JVM is the one that converts the Java code into the native byte code and runs it on the system. The below diagram clearly depicts the relationship between JVM, JRE and JDK.
5. Features of JVM, JRE and JDK
Let’s inspect the distinct features of JVM, JRE and JDK.
5.1. JVM
- JVM is platform independent.
- JVM loads the executable code into Random Access Memory.
- JVM provides the Write once and Run Anywhere functionality.
- JVM is an essential component of the Java platform.
5.2. JRE
- The JRE combines the Java code created using the JDK with all the libraries.
- JRE is what enables a Java program to run in any operating system without modification.
- JRE comprises the class loaders, deployment solutions and the development toolkits.
- JRE is platform dependent.
5.3. JDK
- JDK is a set of tools for developing the Java applications.
- It also provides an environment and tools for developing, compiling, debugging and executing a Java Program.
- It is a layer of JRE and other development tools.
- It is also platform dependent.
6. Difference between JVM, JRE and JDK
All three are core part of Java eco-system, however there are few differences between JVM, JRE and JDK, which we should keep in mind.
- The initial tasks of JVM comprise class loading, verifying and linking the byte code regarding the Java code.
- It is a bundle of software components that is used for running the Java applications. It mainly comprises bootstrap classes and the Extension classes.
- The Java Development Kit provides an environment and tools for creating and developing the Java applications
Summary
In the above article, we explored about the difference between JVM, JRE and JDK. We described how JVM works as an abstract computing machine which actually executes the Java byte code with the help of Just-In-Time Compiler (JIT). Then we looked into JRE and how it helps in running the Java applications.Finally we understood how to develop the Java applications with the help of Java development kit (JDK). As always, you can find the updated source code in our GitHub Repository.