blue green surreal desert looks like alien sea flor with snow bridge

1.9 Java | Naming Conventions

Sticking with the Java naming conventions makes your programs easy to read and avoid errors.

Make sure that you choose descriptive names with straightforward meanings for the variables, constants, classes, and methods in your program. Note that names are case sensitive. Below I will list the naming conventions:

  • Use lower case for variables and methods. If a name consists of several words, concatenate them into one, making the first word lower case and the letter of the following words upper case.
    • i.e. variables radius, area; methods print, nextDouble
  • Capitalize the first letter of each class name. Class uses the same naming convention for variables & methods, except the first letter is of the first word is capitalized.
    • i.e class names ComputeArea and System
  • Capitalize every letter in a constant, and use underscores between words.
    • i.e. PI and MAX_VALUE

Following a naming conventions makes your programs easy to read, since you can identify what is what by distinguishing these differences.

*Note that you should not choose class names that are already used in the Java library. For example, since the System class is defined in Java, you should not name your class System.

What's Your Opinion?