![]() |
VOOZH | about |
Java operators are symbols used to perform operations on variables and values. They play a key role in expressions, calculations, and decision-making in programs. Operators help simplify complex logic into concise statements.
Arithmetic Operators are used to perform arithmetic operations on primitive numeric data types such as int, float, and double.
Sum: 13 Difference: 7 Multiplication: 30 Division: 3 Modulus: 1
Explanation:
Unary Operators need only one operand. They are used to increment, decrement, or negate a value.
Postincrement : 10 Preincrement : 12 Postdecrement : 10 Predecrement : 8
Explanation:
a and b). a++) returns the value first, then increments it. ++a) increments first, then returns the updated value. --).The assignment operator assigns a value from the right-hand side to a variable on the left. Since it has right-to-left associativity, the right-hand value must be declared or constant.
Initial: 10 After +5: 15 After *2: 30 After -5: 25 After /2: 12 After %3: 0
Explanation:
Note: Use compound assignments (+=, -=) for cleaner code.
Relational Operators are used to check for relations like equality, greater than, and less than. They return boolean results after the comparison and are extensively used in looping statements as well as conditional if-else statements.
a > b: true a < b: false a >= b: true a <= b: false a == c: false a != c: true
Explanation:
Logical Operators are used to perform "logical AND" and "logical OR" operations, similar to AND gate and OR gate in digital electronics. They have a short-circuiting effect, meaning the second condition is not evaluated if the first is false.
x && y: false x || y: true !x: false
Explanation:
The Ternary Operator is a shorthand version of the if-else statement. It has three operands and hence the name Ternary. The general format is,
Max of three numbers = 30
Explanation:
(condition) ? value1 : value2. These operators perform operations at the bit level.
d & e : 8 d | e : 14 d ^ e : 6 ~d : -11 d << 2 : 40 e >> 1 : 6 e >>> 1 : 6
Explanation:
The instanceof operator is used for type checking. It can be used to test if an object is an instance of a class, a subclass, or an interface. The general format,
true true false
Explanation:
The common mistakes that can occur when working with Java Operators are listed below: