Difference Between JRE and JVM
Here, we will understand what JVM (Java virtual machine) is: JRE (Java Runtime Environment). Moreover, we will also study the major differences between JVM and JRE. In this topic, we are going to learn about JRE vs JVM.
What is JVM?
The Java Virtual Machine (JVM) is a virtual machine that resides on your computer and executes java byte code. The Java Virtual Machine understands only byte code; that’s why there is a javac compiler that converts the source code (.java) into byte code (.class) which JVM understands. Although JVM installed within different operating systems is different, JVM’s output is consistent across all operating systems.
Components of JVM
The following are different components present inside JVM:
1. ClassLoader: The class loader’s main function is to read the .class file and save the bytecode into the method area of the JVM.
2. Method Area: Java Virtual Machine’s method area stores all class-related information of all the classes being loaded by the class loader.
3. Heap Area: Heap Area is a part of JVM where created objects are located. JVM creates a class object for each .class file loaded by the class loader.
4. Stack: This part of JVM stores temporary variables.
5. PC Registers: PC Registers keep a record of which instruction has been executed and which is next in line to be executed.
6. Native Method Stack: Native method stack contains the native code information. It is written in other programming languages than java.
7. Execution Engine: The execution engine of jvm is responsible for the execution of the bytecode or compiled code. The execution engine of jvm contains:
- Virtual Processor: The virtual processor is responsible for executing operation codes sequentially.
- Interpreter: The interpreter interprets the bytecode. It is responsible for reading the stream of byte code, interpreting bytecode instructions, and executing them through the virtual processor. But the disadvantage of the interpreter is that when one method is called multiple times, every time there is a requirement of a new interpretation.
- Just-In-Time (JIT) compiler: It is basically used for performance improvement. It is used in order to overcome the disadvantage of the interpreter; when JVM finds repeated code, it uses the JIT compiler, which compiles the bytecode and changes it into native code. This native code is directly used in repeated method calls, which in turn provides a drastic performance improvement.
From the details above listed components, functions of JVM can be summarized as:
- JVM loads code.
- JVM verifies the loaded code.
- JVM executes code if it is valid.
- JVM provides a runtime environment.
The working of JVM can be explained through the below flow:
What is JRE?
Java Runtime Environment is a part of the Java development kit (JDK).
Java Runtime Environment (JRE) is an installation package that provides an environment to run java code. It is to be noted that JRE is used only by the end-users who want to run java code. JRE contains JVM in it; that is, JVM is a subset of JRE. Java Runtime Environment includes the following:
- User Interface Toolkits like Abstract Window Toolkit (AWT), Swing, Java Naming and Directory Interface (JBDI), Java 2D, Print Service, Drag and Drop (DND), etc.
- Lang and util libraries like lang and util, management, zip, reflection, JAR, Preference API, Regular Expressions Concurrency and multithreading utilities, Logging and others.
- Base libraries including Input-output (I/0), Math, Networking, Override mechanism Serialization, Java XML parsers, Java Native Interface (JNI).
- Integration libraries, for example, Interface Definition Language, Java DataBase Connectivity (JDBC), Remote Method Invocation (RMI), Java Naming and Directory Interface (JNDI).
- Java Virtual Machine (JVM).
Head to Head Comparison Between JRE and JVM (Infographics)
Below are the top 8 differences between JRE vs JVM
Key Differences Between JRE and JVM
The following are key differences between JRE vs JVM.
- The main function of JRE is to provide a runtime environment to run java applications, whereas JVM converts byte code to machine code for execution and provides platform independence.
- JRE acts as a container, and jvm acts as content.
- JRE is composed of JVM + Libraries to run applications, whereas jvm contains only a runtime environment for executing Java bytecode.
Comparison table between JRE vs JVM
Let’s discuss the top comparison between JRE vs JVM.
|Basis of Comparison||JRE||JVM|
|Full-Form||The full form of JRE is the Java Runtime Environment.||The full form of JVM is Java Virtual Machine.|
|Definition||Java Runtime Environment is a part of Java Development Kit (JDK) that comprises of a JVM, core classes and support libraries. Its main function is to provide a runtime environment to run java code.||Java Virtual Machine (JVM) is like a virtual computer that executes a set of precompiled statements. When a Java compiler compiles source code, it generates a set of instructions called bytecode (.class files). The Java Virtual Machine interprets bytecode instructions and converts them into machine code for its execution.|
|Container and Content||JRE acts as a container that contains JVM, libraries and other files. Moreover, JRE doesn’t contain development tools like compiler and debugger.||JVM is a part of JRE. It can be considered as a subset of JRE.|
|Development Purpose||It is not used for development purposes.||It is used for development purposes.|
|Running Purpose||It is used for running java code.||It is not used for running java code.|
|Composed of||JRE is composed of JVM + Libraries to run applications.||It contains only a runtime environment for executing Java bytecode.|
|Subset of||It is a subset of JDK.||It is a subset of JRE.|
|Tools||It contains class libraries that are required to run programs.||It does not contain any tools.|
From the article, we have a clear understanding of both Java Runtime Environment (JRE) and Java Virtual Machine (JVM), which are the most important parts of the Java Development Kit (JDK).
This is a guide to JRE vs JVM. Here we have discussed the JRE vs JVM key differences with infographics and comparison table. You may also have a look at the following articles to learn more –