JAVA OPERATOR : Operator are among core concept of writing logical condition and business logic in any programming language .
Simplest operators are Arithmetic Operator which we all know :
+ : Addition
- : Subtraction
* : Multiplication
/ : Division
% : Remainder
Now next is Assignment operator
= : To assign any value to any reference name of any type we use this = operator . What is variable in java already explained in my previous post JAVA BASIC OVERVIEW
Example: int input1=10; String name = "My name is John Cena";
Along with this operator we can add Arithmetic Operator to make assignment simple
Example : For int input1= input1 + 10 ; it can be simplified by using combination of Addition and equal to operator like int input1 += 10; this is same as input1= input1 + 10 ;
Same way we can simplified for Subtraction, Multiplication , Division and Remainder like :
-= , *= , /= , %=
Relational Operator , mainly used in case of comparison , if comparison is successful true will be return if not false will be return.
> : To Compare other value is greater than the comparing value or not.
< : To Compare other value is less than the comparing value or not.
== : To compare two objects if equal or not.
!= : To Compare other value is not equal to comparing value.
>= : To Compare other value is equal or greater than the comparing value.
<= : To Compare other value is equal or less than the comparing value.
Logical operator :
& : & is use for applying multiple condition together with AND condition.
| : | is use for applying multiple condition together with OR condition.
&& : && is use for applying multiple condition together with AND condition. Only difference & and && is in case of && if first condition is failed it won't check the next condition while in & all the condition will be check.
|| : || is use for applying multiple condition together with OR condition. Only difference | and || is in case of || if first condition is failed it won't check the next condition while in | all the condition will be check.
++ : To do pre or post increment on any value.
-- : To do pre or post decrement on any value.
Ternary Operator :
? :
Example : 10 > 5 ? "YES" : "NO";
Output will be "Yes" as 10 is greater than 5.
10 > 50 ? "YES" : "NO";
Output will be "NO" as 10 is less than 50.
- BASIC OVERVIEW OF JAVA (SESSION 1)
- PRIMITIVE TYPES AND WRAPPER CLASS (SESSION 2)
- JAVA OPERATORS (SESSION 3)
- LOOPS IN JAVA (SESSION 4)
- NAMING CONVENTION WITH FACTORIAL PROGRAM (SESSION 5)
Comments
Post a Comment