Installing Java¶
To run a program written in Java, we need a runtime environment, known as the Java Runtime Environment (JRE). The JRE includes the Java Virtual Machine (JVM), which executes Java bytecode, as well as many built-in classes that support the basic functionality of programs (e.g., System, wrapper classes, collections, etc.).
However, the JRE alone is not enough for compiling Java code—the compiler is part of the Java Development Kit (JDK). JDK packages always include the JRE, so if we want to develop in Java, we only need to install the JDK. (Previously, the JRE was available as a separate download, but this has not been the case for several years.)
There are many different builds of the JDK available. First and foremost, there is OpenJDK, an open-source project that serves as the core of all JRE/JDK packages. OpenJDK can be used directly, and all Linux distributions typically offer a version of OpenJDK in their package repositories. Binary distributions are also available for Windows, but only for the latest version. (Since it is open source, anyone can create their own build from it.)
Several companies and organizations produce their own builds of OpenJDK, such as Oracle, IBM, RedHat, Azul, and Microsoft. These builds may include proprietary code, modifications, or completely re-implemented parts. Companies often offer these versions as paid products with full support. Their advantages may include long-term security support and potentially better proprietary components compared to the open-source OpenJDK versions. However, these versions are often not free or only available with restrictions. In this course, we will not use or learn anything that requires a paid or corporate version of Java.
So which version should we choose? On Linux, the easiest option is to install the latest JDK available in the package repository. On Windows and macOS, we need to download an installer or package for any version we choose. Some distributions may require personal information for downloads or only provide a paid version.
OpenJDK packages for Windows and macOS can be somewhat difficult to install and are only available for the latest version. The Adoptium (formerly AdoptOpenJDK) project fills this gap by providing pure OpenJDK builds without modifications, handling only the compilation, testing, and distribution. We will demonstrate how to install their packages.
Windows¶
-
Visit the Adoptium website.
-
The site should automatically detect that you are on Windows and identify your architecture (usually x64).
-
Choose a version. The "Latest LTS Release" download button is ideal for this course as it downloads the latest LTS (Long-term support) version. This is sufficient for completing the course since the Java version used in grading is always the latest LTS. However, if you prefer another version, click "Other platforms and versions" to select one.
-
Download and run the installer.
-
Once the installer starts, you will see an old-fashioned window where you can select components to install. The Add to PATH and Associate .jar options are enabled by default. If no other JDK is installed and you want this to be the default version, enable the Set JAVA_HOME variable option by clicking the X.

-
Follow the installation steps.
Linux¶
As mentioned earlier, almost all Linux distributions include OpenJDK binaries in their package repositories, and we recommend installing these versions. Installing other versions is not very complicated either; most distributions offer zip archives that can be extracted for use. Setting the PATH environment variable is important and should also be configured.
Debian, Ubuntu, Linux Mint, etc.¶
The following command will install the latest default JDK version:
sudo apt install default-jdk
Fedora, CentOS, Oracle Linux, Red Hat Enterprise Linux, etc.¶
sudo yum install java-17-openjdk-devel
Arch, Manjaro, etc.¶
sudo pacman -S jdk-openjdk
macOS¶
The Adoptium website also offers macOS builds, though we have no direct experience with their installation, as none of us use macOS. Most likely, the x64 .pkg version is the easiest to install. Follow the official installation guide in English.
Verifying the Installation¶
Once the installation is complete, verify that everything works! Open a command prompt or terminal (on Windows, press Win + R and type cmd), then enter the commands java -version and javac -version. You should see an output similar to the image below.
