I’m trying to learn Java and I’ve got everything setup and I’m running. I created a constructor for my first model and went to setup a constructor function that accepts a parameter. I added this function:
public Guest(String name) {
this.name = name;
this.signingDate = new Date(System.currentTimeMillis());
}
Netbeans threw an error saying I needed a default constructor. The error went away when I changed it to:
public Guest() {
}
public Guest(String name) {
this.name = name;
this.signingDate = new Date(System.currentTimeMillis());
}
I can’t imagine that this is how you create optional parameters within Java. So it brings up 2 questions:
- Why do I need a default constructor?
- How do I create optional parameters?
An entity class must have a no-argument public or protected constructor.