What is JRE?
Java Run-time Environment (JRE) is the part of the Java Development Kit (JDK). It is a freely available software distribution which has Java Class Library, specific tools, and a stand-alone JVM. It is the most common environment available on devices to run java programs. The source Java code gets compiled and converted to Java bytecode. If you wish to run this bytecode on any platform, you require JRE. The JRE loads classes, verify access to memory, and retrieves the system resources. JRE acts as a layer on the top of the operating system.
It also includes:
- Technologies which get used for deployment such as Java Web Start.
- Toolkits for user interface like Java 2D.
- Integration libraries like Java Database Connectivity (JDBC) and Java Naming and Directory Interface (JNDI).
- Libraries such as Lang and util.
- Other base libraries like Java Management Extensions (JMX), Java Native Interface (JNI) and Java for XML Processing (JAX-WS).
What does JRE consist of?
JRE consists of the following components:
- Deployment technologies such as deployment, Java plug-in, and Java Web Start.
- User interface toolkits, including Abstract Window Toolkit (AWT), Swing, Java 2D, Accessibility, Image I/O, Print Service, Sound, drag, and drop (DnD) and input methods.
- Integration libraries including Interface Definition Language (IDL), Java Database Connectivity (JDBC), Java Naming and Directory Interface (JNDI), Remote Method Invocation (RMI), Remote Method Invocation Over Internet Inter-Orb Protocol (RMI-IIOP) and scripting.
- Other base libraries, including international support, input/output (I/O), extension mechanism, Beans, Java Management Extensions (JMX), Java Native Interface (JNI), Math, Networking, Override Mechanism, Security, Serialization and Java for XML Processing (XML JAXP).
- Lang and util base libraries, including lang and util, zip, Java Archive (JAR), instrument, reflection, Collections, Concurrency Utilities, management, versioning, Logging, Preferences API, Ref Objects and Regular Expressions.
- Java Virtual Machine (JVM), which comprise of Server Virtual Machine and Java HotSpot Client.
How does JRE work with JVM?
JRE has an instance of JVM with it, library classes and development tools. To understand the working of JRE let us see an example of a simple "Hello World" program.
Once you write this program, you have to save it with .java extension. Compile your program. The output of the Java compiler is a byte-code which is platform independent. After compiling, the compiler generates a .class file which has the bytecode. The bytecode is platform independent and runs on any device having the JRE. From here, the work of JRE begins. To run any Java program, you need JRE. The flow of the bytecode to run is as follows:
The following steps take place at runtime:
- Class Loader
At this step, the class loader loads various classes which are essential for running the program. The class loader dynamically loads the classes in the Java Virtual Machine.
When the JVM is started, three class loaders are used:
- Bootstrap class loader
- Extensions class loader
- System class loader
- Byte code verifier
Byte code verifier can be considered as a gatekeeper. It verifies the bytecode so that the code doesn't make any sort of disturbance for the interpreter. The code is allowed to be interpreted only when it passes the tests of the Bytecode verifier which checks the format and checks for illegal code.
Once the classes get loaded and the code gets verified, then interpreter reads the assembly code line by line and does the following two functions:
- Execute the Byte Code
- Make appropriate calls to the underlying hardware
In this way, the program runs in JRE.
How to set up Java JRE with PATH Environment Variables?
To develop or run Java applications, you need to download and install the Java SE Development Kit.
Step 1.) Download the Java SE latest release from the official site of the oracle.
Step 2.) After downloading the file, you will have an executable file downloaded. Run that file and keep everything as default and keep clicking next and then install.
Step 3.) After completing the installation, your JDK and JRE would be downloaded in the program files folder.
Step 4.) After complete installation, you need to set up the environment variables.
Step 5.) Go to control panel -> System and Security -> System -> Advanced System Settings. The following dialog box will appear.
Step 6.) Click on Environment Variables, go to system variables, and double click on Path.
Step 7.) Now add the path of your bin file present in the JRE file to the Path variable.
The set up Java environment is complete.
Difference between JVM, JDK, and JRE
- JVM - Java Virtual Machine is a virtual machine which runs programs which are compiled to bytecodes. The JVM is detailed by a specification that formally describes what is required in a JVM implementation. Having a specification ensures interoperability of Java programs across different implementations so that program authors using the Java Development Kit (JDK) need not worry about traits of the underlying hardware platform.
- JDK- JDK is a wrapper around the JRE and additionally contains the compiler, interpreter, debugger and other tools. It provides users with features to run as well as develop Java programs.
- JRE- JRE is made up of class libraries, JVM and supporting files