JavaDoc tool is a document generator tool in Java programming language for generating standard documentation in HTML format. It generates API documentation. It parses the declarations ad documentation in a set of source file describing classes, methods, constructors, and fields.
Before using JavaDoc tool, you must include JavaDoc comments /**………………..*/ providing information about classes, methods, and constructors, etc. For creating a good and understandable document API for any java file you must write better comments for every class, method, constructor.
The JavaDoc comments is different from the normal comments because of the extra asterisk at the beginning of the comment. It may contain the HTML tags as well.
// Single-Line Comment /* * Multiple-Line comment */ /** * JavaDoc comment */
By writing a number of comments, it does not affect the performance of the Java program as all the comments are removed at compile time.
JavaDoc Format: –
It has two parts: – a description which is followed by block tags.
Some Integrated Development Environments (IDE) automatically generate the JavaDoc file like NetBeans, IntelliJ IDEA, Eclipse, etc.
Generation of JavaDoc: –
To create a JavaDoc you do not need to compile the java file. To create the Java documentation API, you need to write Javadoc followed by file name.
javadoc file_name or javadoc package_name
After successful execution of the above command, a number of HTML files will be created, open the file named index to see all the information about classes.
JavaDoc Tags
Tag | Parameter | Description |
---|---|---|
@author | author_name | Describes an author |
@param | description | provide information about method parameter or the input it takes |
@see | reference | generate a link to other element of the document |
@version | version-name | provide version of the class, interface or enum. |
@return | description | provide the return value |
To generate JavaDoc in Eclipse: –
- Select “Generate JavaDoc” option from Project menu and a wizard will appear.
- Specify the location for the JavaDoc file on your computer, by default it will be in the C drive.
- Select the project and then the packages for which you want to create the JavaDoc file.
- After this on the right side, select the classes for which you want to generate the JavaDoc, by default all the classes will be selected.
- Then you can also specify for which classes the JavaDoc will be generated by selecting the visibility.
- Select the destination location where the generated JavaDoc will be placed.
- Then click Next or Finish.
If you select Next in the next window you can select the Document title and other basic options.
Example 1: –
Java
package exa; import java.util.Scanner; /** * * @author Yash */ public class Example { /** * This is a program for adding two numbers in java. * @param args */ public static void main(String[] args) { /** * This is the main method * which is very important for * execution for a java program. */ int x, y; Scanner sc = new Scanner(System.in); /** * Declared two variables x and y. * And taking input from the user * by using Scanner class. * */ x = sc.nextInt(); y = sc.nextInt(); /** * Storing the result in variable sum * which is of the integer type. */ int sum = x + y; /** * Using standard output stream * for giving the output. * @return null */ System.out.println( "Sum is: " + sum); } } |
Generating document for the above class
javadoc exa
Screenshot of javadoc: –