How to install Java on Windows — JDK 21 and VS Code ready in 10 minutes (and the “‘java’ is not recognized” almost everyone sees on day one)
Before writing your first line of Java you need a working environment. It sounds like paperwork, but it is exactly where half the class gets stuck in the first week of FP2: you download something called “Java”, type java --version, and Windows replies that it has no idea what you mean. Or java works but javac doesn’t. Or VS Code says it can’t find any JDK even though you have just installed one.
In this guide we install JDK 21 (and I’ll tell you when JDK 25 makes more sense), set up the PATH if needed, prepare VS Code with the official Java extension and check that everything works by compiling and running a real program. If you come from Python, you’ll also see why Java has two steps (compile and run) where Python had one. When you finish, the next step is Java from scratch: the syntax.
Table of Contents
What you need to install Java on Windows
- Windows 10 or 11, 64-bit (almost every laptop today). If your Windows runs on an ARM processor (some Surface and Snapdragon laptops), download the ARM64 version instead of x64.
- Administrator rights on your computer: the JDK installer and the PATH settings ask for them.
- About 500 MB free for the JDK and roughly the same for VS Code and its extensions.
- If you already installed VS Code for Python with the VS Code for Python guide, you can skip step 5.
Everything that depends on Windows (the installers, the Environment Variables windows, PowerShell) is described but I couldn’t run it for this update. What I did run, once, are the Java programs and commands at the end, with the same JDK 21: the output you’ll see there is real.
What the JDK is and why you need it
In Python you installed the interpreter: a program that reads your .py and runs it directly. Java works differently. You need the JDK (Java Development Kit), a kit with two main tools:
javac, the compiler: it reads yourHelloWorld.javaand translates it into bytecode, aHelloWorld.classfile that is not yet machine code for your processor but an intermediate language.java, which starts the JVM (Java Virtual Machine): the virtual machine that reads that bytecode and runs it on your computer, whether it’s Windows, Linux or macOS.
Look at the diagram: two commands, two different programs from the same JDK.
And the famous JRE? It was the part of the JDK that only runs programs (the JVM and the libraries, without javac). For years people downloaded it separately to “have Java” in the browser. Today it is no longer shipped on its own: to program you need the full JDK, and the JDK already includes everything.
Downloading “Java” from java.com. That is the end-user Java (only for running ready-made programs, and version 8). For FP2 you need the JDK, downloaded from Oracle or from Adoptium as in step 1.
Why JDK 21
Java releases a new version every six months, and every two years one of them is an LTS (Long-Term Support) release. In October 2026 this is the picture (I checked it on Oracle’s website):
| Version | Kind | For FP2? |
|---|---|---|
| JDK 27 | The newest one (September 2026) | Not needed: it’s a short-lived release |
| JDK 25 | Current LTS (September 2025) | Perfectly fine, and the one to pick if you’re starting from scratch outside class |
| JDK 21 | Previous LTS (September 2023) | The one this guide uses: everything in FP2 works the same |
Everything you’ll write in FP2 (classes, inheritance, interfaces, collections, exceptions) works the same on 21 and 25. What matters is that you use the version your course asks for and keep only one installed while you learn, so you don’t get confused about which one is running.
If you choose JDK 25, follow this same guide replacing “21” with “25” in the paths (jdk-25 instead of jdk-21). The steps are identical.
Step 1 — Download JDK 21
You have two options, both free for studying:
Option A: Oracle (the official one). Go to Oracle’s download page: https://www.oracle.com/java/technologies/downloads/#java21. In the JDK 21 tab, choose Windows and download the x64 Installer (the .exe). In October 2026 the file is called jdk-21.0.13.0.3_windows-x64_bin.exe; the number changes with every update, but what matters is the 21 at the start.

Since update 21.0.13, Oracle ships JDK 21 under its OTN licence: free for personal and development use (studying counts), but not for production use in a company. JDK 25, on the other hand, is still under the NFTC licence, free in production too until September 2028. For FP2 it makes no difference; if you’d rather forget about licences, use option B.
Option B: Eclipse Temurin (Adoptium), free and without fine print. Go to https://adoptium.net/temurin/releases/?version=21, choose Windows, x64, JDK and version 21, and download the .msi. It’s the same Java (both come from the OpenJDK project), built and tested by the Eclipse Foundation under a free licence. It’s what most companies use when they don’t want to depend on Oracle.

