Home Segments Top Top Previous Next

88: Mainline

When an expression contains two operators of equal precedence, such as multiplication and division, the Java compiler handles the expression as shown in the following examples:

6 / 3 * 2       // Equivalent to (6 / 3) * 2 = 4, 
                // rather than to 6 / (3 * 2) = 1 
6 * 3 / 2       // Equivalent to (6 * 3) / 2 = 9, 
                // rather than to 6 * (3 / 2) = 6 

Thus, in Java, the multiplication and division operators are said to associate from left to right. Most operators associate from left to right, but certain operators do not, as shown in Segment 95 and in the table provided in AppendixA.