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:
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 operators assign values from right side of operands to the left side of the operand.
Following assignment, operators are supported in Java programming language
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 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
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
Following logical operators are supported in Java
Suggested for you
Data type in C++ language
Data type and variable in Java
Feature of Java programming language
Flavour and versions of Java Programming language
Python code to Calculate sum of odd and even in a list In this tutorial,…
How to find reverse number using method In this article, we will discuss the concept…
C# inverted full pyramid star pattern In this article, we will discuss the concept of…
C# Full Pyramid star pattern program In this article, we will discuss the concept of…
Program to count vowels, consonants, words, characters and space in Java In this article, we…
How to print multiplication table using Array in C++ language In this post, we will…