2.5. Java Source File Structure

The structure of a skeletal Java source file is depicted in Figure 2.2. A Java source file can have the following elements that, if present, must be specified in the following order:

1.
An optional package declaration to specify a package name. Packages are discussed in Section 4.6.
2.
Zero or more import declarations. Since import declarations introduce class and interface names in the source code, they must be placed before any type declarations. The import statement is discussed in Section 4.6.
3.
Any number of top-level class and interface declarations. Since these declarations belong to the same package, they are said to be defined at the top level, which is the package level. The classes and interfaces can ...

Get Programmer's Guide to Java™ Certification, A: A Comprehensive Primer, Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.