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.
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: –
Generating document for the above class
Screenshot of javadoc: –
Attention reader! Don’t stop learning now. Get hold of all the important Java Foundation and Collections concepts with the Fundamentals of Java and Java Collections Course at a student-friendly price and become industry ready. To complete your preparation from learning a language to DS Algo and many more, please refer Complete Interview Preparation Course.