Hierarchy of operators in Java
Operators are the most frequently used terminology in any area of programming, and it helps in various approaches to efficiently solve daily life problems by computer programming.
The simple addition of numbers to complex graph analysis operators plays a key role. Operator precedence is one such topic which is so important to generate correct output. You can learn about the operator hierarchy and its precedence in this article.
Operator precedence
Operator precedence ranks the operator's priority when applied to two operands, and it means computing the expression based on the priority of the operator.
The operator precedence specifies how two expressions are linked and control the grouping of operators with operands in an expression and how an expression will be evaluated.
Precedence and associativity are the two must remember things while evaluating an expression. The operator precedence specifies how two expressions are linked, and it controls the pairing of operators with arithmetic operations in an expression and how an equation will be evaluated.
When grouping various types of drivers with their operands, priority takes precedence. It only makes sense if an expression has more than one operator with greater or lesser precedence. The operators with the greatest precedence are examined first. If we wish to review lower-priority operators first, we must use parenthesis to group operands and then evaluate.

Arithmetic operators :
These mathematical operators may execute various simple or complicated arithmetic operations on the operands, which are primitive data types. These operators consist of various unary and binary operators that may be used with one or two operands. Let's take a look at the various arithmetic operators that Java has to offer.
- Addition ( + )
- Subtraction ( - )
- Multiplication ( * )
- Division ( / )
- Modulo Division ( % )
Unary Operator :
Unary operators in Java can perform any operation with just one operand, such as increment, decrement, negation, etc. It consists of several operators operating on the same operand, including arithmetic, logic, and other operators. Let's examine the various unary operators in more detail and see how they operate.
- Unary minus ( - )
- “ NOT ” Operator ( ! )
- Increment ( + + )
- Decrement ( - - )
- Bitwise complement ( ~ )
Assignment Operator :
Variables are assigned values using these operators. The assignment operator's left operand is a variable, while the assignment operator's right operand is a value. The right-side value must have the same data type as the argument on the left. The compiler will produce an error message if not. This shows that the assignment operators are associative, meaning that they assign the value provided on the right side of the equation to the value on the left.
Relational Operator :
Java Relational Operators are a collection of binary operators used to test for relationships between two operands, such as equality, greater than, less than, and so on. They produce a logical result following the evaluation and are commonly used in iterating expressions, contextual if-else declarations, and so on.
- “ equal to ” operator ( = = )
- “ Not Equal to ” operator ( ! = )
- Greater than ( > )
- Less than ( < )
Logical operators :
The logical " AND ", " " OR ", and " NOT " operations, which are comparable to the " AND " and " OR " gates in digital electronics, are carried out using logical operators. They are utilized to combine two or more limitations or to add to the evaluation of the initial condition being taken into account. One thing to keep in mind is that the conditioned response is not checked if the initial condition is incorrect, which can have a short-circuiting impact. Used widely to test for various conditions in order to make a choice.
- AND Operator ( & & )
- OR operator ( | | )
- NOT operator ( ! )
Ternary operator:
The only conditional operator that accepts three operands is the Java ternary operator. It is a one-liner substitute for the if-then-else statement that is often used in Java programming. We may use the ternary operator instead of if-else conditions, or we can use nested ternary operators to swap conditions. Although it follows the same algorithm as an if-else statement, the conditional operator takes up less space and aids in the writing of if-else statements.
Variable = ( condition ) ? expression1 : expression2
Bitwise Operators:
These operators are used to manipulate the individual bits of a number. They are compatible with all integer types. They are used to conduct binary indexed tree update and query operations.
- Bitwise AND operator ( & )
- Bitwise OR operator ( | )
- Bitwise XOR operator ( ^ )
- Bitwise Complement Operator ( ~ )
Shift operator:
Left shift operator ( < < ) :
The left shift operator is an operator which performs its action at the bits level of a binary Operator. That means when you perform a bitwise left Shift on any operator, and it shifts the position of that particular bit to its next higher bit representation in binary order.
Right Shift Operator ( > > ) :
The Right Shift Operator adjusts the bits of an integer to the right by a specified n place. The right shift operator is represented by the symbol “ >> ” , which stands for twofold larger than. The definition of x >> n is to shift the bits x to the right n specified places.
Precedence | Operator | Type | Associativity |
15 | ( ) [ ] · | Parentheses Array subscript Member selection | Left to Right |
14 | + + - - | Unary post-increment Unary post-decrement | Right to left |
13 | + + - - + - ! ~ (type) | Unary pre-increment Unary pre-decrement Unary plus Unary minus Unary logical negation Unary bitwise complement Unary type cast | Right to left |
12 | * / % | Multiplication Division Modulus | Left to right |
11 | + - | Addition Subtraction | Left to right |
10 | < < > > > > > | Bitwise left shift Bitwise right shift with sign extension Bitwise right shift with zero extension | Left to right |
9 | < < = > > = instanceof | Relational less than Relational less than or equal Relational greater than Relational greater than or equal Type comparison (objects only) | Left to right |
8 | == ! = | Relational is equal to Relational is not equal to | Left to right |
7 | & | Bitwise AND | Left to right |
6 | ^ | Bitwise exclusive OR | Left to right |
5 | | | Bitwise inclusive OR | Left to right |
4 | & & | Logical AND | Left to right |
3 | | | | Logical OR | Left to right |
2 | ? : | Ternary conditional | Right to left |
1 | = + = - = * = / = % = | Assignment Addition assignment Subtraction assignment Multiplication assignment Division assignment Modulus assignment |