Java Tools Tutorials - Herong's Tutorial Examples - v6.24, by Herong Yang
Hello.java API Document
This section provides a tutorial example of how to generated a Java API document for the Hello.java class with 'javadoc' command.
To get started learning the "javadoc" command, let's try it on the Hello.java program.
herong> more Hello.java class Hello { public static void main(String[] a) { System.out.println("Hello world!"); } } herong> javadoc Hello.java Loading source file Hello.java... Constructing Javadoc information... error: No public or protected classes found to document. 1 error
Looks like "javadoc" only documents "protected" and "protected" classes by default. To make it work for the Hello class, we just need to specify the "-private" option.
herong$ javadoc -private Hello.java Loading source file Hello.java... Constructing Javadoc information... Building index for all the packages and classes... Standard Doclet version 17.0.1+12-LTS-39 Building tree for all the packages and classes... Generating .\Hello.html... Hello.java:1: warning: no comment class Hello { ^ Hello.java:2: warning: no comment public static void main(String[] a) { ^ Generating .\package-summary.html... Generating .\package-tree.html... Generating .\overview-tree.html... Building index for all classes... Generating .\allclasses-index.html... Generating .\allpackages-index.html... Generating .\index-all.html... Generating .\index.html... Generating .\help-doc.html... 2 warnings
Not too bad. I only got 2 warnings: "no comment" on the "Hello" class and "no comment" on the "main()" method.
Now, let's what files are generated by "javadoc":
herong$ ls -l -rw-r--r-- 7784 Hello.html -rw-r--r-- 107 Hello.java -rw-r--r-- 3395 allclasses-index.html -rw-r--r-- 3366 allpackages-index.html -rw-r--r-- 3043 constant-values.html -rw-r--r-- 2958 deprecated-list.html -rw-r--r-- 16 element-list -rw-r--r-- 7878 help-doc.html -rw-r--r-- 3989 index-all.html -rw-r--r-- 869 index.html -rw-r--r-- 464 jquery-ui.overrides.css -rw-r--r-- 189 member-search-index.js -rw-r--r-- 45 module-search-index.js -rw-r--r-- 3092 overview-tree.html -rw-r--r-- 95 package-search-index.js -rw-r--r-- 3451 package-summary.html -rw-r--r-- 3209 package-tree.html drwxr-xr-x 136 resources drwxr-xr-x 238 script-dir -rw-r--r-- 2565 script.js -rw-r--r-- 13238 search.js -rw-r--r-- 19763 stylesheet.css -rw-r--r-- 42 tag-search-index.js -rw-r--r-- 120 type-search-index.js 20 File(s) 75,410 bytes
Wow! "javadoc" generated so many files for just a single short Java class file.
As you can see from the file list, Java API documents are generated as Web files (HTML documents). If you open "index.html" in a Web browser, you should see the "Hello" class API document nicely displayed.
Table of Contents
javac - The Java Program Compiler
java - The Java Program Launcher
jpackage - Binary Package Builder
►javadoc - The Java Document Generator
javadoc - Document Generator Command and Options
HelloDocumented.java - javadoc-Style Comments
Generate API Document for Java Package
jdeps - The Java Class Dependency Analyzer
jdeprscan - The Java Deprecated API Scanner
jcmd - The JVM Diagnostic Tool
jconsole - Java Monitoring and Management Console
jstat - JVM Statistics Monitoring Tool
jhsdb - The Java HotSpot Debugger
jvisualvm (Java VisualVM) - JVM Visual Tool
javap - The Java Class File Disassembler
keytool - Public Key Certificate Tool
jrunscript - Script Code Shell
native2ascii - Native-to-ASCII Encoding Converter