Operators Java provides many types of operators which can be used according to the need is knows as Operators in JAVA. For example: +, -, *, / etc.

There are many types of operators in Java.

  • Unary Operator
  • Arithmetic Operator
  • Shift Operator
  • Relational Operator
  • Bitwise Operator
  • Logical Operator
  • Ternary Operator
  • Assignment Operator

Java Unary Operator

1. Example

Example of unary Operator

Input value

public class Operator{  
    public static void main(String args[]){  
    int x=5;  
    System.out.println(x++);  
    System.out.println(++x);  
Java Unary operator

screen shot of Unary Operator

Input values

Output value

Output Value

2. Example

Example of unary Operator

Input Values

public class Operator{  
    public static void main(String args[]){  
    int x=5;  
    System.out.println(x--);  
    System.out.println(--x); 
Java Unary operator

screen shot of Unary Operator

Input values

Output Value

Output Value

3. Example

Example of unary Operator

Input Values

public class Operator{  
    public static void main(String args[]){  
    int x=25;  
    int y=-30;  
    boolean t=true;  
    boolean o=false;  
    System.out.println(~x);
    System.out.println(~y);
    System.out.println(!t);
    System.out.println(!o);
    }}  
Java Unary Operator

screen shot of Unary Operator

Input values

Output Value

Output Values

JAVA Arithmetic Operator

Example of Arithmetic Operator

1. Example

Input Values

public class Operator{  
    public static void main(String args[]){  
    int x=52;  
    int y=25;  
    System.out.println(x+y);  
    System.out.println(x-y); 
    System.out.println(x*y);  
    System.out.println(x/y); 
    System.out.println(x%y); 
    }}  
JAVA Arithmetic Operator

Screen shot of Arithmetic Operator

Input Values

Output Value

Output Value

2.Example

Input Values

public class Operator{  
    public static void main(String args[]){  
    System.out.println(50+25/12*8-9*18/4);  
    }}  
JAVA Arithmetic Operator

Screen shot of Arithmetic Operator

Input Values

Output Value

Output Value

Shift Operators

There are three types of Shift Operator.

  • Left Shift Operator
  • Signed Right Shift Operator
  • Unsigned Right shift operator

Java Left Shift Operators

Example of Left Shift Operators

Input Values

public class Operator{  
    public static void main(String args[]){  
    System.out.println(25<<5);
    System.out.println(30<<6);
    System.out.println(35<<7);
    System.out.println(40<<8); 
    System.out.println(45<<9);
    System.out.println(40<<5);
    }}  
Java Left Shift Operator

Screen shot of Left Shift Operators

Input Values

Output Value

Input Values

Java Right Shift Operators

Example of Right shift Operator

Input Values

public class Operator{  
    public static void main(String args[]){  
    System.out.println(15>>2);
    System.out.println(30>>2);
    System.out.println(45>>3);
    System.out.println(60>>3); 
    System.out.println(75>>4);
    System.out.println(90>>12);
    }}  
Java Right Shift Operator

Screen shot of Right shift Operator

Input values

Output Value

Output Value

Java AND Operator

Example of AND Operator

Input Values

public class Operator{  
    public static void main(String args[]){  
    int x=35;  
    int y=28;  
    int z=49;  
    System.out.println(x<y&&x<z);  
    System.out.println(x<y&x<z);
    }}  
Java AND Operator

Screen Shot of AND Operator

Input Values

Output Value

Output Value

Java OR Operators

Example of OR Operators

Input Values

public class Operator{  
    public static void main(String args[]){  
    int x=65;  
    int y=25;  
    int z=35;  
    System.out.println(x>y||x<z); 
    System.out.println(x>y|x<z); 
    System.out.println(x>y||x++<z);
    System.out.println(x); 
    System.out.println(x>y|x++<z);
    System.out.println(y);
    System.out.println(z);
    }}
Java OR Operator

Screen shot of OR Operators

Input Values

Output Value

Output Value

Java Ternary Operator

Example of Ternary Operator

Input Values

public class Operator{  
    public static void main(String args[]){  
    int x=45;  
    int y=65;  
    int min=(x<y)?x:y;  
    System.out.println(min);  
    }}  
Java Ternary Operator

Screen shot of Ternary Operator

Input Values

Output Value

Output Value

Java Assignment Operator

Example of Assignment Operator

Input Value

public class Operator{  
    public static void main(String[] args){  
    int x=15;  
    x+=5;  
    System.out.println(x);  
    x-=2;
    System.out.println(x);  
    x*=3;  
    System.out.println(x);  
    x/=3;  
    System.out.println(x);  
    }}  
Java Assignment Operator

Screen shot of Assignment Operator

Input Values

Output Value

Output Value

If you have any queries regarding this article or if I have missed something on this topic, please feel free to add in the comment down below for the audience. See you guys in another article.

To know more about JAVA Wikipedia please click here .

Stay Connected Stay Safe, Thank you


Basic Engineer

Hey Readers! We have more than fifteen years of experience in Software Development, IoT, Telecom, Banking, Finance and Embedded domain. Currently we are actively working on Data Science, ML and AI with multiple market leaders worldwide. Happy Reading. Cheers!

0 Comments

Leave a Reply

Avatar placeholder

Your email address will not be published. Required fields are marked *