Javaweb naming rules

Source: Internet
Author: User
Tags class definition uppercase letter administrator password

Naming conventions
Naming specification Naming conventions
Naming conventions


This specification is mainly for Java Development specification project naming
Project naming project naming
Project naming


Project creation, name all letters are lowercase, combined in the following way:
Com.company.projectName.component.hiberarchy.
1. ProjectName: Project Name
2. Component: module name
3. Hiberarchy: Development Hierarchy Name
For example:
Com.company.tims.exchange.dao class folder naming


------------------------------------------
Class Naming conventions

Basic Naming conventions:
Class naming
Naming conventions: Starting with uppercase letters, if there are multiple words, each word is capitalized
Example: UserInfo

Interface naming
Naming conventions: Start with the capital letter "I", and if there are multiple words, capitalize each word first letter
Example: Istudentinfo

Interface implementation class naming:
Naming specification: Remove the first letter "I" of the implemented Interface name with "Impl as the end", if there are multiple words, each single

Prefix uppercase letters.
Example: Studentinfoimpl


------------------------------------------
J2ee+ssh Framework Naming conventions

The Servlet class is named:
Naming conventions: ending with a servlet word
Example: Loginservlet

Pojo Name:
Classes that are automatically generated using hibernate

DAO class naming:
Classes that are automatically generated using hibernate

The action class is named:
Naming conventions: action is named with Pojo name, Pojo name action
For example:
A pojo name is called Diary, and its corresponding action is diaryaction

Actionform class Naming:
Naming specification: Actionform named with Pojo name, Pojo name Form
For example:
A pojo name is called Diary, and its corresponding actioform is Diaryform

Business logic Interface naming:
Naming specification: The name of the business logic interface is established with the Pojo name, Ipojo the service
For example:
A pojo name is called Diary, and its corresponding business logic interface is Idiaryservice

Business logic implementation class naming:
Naming conventions: The naming of the business logic interface implementation class is made by Pojo name
For example:
A pojo name is called Diary, and the corresponding business logic interface implementation class name is Diaryserviceimpl


------------------------------------------------

Class variable Name:
Naming specification: The first letter of the variable name must be lowercase, if the variable name has more than one word, the following word is capitalized,

Do not use "_" connection between words and words, variable name access control must be private, you can increase the 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 conventions: All letters are capitalized, and if there are multiple words, the word is separated from the word with "_". and the variable

Must be public, static, final type
For example: public static final String user_name= "UserName";

Method Name:
Naming specification: The first letter must be lowercase, if the variable name has more than one word, the following words are capitalized, the words and

Do not use "_" to connect between words. Don't use nouns for words.
For example: public int checklogin (String name,string pwd) {}

--------------------------------------------------------
Annotation specification: The annotation specification is the most important part of the whole development specification and must be strictly enforced.
Comments for the class:
Function: Annotate the entire class, briefly outlining the role of the class.
Writing specification: A class's comments must be written before the class's declaration syntax. In the comments to describe the basic role of the class, the 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-determined version number modification
* situation), modification (time of modification, author, change of circumstances)
*
* @see Package name. Reference class name (list parent class, introduce class, one row per class), if any
* Can be omitted
* Relevant data such as: (easy to understand some of this class of constant data and some data format
* or considered to be more important data, if not omitted)
*/
declaration syntax for a class

For example:
/**
* <p>title: Administrator module Data processing class </p>
* <p>description: Two numbers added </p>
* <p>copyright:copyright (c) 2007</p>
* <p>company: Hua Teng software company </p>
*
* @author Dongjingu
*
* @version $Revision: 1.7 $ $Date: 2007/07/08$
*/
public class Admindao

Variable, constant comment:
Function: A simple description of the meaning of the variable.
Writing specification: variable annotations must be written before the definition of a variable, simply describe the meaning of its representation.
Format:
/**
* Variable function Description: (roughly describe the function of the variable)
*/

For example:

/**
* Define Age variables
*/
public int age;
Method notes:
Function: A simple description of the function of the method, its parameters, the meaning of the return value of the annotations.
Writing Specification: Method comments must be written before the method definition. This note includes: A simple description of the function of the method, the parameter of the method

A simple description of the number, return value type, and the meaning of the return value.
Format:
/**
* Method Function Description
* @param args (parameter types can be written in parameters, you can also save
Slightly One row per parameter)
* @return Output parameters (in multiple cases on the same line)
* @see Class # Reference method (the method with which this method has a call relationship
* Test, do not need each method is complete list, to choose meaningful, each
* method takes one line)
* @exception Exception Handling classes (exceptions that can be thrown in a method, each
* One exception in a row)
*/

For example:
/**
* Modify Administrator password
* @param adminid Admin number
* @param oldpassword Old password
* @param password New password
* @return Boolean is edited successfully
* @throws userexception
* @throws serviceexception
*/
Public Booleaneditadminpassword (int adminid,string OldPassword,
String password) throws userexception,serviceexception;


-----------------------------------------------------------
JSP page naming:
Naming conventions: JSP page names start with lowercase letters, and if there are multiple words, the following words are opened in uppercase letters

Head. Name to reflect the meaning of the page, it is best to associate with the module name.
For example:
login.jsp--Login page
REGISTER.JSP--Registration page
MESSAGE.JSP--Customer Message page

------------------------------------------------------------
Java EE Project Engineering folder Organization specification:
Objective: To standardize the resource organization of the learners ' Web application and to form a good document organization habit. The organization of the document shall

Reflect the division of the module.
Depending on the characteristics of the Eclipse tool, the project's directory structure is:
Src
----Storing Java files

Java code
    1. WebRoot
    2. |--images--The public picture required to store the Web application
    3. |--CSS--a common style sheet for storing web programs
    4. |--JS--The common JS file required to store the Web application
    5. |--commons--The public files required to store the Web program
    6. |--Function Module folder (storage of resources related to a function module)
    7. |--images--storing pictures related to this function module
    8. |--CSS--store style sheet files related to this module
    9. |--js--Store the JS file associated with the module
    10. |--jsp, HTML page
    11. |--web-inf
    12. |--classes
    13. |--lib
    14. |--tld file

---------------------------------------------------------------
Java EE Project submission specification
When the project is completed, the project should be delivered to the user as a product, and a good Project organization specification can make it easy for users to find

The resources needed in the project, but also the embodiment of a company's professionalism. When a project is submitted, it must be in the following file format

Submit.
Project Home folder:
Role: Store project other resource files.
Naming specification: Time _ Class Number _ X group.
For example: 070706_gs2t18_ group fourth.
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 the other jar files that must be relied upon to compile the program.
|--javadoc: Saves all class-generated Javadoc API documentation.
|--war: Save the program's archive file
|--xx.war: The project files that have been packaged are ready to be run directly.
|--project: Save the original project code and documents of the development project.
|--product Manual. Doc: Display the method of use of the product by graphic means.
A |--build.xml:ant script that generates a running war file.
|--Project commentary ppt: PPT for project presentation (PPT only for use in school simulation projects, not for other commercial purposes)
Note: In a complete project, the database must have a certain amount of valid test data to support the program's operation

------------------------------------------------------
Name of the package
The Java package name is made up of lowercase words. But because of the Java object-oriented programming features, every Java programmer

You can write your own Java package, in order to guarantee the uniqueness of each Java package naming, in the latest Java programming specification,

Requires the programmer to add a unique prefix to the name of the package that they define. Because the domain name on the internet is not duplicated

, so programmers generally use their own domain name on the Internet as the only prefix for their packages.
Example: Net.frontfree.javagroup

Naming of classes
The name of the class must begin with a capital letter and the other letters in the word are lowercase, and if the class name consists of multiple words,

The first letter of each word should be capitalized such as Testpage, and if the class name contains a word abbreviation, then every

Letters should be capitalized, such as: Xmlexample, and a bit of a naming technique is that because classes are designed to represent objects,

