Java project developed naming specification of Power node Java College collation
- 2020-06-19 10:09:13
It's better to use English, not Hanyu Pinyin
1: Package (package) : Used to group classes that perform different functions under different directories (packages). Package naming rules: reverse the company domain name as the package name. www.bjpowernode.com for package names: lowercase for each letter. For example: com. bjpowernode.test. The full name of the Test class under this package is: com.bjpowernode.Test.java. If the class is defined without package, java assumes that the class we define is in the default package (default package).
2: Classes: Capitalize the first letter. If a class is composed of more than one word, capitalize the first letter of each word without using any connectors. Try to use English. Such as ConnectionFactory
3: Method: The first word is all lowercase. If a method is composed of more than one word, the first letter is capitalized from the second word, without using a linker. addPerson
4: Properties: Same as method. Such as ageOfPerson
5: Constant: All words are capitalized. If there are more than one word, use underlined links.
public static final int AGE_OF_PERSON = 20; // Usually add static
Supplement: Note the following points when naming variables:
· Choose meaningful names and note that the first letter of each word is capitalized.
· Do not use the same variable to represent two values with different meanings before and after the function.
· i, j, k, etc. are only used as circular index variables for small loops.
· Avoid naming state variables with Flag.
· Name logical variables with Is, such as blnFileIsFound. By giving Boolean variables an affirmative form, other developers have a clearer understanding of what Boolean variables represent.
· Append a compute qualifier, such as curSalesSum, to the end of the variable if necessary.
· Naming does not include curSales and curSalesSum.
Names of static final variables (constants) should be capitalized and indicated with full meaning.
· If you need to abbreviate a variable name, 1 must pay attention to the 1 sex of the abbreviation rule throughout the code. For example, if you use intCnt in some areas of your code and intCount in another, you add unnecessary complexity to your code. It is recommended to avoid abbreviations in variable names.
· More uniform variables can be created by placing a quantifier at the end, which is easier to understand and easier to search for. For example, use strCustomerFirst and strCustomerLast instead of strFirstCustomer and strLastCustomer. Common quantifier suffixes are: First (the first variable in group 1), Last (the last variable in group 1), Next (the next variable in group 1), Prev (the last variable in group 1), Cur (the current variable in group 1).
· Select the best data type for each variable, which reduces the memory requirement, speeds up code execution, and reduces the possibility of errors. The type of data used for a variable may affect the results produced by the calculation of that variable. In this case, the compiler does not generate a run-time error; it simply forces the value to conform to the data type. Such problems are extremely difficult to find.
· Minimize the scope of variables. If the scope of a variable is greater than it should be, it can continue to exist and consume resources long after it is no longer needed. The main problem with them is that any method in any class can be modified, and it is difficult to keep track of where the changes are made. The occupation of resources is an important issue of scope. For variables, minimizing the scope can have a huge impact on the reliability of the application.
Regarding the naming of constants, the JAVA code advocates the use of constants in place of Numbers and fixed strings whenever possible. In other words, try not to have any Numbers in your program other than 0,1. Constants can be concentrated at the beginning of the program definition or within a wider scope, names should be in uppercase, and the constant should have full meaning. If a constant name is composed of more than one word, the underlined "_" should be used to split the words such as NUM_DAYS_IN_WEEK, MAX_VALUE.