Archive for October, 2006

Page 103

Tuesday, October 31st, 2006

Page 103

Hint: This post is supported by Gama hrvatski web hosting services

Page 103

Tuesday, October 31st, 2006

Page 104

Hint: This post is supported by Gama hrvatski web hosting services

Page 100

Monday, October 30th, 2006

Page 102
Note: If you are looking for cheap and inexpensive provider to host and run your tomcat application check Actions tomcat hosting services

Page 100

Monday, October 30th, 2006

Page 101
Note: If you are looking for cheap and inexpensive provider to host and run your tomcat application check Actions tomcat hosting services

Page 100

Monday, October 30th, 2006

Page 100
Note: If you are looking for cheap and inexpensive provider to host and run your tomcat application check Actions tomcat hosting services

[ Team LiB ] Page 97

Monday, October 30th, 2006

Page 99

Hint: This post is supported by Gama besplatan domen provider

[ Team LiB ] Page 97

Monday, October 30th, 2006

[ Team LiB ] 3.5 Arithmetic Operators: *, /, %, +, The arithmetic operators are used to construct mathematical expressions as in algebra. Their operands are of numeric type (which includes the char type). Arithmetic Operator Precedence and Associativity In Table 3.3, the precedence of the operators is in decreasing order, starting from the top row, which has the highest precedence. Unary subtraction has higher precedence than multiplication. The operators in the same row have the same precedence. Binary multiplication, division, and remainder operators have the same precedence. The unary operators have right associativity, and the binary operators have left associativity. Table 3.3. Arithmetic Operators Unary + Addition -Subtraction Binary * Multiplication / Division % Remainder + Addition -Subtraction Evaluation Order in Arithmetic Expressions Java guarantees that the operands are fully evaluated from left to right before an arithmetic binary operator is applied. Of course, if evaluation of an operand causes an exception, the subsequent operands will not be evaluated. In the expression a + b * c, the operand a will always be fully evaluated before the operand b, which will always be fully evaluated before the operand c. However, the multiplication operator * will be applied before the addition operator +, respecting the precedence rules. Note that a, b, and c can be arbitrary arithmetic expressions that have been determined to be the operands of the operators. Range of Numeric Values As we have seen, all numeric types have a range of valid values (Section 2.2, p. 28). This range is given by the constants named MAX_VALUE and MIN_VALUE, which are defined in each numeric wrapper class. The arithmetic operators are overloaded, meaning that the operation of an operator varies depending on the type of its operands. Floating-point arithmetic is performed if any operand of an operator is of floating-point type, otherwise, integer arithmetic is performed. Values that are out-of-range or are results of invalid expressions, are handled differently depending on whether integer or floating-point arithmetic is performed. Integer Arithmetic Integer arithmetic always returns a value that is in range, except in the case of integer division by zero and remainder by zero, which causes an ArithmeticException (see the division operator / and the remainder operator % below). A valid value does not necessarily mean that the result is correct, as demonstrated by the following examples: int tooBig = Integer.MAX_VALUE + 1; // -2147483648 which is Page 98

Hint: This post is supported by Gama besplatan domen provider

[ Team LiB ] Page 97

Monday, October 30th, 2006

[ Team LiB ] Page 97

Hint: This post is supported by Gama besplatan domen provider

Page 94

Monday, October 30th, 2006

[ Team LiB ] Review Questions 3.1 Given char c = ‘A’; What is the simplest way to convert the character value in c into an int? Select the one correct answer. a. int i = c; b. int i = (int) c; c. int i = Character.getNumericValue(c); 3.2 What will be the result of attempting to compile and run the following class? public class Assignment { public static void main(String[] args) { int a, b, c; b = 10; a = b = c = 20; System.out.println(a); } } Select the one correct answer. a. The code will fail to compile, since the compiler will recognize that the variable c in the assignment statement a = b = c = 20; has not been initialized. b. c. d. The code will fail to compile because the assignment statement a = b = c = 20; is illegal. The code will compile correctly and will display 10 when run. The code will compile correctly and will display 20 when run. 3.3 What will be the result of attempting to compile and run the following program? public class MyClass { public static void main(String[] args) { String a, b, c; c = new String(”mouse”); a = new String(”cat”); b = a; a = new String(”dog”); c = b; System.out.println(c); } Page 96
Note: If you are looking for best hosting provider to host and run your tomcat application check Astra tomcat hosting services

Page 94

Monday, October 30th, 2006

Page 94
Note: If you are looking for best hosting provider to host and run your tomcat application check Astra tomcat hosting services