Top Banner
COMP 213 Advanced Object-oriented Programming Lecture 11 Documentation and Javadoc.
93

Advanced Object-oriented Programming Lecture 11cgi.csc.liv.ac.uk/~akridel/COMP213-Fall2016/Lecture...private Vector myCars;...} which directs the compiler to look at all

Aug 02, 2020

Download

Documents

dariahiddleston
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Advanced Object-oriented Programming Lecture 11cgi.csc.liv.ac.uk/~akridel/COMP213-Fall2016/Lecture...private Vector<Car> myCars;...} which directs the compiler to look at all

COMP 213Advanced Object-oriented Programming

Lecture 11

Documentation and Javadoc.

Page 2: Advanced Object-oriented Programming Lecture 11cgi.csc.liv.ac.uk/~akridel/COMP213-Fall2016/Lecture...private Vector<Car> myCars;...} which directs the compiler to look at all

Using Off-the-shelf Classes

• All Java classes are contained in some package.The default package is a directory:E.g., when compiling the file Main.java, the compiler will find a reference to class ArrayUnsortedList, so it will look for the file ArrayUnsortedList.class in the same directory (if it doesn’t find it, it will look for the file ArrayUnsortedList.java, and compile that).

• Classes from other packages (i.e., not in the current working directory) need to be explicitly imported.

Page 3: Advanced Object-oriented Programming Lecture 11cgi.csc.liv.ac.uk/~akridel/COMP213-Fall2016/Lecture...private Vector<Car> myCars;...} which directs the compiler to look at all

Using Off-the-shelf Classes

• All Java classes are contained in some package.The default package is a directory:E.g., when compiling the file Main.java, the compiler will find a reference to class ArrayUnsortedList, so it will look for the file ArrayUnsortedList.class in the same directory (if it doesn’t find it, it will look for the file ArrayUnsortedList.java, and compile that).

• Classes from other packages (i.e., not in the current working directory) need to be explicitly imported.

Page 4: Advanced Object-oriented Programming Lecture 11cgi.csc.liv.ac.uk/~akridel/COMP213-Fall2016/Lecture...private Vector<Car> myCars;...} which directs the compiler to look at all

Using Off-the-shelf Classes

• All Java classes are contained in some package.The default package is a directory:E.g., when compiling the file Main.java, the compiler will find a reference to class ArrayUnsortedList, so it will look for the file ArrayUnsortedList.class in the same directory (if it doesn’t find it, it will look for the file ArrayUnsortedList.java, and compile that).

• Classes from other packages (i.e., not in the current working directory) need to be explicitly imported.

Page 5: Advanced Object-oriented Programming Lecture 11cgi.csc.liv.ac.uk/~akridel/COMP213-Fall2016/Lecture...private Vector<Car> myCars;...} which directs the compiler to look at all

Importing Classes

For example, to use the class Vector from package java.util, we write:

import java.util.Vector;

public class CarMain {

private Vector<Car> myCars;

...

}

Page 6: Advanced Object-oriented Programming Lecture 11cgi.csc.liv.ac.uk/~akridel/COMP213-Fall2016/Lecture...private Vector<Car> myCars;...} which directs the compiler to look at all

Importing Classes

For example, to use the class Vector from package java.util, we write:

import java.util.Vector;

public class CarMain {

private Vector<Car> myCars;

...

}

Page 7: Advanced Object-oriented Programming Lecture 11cgi.csc.liv.ac.uk/~akridel/COMP213-Fall2016/Lecture...private Vector<Car> myCars;...} which directs the compiler to look at all

Importing Classes

For example, to use the class Vector from package java.util, we write:

import java.util.Vector;

public class CarMain {

private Vector<Car> myCars;

...

}

Then the compiler knows where to look when it finds the name ‘Vector’.

Page 8: Advanced Object-oriented Programming Lecture 11cgi.csc.liv.ac.uk/~akridel/COMP213-Fall2016/Lecture...private Vector<Car> myCars;...} which directs the compiler to look at all

Importing Classes

For example, to use the class Vector from package java.util, we write:

import java.util.Vector;

public class CarMain {

private Vector<Car> myCars;

...

}

Then the compiler knows where to look when it finds the name ‘Vector’.

Page 9: Advanced Object-oriented Programming Lecture 11cgi.csc.liv.ac.uk/~akridel/COMP213-Fall2016/Lecture...private Vector<Car> myCars;...} which directs the compiler to look at all

Importing Classes

An alternative is:

import java.util.*;

public class CarMain {

private Vector<Car> myCars;

...

}

Page 10: Advanced Object-oriented Programming Lecture 11cgi.csc.liv.ac.uk/~akridel/COMP213-Fall2016/Lecture...private Vector<Car> myCars;...} which directs the compiler to look at all

Importing Classes

An alternative is:

import java.util.*;

public class CarMain {

private Vector<Car> myCars;

...

}

Page 11: Advanced Object-oriented Programming Lecture 11cgi.csc.liv.ac.uk/~akridel/COMP213-Fall2016/Lecture...private Vector<Car> myCars;...} which directs the compiler to look at all

Importing Classes

An alternative is:

import java.util.*;

public class CarMain {

private Vector<Car> myCars;

...

}

which directs the compiler to look at all the classes in package java.util.

Page 12: Advanced Object-oriented Programming Lecture 11cgi.csc.liv.ac.uk/~akridel/COMP213-Fall2016/Lecture...private Vector<Car> myCars;...} which directs the compiler to look at all

Importing Classes

This is convenient if you’re using a large number of classes from the same package. For example,

