Hello all, After taking a seven month break from my SCJD due to studies I have returned to complete it. Following this break I will start off with a nice (very) easy question!! When importing files what is the correct convention i.e. is the package name followed by a star e.g. import java.util.* OR is it an absolute path e.g. import java.util.ArrayList? If you are importing one or two classes you would use the absolute and if using many use the star�is this the general consensus? The only reason I ask is that going through my code I have been inconsistent with this e.g. using * sometimes when just using one class and other times importing the absolute class. Thanks in advance, John
hi John: I don't think that there is an import statement convention. However, good coding style is to import only what you need. So, one should always use an absolute path instead of '*' to import classes.
SCJD 1.4<br />SCJP 1.4<br />-----------------------------------<br />"With regard to excellence, it is not enough to know, but we must try to have and use it.<br />" Aristotle
Hi John, Welcome back! The best practice in that area is to import specific classes instead of whole packages (using the '*'). Now most of Java editors (Eclipse, JBuilder do it for sure) let you "optimize" your importa statements, by replacing generic imports (.*) by specific ones, and by removing useless imports. Regards, Phil.
Joined: May 07, 2003
Thanks Hanna and Philippe for the quick reply!
Will use the fully qualified import statements from now on. Regards, John
From the book, I think I remember if it is like a few classes, like 2, the it is better to use fully qualified so that ppl dont have a hard time figuring out the object type you use is from which package. If you have 30 classes from that package, the it is better to use .*; cos 1, it makes your code look messy, 2 you are likely to keep adding it if you dont use it. There is no adv or disadv over one another except for clarity of your code.
Joined: Jun 02, 2003
From the book,(...)
Which one? Regards, Phil.
Joined: Nov 09, 2003
Max's or Kathy & Bate's... that's where I get the ideas from. Not sure if you can get the exact wording...
Joined: Jun 02, 2003
I cannot check in Max's book because I sent my copy to a rancher a few months ago. But Kathy & Bert seem to prefer explicit class imports (see p. 109).
Phil. [ May 13, 2004: Message edited by: Philippe Maquet ]