In java.. If when we have to compare an object with another object. We compare each field in that object.
Student1 object has marks1, marks2, marks3, name, age as fields. Student2 object has marks1, marks2, marks3, name, age as fields. So to check if 2 students are equal or not... we compare each field.
if(Student1.marks1 == Student2.marks1 &&
Student1.marks2 == Student2.marks2 &&
Student1.marks3 == Student2.marks3 &&
Student1.name == Student2.name &&
Student1.age == Student2.age)
{
// we say that Students are same
}
But what if the Student object has many fields.. Student1 object has marks1, marks2, marks3, name, age, address, color, class, country, section, x, y, z like this 100 such fields Student2 object has marks1, marks2, marks3, name, age, address, color, class, country, section, x, y, z like this 100 such fields
So how should we now check whether 2 objects are equal or not..? going with the above approach.. of checking each individual field does not make sense since they are 100 such fields.
Someone was telling this could be done by serialization in java. Can any one please tell how we can go about it or any other way?