Java is one of the popular programming languages of 2020, it is a platform-independent programming language which means the same Java Code can be compiled and execute at any system without making any changes in the source. Here is a catch to run and execute a java source code we require some tools such as Java Virtual Machine (JVM), Java Runtime Environment (JRE) and Java Development Kit (JDK) all of these three tools are Platform dependent tools. Using these three tools we can create a Java program and execute it, so for a java developer its necessary to have these to be installed before compiling and executing any Java source code or byte code. Among JRE, JDK, and JVM, JDK and JRE are software where JVM is a concept, so we cannot install JVM separately.
Note: JDK is a combination of JRE and JVM so when we install or download a JDK it includes a compatible version of JRE, and the JRE contains default JVM.
What is a Runtime Environment?
A runtime environment is a software which provides an environment to execute and run a program code. The runtime environment loads all the necessary files and makes sure that the program gets enough memory and other resources from the system while it runs the program. The programs like C++ and C do not have any specific runtime environment they depend on the Operating System for all the memory and resource allocation but programming languages like Java use a runtime environment.
Java Runtime Environment (JRE)
As we know most of the other high-level programming languages depend on the Operating System for a runtime environment but this is not a case in Java. When we discuss the different layers in Systems which include hardware and software, there the Runtime Environment resides at the Computer operating system.
Now let’s talk about Java Runtime Environment (JRE), A JRE is a software which is a Part of Java Development Kit and use to execute the compiled code of Java Source code. JRE makes sure that Java code runs on every system without making any changes in the source code. JRE provides many features and Memory management system in one of those services, in this user do not have to control memory allocation and deallocation of the software all is done by the JRE.
In a Nutshell, Java Runtime Environment is a Java Specified software which is designed to run Java programs, it contains many class libraries, java class loader and a JAVA Virtual Machine (JVM).
- Classloader helps to connect the core Java Class libraries with currently loading classes.
- Java Virtual Machine is a concept or virtual machine which helps to provide necessary resources to the Java Application so the program could be run in the environment.
- JRE combines all the resources and concepts which are required to run the Java byte code.
JDK = JRE + JVM (Software)
JRE = JVM + Class loaders (Software)
JVM = Java Interpreter +Threading + Garbage Collection (Virtual Machine)
Working of JRE with JVM
JAVA virtual machine is responsible for executing the Java Program. JRE consists of JVM along with some libraries, JRE is a software that takes the Java code and combines it with the required libraries so the Java Virtual Machine can execute that code, this means JVM execute the code with the help of an interpreter.
If we look at the complete working framework of JRE, it grabs the compiled code from the memory, load that compiled java code into main memory and connect it with the appropriate Java Class libraries, so the Java Virtual Machine could finally execute it.
Now when we install Java or JAVA Standard Edition, we do not have to install JRE separately the Java SE comes with a complete package that consists of the JDK with an appropriate and compatible version of JRE. The Java code becomes platform-independent only if that system has a Java development kit with a compatible version of JRE.
JRE is a part of Java JDK, and it is a piece of software that our system must have if we want to run the Java application. While installing any edition of Java whether it standard or Enterprise they all contain Java Runtime environment with a proper Java Virtual Machine. JRE includes all the core Java class libraries, class loaders, and a Java Virtual machine.