Page 791 - Introduction to Programming with Java: A Problem Solving Approach
P. 791
Figure A4.2a A typical programmer-defined package structure
Appendix 4 Packages 757
IPWJ
. . . IPWJ.chapter13 . . .
IPWJ.chapter13.things IPWJ.chapter13.creatures
IPWJ.chapter13.labor
.. .
IPWJ
chapter13
Apago PDF Enhancer
labor
things
creatures
Figure A4.2b Directory structure that corresponds to package structure in Figure A4.2a
done. If you want source code and bytecode to be in separate directories, you’ll probably decide to write your source code in a separate source-code directory and then move the generated bytecode to the directory that matches its specified package. (Later, we’ll show how you can ask the compiler to move it for you.)
For the Java compiler to import a class that’s in a separate package, that class must be accessible through a class path that has been established previously in your operating system’s environment. There may be more than one class path. On a Windows machine, you can see all registered CLASSPATH’s by opening a command prompt window and entering the command, set. (In UNIX, the command is env.) After CLASSPATH, you’ll see a list of several class path specifications, with semicolons between them. (In UNIX the separators are colons.) Typically, the first class path in the list is a single dot. That means “current di- rectory.” Suppose myJava is a root directory in the C: drive, and suppose the IPWJ directory shown in Figure A4.2b above is in the myJava directory. To make classes in the IPWJ package hierarchy accessible to the Java compiler, your computer’s CLASSPATH must include the following path:
C:/myJava.
Thus, the full pathname of the Car.class file in the things directory shown in Figure A4.2b would be: C:/myJava/IPWJ/chapter13/things/Car.class