Java Fundamentals Part-3
Java Fundamentals Part-3
Java Fundamentals
Operaters:
An operator is a special symbol that operates on data.
1) Arithmetic Operators:
Operator Meaning
+ Addition
- Subtraction
* Multiplication
/ Division
% Modulo Division
Division operator returns quotient whereas modulo division operator
returns remainder.
Example:
class Demo
{
public static void main(String args[])
{
int a=5, b=3, c=2;
int d=a*b/c;
int e=a/b*c;
System.out.println(d);
System.out.println(e);
}
}
2) Relational Operators:
Operator Meaning
< Less than
> Greater than
<= Less than or equals to
>= Greater than or equals to
== Equals to
!= Not equals to
Relational operators are also called as comparison operators also.
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.
Unary Operator:
An operator that operates on only one operand is called as unary
operator.
Examples:
++a, a++, --a, a--, +a, -a, !a, .. etc.,
Binary Operator:
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, .. etc.,
Ternary Operator:
An operator that operates on three operands is called as ternary
operator.
Example:
Conditional 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.
9) Other Operators:
Operator Meaning
[] Array Operator
() Type Cast Operator
instanceof Instance Of Operator
. Member Selection Operator
() Method Call Operator .. etc.,
By