In Java, the import keyword is used to make classes and interfaces available and accessible to the current source code, without specifying fully qualified package names. For example:

import java.awt.*;
import java.util.List;
import java.io.File;

The first import statement makes all classes/interfaces under package java.awt accesible to the current program. It uses the * wildcard character to specify 'everything' under the package.

Likewise, the second and third import statements make the interface List and the class File available to the current source code. It uses exact names instead of wildcard.

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

 

Related keyword: package. See all keywords in Java.

 

Related Topics:

 

Other Recommended Tutorials:


About the Author:

is certified Java programmer (SCJP and SCWCD). He began programming with Java back in the days of Java 1.4 and has been passionate about it ever since. You can connect with him on Facebook and watch his Java videos on YouTube.



Add comment