aspose file tools
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes  Is + , - r Unary operators? Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Reply Bookmark " Is + , - r Unary operators?" Watch " Is + , - r Unary operators?" New topic
Author

Is + , - r Unary operators?

Anupama Kota
Greenhorn

Joined: May 21, 2001
Posts: 22
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
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).]


Dave
Junilu Lacar
Bartender

Joined: Feb 26, 2001
Posts: 4115
    
    2

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


Junilu - [How to Ask Questions] [How to Answer Questions] [MiH]
Anupama Kota
Greenhorn

Joined: May 21, 2001
Posts: 22
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
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
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.
 
subject: Is + , - r Unary operators?
 
Similar Threads
Question about ~ operator
HFSJ mock exam 2 Question -Standard Actions
Increment and Decrement Operators
Unary Operators?
Unary and binary operators