permaculture playing cards*
The moose likes Beginning Java and the fly likes Why Sun made Calendar class as a abstract class Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Why Sun made Calendar class as a abstract class" Watch "Why Sun made Calendar class as a abstract class" New topic
Author

Why Sun made Calendar class as a abstract class

jitendra vishnoi
Greenhorn

Joined: Jan 19, 2010
Posts: 10
I want to know why Sun make Calendar(or DateFormat or NumberFormat etc.) class as a abstract class. This class can also be as a normal class and its methods can also be have some implementation. We can also get instance of Calendar class by Calendar.getInstance() without extending the Calendar class.
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19649
    
  18

Calendar is abstract because there is no global calendar system. Most use the Gregorian calendar; that's why it has a matching concrete class GregorianCalendar. There are at least two other active calendars - the Buddhist calendar and the Japanese imperial calendar. Those too have matching (non-public) classes in Java.

DateFormat and NumberFormat are abstract because, well, that's how it's designed. They are meant to be used as the root of entire formatter hierarchies*. They provide no direct implementation; instead that's up to subclasses like SimpleDateFormat (the most often used DateFormat subclass) and DecimalFormat (the most often used NumberFormat subclass). But because DateFormat and NumberFormat are abstract it's easy to write and use a different one.


* Actually sub hierarchies, with java.text.Format being the root of the entire formatter hierarchy.


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Why Sun made Calendar class as a abstract class
 
Similar Threads
abstract class instance
Why is Calendar an abstract class ?
Instance of an abstract class
Calendar class problem?
calendar.getInstance()