Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

import java.util.* Vs import.util.Vector

Status
Not open for further replies.

rajarajan

Programmer
Jul 16, 2001
33
0
0
IN
Is there any difference between
import java.util.*;
and
import java.util.Vector;
import java.util.Properties;
I need only these two classes.
Does importing all the classes cause any overhead.
Actually what happens while importing a class or package.
Can anyone explain in detail or provide some good link.

Regards,
Rajan
 
no, there is no difference between the two. the import statement is required to during compilation so the compiler can varify your code against the external packages you wish to use. the size of the resultant class file won't be any different after compilation
 
As LittleWing said the resulting class file will be the same.

The main reason to explicitly name the classes being imported is so it is easy to identify which other classes are being used in your class. If I see java.util.Collection being imported then I know you are using a Collection somewhere. If I see java.util.* being imported then I really have no idea how many classes from that library are being used or which ones without diligently looking at the code.

The only other the reason is to avoid name collusions. An example is java.util.Date and java.sql.Date. If you import both java.util.* and java.sql.* then you must use the Fully Qualified Class name to refer to either class because the compiler will not know which Date object you are referring to. However if you only import the classes from java.util that you need then you can refer to java.sql.Date simply as Date.

Hope this makes sense.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top