Advertisement
🔧 Beginner Friendly · Step-by-Step · No Admin Needed

How to Fix "java" Not Recognized
on Windows

You type java -version in Command Prompt and Windows gives you this error:

'java' is not recognized as an internal or external command,
operable program or batch file.
// Why This Happens

What Is Causing This Error?

Understanding the problem makes the fix much easier to follow.

Windows does not know where Java is

When you type a command like java in Command Prompt, Windows searches a list of folders called the PATH to find a program with that name. If Java's bin folder is not in that list, Windows gives up and shows the error above. The fix is simple — tell Windows where Java lives by setting two things: JAVA_HOME (the path to your Java folder) and PATH (which needs to include Java's bin folder).

There are two types of fix

Method 1 — Temporary (for school computers): Use the set command in CMD. Works without admin rights. Lasts only until you close the terminal window. Perfect for school computers where you cannot change system settings.

Method 2 — Permanent (for your personal computer): Edit System Environment Variables through Windows Settings. Requires admin rights. The PATH stays set forever, so you never have to run the set commands again.

// Method 1 – No Admin Rights

Temporary Fix for School Computers

This works without any admin rights and takes about 60 seconds. You will need to repeat it each time you open a new Command Prompt window.

01

Find Your Java Folder

If you downloaded the portable Java 21 ZIP from this site, you already know where it is — for example C:\Users\YourName\Documents\jdk-21 or E:\tools\jdk-21 on a USB drive. Write down or copy this path. You need the folder that contains a bin subfolder inside it.

02

Open Command Prompt

Press Windows + R, type cmd, and press Enter. Or search for "Command Prompt" in the Start menu. You do not need to run it as administrator.

03

Set JAVA_HOME

Type the following command, replacing the path with your actual Java folder location:

C:\Users\You> set JAVA_HOME=C:\Users\YourName\Documents\jdk-21

Press Enter. No output means it worked.

04

Add Java to PATH

Now type this command exactly as shown:

C:\Users\You> set PATH=%JAVA_HOME%\bin;%PATH%

Press Enter. Again, no output means success.

05

Test That It Works

Now type:

C:\Users\You> java -version

You should see output like this:

java version "21.0.7" 2025-04-15 LTS
Java(TM) SE Runtime Environment (build 21.0.7+8-LTS)
Java HotSpot(TM) 64-Bit Server VM (build 21.0.7+8-LTS, mixed mode, sharing)

If you see this, Java is working correctly in this session.

06

Save Time With a Batch File

Tired of typing those two commands every time? Create a file called setjava.bat in your Documents folder with this content:

@echo off
set JAVA_HOME=C:\Users\YourName\Documents\jdk-21
set PATH=%JAVA_HOME%\bin;%PATH%
echo Java is ready! Run: java -version

Next time, just open CMD, type setjava.bat, press Enter, and Java is ready immediately.

⚠️ Remember: These settings only last for the current CMD session. If you close Command Prompt and open a new one, you need to run the commands (or your batch file) again. This is normal for school computers.
Advertisement
// Method 2 – Permanent Fix

Permanent Fix for Your Personal Computer

This requires admin rights and works on your personal laptop or home computer. Once set, Java always works in every CMD window.

Step 1. Right-click the Start button → click System → click Advanced system settings on the right side.

Step 2. In the System Properties window, click the Environment Variables… button at the bottom.

Step 3. Under User variables, click New…. Set Variable name to JAVA_HOME and Variable value to the full path of your JDK folder (e.g. C:\Users\You\Documents\jdk-21). Click OK.

Step 4. Still under User variables, find the Path variable, click it, then click Edit…. Click New and type %JAVA_HOME%\bin. Click OK on all windows.

Step 5. Open a new Command Prompt window and type java -version to confirm it works.

✅ Once this is done, java will work in every new Command Prompt window automatically — no need to run any commands before coding.
// Troubleshooting FAQ

Still Not Working? Try These

Common problems students run into when setting up Java PATH.

I set the PATH but java still says not recognized
The most common cause is a typo in the path. Copy the path directly from your File Explorer address bar rather than typing it manually. Also make sure your path points to the JDK folder itself, not the bin folder inside it — the \bin part is added automatically by the set PATH=%JAVA_HOME%\bin command.
java -version works but javac does not
This usually means you downloaded a JRE (Java Runtime Environment) instead of a JDK (Java Development Kit). The JRE can run Java programs but cannot compile them. The javac compiler only comes with the JDK. Download the JDK from the Java 21 page on this site and use that folder instead.
The path has spaces in it and the command fails
Windows paths with spaces can cause issues. Wrap the path in double quotes: set JAVA_HOME="C:\Program Files\jdk-21". Better still, move your Java folder to a location without spaces, such as C:\Users\YourName\jdk21 (no spaces).
I closed CMD and Java stopped working again
This is expected when using the temporary set method. The setting only lasts for that CMD session. Use the batch file trick from Step 6 above to save time, or use Method 2 (the permanent fix) if you are on your personal computer.
My school computer says access denied when I try System Properties
School computers are usually locked so students cannot change system-wide settings like Environment Variables through System Properties. Use Method 1 (the temporary set command approach) instead. It works without any admin rights.

Need the Java 21 ZIP First?

If you have not downloaded Java yet, start with the portable ZIP guide — no admin rights needed, no installer.

☕ Get Java 21 Portable ZIP →
Ad