Different Operators in Java

Java provides a wide range of operators that can be used to perform various operations on variables, values, and expressions. Here are the different types of operators commonly used in Java:

  1. Arithmetic Operators: Arithmetic operators are used to perform basic mathematical operations.
    • Addition: +
    • Subtraction: -
    • Multiplication: *
    • Division: /
    • Modulus (remainder): %
    • Increment: ++
    • Decrement: --
  2. Assignment Operators: Assignment operators are used to assign values to variables.
    • Simple assignment: =
    • Addition assignment: +=
    • Subtraction assignment: -=
    • Multiplication assignment: *=
    • Division assignment: /=
    • Modulus assignment: %=
  3. Comparison Operators: Comparison operators are used to compare two values and evaluate to a boolean result (true or false).
    • Equal to: ==
    • Not equal to: !=
    • Greater than: >
    • Less than: <
    • Greater than or equal to: >=
    • Less than or equal to: <=
  4. Logical Operators: Logical operators are used to combine boolean expressions and evaluate to a boolean result.
    • Logical AND: &&
    • Logical OR: ||
    • Logical NOT: !
  5. Bitwise Operators: Bitwise operators are used to perform operations at the bit level.
    • Bitwise AND: &
    • Bitwise OR: |
    • Bitwise XOR: ^
    • Bitwise NOT: ~
    • Left shift: <<
    • Right shift: >>
    • Unsigned right shift: >>>
  6. Conditional (Ternary) Operator: The conditional operator (?:) is a shorthand way of writing an if-else statement.
    • Conditional operator: condition ? expression1 : expression2
  7. Instanceof Operator: The instanceof operator is used to check if an object belongs to a particular class or implements an interface.
    • instanceof operator: object instanceof ClassName
  8. Other Operators: Java also provides other operators for specific purposes, such as:
    • Access operators: . (dot) and :: (method reference operator)
    • Type cast operator: (type)
    • Array access operator: []
    • Member selection operator: . (dot)
    • Method call operator: () (parentheses)

These operators allow you to perform a wide range of operations in Java, making it a versatile programming language.

Related Posts