wood burning stoves*
The moose likes Beginning Java and the fly likes Importing packages Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Importing packages" Watch "Importing packages" New topic
Author

Importing packages

Kevin Fellon
Greenhorn

Joined: Jul 07, 2003
Posts: 1
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

Joined: Oct 15, 2002
Posts: 189
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.


Philip Shanks, SCJP - Castro Valley, CA
My boss never outsources or has lay-offs, and He's always hiring. I work for Jesus! Prepare your resume!
Natraj Gudla
Ranch Hand

Joined: Feb 09, 2003
Posts: 34
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

Joined: Jun 17, 2000
Posts: 102
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
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
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Importing packages
 
Similar Threads
Passed PartII-III with 100%
Package does not exist
IDE for Java
jvm vs java compliler
Where are javax.ejb packages