Site icon TestingDocs.com

Java Documentation Comments

Overview

We can use javadoc utility to generate Java Documentation. The HTML documentation for the java code or automation framework code.

Javadoc comments are used to document code. The documented code can then be turned into a set of HTML pages.

Javadoc Tags

@author

The most important is the @author tag. This tag identifies the author of the code. We can use this tag when you develop java automation code or scripts. Syntax of the tag is:
@author <name>

@param

This tag documents a parameter of a method. The syntax for the parameter is:
@param paramterName description

Generating documentation

Let’s create Java documentation for some sample java classes. Let’s use Box with three attributes width, height and length. A driver class BoxDriver that instantiates Box object and prints information on the console.

We can automatically generate documentation comments using an IDE like Eclipse.
There are several ways to generate comments for the methods and constructors.

Steps

Below steps to create comments for the constructor during the automatic creation of the constructor for a class.

 

Generating HTML

Choose Project >> Generate Javadoc… to generate HTML.
Configure Javadoc command for example:
C:\Program Files (x86)\Java\jdk1.8.0\bin\javadoc.exe
Choose the java project that you want to generate documentation.
Click on Next >
Select options and stylesheet (custom) if you want .
Click on Next >

Hit Finish button to generate HTML files for the java classes as shown below.

 

 

Box.java

package com.testingdocs.beans;

/**
 * 
 * @author testingdocs
 *
 */

public class Box {
  private double width;
  private double height;
  private double length;

  /**
   * @param width
   * @param height
   * @param length
   */
  public Box(double width, double height, double length) {
    super();
    this.width = width;
    this.height = height;
    this.length = length;
  }


  /**
   * @return the width
   */
  public double getWidth() {
    return width;
  }
  /**
   * @param width the width to set
   */
  public void setWidth(double width) {
    this.width = width;
  }
  /**
   * @return the height
   */
  public double getHeight() {
    return height;
  }
  /**
   * @param height the height to set
   */
  public void setHeight(double height) {
    this.height = height;
  }
  /**
   * @return the length
   */
  public double getLength() {
    return length;
  }
  /**
   * @param length the length to set
   */
  public void setLength(double length) {
    this.length = length;
  }


  /* (non-Javadoc)
   * @see java.lang.Object#toString()
   */
  @Override
  public String toString() {
    return "Box [width=" + width + ", height=" + height + ", 
length=" + length + "]";
  }	

}

 

BoxDriver.java

package com.testingdocs.driver;

import com.testingdocs.beans.Box;

public class BoxDriver {

  public static void main(String[] args) {
    Box b= new Box(2.0,7.0,9.0);
    b.toString();
  }

}

Java Tutorials

Java Tutorial on this website:

https://www.testingdocs.com/java-tutorial/

For more information on Java, visit the official website :

https://www.oracle.com/java/

 

Exit mobile version