File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Beginning Java and the fly likes Java - import only those classes which you need VS import all/ import .* Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Java - import only those classes which you need VS import all/ import .*" Watch "Java - import only those classes which you need VS import all/ import .*" New topic
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: 297

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: 41576
    
  31
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: 62290
    
  68

The effect is so minuscule as to be completely ignorable.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Prasad prap
Greenhorn

Joined: Sep 26, 2008
Posts: 28
Do have a look at this Stackoverflow
David Jason
Greenhorn

Joined: Aug 21, 2012
Posts: 27
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.
 
wood burning stoves
 
subject: Java - import only those classes which you need VS import all/ import .*