![Trending Articles on Technical and Non Technical topics](/images/trending_categories.jpeg)
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Found 9326 Articles for Object Oriented Programming
![karthikeya Boyini](https://www.tutorialspoint.com/assets/profiles/13518/profile/60_31598-1537784993.jpg)
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
![Samual Sam](https://www.tutorialspoint.com/assets/profiles/13514/profile/60_83486-1512649303.jpg)
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
![karthikeya Boyini](https://www.tutorialspoint.com/assets/profiles/13518/profile/60_31598-1537784993.jpg)
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
![Samual Sam](https://www.tutorialspoint.com/assets/profiles/13514/profile/60_83486-1512649303.jpg)
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
![karthikeya Boyini](https://www.tutorialspoint.com/assets/profiles/13518/profile/60_31598-1537784993.jpg)
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
![Samual Sam](https://www.tutorialspoint.com/assets/profiles/13514/profile/60_83486-1512649303.jpg)
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
![karthikeya Boyini](https://www.tutorialspoint.com/assets/profiles/13518/profile/60_31598-1537784993.jpg)
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
![Samual Sam](https://www.tutorialspoint.com/assets/profiles/13514/profile/60_83486-1512649303.jpg)
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
![karthikeya Boyini](https://www.tutorialspoint.com/assets/profiles/13518/profile/60_31598-1537784993.jpg)
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
![Samual Sam](https://www.tutorialspoint.com/assets/profiles/13514/profile/60_83486-1512649303.jpg)
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