It's not a secret anymore!
The moose likes Beginning Java and the fly likes imports and performance Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Java Interview Guide this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "imports and performance" Watch "imports and performance" New topic

imports and performance

Dale DeMott
Ranch Hand

Joined: Nov 02, 2000
Posts: 515
Will having lots of classes to import slow down performance?

What's this H2SO4 doing in my fridge?? ( thud )

By failing to prepare, you are preparing to fail.<br />Benjamin Franklin (1706 - 1790)
Frank Carver

Joined: Jan 07, 1999
Posts: 6920
In general, no. It might slow down compilation a little, but once a class has been compiled and loaded it just references the other classes it needs directly, regardless of how many import statements were in teh source file.

Read about me at ~ Raspberry Alpha Omega ~ Frank's Punchbarrel Blog
Cindy Glass
"The Hood"

Joined: Sep 29, 2000
Posts: 8521
In C++ when you do an include, all the source is pulled into your code. That is not the case with java. Only the classes that you actually USE are pulled into the code. An import is more like a search path than a copy.

"JavaRanch, where the deer and the Certified play" - David O'Meara
rani bedi
Ranch Hand

Joined: Feb 06, 2001
Posts: 358
cindi is correct the import statement just acts like a search path to reach to the class required.
If you try to decompile a file you will notice that * in the import statement is replaced by the exact class names and the irrelevant import statements are deleted.
import java.util.*;
import java.applet.*;
class test
public static void main(String []args)
Date d = new Date();

Vector v = new Vector();
decompiled file test.class
import java.util.Date;
import java.util.Vector;
class test

public static void main(String []args)
Date date = new Date();

Vector vector = new Vector();

Cheers,<br />Rani<br />SCJP, SCWCD, SCBCD
I agree. Here's the link:
subject: imports and performance
It's not a secret anymore!