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!

How Linux Works

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

In this completely revised second edition of the perennial best seller How Linux Works, author Brian Ward makes the concepts behind Linux internals accessible to anyone curious about the inner workings of the operating system. Inside, you'll find the kind of knowledge that normally comes from years of experience doing things the hard way.

$ Check price
39.9539.95Amazon 5 logo(114+ reviews)

More Linux & UNIX resources

Learn Enterprise Java Development for a Bright Career

Effective Java

Learn Enterprise Java Development for a Bright Career Try Java

Are you looking for a deeper understanding of the Java so that you can write code that is clearer, more correct, more robust, and more reusable? Look no further! Effective Java brings together seventy-eight indispensable programmer's rules of thumb: working, best-practice solutions for the programming challenges you encounter every day.

$ Check price
54.9954.99Amazon 4.5 logo(219+ reviews)

More Java resources

Ad