Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Java: import classes question

Posted on 2003-11-28
5
Medium Priority
?
499 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
5 Comments
 
LVL 24

Accepted Solution

by:
sciuriware earned 100 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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

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…
In this post we will learn how to connect and configure Android Device (Smartphone etc.) with Android Studio. After that we will run a simple Hello World Program.
This video teaches viewers about errors in exception handling.
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …
Suggested Courses

597 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