×

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

TagDescription
@authorDescribes an author
@param       offer information about the method's parameters or the input it requires
@seecreate a link to another document element
@version     the version of the class, interface, or enumeration
@returnThe 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.
@deprecatedIncluding a remark that says this API is no longer recommended
@exceptionAdds 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.
@serialFor a default serializable field, see the doc comment.
@serialData The data written by the writeObject() or writeExternal() methods are documented.
@serialFieldThis class describes an ObjectStreamField component.
@sinceAdds a "Since" header to the produced documentation with the provided since-text.
@throwsThe 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.


Related Topics

Java Characters

Normally, when we work with characters, we use primitive data types char. When we have to work with the objects of char, we use Character class. Character class has many important...

2 minutes read.

Java Socket Programming

Java Socket Programming Socket programming is used for the communication between the applications, i.e., client and server running on different JRE may be connection-oriented or connectionless. The client program can be designed using the...

8 minutes read.

Java Substring

What is a substring in Java? Here by the name  " substring " itself, we can easily come to know it is a part of a string or a subset of...

4 minutes read.

How to Convert String to Object in Java

How to Convert String to Object in Java The Object is the super class of all classes. So you can assign a string to Object directly. There are two methods to...

3 minutes read.

Synchronized Keyword in Java

Synchronization is the process of limiting access to a shared resource or data to a single thread at a given moment in time. This aids in shielding the data from...

6 minutes read.

Java Code Optimization

We encounter the idea of optimization while working on any Java application. It is essential that the code we write is not only clear and error-free but also optimized, meaning...

9 minutes read.

Java Map Example

In Java, the Map is an interface that is used mainly to denote key and value pairs. The central concept and theme of this mapping in the java collection framework...

4 minutes read.

Java FileNotFoundException

FileNotFoundException is another exception class accessible in the java.io bundle. The exemption happens when we attempt to get to that document which isn't accessible in the framework. It is a checked...

5 minutes read.

How to create array of objects in Java

Java is an object-oriented programming language therefore everything in Java is based on objects and classes. Array is a data structure that holds data of similar type and dynamically creates...

4 minutes read.

Java String compareTo() Method

compareTo() method is used to compare the two specified Strings based on the alphabetical order(lexicographical order) of their characters.It returns positive number ,negative number or 0 Syntax: public int compareTo(String anotherString) Parameters: anotherString: the...

2 minutes read.

Java Swing

Java Swing is the extension of Abstract Windows Toolkit (AWT). Any component designed in Swing will appear the same on any platform. Problems/Disadvantage of Abstract Windows Toolkit (AWT): As we know that...

27 minutes read.

GCD Program in Java

GCD Program in Java The GCD program in Java outputs the GCD of the given numbers. In mathematics, Greatest Common Divisor (GCD), Greatest Common Factor or Highest Common Factor (HCF) of...

14 minutes read.

Generic queue in Java

Before understanding how to implement a generic queue in java, one must know about generics and queue in java. Generics in Java Generics are parameterized types. The goal is to enable type...

6 minutes read.

Java Architecture

Java architecture is a combination of three parts they are JVM, JRE and JDK. These components will help in the functioning of the java programs. The process of code interpretation...

6 minutes read.

Collection Interfaces in Java with Examples

In this tutorial, we will discuss collection interfaces in Java with Examples. Introduction The Collection Interface is an individual from the Java Collections Framework. It is a root point of interaction of...

4 minutes read.

String Coding Interview Questions in Java

What is String in Java?In Java, a String is a Class that is defined in the java.lang package. It isn't a basic data type like int or long. Character Strings...

5 minutes read.

Traverse through HashMap in Java

In this tutorial, we will discuss traversing through HashMap in Java Introduction: HashMap<Key, Value> is a part of the java collection implemented from the java 1.2 version. HashMap is written as HashMap<K,...

4 minutes read.

Java Boolean compareTo() method

The compareTo() method of Java Boolean class compares the Boolean argument with the Boolean instance and returns integer value, zero, or negative 1, or positive 1 based on the result...

2 minutes read.

Two Decimal Places Java

When a double data type is used in Java before a variable, this indicates 15 digits after decimal point. However, there are situations when we only require 2 decimal places...

4 minutes read.

How to Round Double Float up to Two Decimal Places in Java

It indicates 15 digits just after the decimal place in Java whenever a double data type is used in front of a variable. For example, when representing rupees and other...

4 minutes read.