Introduction
The Java Development Kit (JDK) is software used for Java programming, along with the Java Virtual Machine (JVM) and the Java Runtime Environment (JRE). The JDK includes the compiler and class libraries, allowing developers to create Java programs executable by the JVM and JRE.
In this tutorial, you will learn to install the Java Development Kit on Windows.
Prerequisites
- A system running Windows 10.
- A network connection.
- Administrator privileges.
- Open a command prompt by typing cmd in the search bar and press Enter.
- Run the following command:
java -version
Download the latest Java Development Kit installation file for Windows 10 to have the latest features and bug fixes.
- Using your preferred web browser, navigate to the Oracle Java Downloads page.
- On the Downloads page, click the x64 Installer download link under the Windows category. At the time of writing this article, Java version 17 is the latest long-term support Java version.
Wait for the download to complete.
After downloading the installation file, proceed with installing Java on your Windows system.
Follow the steps below:
Double-click the downloaded file to start the installation.
After running the installation file, the installation wizard welcome screen appears.
- Click Next to proceed to the next step.
- Choose the destination folder for the Java installation files or stick to the default path. Click Next to proceed.
- Wait for the wizard to finish the installation process until the Successfully Installed message appears. Click Close to exit the wizard.
Set Java environment variables to enable program compiling from any directory. To do so, follow the steps below:
-
Open the Start menu and search for environment variables.
-
Select the Edit the system environment variables result.
- In the System Properties window, under the Advanced tab, click Environment Variables…
- Under the System variables category, select the Path variable and click Edit:
- Click the New button and enter the path to the Java bin directory:
Note: The default path is usually C:\Program Files\Java\jdk-17.0.1\bin.
- Click OK to save the changes and exit the variable editing window.
Some applications require the JAVA_HOME variable. Follow the steps below to create the variable:
- In the Environment Variables window, under the System variables category, click the New… button to create a new variable.
-
Name the variable as JAVA_HOME.
-
In the variable value field, paste the path to your Java jdk directory and click OK.
- Confirm the changes by clicking OK in the Environment Variables and System properties windows.
Run the java -version
command in the command prompt to make sure Java installed correctly:
If installed correctly, the command outputs the Java version. Make sure everything works by writing a simple program and compiling it. Follow the steps below:
-
Open a text editor such as Notepad++ and create a new file.
-
Enter the following lines of code and click Save:
class HelloWorld{
public static void main(String args[]){
System.out.println("Hello world!");
}
}
Name the file and save it as a Java source file (*.java).
Note: When using Notepad, select All files for the Save as type option and add the .java extension to the file name.
- In the command prompt, change the directory to the file's location and use the following syntax to compile the program:
javac [filename]
For example:
After a successful compilation, the program generates a .class file in the file directory.
- Run the program with the following syntax:
java [filename]