Found 9326 Articles for Object Oriented Programming

Duration compareTo() method in Java

karthikeya Boyini
Updated on 30-Jul-2019 22:30:25

5K+ Views

Two durations can be compared using the compareTo() method in the Duration class in Java. This method requires a single parameter i.e. the duration to be compared.If the first duration is greater than the second duration it returns a positive number, if the first duration is lesser than the second duration it returns a negative number and if both the durations are equal it returns zero.A program that demonstrates this is given as follows −Example Live Demoimport java.time.Duration; public class Demo { public static void main(String[] args) { Duration d1 = Duration.ofHours(8); ... Read More

Duration ZERO field in Java

Samual Sam
Updated on 30-Jul-2019 22:30:25

372 Views

The ZERO field sets the duration to zero in the Duration class in Java. This field is quite the same as the null value in different data types in Java.A program that demonstrates the ZERO field is given as follows −Example Live Demoimport java.time.Duration; public class Demo {    public static void main(String[] args) {       Duration d = Duration.ZERO;       boolean flag = d.isZero();       System.out.println("The duration is: " + d);       if(flag)          System.out.println("The above duration is of zero length");       else         ... Read More

Duration ofDays() method in Java

karthikeya Boyini
Updated on 30-Jul-2019 22:30:25

89 Views

The duration can be obtained in a 24 hour format using the ofDays() method in the Duration class in Java. This method requires a single parameter i.e. the number of days and it returns the duration in a 24 hour format. If the capacity of the duration is exceeded, then the ArithmeticException is thrown.A program that demonstrates this is given as follows −Example Live Demoimport java.time.Duration; public class Demo { public static void main(String[] args) { long days = 1; Duration duration = Duration.ofDays(days); ... Read More

MonthDay get() method in Java

Samual Sam
Updated on 30-Jul-2019 22:30:25

67 Views

The value of the specified field from the MonthDay can be obtained using the get() method in the MonthDay class in Java. This method requires a single parameter i.e. ChronoField that is required and it returns the value of the specified field from the MonthDay.A program that demonstrates this is given as follows −Example Live Demoimport java.time.*; import java.time.temporal.*; public class Demo { public static void main(String[] args) { MonthDay md = MonthDay.parse("--02-22"); System.out.println("The MonthDay is: " + md); System.out.println("The ... Read More

MonthDay query() method in Java

karthikeya Boyini
Updated on 30-Jul-2019 22:30:25

56 Views

The MonthDay object can be queried as required using the query method in the MonthDay class in Java. This method requires a single parameter i.e. the query to be invoked and it returns the result of the query.A program that demonstrates this is given as follows −Example Live Demoimport java.time.*; import java.time.temporal.*; public class Demo { public static void main(String[] args) { MonthDay md = MonthDay.parse("--02-22"); System.out.println("The MonthDay is: " + md); String chronology = md.query(TemporalQueries.chronology()).toString(); ... Read More

MonthDay with() Method in Java

Samual Sam
Updated on 30-Jul-2019 22:30:25

57 Views

An immutable copy of a MonthDay with the month of the year altered as required is done using the method with() in the MonthDay class in Java. This method requires a single parameter i.e. the month that is to be set in the MonthDay and it returns the MonthDay with the month of the year altered as required.A program that demonstrates this is given as follows −Example Live Demoimport java.time.*; public class Demo { public static void main(String[] args) { MonthDay md1 = MonthDay.parse("--02-22"); System.out.println("The MonthDay ... Read More

MonthDay withDayOfMonth() Method in Java

karthikeya Boyini
Updated on 30-Jul-2019 22:30:25

60 Views

An immutable copy of a MonthDay with the day of month altered as required is done using the method withDayOfMonth() in the MonthDay class in Java. This method requires a single parameter i.e. the day of month that is to be set in the MonthDay and it returns the MonthDay with the day of month altered as required.A program that demonstrates this is given as follows −Example Live Demoimport java.time.*; public class Demo { public static void main(String[] args) { MonthDay md1 = MonthDay.parse("--02-22"); System.out.println("The MonthDay ... Read More

MonthDay withMonth() Method in Java

Samual Sam
Updated on 30-Jul-2019 22:30:25

71 Views

An immutable copy of a MonthDay with the month altered as required is done using the method withMonth() in the MonthDay class in Java. This method requires a single parameter i.e. the month that is to be set in the MonthDay and it returns the MonthDay with the month altered as required.A program that demonstrates this is given as follows −Example Live Demoimport java.time.*; public class Demo { public static void main(String[] args) { MonthDay md1 = MonthDay.parse("--02-22"); System.out.println("The MonthDay is: " + md1); ... Read More

MonthDay toString() Method in Java

karthikeya Boyini
Updated on 30-Jul-2019 22:30:25

98 Views

The string value of the MonthDay object can be obtained using the method toString() in the MonthDay class in Java. This method requires no parameters and it returns the string value of the MonthDay object.A program that demonstrates this is given as follows −Example Live Demoimport java.time.*; public class Demo { public static void main(String[] args) { MonthDay md = MonthDay.parse("--02-22"); System.out.println("The MonthDay is: " + md.toString()); } }OutputThe MonthDay is: --02-22Now let us understand the above program.The string value of the MonthDay ... Read More

Duration ofMinutes() method in Java

Samual Sam
Updated on 30-Jul-2019 22:30:25

83 Views

The duration can be obtained in a one minute format using the ofMinutes() method in the Duration class in Java. This method requires a single parameter i.e. the number of minutes and it returns the duration in a one minute format. If the capacity of the duration is exceeded, then the ArithmeticException is thrown.A program that demonstrates this is given as follows −Example Live Demoimport java.time.Duration; public class Demo { public static void main(String[] args) { long minutes = 2; Duration duration = Duration.ofMinutes(minutes); ... Read More

Advertisements