Javatpoint Logo
Javatpoint Logo

javac is not Recognized

In Java, we usually get the errors and exceptions during the compilation time. But the error javac is not recognized is the most common error that is faced by many new Java programmer. In this section, we will detect why the javac command is not recognized by the compiler and what is the reasons to generate javac is not recognized. We will also see the possible solutions to resolve the error.

Before moving ahead in this section, let's understand the meaning of the error statement javac is not recognized as internal or external command.

In Java, javac is a command that compiles the Java source code. When we type the command in the Command Prompt, the prompt refuse to identify the javac command. It means that the javac.exe file is not found by the compiler. The javac.exe file exists in the bin folder of the JDK installation folder. The error we get because the PATH is not properly set. The following image shows, what the error shows.

javac is not Recognized

Reason to Occur the Error

javac is not recognized is an error occurs while we compile the Java application. It is because the JVM is unable to find the javac.exe file. The javac.exe file is located in the bin folder of the JDK.

javac is not Recognized

The reason behind to occur the error is that the PATH is not added to the System's environment variable. If the PATH is not added to the environment variable or not properly set, we cannot compile the Java application. So, to resolve the error is important. Let's see the solution to the error.

Solution to the Error

To resolve the error, we need to add PATH (used by operating system to find the executable files) variable to the System's environment variable. The PATH is the address of the folder where javac.exe file located. It is necessary to include bin directory to the environment variable because all the executable files required to compile, run, and debug Java program are located in the bin directory. So, in our case, the PATH to the bin directory is:

C:\ProgramFiles\Java\jdk1.8.0_05\bin;

Your path may differ from the above path. It depends on where you have installed the JDK. Remember that put a semicolon (;) at the end of the PATH because it is possible that you need to add another PATH variable of another application. So, in this case, the semicolon separates two paths.

Note: The PATH may differ if you have installed later versions of Java.

First, we check the PATH is already added or not. To check which paths are added to the environment variable, follow the steps, given below:

  • Open the Command Prompt.
  • Type the command: echo %PATH%
javac is not Recognized

It shows all the paths or directories that are already added to the environment variable. If the PATH is already set, continue with the javac command for compilation, else add the PATH to the environment variable.

There are the two ways to set PATH in the environment variable, either set the PATH temporary or set the PATH permanently. The disadvantage to set the PATH temporary is that as many as times we compile the Java application, we need to specify the PATH. It takes lots of time and there are more chances to type the wrong command. So, it is not good to use. We recommend you to set the PATH permanently.

Let's see how to add PATH to the system's environment variable.

Set the PATH Temporary

To set the PATH temporary, follow the steps given below:

  • Open the Command Prompt.
  • Go to the directory where you have installed the JDK. Inside the JDK folder search the bin folder and open it.
  • Copy the location of the bin folder. In our case, the location of the bin folder is: C:\Program Files\Java\jdk1.8.0_05\bin
javac is not Recognized
  • Now, switch to the Command Prompt and type the command: set PATH= C:\Program Files\Java\jdk1.8.0_05\bin and press the enter key. It sets the PATH to the specified location.
javac is not Recognized

Once the PATH is set, we can compile and run the Java application.

Set the PATH Permanently

To set the PATH permanently, follow the steps given below:

Step 1: Open the Control Panel.

Step 2: Click on the System.

javac is not Recognized

Step 3: Click on the Advanced system settings. It opens a dialog box for the System Properties.

javac is not Recognized

Step 4: In the System Properties dialog box, click on the Environment Variables button, located at the bottom right corner. It opens the Environment Variables dialog box.

javac is not Recognized

Step 5: In the Environment Variables dialog box, click on the New button if the PATH variable is not appearing under User Variables section. It opens the New User Variable dialog box.

javac is not Recognized

Step 6: Provide the Variable name PATH and Variable value path up to the bin folder of the JDK directory. In our case, the path is: C:\ProgramFiles\Java\jdk1.8.0_05\bin. After that, click on the OK button.

javac is not Recognized

Now the PATH variable has been saved and it is visible under the User Variables section.

Step 7: Again, click on the OK button.

javac is not Recognized

Step 8: Click on the OK button.

javac is not Recognized

The PATH has been saved permanently. To test it is working properly or not, open the Command Prompt and type javac command and press the enter key. The command shows the options that we can use with the javac command.

javac is not Recognized

The command ensures that the PATH is properly set and we can compile and run Java programs without occurring the error javac is not recognized as an internal or external command, operable program or batch file.







Youtube For Videos Join Our Youtube Channel: Join Now

Feedback


Help Others, Please Share

facebook twitter pinterest

Learn Latest Tutorials


Preparation


Trending Technologies


B.Tech / MCA