1. Which package contains the Java Date and Time API?
Answer:
Explanation:
The Java Date and Time API is located in the java.time package, introduced in Java 8.
2. What class represents a date in the Java Date and Time API?
Answer:
Explanation:
LocalDate represents a date in the Java Date and Time API without time or timezone information.
3. How do you obtain the current date using the Java Date and Time API?
Answer:
Explanation:
LocalDate.now() is used to obtain the current date according to the system clock and default time-zone.
4. Which class represents time in the Java Date and Time API?
Answer:
Explanation:
LocalTime represents a time without date or timezone information.
5. What is the purpose of the LocalDateTime class?
Answer:
Explanation:
LocalDateTime combines date and time information but does not include time-zone data.
6. How do you format dates and times in the new API?
Answer:
Explanation:
DateTimeFormatter is used for formatting and parsing dates and times in the new API.
7. Which class in the Date and Time API represents a specific instant in time?
Answer:
Explanation:
Instant represents a specific moment on the timeline in UTC.
8. What is the purpose of the ZonedDateTime class?
Answer:
Explanation:
ZonedDateTime handles date and time with associated timezone, including daylight saving time and timezone conversion.
9. How do you add or subtract time from a date or time object?
Answer:
Explanation:
The plus() and minus() methods are used to add or subtract time from date or time objects.
10. What class would you use to represent a duration of time?
Answer:
Explanation:
Duration is used to represent a time-based amount of time, such as seconds, minutes, and hours.
11. How do you obtain the current time based on the system clock?
Answer:
Explanation:
LocalTime.now() obtains the current time based on the system clock in the default time-zone.
12. Which class represents a date-based amount of time, such as '2 years, 3 months and 4 days'?
Answer:
Explanation:
Period is used to represent a date-based amount of time in terms of years, months, and days.
13. How do you compare two LocalDate objects?
Answer:
Explanation:
LocalDate objects can be compared using the equals() method for equality and compareTo() for ordering.
14. What is the primary use of the Clock class in the Date and Time API?
Answer:
Explanation:
The Clock class is used to provide access to the current instant, date, and time using a time-zone.
15. How do you convert a String to a LocalDate in Java?
Answer:
Explanation:
LocalDate.parse() is used to parse a string and return a