pTutorial

New way to learn Programming

When to java error comes

Java errors

This section contains brief information about java compilation errors like unreachable code, else without else etc.

If you are new in java programming then you should know about the some common compilation errors.

Check the some common compilation error in java are following below with proper explanation.

Error number 1

Class First{  
public static void main(String args[]){  
System.out.println("Welcome back java");  
}  
}  
C:\java program>javac First.java
First.java:1: error: class, interface, or enum expected
Class First{
^
First.java:2: error: class, interface, or enum expected
public static void main(String args[]){
              ^
First.java:4: error: class, interface, or enum expected
  }
  ^
3 errors

Explanation

The above error comes when the class keyword is not written in right way like having any letter of class keyword is capital or missing any of letter of class keyword.

Error number 2

class First{  
public Static void main(String args[]){  
System.out.println("Welcome back java");  
}  
}  
C:\java program>javac First.java
First.java:2: error:  expected
public Static void main(String args[]){
             ^
First.java:2: error: invalid method declaration;
 return type required
public Static void main(String args[]){
                   ^
2 errors

Explanation

The above error comes when the static keyword is not written in right way like having any letter of static keyword is capital or missing any of letter of static keyword.

Error number 3

class First{  
public Static void main(String args[]){  
System.out.println("Welcome back java");  
}  


C:\java program>javac First.java
First.java:4: error: reached end of file while parsing
  }
   ^
1 error

C:\java program>

Explanation

The above error comes when the curly braces "{}" are missing.

Error number 4

class First{  
public Static void main(String args[]){  
System.out.println("Welcome back java")  
}  
}

Explanation

The above error comes when we forget to terminate the statement. Terminate means that put the semi colon (;) after each statement.


QUOTES OF THE DAY

Beauty is truth, Truth beauty- That is all

LIKE ON FACEBOOK

+1 ON GOOGLE

SHARE ON TWITTER