Forums Register Login

efficiency of import statements

+Pie Number of slices to send: Send
when using an import statement, does the compiler include every class within a package, or only the classes that are used?
for example, if a program had "import java.io.*" but then only used a File object, would the compiler throw in BufferedReader and all the other classes in to the compiled code? i've heard both sides of the story, but haven't found official documentation on it.
+Pie Number of slices to send: Send
The import statements have no affect what so ever of performance.
You can include as many as you like and it wont affect performance at all (same performance as not including any).
The only thing an import statement does if to make it easier for us programmers to TYPE.
When we use import we dont have to type the full name of teh class (Package and all) - instead we use import and we can only type the class.
+Pie Number of slices to send: Send
In Java unlike C++ classes are loaded as needed, not all at the beginning of the program. Further, in Java class definitions will be unloaded if they are not currently being used and memory gets tight. This is an advantage over c++ who can not nativly unload class definitions at runtime.
He loves you so much! And I'm baking the cake! I'm going to put this tiny ad in the cake:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com


reply
reply
This thread has been viewed 725 times.
Similar Threads
Java
JSP Image Thumbnailer
behaviour of import statement
what happens when i include a package more than once
Packages
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 29, 2024 05:10:57.