Operators

Operators are used to perform some operations between operands.

int  a = 2 , b = 3;
System.out.println(a+b);OUTPUT:
5

Below are the different types of operators

  • Arithmetic operators
  • Assignment operators
  • Comparison operators
  • Logical operators
  • Bitwise operators

Assignment Operator:

Assignment operator are used to assign value to a variable. = (equal) symbol is use as an assignment operator.

In the below code value 3 is assigned to a with the assignment operator.

int a = 3;

Comparisons Operator:

It uses to compare two operands.

Bitwise Operator:

Bitwise operators are used to perform operation on bits of a number. This can be applied to the integer types, long, int, short, char, and byte. We have four types of bitwise operations:

  1. Bitwise AND (&)
  2. Bitwise OR (|)
  3. Bitwise XOR (^)
  4. Bitwise Complement (~)

Bitwise AND (&) Operator:

Bitwise operator can be easily understood by below table:

Example:

What will the output for bitwise operation of (5 & 9)

Bitwise OR (|) Operator:

Bitwise operator can be easily understood by below table:

Example:

What will the output for bitwise operation of (5 | 9)

Bitwise XOR (^) Operator:

Bitwise operator can be easily understood by below table:

Example:

What will the output for bitwise operation of (5 ^ 9)

Bitwise Complement:

Bitwise operator can be easily understood by below table:

Example:

What will the output for bitwise operation of (~5)

Note: Compiler gives 2’s complement of number. 2’s compliment of 10 is -6.

Logical Operator:

Logical operator also called as a Boolean operator as it returns true or false after comparison.

Imran Khan, Adobe Community Advisor, AEM certified developer and Java Geek, is an experienced AEM developer with over 11 years of expertise in designing and implementing robust web applications. He leverages Adobe Experience Manager, Analytics, and Target to create dynamic digital experiences. Imran possesses extensive expertise in J2EE, Sightly, Struts 2.0, Spring, Hibernate, JPA, React, HTML, jQuery, and JavaScript.

0