Parvinder said:
what is the advantage of importing a single class v/s all the classes
from the package
like java.util.date is better then java.util.*.If yes then what are the
advantages ?
The advantage of importing a single class is that it avoids naming conflicts
that sometimes arise when the same class name is used in more than one
package.
Example
import java.awt.*
import java.util.*
List list = new ArrayList ();
Which List is meant? Both java.awt and Java.util think they know what "List"
means (in java.awt it is a class, in java.util it is an interface). The
compiler will stop and demand clarification.
The solution to this is to add this import after the two above:
import java.util.List;
This has the effect of forcing any references to "List" to refer to
java.util. But a general policy of specific importing also solves the
problem.
There are many examples of this kind. The worst situation is to import too
broadly and use a name that *doesn't* result in an error message, but
creates code that is not what you intended.