How to install Java on Windows?


Java Installation Tutorial on Windows

To install Java on Windows and run Java applications on Microsoft’s operating system, you must obtain a copy of the Java Development Toolkit (JDK) installation media.

The JDK includes both a Java Runtime Environment (JRE) and a Java Virtual Machine (JVM), which is all you need to play games like Minecraft or run apps like NASA World Wind after the installing java.

The JDK also includes a number of programming tools, like a compiler and a web server, so that programmers who need to install Java on Windows can also meet all their development needs.

Prerequisites for installing the JDK on Windows

This Java installation tutorial assumes that these prerequisites are met:

  • You are using an updated Windows 10 or Windows 11 operating system
  • You have internet access to be able to download the Java JDK
  • You have sufficient rights to download the JDK and install Java on your computer

Which Java distribution should I choose?

Many companies, including Oracle, Azul, Amazon, and Microsoft, provide their own Java installers, all based on the OpenJDK open source project.

The easiest JDK to install comes from Eclipse’s Adoptium project (formerly AdoptOpenJDK).

The Adoptium JDK has the most permissive open source license, which is another reason why I recommend this JDK to anyone installing Java on Windows for the first time.

How to Install Java on Windows

Follow these five steps to configure and install Java on Windows:

  1. Download Java for Windows
  2. Run the Java installer
  3. Validate the JAVA_HOME parameter
  4. Check that the Java PATH variable has been set correctly
  5. Run a JDK command to verify that the Java installation was successful

Download Java for Windows

You can download the latest recommended version of Java directly from the Eclipse Adoptium Homepage. At the time of writing, this means downloading Java 17.

The Adoptium Java download is packaged as a .msi file of just over 160 MB.

To install Java on Windows, you must first download the JDK.

Run the Windows Java Installer

The Java installation wizards allow you to customize the JDK installation in five different ways. You can choose:

  • Where to Install Java on Your Windows Computer
  • If you want to add Java to the Windows PATH
  • If you want Java to automatically run JAR files
  • If you want to set the JAVA_HOME environment variable
  • If you want to configure JavaSoft registration keys

On a Windows computer with one GB of free memory, an SSD hard drive and an i5 processor, the Java Setup Wizard will complete setup in less than a minute.

install java on windows setup

When setting up Java on Windows, change the installation folder and choose to set JAVA_HOME.

Where to install Java on Windows?

By default, Java installs in a subdirectory of C:Program Files.

The space between words Program and Files can sometimes cause errors in scripts, that’s why I don’t recommend installing Java in this folder.

I recommended that the Java install directory be changed to something like:

  • C:tooljdk17
  • C:jdk17
  • C:javaversion17
Java Setup and Installation Options for Windows
Installation options Default Recommendation
Installation directory C:Program Files Any custom folder without spaces or non-text characters
Add Java to PATH Yes Yes
Associate .jar files Yes Yes
Set JAVA_HOME variable Nope Yes
Configure JavaSoft keys Nope Nope

Set the Java PATH

When the installer configures the Java PATH environment variable, all utilities that are part of the JDK can be called by name in a DOS prompt or in PowerShell.

This makes it very easy for developers to use JDK tools such as the Java compiler and Java Shell, so it is highly recommended to allow the setup wizard to configure the Java path.

Configure JAVA_HOME

When programs like Mincraft or Tomcat run on Java, they query Windows for the JAVA_HOME environment variable to find out where Java is installed.

As with Java PATH, it is recommended to allow the Java install wizard to configure the JAVA_HOME environment variable for you.

Not all Java installers set these environment variables. If you need to configure these settings manually, follow these tutorials to configure JAVA_HOME or set the Java PATH.

steps to configure java on windows

Here are the steps to follow to install Java on Windows and validate the installation.

Validate JAVA_HOME on Windows

Use PowerShell or Windows Command Prompt to verify that the JAVA_HOME environment variable has been set correctly.

To view the JAVA_HOME variable in the command prompt, run the following command:

C:>echo %JAVA_HOME%

PowerShell command to echo JAVA_HOME

The command to echo JAVA_HOME in Windows Powershell is:

PS C:> echo $env:JAVA_HOME

Whether you echo JAVA_HOME with Powershell or at the DOS prompt, the output should be the root folder where you installed Java.

Echo JAVA_HOME on PowerShell

Here is the command to echo JAVA_HOME on Microsoft PowerShell.

Confirm Java PATH configuration

After validation of JAVA_HOME, the PATH parameter of Java must be confirmed.

As with JAVA_HOME, the Windows PATH setting can be passed to the command line.

Run the following command to display the PATH in a command prompt:

C:>echo %PATH%
C:_toolsjdk-17bin; C:WINDOWSsystem32; C:WINDOWS;

The following commands generate the Windows PATH in PowerShell:

PS C:> echo $env:PATH
C:_toolsjdk-17bin;  C:WINDOWSsystem32;  C:WINDOWS;

If the full path to the trash can JDK installation folder is listed, it means that Windows PATH for Java has been configured correctly.

Run Java on Windows

The last step to confirm that the installation of Java on Windows was successful is to run a Java command and see if it works.

The easiest way to do this is to ask the JDK which version of Java is installed. In PowerShell, it looks like this:

PS C:> java -version
openjdk version "17.0.3" 2022-04-19
OpenJDK Runtime Environment Temurin-17.0.3+7 (build 17.0.3+7)
OpenJDK 64-Bit Server VM Temurin-17.0.3+7 (build 17.0.3+7, mixed mode, sharing)

As you can see, we have successfully configured and installed Java 17 on Windows.

run java on windows

To run Java applications on Windows 10, install the JDK and set JAVA_HOME.

Installing Java 17 and Windows 10

And it’s that easy to install Java on Windows.

All that remains is to run applications like Minecraft or Tomcat on the JRE, and remember to update the JDK when a new LTS version of Java arrives.


Comments are closed.