aspose file tools*
The moose likes Beginning Java and the fly likes Calendar or GregorianCalendar - how to get Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Calendar or GregorianCalendar - how to get" Watch "Calendar or GregorianCalendar - how to get" New topic
Author

Calendar or GregorianCalendar - how to get

David Duran
Ranch Hand

Joined: Feb 11, 2002
Posts: 122
Which of the two is the more recommended way to get a calendar object or is there no difference? I read once that the Calendar object is a pretty "heavy" object and they recommened using the latter below. Any thoughts?
Calendar cal = Calendar.getInstance();
GregorianCalendar cal = new GregorianCalendar();
Dirk Schreckmann
Sheriff

Joined: Dec 10, 2001
Posts: 7023
GregorianCalendar is the type meant to represent the standard calendar used by most of the world (according to the class documentation). For that reason, I'd probably prefer it in most situations I'm likely to make use of a calendar.


[How To Ask Good Questions] [JavaRanch FAQ Wiki] [JavaRanch Radio]
Joel McNary
Bartender

Joined: Aug 20, 2001
Posts: 1821

I'm not sure what is meant by a "heavy" object in this context. I personally use Calendar.getInstance(), because that the most loosely coupled reference (and takes less typing, so it's good in two ways ) Since getInstance returns the Locale-based subclass, I am more than likely to wind up with a GregorianCalendar anyway, unless my code is being run in a strange locale. And if my code is being run in a strange locale, then it's a good thing I used the more loosly-coupled Calendar.


Piscis Babelis est parvus, flavus, et hiridicus, et est probabiliter insolitissima raritas in toto mundo.
Thomas Paul
mister krabs
Ranch Hand

Joined: May 05, 2000
Posts: 13974
The Calendar getInstance method eventually runs this method with the default zone and locale:

All Calendar.getInstance() does is create a new GregorianCalendar object with the default zone and locale.
[ June 06, 2003: Message edited by: Thomas Paul ]

Associate Instructor - Hofstra University
Amazon Top 750 reviewer - Blog - Unresolved References - Book Review Blog
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Calendar or GregorianCalendar - how to get