Solved

Java: import classes question

Posted on 2003-11-28
5
497 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 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

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 last of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers our test design approach and then goes through a simple test case example, how …
Java functions are among the best things for programmers to work with as Java sites can be very easy to read and prepare. Java especially simplifies many processes in the coding industry as it helps integrate many forms of technology and different d…
Viewers will learn about basic arrays, how to declare them, and how to use them. Introduction and definition: Declare an array and cover the syntax of declaring them: Initialize every index in the created array: Example/Features of a basic arr…
This video teaches viewers about errors in exception handling.

691 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