Javadoc Getting Started

Source: Internet
Author: User

Bin Bin ( write to me ) original blog (http://blog.csdn.net/binbinxyz), reproduced please indicate the source !
Java Annotations

There are two types of annotations in Java. One is to start with "/*", End with "*/", and can span multiple lines of comments, as follows:

/* * This is a comment, * it spans multiple lines */
The other is a comment that begins with "//", or a single-line comment, in the following format:

This is a single-line comment


Comment Document

Note: This section is excerpted from the Java Programming Idea Fourth Edition 2.8.1 comment document Chapter

One of the most thoughtful designs for the Java language is that people also need to think about the documentation of the program. The biggest problem with documentation is the maintenance of documents. If the document is separated from the code, changing the document every time the code is changed will undoubtedly become a rather troublesome thing. The workaround seems simple: Link the code to the document. The simplest way to achieve this is to put everything in the same file. However, to make everything uniform, you must also use a special annotation syntax to mark special documents, and a tool to extract the annotations and present them in a valuable form. These are the things that Java has to do.
The tool for extracting annotations is called Javadoc. It uses some techniques from the Java compiler to find special comment tags for our placement program. It extracts not only the information indicated by these tokens, but also the class name or method name adjacent to the comment. This allows us to generate very professional program documentation with the lightest amount of work.
The Javadoc output is an HTML file that can be viewed in its own web browser. This tool allows us to create and manage individual source files, and to generate useful documents vividly. Because of the Javadoc, we were able to create documents in a standard way. And because it is very convenient, we can easily get all the documentation for the Java library.

Javadoc Case"Experimental Environment"

MyEclipse 10.0 + JDK 1.6.0_13

"Experimental Steps"

First, create a new Java project Doc.

Second, create a new Java file Org.hbin.JavaDocTest.java, and add class comments. Such as:


Open the path of the project SRC in the command line tool and export the Java documentation comments using the Javadoc command.

The command is as follows:

> Javadoc Org/hbin/javadoctest.java

Operating effects such as:


To refresh the project, the resulting document directory structure is as follows:


At this point, the document mixed with the source code, not easy to manage maintenance. You can add the-d parameter to specify the destination directory for the output file.

The command is as follows:

> javadoc-d. /doc Org/hbin/javadoctest.java
Such as:



In this case, open the index.html file in the doc directory in your project to see the structure of the document we just generated. Such as:


Four, refer to the above three steps, you can already generate your own comment document. However, if your comment contains Chinese or other non-English characters, it may be garbled. At this point, the encoding can be specified using the-charset and-encoding parameters. The-charset parameter specifies to view the encoding of the generated HTML, i.e. add <meta http-equiv= "Content-type" content= "text/html" in the HTML document; Charset=utf-8, while the-encoding parameter specifies the source file encoding.

The command is as follows:

> Javadoc-charset UTF-8-encoding UTF-8-D. /doc Org/hbin/javadoctest.java


Javadoc Getting Started

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.