How to Install Java on Windows?

The purpose of this tutorial is to show you how to install Java on Windows.

Requirements

  • Windows 10 is installed on the system.
  • Connection to a network.
  • Privileges as an administrator.

Check if Java Is Installed

Check if a Java version is already installed on Windows before installing the Java Development Kit. Here are the steps you need to follow:

  1. By typing cmd into the search bar, you will be able to open a command prompt.
  2. You can run the following command:
java -version
check java version through cmd 1

This command displays the Java version on your system. In the absence of Java, a message states that Java is not recognized either internally or externally.

Note: To install Java on another system, see our tutorials on how to install Java on Ubuntu and Mac operating system.



Download Java

Install the latest Java Development Kit for Windows 10 to get the latest features and bug fixes.

  1. You can download Oracle Java using your preferred web browser.
  2. Go to Downloads and click the Windows category link to download the x64 installer. Java version 17 is the most stable long-term supported Java version as of the writing of this article.
download java on windows step1

The download will take a few minutes to complete depending on your internet connection speed.

downloading java for windows

Install Java on Windows

Once you have downloaded the installation file, you can install Java on your Windows system.

The following steps should be followed:

Run Downloaded File Step 1:

Start the installation by double-clicking the downloaded Java file.

Configure Installation Wizard Step 2:

The installation wizard welcome screen appears after running the installation file.

  • To proceed to the next step, click Next.
install java on windows step1

 

  • Specify the location for the Java installation files or stick with the default. Proceed by clicking Next.
install java on windows step2
  • You will see the Successfully Installed message after the wizard has completed the installation process. To exit the wizard, click Close.
install java on windows step3

Set JAVA Environmental Variables

You just install java on your windows machine the next step is to setup JAVA Environmental Variables on your machine.

Java environment variables can be set to enable program compilation from any directory. In order to do so, follow these steps:

Add Java to System Variables Step 1:

  • Search for environment variables on the Start menu.
  • Choose Edit the system environment variables.

search environment variables

  • Under the Advanced tab of the System Properties window, click Environment Variables.
install java on windows env variables1
  • Click Edit on the Path variable under the System variables category:
install java on windows env variables2
  • Enter the path to the Java bin directory by clicking the New button:
install java on windows env variables4

Reminder: By default, the path is C:\Program Files\Java\jdk-17.0.1\bin.

Save your changes and exit the variable editing window by clicking OK.


Add JAVA_HOME Variable Step 2:

There are some applications that require the JAVA_HOME variable. You can create the variable by following the steps below:

  • Click the New button under the System variables category in the Environment Variables window.
install java on windows env variables5
  • The variable should be named JAVA_HOME.
  • Put the path to your Java JDK directory into the variable value field and click OK.

install java on windows env variables6

Ensure that the changes are accepted by clicking OK in the Environment Variables and System Properties windows.


Test Java Installation

To verify that Java is correctly installed, run the java -version command at the command prompt:

check java version Windows

The command outputs the Java version if it has been installed correctly. Write a simple program and compile it to verify that everything works. The following steps should be followed:

Write a Java Code:

  1. Create a new file in a text editor such as Notepad++.
  2. Please enter the following code and click Save:

Example:Test Your Java installation on Windows

class Main{ public static void main(String args[]){ System.out.println("This is my first Java Program "); } }

The file should be named and saved as a Java source file (*.java).

Reminder : Using Notepad, add the .java extension to the file name and choose All files for the Save as type option.


Step 2: Compile Test Java Code

To compile the program, change the directory to the file’s location and use the following syntax:

javac [filename]

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

For example,

A .class file is generated in the file directory after successful compilation.

The following syntax should be used to run the program:

java [filename]

The output will shows that the program runs correctly, displaying the This is my first Java Program message.

Well done! Now you know how to install Java on Windows For more examples, see our article Java basics.
We value your feedback.
+1
0
+1
0
+1
0
+1
0
+1
0
+1
0
+1
0

Subscribe To Our Newsletter
Enter your email to receive a weekly round-up of our best posts. Learn more!
icon

Leave a Reply

Your email address will not be published. Required fields are marked *