Importing packages

Will it make the footprint of my application significantly bigger (and will it run slower) if I import entire packages (javax.swing.*) as opposed to just the classes I am going to use (javax.swing.joptionpane)? I have seen books do it both ways and I want to know if it makes a big difference. Thanks.

No, using "splat" style imports does not increase the size of your application. The imports simply tell the ClassLoader in which packages it can find the classes the code needs to access. It's kind of a style issue. I prefer to explicitly import each class. That way I can see all of the dependencies right at the top of the file. You will find that most good coding tools (IDE's and text editors with language specific plugins, a la Netbeans and jEdit) will allow you to use either style.

Originally posted by Philip Shanks: No, using "splat" style imports does not increase the size of your application. The imports simply tell the ClassLoader in which packages it can find the classes the code needs to access.

Yeah, Philip. I agree. Importing a package totally neither slows down your application nor it makes it bigger. Any way, the class files are loaded as and when they are required (meaning when they are used in the program). I also prefer a specific import of a particular class rather than a entire package as it is easy for maintenance and better readability. K

Regards,
Shakthi

Thillai Sakthi
Ranch Hand

Joined: Jun 17, 2000
Posts: 102

posted Jul 08, 2003 02:16:00

0

Originally posted by Natraj Gudla: Hi, Importing any number of packages though unused,just increases the compile time only , nothing else.It does not effect your binary size or the performance(execution time). Natraj.

Hi, Compilation time is not affected here as the classes are loaded onto memory as and when they are used in the program. And as you rightly said, it does not affect the performance any way. K