OCP Flashcards – 7. Use Java SE 8 Date/Time API

OCP Exam Objective 7 – Use Java 8 Date/Time API

Flashcard OCP.7.Use.Java.SE.8.Date.Time.API.001

What are the primary Date/Time API classes covered by the 1Z0-808 & 1Z0-809 exams?

Click here to view answer
  • Duration
  • Instant
  • LocalDate
  • LocalDateTime
  • LocalTime
  • Period
  • ZonedDateTime

 

Flashcard OCP.7.Use.Java.SE.8.Date.Time.API.002

Which package contains the Java Date/Time API?

Click here to view answer
java.time

 

Flashcard OCP.7.Use.Java.SE.8.Date.Time.API.003

Are java.time classes mutable or immutable?

Click here to view answer
They are ALL immutable.

 

Flashcard OCP.7.Use.Java.SE.8.Date.Time.API.004

Which class models a single instantaneous point on the time-line that might be used to record event time-stamps in the application?

Click here to view answer
Instant

 

Flashcard OCP.7.Use.Java.SE.8.Date.Time.API.005

Which class stores a date and time in a specific time zone and can support daylight savings changes?

Click here to view answer
ZonedDateTime

 

Flashcard OCP.7.Use.Java.SE.8.Date.Time.API.006

Which class represents an amount of time in terms of years, months, and days?

Click here to view answer
Period

 

Flashcard OCP.7.Use.Java.SE.8.Date.Time.API.007

How would you create an object representing 6 months?

Click here to view answer
For example:

  • Period.ofMonths(6);
  • Period.of(0, 6, 0);

 

Flashcard OCP.7.Use.Java.SE.8.Date.Time.API.008

Which class models a quantity of time in terms of seconds and nanoseconds?

Click here to view answer
Duration

 

Flashcard OCP.7.Use.Java.SE.8.Date.Time.API.009

How would you create an object representing 1 day?

Click here to view answer
For example:

  • Period.ofDays(1);
  • Period.of(0, 0, 1);
  • Duration.ofDays(1);
  • and even Duration.of (1, java.time.temporal.ChronoUnit.DAYS);

 

Flashcard OCP.7.Use.Java.SE.8.Date.Time.API.010

What method obtains the current date from the system clock in the default time-zone?

Click here to view answer
LocalDate.now()

 

Flashcard OCP.7.Use.Java.SE.8.Date.Time.API.011

What does the LocalDateTime.now(ZoneId.of(“UTC+3”)) invocation return?

Click here to view answer
The LocalDateTime object that represents the current date-time according to the system clock for the UTC+3 time zone.

 

Flashcard OCP.7.Use.Java.SE.8.Date.Time.API.012

How would you create an object representing a single point on the current timeline, based on the system UTC clock?

Click here to view answer
Instant.now();

 

Flashcard OCP.7.Use.Java.SE.8.Date.Time.API.013

How would you create an object representing the elapsed time between two points in time, in terms of seconds and nanoseconds?

Click here to view answer
Duration.between(point1, point2);

 

Flashcard OCP.7.Use.Java.SE.8.Date.Time.API.014

Of what type are the arguments point1 and point2 in the previous question?

Click here to view answer
Of the Temporal interface type (such as Instant, LocalDate, LocalTime, LocalDateTime, ZonedDateTime, etc.)

 

Flashcard OCP.7.Use.Java.SE.8.Date.Time.API.015

What is the difference between Period and Duration?

Click here to view answer
Unlike Duration, which is about physical duration and whose day is always 24hrs long, Period maintains a conceptual day. Therefore, adding a single-day Period at 18:00 results in the next day again at 18:00 even if there was a daylight savings shift.

 

Flashcard OCP.7.Use.Java.SE.8.Date.Time.API.016

Which classes in java.time package define public constructors?

Click here to view answer
None of them do.

Leave Comment

Your email address will not be published.