JVM without JRE [closed]

Why can't the Java Virtual Machine run without the Java Runtime Environment?

What is the purpose of the Java Virtual Machine, and what is the purpose of the Java Runtime Environment? What are both things actually?


Solution 1:

It's a decision by the Java package maintainers to include the Java Virtual Machine (JVM) in the Java Runtime Environment (JRE) which is itself included in the Java Development Kit (JDK). Both options of installing Java in the Ubuntu repositories include the JVM. You can't run Java program without JVM. JVM is responsible in running a Java program, but the only file that can be executed by JVM is Java bytecode, a compiled Java source code.source

From the Oracle documentation:

Java Runtime Environment (JRE)

The Java Runtime Environment (JRE) provides the libraries, the Java Virtual Machine, and other components to run applets and applications written in the Java programming language. In addition, two key deployment technologies are part of the JRE: Java Plug-in, which enables applets to run in popular browsers; and Java Web Start, which deploys standalone applications over a network. It is also the foundation for the technologies in the Java 2 Platform, Enterprise Edition (J2EE) for enterprise software development and deployment. The JRE does not contain tools and utilities such as compilers or debuggers for developing applets and applications.

Java Development Kit (JDK)

The JDK is a superset of the JRE, and contains everything that is in the JRE, plus tools such as the compilers and debuggers necessary for developing applets and applications.

For running Java programs on your computer you only need to install the JRE. If you are planning to do some Java programming, you need to install the JDK instead.

In Ubuntu the default JRE and JDK packages can be installed by sudo apt install default-jre and sudo apt install default-jdk. It is also possible to install specific versions of JRE and JDK, for example openjdk-11-jre and openjdk-11-jdk.

The web browser Java Plug-in and Java Web Start, which form part of Oracle Java, are not included in OpenJDK from the default Ubuntu repositories.

Solution 2:

The Java Virtual Machine (JVM) is a program. It has the ability to read and execute compiled Java code. Think of it as the processor in a computer.

The Java Runtime Environment (JRE) is a platform. It includes the JVM and additional code and libraries to create a functional environment to run Java programs in. Think of it as the operating system installed on a computer.

The JVM 'needs' the JRE in the same way a processor (CPU) 'needs' an operating system (OS): strictly speaking, it doesn't, but you'll have a hard time getting it to do anything useful without expert knowledge.

Additionally, there is the Java Development Kit (JDK), which is a collection of tools. It includes a compiler and various debugging and information gathering tools to create Java applications. It may include a JRE.