This week's book giveaway is in the Design forum.
We're giving away four copies of Design for the Mind and have Victor S. Yocco on-line!
See this thread for details.
Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Calendar static final fields

 
Pratik D mehta
Ranch Hand
Posts: 121
Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 -


 
Al Fraelich
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 121
Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 14691
16
Eclipse IDE Ubuntu VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Calendar.DATE is just an index (whose value is 5). It is used to access the date field, which is not final.
 
Pratik D mehta
Ranch Hand
Posts: 121
Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I didnt get that Christophe Verré .
Can you please simplify it for me , how does it work .
 
Campbell Ritchie
Sheriff
Posts: 48645
56
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 121
Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 48645
56
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 317
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This might help.
 
Campbell Ritchie
Sheriff
Posts: 48645
56
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sridhar Santhanakrishnan wrote:This might help.
Yes, it did.
 
Pratik D mehta
Ranch Hand
Posts: 121
Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanyou Campbell and Sridhar
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic