0% found this document useful (0 votes)
32 views

Unit-I Chapter in Book - 4 Operators in Java: - K. Indhu

This document discusses operators in Java. It covers the conditional operator, assignment operator, logical operators (Boolean and short-circuit), shift operators, and operator precedence. The conditional operator uses the ? symbol to evaluate an expression based on true/false. The assignment operator assigns values using the = symbol. Logical operators allow combining expressions with AND, OR, and short-circuit versions. Shift operators shift bits left or right with <<, >>, and >>>. Higher precedence operators are evaluated first.

Uploaded by

Ghuru
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
32 views

Unit-I Chapter in Book - 4 Operators in Java: - K. Indhu

This document discusses operators in Java. It covers the conditional operator, assignment operator, logical operators (Boolean and short-circuit), shift operators, and operator precedence. The conditional operator uses the ? symbol to evaluate an expression based on true/false. The assignment operator assigns values using the = symbol. Logical operators allow combining expressions with AND, OR, and short-circuit versions. Shift operators shift bits left or right with <<, >>, and >>>. Higher precedence operators are evaluated first.

Uploaded by

Ghuru
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 13

UNIT- I

CHAPTER IN BOOK- 4
OPERATORS IN JAVA
-K. Indhu

SYLLABUS COVERED HERE


Operators in Java

K. INDHU

GOALS
1.
2.
3.
4.
5.
6.
7.

The Conditional Operator


The Assignment Operator
Boolean Logical Operators
Short Circuit Logical Operator
Shift Operator
Left Shift Operator Example
Operators in Precedence

K. INDHU

THE CONDITIONAL OPERATOR


The ? Operator is called the Conditional Operator.
The ? has this general form->

expression1 ? expression2 : expression3

K. INDHU

THE ASSIGNMENT OPERATOR


The general form is ->
var = expression;

Example ->
int x, y, z;
x = y = z = 100; // set x, y, and z to 100
K. INDHU

BOOLEAN LOGICAL OPERATORS

K. INDHU

SHORT CIRCUIT LOGICAL


OPERATOR
They are secondary version
of Boolean AND & OR.
&& is short circuit AND. || is short circuit OR.
If you use the || and && forms, rather than the | and & forms
of these operators, Java will not bother to evaluate the righthand operand when the outcome of the expression can be
determined by the left operand alone.
Example->
if (denom != 0 && num / denom > 10)
Since the short-circuit form of AND (&&) is used, there is no
risk of causing a run-time exception when denom is zero.
If this line of code were written using the single & version of
AND, both sides would have to be evaluated, causing a runtime exception when denom is zero.
K. INDHU

SHIFT OPERATORS

K. INDHU

LEFT SHIFT OPERATOR


EXAMPLE

K. INDHU

SHIFT OPERATORS
The shift operators include->
1. left shift "<<",
2. signed right shift ">> (only right shift) and
3. unsigned right shift ">>>".

DIFFERENCE BETWEEN RIGHT SHIFT & UNSIGNED


RIGHT SHIFT:I. The value ofn>>sisnright-shiftedsbit positions
withsign-extension.
The value ofn>>>sisnright-shiftedsbit positions
withzero-extension.
II. >>> will always put a 0 in the left most bit, while >>
will put a 1 or a 0 depending on what the sign of it is.
K. INDHU

10

OPERATORS IN PRECEDENCE

K. INDHU

11

SO FAR WE STUDIED
Operators in Java

K. INDHU

12

HAPPY
LEARNING!!!

You might also like