From the course: Java SE 21 Developer (1Z0-830) Cert Prep

Unlock this course with a free trial

Join today to access over 25,600 courses taught by industry experts.

Question deep dive

Question deep dive

- So, here's our question deep dive for dates, times, and time zones. Which are possible results given this code here? Well, if we take a look at it, we are taking an instant value representing exactly now, storing it in ins1. Then we sleep for 10,000 milliseconds or 10 seconds, and we grab another instant, so we have two different instants. At that point, we take instant 1 and truncate it to minutes and compare that with instant 2 truncated to minutes. And then the question is, what possible result will we have? Well, comparison is roughly equivalent to subtraction. The idea of the compareTo methods and the compare methods of different interfaces are that you behave as though you subtract the second argument from the first, because this will give you an idea of relative ordering. If the first is larger than the second, you end up with a positive number. If the first is smaller than the second, you end up with a…

Contents