
javadoc Command in Linux
javadoc is a command-line utility in Linux that is used to generate documents for Java programming language in standard HTML format. This command generates API documentation that helps developers to understand code structure and usage. It extracts comments from Java source code and creates an organized set of HTML files that describes the classes, methods, constructors, and fields.
Table of Contents
Here is a comprehensive guide to the options available with the javadoc command −
- Understanding the javadoc Command
- What are javadoc Comments?
- Syntax of javadoc Command
- Options javadoc Command
- How to Generate JavaDoc in Eclipse IDE?
- How to Use javadoc Command in Linux?
Understanding the javadoc Command
JavaDoc stands for Java Documentation. It is a command-line tool in Linux that generates API documentation for Java source code in HTML format. Before using this tool, you need to add JavaDoc comments formatted as /** ... */ in your Java code. These comments should illustrate classes, methods, constructors, and fields.
Clear and helpful comments create easy-to-understand documentation for your Java files. As a result, the generated API document will be simpler for other developers to understand, use, and maintain.
What are javadoc Comments?
JavaDoc comments are different from regular comments. They have an extra asterisk at the beginning. Moreover, the javadoc comments can also include HTML tags. Writing comments doesnt affect the performance of a Java program because they are removed during compilation.
Lets see how you can add single line, multiple line, and javadoc comments −
// Single-Line Comment. /* Multiple-Line comment */. /** JavaDoc comment */.
JavaDoc comments start with /** and end with */. They allow you to provide detailed descriptions of classes, methods, and other elements in your code.
Syntax of javadoc Command
We dont need to compile the Java file to generate API documentation. Instead, we can use the javadoc command to generate a Java documentation API. Specify the javadoc command followed by the file or package name, as shown below: −
javadoc fileName | javadoc packageName
Options javadoc Command
You can use several tags in JavaDoc comments to explain how to document various elements in your code −
Tag | Parameter | Description |
---|---|---|
@author | author_name | It specifies the name of the author/person or organization that wrote the code. |
@param | description | It describes a method parameter, including its purpose and expected input. |
@see | reference | It links to another related element in the documentation for additional context. |
@version | version-name | It indicates the version of the class, interface, or enum. It helps us track changes. |
@return | description | It provides information about the value that a method returns. |
@throws | exception_name | It indicates the potential exceptions that a method can throw. |
@deprecated | description | It marks a method or class as deprecated. |
@since | version | It indicates the version since a feature has been available. |
To learn more about this command, type man followed by javadoc, as follows −
man javadoc
This command returns a comprehensive manual, which includes all the necessary information regarding the javadoc command −

How to Generate JavaDoc in Eclipse IDE?
Many Integrated Development Environments (IDEs) like NetBeans, IntelliJ IDEA, and Eclipse have built-in features that automatically generate JavaDoc files. These IDEs can extract comments from your Java code and create HTML documentation based on the JavaDoc comments youve written. This makes it easier to document your projects.
For example, you can generate a JavaDoc in Eclipse by going through the following steps −
Step 1: Open the Wizard
Click on "Generate JavaDoc" from the Project menu.
Step 2: Specify File Location
Choose the directory where you want to save the JavaDoc file, usually in your home directory or another folder you like.
Step 3: Select Project and Packages
Pick the specific project and packages for which you want to create JavaDoc.
Step 4: Select Classes
On the right, select the classes you want to document; all classes are selected by default.
Step 5: Set Visibility
Decide which classes' JavaDoc will be generated based on their visibility (like public or protected).
Step 6: Destination Location
Select where you want to save the generated JavaDoc.
Step 7: Finalize Process
Click "Next" or "Finish" to finalize the process. If you choose "Next", you can change the document title and other settings before finishing.
How to Use javadoc Command in Linux?
Lets learn how to use the javadoc command in Linux to generate API documentation for your Java projects −
package demo; import java.util.Scanner; /** * * @author Ravi */ public class AdditionProgram { /** * This program adds two integers in Java. * @param args Command line arguments */ public static void main(String[] args) { /** * This is the main method * that is crucial for * executing a Java program. */ int firstNumber, secondNumber; Scanner inputScanner = new Scanner(System.in); /** * Declared two variables firstNumber and secondNumber. * Taking input from the user * using the Scanner class. */ firstNumber = inputScanner.nextInt(); secondNumber = inputScanner.nextInt(); /** * Storing the result in the variable total * which is of integer type. */ int total = firstNumber + secondNumber; /** * Using the standard output stream * to display the result. */ System.out.println("The total is: " + total); } }
Now run the javadoc command to generate a document for the above code −
javadoc demo
As a result, it generates HTML documentation based on the JavaDoc comments in the code.
Conclusion
JavaDoc is a command-line tool in Linux that generates API documentation for Java code in HTML format. It enhances code understanding for developers. It extracts specially formatted comments from the source code and creates a structured set of HTML files that describes classes, methods, and fields.
In this tutorial, we covered the JavaDoc command, how to write JavaDoc comments, and the syntax and tags used in documentation. Additionally, we explored how to generate JavaDoc in the Eclipse IDE and demonstrated using the command in Linux.