Import Question

if I explicitly call my import statements :
  ie. import javax.swing.JPanel;
       import javax.swing.JSlider;

as opposed to :
   import javax.swing.*;

Will my program compile/run faster?
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

There can be an effect on compilation speed (though I have not noticed one in practice). There is definitely NO effect on running the program.
stalefishAuthor Commented:
Well whats actually happening here? Does the compiler go out and search for the appropriate class file if a ".*;" is found? Does this improve the compilation of the java file, or does it also improve the compilation of intermediate class file?
It doesn't improve things in the sense of making them work better. Usually without an import statement of some kind, it doesn't work at all. When you reference the Vector class for instance you will need to import. You could do:

import java.util.Vector;


import java.util.*;

In the first case the the compiler will load the Vector class (to acquire the information about Vector that it needs to do the compilation). In the second case it will load all classes in java.util. Note that it is the compiler doing this, not the JVM. When the program is running under the JVM it only loads exactly what it needs, when it needs it.

Also again, in my experience, this does not cause a practical compilation delay (i.e. it has such minimal impact (in terms of actual time taken) there is no noticable difference between compiling files that import and those that don't).

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Importing a class or package is simply saving typing time.  It doesnt combine  (link) the package (library) with your classes like it would in C/C++.
I believe that it would effect compilation speed, but its negligible.  
Depending on how many classes in a package you use, I doubt that you would save enough compilation time to make up for the time you took to type all the classes that you use explicitly.
As imladris said, it wouldnt have any effect at all on program execution.

I dont have any benchmarks on this (I doubt anyone does).

My general rule is that if I use approx 2 or more classes in a package Ill import the whole package. But thats just me.
stalefishAuthor Commented:
Thanks alot
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.