• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Java - import only those classes which you need VS import all/ import .*

 
David Jason
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Is there any difference between the two ?
 
jatan bhavsar
Ranch Hand
Posts: 299
Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 49796
69
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I found that old thread confusing to read. Our FAQ is more helpful.
 
David Jason
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 65120
91
IntelliJ IDE Java jQuery Mac Mac OS X
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The effect is so minuscule as to be completely ignorable.
 
Prasad prap
Greenhorn
Posts: 28
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Do have a look at this Stackoverflow
 
David Jason
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Prasad prap wrote:Do have a look at this Stackoverflow

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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic