Constructor vs setter validations
<p>I have the following class : </p>

<pre><code>public class Project {

    private int id;
    private String name;  

    public Project(int id, String name, Date creationDate, int fps, List&lt;String&gt; frames) {
        if(name == null ){
            throw new NullPointerException("Name can't be null");
        }

        if(id == 0 ){
            throw new IllegalArgumentException("id can't be zero");
        }

            this.name = name;
            this.id = id;

    }

    private Project(){}

    public int getId() {
        return id;
    }

    public void setId(int id) { 
        this.id = id;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

}
</code></pre>

<p>I have three questions:</p>

<ol>
<li><p>Do I use the class setters instead of setting the fields directly. One of the reason that I set it directly, is that in the code the setters are not final and they could be overridden. </p></li>
<li><p>If the right way is to set it directly and I want to make sure that the name filed is not null always. Should I provide two checks, one in the constructor and one in the setter.</p></li>
<li><p>I read in effective java that I should use <code>NullPointerException</code> for null parameters. Should I use <code>IllegalArgumentException</code> for other checks, like id in the example.</p></li>
</ol>
