This tutorial provides all the steps required to install OpenJDK 16 on Windows 10. The steps to install OpenJDK 16 on other versions of Windows should be similar to the steps explained in this tutorial.
You may also install the popular IDEs to develop Java applications by following - How To Install Eclipse For Java On Windows, How To Install IntelliJ IDEA for Java on Windows, and How To Install VSCode For Java On Windows. You may also follow the How To Install OpenJDK 15 On Ubuntu to install the latest OpenJDK on Ubuntu and How To Install Java 15 On Ubuntu to install Oracle JDK.
Notes: The newer version of this tutorial is available at How To Install OpenJDK 17 On Windows.
Step 1: Download OpenJDK
Open the JDK 16 GA Release site and download the distribution for Windows as highlighted in Fig 1.
Click the zip download link as highlighted in Fig 1 to download OpenJDK for Windows. Also, verify your download using the given sha256 checksum.
Step 2: Install OpenJDK
Extract the downloaded zip to the desired location. In my case, I have extracted the downloaded zip to C:\Java\OpenJDK. The final path should be C:\Java\OpenJDK\jdk-16.
This is the only step required to install OpenJDK on windows.
Step 3: Set Environment Variables
In this step, we will configure the environment variables to use the OpenJDK from Command Prompt. Open Command Prompt and check the installed version of Java using the command java -version as shown in Fig 2.
It shows the version of Java 16 since my current version of Java is 16. In your case it might show another version of Java if it's already installed, else it will show the message - Java is not recognized as internal or external command, operable program or batch file.
Right Click -> My Computer(This PC) -> Properties -> Advanced System Settings
The above steps will open the Windows Settings Panel as shown in Fig 3.
Now click the Environment Variables Button, select Path under the System Variables section, and click the Edit Button. We need to add the path of installed JDK to the system Path.
Click on the New/Edit Button and add/update the path to the installed JDK bin which is C:\java\openjdk\jdk-16\bin in our case. You might be required to update the path if it already exists. It should look like Fig 4.
Press the OK Button 3 times to close all the windows. This sets the JDK 16 on system environment variables to access the same from the console.
Notes: Remove existing PATH values specific to previously installed Java. Also update JAVA_HOME, in case it was already set. Also, you might be required to remove the previously installed JDK from the Global Path as shown in Fig 5.
Now again open the console and test the Java version as shown in Fig 6. Make sure to use a new console to test the version of the newly installed OpenJDK 16.
It must show the OpenJDK version as shown in Fig 6. You might need to restart the system in case it does not reflect the JDK version installed by us.
Getting started with Java - Hello World
In this step, we will write, compile, and execute our first program in Java using the standard Hello World example.
Now write the first Java program as shown below, save the program as HelloWorld.java and exit the editor. Make sure that the class name and file name are the same.
class HelloWorld {
public static void main( String[] args ) {
System.out.println( "Hello World !!\n" ); } }
Now open the command prompt and navigate to the path where you have saved your Java program. Use the below-mentioned commands to compile and execute the program.
# Compile - Specify file name and extension javac HelloWorld.java
# Execute - Spicy file name java HelloWorld
# Output Hello World !!
These are the easy-to-install steps required to install OpenJDK on Windows and write and execute the Java program.
Summary
This tutorial provided the steps required to download and install the most recent versions of OpenJDK i.e. JDK 16 and also provided the steps to write, compile, and execute the first Java program.