0% found this document useful (0 votes)
1 views12 pages

Java - Java Operators

Operators are symbols that instruct computers to perform operations and are categorized into various types such as arithmetic, relational, logical, and assignment operators. Each category has specific operators with defined meanings, such as addition for '+' and logical AND for '&&'. Additionally, there are special operators like 'instanceof' for testing object classes and the dot operator for accessing class members.

Uploaded by

Vinod Agarkar
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
1 views12 pages

Java - Java Operators

Operators are symbols that instruct computers to perform operations and are categorized into various types such as arithmetic, relational, logical, and assignment operators. Each category has specific operators with defined meanings, such as addition for '+' and logical AND for '&&'. Additionally, there are special operators like 'instanceof' for testing object classes and the dot operator for accessing class members.

Uploaded by

Vinod Agarkar
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

OPERATORS

What is Operator?
Operators
• Operator is:
– a symbol that tells the computer to perform
operations
– usually a part of expression
– Classification into categories:
1) Arithmetic operators
2) Relational operators
3) Logical operators
4) Assignment operators
5) Increment and Decrement
6) Conditional operators
7) Bitwise operators
8) Special operators
1) Arithmetic Operators

Operator meaning

+ Addition or unary plus

- Subtraction or unary minus

* Multiplication

/ Division

% Modulo division (Reminder)


2) Relational Operators

Operator meaning
< is less than

<= is less than or equal to

> is greater than

>= is greater than or equal to

== equal to

!= not equal to
3) Logical Operators
Operator meaning
&& logical AND
|| logical OR
! logical NOT

Truth - Table
Value of the expression
op-1 op-2 op-1 && op-2 op-1 | | op-2
true true true true
true false false true
false true false true
false false false false
4) Assignment Operators

V op= expression;
op= is known as the shorthand assignment operator

Operator Example meaning


+= a += 10 a = a + 10
-= a -= 5 a = a-5
*= a *= 10 a = a * 10
/= a /= 2 a = a/2
%= a %= 2 a = a%2
5) Increment Decrement Operators
++
--
Examples :

++m or m++
--m or m--

m = 5; m = 5;
y = ++m; y = m++;
m = ? m = ?
y = ? y = ?
6) Conditional Operators

exp1 ? exp2 : exp3


?: is known as the ternary operator

Example :

a = 10;
b = 5;
x = (a>b) ? a : b;

x = ?
7) Bitwise Operators
Operator meaning
& bitwise AND

| bitwise OR

^ bitwise exclusive OR

~ one’s complement

<< shift left

>> shift right

>>> shift right with zero fill

Bitwise operators may not be applied to float or double


8) Special Operators

• instanceof operator
– Object Reference operator
– used to test whether an object belongs
to a particular Class.
– returns TRUE if Object on left-hand
side is an instance of the Class on
right-hand side.

Object instanceof Class

S1 instanceof Student
8) Special Operators
• Dot (.) operator
– Member Selection operator
– used to access instance variable or
methods of slass object.
– Also used to access classes and
sub-packages from a package.

[Link];
[Link];
[Link];
[Link]( );

You might also like