How do I install Java on Windows? – | Hot Mobile Press

Instructions for installing Java on Windows

To install Java on Windows and run Java apps on Microsoft’s operating system, you need 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). That’s all you need to play games like Minecraft or run applications like NASA World Wind.

The JDK also includes a set of programming tools, such as a compiler and a Java web server, for programmers who need to install Java on Windows.

Install prerequisites

The following requirements must be met to download and install Java on Windows:

  • You are using an updated Windows 10 or Windows 11 operating system (OS);
  • You can access the Internet to download Java’s JDK;
  • You have sufficient rights to download the JDK and install Java on your computer; and
  • You have at least 500 MB of hard disk space available for both the download and the installation

Which Java distribution should I choose?

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

The easiest JDK to install is 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 set up and install Java on Windows:

    1. Download Java for Windows
    2. Run the Java installer
    3. Validate the JAVA_HOME setting
    4. Confirm 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 Java version directly from the Eclipse Adoptium home page. At the time of writing this is Java 17.

Adoptium’s Java download is available as .msi File that is just over 160MB in size.

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
  • add java to windows PATH
  • Allow Java to run JAR files automatically
  • Set the JAVA_HOME environment variable
  • Configure JavaSoft registry keys

On a Windows machine with 1 GB of free memory, an SSD hard drive and an i5 CPU, the Java installation wizard completes the setup in less than a minute.

Java installation in Windows setup

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

Where do I install Java on Windows?

By default, Java is installed in a subdirectory of C:\Programs. The space between the words program and files can sometimes break scripts, so I don’t recommend installing Java in this folder.

Instead, I recommended changing the Java installation directory to something like this:

  • C:\tool\jdk17
  • C:\jdk17\
  • C:\java\Version\17
Java setup and installation options for Windows
install option default recommendation
install directory C:\Programs\ Any custom folder with no spaces or non-text characters
Add Java to PATH Yes Yes
Associate .jar files Yes Yes
Set the JAVA_HOME variable no Yes
Configure JavaSoft key no no

Set the Java PATH

If 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 including the Java compiler and Java shell. For this reason it is strongly recommended to allow the installation wizard to configure the Java path.

Configure JAVA_HOME

When programs like Minecraft or Tomcat run on Java, they ask 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 installer wizard to configure the JAVA_HOME environment variable for you.

Not all Java installers configure these environment variables. If you need to configure these settings manually, follow these instructions for configuring JAVA_HOME or setting the Java PATH.

Steps to set up Java on Windows

Follow these steps to set up Java on Windows and validate the installation.

Validate JAVA_HOME on Windows

Use either PowerShell or the Windows command prompt to verify that the JAVA_HOME environment variable is set correctly.

Issue the following command to view the JAVA_HOME variable in the command prompt:

C:\>echo %JAVA_HOME%

PowerShell command to echo JAVA_HOME

The command to echo JAVA_HOME in Windows Powershell is as follows:

PS C:\> echo $env:JAVA_HOME

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

Echo JAVA_HOME on PowerShell

The command to echo JAVA_HOME in Microsoft PowerShell uses the $env notation.

Confirm the Java PATH configuration

After validating JAVA_HOME, the PATH setting of Java should be confirmed.

As with JAVA_HOME, the Windows PATH setting can be printed on the command line. Issue the following command to view the PATH in a command prompt:

C:\>echo %PATH%
C:\_tools\jdk-17\bin; C:\WINDOWS\system32; C:\WINDOWS;

The following commands print the Windows PATH in PowerShell:

PS C:\> echo $env:PATH
C:\_tools\jdk-17\bin;  C:\WINDOWS\system32;  C:\WINDOWS;

If the full path to the container folder of the JDK installation is listed, then the Windows PATH for Java has been correctly configured.

Run Java on Windows

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

The easiest way to do this is to ask the JDK what 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 set up and installed Java 17 on Windows.

Run Java on Windows 10

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

Install Java 17 and Windows 10

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

All you have to do is run applications like Minecraft or Tomcat on the JRE and update the JDK when a new LTS version of Java arrives.

Leave a Comment