import javax.swing.JButton;

import javax.swing.JFrame;

import javax.swing.JTextArea;

import javax.swing.JTextField;

import java.util.Vector;

import java.util.LinkedList;

Page 13: Advanced Object-oriented Programming Lecture 11cgi.csc.liv.ac.uk/~akridel/COMP213-Fall2016/Lecture...private Vector<Car> myCars;...} which directs the compiler to look at all

Importing Classes

This is convenient if you’re using a large number of classes from the same package. For example,

import javax.swing.JButton;

import javax.swing.JFrame;

import javax.swing.JTextArea;

import javax.swing.JTextField;

import java.util.Vector;

import java.util.LinkedList;

Page 14: Advanced Object-oriented Programming Lecture 11cgi.csc.liv.ac.uk/~akridel/COMP213-Fall2016/Lecture...private Vector<Car> myCars;...} which directs the compiler to look at all

Importing Classes

This is convenient if you’re using a large number of classes from the same package. For example,

import javax.swing.JButton;

import javax.swing.JFrame;

import javax.swing.JTextArea;

import javax.swing.JTextField;

import java.util.Vector;

import java.util.LinkedList;

could simply be written as:

import javax.swing.*;import java.util.*;

Page 15: Advanced Object-oriented Programming Lecture 11cgi.csc.liv.ac.uk/~akridel/COMP213-Fall2016/Lecture...private Vector<Car> myCars;...} which directs the compiler to look at all

Importing Classes

This is convenient if you’re using a large number of classes from the same package. For example,

import javax.swing.JButton;

import javax.swing.JFrame;

import javax.swing.JTextArea;

import javax.swing.JTextField;

import java.util.Vector;

import java.util.LinkedList;

could simply be written as:

import javax.swing.*;import java.util.*;

but many programmers prefer to explicitly list all the classes they use as a form of documentation.

Page 16: Advanced Object-oriented Programming Lecture 11cgi.csc.liv.ac.uk/~akridel/COMP213-Fall2016/Lecture...private Vector<Car> myCars;...} which directs the compiler to look at all

Documentation

One of the ways we view classes is implementations of ADTs.Once they are written, they can be used and re-used.— How many applications use class javax.swing.JButton, or java.util.ArrayList?

In order to be (re)useful — to other programmers (across the world, or maybe just in another team in the same development project), or even to the original programmer (it can be hard going back to code you wrote even a couple of days ago) — the class must be clearly documented.

Page 17: Advanced Object-oriented Programming Lecture 11cgi.csc.liv.ac.uk/~akridel/COMP213-Fall2016/Lecture...private Vector<Car> myCars;...} which directs the compiler to look at all

Documentation

One of the ways we view classes is implementations of ADTs.Once they are written, they can be used and re-used.— How many applications use class javax.swing.JButton, or java.util.ArrayList?

In order to be (re)useful — to other programmers (across the world, or maybe just in another team in the same development project), or even to the original programmer (it can be hard going back to code you wrote even a couple of days ago) — the class must be clearly documented.

Page 18: Advanced Object-oriented Programming Lecture 11cgi.csc.liv.ac.uk/~akridel/COMP213-Fall2016/Lecture...private Vector<Car> myCars;...} which directs the compiler to look at all

Documentation

One of the ways we view classes is implementations of ADTs.Once they are written, they can be used and re-used.— How many applications use class javax.swing.JButton, or java.util.ArrayList?

In order to be (re)useful — to other programmers (across the world, or maybe just in another team in the same development project), or even to the original programmer (it can be hard going back to code you wrote even a couple of days ago) — the class must be clearly documented.

Page 19: Advanced Object-oriented Programming Lecture 11cgi.csc.liv.ac.uk/~akridel/COMP213-Fall2016/Lecture...private Vector<Car> myCars;...} which directs the compiler to look at all

APIs

An API (Application Program Interface) for a package lists all the public classes in that package.

For each public class, there is a list of its (public or protected):

• constants

• fields

• constructors

• methods

Each of these members has some accompanying documentation.

Page 20: Advanced Object-oriented Programming Lecture 11cgi.csc.liv.ac.uk/~akridel/COMP213-Fall2016/Lecture...private Vector<Car> myCars;...} which directs the compiler to look at all

APIs

An API (Application Program Interface) for a package lists all the public classes in that package.

For each public class, there is a list of its (public or protected):

• constants

• fields

• constructors

• methods

Each of these members has some accompanying documentation.

Page 21: Advanced Object-oriented Programming Lecture 11cgi.csc.liv.ac.uk/~akridel/COMP213-Fall2016/Lecture...private Vector<Car> myCars;...} which directs the compiler to look at all

APIs

An API (Application Program Interface) for a package lists all the public classes in that package.

For each public class, there is a list of its (public or protected):

• constants

• fields

• constructors

• methods

Each of these members has some accompanying documentation.

Page 22: Advanced Object-oriented Programming Lecture 11cgi.csc.liv.ac.uk/~akridel/COMP213-Fall2016/Lecture...private Vector<Car> myCars;...} which directs the compiler to look at all

APIs

An API (Application Program Interface) for a package lists all the public classes in that package.

For each public class, there is a list of its (public or protected):

• constants

• fields

• constructors

• methods

Each of these members has some accompanying documentation.

Page 23: Advanced Object-oriented Programming Lecture 11cgi.csc.liv.ac.uk/~akridel/COMP213-Fall2016/Lecture...private Vector<Car> myCars;...} which directs the compiler to look at all

APIs

