So I'm setting everything up to compile java on my Windows 10 computer, and when I went to the environment variables there was no existing PATH, so I added one. When I type "javac" in the command prompt it is able to recognize it, but when I try to save a java file (on notepad as a test) and try to put that in the command prompt I get the "is not recognized as an internal or external command, operable program or batch file." Everything I've looked up about this response refers back to the environmental variables, but I can't figure out what I did wrong. My PATH looks like this: C:\Program Files\Java\jdk1.8.0_77\bin. Am I missing something obvious?
-
1Can you provide the screenshot of where and what did you set? – Alok Gupta Apr 19 '16 at 04:53
-
4Not clear on what you mean by this"but when I try to save a java file (on notepad as a test) and try to put that in the command prompt I get the "is not recognized as an internal or external command, operable program or batch file." What did you do exactly? – S.B Apr 19 '16 at 04:54
-
1To compile a java source code file, you will have to do something like : javac
and to run it you have to issue the command java SourceFileName. Just saving a file and trying to execute it won't work no mtter how powerful you think Java is. Your PATH contains the directory where the shell can locate the binaries like javac, java and so on. – MS Srikkanth Apr 19 '16 at 04:58 -
I typed in C:\cd\mywork as well as C:\mywork>;dir with the same results. – Ash Apr 19 '16 at 05:02
-
You obviously don't understand DOS and you are not compiling the java classfile, Post some screenshots and let us know if you are in the right directory and/or post some screenshots of your folder tree, showing clearly where are your java files. – goncalopinto Apr 19 '16 at 05:06
-
Here are the screenshots of the file tree: http://postimg.org/image/poxpmarr3/ And a screenshot for the environment variables: http://postimg.org/image/gxd03w2ph/ – Ash Apr 19 '16 at 11:36
4 Answers
Here you need to set two variables in the " Environment Variables " for executing Java files. In the image you can see first variable(Java_Home) is defining the path of jdk in the system and the second variable is defining the path where the Java executables(javac.exe, java.exe, javadoc.exe, and so on) reside. Do it like that your problem will be solved....

- 76
- 1
- 11
-
Okay I followed that and now when I use the command prompt to find it (javac mywork\HelloWorld.java) it says file not found. Here's a screenshot of my file tree: http://postimg.org/image/poxpmarr3/ – Ash Apr 19 '16 at 11:52
-
Okay I just saw your screenshot of environment variables after which I came to know about your mistake. you have set environment variables in system variables whereas you have to set them in `User variables for scorc` same as you can see I have set them in `User variables for ADITYA`... – Aditya kumar Apr 19 '16 at 12:45
-
Also you are not using correct DOS command.....you cannot find a file with command :- `javac mywork\HelloWorld.java` – Aditya kumar Apr 19 '16 at 12:47
-
If the problem persists send the screenshots of what you are doing and the screenshot of the environment Variables window.. – Aditya kumar Apr 19 '16 at 12:51
-
Okay I switched it, which command should I be using then? Everywhere I look seems to say something different. – Ash Apr 19 '16 at 13:06
-
-
I just want to make sure it's set up properly, I'm trying to learn Java, but need to make sure that it will compile and run. – Ash Apr 19 '16 at 13:16
-
1From the Command Prompt, navigate to the directory containing your .java files, say `C:\introcs\hello` by typing the `cd` command below. `C:\Users\username>cd c:\introcs\hello` after that this`C:\introcs\hello\>` will appear in cmd window Assuming the file, say HelloWorld.java, is in the current working directory, type the javac command in boldface below to compile it. `C:\introcs\hello\>javac HelloWorld.java` If everything went well, you should see no error messages. – Aditya kumar Apr 19 '16 at 13:17
-
Okay I think I have it now, thanks. It asked me which program I want to open it in, so it looks like it's able to find it. – Ash Apr 19 '16 at 13:22
Based on the 'not recognized as internal or external command' message it is possible your PATH variable is not set up properly. You need to add the full path to your JDK bin to the system PATH variable, in Control Panel, System, Advanced, Environment Variables. See https://docs.oracle.com/javase/tutorial/essential/environment/paths.html for details.
Though less likely to be the cause of the problem you describe, you also may need to set CLASSPATH. The PATH variable indicates where the executables reside (e.g., javac.exe and java.exe). The CLASSPATH variable indicates where the class files reside. The default CLASSPATH is the current working directory. So if you are executing from the same directory where your class(es) reside(s), you do not need to specify it.
Run 'javac.exe yourprogram.java' to compile the program. Then run 'java yourprogram' to execute it.

- 3,869
- 2
- 39
- 70
-
This is not an answer because the user has a problem with "not recognized as an internal command". Highly likely that it is a problem with her PATH variable or that she is doing something wrong. If it is a CLASSPATH issue then the error would be something different. – MS Srikkanth Apr 19 '16 at 05:23
Just to clarify, you saved your java class , say 'Test.java' and tried to run it through command prompt by calling Test? Can you explain what did you do exactly?
You will need to compile the class using javac and run it using java .

- 101
- 7
-
If you want the OP to explain his/her question clearly then you should ask her in a comment. Not that do that in an answer. – MS Srikkanth Apr 19 '16 at 05:23
-
Well, apparently I don't have enough reputation to comment in the original thread. – java_maniac Apr 19 '16 at 05:28
-
oops sorry...my bad...didnt notice that...perhaps then it is better to not answer at all by asking for clarification...because others have already asked this question and you didn't need to repeat it :) – MS Srikkanth Apr 19 '16 at 05:38
If you have already installed a compatible JDK and JRE for your computer and wondering why your computer is not recognizing 'java' and 'javac' as an internal or external command you probably have not set up your environment variables properly.
Windows directions
Go to Computer > C drive > Program Files > Java > JDK File
Right click on the path and click 'Edit Address'. After you copy the address follow the steps below.
Go to Control Panel > System and Security > System > Advance system settings > environment variables
In the second column (System Variables), Click 'New...'
Set the 'Variable name' to JAVA_HOME
Set the 'Variable value' to the what you recently copied then click 'Ok'
In the same place you were (System variables), find the Variable 'Path' and click 'Edit...'
Under the 'Variable value', move your cursor all the way to the beginning and enter in %JAVA_HOME%\bin;
Click 'Ok' twice then right click directly on your desktop and click 'Refresh'
Lastly, open your command prompt and type in the keywords 'java' and 'javac'
I hoped this worked for most people. I have been trying to figure this out for about a week and I found a great solution that I just wanted to share.

- 19
- 4