This question has already been answered:

I want to run the java file. I understand that the first step is to convert it into a .class file. So: Initial data

Java file

package Main; public class Main { public static void main(String[] args) { System.out.println(“Hello word”); } } 

Address jdk C: \ Program Files \ Java \ jdk1.8.0_121

The address that is displayed on cmd C: \ Users \ Vit \ IdeaProjects \ untitled11 \ src

Error "javac" is not an internal or external command, executable program or batch file.

Reported as a duplicate by Sergey Gornostaev , aleksandr barakin , Pavel Mayorov , Grundy , ию 3 Jun '17 at 20:45 .

A similar question was asked earlier and an answer has already been received. If the answers provided are not exhaustive, please ask a new question .

  • The path to the folder in which javac.exe lies must be added to the environment variables. - post_zeew

2 answers 2

My compiler swears on your code, in particular on your quotes. Below code is:

 package Main; public class Main { public static void main(String[] args) { System.out.println("Hello word"); } } 

PATH variable (Windows)


Windows 10 and Windows 8

In the "Search" line, perform a search:

System (Control Panel)

Click on the link

Additional system parameters

Click

Environment Variables

In the Environment Variables section, select the environment variable.

PATH

Click Edit. If the PATH variable does not exist, click Create. In the Change system variable (or New system variable) window, specify the value of the PATH environment variable ( ;C:\Program Files\Java\jdk1.8.0_121\bin\ ). Click OK. Close all other open windows by clicking OK. Reopen the command window and execute the java code.


Windows 7


On the desktop, right-click on the icon.

Computer

In the context menu, select

Properties

. Click on the link

Additional system parameters

Click

Environment Variables

In the Environment Variables section, select the environment variable.

PATH

Click

Change

If the PATH variable does not exist, click Create. In the Change system variable (or New system variable) window, specify the value of the PATH environment variable ( ;C:\Program Files\Java\jdk1.8.0_121\bin\ ). Click OK. Close all other open windows by clicking OK. Reopen the command window and execute the java code.


Compiling a java file: the file name should be the same as the class name, i.e. Main.java. Further, after installing the PATH: enter image description here

in my case it will appear next to the Main.java file, the file Main.class (compiled)

  • Everything has been done several times already, the result is the same - Vitaliy Vit
  • @VitaliyVit if you are not sure of the correctness of the path to the file, try typing javac in the command line space and then transfer the file from the folder to the command line (this is a guarantee of the correct path) - Aliaksandr Pitkevich
  • Something like the creation of the .class file “C: \ Program Files \ Java \ jdk1.8.0_121 \ bin \ javac” Cat.java But I don’t want to run “C: \ Program Files \ Java \ jdk1.8.0_121 \ bin \ java” Cat Gives an Error Error: Could Cat Error: Could not find or load the main Cat class - Vitaliy Vit
  • Something like the creation of the .class file “C: \ Program Files \ Java \ jdk1.8.0_121 \ bin \ javac” Cat.java But I don’t want to run “C: \ Program Files \ Java \ jdk1.8.0_121 \ bin \ java” Cat Generates an Error Error: Could Cat Error: Could not find or load the main Cat class - Vitaliy Vit
  • let's get your code with class Cat - Aliaksandr Pitkevich

Write the full path to jdk:

 "C:\Program Files\Java\jdk1.8.0_121\bin\javac.exe" YourFile.java 

or add an environment variable.