Java Programs from the Top Down
Before we begin our bottom-up exploration of Java syntax,
let’s take a moment for a top-down overview of a
Java
program. Java programs consist of one or more files, or
compilation units
, of Java source code. Near the end of the
chapter, we describe the structure of a Java file and explain how to
compile and run a Java program. Each compilation unit begins with an
optional package
declaration followed by zero or
more import
declarations. These declarations
specify the namespace within which the compilation unit will define
names, and the namespaces from which the compilation unit imports
names. We’ll see package and
import again in Section 2.10 later in this chapter.
The optional package and import
declarations are followed by zero or more
reference type definitions.
These are typically class or
interface definitions, but in Java 5.0 and later,
they can also be enum definitions or annotation
definitions. The general features of reference types are covered
later in this chapter, and detailed coverage of the various kinds of
reference types is in Chapters Chapter 3 and
Chapter 4.
Type definitions include members such as fields, methods, and constructors. Methods are the most important type member. Methods are blocks of Java code comprised of statements . Most statements include expressions , which are built using operators and values known as primitive data types . Finally, the keywords used to write statements, the punctuation characters that represent ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access