Solved

Java: import classes question

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

U.S. Department of Agriculture and Acronis Access

With the new era of mobile computing, smartphones and tablets, wireless communications and cloud services, the USDA sought to take advantage of a mobilized workforce and the blurring lines between personal and corporate computing resources.

Question has a verified solution.

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

Suggested Solutions

An old method to applying the Singleton pattern in your Java code is to check if a static instance, defined in the same class that needs to be instantiated once and only once, is null and then create a new instance; otherwise, the pre-existing insta…
This was posted to the Netbeans forum a Feb, 2010 and I also sent it to Verisign. Who didn't help much in my struggles to get my application signed. ------------------------- Start The idea here is to target your cell phones with the correct…
Viewers will learn about if statements in Java and their use The if statement: The condition required to create an if statement: Variations of if statements: An example using if statements:
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…

809 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