They probably did it that way to make the code more "self-documenting". A reader can readily see which Swing classes were imported, but we can assume the AWT stuff is only for event handling, so we don't need to see the list of AWT classes.
Give a man a fish, he'll eat for one day. Teach a man to fish, he'll drink all your beer.
Cheers, Jeff (SCJP 1.4, SCJD in progress, if you can call that progress...)
sorry to sound picky I just want everything to be perfect
Joined: Jul 30, 2003
I think which way you import is largely a matter of personal preference. It's been a while since I read the Java coding conventions on Sun's website, but I don't remember them having an entry on import conventions. However, you may want to check because the assignment will in part be graded on conformance to the Java coding style specifications. Personally, I like importing individual classes because then I don't have to comment why I'm importing a package.
"Java 2 Perforamance and Idiom Guide" has a section (15.3) on this, and they have make a good argument for always using the import-on-demand (.*) type (unless of course you can't because of a naming conflict.)
Liberate yourselves from the tyranny of of the single-type-import! Declare your imports with type-imporst-on-demand and get to coding!
In my own experience after having used a utility for a while that would change all your import on demand (.*) to single type imports I ended up just prefering the import on demand.
If I am only importing one class, I will just import the class, not the whole package. But if I have two or more from the same package, I will import-on-demand (Never knew that's what it was called until now, thanks Josh!).
Jeff, you mentioned that you don't like commenting why you import a package. Is that really a standard practice? I have never encountered it before. I can see where it would be useful, but at the same time, I can always simply look at the APIs if I am unsure of a package contents. Just wnated to hear some opinions on it.
“Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning.” - Rich Cook