Browse DevX
Sign up for e-mail newsletters from DevX

Tip of the Day
Language: Java
Expertise: Intermediate
Aug 25, 2000



Building the Right Environment to Support AI, Machine Learning and Deep Learning

Avoiding Confusion about an Import Statement

Every source file in Java (.java file) contains one class. You can bundle a set of related classes into a package. Java provides "import" keyword, which is used to establish a reference to a class in a different package.

There are couple of ways in which you can use "import" statement.

(a) Use a specific class name in "import" statement:

import myPackage.myClass;	// myPackage-Package,
(b) OR you can use wild card "import" statement like :
import myPackage.*; 	// import all the classes

The second approach is simple, because it imports all the classes in the specified package. There are no disadvantages of using wild card "import" statement with respect to compile time, run time, or code size, etc.

The only problem where we cannot use "import" is the place where we want to import two classes of same name from two different packages. In this situation, you can refer to the classes using full qualifier, i.e.

Deepak Pant
Comment and Contribute






(Maximum characters: 1200). You have 1200 characters left.



Thanks for your registration, follow us on our social networks to keep up-to-date