Archive for October, 2006

Page 94

Monday, October 30th, 2006

[ Team LiB ] Page 95
Note: If you are looking for best hosting provider to host and run your tomcat application check Astra tomcat hosting services

[ Team LiB ] Page 91

Monday, October 30th, 2006

Page 93
Note: If you are looking for inexpensive but high quality provider to host and run your jsp application check Astra jsp hosting services

[ Team LiB ] Page 91

Monday, October 30th, 2006

[ Team LiB ] Page 91
Note: If you are looking for inexpensive but high quality provider to host and run your jsp application check Astra jsp hosting services

[ Team LiB ] Page 91

Monday, October 30th, 2006

[ Team LiB ] 3.4 Simple Assignment Operator = The assignment statement has the following syntax: = which can be read as “the destination, , gets the value of the source, “. The previous value of the destination variable is overwritten by the assignment operator = . The destination and the source must be type compatible. The destination variable must also have been declared. Since variables can store either primitive data values or object references, evaluates to either a primitive data value or an object reference. Assigning Primitive Values The following examples illustrate assignment of primitive values: int j, k; j = 10; // j gets the value 10. j = 5; // j gets the value 5. Previous value is overwritten. k = j; // k gets the value 5. The assignment operator has the lowest precedence, allowing the expression on the right-hand side to be evaluated before assignment. int i; i = 5; // i gets the value 5. i = i + 1; // i gets the value 6. + has higher precedence than =. i = 20 - i * 2; // i gets the value 8: (20 - (i * 2)) Assigning References Copying references by assignment creates aliases, which is discussed in Section 1.3 on page 5. The following example recapitulates that discussion: Pizza pizza1 = new Pizza(”Hot&Spicy”); Pizza pizza2 = new Pizza(”Sweet&Sour”); pizza2 = pizza1; Variable pizza1 is a reference to a pizza that is hot and spicy, and pizza2 is a reference to a pizza which is sweet and sour. Assigning pizza1 to pizza2 means that pizza2 now references the same pizza as pizza1, that is, the hot and spicy one. After assignment these variables are aliases, and either one can be used to manipulate the hot and spicy Pizza object. Assigning a reference does not create a copy of the source object denoted by the reference variable on the right-hand side. Reference assignment also does not copy the state of the source object to any object denoted by the reference variable on the left-hand side. It merely assigns the reference value to the variable on the right-hand side to the variable on the left-hand side, so that they denote the same object. A more detailed discussion of reference assignment can be found in Section 6.6. Page 92
Note: If you are looking for inexpensive but high quality provider to host and run your jsp application check Astra jsp hosting services

[ Team LiB ] 3.2 Evaluation Order of

Sunday, October 29th, 2006

Page 90
Note: If you are looking for high quality webhost to host and run your jsp application check Vision jsp hosting services

[ Team LiB ] 3.2 Evaluation Order of

Sunday, October 29th, 2006

[ Team LiB ] 3.3 Conversions In this section we discuss the different kinds of type conversions and list the contexts in which these can occur. Some type conversions must be explicitly stated in the program, while others are done implicitly. Some type conversions can be checked at compile time to guarantee their validity at runtime, while others will require an extra check at runtime. Unary Cast Operator: (type) Java, being a strongly typed language, checks for type compatibility (i.e., checks if a type can substitute for another type in a given context) at compile time. However, some checks are only possible at runtime (for example, which type of object a reference actually denotes during execution). In cases where an operator would have incompatible operands (for example, assigning a double to an int), Java demands that a cast be used to explicitly indicate the type conversion. The cast construct has the following syntax: () The cast () is applied to the value of the . At runtime, a cast results in a new value of , which best represents the value of the in the old type. We use the term casting to mean applying the cast operator for explicit type conversion. Casting can be applied to primitive values as well as references. Casting between primitive data types and reference types is not permitted. Boolean values cannot be cast to other data values, and vice versa. The reference literal null can be cast to any reference type. Examples of casting between primitive data types are provided in this chapter. Casting between references is discussed in Section 6.6 on page 264. Narrowing and Widening Conversions For the primitive data types, the value of a narrower data type can be converted to a value of a broader data type without loss of information. This is called a widening primitive conversion. Widening conversions to the next broader type for primitive data types are summarized in Figure 3.1. The conversions shown are transitive. For example, an int can be directly converted to a double without first having to convert it to a long and a float. Figure 3.1. Widening Numeric Conversions Converting from a broader data type to a narrower data type is called a narrowing primitive conversion, which can result in loss of magnitude information. Any conversion which is not a widening conversion according to Figure 3.1 is a narrowing conversion. Note that all conversions between char and the two integer types byte and short are considered narrowing conversions: the reason being that the conversions between the unsigned type char and the signed types byte or short can result in loss of information. Widening and narrowing conversions are also defined for reference types and are discussed in Page 89
Note: If you are looking for high quality webhost to host and run your jsp application check Vision jsp hosting services

