jQuery in Action, 3rd edition
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Unary Operator () 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 "Unary Operator ()" Watch "Unary Operator ()" New topic

Unary Operator ()

Paul Callaly

Joined: Dec 16, 2003
Posts: 12
Bit of a Programming 101 question but what does the unary operator () do?
The following list might also be helpful for people studying for the test
Thanx, Paul
Unary operators are: ++ -- + - ! ~ ()
Arithmetic operators are: * / % + -
Shift operators are: << >> >>>
Comparison operators are: < <= > >= instanceof == !=
Bitwise operators are: & ^ |
Short-circuit operators are: && ||
Conditional operators are: ?:
Assignment operators are: = "op="
Yuriy Grechukhin
Ranch Hand

Joined: Jan 16, 2004
Posts: 41
I don't know if () is considered an operator, but if it is, I would say it returns unchanged value of what's inside it.
Consider this:
7++ evaluates to 8
5+6 evaluates to 11
Cat instanceof Animal evaluates to true
b = 5 evaluates to 5 (can be checked by a = b = 5, a will be 5 as well)
so since all those expressions evaluate to something (an we consider parantheses an operator) whatever is inside the () will evaluate to itself:
(5) returns 5
[ March 04, 2004: Message edited by: Yuriy Grechukhin ]

The sword of destiny has two blades, one of them is you.
S Anand

Joined: Feb 23, 2004
Posts: 11
Hi Paul
I don't think () is considered as an operator.
Satish Avadhanam
Ranch Hand

Joined: Aug 12, 2003
Posts: 697
Originally posted by S Anand:
Hi Paul
I don't think () is considered as an operator.

I think it is a casting operator. Example follows...

Also for object casting too...
Hope this helps.
Davy Kelly
Ranch Hand

Joined: Jan 12, 2004
Posts: 384
you have postfix() like in a method/constructor: aMethod() Aconstructor()
and you can have cast: (type)e
post fix is higher in precedence than the unary operators, and cast is lower than unary.
is this what you meant?

How simple does it have to be???
I’ve looked at a lot of different solutions, and in my humble opinion Aspose is the way to go. Here’s the link: http://aspose.com
subject: Unary Operator ()
It's not a secret anymore!