Java Program Naming conventions

Source: Internet
Author: User

Program naming rules
Tip: The module designer determines the module naming conventions for the software (such as classes, functions, variables, etc.) to ensure that the style of the module design document is consistent with the style of the code. You can extract or reference (if present) from the programming specifications of the organization.
Naming rules
1. Package naming
The Java program uses the package name as the file directory name, through the package's hierarchical structure implementation to classify the program and the Modularization management. Package name requirements are all in English letter lowercase, through. To split, it is recommended to show the name of the company in the package name or product (project) abbreviated English, usually "Company name + product (Project) name + module name + sub-module name", such as: Ausware.apply.manage (Ausware for the company English name, apply for the product name, manage for the module name), Commercial software usually starts with COM, such as: com.sun.java.swing (COM is the universal prefix, Sun is the company name, Java is the product name, Swing is the module name), and whether to add COM does not make mandatory requirements.

2. Class naming
In Java, the uniform requirements of the class name in English words or combinations, you can use shorthand, the first letter of the word is capitalized, the words are separated by capital letters. The class name should accurately represent the function of this class, usually the "module name + feature name" structure, such as: Enginemanage,deviceaction.

3. Name of class member variable
The action class member variable requires a m_, if the variable is a global variable, starting with G_; Data structure class members are not recommended to start with m_.
Variables need to express the meaning clearly, the use of English words or combinations, you can use shorthand, separated by capital letters, in addition to the range of letters, the first letter lowercase. Typically "range + type + variable description", where the most common types are: Map (representing the map set HashMap, map), VEC (vector set vector), list (for list), B (for Boolean), I (for int), STR (that is, string, because string type is very common in Java, usually can not start with STR to avoid cumbersome), L (for long), C (for Char), F (for float), D (for Double). Example:
Operation class:
public class Enginemanage
{
private static Enginemanage G_instance=null; Global
Private hashmap<long,enginecontext> m_mapenginecontexts=new HashMap (); Members
Private Boolean m_binitflag = false; Member, whether to initialize flag
public int m_iport = 0;
public long m_lsize = 0;
}
Data structure classes:
public class Devicemodel
{
Public String devnamealias = null; Device aliases
Public String devname = null; Device Name
public float fsize = 0;
public double dwidesize = 0;
}

4. class member function naming
Class member function name need to express function function, in English words or combinations, you can use shorthand, the first letter lowercase, the first letter of the middle Word to uppercase, the remaining lowercase. The first word is an action, followed by a function object, usually: "Action + object name", for example: Createenginecontext,adddevice.

5. function parameter name
Use English words or combinations, you can use shorthand, the first letter lowercase, the middle word is separated by capital letters. Don't start with m_ and G_.
For parameter names of interface functions, it is recommended that the parameters be explicitly expressed as input, output, input and output, and type. Input usually with in, output usually with O, input output usually with IO, for example:
Public long Createenginecontext (String enginecontextclassname,refstring oerrmsg);
Interface functions:
public int Retrivedatas (String instrid, Vector Ovecdatas, refstring oerrmsg);
Instrid in is input, str is type, ID is variable description;
O in Ovecdatas is output, VEC is type, datas is variable description;
The O in oerrmsg is the output and errmsg is the variable description.

6. function internal variable name
In principle, in addition to the count variable i,n,k,j, should be used in English words or combinations to express a clear meaning, you can use shorthand, do not use m_ and g_ and so on. Common variables are usually "type + variable description"; The name of a composite custom object can be changed directly to the object name, the first letter to lowercase, the variable to be returned is suggested with a RET prefix, and the TEMP variable is proposed with the TMP prefix. Example:
for (int i; i<10; i++);//Count variable
Boolean Bsearchflag; Prefix by type
int isize;
Long lwidth;
String Strdevname; prefixed with string type str
String Devname; does not have a string type prefix, because string is very common to omit
Enginecontext enginecontext = null; Compound custom object, with the type name, change the initial letter to lowercase
Enginecontext tmpenginecontext = null; With TEMP variable tmp prefix
Enginecontext retenginecontext = null; With return variable prefix RET

7. Constant name
A constant name uses uppercase words or underscores _ to combine multiple words to express meanings, such as:
Public final static String Yes = "yes";
Public final static int debug_error = 2; Log error messages
Public final static String syslog_process_name = "SYSLOG";

Java Program Naming conventions

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.