How to create an immutable class
<p>I want to make the class below immutable. Can anyone provide a simple example of creating an immutable class in java?</p>

<pre><code>class Emp implements Comparable
{
      String name,job;
      int salary;
      public Emp(String n,String j,int sal)
      {
         name=n;
         job=j;
         salary=sal;
       }
      public void display()
      {
        System.out.println(name+"\t"+job+"\t"+salary);
       }
     public boolean equals(Object o)
      {

        // use a shortcut comparison for slightly better performance; not really required  
            if (this == o)  
            {  
                return true;   
            }  
            // make sure o can be cast to this class  
            if (o == null || o.getClass() != getClass())  
            {  
                // cannot cast  
                return false;  
            }            
            // can now safely cast       
          Emp p=(Emp)o;
          return this.name.equals(p.name)&amp;&amp;this.job.equals(p.job) &amp;&amp;this.salary==p.salary;
       }
      public int hashCode()
       {
          return name.hashCode()+job.hashCode()+salary;
       }


       public int compareTo(Object o)
       {
          Emp e=(Emp)o;
          return this.name.compareTo(e.name);
           //return this.job.compareTo(e.job);
        //   return this.salary-e.salary;

        }
} 
</code></pre>
