0% found this document useful (0 votes)
11 views3 pages

Java Operators Detailed Notes

The document provides an overview of various Java operators, including arithmetic, unary, assignment, relational, logical, bitwise, ternary, and instanceof operators. Each operator type is explained with its meaning and examples of usage. This serves as a comprehensive guide for understanding how to perform operations and comparisons in Java programming.
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)
11 views3 pages

Java Operators Detailed Notes

The document provides an overview of various Java operators, including arithmetic, unary, assignment, relational, logical, bitwise, ternary, and instanceof operators. Each operator type is explained with its meaning and examples of usage. This serves as a comprehensive guide for understanding how to perform operations and comparisons in Java programming.
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

Java Operators – Detailed Notes

1. Arithmetic Operators

Arithmetic operators are used to perform mathematical calculations such as addition, subtraction,
multiplication, division, and remainder operations.

Operator Meaning Example


+ Addition of two numbers a+b
- Subtraction of two numbers a-b
* Multiplication of two numbers a*b
/ Division of two numbers a/b
% Returns remainder after division a%b

Example:
int a = 10, b = 3; [Link](a + b); [Link](a % b);

2. Unary Operators

Unary operators operate on a single operand. They are mainly used for incrementing,
decrementing, or negating values.

Operator Meaning
+ Indicates positive value
- Negates value
++ Increments value by 1
-- Decrements value by 1
! Reverses boolean value

Example:
int a = 5; a++; [Link](a);

3. Assignment Operators

Assignment operators are used to assign values to variables and combine arithmetic operations
with assignment.

Operator Meaning
= Assigns value
Operator Meaning
+= Adds and assigns value
-= Subtracts and assigns value
*= Multiplies and assigns value
/= Divides and assigns value
%= Modulus and assigns value

Example:
int a = 10; a += 5; [Link](a);

4. Relational Operators

Relational operators are used to compare two values. The result of comparison is always boolean
(true or false).

Operator Meaning
== Checks equality
!= Checks inequality
> Checks greater value
< Checks smaller value
>= Checks greater or equal value
<= Checks smaller or equal value

Example:
int a = 10, b = 5; [Link](a > b);

5. Logical Operators

Logical operators are used to combine multiple conditions. They are mainly used in decision
making.

Operator Meaning
&& Returns true if both conditions are true
|| Returns true if at least one condition is true
! Reverses result of condition

Example:
int a = 10; if(a > 5 && a < 20) [Link]("Valid");
6. Bitwise Operators

Bitwise operators perform operations at binary level (bit by bit). They are used in low-level
programming and optimization.

Operator Meaning
& Bitwise AND
| Bitwise OR
^ Bitwise XOR
~ Bitwise Complement
<< Left Shift bits
>> Right Shift bits
>>> Unsigned Right Shift

Example:
int a = 5; [Link](a << 1);

7. Ternary Operator

The ternary operator is a shorthand form of if-else statement used to decide between two values.

Syntax: condition ? value1 : value2;

Example: int a = 10, b = 20; int max = (a > b) ? a : b;

8. instanceof Operator

The instanceof operator checks whether an object belongs to a specific class or interface.

Example: String name = "Java"; [Link](name instanceof String);

You might also like