Operators in Java

In this article we will discuss about what is operators and what are the operators supported in Java. So, let’s start exploring the concept.

Multiple types operators are supported by Java programming language. Operators are one of integral part of programming language. As with out operator we can not perform any single logical or arithmetical calculation/operation.


Operators are the symbols which instructs the compiler to perform some calculation/operation. An operator perform it’s operations on operands, in more simple words on variables and values.

Types of Operators:

Java supports many types of operators and based on their unique functionality they are categorized into a set of operators. They are

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

Let’s know little more about these operators.

1. Arithmetic Operator:

Arithmetic operators are used arithmetic/mathematical operations.

  • + : Addition operator : Adds two values.
  • - : Subtraction operator : Subtracts two values.
  • * : Multiplication operator : Multiply two values.
  • / : Division operator : Divides one value by another.
  • % : Modulo operator/Reminder operator : Returns reminder of division.

2. Assignment Operator:

Assignment operator is used to simply assign a value to a variable.

  • = : Assignment operator : Assign value to a variable.

3. Unary Operator:

Unary operator uses only one operand to perform operation. That’s why name is like Unary(means one) operator.

  • var++ and var-- : Postfix operator : First Assign value then increment or decrement.
  • ++var and --var : Prefix operator : First Increment or decrement¬† value hen assign.

4. Relational Operator:

Relational operators are used to check relation between two operands (variables/values). It is also called as comparison operator.

  • == : Equal to operator : Checks two values are equal.
  • != : Not equal to : Checks two values are not equal.
  • > : Greater than operator : Checks left operand is greater than right operand.
  • < : Less than operator : Checks left operand is less than right operand.
  • >= : Greater than equal to operator : Checks left operand is greater than or equal to right operand.
  • <= : Less than equal to operator : Checks left operand is less than or equal to right operand.

5. Logical Operator:

Logical operators are used to determine logic between two variables/values. Checks condition is true or false.

  • && : Logical AND : Returns True if both side conditions are true else false.
  • || : Logical OR : Returns True if any one side condition is true else false.
  • ! : Logical NOT : Returns the reversed result means true becomes false and vice versa.

6. Bitwise Operator:

Bitwise operators are used to perform any operation on individual bits.

  • ~ : Bitwise Complement : Returns 1 value as 0 and 0 value as 1.
  • | :¬† Bitwise OR : Returns 1 if at least one operand is 1
  • & : Bitwise AND : Returns 1 if both the value are 1
  • ^ : Bitwise XOR : Returns 1 if one of operand is 1, If both operands are 0 or 1 then returns 0

7. Shift Operator:

Shift operators are used to shift bits to left or right of a number.

  • << : Left Shift : Shifts all bits to left based on specified bits.
  • >> : Signed Right Shift : Shifts all bits to right based on specified bits.
  • >>> : Unsigned Right Shift : Performs right shift and vacant left bits filled with 0 instead of sign bit.

8. Ternary Operator:

It is another version of if-else operation. It is also called as conditional operator. As it uses 3 operands so it is called as ternary operator.

  • ? : Ternary Operator : (expression) ? value if true : value if false If condition is true then statement after ? and if condition is false then executes statement after :

9. Instanceof Operator:

Instanceof operator compares an object to a specified type.

  • instanceof : Checks if a reference variable is of a given type of object reference.

Have you mastered basic programming topics of java and looking forward to mastering advanced topics in a java programming language? Go with these ultimate Advanced java programs examples with output & achieve your goal in improving java coding skills.

Leave a Comment