File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
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 Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "imports and performance" Watch "imports and performance" New topic
Author

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
Sheriff

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 frankcarver.me ~ Raspberry Alpha Omega ~ Frank's Punchbarrel Blog
Cindy Glass
"The Hood"
Sheriff

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.
test.java
import java.util.*;
import java.applet.*;
class test
{
public static void main(String []args)
{
Date d = new Date();
System.out.println(d.getTime());

Vector v = new Vector();
System.out.println(v.capacity());
}
}
decompiled file test.class
import java.io.PrintStream;
import java.util.Date;
import java.util.Vector;
class test
{
test()
{
}

public static void main(String []args)
{
Date date = new Date();
System.out.println(date.getTime());

Vector vector = new Vector();
System.out.println(vector.capacity());
}
}

Cheers,<br />Rani<br />SCJP, SCWCD, SCBCD
 
Consider Paul's rocket mass heater.
 
subject: imports and performance
 
Similar Threads
Out of Memory Error !!!!!!!!
Youngest to clear WCD? 93%
Passed SCJP2 Exam with 91%
Indian Greetings
Java OS