Java serialisation stores, in the stream, an ObjectStreamClass for each object that has been serialised. This includes, among other things, the name and the serialisation unique identifier (serialVersionUID) of the class.
When deserialising, the serialisation unique identifier must be the same in the stream being serialised as it is in the class of the same name that is loaded. If not, you will get InvalidClassException.
By default, a Serializable class gets a serialisation unique identifier assigned to it by Java. This is obtained by doing some sort of hashing of the data fields and the method signatures in the class, I think.
However, you can specify your own value for serialisation unique identifier, by a line like the following in your class:
static final long serialVersionUID = 7660679424232768991L;
Why would you want to do that?
Well, the default value changes whenever you make any change to the fields or methods of the class. However, changes to the methods may very well not mean that it is wrong to deserialise an old serialised object using the new class. By specifying your own value, and not changing it when you change the methods, you can say to Java that it's OK to deserialise the old serialised object.
Further, Java serialisation is pretty smart in that it stores the field names. So, in fact, if you add a new field to a class, and give an appropriate default value, it may still be OK to deserialise the old object; the field that is missing will simply be defaulted. Again, if you want this to happen, specify your own serialVersionUID value and don't change it when you add the field.
If you delete fields or change their types or their meanings, it is probably not a good idea to try to deserialise an old object.