aspose file tools*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Operators Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Operators" Watch "Operators" New topic
Author

Operators

Sathi Chowdhury
Ranch Hand

Joined: Mar 16, 2001
Posts: 52
Can any body confirm me pls if I am right.
I tested through code
1) shift operators can be applied to char type operand
2) the unary +,- can not be applied to char type operand
3) ~ (bitwise inversion)can be applied to char type operand

ego hu
Ranch Hand

Joined: Mar 20, 2001
Posts: 53
Can any body confirm me pls if I am right.
I tested through code
1) shift operators can be applied to char type operand
char is promoted to int.
2) the unary +,- can not be applied to char type operand
char is unsigned.
3) ~ (bitwise inversion)can be applied to char type operand
char is promoted to int.
mansoor iqbal
Ranch Hand

Joined: Aug 14, 2000
Posts: 91
char a='s';
char b='o';
System.out.println(a);
System.out.println(b);
System.out.println(a | b);
System.out.println(a ^ b);
prints out s,o,127,28

means u can even perform logical operations on char as well.
Sathi Chowdhury
Ranch Hand

Joined: Mar 16, 2001
Posts: 52
thank u Mansoor and Ego.I was just filling up a chart for what operators can be applied to what type operands...
thanks for the help..
Sathi
Pratiti Naphade
Ranch Hand

Joined: Mar 13, 2001
Posts: 39
they are not performed on char...
in the prnt line it is converted to int.
try this
char a = 'a';
char b = 'b';
char c = a& b;//error
ego hu
Ranch Hand

Joined: Mar 20, 2001
Posts: 53
You nust cast it:
char c=(char) a&b;
Sathi Chowdhury
Ranch Hand

Joined: Mar 16, 2001
Posts: 52
because result type of all binary operation should be at least int type.
int a;
char c='a';
char d='b';
a=c&d;// works fine
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Operators