|
Vector
class in the java.util package differs from
the Vector class in a package called
NL.uva.wins.datastructures.java.awt class you can use short names like Button
and TextField instead of the full names
java.awt.Button and java.awt.TextField, respectively.
java.lang,
java.applet, and java.awt.
The first one is so basic that the Java compiler and the Java interpreter
import it
automatically so that all classes inside are available under their abbreviated
names (e.g. you can immediately use String instead of
java.lang.String). The publicly accessible classes of the other
packages must be imported explicitly unless you are happy to use full names.
There are three ways to import a public class :
imports the classimport java.awt.Graphics;
Graphics from the java.awt package.
After this statement, the signature of the paint method
of an applet can be defined by
public void paint(Graphics g){ }
instead of by
public void paint(java.awt.Graphics g){ }
java.awt package, use the import
statement with the asterisk (*) wildcard character.
Importing all classes of a package may slow down compilation, but has no other effects on efficiency.import java.awt.*;
allows you to use the nameimport java.awt;
image.ColorModel instead of
java.awt.image.ColorModel.
Blinkable and Draggable that classes implement
if they can be blinking on the screen or if they can be dragged with the mouse
by the user.
Assuming that you wish to make your collection of classes and interfaces
available to other users in bundled form, say in the package called
shapes, then
A skeleton with Java source code:package shapes;
- Rectangle.java
package shapes; public class Rectangle { ... }
.class)
must be placed in one directory that is also called shapes.
It is convenient to keep the source files there as well.shapes directory must be present in CLASSPATH,
which is a list of names of directories in which you keep the
compiled Java files.
shapes
package and the java.awt package, then he or she can distinguish
between the two Rectangle classes present in both packages
by using the larger names shapes.Rectangle and
awt.Rectangle, respectively.geometry.shapes
and geometry.constructions, that contains classes and interfaces
for describing geometrical objects and for manipulating geometrical objects,
respectively. Each component of the package name represents a
directory on the file system. In our example, the directory
geometry would have two subdirectories, shapes
and constructions, respectively.
wins.uva.nl and suppose that your organization divides the
package name space internally in such a way that your part is called
classes, then your packages would have full names like
NL.uva.wins.classes.packageName. For example, the following
name fits in this scheme:
CLASSPATHCLASSPATH is a list of names of directories separated by
colons (semicolons) on a Unix System (Windows system).
When the Java compiler or the Java interpreter
get a classname, they search each directory in the CLASSPATH
until they find the class they are looking for.
On a Unix system you might use the following specification of the
CLASSPATH environment variable:
On a Windows or DOS system, you might use the following specification of thesetenv CLASSPATH .:~/classes:/usr/local/java/lib
CLASSPATH environment variable:
SET CLASSPATH=C:\JAVA\LIB;.;C:\CLASSES
java/lib, you will not find individual subdirectories
with names like awt and util, but instead
a single ZIP file, classes.zip. If you look inside the archive
with a ZIP viewer, you will see the paths and file names that
you expect. If you like, you can also make a ZIP-archive of
your packages, in a file called classes.zip, which is
located in the CLASSPATH.