Search This Blog

Tuesday, December 29, 2009

Naming Conventions in java:


Naming Conventions in java:
Standardize coding J2EE projects
Source: Network reprint
The purpose of coding norms: in the encoding process to achieve standardization and procedures for future development to develop good habits.
Regulate the use of coding: J2EE project development.
Package naming convention:
Objective: To pack the naming convention should be reflected in a good division of project resources
category where the servlet package naming convention: the company name. the development of group name. project name. web.servlet
For example: net.linkcn.web.servlet
Category where a custom label package naming convention: the company name. The development of group name. Project name. Web.tags
For example: net.linkcn.web.tags
Category where the packet filter naming convention: the company name. The development of group name. Project name. Web.filter
For example: net.linkcn.web.filter
Class Action naming convention where the package: company name. The development of group name. Project name. Web.struts.action
For example: net.linkcn.web.struts.action
ActionForm Class naming convention where the package: company name. The development of group name. Project name. Web.struts.form
For example: net.linkcn.web.struts.form
Javabean naming convention where the package: company name. The development of group name. Project name. Web.struts.service.impl
For example: net.linkcn.web.service.impl
Javabean achieve interface naming convention: the company name. The development of group name. Project name. Web.service
For example: net.linkcn.web.service
DAO Class naming convention where the package: company name. The development of group name. Project name. Dao.impl
For example: net.linkcn.dao.impl
DAO interface class to achieve in the package naming convention: the company name. The development of group name. Project name. Dao
For example: net.linkcn.dao
POJO Class and package hbm file naming convention: the company name. The development of group name. Project name. Dao.hbm
For example: net.linkcn.dao.hbm
Overall public class, interface where the packet type of naming convention: the company name. The development of group name. Project name. Global
For example: net.linkcn.global
Tools where the overall package naming convention: the company name. The development of group name. Project name. Util
For example: net.linkcn.util
Class naming convention
Basic naming convention:
Type, interface name
Naming convention: capital letters at the beginning, if there are multiple words, the first letter of each word capitalized
For example: StudentInfo
Interface name
Naming convention: capital letters "I" at the beginning, if there are multiple words, the first letter of each word capitalized
For example: IStudentInfo
Interface type name:
Naming convention: the name of the interface will be the first letter "I" removed in order to "Impl as at the end of" If there are multiple words, the first letter of each word capitalized.
For example: StudentInfoImpl
J2EE + SSH framework naming convention
servlet named category:
Naming convention: The word at the end of Servlet
For example: LoginServlet
POJO name:
Hibernate use category can be automatically generated
DAO Class name:
Hibernate use category can be automatically generated
Class Action name:
Naming convention: Action name to the name of POJO to develop, POJO Name Action
For example:
POJO name of a Diary, its corresponding action for DiaryAction
ActionForm Class name:
Naming convention: ActionForm named to draw up a POJO name, POJO Name Form
For example:
POJO name of a Diary, its corresponding actioForm for DiaryForm
Business logic interface name:
Naming convention: business logic interface to the name to develop POJO name, IPOJO Name Service
For example:
POJO name of a Diary, the corresponding business logic interface IDiaryService
Business logic implementation class name:
Naming convention: business logic interface POJO class name to the name to develop
For example:
POJO name of a Diary, the corresponding business logic interface type called DiaryServiceImpl
Type variable name:
Naming convention: the first letter of variable name must be lowercase, if the variable names are composed of a number of words, followed by an uppercase first letter of the word, between words and the words do not use "_" to do to connect, access control variable name must be private, you can increase its setter and getter methods.
For example: private int studentAge;
public int getStudentAge ()
(
return studentAge;
)
public void setStudentAge (int studentAge)
(
this.studentAge = studentAge;
)
Constant name:
Naming convention: all capital letters, if there are multiple words of the word and between words to "_" to separate. And the variables must be public, static, final type
For example: public static final String USER_NAME = "userName";
Method named
Naming convention: first letter must be lowercase, if the variable names are composed of a number of words, followed by an uppercase first letter of the word, between words and the words do not use "_" to do to connect. Do not use the word term.
For example: public int checkLogin (String name, String pwd) ()
Notes norms: Notes regulate the development of norms of the most important component of must be strictly enforced.
Class Notes:
Role: Notes of a whole class of such a simple overview of the role.
Written norms: Class notes must be written in such before the statement syntax. Described in the notes to the basic role of this kind, the author, date, version, company name, copyright notice.
Format:
/ * *
* Functional Description: (describe the type of function more or less)
* @ Author: author name
*
* @ Version: the version number of types of documents to start from 1.0 (the version number to determine their own additions and changes
* The case), the revision of (modified, author, change the situation)
*
* @ See package name. Reference to the class name (listed in the parent category, the introduction of categories, each type of line), if there is
* Optional
* Relevant data such as: (easy to understand some of the types of constant data and the format of certain data
* Or that the data is more important, if not optional)
* /
Type of statement syntax
For example:
/ **
*
Title: Data Processing Manager module type
*
Description: the sum of the two a few
*
Copyright: Copyright (c) 2007
*
Company: xxx
*
* @ Author xxx
*
* @ Version $ Revision: 1.08
* /
public class AdminDAO
Variables, constants Notes:
Role: a brief description of the significance of the variables.
Written specification: variable notes must be written in the variable definition, a brief description of the significance of their representatives.
Format:
/ **
* Variable Functional Description: (general description of the function of variables)
* /
For example:
/ **
* The definition of the age variable
* /
public int age;
Method Notes:
Role: a brief description of the method function, its parameters, return values the annotation significance.
Written specification: This method must be written on the methods of the Notes before the definition. The Notes include the following: a simple method to describe its functions, methods, parameters, return value type, the return value of the meaning of a simple description.
Format:
/ **
* Method function
* @ Param args (parameters types can be written on the parameters, but also can save
* Slightly. Parameters of each line)
* @ Return the output parameters (number of situations in the same line)
* @ See Class # reference method (with this method the relationship between the method calls for the Senate
* Test, do not have to have a complete list of each method, it is necessary to choose a meaningful, each
* Method of accounting for line)
* @ Exception Exception class (methods can be caused by abnormal, each
* In unusual line)
* /
For example:
/ **
* Modify the administrator password
* @ Param adminId administrator ID
* @ Param oldPassword Old Password
* @ Param password the new password
* @ Return boolean success whether the Editor
* @ Throws UserException
* @ Throws ServiceException
* /
public booleaneditAdminPassword (int adminId, String oldPassword,
String password) throws UserException, ServiceException;
Jsp page name:
Naming convention: jsp page name must begin with lowercase letters, words, if there are multiple components, behind the words in capital letters at the beginning. Name to reflect the significance of the page, it would be linked with the module name.
For example:
login.jsp - login page
register.jsp - registration page
message.jsp - Feedback page
J2EE project folder organization norms:
Objective: To standardize the training resources web application forms of organization, to form a good habit of document organization. Organizational form of the document should reflect the division of modules.
Eclipse tool in accordance with the characteristics of the project directory structure as follows:
src
Java file storage ----
WebRoot
| - images - stored procedures required for public web picture
| - css - stored procedures required for public web style sheets
| - js - stored procedures required for web documents public js
| - commons - store web of public documents required
| - Folder function modules (function modules with a storage-related resources)
| - images - stored with the function modules related to image
| - css - the storage module associated with the style sheet file
| - js - the storage module associated with the js file
| - jsp, html page
| - WEB-INF
| - classes
| - lib
| - tld file