Friday 1 September 2017

Java Import Declaration

Cited from the Book Jave How to Program

All import declarations must appear before the first class declaration in the file. Placing an import declaration inside or after a class declaration is a syntax error.

Classes System and String are in package java.lang, which is implicitly imported into every Java program, so all programs can use that package’s classes without explicitly importing them.

Classes in the same package are implicitly imported into the source-code files of other classes in the same package.

import java.util.Scanner; // program uses Scanner
....
Scanner input = new Scanner( System.in );
...

java.util.Scanner specifies the full package name and class name. This is known as the class’s fully qualified class name.

Otherwise without the import declaration, it would be written as 

java.util.Scanner input = new java.util.Scanner( System.in );

No comments:

Post a Comment