A blog for computer science passionates.

Wednesday 18 March 2020

Hello Friends!!!
Today we are going to learn more operators. In one of my previous articles, I have mentioned that Java is rich and powerful in the matter of Operators.
Some Operators such as,


.(Dot)   
This operator is used as a member access operator.
+ This operator is also used as a string concatenation operator.
[ ]
Square brackets are used to define the size of the operator.
instanceof This operator is used to check the object is defined in the class or not.
+=
Arithmetic addition and assign to the variable, for example, a+=b
-= Arithmetic subtraction and assign to the variable, for example, a-=b
*=
Arithmetic multiplication and assign to the variable, for example, a*=b
/= Arithmetic division and assign to the variable, for example, a/=b
%=
Arithmetic modules and assign to the variable, for example, a%=b
&= Bitwise AND and assignment
|=
Bitwise OR and assignment
^= Bitwise exclusive OR assignment
>>=
Shift right with assignment
>>>= Shift right zero fill assignment
<<=
Shift left with the assignment


These are more operators available in Java. That's it with the operators in Java. Let's take an example of instanceof operator.


Try this example and check the output.

Sunday 15 March 2020

Hello Friends!!!
This is part 4 for operators in Java, and I hope you can get that Java is rich in the matter of operators and powerful also. In this article, we are going to learn about relational operators and conditional operator.

Relational Operators

The relational operators are used to check the relationship between the two operands. And returns the boolean value, for example, if we want to check the equality between two operands, it checks whether the values are equals or not.

Relational Operators
==
Equal to
a==b
Greater than
a>b
>=
Greater than or equal to
a>=b
Less than
a<b
<=
Less than or equal to
a<=b
!=
Not equal to
a!=b


The above table shows the relational operators. Please note to check the equality we have to use == two equals sign. Single = is used as an assignment operator.

Conditional Operator

This operator is also known as a ternary operator. we can use this operator in the place of if-else. It works with relational operators to check the conditions.
Why it is a ternary operator? the answer is it works with three operands thus it is known as the ternary operator.
Syntax,
condition?expr1:expr2
And even you can check from the syntax there is a condition so it is the conditional operator and expr1 works when a condition is true and expr2 returns when a condition is false. So it is a conditional operator. Let's take an example,

Happy Coding...☺😊