Operators in java

Operators in Java are special symbols that perform specific operations on one or more operands (variables, values, or expressions). Java supports various types of operators, including:

  1. Arithmetic Operators: These operators are used to perform mathematical operations on operands.
  • Addition (+): adds two operands.
  • Subtraction (-): subtracts one operand from another.
  • Multiplication (*): multiplies two operands.
  • Division (/): divides one operand by another.
  • Modulus (%): returns the remainder after division.
  1. Relational Operators: These operators are used to compare two operands and return a boolean value.
  • Equal to (==): returns true if two operands are equal.
  • Not equal to (!=): returns true if two operands are not equal.
  • Greater than (>): returns true if the left operand is greater than the right operand.
  • Less than (<): returns true if the left operand is less than the right operand.
  • Greater than or equal to (>=): returns true if the left operand is greater than or equal to the right operand.
  • Less than or equal to (<=): returns true if the left operand is less than or equal to the right operand.
  1. Logical Operators: These operators are used to perform logical operations on two boolean operands.
  • Logical AND (&&): returns true if both operands are true.
  • Logical OR (||): returns true if at least one of the operands is true.
  • Logical NOT (!): returns true if the operand is false, and vice versa.
  1. Assignment Operators: These operators are used to assign values to variables.
  • Simple Assignment (=): assigns the value on the right to the variable on the left.
  • Addition Assignment (+=): adds the value on the right to the variable on the left.
  • Subtraction Assignment (-=): subtracts the value on the right from the variable on the left.
  • Multiplication Assignment (*=): multiplies the value on the right with the variable on the left.
  • Division Assignment (/=): divides the variable on the left by the value on the right.
  • Modulus Assignment (%=): assigns the remainder after division to the variable on the left.
  1. Unary Operators: These operators are used to perform operations on a single operand.
  • Unary Plus (+): indicates a positive value.
  • Unary Minus (-): indicates a negative value.
  • Increment (++): increases the value of the operand by 1.
  • Decrement (–): decreases the value of the operand by 1.
  • Logical NOT (!): returns true if the operand is false, and vice versa.

These are the main types of operators in Java. By combining different operators and operands, you can create complex expressions and perform a wide range of operations in your Java programs.

Share