Sticking with the Java naming conventions makes your programs easy to read and avoids errors. Make sure that you choose descriptive names with straightforward meanings for the variables, constants, classes, and methods in your program. As mentioned earlier, names are case sensitive. Listed below are the conventions for naming variables, methods, and classes.
- Use lowercase for variables and methods. If a name consists of several words, concatenate them into one, making the first word lowercase and capitalizing the first letter of each subsequent word—for example, the variables radius and area and the method print.
- Capitalize the first letter of each word in a class name—for example, the class names ComputeArea and System.
- Capitalize every letter in a constant, and use underscores between words—for example, the constants PI and MAX_VALUE.
It is important to follow the naming conventions to make your programs easy to read. Do 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.
Top comments (0)