File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Beginning Java and the fly likes Precedence of operators 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 "Precedence of operators " Watch "Precedence of operators " New topic
Author

Precedence of operators

Anto Telvin
Ranch Hand

Joined: Aug 12, 2008
Posts: 113
hi all

what is the difference between left to right associative and right to left associative with eg:


thanks


Anto Telvin Mathew<br />Many of the life failures are people who did not realize how close they were to success when they give up. EDISON
Henry Wong
author
Sheriff

Joined: Sep 28, 2004
Posts: 18896
    
  40

Left to Right means that the evaluation is done left to right. For example, 2+3+4 -- obviously, Java can't do both additions at the same time, and they have the same precedence. It is however, left to right, so the left addition is done first.

Henry


Books: Java Threads, 3rd Edition, Jini in a Nutshell, and Java Gems (contributor)
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 39396
    
  28
. . . And right to left means that if you have

. . . myBoolean ? 123 : otherBoolean ? 345 : 567 . . .

where both the ?: operators have the same priority but associate to the right, the compiler evaluates the bit on the right (345 or 657) before offering that result as an alternative to the bit on the left (123).
Anto Telvin
Ranch Hand

Joined: Aug 12, 2008
Posts: 113
thanks
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 39396
    
  28
You're welcome
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Precedence of operators