Java EE Project Code writing specification share _java

Source: Internet
Author: User
Tags exception handling lowercase naming convention uppercase letter

Code Coding Specification Objective: To be able to standardize in the coding process, to develop good behavior habits for future program development.
Code Coding specifications Use Scope: Java project development.

Package naming specification:
Objective: The nomenclature of package should reflect the good division of Project resources.

The Servlet class contains the package naming specification: Company name. Development Group name. Project name. Web.servlet
For example: Net.linkcn.web.servlet

The custom Label class contains the package naming specification: Company name. Development Group name. Project name. Web.tags
For example: Net.linkcn.web.tags

The package naming specification for the Filter class: Company name. Development Group name. Project name. Web.filter
For example: Net.linkcn.web.filter

The action class contains the package naming specification: Company name. Name of the development group. Web.struts.action
For example: net.linkcn.web.struts.action

Actionform class is the package naming specification: Company name. Development Group name. Project name. Web.struts.form
For example: Net.linkcn.web.struts.form

JavaBean Package naming specification: Company name. Development Group name. Project name. Web.struts.service.impl
For example: Net.linkcn.web.service.impl

JavaBean implements the interface naming specification: Company name. Development Group name. Project name. Web.service
For example: Net.linkcn.web.service

The DAO class contains the package naming specification: Company name. Name of the development group. Dao.impl
For example: Net.linkcn.dao.impl

The interface implemented by the DAO class is named in the package: Company name. Development Group name. Project name. DAO
For example: Net.linkcn.dao

Pojo class and HBM file Package naming specification: Company name. Development Group name. Project name. DAO.HBM
For example: NET.LINKCN.DAO.HBM

Global public class, interface class containing package naming specification: Company name. Development Group name. Project name. Global
For example: Net.linkcn.global

Package naming specification for global tool classes: Company name. Development Group name. Project name. util
For example: Net.linkcn.util

Class Naming conventions
Basic Naming conventions:

Class, interface naming
Naming conventions: Starting with uppercase letters, and if there are multiple words, capitalize each word head
For example: Studentinfo

Interface naming
Naming convention: Starting with the capital letter "I", if there are multiple words, each word head letter capitalized
For example: Istudentinfo

Interface implementation class naming:
Naming convention: The first letter "I" of the implemented interface name is removed, with "Impl as the end", and if there are multiple words, each word head is capitalized.
For example: Studentinfoimpl

J2ee+ssh Framework Naming conventions

Servlet class Naming:
Naming specification: ending with a servlet word
For example: Loginservlet

Pojo named:
Classes that are automatically generated using Hibernate can

DAO class naming:
Classes that are automatically generated using Hibernate can

Action Class Name:
Naming conventions: The name of the action is formulated with Pojo names, Pojo name action
For example:
A pojo name is called a diary, and its corresponding action is diaryaction

Actionform class Name:
Naming convention: The name of the Actionform is formulated with Pojo names, Pojo name form
For example:
A pojo name is called Diary, and its corresponding actioform is Diaryform

Business logic Interface naming:
Naming conventions: The naming of business logic interfaces is made with Pojo names, Ipojo name Service
For example:
A pojo name is called Diary, and its corresponding business logic interface is Idiaryservice

Business logic implementation class naming:
Naming specification: Business logic interface Implementation Class naming is made with Pojo name
For example:
A pojo name called Diary, the corresponding business logic interface implementation class name is Diaryserviceimpl

Class variable naming:
Naming specification: variable name first letter must be lowercase, if the variable name has more than one word, after the first letter of the word, the word and words do not use "_" to do the connection, variable name access control must be private, you can add setter and getter method.
For example: private int studentage;
public int Getstudentage ()
{
return studentage;
}

public void setstudentage (int studentage)
{
This.studentage=studentage;
}

Constant Name:
Naming specification: All uppercase letters, if there are more than one word, separated by "_" between words. And the variable must be public, static, final type
For example: public static final String user_name= "UserName";

Method name
Naming convention: The first letter must be lowercase, if the variable name is composed of more than one word, the first letter of the following words in uppercase, words and words do not use "_" to do the connection. Don't use nouns for words.
For example: public int checklogin (String name,string pwd) {}

