How to Install Multiple JDK's in Windows?

The Java Development Kit (JDK) is a vital tool for creating Java-based computer programmes. It provides all of the tools and resources required by developers to construct Java programmes and applets. The Java Development Kit (JDK) combines the Java Virtual Machine (JVM) and the Java Runtime Environment (JRE), making it an essential component of Java development. Install the JDKs keep track of where you're placing it on your computer, such as the folder, disc, and directory. The relevance of this need will become clear in subsequent phases.

To install JDKs, users should follow specific steps. During installation, it is crucial to remember the destination folder - the drive and directory where the JDK is saved. The information is vital for subsequent stages of the installation, as the requirement associated with this destination folder will become apparent later on.

Step-by-Step Implementation

Two versions of JDK, namely version 20 and 21, have been installed in the directory C:\Program Files\Java. If necessary, you have the option to download JDKs of different versions and save them in separate directories on different drives.

How to Install Multiple JDK's in Windows

After adding "C:\Program Files\Java\jdk-20" to the path environment variable, open the Command Prompt and enter "java," followed by pressing Enter. You will probably encounter an error because the "java" command, located in the "bin" directory of the downloaded JDK, cannot be located. Check the "bin" directory of your downloaded JDK for an executable with a .exe extension. The problem is that the Command Prompt cannot locate this application.

How to Install Multiple JDK's in Windows

When you input a command in the command prompt, Windows tries to find the matching executable. If it can't find it, an error occurs. All executable locations in Windows are stored in an environment variable called "path." In our case, we got an error because we didn't tell the system where to find the Java executable in the path environment variable (like C:\Program Files\Java\jdk-20), and this location changes with each JDK version. To check the value of the path environment variable in Windows, click the search icon next to the start symbol, type "Environment," and choose the option that says "Edit The System Environment Variables."

How to Install Multiple JDK's in Windows

Following the selection of the mentioned option, a GUI application will open. Subsequently, please navigate to the Environment Variables button on the screen of that specific GUI application and click on it.

How to Install Multiple JDK's in Windows

The window shown in the following image will appear when you click the Environment Variables button. Navigate to the System Variables section, pick the "Path" variable, and click the Edit button.

How to Install Multiple JDK's in Windows

The image that appears after clicking the Edit button reveals that the path "C:Program FilesJavajdk-20" is not included in the path environment variable.

How to Install Multiple JDK's in Windows

Next, click the New button in the displayed picture, add "C:\Program Files\Java\jdk-20," and press OK. Continue pressing OK until the GUI application closes automatically. Afterwards, reopen the "Edit The System Environment Variables" option and verify the updated value for the path environment variable. Refer to the picture below for confirmation.

How to Install Multiple JDK's in Windows

Now, open the command prompt. If it was already open, close it and reopen it. Then, type "java." It would help if you observed an output similar to the picture below.

How to Install Multiple JDK's in Windows

To utilize multiple JDKs, we've configured the path to the "bin" folder for JDK version 21 in the path environment variable. It allows for the compilation and execution of Java programs with JDK version 21. To switch to JDK version 21, it's necessary to add the path "C:\Program Files\Java\jdk-21\bin" to the path environment variable. Follow the previously outlined steps to make these additions, remembering that the paths mentioned are specific to our example. Verify the changes through the image below.

How to Install Multiple JDK's in Windows

Now, considering the paths to the executables in the "bin" directories of JDK versions 20 and 21, it's important to remember that when there are multiple paths in the path environment variable, the system prioritizes the first one, and the rest are overlooked. Open the command prompt, and if it's currently open, shut and reopen it. To check the output, type "java -version". In our scenario, it displays "java version 20.0.1" since the path to the "bin" directory of JDK version 20 is first in the list. Check out the image above to confirm this.

How to Install Multiple JDK's in Windows

When choosing a specific JDK, ensure that the path to the "bin" folder of that particular JDK is positioned at the top of the list among all the paths to the "bin" directories of the respective JDKs. In the environment variable window, where the path values are visible, you'll see buttons on the right side labeled "MOVE UP" and "MOVE DOWN." Use these buttons to organize the bin path values for your JDKs accordingly. For instance, if you intend to use JDK version 21, choose the path "C:\Program Files\Java\jdk-21\bin" and move it to the top.

How to Install Multiple JDK's in Windows

After choosing "C:Program FilesJavajdk-21bin," click on the "Move up" button to move it to the top of the list. Press OK and continue pressing OK until the GUI application closes automatically. Afterwards, check the updated values for the path environment variable. Confirm the changes through the image below.

How to Install Multiple JDK's in Windows

Now, open the command prompt. If it was open before, close and reopen it. Then, type the command "java -version" and observe the result. It should display "java version 21.0.1" since the path to the bin folder of JDK-21 is at the top of the list of JDK bin folder paths. You have now successfully setup the machine to build and run Java programmes using JDK-21.

How to Install Multiple JDK's in Windows




Latest Courses