I would be happy with code throwing an IllegalArgumentException there. That is the usual practice when a constructor argument or method argument cannot be validated.
Any method (or constructor) offers a contract to the user: "If you supply an argument which meets these requirements . . . , then I guarantee to . . . "
If you pass an invalid argument (eg negative salary) then that contract is invalidated; the method may do anything it wants, returning an incorrect result, going into an infinite loop, doing nothing at all, etc. It is far better to throw an Exception so the calling method "knows" something has gone wrong.
The design problem is more complicated than you suggested. In fact you have fName lName and Name. You have the same information in two fields. It is then possible to change the fields so fName = "Campbell" lName = "Ritchie" and Name = "Sebastian Janisch", (
) which I am sure would breach your intended class invariants. There are also problems with the constructor; I can't see where fName and lName are passed, so they would default to
null, and this risks Exceptions if those fields are used. And, even better, you are liable to have a Name set to "null null".
Suggestions:
Change the constructor heading to public Employee(String fName, String lName, double salary)Delete the Name fieldIf you ever need name, make it from fName + " " + lNameRemember you may need the this.fName = fName; idiom in the constructor