You type java -version in Command Prompt and Windows gives you this error:
Understanding the problem makes the fix much easier to follow.
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).
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.
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.
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.
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.
Type the following command, replacing the path with your actual Java folder location:
Press Enter. No output means it worked.
Now type this command exactly as shown:
Press Enter. Again, no output means success.
Now type:
You should see output like this:
If you see this, Java is working correctly in this session.
Tired of typing those two commands every time? Create a file called setjava.bat in your Documents folder with this content:
Next time, just open CMD, type setjava.bat, press Enter, and Java is ready immediately.
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.
java will work in every new Command Prompt window automatically — no need to run any commands before coding.Common problems students run into when setting up Java PATH.
bin folder inside it — the \bin part is added automatically by the set PATH=%JAVA_HOME%\bin command.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).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.set command approach) instead. It works without any admin rights.If you have not downloaded Java yet, start with the portable ZIP guide — no admin rights needed, no installer.
☕ Get Java 21 Portable ZIP →