An API (Application Program Interface) for a package lists all the public classes in that package.

For each public class, there is a list of its (public or protected):

• constants

• fields

• constructors

• methods

Each of these members has some accompanying documentation.

Page 24: Advanced Object-oriented Programming Lecture 11cgi.csc.liv.ac.uk/~akridel/COMP213-Fall2016/Lecture...private Vector<Car> myCars;...} which directs the compiler to look at all

APIs

An API (Application Program Interface) for a package lists all the public classes in that package.

For each public class, there is a list of its (public or protected):

• constants

• fields

• constructors

• methods

Each of these members has some accompanying documentation.

Page 25: Advanced Object-oriented Programming Lecture 11cgi.csc.liv.ac.uk/~akridel/COMP213-Fall2016/Lecture...private Vector<Car> myCars;...} which directs the compiler to look at all

APIs

An API (Application Program Interface) for a package lists all the public classes in that package.

For each public class, there is a list of its (public or protected):

• constants

• fields

• constructors

• methods

Each of these members has some accompanying documentation.

Page 26: Advanced Object-oriented Programming Lecture 11cgi.csc.liv.ac.uk/~akridel/COMP213-Fall2016/Lecture...private Vector<Car> myCars;...} which directs the compiler to look at all

Javadoc

Included in the standard distributions of Java is a tool for generating the HTML pages that make up the API documentation.

The tool is called javadoc, and it works on the Java source files in a package (e.g., the default package).

The Java source files should be marked up with special comments preceding each member of the class, as well as the class itself.(By default, javadoc documents only public and protected classes and members, but this default can be overridden.)

Page 27: Advanced Object-oriented Programming Lecture 11cgi.csc.liv.ac.uk/~akridel/COMP213-Fall2016/Lecture...private Vector<Car> myCars;...} which directs the compiler to look at all

Javadoc

Included in the standard distributions of Java is a tool for generating the HTML pages that make up the API documentation.

The tool is called javadoc, and it works on the Java source files in a package (e.g., the default package).

The Java source files should be marked up with special comments preceding each member of the class, as well as the class itself.(By default, javadoc documents only public and protected classes and members, but this default can be overridden.)

Page 28: Advanced Object-oriented Programming Lecture 11cgi.csc.liv.ac.uk/~akridel/COMP213-Fall2016/Lecture...private Vector<Car> myCars;...} which directs the compiler to look at all

Javadoc

Included in the standard distributions of Java is a tool for generating the HTML pages that make up the API documentation.

The tool is called javadoc, and it works on the Java source files in a package (e.g., the default package).

The Java source files should be marked up with special comments preceding each member of the class, as well as the class itself.(By default, javadoc documents only public and protected classes and members, but this default can be overridden.)

Page 29: Advanced Object-oriented Programming Lecture 11cgi.csc.liv.ac.uk/~akridel/COMP213-Fall2016/Lecture...private Vector<Car> myCars;...} which directs the compiler to look at all

Javadoc

Included in the standard distributions of Java is a tool for generating the HTML pages that make up the API documentation.

The tool is called javadoc, and it works on the Java source files in a package (e.g., the default package).

The Java source files should be marked up with special comments preceding each member of the class, as well as the class itself.(By default, javadoc documents only public and protected classes and members, but this default can be overridden.)

Page 30: Advanced Object-oriented Programming Lecture 11cgi.csc.liv.ac.uk/~akridel/COMP213-Fall2016/Lecture...private Vector<Car> myCars;...} which directs the compiler to look at all

Javadoc and APIs

Javadoc is a utility for generating html documentation for classes and packages.

• write the source code, e.g., MyClass.java

• add a javadoc comment for each class and for each of their members

• then, in the command line:

javadoc MyClass.java

…will generate the html files (index.html, MyClass.html, etc.)

The html files will contain all of the javadoc comments from the source-code file.

Page 31: Advanced Object-oriented Programming Lecture 11cgi.csc.liv.ac.uk/~akridel/COMP213-Fall2016/Lecture...private Vector<Car> myCars;...} which directs the compiler to look at all

Javadoc and APIs

Javadoc is a utility for generating html documentation for classes and packages.

• write the source code, e.g., MyClass.java

• add a javadoc comment for each class and for each of their members

• then, in the command line:

…will generate the html files (index.html, MyClass.html, etc.)

The html files will contain all of the javadoc comments from the source-code file.

javadoc MyClass.java

Page 32: Advanced Object-oriented Programming Lecture 11cgi.csc.liv.ac.uk/~akridel/COMP213-Fall2016/Lecture...private Vector<Car> myCars;...} which directs the compiler to look at all

Javadoc and APIs

Javadoc is a utility for generating html documentation for classes and packages.

• write the source code, e.g., MyClass.java

• add a javadoc comment for each class and for each of their members

• then, in the command line:

…will generate the html files (index.html, MyClass.html, etc.)

The html files will contain all of the javadoc comments from the source-code file.

javadoc MyClass.java

Page 33: Advanced Object-oriented Programming Lecture 11cgi.csc.liv.ac.uk/~akridel/COMP213-Fall2016/Lecture...private Vector<Car> myCars;...} which directs the compiler to look at all

Javadoc and APIs

Javadoc is a utility for generating html documentation for classes and packages.

• write the source code, e.g., MyClass.java

• add a javadoc comment for each class and for each of their members

• then, in the command line:

javadoc MyClass.java

…will generate the html files (index.html, MyClass.html, etc.)

The html files will contain all of the javadoc comments from the source-code file.

Page 34: Advanced Object-oriented Programming Lecture 11cgi.csc.liv.ac.uk/~akridel/COMP213-Fall2016/Lecture...private Vector<Car> myCars;...} which directs the compiler to look at all

Javadoc and APIs

Javadoc is a utility for generating html documentation for classes and packages.

• write the source code, e.g., MyClass.java

• add a javadoc comment for each class and for each of their members

• then, in the command line:

javadoc MyClass.java

…will generate the html files (index.html, MyClass.html, etc.)

The html files will contain all of the javadoc comments from the source-code file.

Page 35: Advanced Object-oriented Programming Lecture 11cgi.csc.liv.ac.uk/~akridel/COMP213-Fall2016/Lecture...private Vector<Car> myCars;...} which directs the compiler to look at all

Javadoc Comments

Javadoc comments are like standard multi-line comments, but begin with a slash followed by two asterisks:

/***An unsorted list of objects.*There are operations to add, find, remove an element*inside the list, as well as check if an element is in*the list.*...*/public class ArrayUnsortedList implements ListInterface {...}

Page 36: Advanced Object-oriented Programming Lecture 11cgi.csc.liv.ac.uk/~akridel/COMP213-Fall2016/Lecture...private Vector<Car> myCars;...} which directs the compiler to look at all

Javadoc Comments

Javadoc comments are like standard multi-line comments, but begin with a slash followed by two asterisks:

/***An unsorted list of objects.*There are operations to add, find, remove an element*inside the list, as well as check if an element is in*the list.*...*/public class ArrayUnsortedList implements ListInterface {...}

Page 37: Advanced Object-oriented Programming Lecture 11cgi.csc.liv.ac.uk/~akridel/COMP213-Fall2016/Lecture...private Vector<Car> myCars;...} which directs the compiler to look at all

Javadoc Comments

Javadoc comments are like standard multi-line comments, but begin with a slash followed by two asterisks:

/***An unsorted list of objects.*There are operations to add, find, remove an element*inside the list, as well as check if an element is in*the list.*...*/public class ArrayUnsortedList implements ListInterface {...}

Page 38: Advanced Object-oriented Programming Lecture 11cgi.csc.liv.ac.uk/~akridel/COMP213-Fall2016/Lecture...private Vector<Car> myCars;...} which directs the compiler to look at all

Javadoc Comments

• The first sentence should be a summary of the thing being documented (class, field, method, etc.).

• This will be used in the corresponding ‘Summary’ section of the API.

• Note: ‘sentence’ means everything up to the first full stop “.” followed by white space (space, new line, tab, etc.)

Page 39: Advanced Object-oriented Programming Lecture 11cgi.csc.liv.ac.uk/~akridel/COMP213-Fall2016/Lecture...private Vector<Car> myCars;...} which directs the compiler to look at all

Javadoc Comments

• The first sentence should be a summary of the thing being documented (class, field, method, etc.).

• This will be used in the corresponding ‘Summary’ section of the API.

• Note: ‘sentence’ means everything up to the first full stop “.” followed by white space (space, new line, tab, etc.)

Page 40: Advanced Object-oriented Programming Lecture 11cgi.csc.liv.ac.uk/~akridel/COMP213-Fall2016/Lecture...private Vector<Car> myCars;...} which directs the compiler to look at all

Javadoc Comments

• The first sentence should be a summary of the thing being documented (class, field, method, etc.).

• This will be used in the corresponding ‘Summary’ section of the API.

• Note: ‘sentence’ means everything up to the first full stop “.” followed by white space (space, new line, tab, etc.)

Page 41: Advanced Object-oriented Programming Lecture 11cgi.csc.liv.ac.uk/~akridel/COMP213-Fall2016/Lecture...private Vector<Car> myCars;...} which directs the compiler to look at all

Javadoc Comments

For example, if the input contains:

/** Increments the capacity of the list by an amount equal to the* original capacity.* Creates a larger array and copies all the list elements to the* new larger array.*/

protected void enlarge() {...

}

Page 42: Advanced Object-oriented Programming Lecture 11cgi.csc.liv.ac.uk/~akridel/COMP213-Fall2016/Lecture...private Vector<Car> myCars;...} which directs the compiler to look at all

Javadoc Comments

For example, if the input contains:

/** Increments the capacity of the list by an amount equal to the* original capacity.* Creates a larger array and copies all the list elements to the* new larger array.*/

protected void enlarge() {...

}

Page 43: Advanced Object-oriented Programming Lecture 11cgi.csc.liv.ac.uk/~akridel/COMP213-Fall2016/Lecture...private Vector<Car> myCars;...} which directs the compiler to look at all

Javadoc Comments

…the output (in the ArrayUnsortedList API) will have, in the ‘Method Summary’ section:

void enlarge()

Increments the capacity of the list by an amount equal to the original capacity.

Page 44: Advanced Object-oriented Programming Lecture 11cgi.csc.liv.ac.uk/~akridel/COMP213-Fall2016/Lecture...private Vector<Car> myCars;...} which directs the compiler to look at all

Javadoc Comments

…the output (in the ArrayUnsortedList API) will have, in the ‘Method Summary’ section:

void enlarge()

Increments the capacity of the list by an amount equal to the original capacity.

and in the ‘Method Detail’ section:

public void enlarge()

Increments the capacity of the list by an amount equal to the original capacity.

Creates a larger array and copies all the list elements to the new larger array.

Page 45: Advanced Object-oriented Programming Lecture 11cgi.csc.liv.ac.uk/~akridel/COMP213-Fall2016/Lecture...private Vector<Car> myCars;...} which directs the compiler to look at all

