{"id":"printing-compiler-errors","slug":"compiler-errors","title":"Reading compiler errors","text":"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:\n\n```java\npublic class Main {\n    public static void main(String[] args) {\n        System.out.println(\"Hello\")\n    }\n}\n```\n\n```javac\nMain.java:3: error: ';' expected\n        System.out.println(\"Hello\")\n                                   ^\n1 error\n```\n\nRead it piece by piece:\n\n- `Main.java:3` is the file and the **line number**: line 3.\n- `error: ';' expected` says what went wrong: Java expected a semicolon.\n- The next line repeats the code, and the `^` below it points at the exact position, here the end of the line where the `;` belongs.\n- `1 error` counts the errors. Fix the first one first: one mistake sometimes confuses the compiler into reporting more lines after it.\n\nOn this site each error also gets a plain-English explanation under it, and the editor marks the line.\n\n### A few words to know\n\n- A **statement** is one instruction. The ones in this module each end with a semicolon.\n- The text inside the parentheses of `println( ... )` is the **parameter**: the value the method works with.\n- 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`.\n","task":"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:\n\n```\nFirst line\nSecond line\nThird line\n```\n","kind":"code","seed":"public class Main {\n    public static void main(String[] args) {\n        System.out.println(\"First line\");\n        System.out.println(\"Second line\")\n        System.out.println(\"Third line\");\n    }\n}\n","solution":"public class Main {\n    public static void main(String[] args) {\n        System.out.println(\"First line\");\n        System.out.println(\"Second line\");\n        System.out.println(\"Third line\");\n    }\n}\n","hints":["The error message names a line number. Look at the end of that line.","Each of the three print statements ends with a semicolon `;`, and one of them is missing it."],"tests":[{"name":"Output","stdin":"","expect":"First line\nSecond line\nThird line","hidden":false}],"require":[],"forbid":[],"more":[{"task":"Two mistakes this time, both about spelling and capital letters. Fix them so the program prints:\n\n```\nUpper and lower case matter.\nJava noticed.\n```\n","kind":"code","seed":"public class Main {\n    public static void main(String[] args) {\n        system.out.println(\"Upper and lower case matter.\");\n        System.out.printin(\"Java noticed.\");\n    }\n}\n","solution":"public class Main {\n    public static void main(String[] args) {\n        System.out.println(\"Upper and lower case matter.\");\n        System.out.println(\"Java noticed.\");\n    }\n}\n","hints":["`System` starts with a capital `S`. With a small `s`, Java thinks `system` is the name of a package, which is why the message talks about a package that doesn't exist.","The method is `println`: print, then a lower-case L and N, for line."],"tests":[{"name":"Output","stdin":"","expect":"Upper and lower case matter.\nJava noticed.","hidden":false}],"require":[],"forbid":[]},{"task":"A closing quote and a closing brace are missing. Find both and fix them so the program prints:\n\n```\nAlmost there\nDone!\n```\n","kind":"code","seed":"public class Main {\n    public static void main(String[] args) {\n        System.out.println(\"Almost there);\n        System.out.println(\"Done!\");\n    }\n","solution":"public class Main {\n    public static void main(String[] args) {\n        System.out.println(\"Almost there\");\n        System.out.println(\"Done!\");\n    }\n}\n","hints":["Text starts and ends with a double quote on the same line. Which text has only one quote?","Count the braces: the class and the main method each need a `{` and a `}`. The program ends one `}` short."],"tests":[{"name":"Output","stdin":"","expect":"Almost there\nDone!","hidden":false}],"require":[],"forbid":[]}]}