Creating API Document Javadoc tool
The JavaDoc utility is a document generator tool written in Java that generates standard documentation in HTML format. It parses declarations and documentation in a source file collection that describes classes, methods, constructors, and fields. It produces API documentation.
Before utilizing the JavaDoc tool, you must include JavaDoc comments /**....................*/ that provide information on classes, methods, and constructors, among other things. It would be best if you made better comments for each class, method, and function Object() to create a nice and understandable document API for any java application.
The added asterisk at the beginning of the JavaDoc comment distinguishes it from other comments. It may also include HTML tags.
// Single-Line Comment
/*
* Multiple-Line comment
*/
/**
* JavaDoc comment
*/
Since all comments are removed at build time, writing a lot of them has no impact on how well a Java programme runs.
JavaDoc Format:
It is divided into two sections: block tags are followed by a description.
NetBeans, IntelliJ IDEA, Eclipse, and other Integrated Development Environments (IDE) produce the JavaDoc file automatically.
Generation of JavaDoc:
You are not required to build the java file to produce a JavaDoc. To build the Java documentation API, type Javadoc followed by the file name.
javadoc file_name or javadoc package_name
Following the successful execution of the above command, several HTML files will be produced; open the index file to view all class information.
JavaDoc Tags
Tag | Description |
@author | Describes an author |
@param | offer information about the method's parameters or the input it requires |
@see | create a link to another document element |
@version | the version of the class, interface, or enumeration |
@return | The return value is provided |
{@code} | Text is shown in code font without being interpreted as HTML markup or nested Javadoc elements. |
{@docRoot} | Describes the relative path from any created page to the root directory of the generated document. |
@deprecated | Including a remark that says this API is no longer recommended |
@exception | Adds a Throws subsection with the classname and descriptive text to the produced documentation. |
{@inheritDoc} | The closest inheritable class or implementable interface is used as the source of a comment. |
{@link} | Inserts a visible text labeled in-line link to the documentation for the provided package, class, or member name of a linked class. |
{@linkplain} | Identical to @link, but the link's label is shown in ordinary text rather than code font. |
@serial | For a default serializable field, see the doc comment. |
@serialData | The data written by the writeObject() or writeExternal() methods are documented. |
@serialField | This class describes an ObjectStreamField component. |
@since | Adds a "Since" header to the produced documentation with the provided since-text. |
@throws | The tags @throws and @exception are equivalent. |
{@value} | A static field's value is displayed when the @value element is used in the doc comment. |
JavaDoc generation in Eclipse requires:
- A wizard will display when you choose "Generate JavaDoc" from the Project menu.
- Please choose the location on your computer for the JavaDoc file; it will default to be on the C drive.
- Choose the project, followed by the packages for which you wish to build the JavaDoc file.
- After that, on the right side, pick the classes for which you want the JavaDoc to be generated; by default, all classes will be chosen.
- Then, by selecting the visibility, you can determine which classes will have JavaDoc created.
- Choose the location where the created JavaDoc will be saved.
- Then press the Next or Finish button.
- In the following box, click Next to pick the Document title and other basic parameters.
We may use the Javadoc tool to develop document APIs in Java. To provide information about the class, method, function Object(), fields, and so on, we must use the documentation comment /**... */ in the java file.
Let's look at a simple class that includes a documentation comment.
package com.abc;
/** This is a user-defined class with one method called a cube. M{
/** The cube function returns the square root of the provided value. */
public static void cube(int n){System.out.println(n*n*n);}
}
To build the document API, use the Javadoc tool followed by the name of the java file. There is no need to compile the java file.
You must enter the following command at the command prompt:
Javadoc M.java
To create the document API, multiple HTML files will now be generated. To obtain information about the classes, view the index.html file.