The best place to learn java is compiling as much as errorful Java source files with Java compiler. Most experts, even the beginners use this method, by compiling different codes from different sources make it easy to study and remember hard parts in Java.
Java shows many errors when compliling source codes (That is Javac command). Java compile errors show where and how to correct the error. Following are some common Java errors with the description of the compiler error and solutions you want to carry to correct errors.
These are only simple set of errors. Note that there are seperate books too discuss these error sets.
Java compiler Error 1:
InterfaceC.java:5: class ClassC is public, should be declared in a file named ClassC.java
public class ClassC implements interfaceC{
File Name of the java file do not compatible with class declared inside the file. You need to use same name for the class name and java file name.
Java compiler Error 2:
'cf' is not recognized as an internal or external command, operable program or batch file.
A Problem with your command, and such a command do not exist. Check the command and try again.
Java compiler Error 3:
cannot resolve symbol
symbol : class interfaceC
location: class ClassC
public class ClassC implements interfaceC{
Compiler cannot identify the variable or reference you typed. Check your spellings as well as capitals and simples. Finally check whether your java version have particular facilities for implement such a command. For example your program might written using java 1.6. (Java 6) but, sometimes you can’t compile it in java 1.4 or earlier versions because earlier versions unable to identify some statements in your program.
Java compiler Error 4:
InterfaceC.java:15: incompatible types
found : ClassC
required: InterfaceC
InterfaceC interfaceC = new ClassC();
This error shows you can’t assign a value or reference in a one operand into another because of data type mismatch. This error also occurs because you have another error in a previous declaration. For example, above error occurred because when ClassC declared, the ClassC declaration was incorrect and therefore, compiler cannot perform above assignment. Check whether operands’ data types, other errors compiler shows about operands and your statement.
Java compiler Error 5:
C:\Working Files>java ClassC
Exception in thread "main" java.lang.NoSuchMethodError: main
Check whether you are in correct path of the program and your java <program> command. Otherwise, your main method declaration is missing or incorrect (i.e static keyword in the main method declaration is missing). If main method you have declared is Ok, Then check your java installation. Also remember, some programs (such as QuickTime Player, Firewall) may interrupt your java software or JVM.
Java compiler Error 6:
MainDemo.java:5: '{' expected
class ClassC impliments InterfaceC{
Compiler sighs for possible missed character or symbol. Check whether you have missed the symbol or character it asked for. However, look at the above example. It’s mistakenly typed as’ impliments’ and it should be ‘implements’. But compiler suggests to add ‘{‘ and that will create a class called ClassC. Even the suggession is correct, still it can’t fulfil the requirement and we want to correct ‘impliment’ to ‘implement’.
Look at this too:
MainDemo.java:25: '{' expected
public class MainDemo(){
Java compiler Error 7:
MainDemo.java:33: not a statement
interfaceC.add;
This statement is illegal in java. The statement must be interfaceC.add();. The error can be occurred due to many errors and compiler is unable to say which to the point.
Java compiler Error 8:
error: cannot read: ReverseOrder.java
This error occurs when you command to compile the source code. Check whether the path and file name correctness and you can access it using a file browser.
Java compiler Error 9:
javac: invalid flag: ReverseOrder.javacd\
Usage: javac <options> <source files>
where possible options include:
-g Generate all debugging info
-g:none Generate no debugging info
This error occurs when your javac command went wrong. Retype the command and press enter. Above error message shows set of options (such as –g, -g:none) that you can use with javac command. For example’ javac ReverseOrder.java –verbose’ command will show statements; what compiler actually doing with your source file and how much time it takes.