02. Applying Javadocs

Description

The first sentence of a Javadoc comment is the description.

/** 
 * The first sentence is the summary statement.
 * <p>
 * We can use HTML modifiers in the free-form text such as <em></em>,
 * <strong></strong> and <img ..>.
 * This is where the longer descriptions would go.
 * </p>
 * However, stray away from the <h1></h1> rules, as they can 
 * interfere with the layout of the published page.
 *
 */

Note that we can also use some HTML elements to change the styling of certain texts.

Class Comments

Place any class comments after the import statements. We use tags to describe parameters. They are followed by a @ symbol. The most common class comments are @author and @version.

/** 
 * A Car Object.
 * 
 * A Car object contains the parameters and functionality of
 * an automobile with four wheels.
 *
 * @author Code Snipcademy 
 * @version 1.0.0 Dec 25, 2015
 */
public class Car {
}

Constructor Comments

For a constructor comment, we want to place an @param with any variables that may be passed to construct an object.

/**
 * Car constructor.
 * 
 * @param numWheels The number of wheels on the car
 */
Car(int numWheels) {
  this.numWheels = numWheels;
}

Method Comments

In a method comment, we may need the @param, @return, @throws and @exception tags.

/**
 * Speed up Car.
 * 
 * @param byMPH The amount in mph to increase car speed
 * @return the now-current car speed
 */
public double speedUp(int byMPH){
} 

Field Comments

Generally, you should document public static fields.

/**
 * The number of wheels on a car. 
 */
public static final int numWheels = 4;

With these javadoc comments in place, we should now be ready to compile and generate our HTML files!

Take your Linux skills to the next level!

System Admin Handbook

Take your Linux skills to the next level! Try Linux & UNIX

This book approaches system administration in a practical way and is an invaluable reference for both new administrators and experienced professionals. It details best practices for every facet of system administration, including storage management, network design and administration, email, web hosting, scripting, and much more.

$ Check price
74.9974.99Amazon 4.5 logo(142+ reviews)

More Linux & UNIX resources

Learn Enterprise Java Development for a Bright Career

Head First Java

Learn Enterprise Java Development for a Bright Career Try Java

Jump start your Java education with Head First Java! This book provides clean diagram examples, with text that is easy-to-understand in an almost too-casual language. Great for anyone new to Java or programming in general.

$ Check price
44.9544.95Amazon 4.5 logo(567+ reviews)

More Java resources

Ad