How to Check, Install, & Manage Java Versions (JDK/JRE)

Ad

1. Introduction

Why Java Version Management is Important

Java is a widely used programming language for various software development, including web applications, mobile apps, and business systems. Its evolution has been remarkable, with new features added and specifications changed in each version.

For example, Java 8 introduced Lambda expressions and the Stream API, while Java 11 and later versions deprecated some modules, affecting compatibility with execution environments and libraries. To properly handle these changes, it is essential to constantly keep track of “which Java version is being used” in your development environment.

Furthermore, in companies and development sites, it is common practice to specify a particular Java version for operation from the perspective of security measures and Long-Term Support (LTS). Therefore, using an outdated version can entail risks due to the end of support.

Purpose and Target Audience of This Article

This article comprehensively explains everything from checking Java versions to installation, updates, and troubleshooting. The target audience is as follows:

  • Beginners who want to start developing with Java
  • Intermediate users who want to check their current version
  • Experienced developers facing issues with environment setup or updates

We also provide detailed procedures for major OS like Windows, Mac, and Linux, as well as methods for checking versions using development tools, making it applicable to any environment.

The goal is to help you acquire accurate knowledge about Java versions and set up a safe and comfortable development environment.

Ad

2. How to Check Java Version

2.1 How to Check Java Version via Command Line

Using the java -version command

The most basic and reliable method to check the Java version is by using the command line. This works regardless of the OS.

Procedure (Common):

  1. Open Terminal (Mac/Linux) or Command Prompt (Windows).
  2. Enter and execute the following command.
java -version

Example Output:

java version "17.0.2" 2022-01-18 LTS
Java(TM) SE Runtime Environment (build 17.0.2+8-LTS-86)
Java HotSpot(TM) 64-Bit Server VM (build 17.0.2+8-LTS-86, mixed mode, sharing)

From this result, you can see that the “Java Runtime Environment (JRE)” version is 17.

Check JDK version with javac -version

Checking the version of `javac`, the Java compiler, is also useful to confirm if the JDK is correctly installed.

javac -version

Example Output:

javac 17.0.2

Checking the location of the Java executable

If multiple versions are installed, it’s important to check which executable is being used.

  • Windows:
  where java
  • Mac/Linux:
  which java

By checking the output path, you can find out where Java is installed.

2.2 Checking using GUI (Windows)

If you are not comfortable with command line operations, you can also check the Java version using the Windows GUI.

Checking with the Java Control Panel

  1. From the “Start Menu”, type “Java” and open “Configure Java”.
  2. Click on the “Java” tab and select “View”.
  3. A list of installed Java versions will be displayed.

This allows you to see a list of multiple versions if they coexist.

2.3 Checking using GUI (Mac)

You can also check the Java version on Mac using the GUI.

Checking from System Preferences

  1. From the Apple menu, open “System Settings” > “Java”.
  2. The Java Control Panel will launch.
  3. Select the “Java” tab and click “View”.

Similar to Windows, you can check detailed version information.

2.4 Checking Java Version using Eclipse

If you are using Eclipse as your development environment, it is important to check the Java version settings for each project.

Procedure:

  1. Launch Eclipse and right-click on the target project.
  2. Go to “Properties” > “Java Compiler”.
  3. The “Compiler compliance level” field will display the Java version being used.

Additionally, you can check the JDK version that Eclipse itself is using with the following steps:

  1. Check under “Window” > “Preferences” > “Java” > “Installed JREs”.
  2. Checking the details of the JRE in use will show the JDK path and version.
Ad

3. How to Install Java

3.1 Installation Procedure on Windows

Download JDK from Oracle Official Website

  1. Access the Oracle Official Download Page in your browser.
  2. Find the latest “Java SE Development Kit (JDK)” entry and select the installer for Windows (.exe format).
  3. Agree to the license and start the download.

Installation using the Installer

Once the download is complete, run the installer and follow these steps:

  • The default installation directory is usually fine.
  • Installation should complete in a few minutes.

Setting Environment Variables (Important)

To use Java from the command line, you need to set environment variables.

  1. Open “Control Panel” > “System” > “Advanced system settings” > “Environment Variables”.
  2. Under “System variables”, select Path and add the path to the bin folder (e.g., C:Program FilesJavajdk-17in).
  3. Create a new variable named JAVA_HOME and specify the path to the JDK.

After setting up, open a new Command Prompt and run java -version to confirm if it’s installed correctly.

3.2 Installation Procedure on Mac

JDK Download and Installation

  1. Access the Oracle official page and download the JDK for Mac (.pkg format).
  2. Double-click the downloaded file to launch the installer and follow the on-screen instructions to install.

Verification and Environment Variable Setting in Terminal

After installation, open Terminal and execute the following command:

java -version

If the displayed version is the latest, the installation was successful.

If necessary, add the following lines to your .zshrc or .bash_profile to set JAVA_HOME:

export JAVA_HOME=$(/usr/libexec/java_home)
export PATH=$JAVA_HOME/bin:$PATH

After setting, run source ~/.zshrc to apply the changes.

3.3 Installation Procedure on Linux

Installation via Package Manager (Ubuntu/Debian based)

sudo apt update
sudo apt install openjdk-17-jdk

Then, check the version:

java -version
javac -version

Installation via Package Manager (CentOS/RHEL based)

sudo yum install java-17-openjdk-devel

Switching between Multiple Versions

On Ubuntu and similar systems, you can switch between installed Java versions using the following command:

sudo update-alternatives --config java

Manual Installation (using tar.gz file)

  1. Download the JDK in tar.gz format from the Oracle official website.
  2. Extract it to a directory like /usr/lib/jvm/.
  3. Manually set up symbolic links and environment variables.

This method is useful when you want to use the latest version or a specific JDK distribution.

Ad

4. How to Update Java

4.1 Updating Java on Windows

Manual Update via Java Control Panel

If JRE is installed on Windows, you can update it using the following steps:

  1. From the “Start” menu, type “Java” and open “Configure Java”.
  2. Click on the “Update” tab.
  3. Click “Update Now” to check for and install the latest version.

This method is limited to JRE. If you are using JDK for development, the basic method is to manually reinstall the latest version from the Oracle official website.

How to Manually Reinstall JDK

Updating JDK is done by “downloading and installing the latest version”.

  1. Access the Oracle official page.
  2. Download the latest JDK (you can delete the old version).
  3. After installation, reset JAVA_HOME and Path if necessary.

4.2 Updating Java on Mac

Update via Java Control Panel (for JRE)

  1. Open the Control Panel from “System Settings” > “Java”.
  2. Click on the “Update” tab.
  3. Execute “Update Now”.

How to Update JDK

On Mac, it is also common practice to manually install the latest version of JDK.

  1. Download the latest version from the Oracle official page or JDK distribution sites like Adoptium.
  2. Double-click the .pkg file to install.
  3. If the previous version is no longer needed, you can uninstall it.

Don’t Forget to Reset JAVA_HOME

If you are using a new version, the path for JAVA_HOME might change, so reset it using the following command:

export JAVA_HOME=$(/usr/libexec/java_home)

4.3 Updating Java on Linux

Updating via Package Manager

In Linux environments, you can update Java using the package management system integrated with the OS.

Ubuntu/Debian based:

sudo apt update
sudo apt upgrade openjdk-17-jdk

CentOS/RHEL based:

sudo yum update java-17-openjdk-devel

Switching Multiple Versions

If both old and new JDKs coexist, you need to manually switch the version you want to use.

sudo update-alternatives --config java
sudo update-alternatives --config javac

An interactive list will be displayed, and you can switch versions simply by selecting the one you want to use.

Manual Update (using tar.gz)

If you prefer not to rely on packages and want to install any version, you can download the JDK in tar.gz format and manually extract it and set the path. Delete the old JDK, then set the new path and environment variables.

Ad

5. Common Troubles and Solutions

5.1 When running version check, “java is not recognized as an internal or external command” is displayed.

Cause

  • The path to Java is not set in the Path environment variable.
  • Java is not installed correctly.

Solution

  1. Confirm if JDK is installed correctly.
  2. Add the Java bin directory path to the Path environment variable (Example:):
   C:Program FilesJavajdk-17in
  1. After adding, restart the Command Prompt and run java -version again.

5.2 Multiple Java versions are mixed, and an unintended version is called.

Cause

  • Multiple JDK/JREs are installed, and different versions are being used based on the priority of environment variables.

