Operator precedence in Java determines the order in which operators are evaluated in an expression. Operators with higher precedence are evaluated before operators with lower precedence unless parentheses are used.
Java evaluates expressions using predefined precedence rules. For example, multiplication has higher precedence than addition.
// Demonstrating operator precedence in Java
public class OperatorPrecedence {
public static void main(String[] args) {
int result = 10 + 5 * 2;
System.out.println(result);
}
}
The output will be 20 because multiplication (5 * 2) is evaluated before addition.
Click the expressions below to see how Java evaluates them interactively: