How to Install Java on Windows {Step-by-Step Guide} – phoenixNAP

The

Java

Development Kit (JDK) is software used for Java programming, along with the Java Virtual Machine (JVM) and Java Runtime Environment (JRE). The JDK includes the compiler and class libraries, allowing developers to create Java programs executable by JVM and JRE.

In this tutorial, you will learn how to install Java Development Kit on Windows.

How to install Java on Windows.

Prerequisites

  • A system running Windows 10
  • .

  • A network connection
  • .

  • Administrator privileges.

Check if Java is

installed

Before installing the Java Development Kit, check if a version of Java is already installed on Windows. Follow the steps below

:

  1. Open a command prompt by typing cmd in the search bar and press Enter
  2. .

  3. Run the following command:

java -version

The command generates the version of Java on the system. If Java is not installed, the result is a message stating that Java is not recognized as an internal or external command.

Download Java for Windows 10

Download the latest installation file for the Java Development Kit for Windows 10 for the latest features and bug fixes

.

  1. Using your preferred web browser, go to the Oracle Java downloads
  2. page.

  3. On the Downloads page, click the x64 installer download link under the Windows category. At the time of writing, Java version 17 is the last version of Java for long-term support.

Wait for the download to complete.

Install Java on Windows

10

After downloading the installation file,

proceed with the installation of Java on your Windows system

.

Follow the steps below

: Step 1: Run the downloaded file

Double-click the downloaded file to start the

installation.

Step 2: Configure

the installation wizard After you run the installation

file

, the Welcome screen of the installation wizard appears

.

1. Click Next to proceed to the next step.

2. Choose the destination folder for the Java installation files or stick to the default path. Click Next to continue.

3. Wait for the wizard to finish the installation process until the message Installed successfully appears. Click Close to exit the wizard.

Set environment variables in Java

Set Java environment variables to allow compilation of programs from any directory. To do so, follow the steps below

:

Step 1: Add Java to System Variables 1

. Open the Start menu and search for environment variables.

2. Select the Edit system environment variables result.

3. In the System Properties window, on the Advanced tab, click Environment Variables…

4. In the System Variables category, select the Path variable and click Edit:

5. Click the New button and enter the path to the Java bin directory:

6. Click OK to save your changes and exit the variable editing window.

Step 2: Add

JAVA_HOME variable

Some applications require the JAVA_HOME variable. Follow the steps below to create the variable:

1. In the Environment Variables window, in the System Variables category, click the New… button to create a new variable.

2. Name the variable JAVA_HOME.

3. In the variable value field, paste the path to your Java jdk directory and click OK.

4. Confirm the changes by clicking OK in the Environment Variables and System Properties windows.

Test your Java installation

Run the

java –version command at the command prompt to ensure that Java has been installed correctly:

If installed successfully, the command generates the Java version. Make sure everything works by writing a simple program and compiling it. Follow the steps below

: Step 1

: Write a Test Java Script 1

. Open a text editor such as Notepad++ and create a new file.

2. Enter the following lines of code and click Save:

class HelloWorld{ public static void main(String args[]){ System.out.println(“Hello world!”); } }

3. Name the file and save it as Java source file (*.java).

Step 2: Compile the test Java script

1. At the command prompt, change the directory to the file location and use the following syntax to compile

the program: javac [file name]

For example:

After a successful build, the program generates a .class file in the file directory

.

2. Run the program with the following syntax:

java [file name]

The output shows that the program runs successfully, displaying the message Hello world! Conclusion

This tutorial showed how to install Java Development Kit on a Windows system. If you’re interested in learning more about Java, read our list of the 13 best Java IDEs for writing, debugging, and testing Java code.