Java: Summary: Packages

There are over 200 packages and sub-packages in Java. You won't use most of them, so the table below lists only packages most students need for their programs. For the first two or three programming classes the following are often sufficient.

import java.util.*;      // Scanner and the data structures classes.
import java.awt.*;       // GUI and simple graphics.
import java.awt.event.*; // GUI listeners.
import javax.swing.*;    // GUI components, JOptionPane, ...
import*;        // File IO.

The placement of classes into packages is generally quite good, but you will occasionally get a surprise. When you type a class in NetBeans which hasn't been imported, you can right-click the symbol and select "Fix imports" to get the correct imports. It's a very nice feature.

Basics - This package is automatically imported
java.lang.*Automatically imported. Has String, System, Math, Double, Integer, Thread, ...
General utilities
java.util.*Contains very useful classes and interfaces. Almost all my programs import this package.
  • Data structures: Arrays, Collections, List, ArrayList, Map, HashMap, Iterator, Comparable, ...
  • IO: Scanner.
  • Time: Date, Calendar, GregorianCalendar.
java.util.regex.*Required for regular expressions.
java.math.* BigInteger and BigDecimal are found here.
File and network IO* Used for the many IO classes, but especially file IO.*Used for network IO. Contains the useful URL class.
Graphical User Interface
java.awt.* Many basic GUI and graphics classes: Graphics, Graphics2D, Color, layouts, ...
java.awt.event* Listener classes, eg ActionListener
java.awt.geom.* Many useful classes for drawing shapes.
javax.swing.* Most of the GUI containers and components are here.
javax.swing.event.*Some events are in this package, but often java.awt.event.* is all you need.
javax.swing.filechooser.*JFileChooser is in javax.swing, but FileFilter (if needed) is here.