# Operators in Java

Rate this post

Hello everyone, in the previous topic we were talking about Ratan Tata. Today we are going to talk about the Operators in Java.

Contents

# Operators in Java

Following are the types of operators in Java-

## Arithmetic Operator

They are used to performing simple arithmetic operations on primitive data types.

Java Arithmetic Operator Example is given below-

## Java Modulo Operator

Java Modulo operator or modulus operator is used to get the remainder when we divide an integer with another integer.

The % character is the modulus operator in Java.

The modulus operator always returns an integer. If we try to use the modulo operator with any other type of variable, we will get a compilation error.

Some examples of modulus operators with negative integer

## Java Unary Operator

The Java unary operators require only one operand.

The increment operator (–)- It is used for incrementing the value by 1. There are two varieties of increment operator which is-

• Post-Increment- Value is first used for computing the result and then incremented.
• Pre-Increment- Value is incremented first and then the result is computed. The decrement operator (–)- Is used for decrementing the value by 1. There are two varieties of decrement operators are
1. Post-decrement – Value is first used for computing the result and then decremented.
2. Pre-Decrement- Value is decremented first and then the result is computed.

## Relational Operator

Relational Java operators are used to checking the equality of operands. We can also use them for the comparison of two or more values.

## Logical Operators

A logical operator is a symbol or word used to connect two or more expressions such that the value of the compound expression produced depends only on that of the original expressions and on the meaning of the operator. Common logical operators include AND, OR, and NOT.

## Bitwise Operator

Bitwise operators are used for manipulating data at the bit level, also called bit-level programming. Bit-level programming mainly consists of 0 and 1.

### Bitwise AND, OR and XOR

Bitwise one’s complement operator (~)

Bitwise one’s complement operator will invert the binary bits.

If a bit is 1, it will change it to 0.

If the bit is 0, it will change it to 1.

Bitwise complement operator

0 to 1and 1 to 0

### Bitwise Shift Operators

• >> (Signed right shift)- In Java, the operator >>‘ is signed right shift operator. All integers are signed in Java, and it is fine to use >> for negative numbers. The operator ‘>>‘ uses the sign bit (left-most bit) to fill the trailing positions after the shift. If the number is negative, then 1 is used as a filler and if the number is positive, then 0 is used as a filler.
• >>> (Unsigned right shift)- In Java, the operator >>>‘ is unsigned right shift operator. It always fills 0 irrespective of the sign of the number.

## Conditional Operator

The conditional operator is also known as the ternary operator This operator consists of three operands and is used to evaluate Boolean expressions The goal of the operator is to decide which value should be assigned to the variable.

## Assignment Operator

The assignment operator () is the most commonly used binary operator in Java it evaluates the operand on the right-hand side and then assigns the resulting value to a variable on the left-hand side. The right operand can be a variable, constant function call, or expression The type of right operand must be type compatible with the left operand.

Such type of assignment statement in which a single value is given to a number of variables is called a multiple assignment statement ie value 3 is assigned to the variables x,y, and z.  The assignment operator () has a right to left associatively

## Compound Assignment Operators

The compound-assignment operators combine the simple-assignment operator with another binary operator. Compound-assignment operators perform the operation specified by the additional operator, then assign the result to the left operand.

So, that is all for today guys see you in our next blog. If you like our article please don’t forget to share with others & follow our Instagram page for your daily dose of Motivation.

Thank You,

Regards

Grooming Urban

## General FAQ

### What are the types of operators in Java?

Following are the types of operators in Java-
1. Arithmetic operators
2. Java Modulo operator
3. Java Unary operators
4. Relational Java operators
5. Logical operators
6. Bitwise operators
7. Conditional operator
8. Assignment operator
9. Compound-assignment operators

### What is the arithmetic operator?

Arithmetic operators are used to performing simple arithmetic operations on primitive data types.

### What is the Java modulo operator?

Java Modulo operator or modulus operator is used to get the remainder when we divide an integer with another integer.
The % character is the modulus operator in Java. The modulus operator always returns an integer. If we try to use the modulo operator with any other type of variable, we will get a compilation error.

### What are Java unary operators?

The Java unary operators require only one operand and the increment operator (–)- It Is used for incrementing the value by 1.

### What are Relational Java operators?

Relational Java operators are used to checking the equality of operands. We can also use them for the comparison of two or more values.

### What is the logical operator?

A logical operator is a symbol or word used to connect two or more expressions such that the value of the compound expression produced depends only on that of the original expressions and on the meaning of the operator. Common logical operators include AND, OR, and NOT.

### What are bitwise operators?

Bitwise operators are used for manipulating data at the bit level, also called bit-level programming. Bit-level programming mainly consists of 0 and 1.

### What is the conditional operator?

The conditional operator is also known as the ternary operator This operator consists of three operands and is used to evaluate Boolean expressions The goal of the operator is to decide which value should be assigned to the variable.

### What are assignment operators?

The assignment operator () is the most commonly used binary operator in Java it evaluates the operand on the right-hand side and then assigns the resulting value to a variable on the left-hand side. The right operand can be a variable, constant function call, or expression The type of right operand must be type compatible with the left operand.

### What are compound-assignment operators?

The compound-assignment operators combine the simple-assignment operator with another binary operator. Compound-assignment operators perform the operation specified by the additional operator, then assign the result to the left operand.

Sharing Is Caring: Kumar Shanu Sinha

An aspiring MBA student formed an obsession with Management Related Concept, Digital Marketing, Leadership, and Personality Development now helping others to improve in their studies and personality as well.