Previous | Next | Trail Map | Writing Java Programs | Objects, Classes, and Interfaces


Creating and Using Packages

Typically, to make objects easier to find and use, and to avoid naming conflicts, programmers bundle groups of related objects into class libraries. In Java, a class library is called a package. Packages can also contain interface definitions.

Roll Your Own Packages

You can easily create your own packages and put any number of class and interface definitions in them.

Using the Classes and Interfaces from a Package

To use the classes and interfaces defined in one package from within another package, you need to import the package. The classes and interfaces that you import must be declared public.

The Java Packages

Several packages of reusable classes are shipped as part of the Java development environment. Indeed, you have already encountered several classes that are members of these packages: String, System, and Date, to name a few.

The classes and interfaces contained in the Java packages implement various functions ranging from networking and security to graphical user interface elements. Before you start writing your own classes, interfaces, and packages make sure that one of classes or interfaces in these packages won't do the job for you.


Previous | Next | Trail Map | Writing Java Programs | Objects, Classes, and Interfaces