java註釋範例

 

1、整個類文件註釋

示例如下:

/*

 * @(#)Object.java     1.61 03/01/23

 *

 * Copyright 2003 Sun Microsystems, Inc. All rights reserved.

 * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.

 */

 

package java.lang;

 

註釋結構:

/*

 * @(#){類名稱}.java       {創建時間}

 *

 * {某人或某公司具有完全的版權}

 * {使用者必須經過許可}

 */

 

package java.lang;

 

 

2.     具體類功能註釋

示例如下:

/**

 * Class <code>Object</code> is the root of the class hierarchy.

 * Every class has <code>Object</code> as a superclass. All objects,

 * including arrays, implement the methods of this class.

 *

 * @author  unascribed

 * @version 1.61, 01/23/03

 * @see     java.lang.Class

 * @since   JDK1.0

 */

public class Object {}

 

註釋結構:

/**

 * <code>{類名稱}</code>{此類功能描述}

 *

 * @author  {作者}

 * @version {版本,常用時間代替}

 * @see     java.lang.Class

 * @since   JDK{jdk版本}

 */

public class Object {}

 

3.     類變量註釋

示例如下:

/** The value is used for character storage. */

 private char value[];

 

註釋結構:

 /** {此值是用來存儲/記錄什麼的}*/

 private String str ;

 

4.     類方法註釋

示例如下:

    /**

     * Returns a new string that is a substring of this string. The

     * substring begins with the character at the specified index and

     * extends to the end of this string. <p>

     * Examples:

     * <blockquote><pre>

     * "unhappy".substring(2) returns "happy"

     * "Harbison".substring(3) returns "bison"

     * "emptiness".substring(9) returns "" (an empty string)

     * </pre></blockquote>

     *

     * @param      beginIndex   the beginning index, inclusive.

     * @return     the specified substring.

     * @exception  IndexOutOfBoundsException  if

     *             <code>beginIndex</code> is negative or larger than the

     *             length of this <code>String</code> object.

     */

public String substring(int beginIndex) {

return substring(beginIndex, count);

}

 

註釋結構:

    /**

     * {方法的功能/動作描述}

     *

     * @param      {引入參數名}   {引入參數說明}

     * @return      {返回參數名}   {返回參數說明}

     * @exception   {說明在某情況下,將發生什麼異常}

     */

public String substring(int beginIndex) {

return substring(beginIndex, count);

}

 

 

5.     類方法中代碼塊註釋

示例如下:

/*

* 調用持久化類,將數據保存到庫

*

* 判斷是添加,還是修改

*/

boolean ifSucc = false;

if(request.getParameter("YINGLI_ID")==null){

       String GUID = new RandomGUID().toString();

       stressTestDataBean.setUSER_ID(Integer.toString(userId));

       stressTestDataBean.setSIGN_ISBN((String)vSectNum.get(0));

       stressTestDataBean.setSHENHE_JIEGUO("0");

       stressTestDataBean.setGUID(GUID);

       stressTestDataBean.setCREATE_DATE("getdate()");

       stressTestDataBean.setSTATE("A");

                                         

       ifSucc = StressTestDataDao.addStressTestData(db,stressTestDataBean);

}else{

       ifSucc = StressTestDataDao.mendStressTestData(db,stressTestDataBean);

}

 

 

註釋結構:

/*

* {功能描述}

*

* {具體實現動作}

*/

boolean ifSucc = false;

if(request.getParameter("YINGLI_ID")==null){

       String GUID = new RandomGUID().toString();

       stressTestDataBean.setUSER_ID(Integer.toString(userId));

       stressTestDataBean.setSIGN_ISBN((String)vSectNum.get(0));

       stressTestDataBean.setSHENHE_JIEGUO("0");

       stressTestDataBean.setGUID(GUID);

       stressTestDataBean.setCREATE_DATE("getdate()");

       stressTestDataBean.setSTATE("A");

                                         

       ifSucc = StressTestDataDao.addStressTestData(db,stressTestDataBean);

}else{

       ifSucc = StressTestDataDao.mendStressTestData(db,stressTestDataBean);

}

引用通告地址: http://tmsoft.lsxy.com/trackback.php?tbID=476&extra=40560e
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章