SUBJECT MATERIAL, EBOOKS, IMPORTANT QUESTION , ASSIGNMENT QUESTION, OLD QUESTION PAPER

Thursday 10 August 2017

Java Operators

Explanation : Java operator is a symbol that is used to perform mathematical or logical manipulations.  Java language is rich with buil... thumbnail 1 summary
Explanation :
  • Java operator is a symbol that is used to perform mathematical or logical manipulations. 
  • Java language is rich with built-in operators.
  • Java operators: In any programming language (and in mathematics), we use some symbols to represent an operation (calculation).

Suppose if we want to perform an addition, then we use the symbol  ” + “ Similarly when we want to perform a subtraction, then we use the symbol  ” – “ These symbols are known as mathematical operators. We have different types of operators in java. Each type (group) has some symbols (operators) in it.

Java provides a rich set of operators enviroment. Java operators can be devided into following categories
Operators
Sign
Types
Increment & Decrements Operators
++ , --
Unary operator
Arithmetic operators
+, -, /, %
Binary operator
Relation operators
<,<=, >, >=, ==, !=
Logical operators
&&, ||, !
Bitwise operators
&, |. <<, >>, ~, ^
Assignment operators
=, +=, -=, *=, /=, %=
Conditional operators
?:
Ternary operator



OperatorDescription
+Addition
Subtraction
*Multiplication
/Division
%Modulus


Increment & Decrements Operators

OperatorDescription
++Increment
−−Decrements

Relational Operators

OperatorDescription
==Is equal to
!=Is not equal to
>Greater than
<Less than
>=Greater than or equal to
<=Less than or equal to

Logical Operators

OperatorDescription
&&And operator. Performs a logical conjunction on two expressions.
(if both expressions evaluate to True, result is True. If either expression evaluates to False, result is False)
||Or operator. Performs a logical disjunction on two expressions.
(if either or both expressions evaluate to True, result is True)
!Not operator. Performs logical negation on an expression.

Bitwise Operators

OperatorDescription
<<Binary Left Shift Operator
>>Binary Right Shift Operator
>>>Shift right zero fill operator
~Binary Ones Complement Operator
&Binary AND Operator
^Binary XOR Operator
|Binary OR Operator

Now lets see truth table for bitwise &| and ^
aba & ba | ba ^ b
00000
01011
10011
11110
The bitwise shift operators shifts the bit value. The left operand specifies the value to be shifted and the right operand specifies the number of positions that the bits in the value are to be shifted. Both operands have the same precedence.Example
a = 0001000
b= 2
a << b= 0100000
a >> b= 0000010 

Assignment Operators

OperatorDescription
=Assign
+=Increments, then assigns
-=Decrements, then assigns
*=Multiplies, then assigns
/=Divides, then assigns
%=Modulus, then assigns
<<=Left shift and assigns
>>=Right shift and assigns
&=Bitwise AND assigns
^=Bitwise exclusive OR and assigns
|=Bitwise inclusive OR and assigns

Misc Operators

OperatorDescription
Conditional(Ternary) Operator ( ? : )Operator is used to decide which value should be assigned to the variable.
instanceOf OperatorObject reference variables