Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Importing packages

 
Kevin Fellon
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Philip Shanks
Ranch Hand
Posts: 189
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Natraj Gudla
Ranch Hand
Posts: 34
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Thillai Sakthi
Ranch Hand
Posts: 109
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Thillai Sakthi
Ranch Hand
Posts: 109
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic