Home Segments Top Top Previous Next

89: Mainline

Of course, you can always deploy parentheses around subexpressions whenever the Java compiler's interpretation of the entire expression is not the interpretation that you want:

6 + 3 * 2       // Value is 12, rather than 18 
(6 + 3) * 2     // Value is 18, rather than 12 

You can also use parentheses to make your intentions clear. In the following, for example, the parentheses are not required, but many programmers insert them anyway, just to make the meaning of the expression absolutely clear:

6 + 3 * 2       // Value is clearly 12 
6 + (3 * 2)     // Value is even more clearly 12 

Inserting such parentheses is a good idea, especially when you are working with large expressions.