1

I have an assignment I am working on for my class. In this assignment, I am asked to create the constructor and the get/set methods. I have done all of that EXCEPT in one of the classes, there are several attributes is listed which use "SimpleDateFormat" as a data type. In all my research, I've found SimpleDateFormat as a method, but not as a data type in itself (such as String or Boolean) and I don't see where it's been set up anywhere else except to import "import java.text.SimpleDateFormat;" into the class file. I cannot find anywhere that there's any kind of default format for this as a data type - I am brand new to Java of course so I amy be overlooking it, or missing something completely - but it's not being covered in my text in any way so I'm hoping you wonderful gurus can lend a hand and help point me in the right direction.

Here is the section of the attributes in the class file I was given for this assignment:

private SimpleDateFormat acquisitionDate;
private SimpleDateFormat statusDate;
private String acquisitionSource;
private Boolean reserved;

private String trainingLocation;
private SimpleDateFormat trainingStart;
private SimpleDateFormat trainingEnd;
private String trainingStatus;

Any help/insight is greatly appreciated!

5
  • 1
    Here is the javadocs docs.oracle.com/javase/7/docs/api/java/text/… Commented Oct 9, 2019 at 2:10
  • Where have you found that SimpleDateFormat is a method, not a type? Commented Oct 9, 2019 at 2:16
  • @Tom I probably have the verbiage wrong but I was looking it up here: docs.oracle.com/javase/8/docs/api/java/text/… and it returns that it's a method that I would have to create each date object ... it seems far more convoluted than the assignment and the level of the class... I will reach out to my instructor for further clarify I just wanted to get validation that I wasn't overlooking something simple in just assigning a formatted date of acquisitionDate = "12/1/19" or "Dec 1 19" or something to this effect in my constructor assignments. Thank you. Commented Oct 9, 2019 at 2:21
  • I recommend you don’t use SimpleDateFormat and Date. Those classes are poorly designed and long outdated, the former in particular notoriously troublesome. Instead use DateTimeFormatter and other classes from java.time, the modern Java date and time API. You can tell your instructor the same if relevant. Commented Oct 9, 2019 at 7:48
  • Technically the outdated SimpleDateFormat was a class just like String and Boolean are classes. And therefore also a type. It had got methods just like they have got methods. The difference is that it was a utility class, what Larman calls a pure fabrication, so not useful for holding domain data. Only in this way you are correct in not regarding it as a data type. Commented Oct 9, 2019 at 7:54

1 Answer 1

2

change SimpleDateFormat to Date or String. SimpleDateFormat is just a way to convert String to Date and vice versa with wanted format. it shouldn't be treated as date type.

Sign up to request clarification or add additional context in comments.

1 Comment

This is good. Additionally, when you need to store a "date" and do no date manipulation stuff, it is better to store these dates as String. When date manipulation is needed, it is better to use LocalDate, or LocalDateTime, or any other data types in java.time package. These new classes offers simplier method when manipulating date vs java.util.Date class.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.