Object Oriented Programming with Java

⌘K
  1. Home
  2. Docs
  3. Object Oriented Programmi...
  4. Fundamental Programming S...
  5. Operators in Java

Operators in Java

Operators in Java are special symbols or keywords used to perform operations on variables and values.

  • Java supports a variety of operators, which can be categorized into different types.

Arithmetic operators are used to perform mathematical operations such as addition, subtraction, multiplication, and division.

image

Comparison operators are used to compare two values and return a Boolean result (True or False).

image 1

Logical operators are used to combine conditional statements.

  • Logical AND ( && )
    • The AND operator is used to combine two or more conditions, and it returns TRUE if both conditions are true and, if either condition is false, the result will be false.
  • Logical OR ( || )
    • The OR operator is used to combine two or more conditions, and it returns TRUE if at least one condition is true.
    • If at least one condition is true, the result is true; if both are false, the result will be false.
  • Logical NOT (!)
    • The NOT operator is used to reverse the boolean value of an expression. If the condition is true, it makes it false, and if it is false, it makes it true.
image 2

Assignment operators are used to assign values to variables.

image 3

Bitwise operators work at the binary level (bit-by-bit operation).

image 4

Precedence determines the order in which operators are evaluated in an expression. Operators with higher precedence are evaluated before operators with lower precedence.

Associativity defines the direction in which an expression is evaluated when two operators of the same precedence appear in an expression.

Note: Without understanding precedence and associativity, the result of complex expressions can be unexpected.

image 17

How can we help?

Leave a Reply

Your email address will not be published. Required fields are marked *