| Author |
Java - import only those classes which you need VS import all/ import .*
|
David Jason
Greenhorn
Joined: Aug 21, 2012
Posts: 27
|
|
|
Is there any difference between the two ?
|
 |
jatan bhavsar
Ranch Hand
Joined: Jul 23, 2008
Posts: 296
|
|
Hi David,
Yes there is difference when you import specific class and import all the classes.
Refer to this thread http://www.coderanch.com/t/374863/java/java/import-pkg-vs-import-pkg
Regards
Jatan
|
 |
Campbell Ritchie
Sheriff
Joined: Oct 13, 2005
Posts: 32599
|
|
|
I found that old thread confusing to read. Our FAQ is more helpful.
|
 |
David Jason
Greenhorn
Joined: Aug 21, 2012
Posts: 27
|
|
Campbell Ritchie wrote:I found that old thread confusing to read. Our FAQ is more helpful.
Thanks, just read that now. Got what I was looking for. On the side,
I wish they could also give some info about how the compiling process is affected.
|
 |
Bear Bibeault
Author and ninkuma
Marshal
Joined: Jan 10, 2002
Posts: 56151
|
|
|
The effect is so minuscule as to be completely ignorable.
|
[Smart Questions] [JSP FAQ] [Books by Bear] [Bear's FrontMan] [About Bear]
|
 |
Prasad prap
Greenhorn
Joined: Sep 26, 2008
Posts: 26
|
|
|
Do have a look at this Stackoverflow
|
 |
David Jason
Greenhorn
Joined: Aug 21, 2012
Posts: 27
|
|
Yes, excellent post and good answers. Especially this:
Chris Cudmore wrote:
Take a look at the java API, and you'll see many classes and interfaces with the same name in different packages.
For example:
java.lang.reflect.Array
java.sql.Array
So, if you import java.lang.reflect.* and java.sql.* you'll have a collision on the Array type, and have to fully qualify them in your code.
Importing specific classes instead will save you this hassle.
Thanks for that link prasad.
|
 |
 |
|
|
subject: Java - import only those classes which you need VS import all/ import .*
|
|
|