Operators in Java
Operator in Java is a symbol that is used to perform operations. For example: +, -, *, /
etc.
There are many types of operators in Java which are given below:
o Unary Operator,
o Arithmetic Operator,
o Shift Operator,
o Relational Operator,
o Bitwise Operator,
o Logical Operator,
o Ternary Operator and
o Assignment Operator.
Java Operator Precedence
Operator Category Precedence
Type
Unary postfix expr++ expr--
prefix ++expr --
expr +expr -expr ~ !
Arithmetic multiplicative * / %
additive + -
Shift shift << >> >>>
Relational comparison < > <= >= instanceof
equality == !=
Bitwise bitwise AND &
, bitwise ^
exclusive OR
bitwise |
inclusive OR
Logical logical AND &&
logical OR ||
Ternary ternary ? :
Assignment assignment = += -= *= /= %= &=
^= |= <<= >>= >>>=
Java Unary Operator
The Java unary operators require only one operand. Unary operators are used to
perform various operations i.e.:
466.4K
Stop DAMAGING Your iPhone's Battery! How to Maintain Battery Health!
o incrementing/decrementing a value by one
o negating an expression
o inverting the value of a boolean
Java Unary Operator Example: ++ and --
1. public class OperatorExample{
2. public static void main(String args[]){
3. int x=10;
4. System.out.println(x++);//10 (11)
5. System.out.println(++x);//12
6. System.out.println(x--);//12 (11)
7. System.out.println(--x);//10
8. }}
Output:
10
Operator in Java is a symbol that is used to perform operations. For example: +, -, *, /
etc.
There are many types of operators in Java which are given below:
o Unary Operator,
o Arithmetic Operator,
o Shift Operator,
o Relational Operator,
o Bitwise Operator,
o Logical Operator,
o Ternary Operator and
o Assignment Operator.
Java Operator Precedence
Operator Category Precedence
Type
Unary postfix expr++ expr--
prefix ++expr --
expr +expr -expr ~ !
Arithmetic multiplicative * / %
additive + -
Shift shift << >> >>>
Relational comparison < > <= >= instanceof
equality == !=
Bitwise bitwise AND &
, bitwise ^
exclusive OR
bitwise |
inclusive OR
Logical logical AND &&
logical OR ||
Ternary ternary ? :
Assignment assignment = += -= *= /= %= &=
^= |= <<= >>= >>>=
Java Unary Operator
The Java unary operators require only one operand. Unary operators are used to
perform various operations i.e.:
466.4K
Stop DAMAGING Your iPhone's Battery! How to Maintain Battery Health!
o incrementing/decrementing a value by one
o negating an expression
o inverting the value of a boolean
Java Unary Operator Example: ++ and --
1. public class OperatorExample{
2. public static void main(String args[]){
3. int x=10;
4. System.out.println(x++);//10 (11)
5. System.out.println(++x);//12
6. System.out.println(x--);//12 (11)
7. System.out.println(--x);//10
8. }}
Output:
10