1. 類的命名使用名詞
2. 接口的命名使用名詞或形容詞,例如 Runnable ,Accessable
3. 用複數表示提供靜態方法的類,如Beans ,Types
4. 方法的命名使用動詞
5. 變量的命名使用名詞
6. 集合變量使用複數命名,如 Vector orderItems;
7. 使用this關鍵字標識對象屬性,使其與局部變量區分
8. 常量命名,大寫+下劃線,如MAX_VALUE
9. 使用C風格的註釋來註解暫時不用的方法 /**/
10. 在註釋的描述性文字以及java doc標籤中保留空行,如
/**
* Descriptive text for this entity.
*
* @tag Descriptive text for this tag.
*/
11. java doc 標記
<code></code>標記包名、類名、字段名
<pre></pre>告訴瀏覽器保留原有格式,一般用於註釋代碼
{@link #Flag(String)}在文檔中提供超鏈接
類或接口的一般註釋爲:
/**
* Description.
*
* @author
* @version
*
* @see
* @since
* @deprecated
*/
方法一般註釋格式爲:
/**
* Description.
*
* @param
* @return
* @exception
*
* @see
* @since
* @deprecated
*/
11. 使用統一的標籤標註未解決的問題,如:
// :UNRESOLVED: EBW, 11 July 1999
// This still does not handle the case where
// the input overflows the internal buffer!!
12. 對於沒有break的switch語句加入註釋//Fall through!