This tutorial covers:
The Java Development Kit (JDK) comes with a tool called JavaDoc. This tool will generate documentation for Java source code with comments written in accordance with the Java documentation style. The following are links to useful WEB pages on JavaDoc.
Create a directory ~/comp212/tutorials/02
for this lab and copy the file ~comp212/tutorials/02/*.java
and the whole subdirectory ~comp212/tutorials/02/images
into the new
directory. There should be 3 java source files: FunList.java, Empty.java, and
Cons.java
. images
contains gif
files used by
JavaDoc for display purpose.
Exercises:
FunList.java, Cons.java,
and Empty.java
, a la JavaDoc. For each class, use the @author tag and the
@since tag. For each function method, use the @return tag. For methods and
constructors that have parameters, use the @param tag.javadoc
*.java
. Appropriate html files will be generated. What are the
generated html files ? Use a browser to view them. Are the private fields and
methods displayed?javadoc -private *.java
. Can you see the
difference?javadoc
. You should see a brief description of
the usage of javadoc. Take a brief look at the explanation of the flags.Class Empty represents the "empty list". Conceptually, there is only one empty list in this world. The concept is akin to that of the empty set: there is only one empty set. How can we ensure that only one instance of Empty can be created throughout the life of a program? There is away to design a class to ensure such uniqueness property. It is called the Singleton Design Pattern. The following UML diagram describe the pattern.
Note that the field _instance
and the method UniqueInstance ()
are of class scope (i.e. static).
Exercises:
Cons(int i)
to the class Cons
that takes a single int
as an argument and
creates a FunList
containing that element and the empty list as its tail.
This constructor should use the static method Empty.UniqueInstance
().
Since the constructor for class Empty is private, there is no way for Cons (int i) to call
new Empty()
.
FunList append(FunList other)
to the class FunList
(and all of its variants) that returns a FunList
containing the elements of this
followed by elements of other
.
The new method must not modify this
and should use the static method Empty.UniqueInstance
().
main
to test your new singleton
constructor and append
method. FunList insertInOrder(int i)
to the class FunList
(and all of its variants) that satifies the following
specification.
Pre-condition: This FunList is sorted in non-descending order.
Post-conditon: A FunList
containing the elements of this
FunList
and i inserted in the approriate order is returned.
The new method must not modify this
FunList.
main
to test your new insertInOrder
method. FunList sort()
to your class FunList
class (and
all of its variants) that returns a list in sorted (non-descending) order containing the
same elements as this
. Hint: Use insertInOrder ().main
to test your new sort
method.