DEV Community

Mohan Mogi
Mohan Mogi

Posted on

Java Error Messages Explained with Examples

1.

Game.java:6: error: ';' expected
*Game.java → File name
*6 → Error is on line 6
*';' expected → Java expected a semicolon

2.

System.out.println("Hello world");
*System → Built-in Java class
*out → Output stream object
*. → Access operator
*println() → Prints text and moves to the next line

The dots are very important:
System.out.println("Hello");
↑ ↑

Without the second dot:
System.out println("Hello");

Java cannot understand the statement.

3.

The parameter is missing a variable name.
In Java, method parameters need both a type and a name.

*String[] → Type
*args → Parameter name (identifier)

4.

The problem is that after public static, Java expects a return type and a method name.

5.

Java expects class, interface, enum, or record after public.

Top comments (0)