• Post Reply Bookmark Topic Watch Topic
  • New Topic

effect of imports on java program  RSS feed

 
Manish Singh
Ranch Hand
Posts: 160
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If I need to use only 2 or 3 classes from a package which style of import should be used
1. import java.io.File;
import java.io.IOException;
import java.io.FileReader;

or
2. import java.io.*;

how does these imports effect the size of class file or the time of loading and execution
 
marc weber
Sheriff
Posts: 11343
Java Mac Safari
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The first is preferred because it avoids potential clashes with other classes in the package that you are not using, and it makes it clear to other readers exactly what's being imported.

Import statements only open the door to make these available. Nothing comes through that door until needed, so they will not "bloat" your files.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!