Basic operators in java
Types of Operators in Java:
Java operator precedence
Arithmetic Operators
- Arithmetic Operators
- Bit-wise Operators
- Logical Operators
- Relational Operators
- Assignment Operators
- Misc Operators
Java operator precedence
Arithmetic Operators
- Arithmetic operators are used in mathematical expressions.
- Following are the arithmetic operators in java.
- + : Addition
- - : Subtraction
- * : Multiplication
- / : Division
- % : Modulus
Bit wise Operators:
- Bit wise operators operates on individual bits of operands.
- Following are the Bit-wise operators in java.
- Bitwise operators in java
- ~ : Bit wise unary not
- & : Bit wise And
- | : Bit wise OR
- ^ : Bit wise Exclusive OR
- >> : Shift Right
- >>> : Shift right zero fill
- << :Shift left
Logical Operators:
- && : Logical AND
- || : Logical OR
- ! : Logical NOT
Relational Operators in java
- == : Equal to
- != : Not Equal to
- < : Less Than
- > : Greater Than
- >= : Greater Than or Equal to
- <= : Less Than or Equal to
Assignment Operators:
- = : Simple Assignment
- += : Add and assign
- -= : Subtract and assign
- *= : Multiply and assign
- %= : Modulus and assign
- /= : Divide and assign
- &= : Bit wise AND assignment
- |= : Bit wise assignment OR
- ^= : Bit wise Exclusive OR assignment
- >>= : Shift Right assignment
- >>>= : Shift right zero fill assignment
- <<= : Shift left assignment
Misc Operators:
Increment and Decrement operators:
- ++ : increment
- -- : decrement
Conditional Operator: (?:)
- Also known as ternary operator
- Example: int a= 1>2?1:2;
Ternary operator in java
Instanceof Operator
- Instance of operator is used to test whether that object is belong to that class type or not.
- If that object belongs to that class it returns true .otherwise it returns false.
- Instance of operator is also known as comparison operator.because it compares with the instance of type.