Win a copy of TDD for a Shopping Website LiveProject this week in the Testing 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 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

Possible Errata in OCP Java SE11 Programmer I Study Guide

 
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Chapter 5
Title: Autoboxing and Unboxing



***: this line when run on IDE outputs "Exception in thread "main" java.lang.IndexOutOfBoundsException: Index 50 out of bounds for length 2"

but in book seems it is working fine.

kindle version  Loc 8364

aaaaaa.PNG
[Thumbnail for aaaaaa.PNG]
 
Marshal
Posts: 75633
354
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Please have a look through the known errata; I can't seem to find that problem there. The overlading will be resolved so the direct use of the int takes precedence over the boxed version, so you would expect to suffer an out of bounds exception.
 
Mahmoud Elkeshky
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I looked for the list of errata before posting the thread, i think you confirm the same that "it should report error" but book shows it is removing the item successfully!!!
 
Campbell Ritchie
Marshal
Posts: 75633
354
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yes, that is what the error appears to be. Please wait because the authors monitor this forum.
 
author & internet detective
Posts: 41073
848
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
Confirmed and added to the errata. I re-ran my original test code and it fails. Not sure what happened there!
 
Greenhorn
Posts: 4
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You can remove the element of the ArrayList by sending an Integer Object to the remove method.



 
Greenhorn
Posts: 3
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I seems that somehow the deprecated (since Java 9) new Integer(50) made it into the errata instead of Integer.valueOf(50) suggested here.

In the first code example. line 7 should be weights.remove(new Integer(50)); and the sentence about Line 7 in the following paragraph should be removed




Edit: on the same page at the end of "Autoboxing and Unboxing" the depricated Integer constructor is used again.
 
Jeanne Boyarsky
author & internet detective
Posts: 41073
848
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
We used it a little in the Java 11 books and got rid of it entirely in the Java 17 ones.
 
If you live in a cold climate and on the grid, incandescent light can use less energy than LED. Tiny ad:
free, earth-friendly heat - a kickstarter for putting coin in your pocket while saving the earth
https://coderanch.com/t/751654/free-earth-friendly-heat-kickstarter
reply
    Bookmark Topic Watch Topic
  • New Topic