java operator

Java Operators

Java Operators are used to perform mathematical or logical operations.

There are following types of Operators in Java :

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

1. Unary Operators

Unary operators need only one operand. They are used to increment or decrement a value.

There are two types of Unary Operators :

  • Postfix
  • Prefix

Postfix : In Postfix value is firstly used to compute the result then increment or decrement the value by 1.

Prefix : In Prefix value is firstly increment or decrement then compute the result value by 1.

Example :

2. Arithmetic Operators

Arithmetic Operators are used to perform mathematical operations.

Arithmetic operators like :

  • +
  • -
  • *
  • /
  • %
Example :

3. Relational Operators

Relational Operators are used to perform comparison between two vriables or it is used to compare two values.
It always return true or false based on condition.

Relational operators like :

  • < less than
  • > greater than
  • <= less than or equal to
  • >= greater than or equal to
  • == equal to
  • != not equal to
Example :

4. Bitwise Operators

Bitwise Operators are used to perform operation on bits (binary) numbers and also can apply with boolean.
In this case both expression can cheack either one condition is true or false.
Bitwise operators like :

  • & Bitwise AND
  • | Bitwise OR
  • ^ Bitwise XOR
  • ~ Bitwise NOT
Example :

5. Logical Operators

Logical operators are used to determine the logic between variables or values.
Logical Operators are used with boolean not for bits.

Logical Operators like :

  • && Logical AND
  • || Logical OR
  • ! Logical NOT

Example :

6. Condition Operators

Condition operator is a shorthand version of if-else statement.

(condition)?"true statement":"false statement";

Example :

7. Assignment Operators

Assignment Operators are used to assign a value to a variable.

Assignment Operators Like :

  • =
  • +=
  • -=
  • *=
  • /=
  • %=

Example :

8. Instanceof Operators

Instanceof operator in java is used to check whether the object is an instance of the specified type or not.
In java instanceof is a predefine keyword.
Return true if object is belongs to this type (class or interface).
Example :