Hi I am thiniking upto now that +,- r binary operators and ++,-- r unary operators. Since a+b (a,b r two operands) ++a (a is a single operand) For this concept i understand like that,But in Mughals book +,- r both unary and binary operators.i get confused. Pl clear my doubt???
Dave Vick
Ranch Hand
Joined: May 10, 2001
Posts: 3244
posted
0
Anupama You can use them as either binary or unary. Binary is the traditional x+y and x-y usage. As unary the + re-enforces the fact that the variable/literal is a postive number, it will also promote the operand to an int if it is a byte, short or char.. The - makes an operand negative in value and will also promote to an int if it is a byte short or char. for a more detailed explaination go here: http://java.sun.com/docs/books/jls/second_edition/html/expressions.doc.html#24924 hope that answers your question. Dave [This message has been edited by Dave Vick (edited May 31, 2001).]
Depends on the context: <pre> int i = 5; int j = -i; // using "-" as a unary operator int k = i - 2; // using "-" as a binary operator </pre> Pretty much the same thing for "+" HTH Junilu
Hi Dave,Junilu For this i came to know that operator(+,-) is used for calculating the results for expressions and significance like it is +(positive) r -(Negative). If worng pl correct me.
lusha tak
Ranch Hand
Joined: Dec 30, 2000
Posts: 185
posted
0
apart from expression calculation they have significance in precedence order too.unary plus/unary minus has higher precedence then binary plus/binaty minus operators. moreover, unary plus/minus have right to left associativity whereas the binary counterpart(i.e. bainary plus/minus) have left to right associativity Hope that helps Lusha
Anupama Kota
Greenhorn
Joined: May 21, 2001
Posts: 22
posted
0
Hi Lusha Thanks for clearing my doubt
I agree. Here's the link: http://ej-technologies/jprofiler - if it wasn't for jprofiler, we would need to
run our stuff on 16 servers instead of 3.