Javadoc Comments

All comments can (should) be marked-up HTML, and can contain any HTML tag.

/*** A Car has:* <ul>* <li>a brand;</li>* <li>a model;</li>* <li>a colour;</li>* ...* </ul>*/public class Car {

...}

Page 46: Advanced Object-oriented Programming Lecture 11cgi.csc.liv.ac.uk/~akridel/COMP213-Fall2016/Lecture...private Vector<Car> myCars;...} which directs the compiler to look at all

Javadoc Comments

All comments can (should) be marked-up HTML, and can contain any HTML tag.

/*** A Car has:* <ul>* a brand;* a model;* a colour;* ...* */public class Car {

...}

Page 47: Advanced Object-oriented Programming Lecture 11cgi.csc.liv.ac.uk/~akridel/COMP213-Fall2016/Lecture...private Vector<Car> myCars;...} which directs the compiler to look at all

Javadoc Comments

All comments can (should) be marked-up HTML, and can contain any HTML tag.

/*** A Car has:* <ul>* <li>a brand;</li>* <li>a model;</li>* <li>a colour;</li>* ...* </ul>*/public class Car {

...}

Page 48: Advanced Object-oriented Programming Lecture 11cgi.csc.liv.ac.uk/~akridel/COMP213-Fall2016/Lecture...private Vector<Car> myCars;...} which directs the compiler to look at all

Javadoc Tags

In addition, there are certain tags specific to javadoc.The most useful are:

• @param— describe parameters to a method

• @return— describe the return value of a method

• @link— cross-reference another item in the API

Page 49: Advanced Object-oriented Programming Lecture 11cgi.csc.liv.ac.uk/~akridel/COMP213-Fall2016/Lecture...private Vector<Car> myCars;...} which directs the compiler to look at all

Javadoc Tags

In addition, there are certain tags specific to javadoc.The most useful are:

• @param— describe parameters to a method

• @return— describe the return value of a method

• @link— cross-reference another item in the API

Page 50: Advanced Object-oriented Programming Lecture 11cgi.csc.liv.ac.uk/~akridel/COMP213-Fall2016/Lecture...private Vector<Car> myCars;...} which directs the compiler to look at all

Javadoc Tags

In addition, there are certain tags specific to javadoc.The most useful are:

• @param— describe parameters to a method

• @return— describe the return value of a method

• @link— cross-reference another item in the API

Page 51: Advanced Object-oriented Programming Lecture 11cgi.csc.liv.ac.uk/~akridel/COMP213-Fall2016/Lecture...private Vector<Car> myCars;...} which directs the compiler to look at all

Javadoc Tags

In addition, there are certain tags specific to javadoc.The most useful are:

• @param— describe parameters to a method

• @return— describe the return value of a method

• @link— cross-reference another item in the API

Page 52: Advanced Object-oriented Programming Lecture 11cgi.csc.liv.ac.uk/~akridel/COMP213-Fall2016/Lecture...private Vector<Car> myCars;...} which directs the compiler to look at all

Javadoc Tags

In addition, there are certain tags specific to javadoc.The most useful are:

• @param— describe parameters to a method

• @return— describe the return value of a method

• @link— cross-reference another item in the API

Page 53: Advanced Object-oriented Programming Lecture 11cgi.csc.liv.ac.uk/~akridel/COMP213-Fall2016/Lecture...private Vector<Car> myCars;...} which directs the compiler to look at all

Javadoc Tags

For methods, there are @param and @return tags:

/*** Find if a given element exists in the list.* @param element the element to be found* @return <code>true</code> if there is an item of the list that equals the* given element.*/public boolean contains(Object element) {

...}

Page 54: Advanced Object-oriented Programming Lecture 11cgi.csc.liv.ac.uk/~akridel/COMP213-Fall2016/Lecture...private Vector<Car> myCars;...} which directs the compiler to look at all

Javadoc Tags

For methods, there are @param and @return tags:

/*** Find if a given element exists in the list.* @param element the element to be found* @return <code>true</code> if there is an item of the list that equals the* given element.*/public boolean contains(Object element) {

...}

Page 55: Advanced Object-oriented Programming Lecture 11cgi.csc.liv.ac.uk/~akridel/COMP213-Fall2016/Lecture...private Vector<Car> myCars;...} which directs the compiler to look at all

Javadoc Tags

For methods, there are @param and @return tags:

/*** Find if a given element exists in the list.* @param element the element to be found* @return <code>true</code> if there is an item of the list that equals the* given element.*/public boolean contains(Object element) {

...}

There should be one @param tag for each parameter.

@return should be used for every method with a non-void return type.

Page 56: Advanced Object-oriented Programming Lecture 11cgi.csc.liv.ac.uk/~akridel/COMP213-Fall2016/Lecture...private Vector<Car> myCars;...} which directs the compiler to look at all

Javadoc Tags

For methods, there are @param and @return tags:

/*** Find if a given element exists in the list.* @param element the element to be found* @return <code>true</code> if there is an item of the list that equals the* given element.*/public boolean contains(Object element) {

...}

There should be one @param tag for each parameter.

@return should be used for every method with a non-void return type.

Page 57: Advanced Object-oriented Programming Lecture 11cgi.csc.liv.ac.uk/~akridel/COMP213-Fall2016/Lecture...private Vector<Car> myCars;...} which directs the compiler to look at all

Javadoc Tags

This will produce, in the Method Detail section:

public boolean contains(java.lang.Object element)

Find if a given element exists in the list.

Parameters:element — the element to be found

Returns:true if there is an item of the list that equals the given element.

Page 58: Advanced Object-oriented Programming Lecture 11cgi.csc.liv.ac.uk/~akridel/COMP213-Fall2016/Lecture...private Vector<Car> myCars;...} which directs the compiler to look at all

Javadoc Cross-References

Cross-referencing (generating hyper-links in the HTML pages) can be done with the @link tag.

The general format is: {@link Link-Name Text}

This creates a hyper-link where:

• Text is the text displayed in the hyperlink

• Link-Name is the target (in javadoc notation!)

Page 59: Advanced Object-oriented Programming Lecture 11cgi.csc.liv.ac.uk/~akridel/COMP213-Fall2016/Lecture...private Vector<Car> myCars;...} which directs the compiler to look at all

Javadoc Cross-References

Cross-referencing (generating hyper-links in the HTML pages) can be done with the @link tag.

The general format is: {@link Link-Name Text}

This creates a hyper-link where:

• Text is the text displayed in the hyperlink

• Link-Name is the target (in javadoc notation!)

Page 60: Advanced Object-oriented Programming Lecture 11cgi.csc.liv.ac.uk/~akridel/COMP213-Fall2016/Lecture...private Vector<Car> myCars;...} which directs the compiler to look at all

Javadoc Cross-References

Cross-referencing (generating hyper-links in the HTML pages) can be done with the @link tag.

The general format is: {@link Link-Name Text}

This creates a hyper-link where:

• Text is the text displayed in the hyperlink

• Link-Name is the target (in javadoc notation!)

Page 61: Advanced Object-oriented Programming Lecture 11cgi.csc.liv.ac.uk/~akridel/COMP213-Fall2016/Lecture...private Vector<Car> myCars;...} which directs the compiler to look at all

Javadoc Cross-References

Cross-referencing (generating hyper-links in the HTML pages) can be done with the @link tag.

The general format is: {@link Link-Name Text}

This creates a hyper-link where:

• Text is the text displayed in the hyperlink

• Link-Name is the target (in javadoc notation!)

Page 62: Advanced Object-oriented Programming Lecture 11cgi.csc.liv.ac.uk/~akridel/COMP213-Fall2016/Lecture...private Vector<Car> myCars;...} which directs the compiler to look at all

Javadoc Cross-References

Cross-referencing (generating hyper-links in the HTML pages) can be done with the @link tag.

The general format is: {@link Link-Name Text}

This creates a hyper-link where:

• Text is the text displayed in the hyperlink

• Link-Name is the target (in javadoc notation!)

Page 63: Advanced Object-oriented Programming Lecture 11cgi.csc.liv.ac.uk/~akridel/COMP213-Fall2016/Lecture...private Vector<Car> myCars;...} which directs the compiler to look at all

Javadoc Cross-References

The Link-Name is either:

• just the name of a class in the same package

... implementation of the {@link ArrayUnsortedList ArrayUnsortedList} ...

Page 64: Advanced Object-oriented Programming Lecture 11cgi.csc.liv.ac.uk/~akridel/COMP213-Fall2016/Lecture...private Vector<Car> myCars;...} which directs the compiler to look at all

Javadoc Cross-References

The Link-Name is either:

• just the name of a class in the same package

... implementation of the {@link ArrayUnsortedList ArrayUnsortedList} ...

• the name of a member within the class

... invokes the method {@link #find(Object) find} ...

Page 65: Advanced Object-oriented Programming Lecture 11cgi.csc.liv.ac.uk/~akridel/COMP213-Fall2016/Lecture...private Vector<Car> myCars;...} which directs the compiler to look at all

Javadoc Cross-References

The Link-Name is either:

• just the name of a class in the same package

... implementation of the {@link ArrayUnsortedList ArrayUnsortedList} ...

• the name of a member within the class

... invokes the method {@link #find(Object) find} ...

Note: the link-names for methods always include brackets, which must contain the types only of any parameters.

Page 66: Advanced Object-oriented Programming Lecture 11cgi.csc.liv.ac.uk/~akridel/COMP213-Fall2016/Lecture...private Vector<Car> myCars;...} which directs the compiler to look at all

Javadoc Cross-References

The Link-Name is either:

• just the name of a class in the same package

... implementation of the {@link ArrayUnsortedList ArrayUnsortedList} ...

• the name of a member within the class

