aspose file tools*
The moose likes Beginning Java and the fly likes + operator Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "+ operator" Watch "+ operator" New topic
Author

+ operator

Ramya Iyer
Ranch Hand

Joined: Jul 29, 2003
Posts: 66
I am not able to understand a particular explanation of the + operator. Can some one provide example to throw light on this?

For a + expression with two operands of primitive numeric type, the result
has a value calculated by promoting the operands to the result type and then performing the addition using that type. This might result in overflow or loss of precision.
Roger Chung-Wee
Ranch Hand

Joined: Sep 29, 2002
Posts: 1683
Java, meaning the compiler and runtime system, will not (I think never) tell you that an overflow might occur.


SCJP 1.4, SCWCD 1.3, SCBCD 1.3
marc weber
Sheriff

Joined: Aug 31, 2004
Posts: 11343

Originally posted by Ramya Iyer:
... Can some one provide example to throw light on this? ...



"We're kind of on the level of crossword puzzle writers... And no one ever goes to them and gives them an award." ~Joe Strummer
sscce.org
Stan James
(instanceof Sidekick)
Ranch Hand

Joined: Jan 29, 2003
Posts: 8791
I wonder if the question was about "promoting the operands to the result type". See if this example makes sense:

I think these show your statement was possibly misleading. The operands are not promoted to the declared type of the result variable but to the widest operand which becomes the actual result of the expression.


A good question is never answered. It is not a bolt to be tightened into place but a seed to be planted and to bear more seed toward the hope of greening the landscape of the idea. John Ciardi
marc weber
Sheriff

Joined: Aug 31, 2004
Posts: 11343

Originally posted by Stan James:
I wonder if the question was about "promoting the operands to the result type"...

Good call. I missed that.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: + operator