We have Known in the previous tutorial that the three most basic parts of Java platform are Java Virtual Machine (JVM), Java Runtime Environment (JRE), and Java Development Kit (JDK).
Java Runtime Engine (JRE) is a software environment in which Java program executes.
In other words, JRE is a software environment that is required for executing Java applications on any system regardless of operating system and underlying hardware.
JRE is a part of the Java Development Kit but cannot be used independently to execute any bytecode (compiled java program). It cannot be used for the development of Java application programs but it is used for executing them.
Java Runtime Environment is a collection of programs that contains Java Virtual Machine and many class libraries files that are required to run programs on JVM (via java command).
If your computer system has up-to-date JDK (Java Development Kit) installed, you don’t need to install it again.
Java Development Kit also contains Java Runtime Environment (JRE) that enables to run Java program in Eclipse of your system.
Components of Java Runtime Environment (JRE)
JRE consists of the following main components that are as follows:
- Java API (Application Programming Interface)
- Class Loader
- Bytecode verifier
- Java Virtual Machine (Interpreter)
Look at the below diagram to understand the components of JRE.
Let’s understand a brief description of each component of JRE.
What is Java API (Application Interface Programming)?
Java Application Programming Interface (API) is a very large collection of prepackaged, ready-made software components that provides the core functionality of the Java programming language.
In simple words, Java API is a large collection of already defined classes, interfaces, and methods in the form of Java packages.
It provides many useful capabilities, such as Graphical User Interface (GUI), Date, Time, and Calendar capabilities to programmers.
Java API is grouped into libraries of related classes and interfaces along with their fields, constructors, and methods. These libraries are provided in the form of packages.
It provides extra programming features built on the core java platform. It means that the basic features of Java programming language do not change when a new version of it is released.
Since Java API is flexible, it can be opened to add new packages or libraries into it.
Some popular libraries and their functionality from the Java API, in short, are as follows:
a) Java.lang: It is a package that provides fundamental classes to design the Java programming language. The Java.lang package is dynamically imported (i.e. loaded) in a Java program. It does not need to import explicitly.
The most commonly used classes from Java.lang package are Double, Float, Integer, String, StringBuffer, System, and Math.
b) Java.io: It supports Input/Output through the file system, keyboard, network, etc. The java.io package contains several classes to perform input and output operations.
The most commonly used classes from java.io are File class, InputStreams, OutputStreams, Readers, Writers, and RandomAccessFile.
c) Java.util: It supports various programming utilities. The java.util package provides legacy collection classes, event model, collections framework, date and time capabilities, and other utility classes such as string tokenizer.
d) Java.math: It is used to support mathematical operations.
e) Java.security: It supports security functions.
f) Java.awt: It supports creating graphical user interface (GUI), painting graphics, and images.
g) Java.sql: It support for accessing relational databases through SQL.
h) Java.beans: It supports creating java beans.
i) Java.net: The java.net package provides classes that are used for implementing networking in java programs.
j) Java.imageIO: It support for image input/output.
These predefined Java API provide a tremendous amount of core functionality to a programmer. A programmer should be aware of these Java APIs. He should know how to use these Java APIs.
These are examples of some important libraries from Java API. We will discuss in more detail these libraries in the further tutorial.
A complete list of all classes in Java API can be found at Oracle’s website: https://docs.oracle.com/javase/7/docs/api/.
What is Class Loader in Java?
When we write a program in java, the program is placed in memory by the class loader before it can be executed.
Java Class loader takes .class file containing bytecode and transfers it to the memory. It loads the .class file from a disk on your system or over a network.
After loading of class, it is passed to the bytecode verifier.
There are basically three subcomponents of Class loader in Java. They are as follows:
- Bootstrap class loader
- Extensions class loader
- System class loader
a) Bootstrap class loader:
The bootstrap class loader loads the core Java libraries located in C:\Program Files\Java\jre1.8.0_181\lib. The contents of this directory in the JRE8 environment are shown in the below screenshot.
You can clearly see the different *.jar files such as charsets.jar, deploy.jar, javaws.jar, plugin.jar, etc.
b) Extensions Class Loader:
The extensions class loader loads the classes from the extensions directory C:\Program Files\Java\jre1.8.0_181\lib\ext. The below screenshot shows the contents of the extensions directory in a JRE8 environment.
As you can clearly see the different JAR files available: access-bridge-64.jar, localedata.jar, etc. in the above screenshot. You can also see going to the above path location.
c) System Class Loader:
The system class loader loads the code from the location specified in the CLASSPATH environment variable which is defined by the operating system as shown in the below screenshot.
It can be seen in Windows 10 by going to the Control Panel ⇒ System and Security ⇒ System, Advanced System Settings ⇒ Advanced tab ⇒
What is Bytecode Verifier?
The bytecode verifier verifies that bytecodes are valid or not without breaching any of Java’s security rules. It gives special attention to checking the type of all the variables and expressions in the code.
Bytecode verifier ensures that there is no unauthorized access to memory. Once the code is successfully verified, it is transferred to Java Virtual Machine (JVM) for interpretation.
Note: We can elect to disable the bytecode verifier (which will make it run slightly faster), enable it only for code that is downloaded remotely from the network, or enable it for all the code.
Hope that this tutorial has covered all the basics concepts related to Java Runtime Environment (JRE) and its main components. I hope that you will have understood the basics of JRE.
In the next tutorial, we will familiar with Java Virtual Machine (JVM).
Thanks for reading!!!
Next ⇒ What is JVM in Java