Possible Duplicate:
Why is using a wild card with a Java import statement bad?
Ex. 1
import javax.swing.*
JFrame f = new JFrame()
Ex. 2
import javax.swing.JFrame
JFrame f = new JFrame()
Is there any efficiency gain (even the slightest and minimal) in adapting 2) instead of 1) ? How does java does the referencing of packages internally?
The first time the compiler comes across the word JFrame, I presume that it should search for JFrame in complete swing.* package in case of 1)..Else if in case 2), it might probably get hold of the class directly by some indexing or may be key value hashing? So why is this not considered an efficiency gain even if it is tiny? (Please correct me if my presumptions about the internals are wrong)
EDIT :
Sorry for the duplicate.. Answer at Why is using a wild card with a Java import statement bad?
There is no runtime penalty for using import javax.swing.* and import javax.swing.JFrame in Java. The only different is in compile time, the import package.* will search for whole package to find the correct class' information.
The Single-Type-Import (e.g., import javax.swing.JFrame) increases the readability of the program and it will be very clear which classes have been used.
The Type-Import-on-Demand (e.g. import javax.swing.*) causes the simple names of all public types declared in the package javax.swing to be available within the class and interface declarations of the compilation unit.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With