This week's book giveaway is in the Kotlin forum.
We're giving away four copies of Kotlin for Android App Development and have Peter Sommerhoff on-line!
See this thread for details.
Win a copy of Kotlin for Android App Development this week in the Kotlin 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
  • Liutauras Vilda
  • Devaka Cooray
  • Jeanne Boyarsky
  • Bear Bibeault
Sheriffs:
  • Junilu Lacar
  • Paul Clapham
  • Knute Snortum
Saloon Keepers:
  • Ron McLeod
  • Tim Moores
  • Stephan van Hulst
  • salvin francis
  • Carey Brown
Bartenders:
  • Tim Holloway
  • Frits Walraven
  • Ganesh Patekar

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

 
Ranch Hand
Posts: 142
  • Mark post as helpful
  • send pies
  • 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
  • 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: 39129
723
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • 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
  • 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
  • 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().
 
All of the world's problems can be solved in a garden - Geoff Lawton. Tiny ad:
RavenDB is an Open Source NoSQL Database that’s fully transactional (ACID) across your database
https://coderanch.com/t/704633/RavenDB-Open-Source-NoSQL-Database
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!