Java Reference
In-Depth Information
repetition structure . When we introduce Java's control-structure implementations, we'll
refer to them in the terminology of the Java Language Specification as “control statements.”
Sequence Structure in Java
The sequence structure is built into Java. Unless directed otherwise, the computer executes
Java statements one after the other in the order in which they're written—that is, in se-
quence. The activity diagram in Fig. 4.1 illustrates a typical sequence structure in which
two calculations are performed in order. Java lets you have as many actions as you want in
a sequence structure. As we'll soon see, anywhere a single action may be placed, we may
place several actions in sequence.
Corresponding Java statement:
total = total + grade;
add grade to total
Corresponding Java statement:
counter = counter + 1;
add 1 to counter
Fig. 4.1 | Sequence-structure activity diagram.
A UML activity diagram models the workflow (also called the activity ) of a portion
of a software system. Such workflows may include a portion of an algorithm, like the
sequence structure in Fig. 4.1. Activity diagrams are composed of symbols, such as action-
state symbols (rectangles with their left and right sides replaced with outward arcs), dia-
monds and small circles . These symbols are connected by transition arrows , which rep-
resent the flow of the activity —that is, the order in which the actions should occur.
Like pseudocode, activity diagrams help you develop and represent algorithms.
Activity diagrams clearly show how control structures operate. We use the UML in this
chapter and Chapter 5 to show control flow in control statements. Online Chapters 33-
34 use the UML in a real-world automated-teller-machine case study.
Consider the sequence-structure activity diagram in Fig. 4.1. It contains two action
states , each containing an action expression —for example, “add grade to total” or “add 1
to counter”—that specifies a particular action to perform. Other actions might include
calculations or input/output operations. The arrows in the activity diagram represent
transitions , which indicate the order in which the actions represented by the action states
occur. The program that implements the activities illustrated by the diagram in Fig. 4.1
first adds grade to total , then adds 1 to counter .
The solid circle at the top of the activity diagram represents the initial state —the
beginning of the workflow before the program performs the modeled actions. The solid
circle surrounded by a hollow circle at the bottom of the diagram represents the final
state —the end of the workflow after the program performs its actions.
Figure 4.1 also includes rectangles with the upper-right corners folded over. These are
UML notes (like comments in Java)—explanatory remarks that describe the purpose of sym-
 
Search WWH ::




Custom Search