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.

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 your HelloWorld.java and translates it into bytecode, a HelloWorld.class file 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.

How a Java program goes from code to runningHelloWorld.java goes through javac and becomes HelloWorld.class (bytecode); the java command starts the JVM, which runs it and prints to the screen. The JDK bundles javac, the JVM and the libraries.From HelloWorld.java to the screenHelloWorld.javasource codeHelloWorld.classbytecodeJVMruns itScreenHello, FP2:the JDKworksjavacjavaJDK 21 = javac (compiler) + JVM (virtual machine) + librariesPython had a single step: python file.pyShortcut (Java 11+): java HelloWorld.java compiles in memory and runs in one go
Two commands, two JDK programs: javac translates to bytecode and java runs it on the JVM.

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):

VersionKindFor FP2?
JDK 27The newest one (September 2026)Not needed: it’s a short-lived release
JDK 25Current LTS (September 2025)Perfectly fine, and the one to pick if you’re starting from scratch outside class
JDK 21Previous 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.

Oracle download page with the JDK 21 tab, the Windows option and the x64 Installer link

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.

Eclipse Temurin download page on Adoptium with the Windows, x64, JDK and version 21 filters

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:

  1. Double-click the .exe (Oracle) or the .msi (Temurin). If Windows asks whether to allow the app to make changes, say yes.
  2. Click Next. Keep the default installation folder: you’ll need it later and it’s easier if it’s the standard one.
  3. 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.
  4. Click Install, wait and finish with Close.
JDK 21 installation wizard on Windows with the Next button

The JDK is installed in one of these folders (yours may have a longer version number at the end):

DistributionFolderWhere java.exe and javac.exe are
OracleC:\Program Files\Java\jdk-21C:\Program Files\Java\jdk-21\bin
TemurinC:\Program Files\Eclipse Adoptium\jdk-21.0.x.x-hotspotthe 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:

Searching for java.exe in the PATHWhen you type java, Windows walks the PATH folders in order: system32 does not have it, the JDK 21 bin folder does, so it runs that java.exe. If none has it you get "is not recognized as an internal or external command".How Windows finds the java command> java –versionYou type in the terminalPATH folders, in order1C:\Windows\system32not here2C:\Program Files\Java\jdk-21\binjava.exe is here!3…\Microsoft VS Code\binno need to lookIf no folder has it, Windows answers:'java' is not recognized as an internal or external command…
Step 4 of the guide just adds one line to this list: the JDK bin folder.

So fixing it means adding one line to that list, the JDK bin folder:

  1. Press the Windows key and type environment variables. Open Edit the system environment variables.
  2. Click Environment Variables…
  3. Under System variables, select Path and click Edit…
  4. Click New and paste the bin path you wrote down in step 2, for example C:\Program Files\Java\jdk-21\bin.
  5. With Move Up, move that line above any other Java line (for example one ending in Oracle\Java\javapath from an old installation).
  6. 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.
  7. 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:

  1. Open VS Code.
  2. Click the Extensions icon in the left sidebar (or Ctrl + Shift + X).
  3. Search for Extension Pack for Java.
  4. Click Install on the one published by Microsoft.
VS Code extensions panel with Microsoft's Extension Pack for Java and its Install button

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):

ExtensionWhat it’s for in FP2
Language Support for Java (Red Hat)Autocompletion, errors as you type, go to definition. Essential
Debugger for JavaBreakpoints and step-by-step execution. Essential
Test Runner for JavaRunning JUnit tests (you’ll see them later)
Maven for Java and Gradle for JavaProjects with dependencies; you’ll barely use them in FP2
Project Manager for JavaThe 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:

  1. Open the command palette with Ctrl + Shift + P.
  2. Type Java: Configure Java Runtime and open it.
  3. 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-21 one, without bin).

This is the full map of what you’ve installed and who uses whom:

Java installation mapThree pieces: the JDK in Program Files with javac.exe and java.exe in its bin folder; VS Code with the Extension Pack for Java, which uses that JDK; and your FP2 folder in Documents with the .java files.What gets installed and whereJDK 21 (Oracle or Temurin)C:\Program Files\Java\jdk-21\bin\javac.exe · java.exeVS Code+ Extension Packfor Javaedit · Run · debugYour FP2 folderDocuments\FP2\java\unit1_syntax\HelloWorld.javaVS Code uses the JDK javac and javaand opens your folderPATH points to …\jdk-21\bin so the terminal can find them too
If VS Code cannot find the JDK, the problem is the left arrow (step 7).

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’s public it 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:

  1. Before compiling there’s only HelloWorld.java (and a bad folder I use at the end).
  2. javac HelloWorld.java prints nothing when everything goes well: in Java, as in C, silence is good news. But the second ls shows what it did: HelloWorld.class, the bytecode, has appeared.
  3. java HelloWorld runs the class. Careful: you type the class name, without .class. And the second line confirms that a Java 21 ran it.
  4. java HelloWorld.class is the most repeated mistake on day one: Java reads HelloWorld.class as the name of a class (a class called class in a package called HelloWorld) and can’t find it.
  5. 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.
  6. The bad folder contains a Hello.java holding public class HelloWorld. javac refuses: 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:

PythonJava
What you installThe interpreter (python)The JDK (javac + java)
StepsOne: python hello.pyTwo: javac HelloWorld.java and java HelloWorld
What gets generatedNothing you need to touchHelloWorld.class (bytecode)
When you see syntax errorsWhen running, as it reaches that lineWhen compiling, before anything runs
File nameWhatever you likeThe 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

PieceWhat forHow to check it
JDK 21 (Oracle or Temurin)javac compiles, java runs on the JVMjava --version and javac --version
PATH with …\jdk-21\binSo the terminal finds java and javacwhere.exe java
JAVA_HOMESo other tools find the JDKecho $env:JAVA_HOME in PowerShell
VS Code + Extension Pack for JavaWriting, running and debuggingThe Run button above main
Documents\FP2\java\Keeping units tidyOpened with Open Folder

Three ideas to take away:

  1. To program in Java you need the JDK, not just “Java”: javac compiles and java runs.
  2. If Windows can’t find java, the problem is almost always the PATH: it must include the JDK bin folder. where.exe java tells you which one is used.
  3. 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.

Keep goingAll Tools articles

Did this article help you? Here is how you can support SergioLearns →

Sigue aprendiendo

Leave a Reply

Your email address will not be published. Required fields are marked *