I am a college student.
In our college we have to develop a simple Date class in Java similar to the one available in java.util package.
If we do that then what are the methods we can implement in that class,
Since most of the methods are deprecated in original Date class.
I saw the original Date class definitions in java/util/Date.java. Being a beginner to java, I could not understand the concepts of Serializable, Cloneable, Comparable ,and many variables like fasttime.
It will be good if we can implement this date class simply (since we have to develop this code as a test with in 3 hours at lab.)
Whether it is necessary to implement those concepts in a simple Date class.
If I take it as a Project and start developing the whole Date utilities,
then that code will run to many pages
and I cannot finish it with 3 hours for our lab session.
So someone please guide me….
I have doubts about….
- Whether it is possible to create a utility class similar to Date class with a simpler implementation.
- If we do that, then what are the methods we can implement in that class , since most of the useful methods are deprecated in the original date class.
Thanks in advance.
You don’t have to implement all the interfaces to have a simple working
Dateclass.I would suggest that you forget about Java’s
Dateclass and consider what you think is needed for a date class. For example:toString()Would give you a pretty good basic date class.
For the sake of completeness, I’ll tell you what the interfaces are for. You can decide whether to implement them based on how much you have learned and the assignment’s requirements:
Serializableis for saving your object to a stream. You actually don’t need to do much work to implement it.Comparableis for comparing objects (date1.compareTo(date2)should return an integer indicating whetherdate1is before, after, or the same asdate2).Clonableis for creating a deep copy of the object.