Java Reference
In-Depth Information
For example, if Bertha Walters has an e-mail address walters@cs.sjsu.edu , then she
can use a package name edu.sjsu.cs.walters for her own classes.
Some instructors will want you to place each of your assignments into a separate
package, such as homework1 , homework2 , and so on. The reason is again to
avoid name collision. You can have two classes, homework1.Bank and
homework2.Bank , with slightly different properties.
8.9.4 How Classes are Located
If the Java compiler is properly set up on your system, and you use only the
standard classes, you ordinarily need not worry about the location of class files and
can safely skip this section. If you want to add your own packages, however, or if
the compiler cannot locate a particular class or package, you need to understand the
mechanism.
A package is located in a subdirectory that matches the package name. The parts of
the name between periods represent successively nested directories. For example,
the package com.horstmann.bigjava would be placed in a subdirectory
com/horstmann/bigjava . If the package is to be used only in conjunction
with a single program, then you can place the subdirectory inside the directory
holding that program's files. For example, if you do your homework assignments in
a base directory /home/walters , then you can place the class files for the
com.horstmann.bigjava package into the directory
/home/walters/com/horstmann/bigjava , as shown in Figure 5 . (Here,
we are using UNIX-style file names. Under Windows, you might use
c:\home\walters\com\horstmann\bigjava .)
The path of a class file must match its package name.
However, if you want to place your programs into many different directories, such
as /home/walters/hw1, /home/walters/hw2, . . . , then you
probably don't want to have lots of identical subdirectories
/home/walters/hw1/com/horstmann/bigjava ,
/home/walters/hw2/com/horstmann/bigjava , and so on. In that case,
you want to make a single directory with a name such as
/home/walters/lib/com/horstmann/bigjava , place all class files for
Search WWH ::




Custom Search