The Java Course provides a general introduction to programming in Java. It is based on A.B. Downey's book, How to Think Like a Computer Scientist. Click here for details.


Packages

The built-in Java classes are divided into a number of packages, including java.lang, which contains almost all of the classes we have seen so far, and java.awt, which contains classes that pertain to the Java Abstract Window Toolkit (AWT), which contains classes for windows, buttons, graphics, etc.

In order to use a package, you have to import it, which is why the program in Section 4.8 starts with import java.awt.*. The * indicates that we want to import all the classes in the AWT package. If you want, you can name the classes you want to import explicitly, but there is no great advantage. The classes in java.lang are imported automatically, which is why most of our programs haven't required an import statement.

All import statements appear at the beginning of the program, outside the class definition.



Last Update: 2011-01-24