import Statement

An import statement tells the Java compiler how to resolve external classes used by a program. Here’s an example that references a particular class (named JOptionPane) defined in the package javax.swing:

import javax.swing.JOptionPane;

Here are some helpful rules for working with import statements:

check.png import statements must appear at the beginning of the class file, before any class declarations.

check.png You can include as many import statements as necessary to import all the classes used by your program.

check.png You can import all the classes in a particular package by listing the package name followed by an asterisk wildcard, like this:

import javax.swing.*;

check.png Because many programs use the classes that are contained in the java.lang package, you don’t have to import that package. Instead, those classes are automatically available to all programs. The System class is defined in the java.lang package. As a result, you don’t have to provide an import statement to use this class.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset