'javac' is not recognized as an internal or external command

'javac' is not recognized as an internal or external command, operable program or batch file error comes when you try to compile a Java source file using javac command e.g. javac Helloworld.java but your PATH is not set properly. It means that javac.exe executable file, which exists in bin directory of JDK installation folder is not added to PATH environment variable. You need to add JAVA_HOME/bin folder in your machine's PATH to solve this error. You cannot compile and run Java program until your add Java into your system's PATH variable. Here is how this error looks like in command prompt of windows machine :

'javac' is not recognized as an internal or external command error windows



Steps to fix 'javac' is not recognized as an internal or external command :

Let's see how to fix this problem to compile and run Java program from command line :

1) Open command prompt in Windows by clicking Start button and then typing cmd on run window, as shown in following screenshot :

How to open command prompt in windows


2) Type echo %PATH%,  it will now show you all the directories which are available in PATH environment variable. Now copy this PATH output into your text editor e.g. Notepad or Word-pad and search if it contains the JDK installation directory or JAVA_HOME. For example, if your JDK is installed on "c:\program files\java\jdk1.8.0", then PATH should include "c:\program files\java\jdk1.8.0\bin". It's important to include bin directory because all executable required to compile, run and debug Java program are stored in bin directory.  Sometime you will also see like %JAVA_HOME%\bin , where JAVA_HOME is another user defined environment which points to Java installation directory. 



3) If PATH doesn't contain bin directory of JDK, then you can add them into PATH by following command

set PATH = %PATH%;"c:\program files\java\jdk1.8.0\bin

This is also known as setting PATH in Java. Once PATH is set you can compile, run and monitor Java programs by using various tools which comes with JDK installation. If you are not very familiar with setting environment variable from command prompt, you can also use settings window as shown in this article.

4) Don't forget to close the current command prompt and open a new one before running the javac command again.  Any change in environment variable is only available to new cmd windows.


That's all about how to fix 'javac' is not recognized as an internal or external command, operable program or batch file error in Windows. You might get similar error e.g. 'java' is not recognized as an internal or external command, operable program or batch file, if you try to run an already compiled Java program and PATH is not set in your machine.

Further Learning
Complete Java Masterclass
Java Fundamentals: The Java Language
Java In-Depth: Become a Complete Java Engineer!

