← Back to Chapters

Javadoc Comments

? Javadoc Comments

? Quick Overview

Javadoc comments are special multi-line comments in Java used to generate professional HTML documentation for classes, methods, constructors, and fields. They are widely used in enterprise and Advance Java projects.

? Key Concepts

  • Written using /** ... */ syntax
  • Processed by the javadoc tool
  • Supports tags like @param, @return, @author
  • Helps in API-level documentation

? Syntax / Theory

Javadoc comments must be placed immediately before the class, method, constructor, or variable declaration. Each tag has a specific purpose.

? View Code Example
/** This class demonstrates basic Javadoc usage */
public class Calculator {

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

? Live Output / Explanation

Generated Documentation

Running the javadoc command generates HTML pages showing:

  • Class description
  • Method purpose
  • Parameter and return details

? Tips & Best Practices

  • Always use Javadoc for public classes and methods
  • Write clear and concise descriptions
  • Use proper tags instead of plain text
  • Keep documentation updated with code changes

?‍? Try It Yourself

  1. Create a Java class with Javadoc comments
  2. Add tags like @param and @return
  3. Run javadoc ClassName.java
  4. Open the generated HTML file in a browser