That's not completely true and what actually happens is a good demonstration of why the Calendar class is implemented as a factory. If you look at the source code for the Calendar.getInstance() method you will see it calls the createCalendar method and that decides what type of Calendar subclass to return based on the locale. In other words you can use the same code wherever your program is run and an instance of the appropriate class will be returned
Hello, The calendar.getInstance, if no locale is passed, and if the locale is not Japan, by default returns a Gregorian Calendar. Have a look at the code snippet and its output below:
The above code outputs:
java.util.GregorianCalendar[time=1329329597419,areFieldsSet=true,areAllFieldsSet=true,lenient=true,zone=sun.util.calendar.ZoneInfo[id="America/Los_Angeles",offset=-28800000,
dstSavings=3600000,useDaylight=true,transitions=185,lastRule=java.util.SimpleTimeZone[id=America/Los_Angeles,offset=-28800000,dstSavings=3600000,useDaylight=true,startYear=0,
startMode=3,startMonth=2,startDay=8,startDayOfWeek=1,startTime=7200000,startTimeMode=0,endMode=3,endMonth=10,endDay=1,endDayOfWeek=1,endTime=7200000,endTimeMode=0]],
firstDayOfWeek=1,minimalDaysInFirstWeek=1,ERA=1,YEAR=2012,MONTH=1,WEEK_OF_YEAR=7,WEEK_OF_MONTH=3,DAY_OF_MONTH=15,DAY_OF_YEAR=46,DAY_OF_WEEK=4,
DAY_OF_WEEK_IN_MONTH=3,AM_PM=0,HOUR=10,HOUR_OF_DAY=10,MINUTE=13,SECOND=17,MILLISECOND=419,ZONE_OFFSET=-28800000,DST_OFFSET=0]
The Calendar.getInstance() indeed works as you said. Gets the Locale, and returns a specific subclass implementation based on Locale.
The getInstance() method abstracts all this locale checking and subclass creation from the end user which is the objective of a factory method!
Cheers
Mahesh