About Question enthuware.ocpjp.v8.2.1868 :
Moderator: admin
-
- Posts: 9
- Joined: Wed Nov 25, 2015 11:54 pm
- Contact:
About Question enthuware.ocpjp.v8.2.1868 :
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.
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.
-
- Site Admin
- Posts: 10053
- Joined: Fri Sep 10, 2010 9:26 pm
- Contact:
Re: About Question enthuware.ocpjp.v8.2.1868 :
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.
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.
-
- Posts: 9
- Joined: Wed Nov 25, 2015 11:54 pm
- Contact:
Re: About Question enthuware.ocpjp.v8.2.1868 :
Thanks Paul for quick support and cooperations
-
- Posts: 22
- Joined: Wed Dec 10, 2014 8:28 am
- Contact:
Re: About Question enthuware.ocpjp.v8.2.1868 :
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.
-
- Posts: 6
- Joined: Thu Dec 29, 2016 5:57 am
- Contact:
Re: About Question enthuware.ocpjp.v8.2.1868 :
even too easy tough.This question is marked as easy...
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
-
- Posts: 85
- Joined: Mon Dec 24, 2018 6:24 pm
- Contact:
Re: About Question enthuware.ocpjp.v8.2.1868 :
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-
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-
-
- Site Admin
- Posts: 10053
- Joined: Fri Sep 10, 2010 9:26 pm
- Contact:
Re: About Question enthuware.ocpjp.v8.2.1868 :
Did you try running the code?
java.time.temporal.UnsupportedTemporalTypeException is a DateTimeException.
java.time.temporal.UnsupportedTemporalTypeException is a DateTimeException.
If you like our products and services, please help us by posting your review here.
-
- Posts: 9
- Joined: Wed Jun 30, 2021 6:53 am
- Contact:
Re: About Question enthuware.ocpjp.v8.2.1868 :
Why does this even compile?
-
- Site Admin
- Posts: 10053
- Joined: Fri Sep 10, 2010 9:26 pm
- Contact:
Re: About Question enthuware.ocpjp.v8.2.1868 :
why do you think it should not compile?
If you like our products and services, please help us by posting your review here.
Who is online
Users browsing this forum: No registered users and 52 guests