Monday, September 7, 2009

Java Operators and Assignment

Operators and assignment

What are different types of operators in java

Uniary ++, --, +, -, |, ~, ()
Arithmetic *, /, %,+, -
Shift <<, >>, >>>
Comparison =, instanceof, = =,!=Bitwise &, ^, |Short Circuit &&, ||Ternary ?:Assignment =

How does bitwise (~) operator work

It converts all the 1 bits in a binary value to 0s and all the 0 bits to 1s, e.g 11110000 coverts to 00001111

What is a modulo operator %

This operator gives the value which is related to the remainder of a divisione.g x=7%4 gives remainder 3 as an answer

Can shift operators be applied to float types.

No, shift operators can be applied only to integer or long types

What happens to the bits that fall off after shifting

They are discarded

What values of the bits are shifted in after the shift

In case of signed left shift >> the new bits are set to zero

But in case of signed right shift it takes the value of most significant bit before the shift, that is if the most significant bit before shift is 0 it will introduce 0, else if it is 1, it will introduce 1

 

No comments:

Post a Comment