Creating Your Own Packages

Creating a package for some of your classes in Java is not much more complicated than creating a class. You must follow three basic steps, as outlined next.

Picking a Package Name

The first step is to decide on a name. The name you choose for your package depends on how you will be using those classes. Perhaps you will name your package after you or perhaps after the part of the Java system you're working on (such as graphics or messaging). If you intend to distribute your package to the Net at large or as part of a commercial product, you should use a package name that uniquely identifies the author.

A convention for naming packages recommended by Sun is to use your Internet domain name with the elements reversed. If ...

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.