• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

import statement ..?

 
Ranch Hand
Posts: 76
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi All,
import packagename.*; will it cause an extra overhead during runtime as it brings all classes.
Pls explain what happens when we import..?

-------------
Prashant
 
Author & Gold Digger
Posts: 7617
6
IntelliJ IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Import process: JLS 7.5 Import Declarations
From javaperformancetuning.com


import is a compile time function, so has no effect on runtime (i.e. import a.b.*; or import a.b.c; make no difference to runtime performance).


From Sun Chat: Optimizing Java Program Performance


The import statements do not affect the .class file size. They are used only to resolve references at compile time. Therefore, whether you use import a.b.*; or import a.b.c; doesn't matter.


It's worth noting that Sun developers never use import-on-demand in the JDK sources, they always use single-type-import.
You might also ask your questions in the Performance forum in order to get more precise answers from experts.
You will not be evaluated on the performance of the import statement in the real exam, though.
 
Cowgirl and Author
Posts: 1589
5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Howdy -- I just wanted to add that we usually recommend using the non-wild-card import for readability (but not performance, as the other posters pointed out). With the wild-card import:
import java.util.*;
you just cannot tell from looking at the top of the source code *exactly* which classes are being used.
The other reason to use the non-wild-card import is when there is a naming conflict. For example, both java.util and java.awt have a class called List. If you import both the util and awt packages using the wildcard import, then when you say List list = new List(), the compiler panics, becomes distressed, and complains that it has no clue WHICH List class you're talking about. So in that case, you could use the explicit class-by-class imports. Now, that STILL doesn't solve the problem if you really do want to use *both* List classes in your code. In that case, you'd still have to use the fully-qualified name everywhere you use that Class in your code.
Cheers,
Kathy
"Toss me. But don't tell the elf."
-Gimli the dwarf
reply
    Bookmark Topic Watch Topic
  • New Topic