• Post Reply Bookmark Topic Watch Topic
  • New Topic

Is there any difference in importing.  RSS feed

 
aman hindustani
Ranch Hand
Posts: 57
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello to all...

import java.io.*; (or) import java.io.ArrayList;

Is it makes any difference between importing a whole package ....a single class of that package...in the performance..or during run time..or during compile time..

In this both which one is advisible..
 
steve souza
Ranch Hand
Posts: 862
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
At runtime your code will have no performance difference.

At compilation time the performance difference probably isn't noticeable even if there is one. Most people prefer the approach of importing only the classes that are needed. I suspect because it is a better form of documenation. I would like to understand that justification better myself.

[ August 04, 2006: Message edited by: steve souza ]
[ August 04, 2006: Message edited by: steve souza ]
 
aman hindustani
Ranch Hand
Posts: 57
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks,

But, i still feel that ...it may be some difference between importing single class of that package verses whole pacakge.

Can anyone help me ..where i can read about this...
 
Ilja Preuss
author
Sheriff
Posts: 14112
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
http://faq.javaranch.com/view?WildCardVsSpecificImports
 
Ernest Friedman-Hill
author and iconoclast
Sheriff
Posts: 24217
38
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Nope. Steve is 100% correct.

First, note that import is a compile-time thing; no matter whether you import one class or a whole package, it has absolutely no effect on the generated class file -- none at all. Every bit of the files so generated will be identical.

Now, does one or the other make the compiler any faster? Perhaps, a little, tiny bit: importing a single class may give the compiler less work to do overall. But I've never heard of anyone succeeding in measuring a time difference.
 
aman hindustani
Ranch Hand
Posts: 57
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks to all ....
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!