Java Reference
In-Depth Information
Chapter 11
• Provide an understanding of packages in Java.
• Learn how to set variable CLASSPATH.
People invent classifications and categories in order to make things manageable.
In that old game of twenty questions, things of the world are divided into three
categories: animal, mineral, or vegetable. Animals are further categorized into
different kinds, as are minerals and vegetables. And, books in a library are clas-
sified using the Dewey Decimal system. A hierarchy of categories goes as deep
as need be to provide structure and make things manageable.
Because there are hundreds of Java classes to deal with, Java provides a
mechanism for classifying them: the package.
Using packages
Placing a class in a package
A package is a collection of classes that have been grouped together and
reside in the same folder, or directory, on a computer.
Suppose we have a class OneClass in a file . To specify that
this class belongs to a package named package1 , place a package statement on
the first line of file :
package package1;
public class OneClass {
It is your obligation to see to it that file is placed in direc-
Search WWH ::

Custom Search