Naming conventions in Java syntax

Source: Internet
Author: User

Package, class, interface, enumeration type, parameters, constant fields, methods and exceptions;


1. Naming of packages (package)
The package name should be in full English descriptors, which are made up of a lowercase word. And the prefix of the package name is always a top-level domain,
Usually com, edu, gov, mil, net, org, etc.;
such as: Com.yjhmily.test

2. Naming of classes (class)
The class name should be a noun, in a mixed case, capitalized by the first letter of each word. Try to ensure that the class name is concise and rich in description.
Use full words to avoid abbreviations (unless the project has a uniform abbreviation specification or the abbreviation is more widely used, like URLs, HTML)
such as: filedescription

3, the name of the interface (Interface)
Similar to the naming conventions of Class. On the basis of satisfying the CLASSD naming rules, ensure that the first letter of the beginning is "I",
Easy to distinguish from normal class. Its implementation class name takes the second letter of the interface name to the last, and satisfies the naming specification of the class name;
such as: Imenuengine

4. Enumeration (enum) naming
Similar to the naming conventions of Class. On the basis of satisfying the CLASSD naming rules, guarantee the first letter "E" at the beginning,
Easy to distinguish from normal class.
such as: Euserrole

5. Naming of exceptions (Exception)
Exceptions (Exception) typically use the letter E to indicate an exception, and for a custom exception class, the suffix must be Exception
such as: businessexception

6. Naming Methods (method)
The method name is a verb, in mixed case, the first letter in lowercase, followed by the first letter of the word capital.
The method name describes the action behavior of the method as much as possible. A method that returns a Boolean of type is typically preceded by "is" or "has"
such as: Getcurrentuser (), AddUser (), hasauthority ()

7, the name of the parameter (Param)
The first letter is lowercase, followed by the first letter of the word. The parameter number name does not allow an underscore or dollar sign to start,
Although this is syntactically permissible. Parameter names should be short and descriptive.
such as: Public UserContext getloginuser (String loginName);

8, the name of the constant field (Constants)
Static constants fields (static final) are all uppercase letters, and the words are separated by underscores;
such as: public static final Long FEEDBACK;
Publicstatic Long User_status;


Naming conventions in Java syntax

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.