3 Java Fundamentals Part-3
3 Java Fundamentals Part-3
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(? :)
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.
Logical OR operator returns false if both the expressions returns false, otherwise
returns true.
Logical NOT operators reverse the logical state.
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
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
+ Unary Plus
- Unary Minus
instanceof Instance Of Operator
. Member Selection Operator
() Method Call Operator .. etc.,
By