Using Packages

You've been using packages all along in this book. Every time you use the import command, and every time you refer to a class by its full package name (java.awt.Color, for example), you use packages.

To use a class contained in a package, you can use one of three mechanisms:

  • If the class you want to use is in the package java.lang (for example, System or Date), you can simply use the class name to refer to that class. The java.lang classes are automatically available to you in all your programs.

  • If the class you want to use is in some other package, you can refer to that class by its full name, including any package names (for example, java.awt.Font).

  • For classes that you use frequently from other packages, you can import individual ...

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.