Install Java on Windows 11
This tutorial will walk you through installing the Java Development Kit (JDK) on a Windows 11 machine.
Step 1: Download the Java JDK
Visit the official Oracle website to download the latest version of the JDK:
https://www.oracle.com/java/technologies/javase-downloads.html
Choose the version labeled “Windows x64 Installer” under the latest Java SE version. Click to download the .exe
installer file.
Step 2: Install the JDK
- Run the downloaded installer.
- Click “Next” on the welcome screen.
- Choose the installation location (default is usually fine) and click “Next.”
- Installation begins. Wait for it to complete and click “Close.”
Java is now installed, but we still need to configure it so your system knows how to find Java tools.
Step 3: Set Up Environment Variables
To make Java accessible from the command line, you need to add it to your system's environment variables:
- Search for "Environment Variables" in the Windows Start menu and open it.
- Under “System Properties,” click Environment Variables.
- In the “System Variables” section, find and select
Path
, then click Edit. - Click New and add the path to the
bin
folder inside your JDK installation. (e.g.,C:\Program Files\Java\jdk-21\bin
) - Click OK on all windows to save the changes.
Step 4: Verify the Installation
Open Command Prompt and type the following commands:
java -version
java version "21.0.1" 2024-10-17 LTS
Java(TM) SE Runtime Environment (build 21.0.1+12-LTS-123)
Java HotSpot(TM) 64-Bit Server VM (build 21.0.1+12-LTS-123, mixed mode)
javac -version
javac 21.0.1
If you see version numbers instead of errors, congratulations! Java is successfully installed and configured.
Step 5: Write Your First Java Program
Let’s test your Java setup by writing a simple program.
Create a file called HelloWorld.java
using any text editor (like Notepad).
public class HelloWorld {
public static void main(String[] args) {
System.out.println("Java is successfully installed!");
}
}
Step 6: Compile and Run the Program
Open Command Prompt in the directory where your HelloWorld.java
file is saved and run:
javac HelloWorld.java
This command compiles your Java code. If successful, it will generate a HelloWorld.class
file (the bytecode).
Now run the compiled program:
java HelloWorld
Java is successfully installed!
Perfect! You’ve just written and executed your first Java program.
Troubleshooting Tips
- If
java
orjavac
is not recognized, recheck yourPath
environment variable. - Ensure there are no spaces or typos in the folder path.
- Restart Command Prompt or your system after updating environment variables.