java.awt.event
java
and javax
are reserved by Sun (now Oracle)java.util.Date
from a Date
class of our own by giving the full name like that.net.grelf.astro
(you need a domain name - it gives you something which is guaranteed to be different from anyone else).
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 ();