Download as pptx, pdf, or txt
Download as pptx, pdf, or txt
You are on page 1of 8

Introduction to Java

Operators
Operators are symbols used in Java to perform various operations on variables
and values. They allow you to manipulate data and make decisions in your
Java programs. This presentation will cover the most commonly used Java
operators and their functionality.

by Sahil Kshirsagar
Arithmetic Operators
+, -, *, / % Examples

The basic arithmetic The modulus operator, which int x = 10, y = 3;


System.out.println(x + y); //
operators for addition, gives the remainder of a
Output: 13
subtraction, multiplication, division operation. System.out.println(x - y); //
and division. Output: 7
System.out.println(x * y); //
Output: 30
System.out.println(x / y); //
Output: 3
System.out.println(x % y); //
Output: 1
Relational Operators

1 <, >, <=, >= 2 ==, != 3 Examples


Comparison operators Equality operators that int x = 10, y = 20;
System.out.println(x <
that return true or false check if two values are
y); // Output: true
based on the equal or not equal. System.out.println(x >
relationship between y); // Output: false
two values. System.out.println(x <=
10); // Output: true
System.out.println(x >=
y); // Output: false
System.out.println(x ==
10); // Output: true
System.out.println(x !=
y); // Output: true
Logical Operators
&& (AND) || (OR) ! (NOT)
Returns true if both Returns true if at least one Reverses the logic of the
operands are true, false operand is true, false operand, returning true if
otherwise. otherwise. the operand is false, and
false if the operand is true.
Assignment Operators

= +=, -=, *=, /=, %=


Assigns the value of the right operand to the Compound assignment operators that
left operand. combine an arithmetic operation with an
assignment.
Increment/Decrement Operators

++ --
Increment operator that increases the value of a Decrement operator that decreases the value of a
variable by 1. variable by 1.
Bitwise Operators
& Bitwise AND

| Bitwise OR

^ Bitwise XOR

~ Bitwise NOT

<< Left Shift

>> Right Shift

Bitwise operators work on the individual bits of integer values, allowing you to perform low-level
manipulations on data.
Ternary Operator
?: Example
The ternary operator is a shorthand for an int x = 10, y = 20;
int max = (x > y) ? x : y;
if-else statement. It evaluates an
System.out.println(max); // Output: 20
expression and returns one of two values
based on whether the expression is true or
false.

You might also like