Core java interview Questions You'll Most Likely Be Asked (Second Edition)


Download 1.52 Mb.
Pdf ko'rish
bet90/171
Sana07.01.2023
Hajmi1.52 Mb.
#1081886
1   ...   86   87   88   89   90   91   92   93   ...   171
Bog'liq
Core JAVA Interview Questions Youll M...

237.
238.
number of minutes from the LocalTime on which it is invoked.
After subtracting 30 minutes from 7–15, the time would be 6–45.
So this code prints the output shown below:
06–45
How can you obtain the day of the week corresponding to
a date using the Java 8 DateTime API?
Answer:
The LocalDate class has a method called getDayOfWeek().
You can use this to get the day of the week corresponding to a
Date as shown by the code below:
LocalDate date = LocalDate.parse(“2017–04–25”);
System.out.println(date.getDayOfWeek());
The above code creates a LocalDate corresponding to 25th
April 2017. It then invokes the getDayOfWeek() method on this
date object. This method returns an enum called DayOfWeek.
The DayOfWeek enum has values corresponding to each day of
the week. Since the date 25th April 2017 corresponds to a
Tuesday, the getDayOfWeek method returns an enum value
corresponding to Tuesday. So, this code prints the output shown
below:
TUESDAY
Explain the differences between the Period and Duration
class.
Answer:





239.
The Period and Duration are both classes introduced by the
DateTime API and represent a time duration. However, there are
some differences between the two. These are as follows:
A Period represents a time interval in years, months and
days. A Duration on the other hand represents a time interval
in seconds and nanoseconds.
A Period is used to measure the time interval between two
LocalDate objects. A Duration on the other hand is used to
measure the time interval between two LocalTime objects.
A Period is typically used to measure longer time intervals
whereas a Duration is used to measure shorter time intervals.

Download 1.52 Mb.

Do'stlaringiz bilan baham:
1   ...   86   87   88   89   90   91   92   93   ...   171




Ma'lumotlar bazasi mualliflik huquqi bilan himoyalangan ©fayllar.org 2024
ma'muriyatiga murojaat qiling