1. 'javac' is not recognized as an internal or external command, operable program or batch file
If you receive this error, it means that Windows is not able to find the compiler (javac). Here's one way to tell Windows where to find javac. Set the PATH as follows on Microsoft Windows:
1. Click Start -> Control Panel -> System on Windows XP or Start -> Settings -> Control Panel -> System on Windows 2000.
2. Click Advanced -> Environment Variables.
3. Add the location of bin folder of JDK installation for PATH in User Variables and System Variables. A typical value for PATH is:
- PATH environment variable is a series of directories separated by semi-colons (;) and is not case sensitive. Microsoft Windows looks for programs in the PATH directories in order, from left to right.
- You should only have one bin directory for a JDK in the path at a time. Those following the first instance are ignored. If one is already present, update it to jdk<version>\bin.
- If you are not sure where to add the path, add it to the right end of the PATH in the User Variables.
- The new path takes effect in each new command window you open after setting the PATH variable.
2. Class names, 'HelloWorld', are only accepted if annotation processing is explicitly requested
If you receive this error, it means that you forgot to include the .java suffix when compiling the program. Remember, the command is javac HelloWorld.java not javac HelloWorld!
3. Syntax Errors
If you mistype part of a program, the compiler may issue a syntax error. The message usually displays the type of the error, the line number where the error was detected, the code on that line, and the position of the error within the code. Here's an error caused by omitting a semicolon (;) at the end of a statement:
testing.java:14: `;' expected. System.out.println("Input has " + count + " chars.") ^ 1 error
while (System.in.read() != -1)
System.out.println("Input has " + count + " chars.");
testing.java:13: Invalid type expression. count++ ^ testing.java:14: Invalid declaration. System.out.println("Input has " + count + " chars."); ^ 2 errors
If you see any compiler errors, then your program did not successfully compile, and the compiler did not create a .class file. Carefully verify the program, fix any errors that you detect, and try again.
4. Semantic Errors
In addition to verifying that your program is syntactically correct, the compiler checks for other basic correctness. For example, the compiler warns you each time you use a variable that has not been initialized:
testing.java:13: Variable count may not have been initialized. count++ ^ testing.java:14: Variable count may not have been initialized. System.out.println("Input has " + count + " chars."); ^ 2 errors
1. Exception in thread "main" java.lang.NoClassDefFoundError: HelloWorld
If you receive this error, java cannot find your bytecode file, HelloWorld.class.
One of the places java tries to find your .class file is your current directory. So if your .class file is in C:\java, you should change your current directory to that. To change your directory, type the following command at the prompt and press Enter:
The prompt should change to C:\java>. If you enter dir at the prompt, you should see your .java and .class files. Now enter java HelloWorldApp again.
If you still have problems, you might have to change your CLASSPATH variable. To see if this is necessary, try clobbering the classpath with the following command.
Now enter java HelloWorld again. If the program works now, you'll have to change your CLASSPATH variable. The CLASSPATH variable is set in the same manner PATH variable is set as above. Note it must(CLASSPATH) point to your current directory which is 'C:\java' in this case.
2. Exception in thread "main" java.lang.NoClassDefFoundError: HelloWorld/class
A common mistake made by beginner programmers is to try and run the java launcher on the .class file that was created by the compiler. For example, you'll get this error if you try to run your program with java HelloWorld.class instead of java HelloWorld. Remember, the argument is the name of the class that you want to use, not the filename.
3. Exception in thread "main" java.lang.NoSuchMethodError: main
The Java VM requires that the class you execute with it have a main method at which to begin execution of your application.