Both options work exactly the same for FP2. Pick one and don’t install both.
Step 2 — Install the JDK
Run the installer you downloaded:
- Double-click the
.exe(Oracle) or the.msi(Temurin). If Windows asks whether to allow the app to make changes, say yes. - Click Next. Keep the default installation folder: you’ll need it later and it’s easier if it’s the standard one.
- With Temurin you’ll see a features screen: if there is a Set JAVA_HOME variable option, tick it, and leave the PATH option ticked. That saves you step 4.
- Click Install, wait and finish with Close.

The JDK is installed in one of these folders (yours may have a longer version number at the end):
| Distribution | Folder | Where java.exe and javac.exe are |
|---|---|---|
| Oracle | C:\Program Files\Java\jdk-21 | C:\Program Files\Java\jdk-21\bin |
| Temurin | C:\Program Files\Eclipse Adoptium\jdk-21.0.x.x-hotspot | the bin folder inside |
Write down that bin path: it’s the one we’ll use if the PATH needs fixing.
Step 3 — Verify the installation
Close every terminal you had open (terminals opened before the installation don’t see the changes) and open a new one: search for PowerShell or cmd in the Start menu. Type:
java --version
With Oracle you should see something shaped like this (the exact numbers will be your version’s):
java 21.0.x 2026-xx-xx LTS Java(TM) SE Runtime Environment (build 21.0.x+x-LTS-xxx) Java HotSpot(TM) 64-Bit Server VM (build 21.0.x+x-LTS-xxx, mixed mode, sharing)
With Temurin the first line starts with openjdk 21.0.x and you’ll see Temurin in the other two. What you’re looking for is the 21 at the start. Check the compiler too, since it’s what really tells you that you have a JDK:
javac --version
And it should answer with the same version:
javac 21.0.x
And a trick that will save you more than once: ask Windows which java it is using.
where.exe java
In PowerShell you have to type where.exe (in cmd, where is enough). It returns the paths of every java.exe it finds, in order: the first one is the one that runs. If an old Java folder shows up there, now you know why java --version reports a different version.
'java' is not recognized as an internal or external command, operable program or batch file. Windows can’t find java.exe in any PATH folder. If you’ve just installed, close and reopen the terminal first; if it persists, go to step 4.
Step 4 — Set the PATH manually (only if step 3 failed)
The PATH is a list of folders. When you type java, Windows doesn’t search the whole disk: it walks those folders in order and runs the first java.exe it finds. If none has it, you get the error above. Look at the diagram:
So fixing it means adding one line to that list, the JDK bin folder:
- Press the Windows key and type environment variables. Open Edit the system environment variables.
- Click Environment Variables…
- Under System variables, select Path and click Edit…
- Click New and paste the
binpath you wrote down in step 2, for exampleC:\Program Files\Java\jdk-21\bin. - With Move Up, move that line above any other Java line (for example one ending in
Oracle\Java\javapathfrom an old installation). - While you’re there, create JAVA_HOME: under System variables, click New…, name
JAVA_HOME, value the JDK folder without\bin(C:\Program Files\Java\jdk-21). Many tools (Maven, Gradle, some IDEs) look for it. - Accept every window with OK, close the terminal, open a new one and repeat step 3.
Putting the JDK folder (…\jdk-21) in the PATH instead of its bin (…\jdk-21\bin). Windows looks inside each folder in the list, not in its subfolders: if java.exe is one level deeper, it won’t see it.
If you don’t know the exact path, open File Explorer, go to C:\Program Files, find the JDK folder, open bin, check that java.exe and javac.exe are inside, and copy the path from the address bar.
Step 5 — Install VS Code
If you already have VS Code from the Python block, skip this step. If not, go to https://code.visualstudio.com, download the Windows installer and run it. Accept the defaults and tick these three on the additional tasks screen:
- Add “Open with Code” action to Windows Explorer file context menu.
- Add “Open with Code” action to Windows Explorer directory context menu.
- Add to PATH.
With the first two you can right-click your FP2 folder and open it straight in VS Code; with the third you can type code . in a terminal.
Step 6 — Install the Java extension pack for VS Code
Freshly installed, VS Code is just a text editor with colours. To understand Java (autocompletion, red squiggles while you type, a run button and a debugger) it needs the official extension:
- Open VS Code.
- Click the Extensions icon in the left sidebar (or Ctrl + Shift + X).
- Search for Extension Pack for Java.
- Click Install on the one published by Microsoft.

