Login | Register   
LinkedIn
Google+
Twitter
RSS Feed
Download our iPhone app
TODAY'S HEADLINES  |   ARTICLE ARCHIVE  |   FORUMS  |   TIP BANK
Browse DevX
Sign up for e-mail newsletters from DevX


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

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,
myClass-Class
(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.

  
myPackage.myClass.myMethod().
Deepak Pant
 
Comment and Contribute

 

 

 

 

 


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

 

 

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