aspose file tools*
The moose likes Beginning Java and the fly likes Calendar static final fields Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of JavaScript Promises Essentials this week in the JavaScript forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Calendar static final fields" Watch "Calendar static final fields" New topic
Author

Calendar static final fields

Pratik D mehta
Ranch Hand

Joined: Jul 29, 2010
Posts: 121

My Question is
We Create a concrete subclass instance of the Calendar Abstract Class using getInstance() method.
Than we can use add(field,amount) method to make changes to the fields in Calendar class.
But all these fields in Calendar class are static final , and how can we make changes to static final fields of the Calendar class.
eg -



Understanding is Everything - Peter Lord
Al Fraelich
Greenhorn

Joined: May 25, 2009
Posts: 20
reading through the API, I understand that it's certain things that are "static final" for example, number of months or names of months or number of days in a particular month. they don't want you adding the 45th of septober or something like that. Things that will never change, are best kept as "static final", speed of light, feet in a mile, JavaRanch's awesomeness and so on.

Hope that helps,
Al
Pratik D mehta
Ranch Hand

Joined: Jul 29, 2010
Posts: 121

Al Fraelich wrote:reading through the API, I understand that it's certain things that are "static final" for example, number of months or names of months or number of days in a particular month. they don't want you adding the 45th of septober or something like that. Things that will never change, are best kept as "static final", speed of light, feet in a mile, JavaRanch's awesomeness and so on.

Hope that helps,
Al

Thats not my question Al Fraelich
My question is that I am changing the field DATE in the above example by using add(Calendar.DATE,35);
But DATE is static final .
So why is it changing , we cannot change it Right ?
Christophe Verré
Sheriff

Joined: Nov 24, 2005
Posts: 14688
    
  16

Calendar.DATE is just an index (whose value is 5). It is used to access the date field, which is not final.


[My Blog]
All roads lead to JavaRanch
Pratik D mehta
Ranch Hand

Joined: Jul 29, 2010
Posts: 121

I didnt get that Christophe Verré .
Can you please simplify it for me , how does it work .
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 39773
    
  28
If you enter 1 it alters the no 1 field; if you enter 2 it alters the no 2 field. Those numbers are hidden behind the field names DATE MONTH YEAR etc., but you can find them from Calendar#field_detail and the "Constant Field Values" link.
Pratik D mehta
Ranch Hand

Joined: Jul 29, 2010
Posts: 121

So it it that the static final constant value of DATE gives call to Date which return the current Date .
Can you please tell me it calls which method in date to get the current date.
Have I got it right .
I think I am curious and Impatient on how things work deeply in java , Is it that I should go on reading and things would be clear gradually.
I still havent finished K & B .
Please advice me on that .
How can I proceed towards reading.
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 39773
    
  28
Don't know. You can find the code by unzipping the file called src.zip, which is usually inside your Java installation folder. It probably uses a switch-case block.
Sridhar Santhanakrishnan
Ranch Hand

Joined: Mar 20, 2007
Posts: 317
This might help.
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 39773
    
  28
Sridhar Santhanakrishnan wrote:This might help.
Yes, it did.
Pratik D mehta
Ranch Hand

Joined: Jul 29, 2010
Posts: 121

Thanyou Campbell and Sridhar
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Calendar static final fields