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– Alok Gupta2016-04-19 04:53:49 +00:00Commented Apr 19, 2016 at 4: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– S.B2016-04-19 04:54:25 +00:00Commented Apr 19, 2016 at 4:54
-
1To compile a java source code file, you will have to do something like : javac <SourceFileName.java> 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– MS Srikkanth2016-04-19 04:58:16 +00:00Commented Apr 19, 2016 at 4:58
-
I typed in C:\cd\mywork as well as C:\mywork>;dir with the same results.Ash– Ash2016-04-19 05:02:16 +00:00Commented Apr 19, 2016 at 5: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– goncalopinto2016-04-19 05:06:58 +00:00Commented Apr 19, 2016 at 5:06
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....
9 Comments
User variables for scorc same as you can see I have set them in User variables for ADITYA...javac mywork\HelloWorld.javaC:\introcs\hello by typing the cd command below. C:\Users\username>cd c:\introcs\hello after that thisC:\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.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 .
3 Comments
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.
1 Comment
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.