Annotation Specification: Annotation specification is the most important part of the whole development specification and must be strictly enforced.
Note for class:
Role: Annotate the entire class and briefly outline the role of the class.
Writing specification: Annotations of a class must be written before the declaration syntax of the class. In the comments, describe the basic role of the class, author, date, version, company name, copyright notice.
Format:
/* *
* Class function Description: (roughly describe the function of the class)
* @author: Creator name
*
* @version: The version number of the class file starts at 1.0 (self-determination of the version number of the change
* situation), modification (change time, author, change)
*
* @see Package name. Reference class name (list parent class, introduce class, one row for each class)
* Can be omitted
* Relevant data such as: (easy to understand some of the constant data of this class and some data format
* or data that is considered to be more important, if not omitted)
*/
declaration syntax for a class
For example:
/**
*

Title: Administrator module Data processing class


*
Description: Add two numbers


*
Copyright:copyright (c) 2007


*
Company: Hua Teng software co., ltd


*
* @author Dongjingu
*
* @version $Revision: 1.7 $ $Date: 2007/07/08$
*/
public class Admindao

variables, constant annotations:
function: Simply describe the meaning of the variable.
Writing specification: variable annotations must be written before the variable definition, simply describing the meaning of its representative.
Format:
/**
* Variable function Description: (roughly describe the function of the variable)
*/
For example:
/**
* Define Age variables
*/
public int age;

Method Comment:
Action: A simple description of the method's function, its parameters, and the annotations of its value.
Writing Specification: Method annotations must be written before the method definition. The comment includes a simple   description of the method's function, a description of the method's parameters, the return value type, and a simple meaning of the return value.
Format:
       /**
   * Method Feature Description
   * @param args (parameter Types can be written after the parameters, or you can save the
   *   slightly. One row for each parameter
   * @return Output parameters (written in multiple cases on the same line)
   * @see Class # Reference method (a method that has an invocation relationship with this method for parameter
   *&N bsp; , do not have to complete the list of each method, to select meaningful, each
   *   method takes one row)
   * @exception Exception handling Class (exceptions that can be thrown in a method, one row for each
   *  )
/
For example:
/**
  * Modify Admin password
  * @par Am Adminid Administrator Number
  * @param oldpassword old password
  * @param password new password
* @return Boolean edit succeeded
&nb Sp * @throws userexception
  * @throws serviceexception
  */
Public booleaneditadminpassword (int admin Id,string oldpassword,
String password) throws userexception,serviceexception;

JSP page Name:
Naming specification: The JSP page name starts with a lowercase letter, and if more than one word is formed, the following word begins with an uppercase letter. Name to reflect the meaning of the page, it is best to be associated with the module name.
For example:
login.jsp--Login page
REGISTER.JSP--Registration page
MESSAGE.JSP--Customer Message page

Java EE Project Project folder Organization specification:
Objective: To standardize the resource organization of Web application, and to form good file organization habits. The organization of the document should embody the division of the module.
Depending on the characteristics of the Eclipse tool, the directory structure of the project is:

Src
----Store Java files
WebRoot
|--images--The public pictures you need to store your Web programs
|--CSS-a common style sheet for storing web programs
|--JS--The public JS files needed to store the Web program
|--commons--The public files needed to store the Web program
|--Function Module folder (storing resources related to a functional module)
|--images--store pictures related to this feature module
|--CSS--Store the style sheet files associated with the module
|--js--store JS files related to the module
|--jsp, HTML page
|--web-inf
|--classes
|--lib
|--tld file

Java EE Project submission specification
Project completion to the project as a product delivery users, good Project organization specifications can make it easy for users to find the resources needed in the project, but also a professional embodiment of the company. When a project is submitted, it is submitted in the following file format.

Project Home folder:
Function: Store Other resource files for the project.
Naming specification: Time _ Class Number _ Group X.
For example: 070706_gs2t18_ Fourth group.

The following folders and files are included under the Project home folder:
|--SRC: Save the. java file.
|--database: Save the database script file or the database backup file.
|--source: Saves all files in the Webroot directory in the Eclipse project.
|--depend: Save other jar files that you must rely on to compile the program.
|--javadoc: Saves the Javadoc API documentation generated by all classes.
|--war: Save the program's archive file
|--xx.war: The engineering files that have been packaged can be run directly.
|--project: Save the original project code and document of the development project.
|--Product specification. DOC: Show how the product is used.
|--build.xml:ant script that is used to generate a running war file.
|--Project explanation. ppt: PPT for project presentation (PPT only for use in school simulation projects, not for other commercial purposes)

Note: A complete project, the database must have a certain amount of effective test data to support the operation of the program

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.