Most Common java Problems and Their Solutions
Problem # 1: 'javac' is not recognized as an internal or external command, operable program or batch file
C:\jdk1.7.0\bin\javac MyFirstApp.java
If you choose this option, you'll have to precede your javac and java commands with C:\jdk1.7.0\bin\ each time you compile or run a program. To avoid this extra typing, use second option.
Source:-http://www.nextstep4it.com
Compiler Problems
Common Error Messages on Microsoft Windows Systems
Problem # 1: 'javac' is not recognized as an internal or external command, operable program or batch file
Solution:
If you receive this error, Windows cannot find the
compiler (javac). There are two ways to tell Windows where to find
javac.
1: - Suppose you installed the JDK in C:\jdk1.7.0.
At the prompt you would type the following command and press Enter:
C:\jdk1.7.0\bin\javac MyFirstApp.java
If you choose this option, you'll have to precede your javac and java commands with C:\jdk1.7.0\bin\ each time you compile or run a program. To avoid this extra typing, use second option.
2: - Updating the PATH Environment
Variable: To set the PATH variable permanently, add the full path of
the jdk1.7.0\bin directory to the PATH variable. Typically, this full
path looks something like C:\jdk1.7.0\bin. Set the PATH variable as
follows on Microsoft Windows:
- Click Start, then Control Panel, then System.
- Click Advanced, then Environment Variables.
- Add the location of the bin folder of the JDK installation for the PATH variable in System Variables. The following is a typical value for the PATH variable:
C:\WINDOWS\system32;C:\WINDOWS;C:\jdk1.7.0\binProblem # 2: Class names, 'MyFirstApp', are only accepted if annotation processing is explicitly requested
Solution: If you receive this error, you forgot to include the .java suffix when compiling the program. Remember, the command is javac MyFirstApp.java not javac MyFirstApp.Common Error Messages on UNIX SystemsProblem # 3: javac: Command not found
Solution: If you receive this error, UNIX cannot find the compiler, javac.
Here's one way to tell UNIX where to find javac. Suppose you installed the JDK in /usr/local/jdk1.7.0. At the prompt you would type the following command and press Return:/usr/local/jdk1.7.0/javac MyFirstApp.javaNote: If you choose this option, each time you compile or run a program, you'll have to precede your javac and java commands with /usr/local/jdk1.7.0/.To avoid this extra typing, you could add this information to your PATH variable. The steps for doing so will vary depending on which shell you are currently running.Problem # 4: Class names, ' MyFirstApp', are only accepted if annotation processing is explicitly requestedSolution: If you receive this error, you forgot to include the .java suffix when compiling the program. Remember, the command is javac MyFirstApp.java not javac MyFirstApp.Problem # 5: Syntax Errors (All Platforms) Error caused by omitting a semicolon (;)
Solution: 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 : Sometimes the compiler can't guess your intent and prints a confusing error message or multiple error messages if the error cascades over several lines. For example, the following code snippet omits a semicolon (;) from the bold line:while (System.in.read() != -1)
count++
System.out.println("Input has " + count + " chars.");
When processing this code, the compiler issues two error messages:
testing.java:13: Invalid type expression.
count++
testing.java:14: Invalid declaration.
System.out.println("Input has " + count + " chars.");2 errors : The compiler issues two error messages because after it processes count++, the compiler's state indicates that it's in the middle of an expression. 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.
Tags:
Java