Archive for October, 2006

[ Team LiB ] Page 112

Tuesday, October 31st, 2006

Page 114
Note: If you are looking for cheap and quality provider to host and run your java application check Astra java hosting services

[ Team LiB ] Page 112

Tuesday, October 31st, 2006

[ Team LiB ] Page 112
Note: If you are looking for cheap and quality provider to host and run your java application check Astra java hosting services

[ Team LiB ] Page 112

Tuesday, October 31st, 2006

[ Team LiB ] Review Questions 3.10 Which statements are true? Select the three correct answers. a. The result of the expression (1 + 2 + “3″) would be the string “33″. b. The result of the expression (”1″ + 2 + 3) would be the string “15″. c. The result of the expression (4 + 1.0f) would be the float value 5.0f. d. The result of the expression (10/9) would be the int value 1. e. The result of the expression (’a’ + 1) would be the char value ‘b’. 3.11 What happens when you try to compile and run the following program? public class Prog1 { public static void main(String[] args) { int k = 1; int i = ++k + k++ + + k; System.out.println(i); } } Select the one correct answer. a. The program will not compile. The compiler will complain about the expression ++k + k++ + + k. b. The program will compile and will print the value 3 when run. c. The program will compile and will print the value 4 when run. d. The program will compile and will print the value 7 when run. e. The program will compile and will print the value 8 when run. 3.12 Which is the first incorrect line that will cause a compile time error in the following program? public class MyClass { public static void main(String[] args) { char c; int i; c = ‘a’; // (1) i = c; // (2) i++; // (3) c = i; // (4) Page 113
Note: If you are looking for cheap and quality provider to host and run your java application check Astra java hosting services

[ Team LiB ] 3.6 The Binary String

Tuesday, October 31st, 2006

[ Team LiB ] Page 110

Hint: This post is supported by Gama besplatan domen provider

[ Team LiB ] 3.6 The Binary String

Tuesday, October 31st, 2006

[ Team LiB ] 3.7 Variable Increment and Decrement Operators: ++, - Variable increment (++) and decrement (–) operators come in two flavors: prefix and postfix. These unary operators have the side effect of changing the value of the arithmetic operand, which must evaluate to a variable. Depending on the operator used, the variable is either incremented or decremented by 1. These operators are very useful for updating variables in loops where only the side effect of the operator is of interest. Increment Operator ++ Prefix increment operator has the following semantics: ++i adds 1 to i first, then uses the new value of i as the value of the expression. It is equivalent to the following statements. i += 1; result = i; return result; Postfix increment operator has the following semantics: j++ uses the current value of j as the value of the expression first, then adds 1 to j. It is equivalent to the following statements: result = j; j += 1; return result; Decrement Operator - Prefix decrement operator has the following semantics: –i subtracts 1 from i first, then uses the new value of i as the value of the expression. Postfix decrement operator has the following semantics: j–uses the current value of j as the value of the expression first, then subtracts 1 from j. Examples of Increment and Decrement Operators // (1) Prefix order: increment operand before use. int i = 10; int k = ++i + –i; // ((++i) + (–i)). k gets the value 21 and i becomes 10. –i; // Only side effect utilized. i is 9. (expression statement) // (2) Postfix order: increment operand after use. long i = 10; long k = i++ + i–; // ((i++) + (i–)). k gets the value 21L and i becomes 10L. i++; // Only side effect utilized. i is 11L. (expression statement) An increment or decrement operator, together with its operand can be used as an expression statement (see Section 4.3, p. 113). Page 111

Hint: This post is supported by Gama besplatan domen provider

[ Team LiB ] 3.6 The Binary String

Tuesday, October 31st, 2006

[ Team LiB ] 3.6 The Binary String Concatenation Operator + The binary operator + is overloaded in the sense that the operation performed is determined by the type of the operands. When one of the operands is a String object, the other operand is implicitly converted to its string representation and string concatenation is performed. Non-String operands are converted as follows: . For a operand of a primitive data type, its value is converted to a String object with the string representation of the value. . Values like true, false, and null are represented by string representations of these literals. A reference variable with the value null also has the string representation “null” in this context. . For all reference value operands, a string representation is constructed by calling the toString() method on the referred object. Most classes override this method from the Object class in order to provide a more meaningful string representation of their objects. Discussion of the toString() method can be found in Section 10.2. The result of the concatenation is always a new String object. The String class is discussed in Section 10.5. String theName = ” Uranium”; theName = ” Pure” + theName; // ” Pure Uranium” String trademark1 = 100 + “%” + theName; // “100% Pure Uranium” (1) The integer literal 100 is implicitly converted to the string “100″ before concatenation. This conversion is corresponds to first creating an object of the wrapper class Integer, which represents the integer 100, and then creating a string from this object by using the toString() method supplied by this class: new Integer(100).toString(); Note that using the character literal ‘%’, instead of the string literal “%” in line (1) above, does not give the same result: String trademark2 = 100 + ‘%’ + theName; // “137 Pure Uranium” Integer addition is performed by the first + operator: 100 + ‘%’, that is, (100 + 37). Caution should be exercised as the + operator might not be applied as intended, as shown by the following example: System.out.println(”We put two and two together and get ” + 2 + 2); The above statement prints “We put two and two together and get 22″ and not “We put two and two together and get 4″. The first integer literal 2 is promoted to a String literal “2″ for the first concatenation, resulting in the String literal “We put two and two together and get 2″. This result is then concatenated with the String literal “2″. The whole process proceeds as follows: “We put two and two together and get ” + 2 + 2 “We put two and two together and get ” + “2″ + 2 “We put two and two together and get 2″ + 2 “We put two and two together and get 2″ + “2″ “We put two and two together and get 22″ Page 109

Hint: This post is supported by Gama besplatan domen provider

[ Team LiB ] Page 106

Tuesday, October 31st, 2006

[ Team LiB ] Page 108

Hint: If you are looking for high quality and reliable webspace provider to host and run your jsp hosting application check Virtualwebstudio jsp web hosting provider

[ Team LiB ] Page 106

Tuesday, October 31st, 2006

[ Team LiB ] Review Questions 3.4 Which of the following expressions will be evaluated using floating-point arithmetic? Select the three correct answers. a. 2.0 * 3.0 b. 2 * 3 c. 2/3 + 5/7 d. 2.4 + 1.6 e. 0×10 * 1L * 300.0 3.5 What is the value of the expression (1 / 2 + 3 / 2 + 0.1)? Select the one correct answer. a. 1 b. 1.1 c. 1.6 d. 2 e. 2.1 3.6 What will be the result of attempting to compile and run the following program? public class Integers { public static void main(String[] args) { System.out.println(0×10 + 10 + 010); } } Select the one correct answer. a. The program will not compile. The compiler will complain about the expression 0×10 + 10 + 010. b. When run, the program will print 28. c. When run, the program will print 30. d. When run, the program will print 34. e. When run, the program will print 36. Page 107

Hint: If you are looking for high quality and reliable webspace provider to host and run your jsp hosting application check Virtualwebstudio jsp web hosting provider

[ Team LiB ] Page 106

Tuesday, October 31st, 2006

[ Team LiB ] Page 106

Hint: If you are looking for high quality and reliable webspace provider to host and run your jsp hosting application check Virtualwebstudio jsp web hosting provider

Page 103

Tuesday, October 31st, 2006

Page 105

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