Install On Windows 11
Install On Windows 11
A school program needs reliable data and clear rules. A Windows JDK provides both the Java runtime and compiler. After installation, open a fresh terminal and check their versions before using an editor.
Understand
A Windows JDK provides both the Java runtime and compiler.
Apply
Trace the Java example, predict its output and explain the result before running it.
Avoid mistakes
Several installed JDKs can make PATH choose a different version from your editor. Check the tools actually being used.
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
binfolder 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
Java · example discussed here
public class HelloWorld {
public static void main(String[] args) {
System.out.println("Java is successfully installed!");
}
}
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
javaorjavacis not recognized, recheck yourPathenvironment variable. - Ensure there are no spaces or typos in the folder path.
- Restart Command Prompt or your system after updating environment variables.
Important boundaries and mistakes
Several installed JDKs can make PATH choose a different version from your editor. Check the tools actually being used.
Try the school example
Before running this Java program, write down each line you expect to see. Identify the value, branch, object or exception responsible for each line. Then explain whether the following assumption is valid: Several installed JDKs can make PATH choose a different version from your editor.
Java 17 · Main.java · complete practice program
public class Main {
public static void main(String[] args) {
System.out.println(System.getProperty("java.specification.version"));
}
}
Worked answer and reasoning
Java 17 · Main.java · source repeated for this answer
public class Main {
public static void main(String[] args) {
System.out.println(System.getProperty("java.specification.version"));
}
}
Expected output on the Java 17 teaching runtime; your installed version can differ
17A Windows JDK provides both the Java runtime and compiler. After installation, open a fresh terminal and check their versions before using an editor.
Several installed JDKs can make PATH choose a different version from your editor. Check the tools actually being used.
Run with javac Main.java, then java Main. The declaration of Main names the class; main starts the example, and println writes a complete output line.
Check your understanding
What to remember
A Windows JDK provides both the Java runtime and compiler. After installation, open a fresh terminal and check their versions before using an editor. Several installed JDKs can make PATH choose a different version from your editor. Check the tools actually being used.
Related explanations: Java Variables, Java If Statement - Syntax and Examples, Java Class - Blueprint of Objects, Exceptions in Java Introduction.
Supporting documentation: Official Java learning guide and Java 17 language specification.
Reaching the recap and completing the quizzes are separate milestones.