JRE is an installation package that provides an environment to run the Java program on any Operating System. It does not deal with the development process of any application. It is a part of the Java Development Kit (JDK). It is a software distribution that has Java Class Library, specific tools, and a stand-alone JVM.
JRE is the most common environment available on devices to run Java programs. The source codes are compiled and translated to Java bytecode. If we want to run this bytecode on any Operating System, we just need a specific JRE for that Operating System that is available freely on the Oracle website. The JRE fetch classes, verify access to memory, and retrieves the system resources that are required by the created software.
Java Runtime Environment works as a layer on the top of the OS and also includes:
- It includes the technologies that are used for the deployment, such as Java Web Start and Java plug-in.
- JRE contains the toolkits for user interface like Java 2D, AWT (Abstract Window Toolkit), Swing, Image I/O, print service, sound, etc.…
- It provides integration libraries such as JDBC (Java Database Connectivity) and JNDI (Java Naming and Directory Interface), IDL (Interface Definition Language), RMI (Remote Method Invocation), etc.
- It contains lang, util, zip, Java Archive (JAR), instrument, reflection, Collections, Concurrency Utilities, management, versioning, Logging, Preferences API, etc.…
- Other base libraries such as input/output (I/O), extension mechanism, Beans, JMX (Java Management Extension), Java Native Interface, and JAX-WS (Java for XML Processing).
Working of JRE
Once we write any source code, we have to save it with the .java extension. Next we compile our program using the “javac” command in command prompt (no need in any IDE). It translates the code to the bytecode which is platform-independent. When we compile our program it will generate a .class which has the bytecode for the equivalent java file. And that bytecode is executed on any platform having the JRE. The workflow is explained below.
It loads the various classes dynamically in the JVM (Java Virtual Machine),
which are essential for executing the program. After JVM started following
three class loader are used:
- Bootstrap class loader
- Extension class loader
- System class loader
- Byte code verifier- It verifies the bytecode during the run time so that the code doesn’t make any disturbance for the interpreter. The codes are interpreted, only if it passes the tests of the bytecode verifier that check the formatting and for illegal code.
- Interpreter- When class loaded and code gets verified, then it reads the assembly code line by line and process the following two functions:
- It executes the Byte Code.
- Make appropriate calls to the integrated hardware.