A Java Runtime Environment JRE Or JDK Must Be Available
The Java programming language is a platform-independent language (WORA) because it does not depend on any platform type. When a Java code is compiled, it is compiled into byte code through JIT (Just-in-Time) compiler, and the byte code is independent of the platform. To execute the bytecode, a virtual machine is required, and it is known as Java Virtual Machine or JVM. The Java Virtual Machine converts the byte code into machine code. The JVM also enables other programming languages to execute their codes. The JVM is a virtual machine that needs a runtime environment where it can work, and that is provided by JRE (Java Runtime Environment). Thus, JRE provides a runtime environment to JVM so that it can execute the bytecode. Consequently, both JVM and JRE are contained in a kit which is known as JDK or Java Development Kit. Thus, JDK is a development kit that consists of such tools.
In this section, we will cover what is JRE or JDK and why there is a need to use it.
JRE (Java Runtime Environment)
Also written as Java RTE. JRE is an implementation of Java that provides an executable environment to the JVM so that it can execute the Java code. JRE contains a set of necessary libraries and software tools that can be used by JVM in order to build Java applications. It takes the code, uses the essential Java libraries and combines it with the code, and enables the JVM to execute the code.
JDK (Java Development Kit)
JDK is the container that contains JVM, JRE, and other essential development tools for developing Java applications. It is an environment that allows Java code to get executed. Apart from JVM and JRE, it also contains an interpreter (or loader), a java compiler known as javac, Java documentation, i.e., JavaDoc, an archiver, i.e., jar, and some other tools. That is the reason it is known as a kit.
The complete JDK architecture can be understood by looking at the below image:
Is it necessary to have JRE or JDK?
Such a question seems like interrogating "Is oxygen necessary for a human body to function?". JRE or JDK is oxygen to a Java code without which a Java code cannot be executed. Thus, it is necessary that JDK or JRE must be installed on a system where a Java code needs to be executed. Rather the user has the choice of installing either JDK or JRE on the system. It's the user requirement to select the one.
But it is beneficial to download and install the complete Java setup that means downloading the JDK because the JDK contains all the development tools that users may require to download separately later on. Also, JVM, JRE, and JDK are the three main components of Java architecture. To know more about Java architecture, visit https://www.javatpoint.com/java-architecture of the Java tutorial. With the advancement in technology, the version of JDK also enhances, and the current JDK version being used is Java SE Development Kit 15.0.2. In the Java architecture, it can be seen that JDK and JRE are the essential part of the Java code, which provides the environment for the Java code to get executed. Thus, a Java Runtime Environment JRE or JDK is mandated for executing Java code.