Operators

All type of the operators in Java with example

All type of the operators in Java with the example

In this tutorial, we will learn about All type of the operators in Java programming language with example

Operators are special symbols, using to perform the specific task on the operand

Java provides a rich set of the operator (different type)to manipulate variables. We can divide all the Java operators into the following groups:

Operator in Java
  • Arithmetic Operators
  • Assignment Operators
  • Relational Operators
  • Unary Operator
  • Logical Operators
  • Bitwise Operator

Arithmetic Operators

Arithmetic operators are used in mathematical expressions in the same way that they are used in algebra. The following table lists the arithmetic operators:

Example

class arithmet{
public static void main(String args[]){
int a=20;
int b=12;
System.out.println("addition of a+b :"+(a+b));
System.out.println("subtraction of a-b :"+(a-b));
System.out.println("multiplication of a*b :"+(a*b));
System.out.println("division of a/b : "+(a/b));
System.out.println("modulus of a%b :"+(a%b));
//+ ,-, *, /, % - arithmetic operator
}
}

 

When the above code is compiled and executed, it produces the following results

addition of a+b  :32
subtraction of a-b  :8
multiplication of a*b  :240
division od a/b :1
modulus of a/b :8

Assignment Operator

Assignment operators assign values from right side of operands to the left side of the operand.

Following assignment, operators are supported in Java programming language

Example

 

class assignope1{
public static void main(String args[]){
int a=10;
System.out.println("Value of a+=6 is :"+(a+=6));//same as a=a+6;
System.out.println("Value of a-=5 is :"+(a-=5));//same as a=a-5;
System.out.println("Value of a*=4 is :"+(a*=4));//same as a=a*4;
System.out.println("Value of a/=3 is : "+(a/=3));//same as a=a/5;
System.out.println("Value of a%=2 is : "+(a%=2));//same as a=a%5;

//Assignment operator
}
}

 

 

When we execute above program, it will produce the following result

Addition value  of a+=6 is  :16
Subtraction value 2 of a-=5 is   :11
Multiplication value 3 of a*=4 is  :44
Division value 4 of a/=3 is   :14
modules Value 5 of a%=2 is   :0

 

Relational Operators

Relational operators show the relationship between the right side of operands and the left side operand.

Following relational operators are supported in Java programming language

Example

public class Relationalop{
    public static void main (String args[]){
    int a=10;
    int b=12;
    System.out.println("The result of a==b = "+(a==b));
    System.out.println("The result of a!=b = "+(a!=b));
    System.out.println("The result of a>b = "+(a>b));
    System.out.println("The result of a<b = "+(a<b));
    System.out.println("The result of a>=b = "+(a>=b));
    System.out.println("The result of a<=b = "+(a<=b));
    }
}

 

 

When we execute the above program, it will produce the following result

The result of a==b = false
The result of a!=b = true
The result of a>b = false
The result of a<b = true
The result of a>=b = false
The result of a<=b = true

Unary Operator

Following unary operators are supported in Java programming language

Example

class unaryope1{
public static void main(String args[]){
int a=10;
System.out.println("Value of a++ is :"+(a++));
System.out.println("Value of a-- is :"+(a--));
System.out.println("Value of ++a is :"+(++a));
System.out.println("Value of --a is : "+(--a));

//++, -- - unary operator
}
}

When we execute the above program, it will produce the following result

Value of a++ is :10
Value of a-- is :11
Value of ++ais :11
Value of --ais :10

 

 

Logical Operators

Following logical operators are supported in Java

 

Bitwise Operators

Binary form for Bitwise operator

Operator precedence

Suggested for you

Operators in C++

Operators in C

Operators in Python

 

 

 

Operator in Python
Karmehavannan

I am Mr S.Karmehavannan. Founder and CEO of this website. This website specially designed for the programming learners and very especially programming beginners, this website will gradually lead the learners to develop their programming skill.

Recent Posts

PHP Star Triangle pattern program

PHP Star Triangle pattern program In this tutorial, we will discuss about PHP Star Triangle…

1 month ago

PHP Full Pyramid pattern program

PHP Full Pyramid pattern program In this tutorial, we will discuss about PHP Full Pyramid…

2 months ago

5 methods to add two numbers in Java

5 methods to add two numbers in Java In this tutorial, we will discuss the…

2 months ago

Python Full Pyramid star pattern program

Python full Pyramid star pattern program In this tutorial, we will discuss  the concept of…

5 months ago

Write a function or method to convert C into F -Entered by user

Write a function or method to convert C into F -Entered by the user In…

10 months ago

How to write a function or method to convert Celsius into Fahrenheit

How to write a function or method to convert Celsius into Fahrenheit In this tutorial,…

10 months ago