[java] javac: file not found: first.java Usage: javac <options> <source files>

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.

This question is related to java

The answer is


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++.


just open file then click on save as then name it as first.java then in that box there is another dropdown in that dropdown (save as type) select type as all and save it now you can compile it


Seems like you have your path right. But what is your working directory? on command prompt run:

javac -version

this should show your java version. if it doesnt, you have not set java in path correctly.

navigate to C:

cd \

Then:

javac -sourcepath users\AccName\Desktop -d users\AccName\Desktop first.java

-sourcepath is the complete path to your .java file, -d is the path/directory you want your .class files to be, then finally the file you want compiled (first.java).


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:

  1. right-click "My Computer" and choose "properties" from the context menu.
  2. Choose "Advanced system settings" on the left.
  3. In the "System Properties" popup, in the "Advanced" tab, choose "Environment Variables"
  4. In the "Environment Variables" popup, under the "System variables" section, click "New"
  5. Type "JAVA_HOME" in the "Variable name" field
  6. Paste the path to your JDK folder into the "Variable value" field.
  7. Click OK
  8. In the same section, choose "Path" and change the text where it says:

      blah;blah;blah;C:\Program Files\Java\jdk1.8.0\bin;blah,blah;blah

      to:

      blah;blah;blah;%JAVA_HOME%\bin;blah,blah;blah


first set the path of jdk bin steps to be follow: - open computer properties. - Advanced system settings - Environment Variables look for the system variables -Click on the "path" variable - Edit copy the jdk bin path and done.

The Problem is you just open the command prompt which is default set on current user like "C:\users\ABC>" You have to change the location where your .java file store like "D:\javafiles>"

Now you are able to run the command javac filename.java


If this is the problem then go to the place where the javac is present and then type

  1. notepad Yourfilename.java
  2. it will ask for creation of the file
  3. say yes and copy the code from your previous source file to this file
  4. now execute the cmd------>javac Yourfilename.java

It will work for sure.


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.


So I had the same problem because I wasn't in the right directory where my file was located. So when I ran javac Example.java (for me) it said it couldn't find it. But I needed to go to where my Example.java file was located. So I used the command cd and right after that the location of the file. That worked for me. Tell me if it helps! Thanks!


First set your path to C:/Program Files/Java/jdk1.8.0/bin in the environment variables. Say, your file is saved in the C: drive Now open the command prompt and move to the directory using c: javac Filename.java java Filename

Make sure you save the file name as .java.

If it is saved as a text file name then file not found error results as it cannot the text file.


Sometimes this issue occurs, If you are creating a java file for the first time in your system. The Extension of your Java file gets saved as the text file.

e.g Example.java.txt (wrong extension)

You need to change the text file extension to java file.

It should be like:

Example.java (right extension)


Java file execution procedure: After you saved a file MyFirstJavaProgram2.java

Enter the whole Path of "Javac" followed by java file For executing output Path of followed by comment <-cp> followed by followed by

Given below is the example of execution

C:\Program Files\Java\jdk1.8.0_101\bin>javac C:\Sample\MyFirstJavaProgram2.java

C:\Program Files\Java\jdk1.8.0_101\bin>java -cp C:\Sample MyFirstJavaProgram2

Hello World


Here is the way I executed the program without environment variable configured.

Java file execution procedure: After you saved a file MyFirstJavaProgram.java

Enter the whole Path of "Javac" followed by java file For executing output Path of followed by comment <-cp> followed by followed by

Given below is the example of execution

C:\Program Files\Java\jdk1.8.0_101\bin>javac C:\Sample\MyFirstJavaProgram2.java C:\Program Files\Java\jdk1.8.0_101\bin>java -cp C:\Sample MyFirstJavaProgram2 Hello World


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.

CMD DIR Example


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;.;