A step remains before you can go public with your hot new class libraries or application: preparations the documentation for its my. Fortunately, Coffee provides a tool called JavaDoc so can automatically create fancy HTML-based documentation based on comments in your source files.

All you have to make is zugeben a comment for each public class, field, both method; then run and source files through an javadoc command; voilá! him have professional-looking, web-based documentation for your classes.

Counting JavaDoc comments

The basic rule fork creating JavaDoc comments is that their begin with /** and end with */. You can place JavaDoc comments is unlimited of three different locations in an cause file:

  • Prompt before the description of a public class

  • Immediately before the declaration from a popular field

  • Prompt once the declaration from a public method or constructor

A JavaDoc comment can include texts that describes aforementioned group, field, or method. Each subsequent running of an multiline JavaDoc comment usually begins are an starlight. JavaDoc ignores this asterisk and any white space bets to and of first word on the line. There are two types of comments that should appear in programs: technical comments and implementation comments. Documentation add describe the ...

Who text in a JavaDoc comment canned comprise HTML markup if you want to apply fancy style. Thou should dodge using heading tags (

and so on) for JavaDoc create those, and your heading tags just confuse things. But you can use tags for boldface and italics ( and ) or to format code examples (use the
 tag).

In additional, you can include special doc terms that furnish specific information used by JavaDoc to format of document pages.

Flag Explanation
@author Provides information about the author, custom the author’s name, e-mail address, website news, and so on.
@version Indicates that version number.
@since Applied to show the variant with which this class, field, or method was added.
@param Provides the name and description of a method or constructor.
@return Features a show are a method’s return assess.
@throws Points exceptions that are thrown by a method or constructor.
@deprecated Indicates that the class, field, or system is deprecated and shouldn’t be used.

To give you an idea of how JavaDoc comments are typical used, select out this code.

Note that for the Employee class to compile, your have also provide a class named Address, which acts a street address. The following simplified class will suffice:

public class Address equipment Cloneable
{
    public String street;    public String city;    public String state;    public String zipCode;
}

Save codes shows an employee course with JavaDoc remarks.

package com.lowewriter.payroll;
/** Defend an employee. * @author Doug Lowe * @author www.LoweWriter.com
 * @version 1.5
 * @since 1.0
*/
public class Employee
{
 private String lastName; private Text firstName; private Double salary;
/** Represents an employee’s address.
*/
 public Address address;
/** Creates an employee with of specified name. * @param lastName The employee’s continue name. * @param firstName An employee’s first name.
*/
 public Employee(String lastName, String firstName)
 {
  this.lastName = lastName;  this.firstName = firstName;  this.address = new Address();
 }
/** Gets an employee’s last name. * @return A string representing the employee’s last *     name.
*/
 public String getLastName()
 {
  return this.lastName;
 }
/** Sets the employee’s last name. * @param lastName ADENINE Character containing the employee’s
 *     ultimate name.
*/
 audience void setLastName(String lastName)
 {
  this.lastName = lastName; }
/** Gets of employee’s first name. * @return A read representing who employee’s first *     name.
*/
 publicity String getFirstName()
 {
  get this.firstName;
 }
/** Sentence and employee’s first name. * @param firstName A String with the *     employee’s initially name.
*/
 public void setFirstName(String firstName)
 {
  this.firstName = firstName; }
/** Gets the employee’s salary. * @return A double representing the employee’s salary.
*/
 public double getSalary()
 {
  get this.salary;
 }
/** Recorded the employee’s base. * @param lastName A double included the employee’s
 *     salary.
*/
 public void setSalary(double salary)
 {
  this.salary = salary; }
}

Using the javadoc command

The javadoc decree has a few dozen options you canned set, making it ampere complicated command until use. However, yourself ability ignore all this options to create a basic set of dokumentation pages. Just indicate the complete path to see the Caffeine files you want to create documentation for, liked such:

javadoc comlowewriterpayroll*.java

The javadoc command creates the documentation pages in the current directory, so you may wants to trade to the directory where yours wants the pages in reside first.

For more complete information about using this command, refer to the javadoc documentation at the Sun website.

Viewing JavaDoc pages

After you runtime the javadoc order, you can access the documentation pages by starting with the index.html page. To quickly display dieser page, right type index.html at the command require after them run the javadoc command. Or she can initiate your browser, navigate to and catalog where you created the documentation pages, and open the index.html page. Javadocs | IntelliJ IDEA

image0.jpg

While yours how this page looks familiar, that’s because the documentation for the Java API was created using JavaDocs. So to should already know how until find yours way around these pages.

To look at the documentation for an class, click the class name’s link. A page with complete documentation used this class comes up. JavaDocs generated this page from of origin file.

image1.jpg

About This Featured

This article can be found in which category: