86 Introduction to Java Applications Chapter (Web hosting directory) 2 Common
86 Introduction to Java Applications Chapter 2 Common Programming Error 2.17 Placing a semicolon immediately after the right parenthesis of the condition in an ifstructure is normally a logic error. The semicolon will cause the body of the if structure to be empty, so the ifstructure itself will perform no action, regardless of whether its condition is true. Worse yet, the intended body statement of the ifstructure will now become a statement in sequence with the ifstructure and will always be executed. Notice the use of spacing in Fig. 2.20. Remember that white-space characters, such as tabs, newlines and spaces, are normally ignored by the compiler. So, statements may be split over several lines and may be spaced according to the programmer s preferences without affecting the meaning of a program. It is incorrect to split identifiers and string literals. Ideally, statements should be kept small, but it is not always possible to do so. Good Programming Practice 2.19 A lengthy statement may be spread over several lines. If a single statement must be split across lines, choose breaking points that make sense, such as after a comma in a comma- separated list, or after an operator in a lengthy expression. If a statement is split across two or more lines, indent all subsequent lines until the end of the statement. The chart in Fig. 2.21 shows the precedence of the operators introduced in this chapter. The operators are shown from top to bottom in decreasing order of precedence. Notice that all of these operators, with the exception of the assignment operator, =, associate from left to right. Addition is left associative, so an expression like x+y+zis evaluated as if it had been written as (x+y)+z. The assignment operator, =, associates from right to left, so an expression like x=y=0is evaluated as if it had been written as x=(y=0), which, as we will soon see, first assigns the value 0to variable yand then assigns the result of that assignment, 0, to x. Good Programming Practice 2.20 Refer to the operator precedence chart (see the complete chart in Appendix C) when writing expressions containing many operators. Confirm that the operations in the expression are performed in the order you expect. If you are uncertain about the order of evaluation in a complex expression, use parentheses to force the order, exactly as you would do in algebraic expressions. Be sure to observe that some operators, such as assignment, =, associate from right to left rather than from left to right. Operators Associativity Type () left to right parentheses * / % left to right multiplicative + -left to right additive < <= > >= left to right relational == != left to right equality = right to left assignment Fig. 2.2121 Precedence and associativity of the operators discussed so far. Fig. Copyright 1992 2002 by Deitel & Associates, Inc. All Rights Reserved. 7/2/01
Note: If you are looking for best quality webspace to host and run your tomcat application check Vision shared web hosting services