GeeCON Prague 2014*
The moose likes Beginning Java and the fly likes Why they have named a calendar method like this? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Why they have named a calendar method like this?" Watch "Why they have named a calendar method like this?" New topic
Author

Why they have named a calendar method like this?

ramya narayanan
Ranch Hand

Joined: Oct 06, 2008
Posts: 338
Dear noble ranchers,
We know we can get the date from the Calendar using the method



Actually it is leading to ambiguity as I think it should have been getDate() method.
What do you think?
Regards
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 39084
    
  23
Maybe there ought to have been a Calendar#getDate method, but a Calendar object does not record year, month, day. It records milliseconds since 1st Jan 1970 (negative numbers = before 1970) and calculates the date whenever the get method is called. [Have a look at the code: the values might be cached for future reference and only calculated once.] There are other possible ways to design a Calendar class, but that is the way the Java people at Sun chose to do it.
ramya narayanan
Ranch Hand

Joined: Oct 06, 2008
Posts: 338
As usual thanks Campbell!
Regards
Note: Wondering how you are knowing even the trivia of details. That's why you've been a bartender.

Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19697
    
  20

ramya narayanan wrote:

Just one note:
Calendar.getInstance() already returns a Calendar object for the current moment in time. The creation of the Date object and using it to set the time of the Calendar is not needed.


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 39084
    
  23
ramya narayanan wrote:Note: Wondering how you are knowing even the trivia of details.
Keep reading these fora Take notice when somebody tells me I am mistaken.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
 
subject: Why they have named a calendar method like this?