The Date class is a typical class. It is one of the classes available
in the standard library.
Be warned, there are actually two Date classes. java.util.Date, which
we use here, and java.sql.Date, which is often used with database calls.
If you are using both Date classes, you'll need to specify them with the
package name (java.util or java.sql, as the case may be). If not,
you'll get an ambiguous class error when you try to compile!
The first step in using an object is physically getting an instance
of the object from the class, or constructing the object.
You do this by using the constructor.
Constructors always have the same name as the class name. Remember
StringManip ?
There are a number of constructors for the Date
class. Some are deprecated, meaning they are being phased
out. For our use, we'll use the empty constructor, Date().
If a constructor has the same name as a class, how can a class have multiple
constructors? The constructors actually all have the same name, but
the parameter arguments differ. The parameter arguments are the values
you put between the parenthesis when calling the constructor.
Date() creates a Date object initialized to the current date and
time, in milliseconds.
Interestingly, the instance field (or attribute) of the Date object that
stores the current date and time stores it in one variable - the number
of milliseconds since January 1, 1970.
To create a Date object, use the new keword and the Date()
constructor.
new Date() simply creates an object, presumably to be passed as
a parameter.
Date today = new Date(); creates the object and assigns it to
the variable today.