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:
- 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.
- 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.
- Learn about naming conventions to better learn and memorize classes and functions in Java class libraries.
- 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