Java Programing laungage

java.util Projects

java.util Project 1

Get first day of week

In this programming tutorials, we shall be learn how to get the first day of week in Java. As we know that the GregorianCalendar provides the current date, month and year in a yearly calendar. we can Use the Calendar subclass for performing this task in the java application. This calendar is used in most of world.

Previous Home Next

Program Description

This example helps us for accessing the first day of the week. For accessing the day we need the object of the GregorianCalendar. by help of this object we calculate the first day of week using the getFirstDayOfWeek() method and getActualMaximum(Calendar.DAY_OF_WEEK) methods which is used to match the case. If any of these will match, it will display the actual day that displays like the following output.

Code Description

getActualMaximum(int field)

This method used to return the maximum value according to its field. It is take one field like DAY_OF_MONTH, DAY_OF_WEEK etc.


This method is used to get the first day of the week.


package r4r;
import java.util.*;
public class getfirstdaytest {
public static void main(String[] args) {
GregorianCalendar grecal = new GregorianCalendar();
int week = grecal.getActualMaximum(Calendar.DAY_OF_WEEK);
System.out.println("Day of week: " + week);
int firstday = grecal.getFirstDayOfWeek() ;
case 1:
case 2:
case 3:
case 4: System.out.println("Wednesday"); break; case 5: System.out.println("Thrusday"); break; case 6: System.out.println("Friday"); break; default: System.out.println("Saturday"); break; } } }
Previous Home Next