Chapter 1 · Foundations

Reading compiler errors

You are reading the whole lesson on one page. Back to one step at a time

Step 1 of 17 · Concept

Everyone gets errors

Everyone writes programs that do not compile. javac's messages look strange at first, but they are precise once you can read them.

In this lesson you will:

  • read javac's messages, part by part,
  • fix errors one at a time,
  • read a stack trace when a program crashes.
public class Semicolon {
    public static void main(String[] args) {
        System.out.println("Almost there")
    }
}
public class Pets {
    public static void main(String[] args) {
        int count = 3
        String name = "Ada";
        System.out.println(name + " has " + cont + " cats");
    }
}
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));
    }
}
public class Grades {
    static int percent(int points, int max) {
        return points * 100 / max;
    }

    public static void main(String[] args) {
        int max = 20;
        int ada = 18;
        int bob = 0;
        System.out.println("Ada: " + percent(ada, max) + "%");
        System.out.println("Bob: " + percent(max, bob) + "%");
    }
}
public class Party {
    static int slices(int pizzas, int people) {
        return pizzas * 8 / people;
    }

    public static void main(String[] args) {
        int pizzas = 3;
        int adults = 2;
        int children = 2;
        int people = adults - children;
        System.out.print(people + " people, ");
        System.out.printn(pizzas + " pizzas");
        int each = slices(pizzas, people);
        System.out.println("Slices each: " + each);
    }
}
public class Recipe {
    public static void main(String[] args) {
        int eggs = 3;
        int each = eggs / 2.0;
        System.out.println("Eggs each: " + each);
    }
}
Terminal
Step 1 of 6A missing semicolon

Keyboard shortcuts

The step

ContinueEnter
Previous / next stepAlt+[ · Alt+]
Move along the steps bar← → Home End, then Enter
From a quiz's title to its answers↓
Skip to the stepTab, then Enter (first on the page)
Course outlineAlt+O
These shortcuts?

The workspace

Run the stepCtrl+Enter (⌘↵ on a Mac)
Lesson → editor → consoleF6 (Shift+F6 back)
Output ↔ TerminalCtrl+`
Focus the editorCtrl+. (⌘. on a Mac)
Hide or show the lessonAlt+L
Restore, close a messageEsc (outside the editor and the terminal)

The editor

Leave the editorF6 (Shift+F6 back); or Ctrl+M (⌃⇧M on a Mac), then Tab moves the focus (not in the vim mode)
Open a file by nameCtrl+P (⌘P on a Mac)
All commandsCtrl+Shift+P (⌘⇧P on a Mac) or F1
Go to a lineCtrl+G (⌃G on a Mac)
Show or hide the filesCtrl+B (⌘B on a Mac)
Previous / next file tabCtrl+Shift+[ · Ctrl+Shift+] (⌘⇧[ · ⌘⇧] on a Mac)
The file tabs← → Home End on a tab; Delete closes it
Save the files nowCtrl+S (⌘S on a Mac)
Go to a symbol in the fileCtrl+Shift+O (⌘⇧O on a Mac)
Go to the definitionF12
Format the fileCtrl+Shift+F (⌘⇧F on a Mac), or Shift+Alt+F
Go back / forward after a jumpAlt+← · Alt+→ (⌃- · ⌃⇧- on a Mac)