Next page | Contents page |

Packages

Using packaged classes in your own classes

	import java.util.*;
	import java.io.*;

* means all classes in the package

Putting such statements at the start of a Java file, before the class declaration, gives access to the public classes, data & methods contained in the named packages (but not sub-packages: importing java.awt.* does not import classes in java.awt.event).

The packages in the example above do contain useful fundamental classes. Eg, java.io contains File which we will be using soon.

It is worth considering adopting this standard: name every imported class, do not use the * as above. Eg, import java.util.Date;

Compiler only loads code for classes required during execution, not necessarily every class named in the import statements.

It is not necessary to import java.lang.* - the classes in this fundamental package are always assumed to be imported.

You can also use package names without importing. Eg,

	java.util.Date d = new java.util.Date (); 
Next page | Contents page |