I understand that java.time package introduced in Java 8 is much simpler to use. However, I am doing a challenge in Java 7 and when I run my code and I am breaking my head as to what the mistake is. I am trying to print Day of the week (in text) on last line. However, it prints null in the last print. If I change the month from 7 to 8, it prints Saturday in the last print statement. Wondering, what I am doing wrong.
Output with month parameter for new GregorianCalendar as 7
Wed Aug 05 00:00:00 AEST 2015
4
null
Output with month parameter for new GregorianCalendar as 8
Sat Sep 05 00:00:00 AEST 2015
7
Saturday
import java.util.Calendar;
import java.util.GregorianCalendar;
import java.util.Locale;
public class Test {
public static void main(String[] args){
Calendar calendar = new GregorianCalendar(2015,7,5);
System.out.println(calendar.getTime().toString());
System.out.println(calendar.get(Calendar.DAY_OF_WEEK));
System.out.println(calendar.getDisplayName(calendar.get(Calendar.DAY_OF_WEEK),Calendar.LONG, Locale.getDefault()));
}
}