Java Operators

Operators

Java 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

Specialist Master (Architect) with a passion for cutting-edge technologies like AEM (Adobe Experience Manager) and a proven track record of delivering high-quality software solutions.

  • Languages: Java, Python
  • Frameworks: J2EE, Spring, Struts 2.0, Hibernate
  • Web Technologies: React, HTML, CSS
  • Analytics: Adobe Analytics
  • Tools & Technologies: IntelliJ, JIRA

🌐 LinkedIn

📝 Blogs

📧 Imran Khan