Possible Duplicate:
Why is using a wild card with a Java import statement bad?
Right now I’m using a lot of java.util packages:
import java.util.Calendar;
import java.util.logging.ConsoleHandler;
import java.util.logging.Level;
import java.util.logging.LogRecord;
import java.util.logging.Logger;
Would it be more efficient to just do:
import java.util.*;
What are the performance/efficiency costs of this? Does it even matter? Please excuse my ignorance on the subject.
Also, this is just a shot in the dark but is there a way to import packages for a whole project? So that I don’t need to re-import them on a per-class basis? This is my first big Java project so I’m still learning the more enterprise side of things.
Also, you can’t include a whole tree. You can cut down your import list to
but
does not import anything in the
java.util.loggingpackage. For the Java compiler, there are no subpackages. Also not for the VM (apart from some classloaders which use the package structure as a file directory structure).Also, it seems you are mixing the concepts package and class/interface (or type).
java.utilandjava.util.loggingare packages, whilejava.util.Calendar,java.util.logging.Leveletc. are classes.A type (class/interface) is something you can use in your programm, while a package is mainly only a name space in which to put classes and interfaces. (Additionally, it has some consequences on visibility.)
You can import either single types (by specifying their name) or all types directly in a package (by specifying the package and
.*). (You can also import all nested types in a type by using a wildcard, or import all static methods/fields of a class withimport static <class>.*, just for completeness).Importing is never recursive, wildcard importing is only for one level. (And you also can’t use
import java.util.*.*to import the logging classes.)