1z0809 Java SE 8 Programmer II Free Practice Test — 30 Questions

30 questions · Full explanations · No account required

Free
Question 1 of 30

A developer is tasked with processing a `Stream` of `Product` objects, each possessing a `price` attribute which can be `null`. The objective is to sort these products in ascending order of their price, ensuring that the stream operation completes without throwing a `NullPointerException`. The initial implementation uses `Comparator.comparing(Product::getPrice)`. Which modification to the comparator logic is most effective in achieving the desired outcome and preventing runtime errors due to potential null prices?

`Comparator.nullsFirst(Comparator.comparing(Product::getPrice))`
`Comparator.comparing(Product::getPrice, Comparator.nullsLast(Comparator.naturalOrder()))`
`Comparator.comparing(Product::getPrice, Comparator.nullsFirst(Comparator.reverseOrder()))`
`Comparator.comparing(Product::getPrice, Comparator.nullsLast(Comparator.reverseOrder()))`

About the 1z0809 Java SE 8 Programmer II Certification

These free practice questions are designed to help you assess your readiness for the 1z0809 Java SE 8 Programmer II exam by Other. Each question comes with a detailed explanation to reinforce the correct concept. For a complete exam preparation experience with hundreds of questions, spaced-repetition study tools, and full exam simulations, explore our premium access.