33 comments:

  1. Hey Guys,
    Even I was having the same issue and I did following 2 things which finally worked for me:
    1. In system variables (in Advanced tab) created a new variable 'CLASSPATH' with value 'C:\Program Files\Java\jre-10\lib'
    2. Closed current cmd prompt window (as it was still giving the same error), opened new cmd window where I got correct response for javac :)
    Hope it helps.

    ReplyDelete
    Replies
    1. Thanks, it was "the" exact case.

      Delete
    2. Thank You, It worked for me

      Delete
    3. finally thank you

      Delete
    4. still broken...

      Is it because one of my other programs had a variable called path? Anyway I removed that program but its still busted.

      Delete
    5. just install jdk 8. can't run programs at jdk 9 up

      Delete
  2. Thanks, Its Working

    ReplyDelete
  3. I use this very steps and used to work.. But now its not working..
    What to do? Plzz help

    ReplyDelete
    Replies
    1. Hello Unknown, can you please provide more details, what are you trying to do, what is your system, what is in your PATH environment variable etc?

      Delete
  4. Working by setting c:\program files\java\jdk1.8.0\bin as 'path' in user variables(Y)

    ReplyDelete
  5. Thanks. Its working for me by setting c:\program files\java\jdk1.8.0\bin as 'PATH' in user variables(Y).

    ReplyDelete
  6. Replies
    1. Can you please provide some more details? what error you are getting, what is in your PATH and CLASSPATH? What have you tried so far? This will help me to understand the issue better and help you faster.

      Delete
    2. Tried path, tried class path and path.
      Path = C:\Program Files\Java\jdk-12.0.1\bin

      Windows 7 64 bit operation system.
      I have installed java 5 times now, 0 have worked. Followed 5 completely different tutorials, 0 worked.

      Error is javac is not recognized as internal or external command program batch file.html (read the title...)

      Does it have to be called PATH or CLASS PATH or what.

      I recently had a broken called brakets that had a path file so I deleted it, probably makes no effect I don't know.

      My PC isn't very good, does that make a different. I don't know, it can run other things, e.g. unity.

      Is that enough info?

      Delete
    3. can you open a command prompt and run the echo %PATH% for me and print the output here?

      Delete
    4. C:\ProgramData\Oracle\Java\javapath;C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem;C:\WINDOWS\System32\WindowsPowerShell\v1.0\;C:\Users\bose-3\.dnx\bin;C:\Program Files\Microsoft DNX\Dnvm\;C:\Program Files (x86)\Windows Kits\8.1\Windows Performance Toolkit\;C:\Program Files\Microsoft SQL Server\130\Tools\Binn\;C:\Program Files (x86)\Microsoft Emulator Manager\1.0\;C:\Program Files (x86)\Microsoft Team Foundation Server 2015 Power Tools\;C:\Android;C:\Windows\System32;c:\Program Files (x86)\Microsoft SQL Server\110\Tools\Binn\;c:\Program Files\Microsoft SQL Server\110\Tools\Binn\;c:\Program Files\Microsoft SQL Server\110\DTS\Binn\;C:\Program Files\nodejs\;C:\Program Files (x86)\WebEx\Productivity Tools;C:\Program Files (x86)\Microsoft Team Foundation Server 2012 Power Tools\Best Practices Analyzer\;C:\Program Files (x86)\Webex\Webex\Applications;C:\Program Files\Microsoft SQL Server\120\Tools\Binn\;C:\Program Files\Java\jre1.8.0_161\bin

      Delete
  7. 0001011110111101111111011011101011110111111110001010101011111110010101000101000010101010101010101010101010101000101111110101010001000111010101010101010101010101010100000000000000000001111010101011010111010101010101010110

    ReplyDelete
  8. When the file is placed at bin location, there is no error in compilation. But when I tried to compile the file at desktop location, I'm facing issues. Can you help me?

    ReplyDelete
    Replies
    1. check if your PATH has desktop in it, I think it has bin folder but not Desktop.

      Delete
    2. Thanks... Now it's working fine...

      Delete
  9. I did the same thing but it is showing like that can any one help me

    ReplyDelete
  10. C:\Program Files\Java\jdk-12.0.2\bin
    im getting error msg 'Hello.java' is not recognized as an internal or external command,
    operable program or batch file.

    ReplyDelete
  11. Dear vib,
    Kindly check if the directory in which you have saved your program and directory of cmd is same or not.

    ReplyDelete
  12. getting an error as "could not find or load the main class 'class_name'" when i execute the java command

    ReplyDelete
  13. its not working for me i have tried almost all what everyone has said...can anyone helpme

    ReplyDelete
  14. not working tried the all steps as listed above
    plz help me

    ReplyDelete
    Replies
    1. plz verify that what your system has actua or current l link for java to verify this press Win+R key to open run command then type cmd, in cmd type the following code, eco %PATH% cmd will show your actual path which is system currently assuming, if it shows different then C:\program file\java\jdk-12.0.1\bin so go back to system veriable then delete the path which cmd shows and create new in user veriable section give name "Path" and paste the bin directry path press ok and then close all opened cmd, niw open new cmd and type javac and hit enter, boom it will work

      Delete
  15. C:\Users\Ionut>%path%
    'C:\Program' is not recognized as an internal or external command,
    operable program or batch file.

    what have i done?

    ReplyDelete
  16. Resolved it by adding JAVA_HOMEC:\Program Files\Java\jdk1.8.0_181

    ReplyDelete
  17. Resolved it by adding environment variables JAVA_HOME - C:\Program Files\Java\jdk1.8.0_181

    ReplyDelete
  18. I have set the path in environment and also java_home. but i cannot make cmd to find java file.
    error everytime file not found. it sucked now for me. i have re-install and all casual checkings. trying java 13

    Need help with this..

    ReplyDelete
    Replies
    1. Which OS are you trying? If you are in Windows, can you print echo %PATH% on command prompt? if you don't see JAVA_HOME, then just add the full path like C:\\java\bin in your path by using set PATH = %PATH%;C:\java\bin etc and try

      Delete