3.11. Review Questions

 
[Page 88 ( continued )]

Chapter Summary

  • Java has eight primitive data types. The preceding chapter introduced byte , short , int , long , float , double , and char . This chapter introduced the boolean type that represents a true or false value.

  • The Boolean operators && , & , , , ! , and ^ operate with Boolean values and variables . The relational operators ( < , <= , == , != , > , >= ) work with numbers and characters , and yield a Boolean value.

  • When evaluating p1 && p2 , Java first evaluates p1 and then evaluates p2 if p1 is true ; if p1 is false , it does not evaluate p2 . When evaluating p1 p2 , Java first evaluates p1 and then evaluates p2 if p1 is false ; if p1 is true , it does not evaluate p2 . Therefore, && is referred to as the conditional or short-circuit AND operator, and is referred to as the conditional or short-circuit OR operator.


    [Page 89]
  • Java also provides the & and operators. The & operator works exactly the same as the && operator, and the operator works exactly the same as the operator with one exception: the & and operators always evaluate both operands. Therefore, & is referred to as the unconditional AND operator, and is referred to as the unconditional OR operator.

  • Selection statements are used for building selection steps into programs. There are several types of selection statements: if statements, if ... else statements, nested if statements, switch statements, and conditional expressions.

  • The various if statements all make control decisions based on a Boolean expression. Based on the true or false evaluation of the expression, these statements take one of two possible courses.

  • The switch statement makes control decisions based on a switch expression of type char , byte , short , int , or boolean .

  • The keyword break is optional in a switch statement, but it is normally used at the end of each case in order to terminate the remainder of the switch statement. If the break statement is not present, the next case statement will be executed.

  • The operands of a binary operator are evaluated from left to right. No part of the right-hand operand is evaluated until all the operands before the binary operator are evaluated.

  • The operators in arithmetic expressions are evaluated in the order determined by the rules of parentheses, operator precedence, and associativity.

  • Parentheses can be used to force the order of evaluation to occur in any sequence. Operators with higher precedence are evaluated earlier. The associativity of the operators determines the order of evaluation for operators of the same precedence.

  • All binary operators except assignment operators are left-associative, and assignment operators are right-associative.

 


Introduction to Java Programming-Comprehensive Version
Introduction to Java Programming-Comprehensive Version (6th Edition)
ISBN: B000ONFLUM
EAN: N/A
Year: 2004
Pages: 503

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net