Naming rules/specifications (classes, methods, variables, constants, packages, etc.)

This article follows the Alibaba Development Manual

Naming rules

Correct naming rules can make the project look more beautiful and make it easier to recognize the name.

Let’s talk about the foreshadowing first. Camel case nomenclature is a commonly used naming convention, which is divided into big hump and small hump.

big hump

PascalCase (CamelCase nomenclature): The first letter of each word is capitalized, for example: FirstName, LastName, PhoneNumber.

little hump

camelCase (little camel case nomenclature): the first letter of the first word is lowercase, and the first letter of the remaining words is uppercase, for example: firstName, lastName, phoneNumber.

Class name

The first letter of all words in the class name is capitalized, and the upper camel case nomenclature is used. For example: MyClass, PersonInfo.

method name

The first letter of the method name is lowercase, and the first letter of the rest of the words is uppercase, using camelCase nomenclature. For example: getName(), calculateAverage().

variable name

The first letter of the variable name is lowercase and the first letter of the rest of the words is uppercase, using camelCase nomenclature. For example: age, studentName.

constant name

Constant names are in all capital letters, and multiple words are separated by underscores. For example: MAX_VALUE, CONFIG_FILE.

Package names

Package names must be in lowercase, and there must be one and only one English word with natural semantics between dot separators.
For example: com.example.project. (com, example and project are in a nested relationship, and the corresponding file system is a folder).
Package names always use the singular form, but if the class name has a plural meaning, the class name can use the plural form.
Positive example: The application tool class package name is com.alibaba.open.util, and the class name is MessageUtils

abstract class

Abstract class names start with Abstract or Base;

Exception class

Exception class names end with Exception;

Test class

The test class naming starts with the name of the class it is to test and ends with Test.

brackets

Square brackets are part of the array type. The array is defined as follows: String[] args;
Counterexample: Use String args[] to define.

`

Guess you like

Origin blog.csdn.net/weixin_64618264/article/details/132889154