Year query() Method in Java with Examples Last Updated : 10 Jan, 2019 Summarize Comments Improve Suggest changes Share Like Article Like Report query() method of an Year class used to query this Year using the specified query as parameter.The TemporalQuery object passed as parameter define the logic to be used to obtain the result from this Year. Syntax: public <R> R query(TemporalQuery<R> query) Parameters: This method accepts only one parameter query which is the query to invoke. Return value: This method returns the query result, null may be returned. Exception: This method throws following Exceptions: DateTimeException - if unable to query . ArithmeticException - if numeric overflow occurs. Below programs illustrate the query() method: Program 1: Java // Java program to demonstrate // Year.query() method import java.time.*; import java.time.temporal.*; public class GFG { public static void main(String[] args) { // create Year object Year ym = Year.of(2019); // apply query method of Year class String value = ym.query(TemporalQueries .precision()) .toString(); // print the result System.out.println("Precision value" +" for Year is " + value); } } Output: Precision value for Year is Years Program 2: Showing if query did not found the required object then it returns null. Java // Java program to demonstrate // Year.query() method import java.time.*; import java.time.temporal.*; public class GFG { public static void main(String[] args) { // create Year object Year ym = Year.of(2019); // apply query method of Year class // print the result System.out.println("offset value for Year is " + ym.query( TemporalQueries.offset())); } } Output: offset value for Year is null References: https://docs.oracle.com/javase/10/docs/api/java/time/Year.html#query(java.time.temporal.TemporalQuery) Comment More infoAdvertise with us Next Article Year range() method in Java with Examples A AmanSingh2210 Follow Improve Article Tags : Java Java-Functions Java-time package Java-Year Practice Tags : Java Similar Reads Year of() method in Java with Examples The of() method of Year class in Java is used to return an Year instance. It accepts an year according to the proleptic ISO calendar system and returns an instance of Year with the specified isoYear. Syntax: public static Year of(int isoYear) Parameter: It accepts a single integral value isoYear as 1 min read Year plusYears() Method in Java with Examples plusYears() method of the Year class used to a copy of this Year after adding the specified number of years to this year. This instance is immutable and unaffected by this method call. Syntax: public Year plusYears(long yearsToadd) Parameters: This method accepts yearsToadd as parameter which is the 2 min read Year until() Method in Java with Examples until() method of the Year class used to calculate the amount of time between two Year objects using TemporalUnit. The start and end points are this and the specified Year passed as a parameter. The result will be negative if the end is before the start. The calculation returns a whole number, repre 2 min read Year range() method in Java with Examples range() method of the Year class is used to get the range of field in terms of the minimum and maximum values and the field is passed as a parameter to this method. The returned value for this method is ValueRange object for the field and the method returns ValueRange object only for those fields wh 2 min read Year now() method in Java with examples The now() method of Year class in Java is used to return the current year from the system clock in the default time-zone. Syntax: public static Year now() or, public static Year now(Clock clock) or, public static Year now(ZoneId zone) Parameter: The parameter is optional for this method as shown in 2 min read Year minusYears() method in Java with Examples minusYears() method of the Year class used to a copy of this Year after subtracting the specified number of years from this year. This instance is immutable and unaffected by this method call. Syntax: public Year minusYears(long yearsToSubtract) Parameters: This method accepts yearsToSubtract as par 2 min read Like