# What are Operators in Java?

In this tutorial, we will clarify what are operators in Java. We will also focus on why operators are used in Java and also see how they are used in a Java program.

## What are Operators in Java?

Operators in Java are special symbols that have a predefined meaning in the Java compiler that perform some operation with one or more operands and then return an output (value). There are eight different types of operators available in Java.

1. Arithmetic Operators
2. Relational Operators
3. Logical Operators
4. Assignment Operators
5. Bitwise Operators
6. Shift Operators
7. Unary Operators
8. Ternary Operators

## What are Arithmetic Operators?

Arithmetic Operators are used in arithmetic or mathematical type of operations. These operations can be multiplication, division, addition, etc.

## What are Relational Operators?

Relational Operators are used as a condition to check whether the output is true or false.

## What are Logical Operators?

A Logical operator is a special symbol that takes one or two conditions (based on the operator) and returns the logical output in the form of true/false.

## What are Assignment Operators?

An Assignment Operator is basically used to simply assign a value to a variable.

## What are the Bitwise Operators?

Bitwise Operators are used to performing per bit of operations. If there are two values say 4 and 6, then the bitwise operation will be performed on their binary form.

## What are Shift Operators?

Shift Operators are used for shifting purposes. Shift Operators are used to shifting bits if a number either left to right or right to left. Shifting also causes a number to either multiply or divide based on the type of shifting.

There are two types of shifting that can be done in Java:

1. Left Shift (<<)
2. Right Shift (>>)

Shift Operators are represented by pairs of (less than/greater than) symbols.

## What are the Unary Operators?

Unary Operators are used to performing unary operations on a single operand. They are used to either increment a value or decrement a value by 1.

## What are the Ternary Operators?

A Ternary operator has one condition and two outputs. When the condition is True, the first output is returned, if not then the second output is returned.

The basic form of a Ternary operator is:
(condition) ? (Output 1) : (Output 2)

### Example:

```class Program {
public static void main (String agmt[]) {

//Using Assignment Operator
int n1 = 25;
int n2 = 58;
int n3 = 76;

//Using Relational Operator
if(n2 > n1)
System.out.println("n2 is greater than n1");

//Using Arithmetic Operator
n3 = n1 + n2;

//Using Logical Operator
if (n3>n1  && n3>n2)
System.out.println("n3 is the greatest number");
}
}```

### Output

n2 is greater than n1

n3 is the greatest number

In the above example, we can see the variables n1, n2, and n3 are being assigned values using an Assignment Operator (=). The if-condition is using a Relational Operator (>) to compare the values of n2 and n1. Finally, we have used a Logical Operator (&&) to check if the conditions on either side are true are not.