Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>It's a <em>manifest constant</em>. It doesn't refer to any <em>particular</em> day of the month, but to the <em>concept</em> DAY_OF_MONTH.</p> <p>You use it to specify which element of a date you want to get (or set).</p> <p>E.g., I want to add (increase the Calendar's date by) one month:</p> <pre><code> c.add ( Calendar.MONTH, 1 ) </code></pre> <p>I want to add one day:</p> <pre><code> c.add ( Calendar.DAY_OF_YEAR, 1 ) ; </code></pre> <p>I'm calling the same function, with the first parameter the <em>manifest constant</em> of the Calendar field I want to increment/decrement by. (Of course, incrementing/decrementing by any particular field may change other fields: If I add one day to December 31 2099, The DAY_OF_MONTH, MONTH and YEAR fields will all be changed.)</p> <p>The alternative would be to have different setters for each field, e.g, </p> <pre><code> addMonth( int n ) ; addDayOfYear( int n); </code></pre> <p>That would make coding some use cases more tedious however.</p> <hr> <p>The OP asks:</p> <blockquote> <p>Can anyone walk me through what happens, say, when you invoke cal.set(2010, 8, 2) where cal is a Calendar? What I'd like to know is how the compiler connects 2 to DATE_OF_MONTH, or where that 2 ends up in the heap, or what the qualified variable name is under which that 2 is stored. Thanks all who answered!</p> </blockquote> <p>The "strict" Object Oriented answers is, "as a client programmer using Calendars rather than implementing them, you shouldn't need to know about the Calendar's internal layout or algorithms".</p> <p>The real answer is that Calendar is an interface, so any particular implementing class could do these things any number of ways, so long as the implementation adheres to the public interface <em>and</em> the semantics of the Calendar interface.</p> <p>The actual implementation of, say, GregorianCalendar is probably that internally it holds the date as some number of seconds since some special date, e.g, the linux "era" (1 January 1970) or the first institution of the Gregorian Calendar (15 October 15 1582). </p> <p>So <code>cal.set(2010, 8, 2)</code> probably multiples the year by 365 * 24 * 60 * 60, plus any leap years, the <code>8</code> is used to find the number of seconds to the end of the seventh month (again, accounting for a leap day, if any), the 2 adds the number of seconds in two days, etc.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload