File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Java in General and the fly likes Question on importing a class Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "Question on importing a class" Watch "Question on importing a class" New topic
Author

Question on importing a class

rajesh godbole
Ranch Hand

Joined: Jan 10, 2003
Posts: 31
Is there a particular advantage in this:
import java.util.Enumeration;
import java.util.Hashtable;
versus
import java.util.*

Could you please guide me in this matter.
John Lee
Ranch Hand

Joined: Aug 05, 2001
Posts: 2545
i think it is faster to import only java.util.Enumeration and java.util.Hashtable, if you don't need all java.util.*.
Anonymous
Ranch Hand

Joined: Nov 22, 2008
Posts: 18944
I think there is no difference regarding speed,
cause when compiler is translating code he is importing the references (linking).
The only difference is that you explicitly import a class.
import java.util.Date;
and when you for example
import java.util.*;
import java.sql.*;
Then class Date would be ambigous. So you must import it explicitly or reference it explicitly in your code.
[ June 06, 2003: Message edited by: Oliver Refle ]
John Lee
Ranch Hand

Joined: Aug 05, 2001
Posts: 2545
hi:
is that right? how about:
Improve the performance of your Java code;
strange... ;
java performance.
Maulin Vasavada
Ranch Hand

Joined: Nov 04, 2001
Posts: 1871
hi Don
the links are good but i really didnt understand the relation between those and the topic being discussed here. i mean the purpose of the original post seem not asking "performance" at the heart. to me it is - "why ppl write the class name in import than having * in there?"
the links you have provided are discussing performance issues and i went over them cursorily and didn't seem to see any "import" issues addressed.
i would agree with Oliver's post.
regards
maulin
peter greaves
Ranch Hand

Joined: Sep 27, 2002
Posts: 51
we have a code standard that prefers explicit named class imports (import java.util.HashMap) over whole package imports. this is because it is clearer to the reader to see which classes are (probably) needed, and helps to avoid class name collisions. though it is a matter of preference and style, i like the precision it implies.
just my 0.02c
peter


SJCP 1.2
Ashish Kothari
Ranch Hand

Joined: May 16, 2003
Posts: 37
it is just matter of preferance and style and sometimes to avoid confusion,as peter told.
Ashish
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Question on importing a class