«Back to Home

Core Java

Topics

How To Create API Document | Javadoc Tool In Java

Create API Document | Javadoc Tool
 
With the help of Javadoc tool, we can create a document API in Java.
 
Javadoc tool gives a simple way to write API documentation for the source code and the software projects by Java programming language.
 
In Java, we use the documentation comment “/**…*/” to post the information for the class, method, constructor, fields etc.
 
IDEs such as Eclipse and Netbeans can automatically create HTML documentation for the classes, interfaces, fields, constructors and the implemented methods.
 
Let’s see an example, given below.
 
Code
  1. package Myclass;  
  2. /** 
  3.  * Shape class is a user-defined class that contains one method. 
  4.  */  
  5. public class Shape {  
  6.     /** 
  7.      * The cube method prints cube of the given number 
  8.      */  
  9.     public static void cube(int a) {  
  10.         System.out.println(a * a * a);  
  11.     }  
  12.     public static void main(String args[]) {  
  13.         Shape s = new Shape();  
  14.         s.cube(5);  
  15.     }  
  16. }  
24

Output

25

If we want to create the document API, we need to use the Javadoc tool, followed by Java file name and not required to compile Javafile.
 
We need to write a command on the command prompt.
 
Javadoc Shape.java

To create the document AP, lot of HTML files are created. Open the index.html file to get the information about the classes.
 
Summary

Thus, we learnt that with the help of Javadoc tool, we can create document API in Java and also learnt how to create it.