Java Arena
Step 5 of 5

Reading compiler errors

Before a program runs, the compiler reads all of it. If something isn't valid Java, it stops and prints an error instead, and nothing runs. Errors are normal: they're the compiler pointing at the exact spot it didn't understand. Here is a program with one character missing:

public class Main {
    public static void main(String[] args) {
        System.out.println("Hello")
    }
}
What javac prints
Main.java:3: error: ';' expected
        System.out.println("Hello")
                                   ^
1 error

Read it piece by piece:

  • Main.java:3 is the file and the line number: line 3.
  • error: ';' expected says what went wrong: Java expected a semicolon.
  • The next line repeats the code, and the ^ below it points at the exact position, here the end of the line where the ; belongs.
  • 1 error counts the errors. Fix the first one first: one mistake sometimes confuses the compiler into reporting more lines after it.

On this site each error also gets a plain-English explanation under it, and the editor marks the line.

A few words to know

  • A statement is one instruction. The ones in this module each end with a semicolon.
  • The text inside the parentheses of println( ... ) is the parameter: the value the method works with.
  • A typo in a name gives a cannot find symbol error. For example System.out.printn("Hi"); makes the compiler report that there is no method printn.

Your task

Challenge 1 of 3

This program has one small mistake that stops it from compiling. Press Check to see the error, fix it, and check again. The program should print:

First line
Second line
Third line

Challenge 2

Two mistakes this time, both about spelling and capital letters. Fix them so the program prints:

Upper and lower case matter.
Java noticed.

Challenge 3

A closing quote and a closing brace are missing. Find both and fix them so the program prints:

Almost there
Done!