I know this may be an obvious question, but I am looking at this code:
private Date lastActivity = new Date(-1);
And am curious what this does - the Date class has six different constructors, and only one can take a single argument of long
, like so:
public Date(long date)
which:
Allocates a Date object and initializes it to represent the specified number of milliseconds since the standard base time known as "the epoch", namely January 1, 1970, 00:00:00 GMT.
So is -1 just a placeholder? I appreciate any tips or advice.
Instantiation refers to the allocation of memory to create an instance of a class whereas initialization refers to naming that instance by assigning the variable name to that instance.
Instantiating an Object new requires a single argument: a call to a constructor method. Constructor methods are special methods provided by each Java class that are responsible for initializing new objects of that type. The new operator creates the object, the constructor initializes it.
To instantiate is to create such an instance by, for example, defining one particular variation of an object within a class, giving it a name and locating it in some physical place.
declaring is just what you have shown. like int a; you declared an int named a but you still not initialized it. instantiate is for class objects. means create a new object with new reference.
it is January 1, 1970, 00:00:00 GMT
minus one millisecond (negative numbers are dates in back of the beginning of the epoch)
One would typically do this to get a "well known" Date, perhaps for validation or comparisons (all "real Dates" are greater than this one), as a "marker object" to indicate that the Date is really unknown/illegal/pending but you don't want to use null for some reason, or perhaps for a Unit Test.
O.K., looking up the more proper terms for what I called a "marker value", I get sentinel value, flag value, trip value, rogue value, signal value, or dummy data. see wikipedia article here
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With