O'Reilly logo

Java™ How To Program (Early Objects), Tenth Edition by Harvey Deitel, Paul Deitel

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

2.5.1 import Declarations

A great strength of Java is its rich set of predefined classes that you can reuse rather than “reinventing the wheel.” These classes are grouped into packagesnamed groups of related classes—and are collectively referred to as the Java class library, or the Java Application Programming Interface (Java API). Line 3

import java.util.Scanner; // program uses class Scanner

is an import declaration that helps the compiler locate a class that’s used in this program. It indicates that the program uses the predefined Scanner class (discussed shortly) from the package named java.util. The compiler then ensures that you use the class correctly.

Common Programming Error 2.7

All import declarations ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required