Packages

Using packages, as mentioned previously, is a way of organizing groups of classes. A package contains any number of classes that are related in purpose, in scope, or by inheritance.

If your programs are small and use a limited number of classes, you might find that you don't need to explore packages at all. But the more Java programming you create, the more classes you'll find you have. And although those classes might be individually well designed, reusable, encapsulated, and with specific interfaces to other classes, you might find the need for a bigger organizational entity that enables you to group your packages.

Packages are useful for several broad reasons:

  • Packages enable you to organize your classes into units. Just as you have ...

Get Sams Teach Yourself Java 2 in 21 Days, Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.