Basic structure of a Java program A Java program ( class) is either a library of
static methods (functions) or a data type definition. To create libraries of static methods
and data-type definitions, we use the following five components, the basis of programming
in Java and many other modern languages:
■Primitive data types precisely define the meaning of terms like integer, real number,
and boolean value within a computer program. Their definition includes the
set of possible values and operations on those values, which can be combined
into expressions like mathematical expressions that define values.
■
Statements allow us to define a computation by creating and assigning values to
variables, controlling execution flow, or causing side effects. We use six types of
statements: declarations, assignments, conditionals, loops, calls, and returns.
■ Arrays allow us to work with multiple values of the same type.
■ Static methods allow us to encapsulate and reuse code and to develop programs
as a set of independent modules.
■ Strings are sequences of characters. Some operations on them are built in to Java.
■ Input/output sets up communication between programs and the outside world.
■Data abstraction extends encapsulation and reuse to allow us to define nonprimitive
data types, thus supporting object-oriented programming.
In this section, we will consider the first five of these in turn. Data abstraction is the
topic of the next section.