![]() |
Java Operator Precedence and Associativity Table |
Java Operator Precedence and Associativity Table
Java
Operator: A java operator can be used in mathematical operations performed.
it is performed by java operands mathematical symbols like (+),(-),(*),(/), etc.
the operator can be used in every programming language. the operator has defined operations perform in operands.
Types of operators in Java
1. Arithmetic Operator 2. Relational Operator 3. Logical Operator 4. Assignment operator 5. Bitwise Operator 6. Increment operator 7. Decrement Operator 8. Conditional Operator |
Arithmetic operator in Java
Arithmetic Operator: A arithmetic operation is a
used mathematical operation performed.
It is many operations performed like addition, subtraction, multiplication, and division.
Example of Arithmetic operator
Addition: a+b or 10+10=20
Here a is operands value (+) Addition is operator and b is
operands. It can be used for additional operations performed.
Subtraction: a-b or 20-10=10
Here a is operands value (-) Subtraction sign is operator and b is
operands. It can be used as Subtraction operations performed.
Multiplication: a*b or 10*10=100
Here a is operands value (*) Multiplication sign is operator and b
is operands. It can be used for Multiplication operations performed.
Division: a/b or 10/5=2
Here a is operands value (/) Division sign operator and b is
operands. It can be used for Division operations performed.
Modules: a%b or 10%3=1
Here a is operands value (%) Modules sign operator and b is
operands. It can be used to Modules operations performed.
Java Arithmetic Operator Table
Sign |
Operation |
Example |
(+) |
Addition |
(x+y) |
(-) |
Subtraction |
(x-y) |
(/) |
Multiplication |
(x*y) |
(*) |
Division |
(x/y) |
(%) |
Modules |
(x%y) |
Arithmetic Operator in Java?
class codeswithbaby { public static void main(String[] args() { int a=35 int b=6; System. out.println("Addition:"+(a+b)); System. out.println("Subtraction:"+(a-b)); System. out.println("Multiplication:"+(a*b)); System. out.println("Division:"+(a/b)); System. out.println("Modulus:"+(a%b)); } } *****OUTPUT***** Addition:41 Subtraction:29 Multiplication:210 Division:5.8333333 Modulus:5 |
Relational Operator in Java
Relational Operator: A Java Relational operator has used the comparison of the two operands. It can be using equal operands and condition checks in this operator. The relational operator is the very most useful operator.
Java Relational Operator Table
Sign | Operation | Example |
(==) | Equal | (a=b) |
(!=) | Not Equal To | (!a=b) |
(>) | Greater Than | (a>b) |
(<) | Less Than | (a<b) |
(>=) | Greater Than or Equal | (a>=b) |
(<=) | Less Than or Equal | (a<=b) |
Relational Operator in Java
class codeswithbaby { public static void main(String[] args() { int a=10; int b=10; if(a==b) { System.out.println("value of a and b are equal"); } if(a!=100) { System.out.println("value not equal to"); } if(a>5) { System.out.println("value a is grater than 5"); } if(a<50) { System.out.println("value a is less than 50"); } if(a>=10) { System.out.println("value a is grater than or equal to 10"); } if(a<=10) { System.out.println("value a is less than or equal to 10"); } } *****OUTPUT***** value of a and b are equal value not equal to value a is greater than 5 value a is less than 50 value a is greater than or equal to 10 value a is less than or equal to 10 |
Logical
Operator in Java
Java
Logical Operators: Java Language provides three logical operators. logical
Operator tests more than one condition to make decisions.
Types
of Logical Operator
1.
&& AND
2.
|| OR
3.
! NOT
1.
AND Operator can be used decisions are two values.AND Operator two values are
True AND Operator return True. But two values are anyone False AND Operator
return False.
2.
OR operator performs a logical condition on two expressions. if or Operator can
be two expressions are True OR Operator return true. But any of the expressions
are False OR Operator return True.
3.
NOT operator is a very easy Operator. it can be used conditions are True NOT
Operator returns False and condition are False NOT Operator returns True.
Logical Operator in Java?
class codeswithbaby
{
public static void main(String[] args()
{
int x=10;
int y=60;
int z=40;
if(x>y&&x>z)
System.out.println("x is grater");
if(y>x&&y>z)
System.out.println("y is grater");
if(z>x&&z>y)
}
}
*****OUTPUT*****
y is grater
Logical Operator in Java
Java
Logical Operators: Java Language provides three logical operators. logical
Operator tests more than one condition to make decisions.
Types
of Logical Operator
1.
&& AND
2.
|| OR
3.
! NOT
1.
AND Operator can be used decisions are two values.AND Operator two values are
True AND Operator return True. But two values are anyone False AND Operator
return False.
2.
OR operator performs a logical condition on two expressions. if or Operator can
be two expressions are True OR Operator return true. But any of the expressions
are False OR Operator return True.
3. NOT operator is a very easy Operator. it can be used conditions are True NOT Operator returns False and condition are False NOT Operator returns True.
class codeswithbaby { public static void main(String[] args() { int x=10; int y=60; int z=40; if(x>y&&x>z) System.out.println("x is grater"); if(y>x&&y>z) System.out.println("y is grater"); if(z>x&&z>y) } } *****OUTPUT***** y is grater |
Assignment Operator Table
Sign | Operation | Example |
(=) | a=b | (a=b) |
(+=) | a+=b | (a=a+b) |
(-=) | a-=b | (a=a-b) |
(*=) | a*=b | (a=a*b) |
(/=) | a/=b | (a=a/b) |
(%=) | a%=b | (a=a%b) |
Assignment Operator in Java?
class codeswithbaby { public static void main(String[] args() { int a=10,b=5; a+=b; System.out.println("Assignment Addition:"+a); int a1=10,b1=5; a1-=b1; System.out.println("Assignment Subtraction:"+a1); int a2=10,b2=5; a2*=b2; System.out.println("Assignment multiplication:"+a2); int a3=10,b3=5; a3/=b3; System.out.println("Assignment Division:"+a3); int a4=10,b4=5; a4%=b4; System.out.println("Assignment Division:"+a4); } } *****OUTPUT***** Assignment Addition:15 Assignment Subtraction:5 Assignment Multiplication:50 Assignment Division:2 Assignment Moduls:1 |
Increment Operator in Java
Increment
Operators: Increment Operators are useful operators generally used.like++x and
x++ means x=x+1.
pre-increment
first adds one to the operand and then the result is assigned to the variable
on the left.
post-increment
first assigns the value to the variable on the left and then increments the
operand.
Increment Operator in Java?
class codeswithbaby { public static void main(String[] args() { int a=5; int b=10; System.out.println("pre-increment operator:+(++a)); System.out.println("post-increment operator:+(b+1)); } } *****OUTPUT***** pre-increment operator:6 post-increment operator:11 |
Decrement Operator in Java
Java
Decrement: A Decrement Operator used the decrease the value. like --x and x--.
Pre-decrement
first less one to the operands and then the result is assigned to the variable
on the left.
Post-decrement
first assigns the value to the variables on the left and then decrements the
operands.
Decrement Operator in Java?
class codeswithbaby { public static void main(String[] args() { int a=5; int b=10; System.out.println("pre-decrement operator:+(--a)); System.out.println("post-decrement operator:+(b-1)); } *****OUTPUT***** pre-decrement operator:4 post-decrement operator:9 |
Bitwise Operator in Java
Java
Bitwise Operator: A Bitwise operator is an operation performed on the data bit
level. the bitwise operator is also shifted bit right to left.
Note: Bitwise operators are not
allowed to float and double.
Bitwise Operator Table
Sign |
Operation |
Example |
(&) |
Bitwise AND | (a&b) |
(|) |
Bitwise OR | (a|b) |
(<<) |
Bitwise LEFT | (a<<b) |
(>>) |
Bitwise RIGHT | (a>>b) |
Java Unary Operator
Unary Operator: A Java unary operators require only one operand. Unary operators are used for performing various operations in a java programming language.
Java Unary Operator
public class codeswithbaby{ public static void main(String args[]){ int a=10; int b=10; System.out.println(a++ + ++a); System.out.println(b++ + b++);
} } *****OUTPUT***** 22 21 |
Java Unary Operator
public class codeswithbaby { public static void main(String args[]) { int x=10; System.out.println(x++); System.out.println(++x); System.out.println(x--); System.out.println(--x); } } *****OUTPUT***** 10 12 12 10 |