Java Operator Precedence

Java Operator Precedence

What are Operators?

In the Article, we will Discuss about the Operator Precedence of java.
In Java, operators are special symbols or keywords that perform operations on one or more operands. operators are symbols or keywords that perform specific operations on one or more operands (values or variables). 

Java Operators Precedence:

Java operator precedence determines the order in which operators are evaluated in an expression. Operators with higher precedence are evaluated before operators with lower precedence. If two operators have the same precedence, then their associativity determines the order of evaluation.

Types Of Operators in Java:

In Java, there are Six types of Operators:

Java Example Program For Operator Precedence:

Run
import java.util.*;

public class Main{
    public static void main(String[] args){
        // Initializing the variables
        int a = 10;
        int b = 20;
        int c = 30;
        int d = 60;
        int e;

        //10 + 600
        e = a + b * c;          
        System.out.println(e);

        //30 * 30
        e = (a + b) * c;     
        System.out.println(e);

        //30 * 2        
        e = (a + b) * (d / c);  
        System.out.println(e);
    }
}

Output:

610
900
60

Explanation:

In the above Example of Operator precedence, We had taken different Integer type Variables and we are testing the precedence of different operators with the help of different Examples throughout the program.

Java Precedence And Associativity Table:

PrecedenceOperatorTypeAssociativity
15()
[]
·
Parentheses
Array subscript
Member selection

Left to Right

14++
Unary post-increment
Unary post-decrement
Left to Right
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 ANDLeft to right
6^Bitwise exclusive ORLeft to right
5|Bitwise inclusive ORLeft to right
4&&

Logical AND

Left to right
3||Logical ORLeft to right
2? :Ternary conditionalRight to left
1=
+=
-=
*=
/=
%=
Assignment
Addition assignment
Subtraction assignment
Multiplication assignment
Division assignment
Modulus assignment
Right to left

Prime Course Trailer

Related Banners

Get PrepInsta Prime & get Access to all 200+ courses offered by PrepInsta in One Subscription

Get over 200+ course One Subscription

Courses like AI/ML, Cloud Computing, Ethical Hacking, C, C++, Java, Python, DSA (All Languages), Competitive Coding (All Languages), TCS, Infosys, Wipro, Amazon, DBMS, SQL and others

Checkout list of all the video courses in PrepInsta Prime Subscription

Checkout list of all the video courses in PrepInsta Prime Subscription