The Java Development Kit (JDK), Java Virtual Machine (JVM), and Java Runtime Environment (JRE) together form a powerful trifecta of Java and Jakarta EE platform components for building and running Java applications. They all work together so that developers can build and run Java programs. I have started JDK and JVM earlier. In this quick overview, you’ll learn about the JRE, which is Java’s runtime environment.
Practically speaking, a runtime environment A piece of software designed to run other software. As Java’s runtime environment, the JRE includes the Java class library, the Java class loader, and the Java virtual machine. In this system:
- The class loader Responsible for correctly loading classes and linking to the core Java class library.
- The JVM Responsible for ensuring that Java applications have the necessary resources to run and perform well on your device or cloud environment.
- The JRE It is mainly a container for those other components, and is responsible for orchestrating their actions
We’ll dig deeper into how these elements work together in the following discussion.
What is a runtime environment?
A software program needs to run, and to do that, it needs an environment to run. In the past, most software used the operating system (OS) as the runtime environment. The program ran inside whatever computer it was on and relied directly on operating system settings for resource access; Resources such as memory, disk access and network access. The Java Runtime Environment has changed all that, at least for Java programs. In the case of Java and other JVM-based languages, the JRE forms an intermediary between the operating system and the actual program. The JRE loads class files and starts a virtual machine (JVM) that ensures access to memory and other system resources in a consistent manner across many operating systems.
Java Runtime Environment
We can view software as a series of layers that sit on top of the system hardware. Each layer provides services that will be used (and required) by the layers above it The Java Runtime Environment creates a JVM, a software layer that runs on top of a computer’s operating system, which provides additional services specific to Java. Figure 1 illustrates this arrangement.
The JRE smoothes the diversity of operating systems, ensuring that Java programs can run on virtually any operating system without modification. It also provides value added services. Automatic memory management is one of the most important services of the JRE, ensuring that programmers do not have to manually control the allocation and reallocation of memory.
In short, JRE is a type of meta-OS for Java, along with other JVM languages such as Scala and Groovy. This is a classic example abstractionAbstracting the underlying operating system into a compatible platform for running Java applications.
How JRE works with JVM
A Java Virtual Machine is a running software system responsible for running live Java programs. The JRE is the on-disk software component that takes your compiled Java code (the code is compiled with the JDK), combines it with the necessary libraries, and starts the JVM to run it.
The JRE contains the libraries and software you need to run Java programs. For example, the Java class loader is part of the JRE. This important piece of software compiles the Java code into memory and links the code to the appropriate Java class library (a process known as linking).
In the layered scenario I just described, the JVM is created by the JRE. From a package perspective, the JRE contains the JVM, as shown in Figure 2. The JVM is part of the JRE—the active, running part that the JRE creates to host programs. The JRE takes static assets and turns them into a running JVM that hosts the running program.
Installing and using the JRE
Although the JRE has a conceptual side, in real-world practice it is simply software installed on a computer whose purpose is to run your Java programs. As a developer, you will mostly work with the JDK and JVM, as these are the platform components you use to develop and run your Java programs. As a Java application user, you will be more involved with the JRE, which allows you to run those programs.
Java 9 restructured the Java platform so that the JRE is now only available as part of a JDK. When you want to ship a consumer application using JLink, you can provide a bundled JRE with your application. Such a bundle contains all the components required to run the program. For our purposes, we will use a JRE inside the JDK. You can download the latest JDK for your system from Oracle’s Java SE page. Windows and macOS have automatic installers that will handle the details (such as setting the path). On Linux, a nice alternative is to use SDKMan. In any event, you’ll want to have the JRE available from your command line so you can use it
Version of JRE
The Java Runtime Environment is updated for each new version of Java, and its version numbers align with the Java Platform version system, so for example JRE 1.19 runs Java 19.
Many computers run a JRE built for Java SE, which is capable of running any Java application regardless of how it was built. Most mobile devices have a JRE for Java ME, which is pre-installed on the mobile device and is not available for download. Going forward, applications bundled with their own JRE via JLink will become the norm.
Once you download the JDK, you can interact with the JRE on the command-line by typing
java -version, which will tell you which version is installed. (On POSIX systems, you can always check the installed location with the command,
JRE in DevOps
The JRE is not very noticeable during the development stage, where it mostly runs your program on your OS or IDE of choice. It plays a slightly more prominent role in devops and system administration as the JRE is used for monitoring and configuration.
Basically, the JRE provides the “knobs” that you use to configure and control the properties of a Java application. Memory usage is a prime example, the bread and butter of system administration. While memory usage is always important, it is essential in cloud configurations, and DevOps is a cloud-based approach to building and running software. If you work in a DevOps environment, or are interested in branching out into DevOps, it’s a good idea to understand how Java memory works and how it’s monitored in the JRE.
Java memory and JRE
Java memory consists of three components: heap, stack, and metaspace (formerly called perms).
- Metaspace Where Java stores your program’s immutable information such as class definitions.
- pile of space Where Java holds variable contents.
- stack space Where Java stores function execution and variable references.
Java memory management since Java 8
Until Java 8, was known as Metaspace permgen. Besides being a much cooler name, Metaspace is a significant change in how developers interact with Java memory space. Previously, you would use the command
java -XX:MaxPermSize To monitor the size of the PermGen space. From Java 8 forward, Java automatically increases the size of the metaspace to accommodate the meta-requirements of your program. Java 8 also introduced a new flag,
MaxMetaspaceSizewhich you can use to limit the metaspace size.
Configuring heap space
pile of space Java memory is the most dynamic part of the system. you can use
-Xmx The flags tell Java how big to start the heap and how big to let it grow. Understanding how to tune these flags for specific program needs is an important aspect of memory management in Java. It is ideal to make the heap large enough for the most efficient garbage collection. That is, you want to allow enough memory to run the program, but you don’t want it to be larger than necessary.
Configuring stack space
stack space where function calls and variable references are aligned. The stack space is the source of the second-most infamous exception in Java programming: the StackOverflowError (the first being the NullPointerException). The Stack Overflow Exception Indicates that you have run out of stack space because too much of it has been reserved. Typically, you’ll get a stack overflow when a method or methods call each other in a circular fashion, causing an increasing number of function calls to be dedicated within the stack.
-Xss Switch to configure stack start size. The stack then grows dynamically according to the program’s needs.
Java application monitoring
Although application monitoring is a function of the JVM, the JRE provides configuration options, which are the baseline required for monitoring. From the classics (such as the Unix command
top) Oracle’s infrastructure monitoring such as sophisticated remote monitoring solutions.
Among these options are visual profilers such as VisualVM that allow inspection of the running JVM. These tools enable hotspot and memory leak tracking, as well as viewing overall memory consumption on your system.
The Java Runtime Environment is the on-disk program that loads Java applications for the JVM to run. A JRE is included by default when you download the JDK, and each JRE includes the core Java class library, a Java class loader, and a JVM. It is helpful to understand how the JVM, JDK and JRE interact, especially for working in cloud and DevOps environments. In this environment, the JRE takes a stronger role in monitoring and configuration than in traditional Java application development.
This story, “What is the JRE? Introduction to the Java Runtime Environment” was originally published by
Copyright © 2022 IDG Communications, Inc.