Java Reference
In-Depth Information
• Just as a block can be placed anywhere a single statement can be placed, you can also use an empty
statement, represented by placing a semicolon ( ; ) where a statement would normally be.
Section 4.8 while Repetition Statement
•The while repetition statement (p. 114) allows you to specify that a program should repeat an
action while some condition remains true.
• The UML's merge (p. 114) symbol joins two flows of activity into one.
• The decision and merge symbols can be distinguished by the number of incoming and outgoing
transition arrows. A decision symbol has one transition arrow pointing to the diamond and two
or more transition arrows pointing out from the diamond to indicate possible transitions from
that point. Each transition arrow pointing out of a decision symbol has a guard condition. A
merge symbol has two or more transition arrows pointing to the diamond and only one transi-
tion arrow pointing from the diamond, to indicate multiple activity flows merging to continue
the activity. None of the transition arrows associated with a merge symbol has a guard condition.
Section 4.9 Formulating Algorithms: Counter-Controlled Repetition
• Counter-controlled repetition (p. 115) uses a variable called a counter (or control variable) to
control the number of times a set of statements execute.
• Counter-controlled repetition is often called definite repetition (p. 115), because the number of
repetitions is known before the loop begins executing.
• A total (p. 115) is a variable used to accumulate the sum of several values. Variables used to store
totals are normally initialized to zero before being used in a program.
• A local variable's declaration must appear before the variable is used in that method. A local vari-
able cannot be accessed outside the method in which it's declared.
• Dividing two integers results in integer division—the calculation's fractional part is truncated.
Section 4.10 Formulating Algorithms: Sentinel-Controlled Repetition
• In sentinel-controlled repetition (p. 119), a special value called a sentinel value (also called a sig-
nal value, a dummy value or a flag value) is used to indicate “end of data entry.”
• A sentinel value must be chosen that cannot be confused with an acceptable input value.
• Top-down, stepwise refinement (p. 120) is essential to the development of well-structured pro-
grams.
• Division by zero is a logic error.
• To perform a floating-point calculation with integer values, cast one of the integers to type double .
• Java knows how to evaluate only arithmetic expressions in which the operands' types are identi-
cal. To ensure this, Java performs an operation called promotion on selected operands.
• The unary cast operator is formed by placing parentheses around the name of a type.
Section 4.12 Compound Assignment Operators
• The compound assignment operators (p. 131) abbreviate assignment expressions. Statements of
the form
variable = variable operator expression ;
where operator is one of the binary operators + , - , * , / or % , can be written in the form
variable operator = expression ;
•The += operator adds the value of the expression on the right of the operator to the value of the
variable on the left of the operator and stores the result in the variable on the left of the operator.
Search WWH ::




Custom Search