This week's book giveaway is in the Design forum.
We're giving away four copies of Building Microservices and have Sam Newman on-line!
See this thread for details.
The moose likes Performance and the fly likes Import package.* Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Building Microservices this week in the Design forum!
JavaRanch » Java Forums » Java » Performance
Bookmark "Import package.*" Watch "Import package.*" New topic

Import package.*

James Inge

Joined: Dec 04, 2000
Posts: 12
I was wondering if there are any performance or class 'bloat' issues associated with using the import of package.* versus including only the classes which you are using?
Peter Chase
Ranch Hand

Joined: Oct 30, 2001
Posts: 1970
I think that importing more classes than you need has no effect on run-time performance.
The import statement affects which classes should be made available by class name only, so that they may be referenced in the source without their package prefix, during compilation. However, this does not affect which files get loaded, or how much memory gets used when running.
I do not know whether the compiler goes slower, faster or about the same speed if import packagexxx.* is used, compared to individual imports.
However, for clarity and to avoid namespace clashes (class with same name in two packages -> confusion), I think that developers should always explicitly import individual classes, even if it makes for a rather long prolog to the source file.

Betty Rubble? Well, I would go with Betty... but I'd be thinking of Wilma.
I’ve looked at a lot of different solutions, and in my humble opinion Aspose is the way to go. Here’s the link:
subject: Import package.*
It's not a secret anymore!