how to import

Hello All,I can import a package likeimport java.io.*;or likeimport java.io.FileReader;The first approach makes me type less... but what is the disadvantage ?Will my program run slower because of the "*"?regards,Abhishek.
[298 byte] By [abhishes] at [2007-9-26 3:14:22]
# 1
The '*' may just increase compilation time ... especially when importing multiple large packages. But the use of '*' has no effect on the run-time performance or the size of you '.class' files.M. Carpentier
Morgoth_Sauron at 2007-6-29 11:24:33 > top of Java-index,Archived Forums,Java Programming...
# 2

The import statement is read and handled by the compiler, so there is no runtime issue if you use

import java.io.*;

or

import java.io.FileReader;

You can avoid name clashes if you explicitly use class names in import statements. Consider the case where 2 packages have a class called MyClass. If you import both packages with

import package1.*;

import package2.*;

and then try to declare

MyClass mC = new MyClass();

the complier cannot determine which package's version of MyClass it should use. If you just import the classes from the packages that you explicity require, then this problem goes away say,

import package1.MyClass;

import package2.OtherClass;

If you want to use MyClass from package1 and package2, you must use the full name of the class.

package1.MyClass mc1 = new package1.MyClass();

package2.MyClass mc2 = new package2.MyClass();

rob_canoe2 at 2007-6-29 11:24:33 > top of Java-index,Archived Forums,Java Programming...
# 3
I always thought that the * pull all packages within that class into the code whereas specific imports, such as your second call, only call specfic packages.
davyboy1979 at 2007-6-29 11:24:33 > top of Java-index,Archived Forums,Java Programming...
# 4
There is nothing added to your code, either way. You can import the whole fu*king shithouse and it won't insert them to your code. That's the greatest thing.
Kayaman at 2007-6-29 11:24:33 > top of Java-index,Archived Forums,Java Programming...