• 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
  • Paul Clapham
  • Ron McLeod
  • Jeanne Boyarsky
  • Tim Cooke
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Frits Walraven
Bartenders:
  • Piet Souris
  • Himai Minh

Error in Mala Gupta's OCA Java SE8 (page 238)

 
Greenhorn
Posts: 5
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi all,

I found an error in Mala Gupta's OCA Java SE8 (page 238).

See page 238:



In the preceding code, the call to lang1.substring() and lang2.subtring() will return "Ja".

The call to lang1.substring() and lang2.subtring() will return "J" instead of "Ja" because the substring method doesn't include the character at the end position (1) so only the position 0 ("J") will be returned.
 
Author
Posts: 375
22
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Daniel Lobo wrote:Hi all,

I found an error in Mala Gupta's OCA Java SE8 (page 238).

See page 238:



In the preceding code, the call to lang1.substring() and lang2.subtring() will return "Ja".

The call to lang1.substring() and lang2.subtring() will return "J" instead of "Ja" because the substring method doesn't include the character at the end position (1) so only the position 0 ("J") will be returned.



Hi Daniel -

Thanks for posting it.

You are correct. lang1.substring(0,1) returns 'J'.

A lot of folks ask me - how is it that simple errors like these aren't noticed during the content review cycles.
My response - You can compare books with software. Perhaps an open bug on the system is due to changes in the code that fixed a bug in its last cycle. :-)

I've added it the book's errata. I'll post the link to the errata soon.

Thanks again.

With much respect,
Mala
 
author & internet detective
Posts: 41083
848
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

Mala Gupta wrote:My response - You can compare books with software. Perhaps an open bug on the system is due to changes in the code that fixed a bug in its last cycle. :-)


Love this quote. So true!
 
Mala Gupta
Author
Posts: 375
22
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Jeanne Boyarsky wrote:
Love this quote. So true!



Being authors, both of us can understand the pain here! :-)

Hope you are doing good.

Cheers,
Mala
 
Daniel Lobo
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Mala,

Thanks for replying!
I have learned a lot by reading your book =)

I found another issue in page 260.

See what the books says:

Examine the definition of the following no-argument constructor defined in the class ArrayList.java:



However, the constructor code is:



Where DEFAULTCAPACITY_EMPTY_ELEMENTDATA is:



Thus, array list is created with size 0. The size is only increased to 10 when adding the first element. When adding the first element, the code will check the capacity. The argument to ensureCapacityInternal will be 1 (size 0 + 1). As the elementData is equals to DEFAULTCAPACITY_EMPTY_ELEMENTDATA, the capacity will be the greater value between 1 and default 10. So 10 will be the new size! See the code below.




ps: I'm using jdk1.8.0_121.

Regards,
Daniel Lobo
 
Today's lesson is that you can't wear a jetpack AND a cape. I should have read this tiny ad:
Free, earth friendly heat - from the CodeRanch trailboss
https://www.kickstarter.com/projects/paulwheaton/free-heat
reply
    Bookmark Topic Watch Topic
  • New Topic