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...
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!!!
Joined: Jul 15, 2003
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 .
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.
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’ve looked at a lot of different solutions, and in my humble opinion Aspose is the way to go. Here’s the link: http://aspose.com