Names

In addition to the requirement that a class name exactly match the name of the .java file, there are three things to bear in mind about naming classes, interfaces, variables, and methods.

  • Avoid names that are the same as keywords. So, for example, do not use default as the name of anything, because default is a Java keyword.

  • By convention, class and interface names begin with a capital letter. Variables that serve as constants are all capitals with underscores between words. A capital letter starts each word in the name of the class, interface, method, or variable. Everything else begins with a lowercase letter.

  • A variable may start with a letter, an underscore, or a $.

Listing 3.2 shows examples of these rules and conventions.

Code Listing ...

Get PURE Java™ 2 now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.