Naming the Java naming rules package in Android development

Source: Internet
Author: User
Tags comment tag

The name of the AVA package is made up of lowercase words. However, due to the Java object-oriented programming feature, each Java programmer can write their own Java package, in order to guarantee the uniqueness of each Java package naming, in the latest Java programming specification, the programmer is required to add a unique prefix to the name of the package they define. Because domain names on the Internet are not duplicated, programmers generally use their own domain name on the Internet as the only prefix for their packages.

Example: Net.frontfree.javagroup

Package partitioning 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


Naming of classes
The name of the class must start with a capital letter and the other letters in the word are lowercase, and if the class name consists of multiple words, the first letter of each word should be capitalized such as Testpage, and if the class name contains a word abbreviation, each letter of the word should be capitalized, such as: Xmlexample, One more naming technique is that because a class is designed to represent an object, you should choose a noun when you name the class.
For example: Circle

name of the method
The first word of the name of the method should begin with a lowercase letter, and the following words begin with a capital letter.
Example: Sendmessge

name of the constant
The names of the constants should all use uppercase letters and indicate the full meaning of the constant. If a constant name consists of multiple words, you should use underscores to split the words.
Example: Max_value

name of the parameter
The naming conventions for parameters are the same as the naming conventions for methods, and to avoid confusion when reading a program, make the name of the parameter as clear as possible if the parameter name is a single word.

Javadoc Notes
In addition to the common annotations that Java can use, the Java language Specification defines a special kind of comment, which is what we call the Javadoc annotation, which is used to record the API in our code. The Javadoc comment is a multiline comment that ends with a comment that can contain some HTML tags and special keywords. The advantage of using the Javadoc annotation is that comments written can be automatically converted to online documents, eliminating the hassle of writing program documents separately.

At the beginning of each program, generally use Javadoc annotation to the overall description of the program and copyright information, and then in the main program for each class, interface, method, field to add Javadoc comments, the beginning of each note in a sentence to summarize the class, interface, methods, fields completed functions, This sentence should occupy a single line to highlight its general role, in the following sentence can follow a more detailed description of the paragraph. After a descriptive paragraph, you can also follow some special paragraphs that start with the Javadoc comment tag, such as the @auther and @version in the example above, which appear in the generated document in a specific way.

Although adding comments to a poorly designed program does not make it a good program, writing programs according to programming specifications and adding good annotations to your programs can help you write programs that are perfectly designed, run efficiently, and are easy to understand, especially if the programming specification becomes more important when multiple people work together to complete the same project. As the saying goes, "Ax", it's good to spend a little time adapting to the Java programming specification.

Naming the Java naming rules package in Android development

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.