-->
Drop Down MenusCSS Drop Down MenuPure CSS Dropdown Menu

Friday, July 14, 2017

Operators and Expressions

 Operators
An Operator is a symbol that tell the compiler to perform some mathematical, logical operations.Java supports a wide variety of operators.They are used to manipulate data inside the program.

In Java Operators are classified into related categories:
i)Arithmetic Operators
ii)Relational operators
iii)Logical operators
iv)Assignment Operators
v)Increment and Decrement operators
vi)Conditional operators
vii)Bit-wise Operators
viii)Special Operators

Arithmetic Operators:-Arithmetic Operators are used to do mathematical manipulations in algebra.Java supports all basic arithmetic operators
+
-
*
/

Relational operators:-Sometimes we compare two elements and take decision depending upon their relation. To do these comparisons we need relational operators.Supported relational operators
<(is less than)
<=(is less than or equal to)
>(is greater than)
>=(is greater than or equal to)
==(is equal to)
!=(is not equal to)


Logical operators:-Apart from relational operators java also supports 3 logical operators which helps in taking decisions.
&&(logical AND)
||(logical OR)
!(logical NOT)

Assignment Operators:-
This operator is used to assign value to a variable.It assign value from right to left. e.g-
int a=10;
value of a is set to 10.

We can also use shorthand assignment to assign
instead of 
a=a+10;
we can write
a=+10;

Increment and Decrement operators:-Java has one very important operator.These operators are used to increase or decrease the value of a variable by 1.They are unary operator and operates on only one operand.

Conditional operators:- This operator can be used as an substitute to if-else statement.  
? : is called ternary or conditional operator.This is used to form conditional expression like
condition?expression 1: expression 2
int a=10;
int b=15;
int c=(a>b)?a:b;
It will assign 15 to variable c.

Bit-wise Operators:-Java supports a special operator known as Bitwise Operator for manipulation of data at values of bit level.These operators are used to shift bits to left and right. It may not be applied to float and double
&(bitwise AND)
!(bitwise OR)
^(bitwise exclusive OR)
~(one's complement)
<<(shift left)
>>(shift right)
>>>(shift right with zero fill)

Special Operators:-
instanceof operator-It is used to check whether the object belongs to to a particular class or not
person instanceof student
It returns true if the object person belongs to the class student,else false
Dot(.) operator-This operator us used to access the instance variable and methods of a class object
student.marks 
student.check() 

Expressions
Expression in java are evaluated using an assignment operator

variable=expression
a=b+c*d;

The expression on the right hand side is evaluated and the result is stored on left hand side.

No comments:

Post a Comment