Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Question on importing a class

 
rajesh godbole
Ranch Hand
Posts: 31
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 2545
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 18944
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 2545
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi:
is that right? how about:
Improve the performance of your Java code;
strange... ;
java performance.
 
Maulin Vasavada
Ranch Hand
Posts: 1873
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 51
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Ashish Kothari
Ranch Hand
Posts: 37
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
it is just matter of preferance and style and sometimes to avoid confusion,as peter told.
Ashish
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic