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

3 Java Fundamentals Part-3

The document provides an overview of Java operators, categorizing them into unary, binary, and ternary operators, along with detailed explanations of various types such as arithmetic, relational, logical, increment & decrement, bitwise, assignment, and conditional operators. Each operator type is accompanied by examples to illustrate their usage in Java programming. Additionally, it briefly mentions other operators like array, type cast, and member selection operators.
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views

3 Java Fundamentals Part-3

The document provides an overview of Java operators, categorizing them into unary, binary, and ternary operators, along with detailed explanations of various types such as arithmetic, relational, logical, increment & decrement, bitwise, assignment, and conditional operators. Each operator type is accompanied by examples to illustrate their usage in Java programming. Additionally, it briefly mentions other operators like array, type cast, and member selection operators.
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 6

Java By Venkatesh Mansani Naresh i Technologies

Java Fundamentals
Operaters: An operator is a special symbol that operates on data.
Operators are divided into 3 categories:
1) Unary Operators
2) Binary Operators
3) Ternary Operators

Unary Operators:
An operator that operates on only one operand is called as unary operator.
Examples: ++a, a++, --a, a--, +a, -a, !a, .. etc.,

Binary Operators:
An operator that operates on two operands is called as binary operator.
Examples:a+b, a-b, a*b, a/b, a%b, a<b, a>b, a<=b, a>=b, a==b, a!=b, .. etc.,

Ternary Operators:
An operator that operates on three operands is called as ternary operator.
Example:Conditional operator(? :)

Operators are divided into many categories based on their


operations:
1) Arithmetic Operators
2) Relational Operators
3) Logical Operators
4) Increment & Decrement Operators
5) Bitwise Operators
6) Assignment Operators
7) Conditional Operators
8) Other Operators

Java By Venkatesh Mansani Naresh i Technologies


Java By Venkatesh Mansani Naresh i Technologies

1) Arithmetic Operators:
Operator Meaning
+ Addition
- Subtraction
* Multiplication
/ Division
% Modulo Division
Division operator returns quotient whereas modulo division operator returns
remainder.

2) Relational Operators:
Operator Meaning
< Less than
> Greater than
<= Less than or equals to
>= Greater than or equals to
== Equals to
!= Not equals to
The above all operators returns boolean value.

3) Logical Operators:
Operator Meaning
&& Logical AND
|| Logical OR
! Logical NOT
Logical AND operator returns true if both the expressions returns true, otherwise
returns false.

Java By Venkatesh Mansani Naresh i Technologies


Java By Venkatesh Mansani Naresh i Technologies

Logical OR operator returns false if both the expressions returns false, otherwise
returns true.
Logical NOT operators reverse the logical state.

4) Increment & Decrement Operators:


Operator Meaning
++ Increment
-- Decrement
Pre IncrementExample:
class Demo
{
public static void main(String args[])
{
int a=5;
int b=++a;
System.out.println(a);
System.out.println(b);
}
}
In the above example, value of a incremented by 1 then assigned to b because it
is a pre increment operator.
Post Increment Example:
class Demo
{
public static void main(String args[])
{

Java By Venkatesh Mansani Naresh i Technologies


Java By Venkatesh Mansani Naresh i Technologies

int a=5;
int b=a++;
System.out.println(a);
System.out.println(b);
}
}
In the above example, value of a assigned to b then a value incremented by 1
because it is a post increment operator.

5) Bitwise Operators:
Operator Meaning
& Bitwise AND
| Bitwise OR
^ Bitwise XOR
<< Left Shift
>> Right Shift
~ tilde
Note: All bitwise operators operate on binary data.

6) Assignment Operators:
Operator Meaning
= Normal Assignment
a+=b a=a+b
a-=b a=a-b
a*=b a=a*b
a/=b a=a/b

Java By Venkatesh Mansani Naresh i Technologies


Java By Venkatesh Mansani Naresh i Technologies

a%=b a=a%b
a&=b a=a&b
a|=b a=a|b
a^=b a=a^b
a<<=b a=a<<b
a>>=b a=a>>b

7) Conditional Operator(?:):
It is used to express the condition.
Example:
class Demo
{
public static void main(String args[])
{
int a=5, b=3;
int c=(a>b)?a:b;
System.out.println(c);
}
}
In the conditional operator statement, if the condition returns true then a value
stored in c otherwise b value stored in c.

8) Other Operators:
Operator Meaning
[] Array Operator
() Type Cast Operator

Java By Venkatesh Mansani Naresh i Technologies


Java By Venkatesh Mansani Naresh i Technologies

+ Unary Plus
- Unary Minus
instanceof Instance Of Operator
. Member Selection Operator
() Method Call Operator .. etc.,

By

Mr. Venkatesh Mansani


Naresh i Technologies

Java By Venkatesh Mansani Naresh i Technologies

You might also like