The no-arg constructor is automatically added by the compiler if the developer does not provide a constructor. However, as soon as you put your own custom constructor with parameters, the compiler stops adding the default constructor to you.
In this case, if you still want to use the no-arg constructor, you must explicitly specify it:
public User() { } public User(int id, String name) { }
The logic of this is as follows: if you define your own parameterized constructor, you declare that the parameters specified in the constructor are needed to create the class object. Therefore, you also implicitly declare if the user of your library does not provide these two parameters, the object cannot be created. Thus, the compiler will not add you the no-arg constructor.
If you also want to declare that your class can still work, if none of the specified parameters is provided in the parameterized constructor, and you (no argument), then you explicitly declare that you create the constructor yourself without arguments.
source share