What is JRE?
JRE (Java Runtime Environment) or the runtime environment is a software that runs on a computer's operating system and provides the necessary class libraries and other resources for a specific Java program to run.
JRE is one of the three components involved in developing and running Java programs. The other two components are as follows:
What does JRE include?
In addition to the JVM, JRE also includes a range of other tools and supporting features to maximize the utilization of your Java applications. These tools and supporting features include:
Deployment technologies such as Java Web Start and Java Plugin are integrated into the JRE installation to simplify the activation of applications and provide enhanced support for future Java updates.
JRE also includes development tools designed to help developers enhance their user interfaces. Some of these tools include:
Java 2D: An Application Programming Interface (API) used for drawing 2D graphics in the Java language. Developers can create rich user interfaces, special effects, games, and animations.
Abstract Window Toolkit (AWT): A graphical user interface (GUI) used to create objects, buttons, scrollbars, and windows.
Swing: Another lightweight GUI that uses a set of diverse tools to provide flexible customization and user-friendliness.
Java Runtime Environment provides several integrated libraries to support developers in seamlessly connecting data between their applications and services. Some of these libraries include:
Java IDL (CORBA): Uses the Common Object Request Broker Architecture to support distributed objects written in the Java programming language.
Java Database Connectivity (JDBC) API: Provides tools for developers to write applications capable of accessing remote relational databases, flat files, and spreadsheets.
Java Naming and Directory Interface (JNDI): A programming interface and directory service that allows clients to create mobile applications that can retrieve information from a database using a naming convention.
Language Library and Utilities
Included in the JRE are the java.lang and java.util packages, which are essential for designing Java applications, package versioning, and monitoring. Some of these packages include:
Collections Framework: A unified architecture consisting of a set of interfaces designed to improve the storage and processing of application data.
Concurrency Utilities: A powerful package of high-performance multithreading utilities.
Preferences API: A lightweight, cross-platform API with persistence that allows multiple users on the same machine to define their own application-specific preference groups.
Logging: Creating log reports - such as security errors, configuration errors, and performance issues - for further analysis.
Java Archive (JAR): A platform-independent file format that allows packaging multiple files into a JAR format, significantly speeding up downloads and reducing file size.
How do JVM and JRE work?
JRE (Java Runtime Environment) consists of the JVM (Java Virtual Machine) along with libraries and development tools. After a program is written, it is saved with a .java extension and goes through the next step, which is compilation. Upon compilation, the compiler generates a .class file containing byte code. Byte code is platform-independent and can run on any device with JRE. From here, the role of JRE begins. To execute any Java program, you need to have JRE. The flow of the byte code to run is as follows:
The Java ClassLoader is responsible for loading the necessary classes to execute a Java program. The ClassLoader uses lazy loading mechanism to load classes only when they are required by the program. This helps optimize memory usage and improve the performance of the Java program. In this step, the classloader loads the necessary classes for program execution. The classloader supports loading classes into the Java Virtual Machine. When the JVM is started, three classloaders are used: the Bootstrap class loader, the Extensions class loader, and the System class loader.
The Java ClassLoader dynamically loads all the necessary classes to run a Java program. Since Java classes are loaded into memory only when they are required, the JRE uses the ClassLoader to automate this process as needed.
The Interpreter is another component of the JRE that is responsible for executing bytecode and generating executable machine code. The Interpreter reads bytecode and converts it into executable machine code based on the defined rules in the JVM architecture. It also provides security features such as access control and memory limit checks.
With these steps, the program is executed within the JRE.