[Page 236 (continued)] Technical Terms action binary digit (bit) binary operator boundary value cast operation class constant input-process-output lexical-order named constant operand operator overloading precedence order promotion representation round-off error short-circuit evaluation type conversion unary operator Unicode Summary of Important Points The way we approach a problem can often help or hinder 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. [Page 237]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 2n different values. Defining primitive types 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 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 216 = 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 Table 5.15. 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). Table 5.15. Java operator precedence and associativity tableOrder | Operator | Operation | Association |
---|
0 | ( ) | Parentheses | | 1 | ++ -- . | Postincrement, postdecrement, dotOperator | L to R | 2 | ++ -- + - ! | Preincrement, predecrement Unary plus, unary minus, 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, string concatenation | L to R | 6 | < > <= >= | Relational operators | L to R | 7 | == != | Equality operators | L to R | 8 | L | Boolean XOR | L to R | 9 | && | Boolean AND | L to R | 10 | || | Boolean OR | L to R | 11 | = += -= *= /= %= | Assignment operators | R to L |
|