Typing java -version or trying to run a .jar file and getting “‘java’ is not recognized as an internal or external command, operable program or batch file” doesn’t mean Java is broken, or even that it’s missing. Nine times out of ten, Java is sitting on your drive just fine — Windows simply doesn’t know where to look for it. Here’s why that happens and the fix that actually sticks, instead of working for one Command Prompt session and then breaking again the next time you reboot.
Why This Actually Happens
When you type a command, Windows doesn’t search your whole drive for a matching program — it only checks the folders listed in a system variable called PATH. If the folder containing java.exe isn’t in that list, Windows reports the command as unrecognized, even though the file exists a few clicks away in File Explorer. Some Java installers add this entry automatically; manual OpenJDK installs or ZIP-file distributions usually leave it up to you. A sneakier second cause: PATH is read once when a terminal window opens, so if you edited it after that window was already open, it’s still working from the old list — reopening the terminal, not just re-running the command, is part of the fix.
Step 1: Confirm Java Is Actually Installed
Check C:\Program Files\Java (or C:\Program Files\Eclipse Adoptium for Temurin builds) for a folder like jdk-21 or jre-21. If nothing’s there, install a JDK first. If a folder exists, note whether it’s a JRE or a JDK: a JRE only runs Java programs, while a JDK adds the compiler needed to build them. If you only have a JRE, you can fix PATH perfectly and still get a separate error on javac specifically — that’s a missing-JDK problem, not a PATH problem.
Step 2: Set JAVA_HOME and Add It to PATH on Windows 11
Press Windows key + R, type sysdm.cpl, and hit Enter to jump straight to System Properties rather than hunting through Settings. Open the Advanced tab, click Environment Variables, and under System variables:
- Click New, name it JAVA_HOME, and set the value to your JDK’s root folder — something like
C:\Program Files\Java\jdk-21, not thebinsubfolder inside it. - Select the existing Path variable, click Edit, then New, and add
%JAVA_HOME%\binas a new entry. Don’t delete anything else already in the list. - Click OK on every open dialog to actually save the change — closing the window with the X discards it.
Using %JAVA_HOME%\bin instead of hardcoding the full path again means that when you eventually update Java, you only need to change JAVA_HOME once rather than hunting down every place you typed the old version number.
Step 3: Restart Your Terminal — and Possibly More Than That
Close every open Command Prompt, PowerShell, or Windows Terminal window and open a fresh one; environment variables load when a process starts, not continuously. An IDE like VS Code or IntelliJ usually needs a full restart too, since its integrated terminal often inherits the environment from when the IDE launched, not from Windows directly. On a shared or managed PC, you may need to sign out and back in before every process picks up the change.
Common Mistakes That Keep the Error Coming Back
A few mistakes account for most repeat cases of this error after someone’s already “fixed” it once:
- Pointing JAVA_HOME at the wrong folder. It should be the JDK root, not the
binfolder —%JAVA_HOME%\binalready appends that for you. - Multiple Java versions fighting for position. If you have two JDKs installed, whichever one’s
binfolder appears earlier in the Path list wins, regardless of which one you think is “active.” Check for old entries from a previous install you forgot about. - Editing User PATH when the real problem is System PATH, or the reverse. Windows merges both, but background services and other user accounts on the same machine only see the System-level entry.
- A trailing backslash or stray space pasted into the PATH entry, which breaks the lookup silently with no error pointing at the actual cause.
Verify the Fix Actually Worked
Open a brand-new terminal window and run java -version. A correct fix prints a version string immediately. If you need to compile code, also run javac -version — if java works but javac doesn’t, you’ve confirmed you only have a JRE and need to install a full JDK instead, which is a different fix from anything above. The command where java is also worth knowing: it shows you exactly which java.exe Windows is finding first, which is the fastest way to catch a stale, outdated install still sitting ahead of your new one in PATH.
What If the Error Still Won’t Go Away?
Double-check you actually clicked OK rather than Cancel on each dialog — it’s an easy step to fumble, and the variable can look “set” the next time you open the window even though nothing saved. On a work or school laptop under IT policy, environment variables can be locked at the group policy level, overriding anything you set manually; if PATH keeps reverting with no action from you, that’s the likely cause, and it needs an administrator rather than another attempt at the same fix. If a different error shows up once java -version actually works — like a missing jvm.dll or a specific installer code — that’s a separate issue; see our guides on fixing a missing jvm.dll error and Java installer error code 1618.
FAQ
Why do I get “‘java’ is not recognized” even though Java is installed?
Windows only looks in the folders listed in the PATH environment variable. If Java’s bin folder isn’t in that list, the command fails even though java.exe exists on your drive. Some installers add this automatically; manual or ZIP installs usually don’t.
Do I need to restart my computer after fixing PATH?
Not your whole computer, but you do need to close and reopen any terminal window, since environment variables are only read when a new process starts. IDEs like VS Code or IntelliJ often need a full restart too.
What’s the difference between fixing this for java vs. javac?
Both commands need the same PATH entry, but javac additionally requires a full JDK rather than just a JRE. If java works but javac still fails, the fix is installing the JDK, not adjusting PATH again.
How do I check which Java installation Windows is actually using?
Run “where java” in a terminal. It lists every matching java.exe Windows can find, in the order PATH searches them, which quickly reveals an old, outdated install sitting ahead of a newer one you just set up.