Greeter and GreeterApp - JavaDoc version

See Oracle's Tutorial on Writing Java Doc Comments and the javadoc programmers guide (includes a link to the javadoc tool reference).

Demo of creating JavaDocs for Greeter and GreeterApp classes

C:\Temp>mkdir docs
C:\Temp>notepad Greeter.java
C:\Temp>notepad GreeterApp.java

    The following javadoc command must be entered
    as a single line, even if it wraps as shown here:

C:\Temp>javadoc -d docs -private -author -version -noqualifi
er java.* -link http://docs.oracle.com/javase/8/docs/api/ *.java
Loading source file Greeter.java...
Loading source file GreeterApp.java...
Constructing Javadoc information...
Standard Doclet version 1.8.0_25
Building tree for all the packages and classes...
Generating docs\Greeter.html...
Generating docs\GreeterApp.html...
Generating docs\package-frame.html...
Generating docs\package-summary.html...
Generating docs\package-tree.html...
Generating docs\constant-values.html...
Building index for all the packages and classes...
Generating docs\overview-tree.html...
Generating docs\index-all.html...
Generating docs\deprecated-list.html...
Building index for all classes...
Generating docs\allclasses-frame.html...
Generating docs\allclasses-noframe.html...
Generating docs\index.html...
Generating docs\help-doc.html...

C:\Temp>

At this point, you can point your web browser to the generated documentation at ...\docs\index.html.

Make sure you use the correct URL for the current version of Java; here I used the URL for Java 8.  Note in this example, only some classes were documented.  To document a package, list the package name on the command line instead of “*.java”.  (You can do both.)

Although not shown in this example, you can also have doc comments on a package itself.  Simply create the file “package-info.java” in your package, that contains a doc comment and the package statement, only.  It should look something like this:

/** My package overview sentence goes here.
 * Description of the package, that will show in the HTML
 * for the package as a whole.
 * @see <a href="http://wpollock.com/Java/PkgDemo.htm">Package Demo</a>
 */
package mypackagename;

 

Greeter.java

Download Greeter.java (source)


/** Displays a custom greeting message.
 *  Greeter objects have a <code>greet<code> method that takes a name
 *  and greets that person.  The message used to greet the person is a
 *  <i>property</i> of the Greeter object.
 *
 *  @author Wayne Pollock, Tampa Florida USA.
 *  @see GreeterApp
 *  @version 1.0 (1/2004)
 */
 
public class Greeter
{
   /** The message to use in the greeting. */
   private String message;

   /** A <i>constructor</i> that is used to initialize a Greeter
    *  object's properties: the greeting message to use.
    *
    *  @param message A <code>String</code> used to initialize
    *  the Greater object with the greeting message to use.
    */

   public Greeter ( String message )
   {
      this.message = message;  // Sets the message property
                               // from the message argument
   }

   /**
    *  A <i>method</i> used to greet the named person.
    *
    *  @param name The name of the person to greet.
    */
    
   public void greet ( String name )
   {
      System.out.println( message + " " + name );
   }
}

 

GreeterApp.java

Download GreeterApp.java (source)


/** A class that demonstrates creating {@link Greeter} objects
  * and invoking methods on them.
  * Greeter objects have a
  * {@link Greeter#greet(java.lang.String) greet} method
  * that takes a name of a person and greets that person.
  *
  * @author Wayne Pollock, Tampa Florida USA.
  * @see Greeter
  * @version 1.0 (1/2004) - Initial version
  * @version <br>1.1 (10/2014) - Added {@code @param} for {@code args}
  */

public class GreeterApp
{
   /** The main method of the Greeter application, it creates
    *  some Greet objects and invokes methods on these objects.
    *  @param args unused
    */
   public static void main ( String [] args )
   {
      // Create some Greeter objects...
      Greeter casual = new Greeter( "Howdy" );
      Greeter formal = new Greeter( "Salutations" );

      // ... and use them!
      casual.greet( "Hymie" );
      casual.greet( "Jane" );
      formal.greet( "Mr. President" );
      formal.greet( "Caleb" );
   }
}