Answer» The below image shows the different types of operators available in Java.
The following table describes each category of operators along with examples of each type.
| Operator Type | Description | Operators |
|---|
| Unary Operators | Only one operand is required for unary operators. They are used to increase, decrease, or negate a value. | ++, --, +, -, ! |
|---|
| Arithmetic Operators | Simple arithmetic operations on primitive data types are performed with them. | +, – , *, / , % |
|---|
| Assignment Operators | The assignment operator is used to give any variable a value. It has right-to-left associativity, which means that the value given on the right-hand side of the operator is assigned to the variable on the left. As a result, the right-hand side value must be declared before use or be a constant. | =, +=, -=, *=, /=, %=, &=, ^=, |
|---|
| Relational Operators | These operators are used to verify for equality, greater than, and less than relationships. They return a boolean result following comparison and are frequently used in looping and conditional if-else statements. | >, <, >=, <=, ==, != |
|---|
| Logical Operators | These operators conduct “logical AND” and “logical OR” operations, which are analogous to the AND and OR gates in digital electronics. One point to bear in mind is that if the first condition is false, the second condition is not examined, resulting in a short-circuiting effect. Used to test for a variety of variables before making a choice. | &&, || |
|---|
| Ternary Operator | The ternary operator is a condensed form of the if-else expression. The name ternary comes from the fact that it has three operands. | ?: |
|---|
| Bitwise Operators | These operators are used to manipulate the bits of a number individually. They can be applied to any integer type. They’re used to do Binary indexed tree updates and query operations. | &, |, ^ |
|---|
| Shift Operators | These operators shift the bits of a number to the left or right, multiplying or dividing it by two, accordingly. When we need to multiply or divide a number by two, we can use them. | <<, >>, >>> |
|---|
Precedence and Associativity of operators in Java:- When dealing with hybrid equations involving more than one type of operator, precedence and associative principles are applied. Because there might be multiple valuations for the same equation, these criteria determine which component of the equation to analyse first. The precedence of operators is shown in the table below in decreasing order of magnitude, with the highest precedence at the top and the lowest precedence at the bottom.
| Operators | Associativity | Type |
|---|
| ++, – | Right to Left | Unary postfix | | ++, --, +, -, ! | Right to Left | Unary prefix | | /, *, % | Left to Right | Multiplicative | | +, - | Left to Right | Additive | | <, <=, >, >= | Left to Right | Relational | | ==, !== | Left to Right | Equality | | & | Left to Right | Boolean Logical AND | | ^ | Left to Right | Boolean Logical Exclusive OR | | | | Left to Right | Boolean Logical Inclusive OR | | && | Left to Right | Conditional AND | | || | Left to Right | Conditional OR | | ?: | Right to Left | Conditional | | =, +=, -=, *=, /=, %= | Right to Left | Assignment |
|