Take, for example, the Java-supplied package "java.awt". The first part of that package name "java" represents the organization that developed the package (Sun's Java group). The second part of the package name "awt" stands for the contents of the package, in this case the Abstract Window Toolkit. The "java.awt" package resides in a directory structure which reflects the package name:
<path>/classes/java/awt/*.classAll classes contained in the java.awt package reside in the above directory. For this tutorial, we will be working with three packages. The organization name "v2k" in the Java Package names stands for Hubble Space Telescope Vision 2000 GUI group. The three Java Package names are given below:
Directory Package ========================= ======= /GUI/java/classes/v2k/awt v2k.awt // Abstract Window Toolkit /GUI/java/classes/v2k/ddo v2k.ddo // Realtime Data Driven Objects /GUI/java/classes/v2k/p3d v2k.p3d // Three DimensionalAll classes for the Package v2k.awt reside in the above directories. The Java source for these classes reside in the following directories:
Source Directory ========================= /GUI/java/src/v2k/awt // Abstract Window Toolkit /GUI/java/src/v2k/ddo // Realtime Data Driven Objects /GUI/java/src/v2k/p3d // Three Dimensional
import v2k.awt.RGBColorSelector; // imports the RGBColorSelector class only or import v2k.awt.*; // imports all classes in awt packageIf you use "import v2k.awt.*" , ALL classes in the awt package will be imported. We recommend importing only the classes you need. Bringing in an entire Package does not alter the size of the class file, but does lengthen the compile time. Wildcarding also increases the chances of namespace conflict as new classes are added to the package over time.
% setenv CLASSPATH ".:/GUI/java/classes"You can add as many directories as you like to the path (separated by ":"), but remember that order is important. The directories will be searched in the left-to-right order. In the above example, your current directory would be searched first, then the "/GUI/java/classes" directory. If the same class exists in both directories, the class in the current directory will be used.
Note: The window in which you invoke Netscape MUST NOT have the CLASSPATH set! The use of CLASSPATH will conflict with Netscape accessing the Java classes in its own installation directory.
% unsetenv CLASSPATH % netscape
MyClass.java: package v2k.awt;
UNIX example: % mv MyClass.java /GUI/java/src/v2k/awt/.
% javac -d /GUI/java/classes /GUI/java/src/v2k/awt/MyClass.javaThe -d option tells the compiler to place the MyClass.class file in the directory: /GUI/java/classes/v2k/awt.
% javac -d /GUI/java/classes -classpath .:/GUI/java/classes:/usr/java/classes /GUI/java/src/v2k/awt/MyClass.javaThe -d option tells the compiler to place the MyClass.class file in the directory: /GUI/java/classes/v2k/awt.
The -classpath option tells the compiler to search for classes being imported by MyClass.java
in the path: .:/GUI/java/classes/.
If you have compiler errors, see javac Compiler Errors Relating to Java Packages.
The class "MyClass" is now part of the Java Package v2k.awt. You can now import this class using
the statement import v2k.awt.MyClass.
UNIX example: % cd /GUI/java/classes/v2k // change directory under the // main organization directory % mkdir NEW // create a new directory with // new Package name
UNIX example: % cd /GUI/java/src/v2k // change directory under the // main organization directory % mkdir NEW // create a new directory with // new Package name
UNIX example: % cp *.java /GUI/java/src/v2k/NEW/.
package v2k.NEW;
% javac -d /GUI/java/classes /GUI/java/src/v2k/NEW/*.javaThe -d option tells the compiler to place the MyClass.class file in the directory: /GUI/java/classes/v2k/NEW.
% javac -d /GUI/java/classes -classpath .:/GUI/java/classes:/usr/java/classes /GUI/java/src/v2k/NEW/*.javaThe -d option tells the compiler to place the MyClass.class file in the directory: /GUI/java/classes/v2k/NEW.
The -classpath option tells the compiler to search for imported classes
in the path: .:/GUI/java/classes/.
If you have compiler errors, see javac Compiler Errors Relating to Java Packages.
The Java Package v2k.NEW has been created. You can now import classes from this package using the statement import v2k.NEW.*.
test/b/Dummy.java:30: No constructor matching RGBColorSelector(test.b.Dummy) found in class v2k.NEW.RGBColorSelector. cs = new RGBColorSelector( this ); ^ 1 error
UNIX example: % cd /GUI/java/ // already at this level are directories: // GUI/java/classes // GUI/java/src % mkdir doc // create a new directory for documentation
UNIX example: % cd /GUI/java/src // source for NEW package is in /GUI/java/src/NEW/*.javaThen type the following javadoc command. The -d option tells the compiler to place the .html documentation files in the directory: /GUI/java/doc):
UNIX example: % javadoc -d /GUI/java/doc v2k.NEW Loading source files for v2k.NEW Generating packages.html generating documentation for interface v2k.NEW.Colorable generating documentation for interface v2k.NEW.SliderClient generating documentation for class v2k.NEW.ColorSlider . . . Generating index Sorting 76 items . . . done Generating tree
- -author
- -authors
- Use either of these options to display author information in the generated documentation. To see documentation which resulted from using the -author javadoc option, go to v2k.awt API documentation. Multiple
@author
tags will generate a comma-separated list.An example of a comment containing a single @author tag: /** * @author Joe Smith **/ An example of a comment containing multiple @author tags: /** * @author Joe Smith * @author Bill Smith * @author Gene Smith **/
This option generates command line output demonstrating the parsing of the input java source file by javadoc. This option was probably used by the developer of the javadoc tool and will not be of much use to others.
Use this option to understand dependencies on other Java Packages when generating documentation.
UNIX example: % javadoc -d directory_name -version -depend v2k.p3d v2k.awt v2k.ddoThis allows the dependencies between Java Packages to be built in to the generated API documentation for more than one related Package at a time (ex. provides a hyperlink to a class in Package v2k.awt which is related to a class in package v2k.ddo).It also provides a merged index (of all fields and methods) and class heirarchy of all dependent Packages. In addition, this option provides a main package index (in packages.html) with hyperlinks to all dependent packages.
This option allows user to execute the javadoc command without producing an index file.
This option allows user to execute the javadoc command without producing an class heirarchy.
This option allows user to execute the javadoc command without producing any output.
Specifies the path javadoc uses to look up the .java files. Directories are separated by colons, for example: This option allows user to execute the javadoc command without producing an class heirarchy..:/GUI/java/src/
Use this option to display source code version information in the generated documentation.UNIX example: % javadoc -d directory_name -version v2k.p3d v2k.awt v2k.ddo
UNIX example: % cd /GUI/java/classes/v2k/awt
UNIX example: % javap v2k.awt.ColorSlider Compiled from ColorSlider.java public class v2k.awt.ColorSlider extends java.awt.Canvas { protected v2k.awt.SliderClient client; protected double min; protected double max; protected double value;
UNIX example: % cd /home/jsmith/javaclasses
UNIX example: % javap MyButton Compiled from MyButton.java public class MyButton extends java.awt.Button { protected double min; protected double max; protected double value;
Last updated February 22, 1996 by Mary Smiley:
msmiley@v2mc01.gsfc.nasa.gov