• 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
  • Devaka Cooray
  • Tim Cooke
Sheriffs:
  • Rob Spoor
  • Liutauras Vilda
  • paul wheaton
Saloon Keepers:
  • Tim Holloway
  • Tim Moores
  • Mikalai Zaikin
  • Carey Brown
  • Piet Souris
Bartenders:
  • Stephan van Hulst

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: 79799
385
  • 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: 79799
385
  • 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: 41988
911
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: 41988
911
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.
 
joke time: What is brown and sticky? ... ... ... A stick! Use it to beat this tiny ad!
Smokeless wood heat with a rocket mass heater
https://woodheat.net
reply
    Bookmark Topic Watch Topic
  • New Topic