In this blog we will discuss what is Operators in Java?What is the types of Operators in Java?
Operators in java:
Types Of Operators:
Java Unary Operator:
class UnaryOperatorExample{
public static void main(String args[]){
int x=11;
System.out.println(++x);//13
System.out.println(x--);//13 (12)
Java Arithmetic Operators:
class ArithmeticsOperatorExample{
public static void main(String args[]){
int a=10;
int b=2;
System.out.println(a+b);//12
System.out.println(a-b);//8
System.out.println(a*b);//20
}}
Java Shift Operator:
Java Left Shift Operator: The Java left shift operator << is used to shift all of the bits in a value to the left side of a specified number of times.
class LeftShiftOperatorExample{
public static void main(String args[]){
System.out.println(10<<2);//10*2^2=10*4=40
System.out.println(10<<3);//10*2^3=10*8=80
System.out.println(20<<2);//20*2^2=20*4=80
System.out.println(15<<4);//15*2^4=15*16=240
}}
Java Right Shift Operator: The Java right shift operator >> is used to move left operands value to right by the number of bits specified by the right operand.
class RightShiftOperatorExample{
public static void main(String args[]){
System.out.println(10>>2);//10/2^2=10/4=2
System.out.println(20>>2);//20/2^2=20/4=5
System.out.println(20>>3);//20/2^3=20/8=2
}}
Java AND Operator Example: Logical && and Bitwise &:
class AndOperatorExample{
public static void main(String args[]){
int x=10;
int y=5;
int z=20;
System.out.println(x<y&&x<z);//false && true = false
System.out.println(x<y&x<z);//false & true = false
}}
Java OR Operator Example: Logical || and Bitwise |:
class OrOperatorExample{
public static void main(String args[]){
int x=15;
int y=10;
int z=30;
System.out.println(x>y||x<z);//true || true = true
System.out.println(x>y|x<z);//true | true = true
}
}
Java Ternary Operator:
class TernaryOperatorExample{
public static void main(String args[]){
int x=5;
int y=8;
int min=(a<b)?a:b; //5
System.out.println(min);
}}








