Reading compiler errors

Everyone writes programs that do not compile. The compiler's messages are precise once you know how to read them. Run this program: it is missing something.

1 A missing semicolon Semicolon.java ● in the editor

public class Semicolon {
    public static void main(String[] args) {
        System.out.println("Almost there")
    }
}

javac printed Semicolon.java:3: error: ';' expected. Read it from the left:

  1. the file (Semicolon.java) and the line (3),
  2. error, then what is wrong: a ; was expected,
  3. the line itself, with a ^ under the place where javac noticed the problem.

The editor marks the same place with a red squiggle; hover over it to read the message. javac notices a missing ; only when it reaches the next thing, so the caret often sits at the end of the line. When there are several errors, fix the first one and compile again: later errors are often caused by the first.

This program should print Ada has 3 cats. javac finds two mistakes; fix them one at a time.

2 Exercise: two mistakes Pets.java ○ to do

public class Pets {
    public static void main(String[] args) {
        int count = 3
        String name = "Ada";
        System.out.println(name + " has " + cont + " cats");
    }
}

When the program crashes

A program can compile and still fail while it runs. Java then stops it with an exception and prints a stack trace: the kind of problem, then the methods that were running, innermost first, each with its file and line. Click a line like Crash.java:7 in the output to jump to it.

3 Division by zero Crash.java ○ to do

public class Crash {
    static int share(int total, int people) {
        return total / people;
    }

    public static void main(String[] args) {
        System.out.println(share(10, 0));
    }
}

The program's exit code is 1: by convention, 0 means success and anything else means failure.

Terminal

Editor.sh · Learn to program by writing and running real code in your browser. Nothing to install; your work stays in this browser.

© 2026 xuwaters.com

Step 1 of 3A missing semicolon