• Post Reply Bookmark Topic Watch Topic
  • New Topic

When a Period is initialized with more than 31 days or 12 months, it doesn't recalculate  RSS feed

 
Rebecca Wolf
Ranch Hand
Posts: 113
7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all,

First off: My apologies if all the threads I'm starting come across as spammy. I hope other people will benefit from them as well, though.

From Mala Gupta's OCAJP 8 book, page 289: 'When you initialize a Period instance with days more than 31 or months more than 12, it doesn't recalculate its years, months, or days components'. What does this mean? I understand a Period instance can't deal with more than 31 days or more than 12 months, but what does 'not recalculating' mean in this context?

Thanks!

Regards,
Shane
 
Stephan van Hulst
Saloon Keeper
Posts: 7993
143
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Shane Jensen wrote:I understand a Period instance can't deal with more than 31 days or more than 12 months

This is untrue. For instance, Period can handle more than 12 months just fine. When you initialize a Period with 15 months, it means just that: "A period of 15 months". When the book mentions that Period doesn't recalculate, it means that a "period of 15 months" is not normalized to a "period of 1 year and 3 months".

Be careful, a "period of 15 months" is NOT equal to a "period of 1 year and 3 months".
 
Roel De Nijs
Sheriff
Posts: 11338
177
AngularJS Chrome Eclipse IDE Hibernate Java jQuery MySQL Database Spring Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Shane Jensen wrote:From Mala Gupta's OCAJP 8 book, page 289: 'When you initialize a Period instance with days more than 31 or months more than 12, it doesn't recalculate its years, months, or days components'. What does this mean? I understand a Period instance can't deal with more than 31 days or more than 12 months, but what does 'not recalculating' mean in this context?

That's something you can easily figure out yourself by creating a few code snippets using the Period API and experiment with it. This will give you some (very important) hands-on experience! Learning a programming language is like driving a car: you don't learn how to drive a car by just reading a book, you have to get your hands dirty. And if I remember correctly, you have asked (in one of your other threads) some advice about what to do next after completely having read this study guide
 
Rebecca Wolf
Ranch Hand
Posts: 113
7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for your replies Stephan and Roel! I played around a bit with Periods, and I understand the meaning of this now.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!