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

Operators in Java

Uploaded by

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

Operators in Java

Uploaded by

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

Operators in Java

Relational operators in Java are used to compare operands and return a boolean value,
either true or false. These operators include:

> (greater than)

>= (greater than or equal to)

< (less than)

<= (less than or equal to)

== (equal to)

!= (not equal to)1

Logical operators in Java operate on boolean values and variables. They include:

&& (logical AND)

& (bitwise AND)

|| (logical OR)

| (bitwise OR)

! (logical NOT)2

The AND operators (& and &&) return true only if both operands are true.3 The difference
between the two is that:

&& supports short-circuit evaluations meaning it only evaluates the second operand if the
first one is true.

& always evaluates both operands.3

Similarly, the OR operators (| and ||) return true if at least one operand is true.4 The difference
between the two is that:

|| supports short-circuit evaluations, meaning it only evaluates the second operand if the first
one is false.

| always evaluates both operands.5

Bitwise operators operate on the individual bits of the operands.6

Operator Precedence Chart17: Java operators follow a specific order of precedence,


determining the order of evaluation in an expression.

Loops in Java


For loops are best suited for situations where the number of iterations is known beforehand.8

While loops provide more flexibility and are used when the number of iterations is not fixed.9

Do-while loops guarantee that the loop body is executed at least once before the loop
condition is checked.9

Branching Statements in Java

Branching statements are used to alter the flow of execution in a program. The three types of
branching statements are:

continue (used within loops to skip the current iteration and move to the next one)10

break (used within loops to immediately exit the loop)10

return (used within methods to exit the method)11

Please let me know if you have any further questions about the information presented in the
sources.

You might also like