Java operators are special symbols that perform specific operations on one or more
operands (variables or values). They are fundamental to manipulating data and
controlling program flow in Java.
Here are the main types of operators in Java:
• Arithmetic Operators:
Used for basic mathematical calculations.
• + (Addition)
• - (Subtraction)
• * (Multiplication)
• / (Division)
• % (Modulo - remainder after division)
• ++ (Increment - increases value by 1)
• -- (Decrement - decreases value by 1)
• Relational (Comparison) Operators:
Used to compare two operands and return a boolean result (true or false).
• == (Equal to)
• != (Not equal to)
• > (Greater than)
• < (Less than)
• >= (Greater than or equal to)
• <= (Less than or equal to)
• Logical Operators:
Used to combine or modify boolean expressions.
• && (Logical AND)
• || (Logical OR)
• ! (Logical NOT)
• Assignment Operators:
Used to assign values to variables.
• = (Simple assignment)
• Compound assignment operators like +=, -=, *=, /=, %=, etc. (e.g., x += 5 is
equivalent to x = x + 5)
• Unary Operators:
Operate on a single operand.
• + (Unary plus - indicates positive value)
• - (Unary minus - negates a value)
• ++ (Increment - already mentioned in arithmetic)
• -- (Decrement - already mentioned in arithmetic)
• ! (Logical NOT - already mentioned in logical)
• Bitwise Operators:
Perform operations on individual bits of integer types.
• & (Bitwise AND)
• | (Bitwise OR)
• ^ (Bitwise XOR)
• ~ (Bitwise NOT)
• Shift Operators:
Used to shift the bits of a number.
• << (Left shift)
• >> (Signed right shift)
• >>> (Unsigned right shift)
• Ternary Operator (Conditional Operator):
A shorthand for an if-else statement.
• condition ? expression1 : expression2
• instanceof Operator:
Used to check if an object is an instance of a particular class or interface.