Java Runtime Environment (JRE) is an open-access software distribution that has a Java class library, specific tools, and a separate JVM. In Java, JRE is one of the interrelated components in the Java Development Kit (JDK). It is the most common environment available on devices for running Java programs. Java source code is compiled and converted to Java bytecode. If you want to run this bytecode on any platform, you need JRE. The JRE loads classes check memory access and get system resources. JRE acts as a software layer on top of the operating system.
Components of Java JRE
The components of JRE are mentioned below:
- Integration libraries include Java Database Connectivity (JDBC)
- Java Naming, Interface Definition Language (IDL)
- Directory Interface (JNDI)
- Remote Method Invocation Over Internet Inter-Orb Protocol (RMI-IIOP)
- Remote Method Invocation (RMI)
- Scripting
Java Virtual Machine (JVM) consists of Java HotSpot Client and Server Virtual Machine.
- User interface libraries include Swing, Java 2D, Abstract Window Toolkit (AWT), Accessibility, Image I/O, Print Service, Sound, drag, and Drop (DnD), and input methods.
- Lang and util base libraries, which include lang and util, zip, Collections, Concurrency Utilities, management, Java Archive (JAR), instrument, reflection, versioning, Preferences API, Ref Objects, Logging, and Regular Expressions.
- Other base libraries, including Java Management Extensions (JMX), Java Native Interface (JNI), Math, Networking, international support, input/output (I/O), Beans, Java Override Mechanism, Security, Serialization, extension mechanism, and Java for XML Processing (XML JAXP).
- Deployment technologies such as Java Web Start, deployment, and Java plug-in.
Working of JRE
Java Development Kit (JDK) and Java Runtime Environment (JRE) both interact with each other to create a sustainable runtime environment that enables Java-based applications to run seamlessly on any operating system. The JRE runtime architecture consists of the following elements as listed:
- ClassLoader
- ByteCode verifier
- Interpreter
Now let us briefly about them as follows:
- ClassLoader: Java ClassLoader dynamically loads all the classes necessary to run a Java program. Because classes are only loaded into memory whenever they are needed, the JRE uses ClassLoader will automate this process when needed. During the initialization of the JVM, three classLoaders are loaded:
- Bootstrap class loader
- Extensions class loader
- System class loader
- Bytecode Verifier: The bytecode checker ensures the format and precision of Java code before passing it to the interpreter. If the code violates system integrity or access rights, the class is considered corrupt and will not load.
- Interpreter: After loading the byte code successfully, the Java interpreter creates an object of the Java virtual machine that allows the Java program to run natively on the underlying machine.
How does JRE work with JVM?
JRE has an object of JVM with it, development tools, and library classes. To understand the working of Java Runtime Environment let us see an example of a simple Java program that prints “GeeksForGeeks”.
Example:
Java
// Java class class GFG { // Main driver method public static void main(String[] args) { // Print statement System.out.println( "GeeksForGeeks" ); } } |
GeeksForGeeks
Once you write your Java program, you must save it with a file name with a “.java” extension. Then after you Compile your program. The output of the Java compiler is byte code which is a platform-independent code. After compiling, the compiler generates a .class file that contains the byte code. Bytecode is platform-independent that runs on all devices which contain Java Runtime Environment (JRE).
Difference between JVM, JRE, and JDK.
- JVM: JVM stands for Java Virtual Machine. JVM is used for running Java bytecode.Java applications are called WORA (Write Once Run Anywhere). This means a programmer can develop Java code on one system and can expect it to run on any other Java-enabled system without any adjustment. This is all possible because of JVM.
- JRE: JRE stands for Java Runtime Environment. JRE is made up of class libraries.
- JDK: JDK stands for Java Development Kit. JDK contains the JRE with compiler, interpreter, debugger, and other tools. It provides features to run as well as develop Java Programs.