← Back to Chapters

Generating JavaDoc

? Generating JavaDoc

? Quick Overview

JavaDoc is a documentation generator tool provided by Java. It automatically creates professional HTML documentation from specially formatted comments written in Java source code.

? Key Concepts

  • JavaDoc comments start with /** and end with */
  • Used for classes, methods, constructors, and fields
  • Generates readable API documentation
  • Uses tags like @param, @return, @author

? Syntax / Theory

JavaDoc comments are placed directly above the element they describe. These comments are then processed by the javadoc command-line tool to generate HTML files.

? Code Example

? View Code Example
/**
 * This class demonstrates JavaDoc usage
 * @author Admin
 */
public class Sample {

/**
 * Adds two numbers
 * @param a first number
 * @param b second number
 * @return sum of a and b
 */
public int add(int a, int b) {
return a + b;
}
}

? Interactive Simulator

Type in the code comments on the left to see how the HTML documentation updates in real-time on the right.

1. Write Comments
/**
*
*
*
*
*/
public double calculate() { ... }
2. Generated HTML Preview
calculate

Calculates total price

Author: John Doe
Parameters: price - item cost
Returns: total with tax

?️ Live Output / Explanation

Generated Result

Running the JavaDoc tool creates an HTML page containing:

  • Class description
  • Method summary
  • Parameter and return details

✅ Tips & Best Practices

  • Always write JavaDoc for public classes and methods
  • Use meaningful descriptions, not obvious ones
  • Keep formatting clean and consistent
  • Run JavaDoc regularly to verify documentation quality

? Try It Yourself

  1. Create a Java class with JavaDoc comments
  2. Open terminal in project folder
  3. Run: javadoc Sample.java
  4. Open generated index.html in browser