Java SE 8 OCP - Dates, Times, Locales, and Resource Bundles

Correct : 2

18% Complete (success)

18 %

False : 9

81% Complete (success)

81 %



Aysel 2019-06-03T15:53:58

Not Correct

1. Given the code fragment: {code}
What is the result? (Choose all that apply.)

The string we are parsing has no time zone, so the parse will fail at runtime.

Not Correct

2. Given the code fragment: {code}
Which of the following code fragment(s) will produce a new LocalTime t3 that represents the same time as t2? (Choose all that apply.)

Each adds 1 hour and 5 minutes to t1 to make a new LocalTime t3, which represents 10:05, the same time as t2. The plus() method takes an amount to add as a long, and a unit (A) or a TemporalAmount (E). C adds only 1 hour to make 10 AM instead of 10:05 AM. D generated a compile error because LocalTime does not have a plusDays() method.

Correct

3. Given the code fragment: {code}
What are the correct types to fill in the blanks on line 3?

Period is the correct type to measure a period of time in days.

Not Correct

4. How would you use nowzdt from the code fragment below to compute the equivalent time in Berlin, Germany? (Choose all that apply.)
ZonedDateTime nowzdt = ZonedDateTime.of(LocalDateTime.now(), ZoneId.of("US/Pacific"));

In both cases, we’re creating an Instant from nowzdt and then creating a new ZonedDateTime from that Instant, representing the same time as nowzdt, in Berlin. A is incorrect because,although you can create a new ZonedDateTime from an existing ZonedDateTime with from(), you can’t change the zone when you do. D is incorrect because withZoneId() is not a valid method.

Not Correct

5. The next total solar eclipse visible in South America is on July 2, 2019, at 16:55 UTC. Which code fragment will correctly compute and display the time in San Juan, Argentina, for this solar eclipse?

We first create a ZonedDateTime for the UTC time with zone “Z” (corresponding to GMT zone) and then create the equivalent ZonedDateTime for the San Juan, Argentina, zone. A is missing the time zone on the UTC time. B includes incorrect arguments to the LocalDateTime.of() method. D has the incorrect time zone on the UTC time. E has the incorrect type for totalitySanJuan.

Correct

6. Given: {code}
Assume the default Locale is Italian. If each of the following is the only resource bundle on the classpath and contains key=value, which will be used? (Choose all that apply.)

The default Locale is irrelevant here since none of the choices use Italian. A is the default resource bundle. C and D use the language but not the country from the requested locale. E uses the exact match of the requested locale. B is incorrect because the language code of CA does not match en. And CA isn't a valid language code. F is incorrect because the language code "fr" does not match en.

Not Correct

7. Given three resource bundles and a Java class: {code}
Train_en_US.properties: train=subway
Train_en_UK.properties: train=underground
Train_en.properties: ride = ride
Which of the following, when made independently, will change the output to "ride underground"? (Choose all that apply.)

As is, the code finds resource bundle Train_en_US.properties, which uses Train_en.properties as a parent. Choice D finds resource bundle Train_en_UK.properties, which uses Train_en.properties as a parent.

Not Correct

8. Given two files: {code}
Which, inserted independently, will compile? (Choose all that apply.)

When getting a key from a resource bundle, the key must be a string. The returned result must be a string or an object. While that object may happen to be an integer, the API is still getObject(). E will throw a ClassCastException since 456 is not a string, but it will compile.

Not Correct

9. Given the following code fragment: {code}
Which String inserted as an argument to DateTimeFormatter.ofPattern() at // L1 will produce the output? (Choose all that apply.)
Formatted DateTime: 2017-10-27 14:22:54

D is correct; this string corresponds to the format shown in the output. A uses hh for the hour, which will show 02 instead 14 (that is, a 12-hour format instead of a 24-hour format), and displays the AM/PM at the end, which is great if we’re using 12-hour format, but that’s not what we’re looking for. B results in 12-hour format instead of 24-hour format. C switches months and minutes.

Not Correct

10. Given the following code fragment: {code}
What output will you see?

B and D show the time, and we are displaying LocalDate values that have no time associated with them. A has the incorrect value for d3, and E has the wrong value for d4.

Not Correct

12. If it is 19:12:53 on October 27, 2017, in the US/Pacific Zone (which is GMT- 8:00, summer time), then what does the following code fragment produce? (Choose all that apply.)

We first get the zoneId for “US/Eastern" time, which is GMT- 5:00, and the locale to US. We then create an Instant for “now,” which is 19:12:53 on October 27, 2017 (7:12:53 PM PDT, which is 10:12:53 PM EDT).