When naming a class, you should choose a noun as much as possible.
For example: Circle

Name of the method
The first word of the name of the method should begin with a lowercase letter, and the following words begin with a capital letter.
Example: Sendmessge

Name of the constant
The names of the constants should all use uppercase letters and indicate the full meaning of the constant. If a constant name consists of multiple word groups

, you should use underscores to divide the words.
Example: Max_value

Name of the parameter
The naming conventions of the parameters are the same as the naming conventions of the methods, and in order to avoid confusion when reading the program, try to ensure

When a number of names is called a word, make the name of the parameter as clear as possible.

Javadoc notes
In addition to our common annotation approach, Java language Specification defines a special kind of annotation,

What we call the Javadoc annotation, which is used to record the API in our code. The Javadoc comment is a multiline comment to

/** begins, and ends with */, comments can contain some HTML tags and special keywords. Good use of Javadoc annotations

Notes that are written can be automatically converted to online documents, eliminating the hassle of writing program documents separately.
For example:
/**
* This is an example of
* Javadoc
*
* @author Darchon
* @version 0.1, 10/11/2002
*/
At the very beginning of each program, the general description of the program and the copyright information are generally used in the Javadoc annotation, followed by the main process

You can add Javadoc comments to each class, interface, method, field, and the first part of each comment

The function of the class, interface, method, and field, this sentence should occupy a single line to highlight its generalization, in this sentence

Later, you can follow a more detailed description of the paragraph. After a descriptive paragraph, you can follow some of the Javadoc comment tags

headers, such as @auther and @version in the example above, which will be shown in a particular way in the generated document

Shown

Variable and constant naming
The variable naming method uses the Hungarian nomenclature, the basic structure is scope_typevariablename, which uses the 3-character prefix to

Represents a data type, the 3-character prefix must be lowercase, followed by a word with a strong ideographic meaning or multiple words

Name, and the first letter of each word capitalized, the other letters lowercase, so that the variable name can be correctly broken

Sentence For example, define an shaping variable that is used to record the number of documents: Intdoccount, where int indicates the data type, after

The face is the English name of the ideographic, with the first letter capitalized for each word. In this way, variable types and variables can be reflected in a variable name

The meaning of the stored value is two-part, which makes the code statement more readable and easier to understand. byte, int, char,

Long, float, double, Boolean, and short.
The variable type and the first letter control relationship are the following table:
Data type/object type/variable prefix/comment
BYTE bye
Char CHR
Float FLT
Boolean bln when making Boolean variables, use bln
Integer/int int
String Str
Single SNG
Short Sht
Long/long LNG
Double/double Dbl
Currency cur
Variant bln astr obj vnt do boolean variable time, use bln, do string array time, use Astr as Object

When used, with obj, when unsure, use vnt.
For arrays, add a to the prefix of the data type, for example, the string array is astr. For multiple functions

Use the global variable, and then add "g_" to the front. For example, a global string variable: G_struserinfo.

The following points should be noted when naming variables:
· Select a meaningful name and note that the first letter of each word should be capitalized.

· The same variable is not used in a function to represent two values with different meanings before and after.

· I, j, K, etc. are only used as cyclic index variables for small loops.
· Avoid naming state variables with flag.
· Use is to name logical variables, such as: Blnfileisfound. By giving the Boolean variable a definite form of naming, the

Other developers to understand more clearly the meaning of the Boolean variable represented.
· If necessary, add a computed qualifier at the end of the variable, such as: Cursalessum.
· The names do not contain, cursales and cursalessum.
· The name of the Static Final variable should be capitalized and indicate the full meaning.
· If you need to abbreviate variable names, be sure to note the consistency of the abbreviation rules throughout your code. For example, if the generation

Using intcnt in some areas of the code, and in other areas using intcount, will add unnecessary

The miscellaneous nature. It is recommended to avoid abbreviations in variable names.
· By placing a quantifier at the end, you can create more uniform variables that are easier to understand and easier to search.

For example, use Strcustomerfirst and strcustomerlast instead of using Strfirstcustomer and

