01 / 20
/** */

Writing
Javadoc

Learn to write professional documentation for your Java methods using Javadoc comments: the standard that powers every Java library you use.

Java

What is Javadoc?

Javadoc is Java's built-in documentation system. It lets you embed structured descriptions directly above your classes, methods, and fields using special comment blocks. The Java compiler can then generate HTML reference pages automatically from these comments.

Anatomy of a Javadoc Comment

1 2 3 4 5 6 7 8 /** * Calculates the area of a circle. * * @param radius the radius of the circle * @return the area as a double */ public double getArea ( double radius ) { Opening tag Description @param tag @return tag Closing tag

Why Write Javadoc?

IDE Tooltips
Your IDE reads Javadoc and shows helpful pop-ups when hovering over methods.
Team Communication
Other developers understand your code's purpose without reading every line.
Auto-Generated Docs
The javadoc tool creates professional HTML documentation sites automatically.

The Three Essential Tags

1
Description: the first sentence summarizes what the method does. Additional sentences add detail.
2
@param: one tag per parameter, naming it and explaining what value it expects.
3
@return: describes the value the method sends back. Omit this only for void methods.

The Javadoc Structure

Method your code Description "What does it do?" @param "What goes in?" @return "What comes out?" @throws "What can go wrong?"

Javadoc vs Regular Comments

Javadoc Comment Regular Comment
Syntax /** ... */ // or /* ... */
Audience Users of your code Developers reading source
Parsed by tools ✓ Yes ✕ No
Supports tags ✓ @param, @return ✕ No
IDE integration ✓ Tooltips ✕ Ignored
Placement Before class/method Anywhere

How to Write Javadoc: Step by Step

1
Place your cursor on the line directly above the method signature.
2
Type /** and press Enter. Most IDEs auto-generate the skeleton with @param and @return stubs.
3
Write a clear first sentence describing the method's purpose. Start with a verb (e.g., "Calculates", "Returns", "Converts").
4
Fill in each @param with a lowercase description of what the parameter represents.
5
Fill in @return with what the method gives back. Skip this for void methods.

Example 1: Simple Method

Java
/** * Converts a temperature from Fahrenheit to Celsius. * * @param fahrenheit the temperature in Fahrenheit * @return the equivalent temperature in Celsius */ public double toCelsius(double fahrenheit) { return (fahrenheit - 32) * 5.0 / 9.0; }

Example 2: Multiple Parameters

Java
/** * Calculates the total price after applying a discount. * * @param price the original price of the item * @param discount the discount percentage (0 to 100) * @return the final price after the discount */ public double applyDiscount(double price, double discount) { return price * (1 - discount / 100); }

Example 3: Void Method

Java
/** * Prints a greeting message to the console. * * @param name the name of the person to greet */ public void greet(String name) { System.out.println("Hello, " + name + "!"); }

Good vs Bad Descriptions

✕ Bad ✓ Good
Description "This method does stuff" "Calculates the area of a rectangle"
@param "@param x the x" "@param width the width in pixels"
@return "@return the result" "@return the area as a double"
First word "This method calculates..." "Calculates..."
Specificity "Takes a number" "the radius in centimeters"

Common Javadoc Tags

@param
Describes a method parameter. One per parameter, in order.
@return
Describes the return value. Omit for void methods.
@throws
Documents exceptions the method may throw and when.
@see
Links to a related class or method for cross-referencing.

Common Mistakes

✕ Wrong Delimiter
Using /* instead of /**. That single missing asterisk makes it a regular comment, invisible to Javadoc tools.
✕ Missing @param
Forgetting to document a parameter. Every parameter in the signature needs its own @param tag.
✕ Vague Description
Writing "does the thing" instead of clearly stating what the method computes, modifies, or returns.
✕ @return on Void
Adding @return to a void method. There is nothing to return, so the tag is incorrect and confusing.

Javadoc Checklist

✓
Comment starts with /** (two asterisks), not /*
✓
First sentence is a clear, complete summary starting with a verb
✓
Every parameter has its own @param tag with a meaningful description
✓
Non-void methods have a @return tag describing the return value
✓
Comment is placed directly above the method signature (no blank line between)

Question 1 of 5

Which opening delimiter marks a comment as a Javadoc comment (as opposed to a regular block comment)?

Question 2 of 5

How many @param tags should the Javadoc for this method contain?

Question 3 of 5

When should you omit the @return tag from a Javadoc comment?

Question 4 of 5

Which of the following is the best first sentence for a Javadoc description?

Question 5 of 5

What is wrong with this Javadoc comment?