Skip to main content



      Home
Home » Language IDEs » Java Development Tools (JDT) » Import question
Import question [message #147438] Fri, 05 March 2004 07:41 Go to next message
Eclipse UserFriend
Originally posted by: pmdanger.yahoo.com

Hi,

Reading a book about java, i saw that we can use :

import javax.*

or

import javax.swing
import javax.xxxx
import javax.yyyy

which solution offer the best result in term of compilation ?
when is compilation fast ?
when is file size smaller ?

thanks in advance,
Maileen
Re: Import question [message #147470 is a reply to message #147438] Fri, 05 March 2004 09:48 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: manahan.NOSPAM.ca.ibm.com

You probably get more responses to those kinds of questions on a java
newsgroup like comp.lang.java.* newsgroups.

Peter

Maileen wrote:

> Hi,
>
> Reading a book about java, i saw that we can use :
>
> import javax.*
>
> or
>
> import javax.swing
> import javax.xxxx
> import javax.yyyy
>
> which solution offer the best result in term of compilation ?
> when is compilation fast ?
> when is file size smaller ?
>
> thanks in advance,
> Maileen
>
Re: Import question [message #147478 is a reply to message #147470] Fri, 05 March 2004 09:58 Go to previous message
Eclipse UserFriend
Originally posted by: eclipse-user.jibeinc.com

Peter Manahan wrote:

> You probably get more responses to those kinds of questions on a java
> newsgroup like comp.lang.java.* newsgroups.

True. But I'll answer it because it's easy and important for Java
newbies to know about.


> Maileen wrote:
>
>> Hi,
>>
>> Reading a book about java, i saw that we can use :
>>
>> import javax.*
>>
>> or
>>
>> import javax.swing
>> import javax.xxxx
>> import javax.yyyy
>>
>> which solution offer the best result in term of compilation ?
>> when is compilation fast ?
>> when is file size smaller ?

First: in terms of compile speed and generated file size, there is
absolutely no difference between the two import formats. The import
statements are just syntactic sugar to make the code writer's life a
little easier - they do not end up in the compiled classes at all.

Second: always use the long form, unless you are importing a very large
number of classes from one package. The wildcard form is tempting,
especially for those programmers who are used to languages that
encourage as little typing as possible. But all those wildcard imports
make it difficult to determine where individual classes are coming from.
If I see a class that I'm not familiar with, such as FooBarAdapter, and
the code has a bunch of wildcard imports, it becomes very much a PITA to
determine what package FooBarAdapter comes from (yes, Eclipse helps in
that regard, but the point is still valid).

Eclipse automatically generates appropriate import statements for you
anyway, so you should never have to worry too much about this. There are
settings to tell it at what threshold to use the wildcard import for a
package - see Preferences > Java > Organize Imports (I have my threshold
set to 10, and I can't find any of my code that uses wildcard imports).

HTH,
Eric
--
Eric Rizzo
Software Architect
Jibe, Inc.
http://www.jibeinc.com
Previous Topic:Uncomment command
Next Topic:Debug problems with the system.out.println statement
Goto Forum:
  


Current Time: Sat Jun 07 18:02:19 EDT 2025

Powered by FUDForum. Page generated in 1.03128 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top