java代码注释风格

整个类文件注释

示例如下:
Java代码 
  1. /* 
  2.  
  3.  * @(#)Object.java     1.61 03/01/23 
  4.  
  5.  * 
  6.  
  7.  * Copyright 2003 Sun Microsystems, Inc. All rights reserved. 
  8.  
  9.  * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms. 
  10.  
  11.  */  
  12.   
  13.    
  14.   
  15. 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;



注释结构:
Java代码 
  1. /* 
  2.  
  3.  * @(#){类名称}.java       {创建时间} 
  4.  
  5.  * 
  6.  
  7.  * {某人或某公司具有完全的版权} 
  8.  
  9.  * {使用者必须经过许可} 
  10.  
  11.  */  
  12.   
  13.    
  14.   
  15. package java.lang;  
  16.   
  17.    
/*
* @(#){类名称}.java       {创建时间}
*
* {某人或某公司具有完全的版权}
* {使用者必须经过许可}
*/
package java.lang;




2. 具体类功能注释

示例如下:
Java代码 
  1. /** 
  2.  
  3.  * Class <code>Object</code> is the root of the class hierarchy. 
  4.  
  5.  * Every class has <code>Object</code> as a superclass. All objects, 
  6.  
  7.  * including arrays, implement the methods of this class. 
  8.  
  9.  * 
  10.  
  11.  * @author  unascribed 
  12.  
  13.  * @version 1.61, 01/23/03 
  14.  
  15.  * @see     java.lang.Class 
  16.  
  17.  * @since   JDK1.0 
  18.  
  19.  */  
  20.   
  21. public class Object {}  
  22.   
  23.    
/**
* 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 {}


注释结构:
Java代码 
  1. /** 
  2.  
  3.  * 类 <code>{类名称}</code>{此类功能描述} 
  4.  
  5.  * 
  6.  
  7.  * @author  {作者} 
  8.  
  9.  * @version {版本,常用时间代替} 
  10.  
  11.  * @see     java.lang.Class 
  12.  
  13.  * @since   JDK{jdk版本} 
  14.  
  15.  */  
  16.   
  17. public class Object {}  
  18.   
  19.    
/**
* 类 <code>{类名称}</code>{此类功能描述}
*
* @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.  
  3.      * Returns a new string that is a substring of this string. The 
  4.  
  5.      * substring begins with the character at the specified index and 
  6.  
  7.      * extends to the end of this string. <p> 
  8.  
  9.      * Examples: 
  10.  
  11.      * <blockquote><pre> 
  12.  
  13.      * "unhappy".substring(2) returns "happy" 
  14.  
  15.      * "Harbison".substring(3) returns "bison" 
  16.  
  17.      * "emptiness".substring(9) returns "" (an empty string) 
  18.  
  19.      * </pre></blockquote> 
  20.  
  21.      * 
  22.  
  23.      * @param      beginIndex   the beginning index, inclusive. 
  24.  
  25.      * @return     the specified substring. 
  26.  
  27.      * @exception  IndexOutOfBoundsException  if 
  28.  
  29.      *             <code>beginIndex</code> is negative or larger than the 
  30.  
  31.      *             length of this <code>String</code> object. 
  32.  
  33.      */  
  34.   
  35. public String substring(int beginIndex) {  
  36.   
  37. return substring(beginIndex, count);  
  38.   
  39. }  
  40.   
  41.    
    /**
* 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);
}


注释结构:
Java代码 
  1.     /** 
  2.  
  3.      * {方法的功能/动作描述} 
  4.  
  5.      * 
  6.  
  7.      * @param      {引入参数名}   {引入参数说明} 
  8.  
  9.      * @return      {返回参数名}   {返回参数说明} 
  10.  
  11.      * @exception   {说明在某情况下,将发生什么异常} 
  12.  
  13.      */  
  14.   
  15. public String substring(int beginIndex) {  
  16.   
  17. return substring(beginIndex, count);  
  18.   
  19. }  
  20.   
  21.    
    /**
* {方法的功能/动作描述}
*
* @param      {引入参数名}   {引入参数说明}
* @return      {返回参数名}   {返回参数说明}
* @exception   {说明在某情况下,将发生什么异常}
*/
public String substring(int beginIndex) {
return substring(beginIndex, count);
}




5. 类方法中代码块注释

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

你可能感兴趣的:(java代码注释风格)