import keyword in java

The ” import ” keyword makes one class or all classes in a specified package visible in the current Java source file.

Imported classes can be referenced without the use of fully−qualified class names.

We can either import all the classes from a package using “*” wildcard or

We can import specific class from a package using exact class name in the import.



In the first import, we are importing all the classes under package.

In the second import, we are importing only “File” class from package.

The import statements must be placed on top of the source file, just after the package statement.


  1. package com.kb;
  2. import;
  3. public class ImportExample{
  5. //variables and methods goes here
  6. }
package com.kb;
public class ImportExample{

//variables and methods goes here


Its good practice to use only specific import statements (rather than ‘*’) to avoid ambiguity when multiple packages contain classes of the same name.

About the Author

Karibasappa G C (KB)
Founder of
I love Java and open source technologies and very much passionate about software development.
I like to share my knowledge with others especially on technology 🙂
I have given all the examples as simple as possible to understand for the beginners.
All the code posted on my blog is developed,compiled and tested in my development environment.
If you find any mistakes or bugs, Please drop an email to

Connect with me on Facebook for more updates

Share this article on