Thursday, September 4, 2025
HomeLanguagesJavaCalendar getActualMaximum() Method in Java with Examples

Calendar getActualMaximum() Method in Java with Examples

The getActualMaximum(int field_value) method of Calendar class is used to return the maximum value that the specified calendar field could have, based on the time value of this Calendar.

Syntax:

public int getActualMaximum(int field_value)

Parameters: The method takes one parameter field_value of integer type and refers to the calendar whose maximum value is needed to be returned.

Return Value: The method returns the maximum value of the passed field.

Below programs illustrate the working of getActualMaximum() Method of Calendar class:
Example 1:




// Java Code to illustrate
// getActualMaximum() Method
  
import java.util.*;
  
public class CalendarClassDemo {
    public static void main(String args[])
    {
        // Creating a calendar
        Calendar calndr
            = Calendar.getInstance();
  
        // Getting the maximum value that
        // year field can have
        int yr
            = calndr.getActualMaximum(Calendar.YEAR);
        System.out.println("The Maximum year: "
                           + yr);
  
        // Getting the maximum value that
        // month field can have
        int mon
            = calndr.getActualMaximum(Calendar.MONTH);
        System.out.println("The Maximum Month is: "
                           + mon);
    }
}


Output:

The Maximum year: 292278994
The Maximum Month is: 11

Example 2:




// Java Code to illustrate
// getActualMaximum() Method
  
import java.util.*;
  
public class CalendarClassDemo {
    public static void main(String args[])
    {
        // Creating a calendar object
        Calendar calndr
            = new GregorianCalendar(2018, 9, 2);
  
        // Getting the maximum value that
        // year field can have
        int yr
            = calndr.getActualMaximum(Calendar.YEAR);
        System.out.println("The Maximum year: "
                           + yr);
  
        // Getting the maximum value that
        // month field can have
        int mon
            = calndr.getActualMaximum(Calendar.MONTH);
        System.out.println("The Maximum Month is: "
                           + mon);
    }
}


Output:

The Maximum year: 292278993
The Maximum Month is: 11

Reference: https://docs.oracle.com/javase/7/docs/api/java/util/Calendar.html#getActualMaximum(int)

RELATED ARTICLES

Most Popular

Dominic
32261 POSTS0 COMMENTS
Milvus
81 POSTS0 COMMENTS
Nango Kala
6626 POSTS0 COMMENTS
Nicole Veronica
11795 POSTS0 COMMENTS
Nokonwaba Nkukhwana
11855 POSTS0 COMMENTS
Shaida Kate Naidoo
6747 POSTS0 COMMENTS
Ted Musemwa
7023 POSTS0 COMMENTS
Thapelo Manthata
6695 POSTS0 COMMENTS
Umr Jansen
6714 POSTS0 COMMENTS