... invokes the method {@link #find(Object) find} ...

• the name of a member in some other class

... by {@link ArrayUnsortedList#DEFCAP the default capacity}...

Note: the link-names for methods always include brackets, which must contain the types only of any parameters.

Page 67: Advanced Object-oriented Programming Lecture 11cgi.csc.liv.ac.uk/~akridel/COMP213-Fall2016/Lecture...private Vector<Car> myCars;...} which directs the compiler to look at all

Javadoc Cross-References

The generated link points to the relevant part of the API pages.

For example,

... invokes the method {@link #find(Object) find} ...

will produce an html file containing:

… invokes the method find ...

with the hyperlink pointing to the part of ArrayUnsortedList.html where the method find is described.

Page 68: Advanced Object-oriented Programming Lecture 11cgi.csc.liv.ac.uk/~akridel/COMP213-Fall2016/Lecture...private Vector<Car> myCars;...} which directs the compiler to look at all

Javadoc Cross-References

The generated link points to the relevant part of the API pages.

For example,

... invokes the method {@link #find(Object) find} ...

will produce an html file containing:

… invokes the method find ...

with the hyperlink pointing to the part of ArrayUnsortedList.html where the method find is described.

Page 69: Advanced Object-oriented Programming Lecture 11cgi.csc.liv.ac.uk/~akridel/COMP213-Fall2016/Lecture...private Vector<Car> myCars;...} which directs the compiler to look at all

Javadoc Cross-References

The generated link points to the relevant part of the API pages.

For example,

... invokes the method {@link #find(Object) find} ...

will produce an html file containing:

… invokes the method find ...

with the hyperlink pointing to the part of ArrayUnsortedList.html where the method find is described.

Page 70: Advanced Object-oriented Programming Lecture 11cgi.csc.liv.ac.uk/~akridel/COMP213-Fall2016/Lecture...private Vector<Car> myCars;...} which directs the compiler to look at all

Javadoc Cross-References

The generated link points to the relevant part of the API pages.

For example,

... invokes the method {@link #find(Object) find} ...

will produce an html file containing:

… invokes the method find ...

with the hyperlink pointing to the part of ArrayUnsortedList.html where the method find is described.

Page 71: Advanced Object-oriented Programming Lecture 11cgi.csc.liv.ac.uk/~akridel/COMP213-Fall2016/Lecture...private Vector<Car> myCars;...} which directs the compiler to look at all

Important Points

• Javadoc comments come immediately before the thing they describe.

• They can describe: classes, methods, and fields.

• They cannot be used inside methods (well, they can, but they’ll be ignored, so just use standard in-line comments// ...

and/*...*/

).

Page 72: Advanced Object-oriented Programming Lecture 11cgi.csc.liv.ac.uk/~akridel/COMP213-Fall2016/Lecture...private Vector<Car> myCars;...} which directs the compiler to look at all

Important Points

• Javadoc comments come immediately before the thing they describe.

• They can describe: classes, methods, and fields.

• They cannot be used inside methods (well, they can, but they’ll be ignored, so just use standard in-line comments// ...

and/*...*/

).

Page 73: Advanced Object-oriented Programming Lecture 11cgi.csc.liv.ac.uk/~akridel/COMP213-Fall2016/Lecture...private Vector<Car> myCars;...} which directs the compiler to look at all

Important Points

• Javadoc comments come immediately before the thing they describe.

• They can describe: classes, methods, and fields.

• They cannot be used inside methods (well, they can, but they’ll be ignored, so just use standard in-line comments// ...

and/*...*/

).

Page 74: Advanced Object-oriented Programming Lecture 11cgi.csc.liv.ac.uk/~akridel/COMP213-Fall2016/Lecture...private Vector<Car> myCars;...} which directs the compiler to look at all

Good Practice

• one javadoc comment for each class

• one javadoc comment for each member of a class (public, protected, or private)

• always use @param for each parameter

• always use @return for non-void return types

• comments should be useful

Page 75: Advanced Object-oriented Programming Lecture 11cgi.csc.liv.ac.uk/~akridel/COMP213-Fall2016/Lecture...private Vector<Car> myCars;...} which directs the compiler to look at all

Good Practice

• one javadoc comment for each class

• one javadoc comment for each member of a class (public, protected, or private)

• always use @param for each parameter

• always use @return for non-void return types

• comments should be useful

Page 76: Advanced Object-oriented Programming Lecture 11cgi.csc.liv.ac.uk/~akridel/COMP213-Fall2016/Lecture...private Vector<Car> myCars;...} which directs the compiler to look at all

Good Practice

• one javadoc comment for each class

• one javadoc comment for each member of a class (public, protected, or private)

• always use @param for each parameter

• always use @return for non-void return types

• comments should be useful

Page 77: Advanced Object-oriented Programming Lecture 11cgi.csc.liv.ac.uk/~akridel/COMP213-Fall2016/Lecture...private Vector<Car> myCars;...} which directs the compiler to look at all

Good Practice

• one javadoc comment for each class

• one javadoc comment for each member of a class (public, protected, or private)

• always use @param for each parameter

• always use @return for non-void return types

• comments should be useful

Page 78: Advanced Object-oriented Programming Lecture 11cgi.csc.liv.ac.uk/~akridel/COMP213-Fall2016/Lecture...private Vector<Car> myCars;...} which directs the compiler to look at all

Good Practice

• one javadoc comment for each class

• one javadoc comment for each member of a class (public, protected, or private)

• always use @param for each parameter

• always use @return for non-void return types

• comments should be useful

Page 79: Advanced Object-oriented Programming Lecture 11cgi.csc.liv.ac.uk/~akridel/COMP213-Fall2016/Lecture...private Vector<Car> myCars;...} which directs the compiler to look at all

Useful Comments

The point of documenting classes and their members is to help other programmers use your class.(This includes yourself: if there are any private methods in the class, they can only be used inside the class itself; sometimes it can be hard to understand ‘old’ code, even if it’s only a couple of days old.)

Comments should be clear, and say:

• what the thing is for

• how to use the thing

Page 80: Advanced Object-oriented Programming Lecture 11cgi.csc.liv.ac.uk/~akridel/COMP213-Fall2016/Lecture...private Vector<Car> myCars;...} which directs the compiler to look at all

Useful Comments

The point of documenting classes and their members is to help other programmers use your class.(This includes yourself: if there are any private methods in the class, they can only be used inside the class itself; sometimes it can be hard to understand ‘old’ code, even if it’s only a couple of days old.)

Comments should be clear, and say:

• what the thing is for

• how to use the thing

