Solved

Java: import classes question

Posted on 2003-11-28
5
493 Views
Last Modified: 2010-03-31
Hi guys,

this is just a simple question really which im not sure what the answer is

you know when you import java classes at the top, usually i just do this for quick reason:

import java.net.*;
import java.io.*;
import java.util.*;

But quite often i see codes where it doesnt do that, instead the line is more specific like:

import java.io.BufferedOutputStream;
import java.io.BufferedReader;
import java.util.ArrayList;
import java.util.TimerTask;

The question is, which one is a better way to do it? is there any big performance differences between those two?

Cheers,
Andre

0
Comment
Question by:JaZziD
  • 3
5 Comments
 
LVL 24

Accepted Solution

by:
sciuriware earned 25 total points
ID: 9836565
The latter is faster, but clumsy when indeed you need all classes from a group.

You should only add imports when you need them.
In due course you'll learn that some classes need some imports, so you'll add the imports automatically.
Otherwise, do as I do: let the compiler complain, find the class in the JavaDoc and add its import.
;JOOP!
0
 

Author Comment

by:JaZziD
ID: 9836731
cheers

Good that im using Eclipse...
all i need to do is delete the "import java.io.*;" bit and it tells me what classes i need to import for my class.

Thanks again for your info.
0
 
LVL 24

Expert Comment

by:sciuriware
ID: 9836770
...  I'm using ECLIPSE too!  No wonder .....
;JOOP!
0
 
LVL 92

Expert Comment

by:objects
ID: 9841207
> The latter is faster

Though I think the difference is neglible, and not significant.
0
 
LVL 24

Expert Comment

by:sciuriware
ID: 9844935
Sure, when I started programming I had to spare every uSec.
That's different these days.
And things that appear only once in a program are of no concern.
;JOOP!
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

For customizing the look of your lightweight component and making it look lucid like it was made of glass. Or: how to make your component more Apple-ish ;) This tip assumes your component to be of rectangular shape and completely opaque. (COD…
Introduction This article is the second of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers the basic installation and configuration of the test automation tools used by…
Viewers learn about the third conditional statement “else if” and use it in an example program. Then additional information about conditional statements is provided, covering the topic thoroughly. Viewers learn about the third conditional statement …
This video teaches viewers about errors in exception handling.

867 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now