• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Code Effectiveness

 
Fitra Fadilana
Greenhorn
Posts: 2
Java Linux Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sometimes i wonder with the convention of writing the import statement in java for effectiveness and best result.
when i read the tutorial in java programming, I often see the writer use all the class inside the package which he/she use in his/her code.
for example:
import javax.microedition.lcdui.*;

after i read the rest of its code, i just noticed it use just one or two class.
for example:
import javax.microedition.lcdui.Canvas;

but why the writer import all unnecessary class.
the question is. what is the impact of importing all the class that we don't need to use.
is it make the code eat much memory when it runs? or it file size if bigger rather than importing necessary class?
 
Matthew Brown
Bartender
Posts: 4568
9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It will make almost certainly no difference to the performance, because importing is purely a compile-time operation to remove the need to fully-qualify class names. Having said that, some people do argue that it's better to use explicit imports because it makes the dependencies you're introducing clearer.

I'd use the .* format if it wasn't for the fact that modern IDEs make it easy to handle specific imports - you don't need to type them all out yourself.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic