Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / December 2007

Tip: Looking for answers? Try searching our database.

Import efficiency

Thread view: 
Crouchez - 17 Dec 2007 23:09 GMT
Is importing a class directly ie.

import java.io.InputStream

more efficient than

import java.io.*;

?

What happens? Does the JVM import all the classes if using a wildcard?
Stefan Ram - 17 Dec 2007 23:24 GMT
>more efficient than

 There is run-time efficiency, memory efficiency, disk usage
 efficiency ...

>What happens? Does the JVM import all the classes if using a wildcard?

 An import declaration allows a static member or a named type
 to be referred to by a simple name that consists of a single
 identifier. I don't think that the JVM is aware of it at all.
Arne Vajhøj - 18 Dec 2007 01:18 GMT
>   An import declaration allows a static member or a named type
>   to be referred to by a simple name that consists of a single
>   identifier. I don't think that the JVM is aware of it at all.

I don't think he asked for static import just plain import.

Arne
Lew - 18 Dec 2007 03:41 GMT
>>   An import declaration allows a static member or a named type
>>   to be referred to by a simple name that consists of a single
>>   identifier. I don't think that the JVM is aware of it at all.
>
> I don't think he asked for static import just plain import.

The answer is the same for both domains of discourse - there is no run-time
impact.

Signature

Lew

Arne Vajhøj - 18 Dec 2007 03:47 GMT
>>>   An import declaration allows a static member or a named type
>>>   to be referred to by a simple name that consists of a single
[quoted text clipped - 4 lines]
> The answer is the same for both domains of discourse - there is no
> run-time impact.

Yep.

But maybe the original poster were a bit confused by the explanation.

Arne
Mark Rafn - 18 Dec 2007 00:12 GMT
>Is importing a class directly ie.

>import java.io.InputStream
>more efficient than
>import java.io.*;

It has no effect on the generated class, so no effect on runtime efficiency.
It's probabaly a hair faster to compile.  

As a developer, I prefer specific imports, as it's easy to expand a classname
if the import is there, rather than having to search through a bunch of
packages to see where SomeFooAccessor is defined.

>What happens? Does the JVM import all the classes if using a wildcard?

No.  The JVM doesn't see imports.  They're thrown away by the compiler.  The
compiler uses them to replace short type names with fully-qualified names.
There is no bytecode difference between importing specific names, wildcards,
and not importing anything in favor of using fully-qualified names everywhere.
--
Mark Rafn    dagon@dagon.net    <http://www.dagon.net/>
Roedy Green - 18 Dec 2007 01:38 GMT
>Is importing a class directly ie.
>
[quoted text clipped - 3 lines]
>
>import java.io.*;

import is a purely a compile time feature. It has no effect on run
times.  See http://mindprod.com/jgloss/import.html
on rules of thumb on how to use it.
Signature

Roedy Green Canadian Mind Products
The Java Glossary
http://mindprod.com

Crouchez - 18 Dec 2007 03:49 GMT
of course it's compile time isn't it, doh

cheers for the help


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.