Solution (Windows/Mac/Linux Common)

  • Use where java (Windows) or which java (Mac/Linux) in the command line to check the actual Java executable being used.
  • Explicitly specify the path to the desired Java version in Path (Windows) or .zshrc, .bash_profile.
  • On Linux, utilize update-alternatives to switch versions.

5.3 Build errors occur in IDEs like Eclipse (Example: “Compiler compliance level does not match”)

Cause

  • The Java version set in the project differs from the JDK version recognized by Eclipse.

Solution

  1. In Eclipse, check the JDK path in “Window” -> “Preferences” -> “Java” -> “Installed JREs”.
  2. Right-click on the project -> “Properties” -> “Java Compiler” and adjust the “Compiler compliance level” (Example: align with Java 17).

5.4 Old versions remain after updating Java.

Cause

  • Java’s design does not overwrite and instead leaves old versions when installing new ones.
  • The coexistence of multiple versions can lead to configuration errors and security risks.

Solution

  • Delete unnecessary versions from “Apps & features” (Windows) or /Library/Java/JavaVirtualMachines/ (Mac).
  • After deletion, reconfirm that environment variables like Path and JAVA_HOME are correctly updated.

5.5 “Unsupported major.minor version” error occurs in Java Web applications.

Cause

  • The Java version used for compilation does not match the Java version of the execution environment (Example: Built with Java 17 -> Executed with Java 8).

Solution

  • Check the Java version of the execution environment and explicitly specify the target version during compilation (Example: javac -target 1.8).
  • Alternatively, upgrade the Java version on the execution environment side.
Ad

6. FAQ (Frequently Asked Questions)

Here, we have compiled common questions and their answers regarding Java versions, from beginners to intermediate users. The explanations focus on frequently searched questions and aim to be as practical and easy to understand as possible.

Q1. What is the difference between JRE and JDK?

A:
JRE (Java Runtime Environment) is the environment for “running” applications created with Java. On the other hand, JDK (Java Development Kit) is a set of tools for “developing, compiling, and executing” Java programs. Developers typically need to install JDK.

Q2. What do Java version numbers mean?

A:
Java versions are indicated, for example, as “Java 17.0.2”.

  • The first “17” is the major version (Java 17)
  • “0” is the minor version
  • “2” represents the update number

Since Java 9, a new version numbering scheme (time-based release model) has been adopted, with a new version released every six months. LTS (Long-Term Support) versions are particularly emphasized in enterprises (e.g., Java 8, 11, 17, 21, etc.).

Q3. Is it okay to have multiple Java versions installed?

A:
Yes, multiple versions can coexist. However, it is crucial to explicitly specify the version to be used in environment variables and IDE settings to prevent unintended versions from being used. Managing update-alternatives on Linux and Path and JAVA_HOME on Windows and Mac are key points.

Q4. Should I uninstall older Java versions?

A:
Basically, it is advisable to uninstall unnecessary versions. To reduce security risks, it is recommended to delete old JREs and JDKs that are not being used and organize your environment variables to point to the latest one.

Q5. How can I switch Java versions?

A:
For Windows:

  • Manually set Path and JAVA_HOME in environment variables. You can also use batch files or dedicated tools to switch between multiple versions.

For Mac/Linux:

  • Switch by writing export JAVA_HOME=... in .bash_profile or .zshrc.
  • Also, on Mac, you can easily switch using /usr/libexec/java_home -v version.

Q6. I frequently see Java update notifications. Can I ignore them?

A:
As long as it doesn’t directly affect development or execution, ignoring them in the short term may not cause significant operational issues. However, from a security perspective, early updates are recommended. Especially when using Java for business purposes or web applications, updating to the latest version is strongly encouraged.

Ad

7. Conclusion

The Java version is a crucial factor deeply related to the stability of the development environment, application compatibility, and even security. It is not uncommon for bugs and issues to occur due to mismatched versions.

This article has systematically explained the following points:

  • How to check the Java version (command line, GUI, IDE)
  • Installation procedures by OS (Windows, Mac, Linux)
  • How to perform safe updates and important notes
  • Common troubles and their solutions
  • FAQ for questions beginners often have

By correctly understanding and practicing these points, you will gain confidence in Java version management.

Especially for those who are new to learning Java or want to set up a new development environment, being able to smoothly handle JDK installation, version switching, and updates is directly linked to skill improvement.

Setting up the development environment significantly impacts programming results and motivation. Please refer to this article to build a reliable and up-to-date Java environment.

Ad