Solved

Java: import classes question

Posted on 2003-11-28
5
491 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
Comment Utility
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
Comment Utility
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
Comment Utility
...  I'm using ECLIPSE too!  No wonder .....
;JOOP!
0
 
LVL 92

Expert Comment

by:objects
Comment Utility
> The latter is faster

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

Expert Comment

by:sciuriware
Comment Utility
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

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
network + 7 72
countAbc challenge 9 49
maven example error 3 34
Java / Linux and Regular Expressions 11 42
For customizing the look of your lightweight component and making it look opaque like it was made of plastic.  This tip assumes your component to be of rectangular shape and completely opaque.   (CODE)
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
Viewers learn about the “while” loop and how to utilize it correctly in Java. Additionally, viewers begin exploring how to include conditional statements within a while loop and avoid an endless loop. Define While Loop: Basic Example: Explanatio…
Viewers learn about the “for” loop and how it works in Java. By comparing it to the while loop learned before, viewers can make the transition easily. You will learn about the formatting of the for loop as we write a program that prints even numbers…

763 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

9 Experts available now in Live!

Get 1:1 Help Now