When serializing an object from a stream it is used to check that the version being read is compatible with the current implementation.
Suppose this class is serialized to a file:
public class Foo implements Serializable {
public int x;
}
Subsequently the implementation changes, and now looks like this:
public class Foo {
public int y;
public int x;
}
If we try to read the original file, things will go wrong, and something will break.
Every class therefore has an implicit or explicit serialVersionUID which allows the compatibility or otherwise to be determined. If the serialVersionUID is identical between versions, it is assumed that they are compatible. If it is different, it is assumed that they are not.
The serialVersionUID is an internal ID for objects that are serializable (meaning: implement the Serializable interface). If you have e.g. a client and a server that send data via objects (e.g. a Message object) and you want to change something in the client and therefore compile the classes again. Then you deploy the client but leave the server as is. Then you have the Message class on the server in an old version and the Message class on the client in a new version and you will get a runtime error. However, if you provide a serialVersionUID in the Message class and don't change this ID when you compile your client again, the server will keep working. This is usefull e.g. if you change the Message class by adding new methods but want old applications still running. However, if you change existing methods, it is a good idea to also recreate the serialVersionUID as existing servers also don't work anymore with the new message object.