3

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?

Renan
  • 813
Asad Mehmood
  • 157
  • 1
  • 6

3 Answers3

6

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.

karel
  • 114,770
  • I find the question off topic too. I don't have the right to vote to close, which is what I would have done if I had enough rep on this SE (I saw the question through the HNQ). I think the perfect action would be to redirect towards https://stackoverflow.com/a/6634882/180719. – Olivier Grégoire Nov 12 '18 at 14:49
  • By my calculation the question is two thirds off topic, based on word count.That seems fair to me. – karel Nov 12 '18 at 14:52
4

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.

JvR
  • 141
  • 3
0

The JVM is the Virtual Machine that interpretes Java Bytecode and execute it so a programm Based on Java Bytecode can be runned on the current Machine.

The JRE is the Standard Library Set of Java. Every Class that is used inside of Java Programms (the Classes String, Object,... etc)

It could be possible to run Java Bytecode without the entire JRE, but not without it completely because the JVM uses many Classes from the JRE (like Object, String, Unsafe, etc..).