Learn Java
import com.learnjava.packagesstandardlibrary.Javadoc;

Javadoc & Documentation Comments

@Concept

A Javadoc comment, delimited by /** and */ and placed directly above a class, method, or field, documents that piece of code in a structured format the javadoc command-line tool can extract and turn into browsable HTML documentation — precisely the same kind of official reference documentation the JDK's own classes ship with. Inside a Javadoc comment, special tags add structured detail: @param describes one method parameter, @return describes what a method gives back, @throws documents an exception the method might throw and under what condition, and @author or @since record authorship or version history.

Beyond the generated HTML, a well-written Javadoc comment is also what most IDEs display directly in a tooltip the moment a developer hovers over a method call, making good Javadoc comments genuinely useful even for a team that never runs the javadoc tool to generate a formal HTML site at all.

@HowItWorks
1

The comment syntax

/** ... */ placed directly above a class, method, or field marks it as a Javadoc comment.

2

The javadoc tool

Extracts these comments and generates browsable HTML reference documentation from them.

3

@param

Documents what one specific method parameter represents.

4

@return

Documents what a method's return value represents.

5

@throws

Documents a specific exception the method might throw, and under what condition it does.

@Example
public class JavadocDemo {
/**
* Calculates the square of a given number.
*
* @param n the number to square
* @return the square of n
*/
static int square(int n) {
return n * n;
}
 
public static void main(String[] args) {
System.out.println("Square: " + square(6));
}
}
Output
Square: 36
1The Javadoc comment sits directly above square, describing its purpose, its parameter, and its return value in a structured format.
2@param n the number to square documents specifically what the n parameter represents.
3@return the square of n documents what the method's return value represents.
4The single println call runs square(6) and prints its result, 36, with no connection to the documentation itself affecting runtime behavior at all.
@UseCases
Generating official, browsable API reference documentation for a library's public classes and methods
Seeing a method's documented purpose, parameters, and return value directly in an IDE tooltip while calling it
Documenting a specific exception a method might throw and exactly when it does, with @throws
Writing clear documentation for a public API that other developers, not just the original author, will rely on

Recommended resourcesAffiliate links · may earn us a commission

Recommended for learners

Structured coding coursesVideo courses that pair well with visual practice — pick one language and go deep.Browse courses Pro code editor & AI assistantWrite, debug and explain code faster while you practice the patterns here.Try it free Classic DSA interview booksThe reference books interviewers themselves learned from — great next to the visualizers.See the books

Practice what you learned

Re-implement each visualized algorithm in Java yourself — building beats watching.