Java import keyword example
- Details
- Written by Nam Ha Minh
- Last Updated on 19 August 2019   |   Print Email
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:
- 9 Rules about Constructors in Java
- 12 Rules and Examples About Inheritance in Java
- 12 Rules of Overriding in Java You Should Know
- 10 Java Core Best Practices Every Java Programmer Should Know
- Understand Interfaces in Java
- Understand how variables are passed in Java
- Understand encapsulation in Java
Comments