'javac' is not recognized as an internal or external command, operable program or batch file
This is the most common of all the errors faced by people trying to compile their first piece of code. This message means that Windows cannot find the compiler (javac).
Here's one way to tell Windows where to find javac. At the prompt type the following command and press Enter:
C:> "\Program Files\Java\jdk1.6.0_
If you choose this option, you'll have to precede your javac and java commands with C:> "\Program Files\Java\jdk1.6.0_
To set the PATH permanently, add the full path of the jdk1.6.0_
1. Click Start > Control Panel > System on Windows XP or Start> Settings > Control Panel > System on Windows 2000.
2. Click Advanced > Environment Variables.
C:\Program Files\Java\jdk1.6.0_
The 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 jdk1.6.0_
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
Without the semicolon, the compiler has no way of knowing that the statement is complete.
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.
3. 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++
^
Again, your program did not successfully compile, and the compiler did not create a .class file. Fix the error and try again.
4. Runtime Errors
Exception in thread "main" java.lang.NoClassDefFoundError: HelloWorldApp
The prompt should change to C:\uiet>. If you enter dir at the prompt, you should see your .java and .class files. Now enter java HelloWorldApp again.
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 HelloWorldApp.class instead of java HelloWorldApp. Remember, the argument is the name of the class that you want to use, not the filename.
The Java VM requires that the class you execute with it have a main method at which to begin execution of your application.
I hope all the errors that have been bugging you fall in one of the above categories. Still, if you are confronted with an error that is not listed above do write to me.
No comments:
Post a Comment