• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Devaka Cooray
  • Ron McLeod
  • Jeanne Boyarsky
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Piet Souris
  • Carey Brown
  • Tim Holloway
Bartenders:
  • Martijn Verburg
  • Frits Walraven
  • Himai Minh

import

 
Ranch Hand
Posts: 111
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Can anybody please help me to clear this doubt?

suppose I need only to import Vector class,so what is the difference
between this two imports from performance point of view?

(1)import java.util.*;
(2)import java.util.Vector;
 
Ranch Hand
Posts: 1365
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Actually either version compiles to exactly the same bytecode, so no performance difference. The compiler determines the fully-qualified name of every class your code references and embeds the names into the classfile. Import statements are just a little syntactic sugar to save you the trouble of repeatedly typing the complete name java.util.Vector everywhere your code needs to refer to the Vector type.
 
slicker
Posts: 1108
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I once went to one of those java training camps, (for JINI), and the example station that was setup wouldn't work. A few SUN programmers were banging away it for awhile until someone decided to make all the import explicit. Turns out there was the same named class in two packages that never got picked up. Yikes. Well it probably won't happen often, but when it does it'll be a real pain. I ALWAYS use explicit imports.

Also, I like to look in a class and know which classes it uses. So if you are working in some new class and notice that it only access two other classes, you'll quickly get an idea of what it probably does or does not do. Alos, very helpful to get new programmers up to speed, and when you go looking through very old code. (in my opinion...)
 
Ranch Hand
Posts: 163
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by David Weitzman:
Actually either version compiles to exactly the same bytecode, so no performance difference. The compiler determines the fully-qualified name of every class your code references and embeds the names into the classfile. Import statements are just a little syntactic sugar to save you the trouble of repeatedly typing the complete name java.util.Vector everywhere your code needs to refer to the Vector type.



Exactly. Don't confuse "import" with "class loading".

And follow the advice to always spell out all your imports. It's better documentation that using the "*" notation. Make clear what you're using.

It's especially easy if you have an IDE like IntelliJ that helps you manage imports. But I still used to spell them out, even before I got my hands on IntelliJ.
 
Anil Kumar Saha
Ranch Hand
Posts: 111
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi All,

Thanks a lot for clearing my doubt.
 
eat bricks! HA! And here's another one! And a tiny ad!
the value of filler advertising in 2021
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic