java naming conventions and conventions

Java naming rules and conventions

1. Project name

It is best to use English, and all words should be in lowercase, such as testjavaproject, studentmanagement, etc., of course, you can also use Chinese, such as "student management system".

2. Related naming in Java project

1. Package name

The package name is uniformly lowercase, and there is only one natural semantic English word between the dot separators. It is best to use the domain name to write it in reverse, and there will be no conflict. Such as com.cnblogs.sun99bk.myutil and so on.

In addition, it should be noted that it is best to use the singular form of the package name uniformly, but if the class name has a plural meaning, the class name can use the plural form.

2. Class name

The class name uses UpperCamelCase style and must follow the camel case, that is, the first letter of each word is capitalized, and the public class name should be consistent with the project name.

3. Method name, object name and variable name

Method names, parameter names, member variables, and local variables all use the lowerCamelCase style uniformly, which means that the first letter of the first word must be lowercase (if there is only one word, all lowercase), and the first letters of the remaining words are all uppercase. The method name is represented by a verb + noun or a verb, such as append(), getName(), etc.

4. Attribute name

Same as the object naming method, it is expressed in the form of nouns or adjectives + nouns, such as name, dbClassName, dbUser, dbPassword, dbUrl, etc.

5. Constant

Constant names are all capitalized, separated by underscores between words, and strive for complete and clear semantic expression, and don't take long names, such as MAX_STOCK_COUNT, etc.

Naming convention
1. Project name is all lowercase
2. Package name is all lowercase

When creating a new package project, multi-layer design may be involved. The package name of each layer should follow the specification of all lowercase package names. The upper-level package name of a function is all lowercase and composed of characters.

3. The naming of the class name should follow the principle of initial capitalization. The name of the class must start with a capital letter and the other letters in the word are lowercase; if a class name is composed of multiple words, the first letter of each word must be Should be capitalized, such as ModelWhAction; if the name of the class contains a word abbreviation, each letter of the word should be capitalized, such as: XMLExample, there is another naming technique because the class is designed to represent objects, so in the naming Try to choose nouns when classifying.

4. The naming of variables should follow easy-to-understand principles. For example, use name instead of a, b, and c. In addition to variable names, examples, including classes and class constants, are all case-mixed. The first letter of the first word is lowercase, and the first letter of subsequent words is uppercase. Variable names should not start with an underscore or dollar sign, although this is grammatically allowed. But doing so at work will reduce the readability of the code, which is not standardized at work.

5. The first word of the method name should start with a lowercase letter, and the following words should start with an uppercase letter.

6. The variable naming and method naming that need to be used should follow the principle of lowercase first letter. If the name is composed of multiple words, the first letter of each word must be capitalized (except for the first word).

7. Use camel case to name variable names composed of multiple words.
Such as: modelFacade

8. When naming constants, you need to follow the principle of all capitals.

In JAVA code, at any time, it is advocated to use constants instead of numbers and fixed strings. In other words, in addition to 0, 1 in the program, try to avoid other numbers. Constants can be concentrated in the definition at the beginning of the program or in a wider scope. The names should all use capital letters and indicate the full meaning of the constant. The declaration of constants should be in all capitals, separated by underscores between words.

示例:static final int MIN_WIDTH = 4;static final int MAX_WIDTH = 999;static final int GET_THE_CPU = 1;

9. All naming rules must follow the following rules:

1)、名称只能由字母、数字、下划线、$符号组成

2)、命名时不能以数字开头

3)、在命名是绝对不能出现Java关键字。

4)、绝对不允许在命名时出现中文及拼音命名。

10. Object naming follows the little camel case format:

Method names, parameter names, member variables, and local variables all use the lowerCamelCase style uniformly, which means that the first letter of the first word must be lowercase (if there is only one word, all lowercase), and the first letters of the remaining words are all uppercase. The method name is represented by a verb + noun or a verb, such as append(), getName(), etc. And it is related to the class name. Such as Map infoMap; StringBuffer nameBuffer;

Guess you like

Origin blog.csdn.net/qq_44346427/article/details/109504327