About Question enthuware.ocpjp.v8.2.1868 :

Help and support on OCA OCP Java Programmer Certification Questions
1Z0-808, 1Z0-809, 1Z0-815, 1Z0-816, 1Z0-817

Moderator: admin

Post Reply
ashish
Posts: 9
Joined: Wed Nov 25, 2015 11:54 pm
Contact:

About Question enthuware.ocpjp.v8.2.1868 :

Post by ashish »

Answer of below question is wrong.

What will the following code print when run?
Period p = Period.between(LocalDate.now(), LocalDate.of(2015, Month.SEPTEMBER, 1)); System.out.println(p);

Duration d = Duration.between(LocalDate.now(), LocalDate.of(2015, Month.SEPTEMBER, 1)); System.out.println(d);

Assume that the local time on the system at the time this code is run is 2nd Sep 2015 1:00 AM.

Options Given:
1 : P-1D
PT-14H-50M

2 : P1D
PT9H10M

3 : P-1D
P-9H-10M

4:P1D
PT14H50M

5 : It will throw an exception at run time.

Answer Given : Option 5.

But when you will run same code in java editor it will print below answer.

P-1D
It will throw an exception at run time. (Exception in thread "main" java.time.temporal.UnsupportedTemporalTypeException: Unsupported unit: Seconds)

Means Option 5 is correct partially , Actual answer should be above (P-1D with exception) as you have give 2 system.out.println statement.

admin
Site Admin
Posts: 10036
Joined: Fri Sep 10, 2010 9:26 pm
Contact:

Re: About Question enthuware.ocpjp.v8.2.1868 :

Post by admin »

The given answer is correct because you have to pick the best answer out of all the given options. Yes, it does print something but it does also throw an exception at run time and that is given in option 5. None of the other options is correct and that is why option 5 is the correct answer.

You will get similar situation in the real exam as well and you need to pick the best option.
HTH,
Paul.
If you like our products and services, please help us by posting your review here.

ashish
Posts: 9
Joined: Wed Nov 25, 2015 11:54 pm
Contact:

Re: About Question enthuware.ocpjp.v8.2.1868 :

Post by ashish »

Thanks Paul for quick support and cooperations

MichaelZett
Posts: 22
Joined: Wed Dec 10, 2014 8:28 am
Contact:

Re: About Question enthuware.ocpjp.v8.2.1868 :

Post by MichaelZett »

This question is marked as easy, so perhaps it's okay but I'd like more options that actually could be the answer for the second statement. Something like: PT-25H.

dr_astico
Posts: 6
Joined: Thu Dec 29, 2016 5:57 am
Contact:

Re: About Question enthuware.ocpjp.v8.2.1868 :

Post by dr_astico »

This question is marked as easy...
even too easy tough.
none of the first four option has any acceptable value for the code given (if it would be somehow valid).

In this way, you can get the correct option even if you don't know about Temporal fields.

it feels like this question is more about logical thinking, not about Duration.betwen() method, isn't it?

Thanks in advance,
Marco

crazymind
Posts: 85
Joined: Mon Dec 24, 2018 6:24 pm
Contact:

Re: About Question enthuware.ocpjp.v8.2.1868 :

Post by crazymind »

The answer says throw java.time.temporal.UnsupportedTemporalTypeException which is wrong. This method only throws two kind of exceptions:
This code should throw DateTimeException since missing second component

DateTimeException - if the seconds between the temporals cannot be obtained
ArithmeticException - if the calculation exceeds the capacity of Duration
https://docs.oracle.com/javase/8/docs/a ... .Temporal-

admin
Site Admin
Posts: 10036
Joined: Fri Sep 10, 2010 9:26 pm
Contact:

Re: About Question enthuware.ocpjp.v8.2.1868 :

Post by admin »

Did you try running the code?

java.time.temporal.UnsupportedTemporalTypeException is a DateTimeException.
If you like our products and services, please help us by posting your review here.

Javatje
Posts: 9
Joined: Wed Jun 30, 2021 6:53 am
Contact:

Re: About Question enthuware.ocpjp.v8.2.1868 :

Post by Javatje »

Why does this even compile?

admin
Site Admin
Posts: 10036
Joined: Fri Sep 10, 2010 9:26 pm
Contact:

Re: About Question enthuware.ocpjp.v8.2.1868 :

Post by admin »

why do you think it should not compile?
If you like our products and services, please help us by posting your review here.

Post Reply

Who is online

Users browsing this forum: No registered users and 46 guests