Page 81: Advanced Object-oriented Programming Lecture 11cgi.csc.liv.ac.uk/~akridel/COMP213-Fall2016/Lecture...private Vector<Car> myCars;...} which directs the compiler to look at all

Useful Comments

The point of documenting classes and their members is to help other programmers use your class.(This includes yourself: if there are any private methods in the class, they can only be used inside the class itself; sometimes it can be hard to understand ‘old’ code, even if it’s only a couple of days old.)

Comments should be clear, and say:

• what the thing is for

• how to use the thing

Page 82: Advanced Object-oriented Programming Lecture 11cgi.csc.liv.ac.uk/~akridel/COMP213-Fall2016/Lecture...private Vector<Car> myCars;...} which directs the compiler to look at all

A Bad Comment

This gives no new information; the type of the method is already given in the API page:

/**

*This method takes a String as argument

*and returns a boolean value.

*/

public boolean isIn(String name) { ... }

boolean isIn(String name)

This method takes a String as argument ...

Page 83: Advanced Object-oriented Programming Lecture 11cgi.csc.liv.ac.uk/~akridel/COMP213-Fall2016/Lecture...private Vector<Car> myCars;...} which directs the compiler to look at all

A Bad Comment

/**

*This method takes a String as argument

*and returns a boolean value.

*/

public boolean isIn(String name) { ... }

This gives no new information; the type of the method is already given in the API page:

boolean isIn(String name)

This method takes a String as argument ...

Page 84: Advanced Object-oriented Programming Lecture 11cgi.csc.liv.ac.uk/~akridel/COMP213-Fall2016/Lecture...private Vector<Car> myCars;...} which directs the compiler to look at all

A Bad Comment

This gives no new information; the type of the method is already given in the API page:

/**

*This method takes a String as argument

*and returns a boolean value.

*/

public boolean isIn(String name) { ... }

boolean isIn(String name)

This method takes a String as argument ...

Page 85: Advanced Object-oriented Programming Lecture 11cgi.csc.liv.ac.uk/~akridel/COMP213-Fall2016/Lecture...private Vector<Car> myCars;...} which directs the compiler to look at all

A Bad Comment

Far too detailed…

and the details aren’t relevant!

/**

*This method computes the length of a list

*by looping through the nodes, traversing

*through the nodes and incrementing the len

*variable on each iteration.

*/

public int length() { ... }

Page 86: Advanced Object-oriented Programming Lecture 11cgi.csc.liv.ac.uk/~akridel/COMP213-Fall2016/Lecture...private Vector<Car> myCars;...} which directs the compiler to look at all

A Bad Comment

Far too detailed…

and the details aren’t relevant!

/**

*This method computes the length of a list

*by looping through the nodes, traversing

*through the nodes and incrementing the len

*variable on each iteration.

*/

public int length() { ... }

Page 87: Advanced Object-oriented Programming Lecture 11cgi.csc.liv.ac.uk/~akridel/COMP213-Fall2016/Lecture...private Vector<Car> myCars;...} which directs the compiler to look at all

A Bad Comment

Far too detailed…

and the details aren’t relevant!

/**

*This method computes the length of a list

*by looping through the nodes, traversing

*through the nodes and incrementing the len

*variable on each iteration.

*/

public int length() { ... }

Page 88: Advanced Object-oriented Programming Lecture 11cgi.csc.liv.ac.uk/~akridel/COMP213-Fall2016/Lecture...private Vector<Car> myCars;...} which directs the compiler to look at all

A Bad Comment

/**

*Returns the number of {@link Car Cars}

*in the list.

*/

public int length() { ... }

It should use the @return tag.

Page 89: Advanced Object-oriented Programming Lecture 11cgi.csc.liv.ac.uk/~akridel/COMP213-Fall2016/Lecture...private Vector<Car> myCars;...} which directs the compiler to look at all

A Bad Comment

It should use the @return tag.

/**

*Returns the number of {@link Car Cars}

*in the list.

*/

public int length() { ... }

Page 90: Advanced Object-oriented Programming Lecture 11cgi.csc.liv.ac.uk/~akridel/COMP213-Fall2016/Lecture...private Vector<Car> myCars;...} which directs the compiler to look at all

A Bad Comment

/**

* Adds the given element to the queue, wrapping

* around the underlying array, if needed.

*/

public void enqueue(Object element) {

...

rear = (rear+1)%queue.length;

queue[rear] = element;

...

}

Page 91: Advanced Object-oriented Programming Lecture 11cgi.csc.liv.ac.uk/~akridel/COMP213-Fall2016/Lecture...private Vector<Car> myCars;...} which directs the compiler to look at all

A Bad Comment

Too detailed: the user doesn’t need to know the implementation details; better to say ‘the number of BandCards in the list.

/**

* Adds the given element to the queue, wrapping

* around the underlying array, if needed.

*/

public void enqueue(Object element) {

...

rear = (rear+1)%queue.length;

queue[rear] = element;

...

}

Page 92: Advanced Object-oriented Programming Lecture 11cgi.csc.liv.ac.uk/~akridel/COMP213-Fall2016/Lecture...private Vector<Car> myCars;...} which directs the compiler to look at all

More Information

For more information on javadoc:

• The Java documentation(see the link from the module web-page)

• The examples on the old module web-pages(see the link to “Past Lectures Material” on the module web-page)

Page 93: Advanced Object-oriented Programming Lecture 11cgi.csc.liv.ac.uk/~akridel/COMP213-Fall2016/Lecture...private Vector<Car> myCars;...} which directs the compiler to look at all

Summary

• import

• javadoc

• comments

• Next: Java Collections