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

Content Operators

The document discusses different types of operators in Java including relational, instanceof, arithmetic, string concatenation, increment/decrement, ternary conditional, and logical operators.

Uploaded by

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

Content Operators

The document discusses different types of operators in Java including relational, instanceof, arithmetic, string concatenation, increment/decrement, ternary conditional, and logical operators.

Uploaded by

Karthik Baskaran
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 2

1) Relational Operators

❑ Relational operators always result in a boolean value true or false.

❑ There are six relational operators: >, >=, <, <=, ==, and !=. ❑ When comparing
characters, Java uses the Unicode value of the character as the numerical value.

❑ When comparing reference variables, == returns true only if both references


refer to the same object.

2) instanceof Operator

❑ instanceof is for reference variables only, and checks for whether the object is
of a particular type.

❑ For interfaces, an object passes the instanceof test if any of its superclasses
implement the interface on the right side of the instanceof operator.

3) Arithmetic Operators

❑ There are four primary math operators: add, subtract, multiply, and divide.

❑ The remainder operator (%), returns the remainder of a division.

❑ The *, /, and % operators have higher precedence than + and -.

4)String Concatenation Operator

❑ If either operand is a String, the + operator concatenates the operands.

❑ If both operands are numeric, the + operator adds the operands.

5) Increment/Decrement Operators

❑ Prefix operators (++ and --) run before the value is used in the expression.

❑ Postfix operators (++ and --) run after the value is used in the expression.

❑ In any expression, both operands are fully evaluated before the operator is
applied.

❑ Variables marked final cannot be incremented or decremented.

6) Ternary Conditional Operator

❑ Returns one of two values based on whether a boolean expression is true or


false.

❑ Returns the value after the ? if the expression is true.

❑ Returns the value after the : if the expression is false.

7) Logical Operators

❑ The && and & operators return true only if both operands are true.

❑ The || and | operators return true if either or both operands are true.
❑ The && and || operators are known as short-circuit operators.

❑ The && operator does not evaluate the right operand if the left operand is
false.

❑ The || does not evaluate the right operand if the left operand is true.

❑ The & and | operators always evaluate both operands.

❑ The ^ operator (called the logical XOR), returns true if exactly one operand is
true.

You might also like