Class 1, Part 2 | Intro to Java 30-IT-396 |
Using the Instantiated Date Object
Date today;
today.toString(); // This will not work.
It won't even compile. At this point,
// today is not an object and does not even refer to an object.
today = new Date(); // Ok, now today is an object.
Date today = null;
// more lines of code...
if (today == null) {
System.out.println("No date provided.");
}
Date myDate = new Date();
Date yourDate;
yourDate = myDate; // Though legal, this
will just copy the reference.
// There is still one and only one Date object in existence.
yourDate = (Date) myDate.clone();
// Now we actually have a copy of the first date object in
// another date object. We use (Date) because clone()
// actually returns an Object type, and we must cast it to
// Date type.
Created by: Brandan
Jones January 4, 2002