Operators

 

Define Operators in java

In Java, the term operator refers to a special symbol (or keyword) that performs an operation on one, two, or three operands and returns a result.

Definition

An operator in Java is a symbol that tells the compiler to perform a specific mathematical, logical, or relational operation on data (operands).


Categories of Operators in Java

1. Arithmetic Operators

Used for basic math operations.

  • + (addition)
  • - (subtraction)
  • * (multiplication)
  • / (division)
  • % (modulus)

2. Unary Operators

Operate on a single operand.

  • ++ (increment)
  • -- (decrement)
  • ! (logical NOT)
  • + (unary plus)
  • - (unary minus)

3. Relational (Comparison) Operators

Compare two values and return true or false.

  • ==
  • !=
  • >
  • <
  • >=
  • <=

4. Logical Operators

Used for boolean logic.

  • && (logical AND)
  • || (logical OR)
  • ! (logical NOT)

5. Bitwise Operators

Perform operations on bits.

  • &, |, ^, ~, <<, >>, >>>

6. Assignment Operators

Assign values to variables.

  • =
  • +=, -=, *=, /=, %= etc.

7. Ternary Operator

The only operator that takes three operands.

  • ? : (conditional operator)

8. Instanceof Operator

Checks if an object is an instance of a class.

  • instanceof

Example

int a = 10, b = 5;
int sum = a + b;  // '+' is an operator
boolean result = a > b; // '>' is an operator

Comments

Popular posts from this blog

keyboard

Data classification

Software development