my dog learned polymorphism
The moose likes Java in General and the fly likes imports statement. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "imports statement." Watch "imports statement." New topic

imports statement.

ManavChowdary Chalasani

Joined: Dec 19, 2003
Posts: 2
what is the difference between import package.* and import package.class in java? Performance wise? I know the basic difference , like using "*" imports all the classes and using the "package.class" only a particular class in the package. I want more in detail.
Ernest Friedman-Hill
author and iconoclast

Joined: Jul 08, 2003
Posts: 24199

Here is the [url=http://""]JavaRanch FAQ entry on this topic.[/url] This question is asked very often.

Short answer: performance-wise, there's no detectable difference whatsoever, either at runtime or compile time. Which you use is a matter of taste; most experienced practitioners recommend the individual class imports.

[Jess in Action][AskingGoodQuestions]
Srinivas Kalvala
Ranch Hand

Joined: Oct 20, 2005
Posts: 257


The individual import statements increases the readability of the program and it will be very clear which classes have been used.

In terms of performance there is no significance difference and more over .* will not include all classes, but will search for whole package to find the correct class to load.
I agree. Here's the link:
subject: imports statement.
It's not a secret anymore!