Win a copy of High Performance Python for Data Analytics this week in the Python forum!
  • 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
  • Paul Clapham
  • Ron McLeod
  • Bear Bibeault
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Jj Roberts
  • Carey Brown
Bartenders:
  • salvin francis
  • Frits Walraven
  • Piet Souris

Errata for OCP: Oracle Certified Professional Java SE 8 Programmer II Study Guide - Chapter 3

 
Ranch Hand
Posts: 142
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Page 136, at the end:

Shouldn't

When talking about LIFO (stack), people say push/poll/peek.

be

When talking
about LIFO (stack), people say push/pop/peek.

?
 
Jan Sterk
Ranch Hand
Posts: 142
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Page 146:

book wrote:A natural ordering that uses compareTo() is said to be consistent with equals if, and only if, x.equals(y) is true whenever x.compareTo(y) equals 0.



The API doc of Comparable says

API doc wrote:The natural ordering for a class C is said to be consistent with equals if and only if e1.compareTo(e2) == 0 has the same boolean value as e1.equals(e2) for every e1 and e2 of class C.



That's different. According to the book's rule, a class which equals() method always returns true, is always consistent, even if its compareTo() method does not return 0. According to the API, equals() must return false if compareTo() doesn't return 0 (and true if it does).

Then follows this:


You might be sorting Product objects by name, but names are not unique. Therefore, the return value of compareTo() might not be 0 when comparing two equal Product objects,
so this compareTo() method is not consistent with equals.


(This refers to the case where two Product objects have the same id values, and different name values.)
Its inconsistency does not follow from the rule in the book's quote, but from the API doc's quote.
(It is also inconsistent because of the following case. Say you have two Product objects with different id values, and with equal name values. Then namecompareTo() returns 0, but equals() returns false. This is because of both the book's rule and the API's rule.)

[edit] Reading it over again, I think the only typo in the book's rule is that the phrase if, and only if has to be in two places. It should be:
A natural ordering that uses compareTo() is said to be consistent with equals if, and only if: x.equals(y) is true if, and only if x.compareTo(y) equals 0.
 
author & internet detective
Posts: 40400
821
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
You are correct on both and I've added them to the errata
 
Ranch Hand
Posts: 74
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

When talking about LIFO (stack), people say push/pop/peek.  ?


No, the original version in the book is correct:

When talking about LIFO (stack), people say push/poll/peek.


poll() doesn't throw an exception as push/peek. Even your example an page 137 uses push/poll/peek.
 
Juerg Bauman
Ranch Hand
Posts: 74
1
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I was wrong. The API-Doc to the Interface Deque<E> says:
Stack Method
 push(e)
 pop()
 peek()
Since Deque extends Queue, both methods poll() and pop() are available in a Deque-Stack. The older class Stack just contains the method pop().
reply
    Bookmark Topic Watch Topic
  • New Topic