• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

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

 
Mushfiq Mammadov
Ranch Hand
Posts: 187
25
Java jQuery Netbeans IDE
  • Likes 1
  • Mark post as helpful
  • send pies
  • 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:

 
Roel De Nijs
Sheriff
Posts: 10662
144
AngularJS Chrome Eclipse IDE Hibernate Java jQuery MySQL Database Spring Tomcat Server
  • Likes 1
  • Mark post as helpful
  • send pies
  • 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: 187
25
Java jQuery Netbeans IDE
  • Mark post as helpful
  • send pies
  • 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
 
Jeanne Boyarsky
author & internet detective
Marshal
Posts: 35279
384
Eclipse IDE Java VI Editor
  • Likes 1
  • Mark post as helpful
  • send pies
  • 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!
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic