BEST SITE FOR WEB DEVELOPERS
Java programming language. Lessons for beginners from hyperskill

Ua

JVM, JRE, and JDK


Theory

JVM languages, such as Java, Kotlin, or Scala, may be confusing for beginners since there are a number of basic terms that might be hard to differentiate between at first. This topic will get you more familiar with development for Java Platform by introducing those basics and giving an overview of how the code is being treated by different components of the platform.

§1. Java Virtual Machine (JVM)

The Java Virtual Machine, or JVM, is a virtual simulation of a physical computer. It executes the Java (or Java-compatible) bytecode, which comes after the source code compilation. In some sense, JVM acts as a mediator between the code and the real machine. It operates with a set of unified bytecode instructions that are interpreted and translated into machine instructions.

JVMs are available for many hardware and software platforms, so you can run the bytecode almost everywhere. A program compiled to bytecode is almost always platform-independent. Basically, when you have a JVM language code, you need to compile it only once, get the bytecode, and you'll be able to run it on any platform that has JVM.

Today there is a variety of JVM implementations, Java HotSpot Virtual Machine being the primary reference.


§2. Java Runtime Environment (JRE)

Java Runtime Environment, or JRE, is an execution environment. It includes the necessary components for running compiled JVM programs: the JVM itself and the Java Class Library (JCL).

JCL is essentially a set of standard libraries providing the most common functionality: fundamental classes, input/output, math package, collections, security, user interface toolkits, and many others. You can utilize these libraries in your programs.

When you run a compiled program, JRE combines the program bytecode with necessary libraries and runs the JVM, which executes the resulting bytecode.


§3. Java Development Kit (JDK)

Java Development Kit, or JDK, is a package to develop programs for the Java Platform. It includes JRE to run the programs and tools for developers: Java compiler, debugger, archiver, documentation generator, etc.

At the compilation stage, compilers translate source code into .class files that contain bytecode and can be executed by JVM. Note that if you're using JVM languages other than Java, you will need to download compilers separately, as they are not bundled with JDK.

In practice, programs often consist of multiple .class files packed together with an archiver tool into a single Java Archive (JAR file). JRE can run the program packed into a JAR directly without extracting the archived files. The resulting file is more convenient to store and share over the network since the data is compressed.

Before Java 11, if you wanted only to run a Java program, JRE was enough for you. However, since Java 11 was released, for most JVM implementations JRE is no longer downloadable as a separate component. If you want to run programs in JVM 11 or newer, you have to install JDK.


§4. The relationship between JVM, JRE, and JDK

The following image illustrates the relationship between JVM, JRE, and JDK:

JVM, JRE, JDK

§5. Summary

  • Java Virtual Machine executes compiled bytecode.
  • Java Runtime Environment includes JVM and standard libraries and runs compiled programs.
  • Java Development Kit, which includes JRE and development tools, is used by developers to write programs.

You can also view Lesson on hyperskill.org.


Practical tasks and answers

Tasks and answer options are given. The correct option is highlighted in blue color.

№1. What do you need as a user

Question: Imagine that you are a user, and you have a compiled JVM program (.class file). What do you need to start the program?

Select one option from the list:

  • Java compiler
  • Bytecode interpreter
  • JRE ✔
  • Debugger

Explanation. To run a compiled JVM program (.class file), you need the Java Runtime Environment (JRE), which contains the bytecode interpreter needed to run the program. So the correct answer is JRE.


№2. Where is JVM

Question: JVM is included in ...

Select one option from the list:

  • JAR
  • JCL
  • Developer tools
  • JRE ✔

Explanation. JVM is included in JRE (Java Runtime Environment).


№3. What do you need as a developer

Question: Imagine you want to write a Java program. First, you will write a source code file with the .java extension. Then you will compile it to obtain a .class file. Finally, you want to run the program. What is the minimal environment required to perform all of these actions?

Select one option from the list:

  • JRE
  • JDK ✔
  • JVM
  • Java compiler

Explanation. The minimal environment required to perform all of these actions is JDK (Java Development Kit).


№4. What does JDK include

Question: Select all components of JDK.

Select one or more options from the list:

  • JRE ✔
  • Java Compiler ✔
  • git
  • IDE

Explanation. The components of JDK are: JRE (Java Runtime Environment), Java Compiler


№5. What do you need as a developer?

Question: What is the minimal environment required to write, compile and run a program on a JVM language other than Java?

Select one option from the list:

  • JVM
  • JRE
  • JDK + Compiler ✔
  • JDK
  • Compiler

Explanation. The minimal environment required to write, compile and run a program on a JVM language other than Java is JDK (Java Development Kit) along with the Compiler for that particular language.


№6. Match abbreviations with their definitions

Question: Match the following abbreviations with their definitions.

Match the items from left and right columns:

  • JDK - A toolkit for developing programs including the Java compiler.
  • JRE - A toolkit for running programs, including the JVM.
  • JVM - The Java Virtual Machine.
  • JCL - A set of standard class libraries.
  • JAR - An archive format for packing programs.

№7. What does JRE include

Question: Select all components of JRE.

Select one or more options from the list:

  • Class library ✔
  • JVM ✔
  • Java Compiler
  • IDE

Explanation. The components of JRE (Java Runtime Environment) are: Class library, JVM (Java Virtual Machine).


№8. What is HotSpot?

Question: What is HotSpot?

Select one option from the list:

  • This is the name of the specification for Java Virtual Machines.
  • This is one of the existing JVM implementations. ✔
  • This is the only legal implementation of the JVM.
  • This is a synonym for the Java Virtual Machine.

Explanation. HotSpot is one of the existing JVM (Java Virtual Machine) implementations.


№9. Where is the Java compiler

Question: You can find javac (a Java compiler) in ...

Select one option from the list:

  • JVM (Java Virtual Machine)
  • JDK (Java Development Kit) ✔
  • JRE (Java Runtime Environment)
  • JAR (Java Archive)
  • JCL (Java Class Library)

Explanation. You can find javac (a Java compiler) in JDK (Java Development Kit).


Which operating systems have the JVM installed by default?

Most modern operating systems such as Windows, macOS, and various Linux distributions do not have JVM installed by default. However, some operating systems such as Oracle Solaris have JVM installed by default. Also, some computer manufacturers may ship their computers with JVM pre-installed. However, if you want to run Java programs on your computer, you should download and install JRE or JDK from the official Oracle website or from the OpenJDK website.