DEV Community

VIDHYA VARSHINI
VIDHYA VARSHINI

Posted on

Errors in Java

We know that Java is a reliable programming language because it can catch mistakes early while writing the code and also keeps checking for errors when the program is running. In this blog, we will discuss the type of errors which can occur while doing a code.

public class Laptop{
    public static void main(String[] args){
        System.out.println("hello world");
    }
}
Enter fullscreen mode Exit fullscreen mode

Output: hello world

Here are the possible errors which can occur:

  1. If the class first letter is given in capital like 'Class' , the error occur *error: class, interface, enum, or record expected Class Laptop{ *
  2. If the file name doesn't match the public class name like it is given as Home.java instead of Laptop.java, then the error occur as
    error: file not found: test.java .

  3. If semicolon is removed from the code, then the error will occur as
    error: ';' expected
    System.out.println("hello world")

  4. If double quotes was removed in the arguments, then the error occur as
    ** error: ')' or ',' expected
    System.out.println(hello world)**
    ** error: not a statement
    System.out.println(hello world)**

  5. If one of the parentheses ( is removed, then the error occur as
    *error: ')' or ',' expected *
    ** System.out.println("hello world" **

  6. If static is missing in the main method, the error occurs
    error: package system does not exist
    system.out.print("hello world");

  7. If wrong case word is given, the error occurs
    error: class, interface, enum, or record expected

  8. If dot(.) is removed, the error occurs
    error: class, interface, enum, or record expected
    error: ';' expected

  9. If args is missing in the main method, the error occurs
    error: expected

  10. If double quotes are replaced with single quotes, the error occurs
    error: unclosed character literal

Top comments (0)