The purpose of code writing standards is to achieve standardization in the coding process and develop good behavioral habits for future program development.
Scope of use of code writing specifications: J2EE project development.
Package naming convention:
Purpose: The naming convention of packages should reflect a good division of project resources
Naming convention for the package where the servlet class is located: company name.development group name.project name.web.servlet
For example: net.linkcn.web.servlet
Naming convention for the package where the custom tag class is located: company name.development group name.project name.web.tags
For example: net.linkcn.web.tags
Naming convention for the package where the filter class is located: company name.development group name.project name.web.filter
For example: net.linkcn.web.filter
Naming convention for the package where the Action class is located: company name.development group name.project name.web.struts.action
For example: net.linkcn.web.struts.action
Naming convention for the package where the ActionForm class is located: company name.development group name.project name.web.struts.form
For example: net.linkcn.web.struts.form
Javabean package naming convention: company name. development group name. project name. web.struts.service.impl
For example: net.linkcn.web.service.impl
Javabean implementation interface naming convention: company name.Development group name.Project name.web.service
For example: net.linkcn.web.service
Naming convention for the package where the DAO class is located: company name.development group name.project name.dao.impl
For example: net.linkcn.dao.impl
The interface implemented by the DAO class has a naming convention in the package: company name.development group name.project name.dao
For example: net.linkcn.dao
Naming convention for the package where the POJO class and hbm files are located: company name. development group name. project name.dao.hbm
For example: net.linkcn.dao.hbm
Naming convention for the package where global public classes and interface classes are located: company name.Development group name.Project name.global
For example: net.linkcn.global
Naming convention for the package where the global tool class is located: company name.development group name.project name.util
For example: net.linkcn.util
Class naming convention Basic naming convention:
Class and interface naming convention: start with a capital letter. If there are multiple words, capitalize the first letter of each word. For example: StudentInfo
Interface naming convention: start with a capital letter "I", if there are multiple words, capitalize the first letter of each word. For example: IStudentInfo
Interface implementation class naming:
Naming convention: Remove the first letter "I" from the implemented interface name and end with "Impl". If there are multiple words, capitalize the first letter of each word.
For example: StudentInfoImpl
J2EE+SSH framework naming convention
servlet class naming:
Naming convention: ends with the word Servlet. For example: LoginServlet
POJO naming:
Just use the classes automatically generated by hibernate
DAO class naming:
Just use the classes automatically generated by hibernate
Action class naming:
Naming convention: Action naming is based on POJO name, POJO name Action
For example:
A POJO name is Diary, and its corresponding action is DiaryAction.
ActionForm class naming:
Naming convention: The naming of ActionForm is determined by the POJO name, and the POJO name Form
For example:
A POJO name is Diary, and its corresponding actioForm is DiaryForm
Business logic interface naming:
Naming convention: The naming of the business logic interface is determined by the POJO name, and the IPOJO name is Service
For example:
A POJO name is Diary, and its corresponding business logic interface is IDiaryService.
Business logic implementation class naming:
Naming convention: The naming of the business logic interface implementation class is based on the POJO name. For example:
A POJO is named Diary, and the corresponding business logic interface implementation class is named DiaryServiceImpl.
Class variable naming:
Naming convention: The first letter of the variable name must be lowercase. If the variable name consists of multiple words, the first letter of the subsequent words must be capitalized. Do not use "_" to connect the words. The access control of the variable name must be private. You can It adds setter and getter methods.
For example: private int studentAge;
public int getStudentAge()
{
return studentAge;
}
public void setStudentAge(int studentAge)
{
this.studentAge=studentAge;
}
Constant naming:
Naming convention: All letters are in capital letters. If there are multiple words, the words should be separated by "_". And the variable must be of public, static, final type. For example: public static final String USER_NAME=”userName”;
Method naming convention: the first letter must be lowercase. If the variable name consists of multiple words, the first letter of the following words should be capitalized. Do not use "_" to connect words. Do not use nouns for words.
For example: public int checkLogin(String name,String pwd){}
Annotation specifications: Annotation specifications are the most important component of the entire development specification and must be strictly implemented.
Class notes:
Function: Annotate the entire class and briefly outline the function of the class.
Writing convention: Class annotations must be written before the declaration syntax of the class. In the comments, describe the basic function of the class, author, date, version, company name, and copyright statement.
Format:
/* *
* Class function description: (roughly describe the function of the class)
* @author: author name
*
* @version: The version number of the class file starts from 1.0 (determine the addition and change of the version number yourself
* Situation), modification status (modification time, author, modification status)
*
* @see package name. Reference class name (list parent classes, introduce classes, each class occupies one line), if any
*can be omitted
* Relevant data such as: (to facilitate understanding of some constant data of this class and the format of some data
* Or data that is considered important, if not available, it can be omitted)
*/
Class declaration syntax is as follows:
/**
*
Title:Administrator module data processing class
*
Description: Add two numbers
*
Copyright: Copyright (c) 2007
*
Company:Huateng Software Company
*
* @author Tong Jinhu
*
* @version $Revision: 1.7 $ $Date: 2007/07/08$
*/
public class AdminDAO
Variable and constant comments:
Function: Briefly describe the meaning of this variable.
Writing standards: Variable comments must be written before the variable definition, briefly describing its meaning.
Format:
/**
* Variable function description: (roughly describe the function of the variable)
*/
For example:
/**
*Define age variable
*/
public int age;
Method comments:
Function: A brief description of the function of the method, annotations on the meaning of its parameters and return values.
Writing convention: Method comments must be written before the method definition. The annotation includes: a brief description of the function of the method, a brief description of the method's parameters, return value type, and return value meaning.
Format:
/**
*Method function description
* @param args (the parameter type can be written after the parameter, or it can be omitted
* Omitted. Each parameter occupies one line)
* @return output parameters (multiple situations written on the same line)
* @see class #reference method (methods related to calling this method are for reference
* For exams, it is not necessary to list every method in full. You must choose meaningful ones.
*Methods occupy one line)
* @exception exception handling class (exceptions that can be thrown in the method, each
*Exceptions occupy one line)
*/
For example:
/**
* Change administrator password
* @param adminId administrator number
* @param oldPassword old password
* @param password new password
* @return boolean whether the editing was successful
* @throws UserException
* @throws ServiceException
*/
public booleaneditAdminPassword(int adminId,String oldPassword,
String password) throws UserException,ServiceException;
Jsp page naming:
Naming convention: The jsp page name should start with a lowercase letter. If it consists of multiple words, the subsequent words should start with an uppercase letter. The name should reflect the meaning of the page and should preferably be linked to the module name.
For example:
login.jsp --Login page
register.jsp --Registration page
message.jsp --Customer message page
J2EE project project folder organization specifications:
Purpose: To standardize the resource organization form of students' web applications and form good file organization habits. The organization of the document should reflect the division into modules.
According to the characteristics of the eclipse tool, the directory structure of the project is:
src
----Storage java files
WebRoot
|--images --store public images required by web programs
|--css -- stores the public style sheets required by web programs
|--js --Store public js files required by web programs
|--commons --store public files required by web programs
|--Function module folder (to store resources related to a certain function module)
|--images --store images related to this function module
|--css --Store the style sheet files related to this module
|--js --Store js files related to this module
|--jsp, html page
|--WEB-INF
|--classes
|--lib
|--tld file
J2EE project submission specifications When the project is completed, the project must be delivered to the user as a product. Good project organization specifications allow users to easily find the resources needed for the project, and are also a reflection of the company's professionalism. When submitting a project, it must be submitted in the following file format.
Project main folder:
Function: Store other resource files of the project.
Naming convention: time_class number_group X.
For example: 070706_GS2T18_Group 4.
The project main folder includes the following folders and files:
|--src: Save .java file.
|--database: Save the script file or database backup file of the database.
|--source: Save all files in the WebRoot directory in the eclipse project.
|--depend: Save other jar files that must be relied upon to compile the program.
|--javadoc: Save the javadoc api documentation generated by all classes.
|--war: archive file to save the program
|--xx.war: The project file has been packaged and can be run directly.
|--project: Save the original engineering code and files of the development project.
|--Product manual.doc: Shows how to use the product in pictures and text.
|--build.xml: ant script, used to generate running war files.
|--Project explanation.ppt: ppt for project explanation (ppt is only for use in school simulation projects and not for other commercial purposes)
Note: In a complete project, the database must have a certain amount of valid test data to support the operation of the program.