How to Install Java on Windows?
The purpose of this tutorial is to show you how to install Java on Windows.
- 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:
- By typing cmd into the search bar, you will be able to open a command prompt.
- You can run the following command:
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.
Install the latest Java Development Kit for Windows 10 to get the latest features and bug fixes.
- You can download Oracle Java using your preferred web browser.
- 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.
The download will take a few minutes to complete depending on your internet connection speed.
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.
- Specify the location for the Java installation files or stick with the default. Proceed by clicking Next.
- You will see the Successfully Installed message after the wizard has completed the installation process. To exit the wizard, click Close.
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.
- Under the Advanced tab of the System Properties window, click Environment Variables.
- Click Edit on the Path variable under the System variables category:
- Enter the path to the Java bin directory by clicking the New button:
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.
- The variable should be named JAVA_HOME.
- Put the path to your Java JDK directory into the variable value field and click OK.
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:
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:
- Create a new file in a text editor such as Notepad++.
- Please enter the following code and click Save:
Example:Test Your Java installation on Windows
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.
To compile the program, change the directory to the file’s location and use the following syntax:
After a successful compilation, the program generates a .class file in the file directory.
A .class file is generated in the file directory after successful compilation.
The following syntax should be used to run the program:
The output will shows that the program runs correctly, displaying the This is my first Java Program message.