• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Tim Cooke
  • Jeanne Boyarsky
Sheriffs:
  • Rob Spoor
  • Devaka Cooray
  • Liutauras Vilda
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Tim Moores
  • Mikalai Zaikin
Bartenders:
  • Piet Souris

Some minor typos about String methods, on page 108,109,110 (Java OCA 8 Programmer I Study Guide)

 
Ranch Hand
Posts: 221
27
IntelliJ IDE Spring Java
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
When I practice some codes in Netbeans I saw that there are some disparity between this book and Oracle documentation. Those are:

1. On page 108, “toLowerCase() and toUpperCase()” section, method signatures are:
But Oracle documentation says:
or


2. On page 109, “equals() and equalsIgnoreCase()” section, method signatures are:
But Oracle documentation says:


3. On page 109, “contains()” section, method signature is:
But Oracle documentation says:


4. On page 110, “replace()” section, method signature is:
But Oracle documentation says:

 
Sheriff
Posts: 11604
178
Hibernate jQuery Eclipse IDE Spring MySQL Database AngularJS Tomcat Server Chrome Java
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Mushfiq Mammadov wrote:1. On page 108, “toLowerCase() and toUpperCase()” section, method signatures are:


These method signatures are wrong! toLowerCase() and toUpperCase() don't have a String parameter as you can notice in the provided example code. They can indeed have a Locale parameter, but that's for localisation which is not on the OCA exam.

Mushfiq Mammadov wrote:2. On page 109, “equals() and equalsIgnoreCase()” section, method signatures are:


The equals method should indeed use Object as parameter, because it's a (valid) override of the equals-method from the Object class. Nothing wrong with the equalsIgnoreCase method: it takes a String parameter and you have almost a completely free choice of the name (must be a valid identifier, e.g. java keywords not allowed). But of course an appropriate meaningful parameter name is preferred (applies also to class names, method nams, variable names and so on). Although this declaration would be completely valid, this parameter name is not really recommended:

Mushfiq Mammadov wrote:3. On page 109, “contains()” section, method signature is:


For the OCA exam you don't need to know the CharSequence interface (it's not mentioned in the exam topics), so the authors probably simplified the signature using a String. And luckily for them (and us): String IS-A CharSequence so no problem here as well. But because they explain the CharSequence later on (for the replace method) it's maybe better to explain it here already and use the same signature as in the Oracle documentation. And for the OCA exam you do need to know what's an interface and what it means when a method parameter has an interface type, so using CharSequence in the method signature should be no problem at all.

Mushfiq Mammadov wrote:4. On page 110, “replace()” section, method signature is:


Here the same remark applies as with the equalsIgnoreCase method: you can use any parameter name you like (if a valid identifier). But here it's probably a copy/paste left-over from the variant using the chars. So I would at least use a variable name which indicates you can use this version to replace more than 1 char (a sequence of chars) e.g. oldChars and newChars (or of course the parameter names from Oracle documentation)

Hope it helps!
Kind regards,
Roel
 
Mushfiq Mammadov
Ranch Hand
Posts: 221
27
IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Roel De Nijs wrote:

Mushfiq Mammadov wrote:2. On page 109, “equals() and equalsIgnoreCase()” section, method signatures are:


Nothing wrong with the equalsIgnoreCase method: it takes a String parameter and you have almost a completely free choice of the name (must be a valid identifier, e.g. java keywords not allowed). But of course an appropriate meaningful parameter name is preferred (applies also to class names, method nams, variable names and so on).


I am agree with you, Roel. But I note this so maybe authors forget it, maybe they want to change it for the next publication of book
 
author & internet detective
Posts: 41762
885
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
toLowerCase()/toUpperCase() are just plain wrong. There's certainly no String parameter. I meant to use the signature without any parameters. (Locale isn't on the OCA exam. And on the OCP exam, Locale is on the exam, but not with respect to these methods.

For equals(), contains(), and replace(), my intent was to simplify the signatures to what is on the exam. (They only test passing in Strings.) I should have clarified this 'shortcut" and will do so if we get to do a Java 9 version of the book! So while it isn't an errata per se (I did it on purpose), it also isn't accurate.

I've noted both on our list. Thanks!
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic