Java Naming conventions: some details

Source: Internet
Author: User
Tags naming convention

Java Naming conventions: some details

any language is used to communicate, has its own set of writing standards, Java is no exception. There are several benefits to focusing on these details:
    1. A good naming convention makes it easier for people to understand and maintain a written program. Of course it's easy to understand, so you can expand later.
    2. At the same time, it also makes the procedure more normative and professional. In this humane and rampant today, our Java naming conventions should also focus on experience.
    3. Learn about naming conventions to better learn and memorize classes and functions in Java class libraries.
    4. Many of the naming conventions involve English, which can promote English learning.
For example: Numbermax, MaxNumber and MaxNumber are different. MaxNumber may be a property name; MaxNumber is generally a class name; Numbermax prefers methods. There is also an English collocation problem here. For example: FileRead, FileReader, this is obviously the latter as the class name better. Readfile,fileread, this is obviously the former as a method more suitable.

The following are some of the principles that you must follow to write Java programs
If there is no good reason, never disobey him.

1. Package
Composed of lowercase letters and small numbers
Java has its own package in Java. Start with Javax, for example: java.awt
Packages developed by other organizations start with the organization's Internet domain name section, such as: Com.sun, Com.borlandSome examples:com.aliasi.hmm;  com.aliasi.classify; Com.aliasi.cluster;com: organization; Aliasi: specific organization name or individual; Classify,cluter: Package name (subject)Org.apache.lucene; Org.apache.lucene.analysis.standard;Org.apache.nutch.ndfs; Org.apache.nutch.fs; org.apache.nutch.db; Org.apache.nutch.parse;

2. Class, interface
Consists of one or more words, with the first letter of each word capitalized, for example: StringBuffer
Class: Generally named by nouns and noun phrases;     Indexoptimizer.java; Webdbreader.java
Interface: Same as class, can use adjective affixes, such as Runnable, comparable

3. Methods
In addition to the first letter lowercase, the same as the class, the interface naming convention. For example: Getpersoninfo ()
For the method to take the property value and set the property value:
Regardless of whether it is a Bean, follow the JavaBean naming convention: GetXXX (), setxxx ()
Conversion object types return different types of methods:
Named ToType, for example: toString (), ToArray ()
Ways to return Views:
Name into Astype () Form, aslist ()
Returns the method of the original type with the same value as the object calling this method (Wrapper Class):
Name into Typevalue () form, e.g. Intvalue (), Floatvalue ()

Parsecharacterencoding (String);
4. Domains (attributes)
Normal domain:
In addition to the first letter lowercase, the same as the class, the interface naming convention. For example: PersonInfo
Constant field:
Consists of one or more words separated by an underscore, such as: VALUES, negative_intinity
The constant field is the only case where the underscore is allowed.

5. Local Variables
The name is the same as the domain, you can use shorthand, such as: I, J, temp, MaxNumberIn fact, defining a class and a method is not too complex, when there are a lot of classes, methods, variables are complex, each to be differentiated, consistent and interrelated.

Java Naming conventions: some details

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.