Writing Documentation for a Java Project: From A to Z

Online Python Trainer for Beginners

Learn Python easily without overwhelming theory. Solve practical tasks with automatic checking, get hints in Russian, and write code directly in your browser — no installation required.

Start Course

Introduction: Why Documentation is the Key to a Successful Java Project

High-quality documentation is not just a formality, but an investment in the future of your project. For a Java developer, the ability to write clear and structured documentation is as important as knowing the language syntax. Without it, even the most elegant code becomes a "black box" for other developers, and project support turns into a nightmare. In this article, we will break down the complete cycle of creating documentation for a Java project — from code comments to publishing a finished site.

We will look at three main levels of documentation: technical comments in the code (Javadoc), architecture and API descriptions (Markdown/AsciiDoc), and user guides. You will learn how to make documentation useful and readable using built-in Java tools and modern formats.



Level 1: Documenting Code with Javadoc

Javadoc is a standard Java tool for generating documentation from special comments. It analyzes your source code and creates HTML pages describing classes, methods, and fields. Proper use of Javadoc is the foundation of technical documentation for any Java project.



Basic Javadoc Tags

To document the public API (public and protected methods/classes), use the following tags:

  • @param — description of a method parameter.
  • @return — description of the return value.
  • @throws or @exception — description of exceptions a method may throw.
  • @see — a link to another class or method.
  • @since — the version in which the element was introduced.
  • @deprecated — a mark for a deprecated element with an indication of an alternative.


Example: Documenting a Class and Method

Consider an example of a properly documented Calculator class:

/** * A simple calculator for performing basic arithmetic operations. * * <p>This class provides methods for addition, subtraction, * multiplication, and division of two numbers. All methods work with the {@code double} type.</p> * * @author Ivan Petrov * @version 1.0 * @since 2023-10-01 */public class Calculator {

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

/** * Divides one number by another. * * @param dividend the dividend * @param divisor the divisor * @return the result of the division * @throws ArithmeticException if divisor is zero */ public double divide(double dividend, double divisor) { if (divisor == 0) { throw new ArithmeticException("Division by zero is not allowed"); } return dividend / divisor; }}

After running the command javadoc -d doc src/Calculator.java, you will get HTML documentation where each tag is converted into a readable format.



Javadoc Style Tips

  • Write comments in Russian if the project team speaks it. For Open Source projects, use English.
  • Don't duplicate the obvious. Instead of @return the name, it's better to write @return the user's full name, including the last name.
  • Use HTML tags inside the description (e.g., <code>, <ul>) for formatting.


Level 2: Architectural and API Documentation (Markdown / AsciiDoc)

Javadoc is great for describing individual classes, but for describing project architecture, module interactions, and general operating principles, more flexible tools are needed. This is where Markdown and AsciiDoc come to the rescue.



Markdown for README and Wiki

File

Blogs

Book Recommendations