aspose file tools*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes import statement Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Soft Skills this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "import statement" Watch "import statement" New topic
Author

import statement

Puneet Agarwal
Ranch Hand

Joined: Jul 15, 2003
Posts: 49
In import statements , why is it that we must not write import java.util.* but instead we must write the fully qualified import statement for the class(s) which are being used , like java.util.Hashtable . There should be no unused import statements in the file . Why is that so...
Vicken Karaoghlanian
Ranch Hand

Joined: Jul 21, 2003
Posts: 522


why is it that we must not write import java.util.* but instead we must write the fully qualified import statement for the class(s) which are being used , like java.util.Hashtable


Who says this!!! it is totally legal to import the entire classes in the package (java.util.*) or simply import a single class (java.util.Hastable), both statements are correct.
I for example, like most programmers tend to use the first option because if you want to import every single class by writing its own individual import statement, then you'll end up with a code that has a dozen of import statement.
FYI, importing the entire package does not make your code any less efficient.


- Do not try and bend the spoon. That's impossible. Instead, only try to realize the truth. - What truth? - That there is no spoon!!!
Puneet Agarwal
Ranch Hand

Joined: Jul 15, 2003
Posts: 49
I was asked this question in an interview yesterday . From my programming experience in Java , it is certainly not recommended to import the entire package . I am saying this from the code that I work on in my project .
Mani Ram
Ranch Hand

Joined: Mar 11, 2002
Posts: 1140
It's all about the standards and your personal preferences.
Normally, if I'm importing more than 4 classes from a same package, I use the wildcard version (import *). Anything less than 4, I import the individual classes.


Mani
Quaerendo Invenietis
Anand Sidharth
Ranch Hand

Joined: Dec 17, 2003
Posts: 44
As said before importing the entire package instead of the class doesnt affect the performance of the code.
The main reason is to get an idea of the code and what classes are used in the class as soon as u see the code. It gives a clear picture to the person who goes through the code and the reviewer and some times to u when u have a look at the code after a long time on the classed that are used in that code.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: import statement