Strlastcustomer. The commonly used quantifier suffixes are: first (one in a set of variables), last (a set of variables

Last), next (the next variable in a set of variables), Prev (the previous one in a set of variables), Cur (a set of variable

The current variable in the volume).
· Choose the best data type for each variable, which can reduce the need for memory, speed up code execution, and

Will reduce the likelihood of errors. The data type used for the variable may affect the result of the variable being evaluated. In this

Case, the compiler does not produce a run-time error, it simply forces the value to conform to the data type requirements. This kind of problem is extremely difficult to find

Find.
· Try to narrow the scope of the variable. If the scope of the variable is greater than it should be, the variable can continue to exist and is not

The resource is still occupied for a long time after the variable is needed. The main problem is that any method in any class can

They are modified, and it is difficult to track exactly where the modifications were made. Occupying resources is one of the important issues involved in the scope

。 Minimizing the scope of a variable can have a huge impact on the reliability of the application.
With respect to the method of naming constants, in Java code, it is recommended to apply constants instead of numbers, fixed strings, whenever

。 That is, the program should try to avoid other numbers except 0 and 1. Constants can be centrally set at the beginning of the program

or wider scope, the name should all be capitalized and indicate the full meaning of the constant. If a constant

Name consists of multiple words, you should use the underscore "_" to divide the words such as: Num_days_in_week,

Max_value.

Source code module config configuration file module Test test module package naming
Package naming package naming
Package naming


Rule o all lowercase. o identifiers are separated by dot numbers. To make the name of the package easier to read. Such as
Com.leadal.shanty
Often several package names O DAO: Data tier O Service: Logical layer O Model: Persistent class definition package implementation serializable

Port, create Serialversionuid primary key Unified ID identifier, long type O Web: Presentation layer and Control layer O enums:

Type O Config: Configuration file Class Package O Resource: Resource file Package class file naming
class file naming class file naming
class file naming

Make the class definition as English as possible all classes begin with an uppercase letter each word starts with an uppercase letter without underlining

or other symbols avoid using abbreviations for words unless their abbreviations are well known, such as HTTP variable naming
Variable named variable name
Variable naming

The first letter is lowercase, the first letter of the middle word is capitalized without _ or & as the first letter. Try to use short and

The variable name of a meaningful word character is generally used only for variables with very short lifetimes. I,j,k,m,n is generally used for
Integers;c,d,e generally used for characters
If the variable is a collection, the variable name applies a complex number.
String MyName;

Int[] students;

int i;

int n;

char c;


Btnew;

(BT is the abbreviation for button)

Constant naming
Constant named constant name
Constant naming

All constant names are all capitalized, separated by ' _ ' between words
int max_num; Method naming rules
Method naming rules method naming rules
Method naming rules


Rule o The first word is usually a verb. o The first letter is smaller, but the first letter of the middle word is uppercase. O

If the method returns the value of a member variable, the method name is typically the get+ member variable name,
If the value returned is a bool variable, it is generally prefixed with IS. O
If the method modifies the value of a member variable, the method name is typically: Set + member variable
Name.
Common verbs o get a single object Loado get list find Listo get paged Pageo Search

Searcho Save Saveo Add Inserto Remove delete Removeo Modify Updatedao
Daodao
DAO Naming conventions
Naming rule naming rules
Naming rules


The interface class is named with the DAO end implementation class class named with DAOIMPL end structure reference as follows: DAO.DOM4J

UserDAOImpl.hibernate.UserDAOImpl.UserDAO Service
Serviceservice
Service Naming specification
Naming specification Naming conventions
Naming conventions

The interface class is named with the service end implementation class class named with SERVICEIMPL end structure reference as follows: Service.impl

. Userserviceimpl.userservice Struts Action
Struts action Struts Action
Struts Action Naming specification
Naming specification Naming conventions
Naming conventions

The class naming and action end structures are referenced as follows: Web.struts.UserAction.GroupAction

Javaweb naming rules

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.