77范文网 - 专业文章范例文档资料分享平台

Java coding rule

来源:网络收集 时间:2019-02-15 下载这篇文档 手机版
说明:文章内容仅供预览,部分内容可能不全,需要完整文档或者需要复制内容,请下载word后使用。下载word有问题请添加微信号:或QQ: 处理(尽可能给您提供完整文档),感谢您的支持与谅解。点击这里给我发消息

Java coding rules

(a) The class name should be the same as file name

Example: public class Point => Point.java

(b) The location of file

The root directory of the project is decided, and it puts it in the directory tree according to the “.” in the package name.

Example: com.yellowbook.myProject => /com/yellowbook/myProject

(c) Package name

The package name should be all lowercase Example: com.yellowbook.common.dao

(d) Class name

The first letter of each word in the class name should be capitalized. The length of the class name should be within 20 characters. The name should be a noun. Example: GoogleSearchEngine

(e) Exceptional Class name

The word “Exception” should be put at the end of the Class name.

Apart from the word “Exception”, the name should be limited to 15 characters. Example: ClassNameException

(f) Interface name

The letter “I” should be in the front of the class name. Example: IClassName

(g) Implement class name

“Impl” should be at the end of the class name. Example: ClassNameImpl

(h) Abstract class name

“Abstract” should be in the front of the class name. Example: AbstractClassName

(i) Constant name

Static variable (constant) declared names should all be capital letters. When the name consists of two or more words, delimit it with “_\ Example: ER_CASE_WITH_UNDERSCORES (j) Variable name

The first letter should be lower case, and the head of following words should be capitalized. The words in the variable name should be meaningful.

Neither an array nor a primitive variable should be written in one line. Example(Bad): int a, b[]; × Example(Good): int firstArray[]; Int secondArray[]; ○

Static variables should not be used if possible unless they are static final variables. Example: targetList, anniversaryDate etc.

(k) Method name

The first letter should be lowercase, and the first letter of the following words should be capitalized.

Example: setSecurtyFlag, setMailSecurtyLevel etc.

(l) Factory method name

Example: newXXX(), createXXX()

(m) Converter method name

Example: toXXX()

(n) Boolean returned method name

Is + Adjective, can + Verb, has + Past participle

Example: isEmpty(), canGet(), hasChenged()

(o) Loop counter

I, j, and k are sequentially used for loop counter

(p) Symmetry of name

When the class name and the method name are named, the following English symmetry should be noted. add/remove insert/delete get/set start/stop begin/end send/receive first/last

apply/release put/get up/down show/hide

source/target open/close

source/destination increment/decrement lock/unlock old/new

next/previous

(q) No meaningful name

The following nouns should not be used to name variables. Example: Info, Data, Temp, Str, Buf ×

(r) Source Comment

Block comment:

/*

* block comment * block comment */

One line comment if (xxx) { }

(s) Method comment

/**

* The functionality of the method should be explained. *

* @param the explanation of parameter

* @return the explanation of returned value

* @exception the explanation of expected exception of the method * @see Class name * @since version */

(t) Class comment

/* one line comment */ xxxMethod(xxx);

/**

* The functionality of the class *

* @see class name * @since version */

(u) Statement

Two or more variable definitions should not be in one line.

\

Example(Bad): i++; j++; ×

if (xxx) i++; × Example(Good):

if (xxx) {

i++;

}

Switch block should be:

If “break” is not used、the comment“/* no break*/”should be added.

“default” should not be omitted. “break” must be specified in the “default” block. switch (a) {

case ABC: ???? /* no break */ case DEF: ???? break; default:

???? break;

}

(v) Collection

It is recommended that List(ArrayList), Map(HashMap), and Iterator should be used instead of Vector, Hashtable, and Enumeration, respectively.

(w) import

import xxx.xxx.* is not recommended. (x) Final

If a parameter of a method does not have its value changed within the method, it is strongly recommended that the word “final” be added in front of the parameter. Example:

Private String searchRouteName(final String strSource, final String strDestination) { …. }

百度搜索“77cn”或“免费范文网”即可找到本站免费阅读全部范文。收藏本站方便下次阅读,免费范文网,提供经典小说综合文库Java coding rule在线全文阅读。

Java coding rule.doc 将本文的Word文档下载到电脑,方便复制、编辑、收藏和打印 下载失败或者文档不完整,请联系客服人员解决!
本文链接:https://www.77cn.com.cn/wenku/zonghe/467154.html(转载请注明文章来源)
Copyright © 2008-2022 免费范文网 版权所有
声明 :本网站尊重并保护知识产权,根据《信息网络传播权保护条例》,如果我们转载的作品侵犯了您的权利,请在一个月内通知我们,我们会及时删除。
客服QQ: 邮箱:tiandhx2@hotmail.com
苏ICP备16052595号-18
× 注册会员免费下载(下载后可以自由复制和排版)
注册会员下载
全站内容免费自由复制
注册会员下载
全站内容免费自由复制
注:下载文档有可能“只有目录或者内容不全”等情况,请下载之前注意辨别,如果您已付费且无法下载或内容有问题,请联系我们协助你处理。
微信: QQ: