Java javadoc

From wikinotes

Documentation

official docs https://docs.oracle.com/javase/1.5.0/docs/guide/javadoc/index.html
documentation-comment syntax https://docs.oracle.com/javase/1.5.0/docs/tooldocs/solaris/javadoc.html#documentationcomments
how to write documentation-comments https://www.oracle.com/technetwork/java/javase/documentation/index-137868.html

Usage

Commandline

document target sourcefiles


   # by sourcefile (wildcard allowed)
   javadoc \
      src/javadoc_intro/*.java  `# paths of sourcefile(s) ` \
      -d html_output/

document target packages


   javadoc \
      javadoc_intro              `# name of package(s)` \
      -sourcepath  src/          `# path containing java packages ` \
      -d           html_output/  `# output html dir`

Build System Integration

java maven plugin: javadoc

Syntax

Components

Doc Comments

/**
* A javadoc comment documenting `MyClass`
*/
class MyClass {}

Tags


/**
* @author   Will Pittman
* @version  1.1.1
* @since    1.1.0
*/
class WebsiteLoader
{
    /** name of the current platform
    */
    String platform;

    /** Loads a Website
    * 
    * @param    url     description...        (parameter docs)
    * @return   description...                (return value of method)
    * @see      Image                         (can link to other class pages)
    * @throws   RuntimeException              (also @exception)
    */
    Image get_image(String url){...}
}

references


{@link package.class#member label}

see tag


The see tag has a special format for linking to descriptions of other methods.

@see #field
@see #Constructor(Type, Type...)
@see #Constructor(Type id, Type id...)
@see #method(Type, Type,...)
@see #method(Type id, Type, id...)
@see Class
@see Class#field
@see Class#Constructor(Type, Type...)
@see Class#Constructor(Type id, Type id)
@see Class#method(Type, Type,...)
@see Class#method(Type id, Type id,...)
@see package.Class
@see package.Class#field
@see package.Class#Constructor(Type, Type...)
@see package.Class#Constructor(Type id, Type id)
@see package.Class#method(Type, Type,...)
@see package.Class#method(Type id, Type, id)
@see package


Block/Inline Tag-Formatting


JavaDoc comments use tags to communicate special information. These are rendered in special ways (ex: param, returns, ...). You can present these tags in two styles:

  • block tag @param
  • inline-tag (no newline) {@link #setBounds(int, int, int, int)}

Formatting

HTML

/**
* A javadoc comment documenting <i>MyClass</i>
*/
class MyClass {}

HTML can be used in documentation-tags.

Leading Spaces

omitting * characters will preserve newlines/spacing.

/**
* A javadoc comment.
*

public void foo()
{
    //...
}

* return to normal
* comment behaviour.
*/