JAVA代码注释规范

转载地址

 

整个类文件注释

示例如下:

Java代码
  1. /*
  2. * @(#)Object.java      1.61 03/01/23
  3. *
  4. * Copyright 2003 Sun Microsystems, Inc. All rights reserved.
  5. * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
  6. */  
  7.   
  8.   
  9.   
  10. package java.lang;  
/*

 * @(#)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;
注释结构:
  1. /*
  2. * @(#){类名称}.java        {创建时间}
  3. *
  4. * {某人或某公司具有完全的版权}
  5. * {使用者必须经过许可}
  6. */  
  7.   
  8.   
  9.   
  10. package java.lang;   
  11.   
  12.    
/*

 * @(#){类名称}.java       {创建时间}

 *

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

 * {使用者必须经过许可}

 */

package java.lang;
2. 具体类功能注释

示例如下:
Java代码
  1. /**
  2. * Class Object is the root of the class hierarchy.
  3. * Every class has Object as a superclass. All objects,
  4. * including arrays, implement the methods of this class.
  5. *
  6. * @author   unascribed
  7. * @version 1.61, 01/23/03
  8. * @see      java.lang.Class
  9. * @since    JDK1.0
  10. */  
  11.   
  12. public class Object {}   
  13.   
  14.    
/**

 * Class Object is the root of the class hierarchy.

 * Every class has Object 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 {}
注释结构:
Java代码
  1. /**
  2. * 类 {类名称}{此类功能描述}
  3. *
  4. * @author   {作者}
  5. * @version {版本,常用时间代替}
  6. * @see      java.lang.Class
  7. * @since    JDK{jdk版本}
  8. */  
  9.   
  10. public class Object {}   
  11.   
  12.    
/**

 * 类 {类名称}{此类功能描述}

 *

 * @author  {作者}

 * @version {版本,常用时间代替}

 * @see     java.lang.Class

 * @since   JDK{jdk版本}

 */

public class Object {}
3. 类变量注释

示例如下:
Java代码
  1. /** The value is used for character storage. */  
  2.   
  3. private char value[];   
  4.   
  5.    
/** The value is used for character storage. */

 private char value[];
注释结构:
Java代码
  1. /** {此值是用来存储/记录什么的}*/  
  2.   
  3. private String str ;   
/** {此值是用来存储/记录什么的}*/

 private String str ;
4. 类方法注释

示例如下:
Java代码
  1.     /**
  2.       * Returns a new string that is a substring of this string. The
  3.       * substring begins with the character at the specified index and
  4.       * extends to the end of this string.

  5.       * Examples:
  6.       *
     
  7.       * "unhappy".substring(2) returns "happy"
  8.       * "Harbison".substring(3) returns "bison"
  9.       * "emptiness".substring(9) returns "" (an empty string)
  10.       *
  11.       *
  12.       * @param       beginIndex    the beginning index, inclusive.
  13.       * @return      the specified substring.
  14.       * @exception   IndexOutOfBoundsException   if
  15.       *              beginIndex is negative or larger than the
  16.       *              length of this String object.
  17.       */  
  18.   
  19. public String substring(int beginIndex) {   
  20.   
  21. return substring(beginIndex, count);   
  22.   
  23. }   
  24.   
  25.    
/**

     * 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. 

* Examples: *


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

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

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

     * 
* * @param beginIndex the beginning index, inclusive. * @return the specified substring. * @exception IndexOutOfBoundsException if * beginIndex is negative or larger than the * length of this String object. */ public String substring(int beginIndex) { return substring(beginIndex, count); }
注释结构:
Java代码
  1.     /**
  2.       * {方法的功能/动作描述}
  3.       *
  4.       * @param       {引入参数名}    {引入参数说明}
  5.       * @return       {返回参数名}    {返回参数说明}
  6.       * @exception    {说明在某情况下,将发生什么异常}
  7.       */  
  8.   
  9. public String substring(int beginIndex) {   
  10.   
  11. return substring(beginIndex, count);   
  12.   
  13. }   
  14.   
  15.    
/**

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

     *

     * @param      {引入参数名}   {引入参数说明}

     * @return      {返回参数名}   {返回参数说明}

     * @exception   {说明在某情况下,将发生什么异常}

     */

public String substring(int beginIndex) {

return substring(beginIndex, count);

}
5.     类方法中代码块注释

示例如下:
Java代码
  1. /*
  2. * 调用持久化类,将数据保存到库
  3. *
  4. * 判断是添加,还是修改
  5. */  
  6.   
  7. boolean ifSucc = false;   
  8.   
  9. if(request.getParameter("YINGLI_ID")==null){   
  10.   
  11.         String GUID = new RandomGUID().toString();   
  12.   
  13.         stressTestDataBean.setUSER_ID(Integer.toString(userId));   
  14.   
  15.         stressTestDataBean.setSIGN_ISBN((String)vSectNum.get(0));   
  16.   
  17.         stressTestDataBean.setSHENHE_JIEGUO("0");   
  18.   
  19.         stressTestDataBean.setGUID(GUID);   
  20.   
  21.         stressTestDataBean.setCREATE_DATE("getdate()");   
  22.   
  23.         stressTestDataBean.setSTATE("A");   
  24.   
  25.                                             
  26.   
  27.         ifSucc = StressTestDataDao.addStressTestData(db,stressTestDataBean);   
  28.   
  29. }else{   
  30.   
  31.         ifSucc = StressTestDataDao.mendStressTestData(db,stressTestDataBean);   
  32.   
  33. }   
  34.   
  35.    
/*

* 调用持久化类,将数据保存到库

*

* 判断是添加,还是修改

*/

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);

}
注释结构:
Java代码
  1. /*
  2. * {功能描述}
  3. *
  4. * {具体实现动作}
  5. */  
  6.   
  7. boolean ifSucc = false;   
  8.   
  9. if(request.getParameter("YINGLI_ID")==null){   
  10.   
  11.         String GUID = new RandomGUID().toString();   
  12.   
  13.         stressTestDataBean.setUSER_ID(Integer.toString(userId));   
  14.   
  15.         stressTestDataBean.setSIGN_ISBN((String)vSectNum.get(0));   
  16.   
  17.         stressTestDataBean.setSHENHE_JIEGUO("0");   
  18.   
  19.         stressTestDataBean.setGUID(GUID);   
  20.   
  21.         stressTestDataBean.setCREATE_DATE("getdate()");   
  22.   
  23.         stressTestDataBean.setSTATE("A");   
  24.   
  25.                                             
  26.   
  27.         ifSucc = StressTestDataDao.addStressTestData(db,stressTestDataBean);   
  28.   
  29. }else{   
  30.   
  31.         ifSucc = StressTestDataDao.mendStressTestData(db,stressTestDataBean);   
  32.   
  33. }  

你可能感兴趣的:(JAVA代码注释规范)