Immutable classes:
1. All fields is private final.
2. Noway to modify the object after construction.
3. Object must be constructed probably that all fields must be initialized.
4. the class must be final.
For example:
public final class ImmutableClass{
private final int field1;
private final String field2;
public ImmutableClass(int _1, String _2) {
this.field1 = _1;
this.field2 = _2;
}
public int getfield1(){
return field1;
}
public String getfield2(){
return field2;
}
}
Note that there are no set method and the only way to modify the fields is using constructor. Read more
here