I have a filename named "first.java" saved on my desktop in notepad++. When I run the cmd command "javac first.java" it gives me this error.
javac: file not found: first.java
Usage: javac <options> <source files>
I know you are required to go to C:\Programfiles\java\jdk.
and in my C:\Program Files\Java\ I have thesE folders
"jdk1.8.0" "jre6" "jre8"
In C:\Program Files (x86)\Java
I have this folder
"jre6"
The Environmental settings are as follows
CLASSPATH
C:\Program Files\Java\jre8\bin
Variable name: LEJOS_NXT_JAVA_HOME
Variable value: C:\Program Files (x86)\Java\jdk1.6.0_21\bin
PATH
Variable name: PATH
Variable value: C:\Program Files\Java\jdk1.8.0\bin
Please tell me where I am going wrong. I have read several posts on the Internet, and I can't figure it out.
Description. The javac command reads source files that contain module, package and type declarations written in the Java programming language, and compiles them into class files that run on the Java Virtual Machine. The javac command can also process annotations in Java source files and classes.
“javac” is the java compiler available in bin folder of the jdk. “-d” stands for the “directory“. it explains compiler that where the class files should be created. Last argument is the Complete path, where the java file exists.
Type 'javac MyFirstJavaProgram. java' and press enter to compile your code. If there are no errors in your code, the command prompt will take you to the next line (Assumption: The path variable is set). Now, type ' java MyFirstJavaProgram ' to run your program.
I had the same issue and it was to do with my file name. If you set the file location using CD in CMD, and then type DIR it will list the files in that directory. Check that the file name appears and check that the spelling and filename ending is correct.
It should be .java but mine was .java.txt. The instructions on the Java tutorials website state that you should select "Save as Type Text Documents" but for me that always adds .txt onto the end of the file name. If I change it to "Save as Type All Documents" it correctly saved the file name.
I had same problem. The origin of the problem was the creation of text file in Notepad and renaming it as a java file. This implied that the file was saved as WorCount.java.txt file.
To solve this I had to save the file as java file in an IDE or in Nodepad++.
As KhAn SaAb has stated, you need to set your path.
But in order for your JDK to take advantage of tools such as Maven in the future, I would assign a JAVA_HOME
path to point to your JDK folder and then just add the %JAVA_HOME%\bin
directory to your PATH
.
JAVA_HOME = "C:\Program Files\Java\jdk1.8.0"
PATH = %PATH%\%JAVA_HOME%\bin
In Windows:
blah;blah;blah;
C:\Program Files\Java\jdk1.8.0\bin;blah,blah;blah
to:
blah;blah;blah;
%JAVA_HOME%\bin;blah,blah;blah
For Windows, javac
should be a command that you can run from anywhere. If it isn't (which is strange in and of itself), you need to run javac
from where it's located, but navigate to the exact location of your Java class file in order to compile it successfully.
By default, javac
will compile a file name relative to the current path, and if it can't find the file, it won't compile it.
Please note: You would only be able to use jdk1.8.0 to actually compile, since that would be the only library set that has javac
contained in it. Remember: the Java Runtime Environment runs Java classes; the Java Development Kit compiles them.
SET path of JRE as well
jre is nothing but responsible for execute the program
PATH Variable value:
C:\Program Files\Java\jdk1.8.0\bin;C:\Program Files\Java\jre\bin;.;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With