Naming rules for java packages, classes, methods, properties, constants

Java package names are composed of lowercase words, and the first letter of the class name is capitalized; the path of the package conforms to the definition of the developed system module, such as production to production, material to material, and basic class to basic class. In order to see the package name to understand which module is, so as to directly find the corresponding implementation in the corresponding package.

 

    Due to the object-oriented characteristics of Java, each Java developer can write his own Java Package. In order to ensure the uniqueness of the naming of each Java Package, in the latest Java programming specification, developers are required to add a prefix to the package name defined by themselves. unique prefix. Because domain names on the Internet are not repeated, most developers use their company's domain name on the Internet as the only prefix for their packages. For example: com.sun.swt. ….

 

    Therefore, we know that the general company name is "com.company name.project name.module name....".
    So, how do we name our personal projects?

    After my search for "personal" words, there are "individual, personal, private, one-man", further analysis of the meaning of the above 4 words, and to ensure the uniqueness, use the first 4 letters of each word As a prefix, it happens to be distinguished from "com". as follows:

    indi :

         Individual projects refer to projects initiated by individuals but not completed by themselves. They can be public or private projects, and the copyright mainly belongs to the initiator.

         The package name is " indi . Initiator name . Project name . Module name . … ".

    pers :

         Personal projects refer to projects initiated by individuals, completed by themselves, and can be shared. The copyright mainly belongs to individuals.

         The package name is " pers .personname.projectname.modulename . … ".

    priv :

         Private projects refer to projects initiated by individuals, completed by themselves, non-public and privately used, and the copyright belongs to individuals.

         The package name is " priv.personname.projectname.modulename . … ".

    onem  :

         Same as "indi", "indi" is recommended.

 

    In addition, in order to distinguish the difference between the team project and the project mentioned above, I have an extension:

    team :

         Team project refers to the project initiated by the team and developed by the team, and the copyright belongs to the team.

         The package name is " team.TeamName.ProjectName.ModuleName . … ".

    with  :

 

 For company projects, the copyright is owned by the company that initiated the project.

         The package name is " com.companyname.projectname.modulename . … ".

 

1: Package: It is used to classify the classes that complete different functions and put them in different directories (packages). The naming rule of the package: the company domain name is reversed as the package name. For example www.baidu.com For package name: each letter needs to be lowercase. For example: com.baidu.test; the full name of the Test class under this package is: com.baidu.Test.java.

 
If no package is used when defining the class, then java thinks that the class we define is located in the default package (default package).
 
2: Class: Capitalize the first letter. If a class consists of multiple words, the first letter of each word is capitalized, and no connectors are used in the middle. Use English as much as possible. such as ConnectionFactory
 
3:方法:首单词全部小写,如果一个方法由多个单词构成,那么从第二个单词开始首字母大写,不使用连接符。addPerson
 
4:属性:与方法相同。如ageOfPerson
 
5:常量:所有单词的字母都是大写,如果有多个单词,那么使用下划线链接即可。
 
如:public static final int AGE_OF_PERSON = 20;  //通常加上static

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326267812&siteId=291194637