Skip to main content
Logo image

Java, Java, Java: Object-Oriented Problem Solving, 2022E

Section 5.12 Chapter Summary

Subsection 5.12.1 Technical Terms

action input-process-output representation
binary digit (bit) named constant round off error
binary operator operand short-circuit evaluation
boundary value operator overloading type conversion
cast operation precedence order unary operator
class constant promotion Unicode

Subsection 5.12.2 Summary of Important Points

  • The way we approach a problem can often help or hinder us in our ability to solve it. Choosing an appropriate representation for a problem is often the key to solving it.
  • In order to evaluate complex expressions, it is necessary to understand the precedence order and associativity of the operators involved. Parentheses can always be used to override an operator’s built-in precedence.
  • Java provides several types of integer data, including the 8-bit byte, 16-bit short, 32-bit int, and 64-bit long types. Unless otherwise specified, integer literals are represented as int data in a Java program.
  • Java provides two types of floating-point data, the 32-bit float type and the 64-bit double type. Unless otherwise specified, floating-point literals are represented as double data.
  • In general, if a data type uses n bits in its representation, then it can represent \(2^n\) different values.
  • The fact that Java’s primitive types are defined in terms of a specific number of bits is one way that Java promotes platform independence.
  • It is necessary to distinguish integer operations from floating-point operations even though the same symbols are used. For example, (7/2) is 3, while (7.0/2) is 3.0.
  • In revising a class that is used by other classes it is important to preserve as much of the class’s interface as possible.
  • In Java, character data are based on the Unicode character set, which provides \(2^{16}\) = 65,536 different character codes. To provide backward compatibility with the ASCII code, the first 128 characters are the ASCII coded characters.
  • Java operators are evaluated according to the precedence hierarchy shown in the table below. The lower the precedence number, the earlier an operator is evaluated. So the operators at the top of the table are evaluated before operators that occur below them in the table. Operators at the same precedence level are evaluated according to their association, either left to right (L to R) or right to left (R to L).
    Order Operator Operation Association
    0 ( ) Parentheses
    1 ++ -- Postincrement, postdecrement L to R
    1 . dot operator L to R
    2 ++ -- Preincrement, predecrement R to L
    2 + - unary plus, unary minus R to L
    2 ! Boolean NOT R to L
    3 (type) new Type cast, object instantiation R to L
    4 * / % Multiplication, division, modulus L to R
    5 + - Addition, subtraction L to R
    5 + String concatenation L to R
    6 < > <= >= Relational operators L to R
    7 == != Equality operators L to R
    8 ^ Boolean XOR L to R
    9 && Boolean AND L to R
    10 || Boolean OR L to R
    11 = += -= *= /= %= assignment operators R to L

Solutions 5.12.3 Solutions to Self-Study Exercises

5.2 Boolean Data and Operators
5.2.1 Boolean (or Logical) Operations

Self-Study Exercises

5.2.3 Short-Circuit Evaluation

Self-Study Exercises

5.5 Numeric Data and Operators
5.5.1 Primitive Numeric Types

Self-Study Exercises

5.5.2 Arithmetic Operators

Self-Study Exercises Evaluate Decimal Expressions.

5.5.3 Numeric Promotion Rules

Self-Study Exercises

5.5.4 Operator Precedence

Self-Study Exercises

5.5.6 Assignment Operators

Self-Study Exercises Evaluate Shortcut Expressions.

5.5.7 Relational Operators

Self-Study Exercises Evaluate Precedence with Increment Expressions.

5.7 Numeric Processing Examples
5.7.2 Example: Converting Fahrenheit to Celsius

Self-Study Exercises

5.7.3 Example: Using Class Constants

Self-Study Exercises OneRowNim with Constants.

5.7.5 Example: A Winning Algorithm for One Row Nim

Self-Study Exercises

5.8 From the Java Library java.text.NumberFormat

Self-Study Exercise

5.9 Character Data and Operators
5.9.1 Character to Integer Conversions

Self-Study Exercises
You have attempted of activities on this page.