Is importing only the necessary files from package advantageos???
jyothi lakshmi
Greenhorn
Joined: Apr 10, 2001
Posts: 1
posted
0
If I include only specific(required) files from a package have any advantage over importing all the files from the package? Thanx in advance. rgds jyothi
sanjays samadder
Greenhorn
Joined: Mar 30, 2001
Posts: 24
posted
0
hi, an import statement does not bring all the classes in that package.it inludes only the ones used. e.g if you import import java.appelt.*; instead of java.applet.Applet; it does not make a difference. both the statement bring only those classes that you use. this is as far as I know. regards
Jyothi, The only advantage of importing specific classes instead of all classes in a package is that if both packages contain classes with the same name you will not have to always refer to them explicitly. i.e. Both java.awt, and java.util have a List class ( well, the util one is an interface, but they are both called List ). If you needed to use classes from both packages, but not both java.awt.List and java.util.List ( for example, you use some awt components, but not the List awt component, and you use the java.util.List collection ) then you would do this :
If you imported them like this :
You would have to explicitly refer to List as java.util.List everywhere in your code. Of course, if you are actually using both components, you have to do this anyway... i.e. you are using a java.awt.List component to display the contents of a java.util.List. Fortunately, there are not many classes in the Java APIs that have a name collision like this ( in fact, java.awt.List and java.util.List, & java.sql.Date and java.util.Date are the only ones that come to mind. ), so this will not come up too often. There is no other impact that importing has on your code. It is not like the C #import statement where code is appended to your cpde, the Java import statement just tells the compiler how to resolve references. HTH, -Nate
-Nate
Write once, run anywhere, because there's nowhere to hide! - /. A.C.
Thomas Paul
mister krabs
Ranch Hand
Joined: May 05, 2000
Posts: 13974
posted
0
There is another advantage... you document which classes you are using right at the top of your class. Many shops forbid the use of "*" for just this reason. ------------------ Moderator of the JDBC Forum