Java – How to document your code ?
Problem Statement
You need to document your java classes so that it helps in maintenance.
Solution
Use Javadoc and place comments before any method , field or class to document.
Just enter /** to start writing the comments using javadoc. The subsequent lines needs to begin with * and end the comment section with */
Below is a sample code demonstrating the usage of the javadoc for the comments.
Java
x
34
34
1
package abundantcode;
2
3
import java.io.BufferedReader;
4
import java.io.InputStreamReader;
5
6
/**
7
*
8
* @author Abundantcode
9
*
10
*/
11
public class abundantcodeconsole {
12
/**
13
* The main method that accepts input from the console and displays it
14
* @param args
15
*/
16
public static void main(String[] args) {
17
18
BufferedReader input = new BufferedReader(new InputStreamReader(System.in));
19
System.out.println("Enter data");
20
try {
21
String data = input.readLine();
22
System.out.println(data);
23
}
24
catch(Exception ex)
25
{
26
System.out.println(ex.getMessage());
27
}
28
29
Boolean b1 = Boolean.valueOf("false");
30
System.out.println(b1);
31
32
}
33
34
}
The specific format defined above lets the developers to generate HTML documentation for the classes using the command-line tool called Javadoc. This tool parses the java source file and generates HTML documentation.
Eg :
javadoc abundantcodeconsole.java
You can also pass the complete package to the Javadoc tool instead of the single java file.
javadoc abundantcode
Leave Your Comment