Read a Java expression by grouping precedence first, then tracing operand types, promotions, side effects, and whether short-circuit evaluation skips the right operand.
Arithmetic operators work with numeric values. The remainder operator (%) is especially useful for checking even numbers, cycling indexes, and extracting digits.
public class ArithmeticOperators {
public static void main(String[] args) {
int a = 17;
int b = 5;
System.out.println(a + b); // 22
System.out.println(a - b); // 12
System.out.println(a * b); // 85
System.out.println(a / b); // 3, integer division
System.out.println(a % b); // 2, remainder
System.out.println(a % 2 == 0 ? "Even" : "Odd");
}
}
Relational operators compare values and produce boolean results. Logical operators combine boolean expressions. Java uses short-circuit evaluation for && and ||.
public class LogicalOperators {
public static void main(String[] args) {
int age = 22;
boolean hasId = true;
boolean canEnter = age >= 18 && hasId;
boolean needsHelp = age < 18 || !hasId;
System.out.println(canEnter);
System.out.println(needsHelp);
}
}
Assignment stores a value in a variable. Compound assignment combines an operation and assignment. Increment and decrement are compact but should be used carefully in complex expressions.
public class AssignmentOperators {
public static void main(String[] args) {
int score = 10;
score += 5; // score = score + 5
score *= 2; // score = score * 2
int post = score++;
int pre = ++score;
System.out.println(score);
System.out.println(post);
System.out.println(pre);
}
}
Bitwise operators work at the binary level. The ternary operator is a compact if-else expression. The instanceof operator checks whether an object is compatible with a type.
public class SpecialOperators {
public static void main(String[] args) {
int marks = 76;
String result = marks >= 35 ? "Pass" : "Fail";
System.out.println(result);
Object value = "Core Java";
if (value instanceof String text) {
System.out.println(text.toUpperCase());
}
}
}
Operators perform calculations, comparisons, assignments, and logical decisions. Java includes arithmetic operators such as + and *, relational operators such as > and ==, logical operators such as && and ||, assignment operators such as +=, and the ternary operator for compact conditional values.
The difficult part is usually precedence and short-circuit behavior. Multiplication runs before addition, && can skip the right side when the left side is false, and || can skip the right side when the left side is true. Parentheses are not a weakness; they are often the clearest way to show the intended order.
double total = 1250;
boolean member = true;
double payable = member && total >= 1000
? total * 0.90
: total;
System.out.println(payable);
&& stops when the left side is false. & evaluates both sides.
When both operands are integers, Java produces an integer result. Cast an operand to double when you need a fraction.
No. Use equals for contents; == checks whether both references point to the same object.
Explore 500+ free tutorials across 20+ languages and frameworks.