浪客剑心

/** <- 这里一定要用两个星号, 否则会被认为是普通注释的
* ........
*/
public int getCount() { .......

/**
* 一些参数列表<p>
*
* @see 类名
* @see 完整类名
* @see 完整类名#方法
*
* @param 参数名 说明
* @return 说明
* @exception 完整类名 说明
* @deprecated
*
* @version 版本信息
* @author 作者名
*/

@see : 就是文档中的 参见xx 的条目, 其实就是超链接.

1. 类注释

2. 变量注释

3. 方法注释

@param : 参数名是指参数列表内的标识符, 说明就是一些解释性质的文字, 可以多行.
@return : 返回值的说明, 可以多行
@exception : 完整类名应该明确指定一个违例类的名字，它是在其它某个地方定义好的。而说明则阐述为什么这种特殊类型的违例会在方法调用中出现。说明可以多行
@deprecated : 指出一些旧功能已由改进过的新功能取代。该标记的作用是建议用户不必再使用一种特定的功能，因为未来改版时可能摒弃这一功能。若将一个方法标记为@deprecated，则使用该方法时会收到编译器的警告。

1.?JavaDocHow to Write Doc Comments for the JavadocTM Tool, an API should describe “all aspects of the behavior of each method on which a caller can rely”. One generally uses JavaDoc to document things such as Classes, Interfaces and Methods but one can theoretically use it for anything written in Java by defining custom tags and creating custom DocLets.

JavaDoc is a tool which extracts information from a Java source file to create an API. It is specifically oriented toward this kind of documentation. To quote

JavaDoc is written within the Java source code for a particular project and then the javadoc tool is used to extract the JavaDoc-marked-up sections and create the HTML files that comprise the JavaDoc output.

2.?Installationhttp://java.sun.com/j2se/. You should be capable of following the instructions that come with this to install it; see Configuring A Windows Working Environment and Configuring A Unix Working Environment.

JavaDoc comes with the J2SE (Java 2 Platform Standard Edition), available from

The general format of a JavaDoc marked up section is:

 /** * This is the description part of the doc comment. * * Additional details * * @tag1 Tag Content * @tag2 Tag Content * . * . * . */ 

Take notice of the spacing used, the tags section must be separated from the description by a single blank line. The content of the comment starts one space in from the left hand edge of the comment. Tag lists may be separated into logical blocks by inserting a blank line. Lines should preferably be below 80 columns in width. New paragraphs can be specified by using the <p> tag.

The first sentence should summarize the overall behaviour of the Class, Interface or Method being described. It should be terminated with a full stop followed by either a space, tab or newline, it may span more than one line. To include multiple full stops in the first sentence, make sure that the ones that do not signify the end of the first sentence are not followed by a space, tab or newline. This can be achieved by using the HTML entity &nsbp;:

  /** * This is the part of the first sentence.&nsbp;This is still part of the first sentence. This is not. * */ 

One should write from the perspective of the third person:

  /** * Correct - Returns an Integer representing the mean of the numbers provided as parameters. * * It has the special feature of blah blah blah... * * Incorrect - This method returns an Integer representing the mean of the numbers you provide as parameters. * * This has the special feature of blah blah blah... */ 

Tag inclusion should accord to the following order:

*?@author???????(classes?and?interfaces?only,?required)
*?@version??????(classes?and?interfaces?only,?required)
*???????????????
*?@param????????(methods?and?constructors?only)
*?@return???????(methods?only)
*?@see??????????
*?@since????????
*?@serial???????(or?@serialField?or?@serialData)
*?@deprecated
????????

When using Java code in a description, one should use <code>blah</code>:

 * * Returns true if blah otherwise returns false * 

A description may contain any HTML tags:

 /** * This is the description part of the doc comment. *

* blah blah blah blah blah * blah blah blah blahblah *

*
*     blah  * blah    blah  *
* * @author Ashley Mills * @version 1.2 */ public class test { . . . 

 javadoc blah.java

Creates JavaDoc for the file blah.java.

 javadoc *.java

Creates JavaDoc for all java files in the current directory.

 javadoc -help

Displays the command line options (so does not providing any).

JavaDoc does not automatically link to the real online API, to achieve this one has to utilise the -link option provided by StandardDoclet. Assuming one desires to link to the Java 1.4 API, one would use:

  javadoc -link http://java.sun.com/j2se/1.4/docs/api *.java 

This causes all references to Java 1.4 classes in the generated HTML to be resolved.

Tip Use the -d option to direct generated JavaDoc to a specific directory.

@author author name

Specifies the author of the class or interface:

  * * @author Jimmy Petronas * @author Mickey Block * @author Sally Finch * 

Not included in generated HTML using standard Doclet, unless turned on by specifying -author option when running javadoc

@version version information

Adds version information to a class.

 * * @version 1.2 * 

Only one per class or interface allowed. Not included in generated HTML using standard Doclet, unless turned on by specifying the -version option when running javadoc.

@param parameter-name description

Adds a parameter to the parameter list.

 /** * Returns the product of two integers. * * @param int operand one * @param int operand two * @return an int */ public int mul(int a, int b) { return a*b; } 

@return description of return value

Describes the value returned from a method.

 * * @return A new BlahBlah Object with a field size of 100. * 

@exception class-name description

Describes the exceptions thrown by the constructor, method, class or interface. class-name is the name of the exception.

  /** * Replaces test(). * @throws BlahException unless blah blah blah * @exception BlahBlahException */ public test(int i) { } 

@see classname

 /** * Returns the product of the squares of a and b. * * @see #mul * * @param int operand one * @param int operand two * @return an int */ public int squaredMul(int a, int b) { return mul(mul(a,a),mul(b,b)); } 

The classname can be local like this example, prefixed with a hash '#' or a fully qualified class name likejava.lang.String or java.lang.String#charAt.

@since since-text

Specifies from which version of Java this class, method or interface has been available from.

 * * @since JDK1.4 * 

@deprecated deprecated-text

Marks a class, interface or method as deprecated.

 /** * @deprecated Replaced by test(int) * @see #test(int) */ public test() { } /** * Replaces test(). */ public test(int i) { } 

More detail pertaining to the available tags can be found at the JavaDoc reference page:

Here is a simple example showing a few of the features of JavaDoc:

 /** * Represents a "fuzzy" integer, in that the integer is * not exact, but is instead specified as being between a range. * * @author Ashley Mills * @version 1.0b */ public class FuzzyInteger { private int lowerVal, upperVal; /** * Creates a new FuzzyInteger object based on the * range specified. * * @param lowerVal The lowest value that the integer could be. * @param upperVal The highest value that the integer could be. */ public FuzzyInteger(int lowerVal, int upperVal) { this.lowerVal = lowerVal; this.upperVal = upperVal; } /** * Doubles the value of the FuzzyInteger. */ public void doubleFuzzy() { lowerVal = lowerVal+lowerVal; upperVal = upperVal+upperVal; } } 

2010-02-24 08:35:00

2007-09-23 10:51:00

2015-02-03 10:53:51

2014-03-01 00:44:14

2017-08-01 10:02:49

2009-04-30 14:42:00

2017-02-09 23:33:31

zblogphp文章页调用相关文章

2015-12-25 20:25:03

2013-06-28 23:02:56

wordpress 在文章内容页获取相关文章,本文章所在分类的其它文章的方法

2016-10-19 23:18:18