Back

Explore Courses Blog Tutorials Interview Questions
+1 vote
3 views
in Java by (11.4k points)

I am new to Java application and having trouble compiling a simple Helloworld program.

JDK 1.7.0 is installed in my Windows 7 and was able to set the path variable but didn't work. I keep getting the following error:

C:\Users\Ivy>cd \
C:\cd java files
C:\java files>set path=C:Program Files (x86)\Java\jdk1.7.0\bin
C:\java files>javac Hello.java
'javac' is not recognized as an internal or external command, operable program or batch file

1 Answer

+1 vote
by (32.3k points)

This error occurs usually when you try to compile a Java source file using javac command e.g. javac Helloworld.java and your PATH is not set properly. It means that javac.exe executable file, which exists in the bin directory of the JDK installation folder is not added to the PATH environment variable. In order to solve this error, you need to add JAVA_HOME/bin folder in your machine's PATH. Until your add Java into your system's PATH variable, you cannot compile and run Java program.

Just follow the steps given below to resolve your problem:

1) Just click on the Start button and open the command prompt and then type cmd on the run window.

2)  Type echo %PATH%,  it will now show you all the directories available in the PATH environment variable. The PATH output that you will receive, just copy it into your text editor e.g. Notepad or Word-pad and search if it contains the JDK installation directory or JAVA_HOME. Just take an example: Suppose if your JDK is installed on "c:\program files\java\jdk1.8.0", then PATH must 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 the bin directory.  Sometimes you may also see something 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 the following command

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

This is also called setting PATH in Java. Once PATH is set you can compile, run and monitor Java programs by using various tools that come with JDK installation.

4) Now, just run the javac command again and do not forget to close the current command prompt.  Any change in the environment variable is only available to new cmd windows.

Browse Categories

...