Java Operators

Selinnur Göl
3 min readApr 18, 2021

--

we use the + operator to add together two values:

it can also be used to add together a variable and a value, or a variable and another variable:

Java Operators

  • Arithmetic operators
  • Assignment operators
  • Comparison operators
  • Logical operators
  • Bitwise operators

Arithmetic operators

a + b = 17
a - b = 7
a * b = 60
a / b = 2
a % b = 2

Assignment operators

Assignment operators are used in Java to assign values to variables. For example,

int age;
age = 5;

Here, = is the assignment operator. It assigns the value on its right to the variable on its left. That is, 5 is assigned to the variable age.

EXAMPLE

output:

var using =: 4
var using +=: 8
var using *=: 32

Comparison operators

Relational operators are used to check the relationship between two operands. For example,

// check is a is less than b
a < b;

Here, > operator is the relational operator. It checks if a is less than b or not.

It returns either true or false.

Note: Relational operators are used in decision making and loops.

Logical operators

Logical operators are used to check whether an expression is true or false. They are used in decision making.

Working of Program

  • (5 > 3) && (8 > 5) returns true because both (5 > 3) and (8 > 5) are true.
  • (5 > 3) && (8 < 5) returns false because the expression (8 < 5) is false.
  • (5 < 3) || (8 > 5) returns true because the expression (8 > 5) is true.
  • (5 > 3) && (8 > 5) returns true because the expression (5 > 3) is true.
  • (5 > 3) && (8 > 5) returns false because both (5 < 3) and (8 < 5) are false.
  • !(5 == 3) returns true because 5 == 3 is false.
  • !(5 > 3) returns false because 5 > 3 is true.

Bitwise operators

Bitwise operators in Java are used to perform operations on individual bits.

--

--