The pack installs several extensions at once. In October 2026 they are these (the screenshot is from May and may show a slightly different list: Microsoft changes it from time to time):
| Extension | What it’s for in FP2 |
|---|---|
| Language Support for Java (Red Hat) | Autocompletion, errors as you type, go to definition. Essential |
| Debugger for Java | Breakpoints and step-by-step execution. Essential |
| Test Runner for Java | Running JUnit tests (you’ll see them later) |
| Maven for Java and Gradle for Java | Projects with dependencies; you’ll barely use them in FP2 |
| Project Manager for Java | The Java Projects panel with your classes and packages |
Step 7 — Configure VS Code for Java
The first time you open a .java file, the extension looks for the JDK by itself (it checks the PATH, JAVA_HOME and the usual folders). It almost always finds it. If not:
- Open the command palette with Ctrl + Shift + P.
- Type Java: Configure Java Runtime and open it.
- In the project JDK section, check that JDK 21 is listed. If it isn’t, use the option to add it and choose the JDK folder (the
C:\Program Files\…\jdk-21one, withoutbin).
This is the full map of what you’ve installed and who uses whom:
If VS Code complains that it can’t find Java but java --version works in the terminal, close VS Code completely and open it again: like the terminal, it only sees the PATH that existed when it started.
Step 8 — Create your working folder
Before writing code, organise where it’s going to live. A clear structure from day one saves you from hunting for “that arrays exercise” among twenty loose files on the Desktop:
Documents/
└── FP2/
├── java/
│ ├── unit1_syntax/
│ ├── unit2_variables/
│ └── ...
└── python/
└── ...
To open it in VS Code: File → Open Folder… → Documents\FP2\java → Select Folder. The left panel then shows all your units and the Java extension treats each folder as a project.
Check that everything works: your first program
Now the real test: compiling and running. In unit1_syntax, create a file named exactly HelloWorld.java (with capital H and W) and type this:
public class HelloWorld {
public static void main(String[] args) {
System.out.println("Hello, FP2: the JDK works");
System.out.println("Java " + Runtime.version().feature() + " ready to code");
}
}
Line by line, without going into detail yet (that’s the syntax article):
public class HelloWorld: in Java everything lives inside a class, and if it’spublicit must have the same name as the file.public static void main(String[] args): the entry point, the first thing the JVM runs.System.out.println(...): prints a line in the terminal.Runtime.version().feature(): asks the JVM for its major version. It’s a way to check, from inside the program, which Java is running it.
In VS Code you just click Run above main. But it’s worth doing it once by hand in the terminal to see the two steps. This is the real session, run once with JDK 21 (I ran it in a Linux terminal, which is why you see $ and ls; in PowerShell you’ll see PS C:\…> and can use dir, but javac and java behave the same):
$ ls
HelloWorld.java
bad
$ javac HelloWorld.java
$ ls
HelloWorld.class
HelloWorld.java
bad
$ java HelloWorld
Hello, FP2: the JDK works
Java 21 ready to code
$ java HelloWorld.class
Error: Could not find or load main class HelloWorld.class
Caused by: java.lang.ClassNotFoundException: HelloWorld.class
$ java HelloWorld.java
Hello, FP2: the JDK works
Java 21 ready to code
$ cd bad
$ javac Hello.java
Hello.java:1: error: class HelloWorld is public, should be declared in a file named HelloWorld.java
public class HelloWorld {
^
1 error
Step by step:
- Before compiling there’s only
HelloWorld.java(and abadfolder I use at the end). javac HelloWorld.javaprints nothing when everything goes well: in Java, as in C, silence is good news. But the secondlsshows what it did:HelloWorld.class, the bytecode, has appeared.java HelloWorldruns the class. Careful: you type the class name, without.class. And the second line confirms that a Java 21 ran it.java HelloWorld.classis the most repeated mistake on day one: Java readsHelloWorld.classas the name of a class (a class calledclassin a package calledHelloWorld) and can’t find it.java HelloWorld.java(since Java 11) compiles in memory and runs in one go, without leaving any.class. Handy for single-file programs like the first ones in FP2.- The
badfolder contains aHello.javaholdingpublic class HelloWorld.javacrefuses: a public class has to live in a file with its own name.
Saving the file as helloworld.java or Hello world.java. The Windows file system doesn’t care about capitals, but Java does: the file name must match the public class name exactly, capitals included.
Understanding the basic structure
In Python you typed python file.py and that was it. In Java the road has two stops:
| Python | Java | |
|---|---|---|
| What you install | The interpreter (python) | The JDK (javac + java) |
| Steps | One: python hello.py | Two: javac HelloWorld.java and java HelloWorld |
| What gets generated | Nothing you need to touch | HelloWorld.class (bytecode) |
| When you see syntax errors | When running, as it reaches that line | When compiling, before anything runs |
| File name | Whatever you like | The public class’s, exactly |
That fourth row is the big advantage of compiling: if you’re missing a ; on line 40, javac tells you before running the first 39. VS Code does both steps when you click Run, but if there’s a compilation error no .class is created and there’s nothing to run.
Troubleshooting — “java is not recognized”
'java' is not recognized as an internal or external command. Windows can’t find java.exe in the PATH. Close and reopen the terminal; if it persists, step 4.
java works but javac doesn’t. You have a Java that isn’t a full JDK (an end-user Java from java.com) or the PATH points to a folder that only has java.exe (such as …\Oracle\Java\javapath). Run where.exe java and where.exe javac: both must come from the same JDK 21 bin folder.
java --version says 1.8, 17 or another version. An old Java comes first in the PATH. where.exe java shows which one; move the JDK 21 line up in the PATH (step 4) or uninstall the old one from Settings → Apps.
Error: Could not find or load main class HelloWorld.class. You typed .class when running. It’s java HelloWorld.
class HelloWorld is public, should be declared in a file named HelloWorld.java. The file name doesn’t match the class name. Rename the file (or the class).
VS Code says it can’t find the JDK or that the version is too old. Close VS Code and open it again; if it persists, Java: Configure Java Runtime (step 7) and choose the JDK 21 folder.
VS Code’s Run doesn’t appear above main. The extension is still loading (check the bottom bar) or the file isn’t inside the folder you opened with Open Folder.
Quick summary
| Piece | What for | How to check it |
|---|---|---|
| JDK 21 (Oracle or Temurin) | javac compiles, java runs on the JVM | java --version and javac --version |
PATH with …\jdk-21\bin | So the terminal finds java and javac | where.exe java |
| JAVA_HOME | So other tools find the JDK | echo $env:JAVA_HOME in PowerShell |
| VS Code + Extension Pack for Java | Writing, running and debugging | The Run button above main |
Documents\FP2\java\ | Keeping units tidy | Opened with Open Folder |
Three ideas to take away:
- To program in Java you need the JDK, not just “Java”:
javaccompiles andjavaruns. - If Windows can’t find
java, the problem is almost always the PATH: it must include the JDKbinfolder.where.exe javatells you which one is used. - The file is named exactly like the public class, and you run it with
java HelloWorld, without.class.
With the environment ready, the next step is understanding what every word in that HelloWorld means: we cover it in Java from scratch: the syntax, where we write the first FP2 program line by line.
Did this article help you? Here is how you can support SergioLearns →




What is an operating system — theory with your laptop on a study afternoon, a write() call and a CPU that never rests (and the three programs that weren’t running at the same time)