Option statement is clear, the code does still compile without changing LocalDateTime to ZonedDateTime. But I can't understand explanation maybe for my english. Is it regarding LocalDateTime parameter or ZonedDateTime? Because the code will work if we change LocalDateTime to ZonedDateTime:
If you pass a LocalDateTime and try to format it with ISO_ZONED_DATE_TIME, it will throw an exception at run time. That is why the explanation says that the given code will not work at run time. Of course, the code can be fixed. But the explanation is talking about the code as presented in the problem statement.
If you like our products and services, please help us by posting your review here.
admin wrote:If you pass a LocalDateTime and try to format it with ISO_ZONED_DATE_TIME, it will throw an exception at run time. That is why the explanation says that the given code will not work at run time.
This had already been written in the explanation of option 1 therefore I guessed the underlined part was regarding ZonedDateTime parameter.
Thanks for the reply
No, you don't need to read any thing more about ZonedDateTime. Whatever information is given in this question's explanation is enough.
Just remember that LocalDateTime class does not contain Zone information but if you format a local date using ISO_ZONED_DATE_TIME formatter, then there will be an exception because this formatter requires zone information.
If you like our products and services, please help us by posting your review here.
I think the fourth answer's explanation is not fully correct.
option four:
The method parameter type must be changed from LocalDateTime to ZonedDateTime for it to compile. and its explanation:
Although it is true that this code will never work at runtime, it will compile fine as it is.
I understand that the method parameter changing from LocalDateTime to ZonedDateTime it's not neccessary and thus the option one is the answer. But the code will works at runtime if we change the method parameter type (and of course we should add to ZoneDateTime to method argument).
zserrbo wrote:I think the fourth answer's explanation is not fully correct.
option four:
The method parameter type must be changed from LocalDateTime to ZonedDateTime for it to compile. and its explanation:
Although it is true that this code will never work at runtime, it will compile fine as it is.
I understand that the method parameter changing from LocalDateTime to ZonedDateTime it's not neccessary and thus the option one is the answer. But the code will works at runtime if we change the method parameter type (and of course we should add to ZoneDateTime to method argument).
Am I correct?
Agree with you. This variant and explanation is not clear.
I am not sure what is not clear. The option says that you must do X for it to compile.
The explanation says that it will compile without any change.
The explanation also says that the given code will not work at run time even though it will compile fine.
Now, you are saying that it will compile and run fine if the code is changed to something else. Yes, there could be multiple ways to make the code compile and run fine. But the explanation is talking about the code that is given.
HTH,
Paul.
If you like our products and services, please help us by posting your review here.
The option number 3 seems to be correct because when we change from LocalDateTime to ZonedDateTime it compiles and runs properly.
ZonedDateTime zdt1 = ZonedDateTime.now();
System.out.println(DateTimeFormatter.ISO_ZONED_DATE_TIME.format(zdt1)); //output: 2018-12-12T21:51:59.931+05:30[Asia/Calcutta]
I dont understand why it has been said that it will never work at runtime.
Regards
Raj
I can see that the option 3 of Question number 63 of Test 6 say - "The method parameter type must be changed from LocalDateTime to ZonedDateTime for it to compile." So, I tried out the following:
}
public static String getDateString(ZonedDateTime zdt){
return DateTimeFormatter.ISO_ZONED_DATE_TIME.format(zdt);
}
}
This compiles and runs fine and the output is: 2018-12-13T10:52:47.093+05:30[Asia/Calcutta]
Regards
Raj
Sorry, but I am really not sure what is the issue. To see whether the given option is correct or not you have to compile the code that is given. Does the given code compile? If yes, then the option is wrong because the option says the code must be changed to compile. But no change is required to make the code compile. The explanation also says the same thing...the given code will compile but it will throw an exception at run time. So, I don't know what you are trying to show by your example. The same thing is also explained in older posts. You need to go through the thread.
If you like our products and services, please help us by posting your review here.
Oh I am so sorry. I got it now. That option is wrong because even without changing the parameter from LocalDateTime to ZonedDateTime, the given program will compile.
Thanks for patiently explaining.
Regards
Raj