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:

[wp_table id=6914/]

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

[wp_table id=6919/]
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

[wp_table id=6923/]

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

[wp_table id=6924/]
[wp_table id=6926/]

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

[wp_table id=6943/]

 

Bitwise Operators

[wp_table id=6945/]
Binary form for Bitwise operator
[wp_table id=6948/]

Operator precedence

[wp_table id=6956/]

Suggested for you

Operators in C++

Operators in C

Operators in Python

Keywords in Java language

Data types in Python

Data type in C language

Data type in C++ language

Hollow world program in Java

Data type and variable in Java

History of Java

Download and  install  Java

How to install Java

Feature of Java programming language

Flavour and versions of Java Programming language

 

 

 

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

Python code to Calculate sum of odd and even in a list

Python code to Calculate sum of odd and even in a list In this tutorial,…

9 hours ago

How to find reverse number using method in Java

How to find reverse number using method In this article, we will discuss the concept…

3 days ago

C# inverted full pyramid star pattern

C# inverted full pyramid star pattern In this article, we will discuss the concept of…

3 weeks ago

C# Full Pyramid star pattern program

C# Full Pyramid star pattern program In this article, we will discuss the concept of…

1 month ago

Program to count vowels,consonants,words, characters and space in Java

Program to count vowels, consonants, words, characters and space in Java In this article, we…

1 month ago

How to print multiplication table using Array in C++ language

How to print multiplication table using Array in C++ language In this post, we will…

1 month ago