Java Reference
In-Depth Information
Operators
Associativity
Typ e
left to right
additive
+ -
< <= > >=
left to right
relational
== !=
left to right
equality
&
left to right
boolean logical AND
^
left to right
boolean logical exclusive OR
|
left to right
boolean logical inclusive OR
&&
left to right
conditional AND
||
left to right
conditional OR
?:
right to left
conditional
= += -= *= /= %=
right to left
assignment
Fig. 5.20 | Precedence/associativity of the operators discussed so far. (Part 2 of 2.)
5.10 Structured Programming Summary
Just as architects design buildings by employing the collective wisdom of their profession,
so should programmers design programs. Our field is much younger than architecture,
and our collective wisdom is considerably sparser. We've learned that structured program-
ming produces programs that are easier than unstructured programs to understand, test,
debug, modify and even prove correct in a mathematical sense.
Java Control Statements Are Single-Entry/Single-Exit
Figure 5.21 uses UML activity diagrams to summarize Java's control statements. The ini-
tial and final states indicate the single entry point and the single exit point of each control
statement. Arbitrarily connecting individual symbols in an activity diagram can lead to un-
structured programs. Therefore, the programming profession has chosen a limited set of
control statements that can be combined in only two simple ways to build structured pro-
grams.
For simplicity, Java includes only single-entry/single-exit control statements—there's
only one way to enter and only one way to exit each control statement. Connecting control
statements in sequence to form structured programs is simple. The final state of one con-
trol statement is connected to the initial state of the next—that is, the control statements
are placed one after another in a program in sequence. We call this control-statement
stacking . The rules for forming structured programs also allow for control statements to be
nested .
Rules for Forming Structured Programs
Figure 5.22 shows the rules for forming structured programs. The rules assume that action
states may be used to indicate any action. The rules also assume that we begin with the
simplest activity diagram (Fig. 5.23) consisting of only an initial state, an action state, a
final state and transition arrows.
 
 
Search WWH ::




Custom Search