Java Naming rule package naming in Android Development

Source: Internet
Author: User

Java in Android Development
Naming rule package
 
The Java package name is composed of lowercase words. However, due to the characteristics of Java object-oriented programming, every Java programmer can write their own Java packages. To ensure the uniqueness of each Java package name, in the latest Java programming specification, the programmer is required to add a unique prefix before the name of the defined package. Because domain names on the Internet are not repeated, programmers generally use their own domain names on the Internet as the unique prefix of their packages.

Example: net. frontfree. javagroup

Package division and naming rules:

Java code:
Com. mycompany. util
Com. mycompany. myproject
Com. mycompany. myproject. util
Com. mycompany. myproject. Model
Com. mycompany. myproject. Dao
Com. mycompany. myproject. Dao. EJB

Com. mycompany. myproject. Dao. hibernate
Com. mycompany. myproject. Service
Com. mycompany. myproject. Service. impl
Com. mycompany. myproject. webapp. Action
Com. mycompany. myproject. webapp. Filter
Com. mycompany. myproject. webapp. Listener
Com. mycompany. myproject. webapp. taglib


Class Name
The class name must start with an upper-case letter and the other letters in the word must be lower-case. If the class name is composed of multiple words, the first letter of each word should be in the upper-case format, such as testpage; if the class name contains the abbreviation, each letter in the written word should be capitalized, for example, xmlexample. Another naming technique is that the class is designed to represent objects, therefore, you should select a noun whenever possible when naming a category.
Example: Circle

Method Name
The first word of the method name should start with a lower-case letter, and the subsequent words should start with an upper-case letter.
Example: sendmessge

Constant name
The constant names should all use uppercase letters and indicate the complete meaning of the constant. If a constant name is composed of multiple words, the words should be separated by underscores.
Example: max_value

Parameter Name
The parameter naming rules are the same as the method naming rules. To avoid confusion during reading the program, make sure that the parameter name is a word as clear as possible.

Javadoc comments
In addition to using our common annotation methods, the Java language specification also defines a special annotation, that is, the javadoc annotation we call, it is used to record APIs in our code. Javadoc annotation is a multiline annotation that ends with a single end. It can contain HTML tags and specialized keywords. The advantage of using javadoc annotations is that the compiled notes can be automatically converted into online documents, saving the trouble of writing program documents separately.

At the beginning of each program, javadoc is generally used to comment on the overall description of the program and copyright information. Then, javadoc comments can be added to each class, interface, method, and field in the main program, the first part of each comment first summarizes the functions completed by the class, interface, method, and field in one sentence. This sentence should take a separate line to highlight its generalization, A more detailed description section can be followed after this sentence. After descriptive paragraphs, you can also follow special paragraphs starting with the javadoc annotation label, such as @ auther and @ version in the preceding example. These paragraphs are displayed in a specific way in the generated document.

Although adding comments to a poorly designed program won't make it a good program, writing programs according to programming specifications and adding good comments to the program can help you write out the perfect design, it is more important to run highly efficient and easy-to-understand programs, especially when multiple people work together to complete the same project. As the saying goes, it is good to spend a little time adapting to Java programming specifications.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.