๐ WAYPOINT LESSON
Names, comments, and compiler errors
โญ beginnerโณ 10 min read๐ Lesson 3 of 256
Naming conventions, comments, and how to read javac error messages.
Two commandments of Java style (the AP exam follows them too):
- Class names start with an uppercase letter, one word per part:
Gradebook,StudentList. - Variables and methods start lowercase, then capitalize:
totalScore,findMax().
Identifiers may contain letters, digits, _, $, but may not start with a
digit, and int, class, public are reserved keywords.
Comments are for humans and are ignored by the compiler:
// one-line comment
/* a comment
spanning lines */
Reading compiler errors. javac reports the file, the line, and a
(terse) reason:
Solution.java:4: error: ';' expected
System.out.println("hi")
^
The caret points where the compiler got confused โ often after the real
mistake. A missing ; on line 4 is reported on line 4; a missing } may be
reported at the very end of the file.