JamesMadisonUniversity

Computer Science Department


CS 139-239 Lab: Packages, jars, and javadocs


Objectives:

At the conclusion of this lab, students will make packages in java, create jar files, and create appropriate javadocs documentation.

Background:

This lab looks at a variety of java tools.

New Terms:

  • jar - java archive
  • package (while not a new term, you will use it in a new way)
  • javadocs (while not a new term, you will learn to generate these for your own programs)

Materials:

Weight.java
Length.java

Driver.java

Any application that you have previously written and documented
Acknowledgment Author: Nancy Harris

1 General Instructions:

Carry out each of the activities below.  As you finish each section, demonstrate your result for the lab instructors.  If you do not finish in lab today, you may finish during office hours or during the evening lab time.  The TAs will have the information to check you off.  The questions are thought questions to help you explore this assignment.

2 Java Packages:

  1. Download the two java files, Weight and Length into a directory on your desktop called size.
  2. Add code to each of the two .java files to put them into the size package.
  3. Compile them correcting any errors.
  4. Create a second directory on the desktop named anything you want.
  5. Download the driver program that will build an object of each of the two classes and print the values. Do not do any imports yet.
  6. Compile your Driver. What error did you find?
  7. Add the necessary import statement(s).
  8. Compile your Driver. What error did you find?
  9. The problem is that the directory called size is not found in the classpath to your package.
  10. Open a terminal window.
  11. Type echo $CLASSPATH and press <Enter>.
  12. This monitor displays the value of the CLASSPATH system variable. If size were directly underneath any directory in this CLASSPATH, the import would find it.
  13. What is the absolute pathname to your directory called size? This will be the absolute pathname (starting with the root) of the directory in which size resides.
  14. In the terminal window, issue the command, export CLASSPATH=$CLASSPATH: followed directly (with no spaces) by the absolute pathname to your directory. Note, there are no spaces between CLASSPATH and the = symbol and between the = symbol and the $.
  15. Press enter and then issue the command echo $CLASSPATH. What is output by the command? Or in other words, do you see the new path.
  16. Change to the directory in which your driver is located. Compile your driver in the terminal window. What happens?
  17. NOTE:  You can alter the classpath for the session in JGrasp as well.  Settings/Path-Classpath.
  18. Show your working application to the lab instructors.

3 jar files

  1. Create a third directory and place all of your source files into it. Remove the package statements from the two programs in size and compile all of the files.
  2. Create a jar file using Jgrasp or using the command line (see the tutorial). Test your work by using the terminal window to run the java -jar command.
  3. To use the Terminal window to create your jar file, you need a manifest file. Using any test editor, create a manifest file which will point to the driver class. Note: you do not need to call your driver, Driver.
  4. Create a different jar file using the terminal window. Refer to the class notes from Tuesday to create the file.
  5. Test your work using the java -jar jarfilename command, where jarfilename is the name of the jarfile..
  6. Did it work?
  7. Show your working jar program to the lab instructors.

4 javadocs - Java documentation

  1. Choose one of your applications for which you have written javadoc style documentation.  PA3 would be a good choice.
  2. Go to the terminal window.  Navigate to the directory containing the application.
  3. Use the command to produce javadocs:  javadoc filename, where filename is the name of one of your application programs.  Make sure that the program you choose includes both @param and @return tags.
  4. The javadoc command should produce a set of documentation in the current directory.  Open the index.html file in your internet browser.  Look at the javadoc that is produced and your original source file.  Note the correspondence of each of the descriptions of methods and the class itself with the original source code.  Make any corrections to the original source file to make appropriate documentation.  Reproduce the javadocs.
  5. Now document your entire application.  Use the command: javadoc *.java.  This variant will document all of the files in the current working directory.  Open the index.html file in your internet browser.
  6. Show your completed documentation to the lab instructors.
  7. You can also produce javadocs through JGrasp.  The open book produces javadoc documentation.  The command line command provides more control over how you want to produce the documents.  In Windows type javadocs without any parameters to see a list of all the different parameters that can affect what you see in the javadocs.  In Linux type man javadocs to see the manual entry for the javadocs command.


Updated 03/10/08 (nlh)