Key points related to operators in java:
Key points related to operators in java:
1) modulus operator can be use on float like 3.2%3.1= 0.1
2) instanceof used to test the class of an object
boolen state = object_name indtanceof class_name
state = true ( object is instance of that class )
else return false
3) Right shift with zero fill (>>>) is a logical sift
int y = -32;
int x = y>>>4; => 268435454 shift 4 bits right and fill left with zero although >> is a arithmetic shift will give -2 as result.
4) Type conversion in expressions
if expression have char , short or Byte(all are converted into int before evaluation of expression) => int
if expression have long as higher type => long
if expression have float as higher type => float
if expression have double as higher type => double
5) overflow : ex. like int 32 bit if result of any expression increase to more then it will keep least 32 bit and truncate the extra bits
6) Type casting :
a) Down casting : lower type = higher type ( need to explicit casting , In some case it can be implicit)
int a=4;
byte b = (byte ) a;
in such type of conversion : b will take last 8 bits and truncate higher order bits ;
In some cases down casting is also implicit ;
# if we assign const int value to short , byte , char and value of int under the range of target variable
final int a =127;
byte b = a; implicit casting
but if a= 128 ;
byte b = a; need to casting explicit casting because byte range (-128 to 127)
byte
# increment and decrements : b++;
byte b =127;
b++ implicit casting
b = b+ 1; explicit casting
# compound assignment statement : *=,+=, &= , <<= etc
b= b+1 explicit casting
b+= 1; implicit casting
example :
byte b =127;
b++ => -128 ;
b+=1; => -128
b=b++= > 127
b = byte(b +1)
1) modulus operator can be use on float like 3.2%3.1= 0.1
2) instanceof used to test the class of an object
boolen state = object_name indtanceof class_name
state = true ( object is instance of that class )
else return false
3) Right shift with zero fill (>>>) is a logical sift
int y = -32;
int x = y>>>4; => 268435454 shift 4 bits right and fill left with zero although >> is a arithmetic shift will give -2 as result.
4) Type conversion in expressions
if expression have char , short or Byte(all are converted into int before evaluation of expression) => int
if expression have long as higher type => long
if expression have float as higher type => float
if expression have double as higher type => double
5) overflow : ex. like int 32 bit if result of any expression increase to more then it will keep least 32 bit and truncate the extra bits
6) Type casting :
a) Down casting : lower type = higher type ( need to explicit casting , In some case it can be implicit)
int a=4;
byte b = (byte ) a;
in such type of conversion : b will take last 8 bits and truncate higher order bits ;
In some cases down casting is also implicit ;
# if we assign const int value to short , byte , char and value of int under the range of target variable
final int a =127;
byte b = a; implicit casting
but if a= 128 ;
byte b = a; need to casting explicit casting because byte range (-128 to 127)
byte
# increment and decrements : b++;
byte b =127;
b++ implicit casting
b = b+ 1; explicit casting
# compound assignment statement : *=,+=, &= , <<= etc
b= b+1 explicit casting
b+= 1; implicit casting
example :
byte b =127;
b++ => -128 ;
b+=1; => -128
b=b++= > 127
b = byte(b +1)
Comments
Post a Comment