• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Jeanne Boyarsky
  • Bear Bibeault
Sheriffs:
  • Rob Spoor
  • Henry Wong
  • Liutauras Vilda
Saloon Keepers:
  • Tim Moores
  • Carey Brown
  • Stephan van Hulst
  • Tim Holloway
  • Piet Souris
Bartenders:
  • Frits Walraven
  • Himai Minh
  • Jj Roberts

Sybex OCP11-Complete - Chapter-3 - Increment and Decrement Operators - Lion and Tiger - Kindle

 
Rancher
Posts: 126
15
Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

I created a new post because this is on a different book, the complete version. I'm new here and not familiar with the regulation. If this is not allowed, I will delete it.

This problem has been discussed in another post, and according to Campbell Ritchie's reply and tests, the 1z0-815 version, which reads "First, lion is incremented", is correct.

Campbell Ritchie wrote:Yes, as we concluded earlier, the original explanation in the book appears to be correct.


That is to say, in code ++lion should be evaluated before lion-- because of order of evaluation.

However, it looks like the author misunderstood Campbell Ritchie and put it into errata again.

Jeanne Boyarsky wrote:And back to errata.


And now, it is still in the errata of 1z0-815, and to the contrary, the complete study guide reads "First, lion is decremented."

I can tell, only one of the two versions is correct, right? In my own opinion, the original one is correct.




 
Marshal
Posts: 72409
315
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Welcome to the Ranch

Not got the time or energy to go through this problem in detail, but it appears from the older discussion you quoted that the older versions of the book had the correct explanation but not the later edition. I think my example starting −1 shows that the ++ is executed first. If the -- were executed first, the code wouldn't throw an exception.
 
Frank Mi
Rancher
Posts: 126
15
Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks. ^_^

Yes, long story short, the 1z0-815 book might be correct (the same as what you said), but it was put into errata incorrectly, then affect the new complete version.
 
Campbell Ritchie
Marshal
Posts: 72409
315
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Again to cut a long story short, whichever version says ++ is executed first is correct.
 
Frank Mi
Rancher
Posts: 126
15
Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Got it, thanks. I don't know how to @ person in this forum, could you tell me how to inform the authors to put it onto errata?
 
Campbell Ritchie
Marshal
Posts: 72409
315
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Please wait; one of the authors checks this forum regularly.
 
author & internet detective
Posts: 40521
825
Eclipse IDE VI Editor Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I've added it back to the errata. Scott and I discussed it and we want to get rid of this example. it's too complicated for the exam. It's also too complicated to explain/understand to be useful.
 
Frank Mi
Rancher
Posts: 126
15
Eclipse IDE Java Windows
  • Likes 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Jeanne and Scott,

Thank you for your reply. Though I don't agree that it is too complicated, actually it is common and in scope of the exam. So please modify but don't get rid of the example.

According to JLS §15.7.1:

JLS §15.7.1 wrote:The left-hand operand of a binary operator appears to be fully evaluated before any part of the right-hand operand is evaluated.


So that,
is the same as:

Other than that, I've seen several java mock exam questions like the following one:

These questions are fine and should be understood by us.

Do you think what I said make sense?
 
Jeanne Boyarsky
author & internet detective
Posts: 40521
825
Eclipse IDE VI Editor Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Frank,
The number of people who found it confusing suggests it isn't furthering our goals here . I'm glad you understand it though!
 
Frank Mi
Rancher
Posts: 126
15
Eclipse IDE Java Windows
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Jeanne,

Sorry for bothering you again. But the information in the Errata (both the 1z0-815 and the complete version) is still incorrect. It should be "++lion should execute before lion–",  rather than after.
 
Jeanne Boyarsky
author & internet detective
Posts: 40521
825
Eclipse IDE VI Editor Java
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Frank Mi wrote:Hi Jeanne,

Sorry for bothering you again. But the information in the Errata (both the 1z0-815 and the complete version) is still incorrect. It should be "++lion should execute before lion–",  rather than after.


Yup. Thank you
 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I was reading the edition published in Oreily, I believe the example is a pretty good one, but maybe you can use other numbers in order to avoid that as readers we misunderstand the example.

In the book, we can see



Which unfortunately has the same result as the following



And that result is (at least from my point of view) the one that got me confused.

After changing the value of the lion's variable to a different number is easier to understand how the operators are changing the lion variable.
 
Of course, I found a very beautiful couch. Definitely. And this tiny ad:
SKIP - a book about connecting industrious people with elderly land owners
https://coderanch.com/t/skip-book
reply
    Bookmark Topic Watch Topic
  • New Topic