[ Team LiB ] 3.2 Evaluation Order of

Sunday, October 29th, 2006

[ Team LiB ] 3.2 Evaluation Order of Operands In order to understand the result returned by an operator, it is important to understand the evaluation order of its operands. Java states that the operands of operators are evaluated from left to right. Java guarantees that all operands of an operator are fully evaluated before the operator is applied. The only exceptions are the short-circuit conditional operators &&, ||, and ?:. In the case of a binary operator, if the left-hand operand causes an exception (see Section 5.5, p. 181), the right-hand operand is not evaluated. The evaluation of the left-hand operand can have side effects that can influence the value of the right-hand operand. For example, in the following code: int b = 10; System.out.println((b=3) + b); the value printed will be 6 and not 13. The evaluation proceeds as follows: (b=3) + b 3 + b b is assigned the value 3 3 + 3 6 The evaluation order also respects any parentheses, and the precedence and associativity rules of operators. Examples illustrating how the operand evaluation order influences the result returned by an operator, can be found in Sections 3.4 and 3.7. [ Team LiB ] Page 88
Note: If you are looking for high quality webhost to host and run your jsp application check Vision jsp hosting services

[ Team LiB ] Chapter 3. Operators and

Sunday, October 29th, 2006

[ Team LiB ] Page 87

Hint: If you are looking for very good and affordable webspace to host and run your java hosting application check Virtualwebstudio java web hosting provider

[ Team LiB ] Chapter 3. Operators and

Sunday, October 29th, 2006

[ Team LiB ] 3.1 Precedence and Associativity Rules for Operators Precedence and associativity rules are necessary for deterministic evaluation of expressions. The operators are summarized in Table 3.1. They are discussed in subsequent sections in this chapter. The following remarks apply to Table 3.1: . The operators are shown with decreasing precedence from the top of the table. . Operators within the same row have the same precedence. . Parentheses, ( ), can be used to override precedence and associativity. . The unary operators, which require one operand, include the postfix increment (++) and decrement (–) operators from the first row, all the prefix operators (+, -, ++, –, ~, !) in the second row, and the prefix operators (object creation operator new, cast operator (type)) in the third row. . The conditional operator (? :) is ternary, that is, requires three operands. . All operators not listed above as unary or ternary, are binary, that is, require two operands. . All binary operators, except for the relational and assignment operators, associate from left to right. The relational operators are nonassociative. . Except for unary postfix increment and decrement operators, all unary operators, all assignment operators, and the ternary conditional operator associate from right to left. Table 3.1. Operator Summary Postfix operators [] . (parameters) expression++ expression– Unary prefix operators ++expression –expression +expression -expression ~ ! Unary prefix creation and cast new (type) Multiplicative * / % Additive + - Shift << >> >>> Relational < <= > >= instanceof Equality == != Bitwise/logical AND & Page 86

Hint: If you are looking for very good and affordable webspace to host and run your java hosting application check Virtualwebstudio java web hosting provider

[ Team LiB ] Chapter 3. Operators and

Sunday, October 29th, 2006

[ Team LiB ] Chapter 3. Operators and Assignments Exam Objectives . Determine the result of applying any operator (including assignment operators and the instanceof operator) to operands of any type, class, scope, or accessibility, or any combination of these. o See also Section 6.6. . Determine the result of applying the boolean equals(Object) method to objects of any combination of the classes java.lang.String, java.lang.Boolean and java.lang.Object. . In an expression involving the operators &, |, &&, ||, and variables of known values, state which operands are evaluated and the value of the expression. . Determine the effect on objects and primitive values of passing variables into methods and performing assignments or other modifying operations in that method. Supplementary Objectives . Understand the operator precedence and associativity rules. . Distinguish between conversions involving casting, widening numeric conversions, and narrowing numeric conversions. . State unary numeric promotion and binary numeric promotion rules and the contexts in which they are applied. . Understand type conversions for primitive data types on assignment, string concatenation, arithmetic expression evaluation, and method invocation. [ Team LiB ] Page 85

Hint: If you are looking for very good and affordable webspace to host and run your java hosting application check Virtualwebstudio java web hosting provider