What does it mean: The serializable class does not declare a static final serialVersionUID field?

From the javadoc: The serialization runtime associates with each serializable class a version number, called a serialVersionUID, which is used during deserialization to verify that the sender and receiver of a serialized object have loaded classes for that object that are compatible with respect to serialization. If the receiver has loaded a class for the object that has a different serialVersionUID than that of the corresponding sender's class, then deserialization will result in an InvalidClassException. A serializable class can declare its own serialVersionUID explicitly by declaring a field named "serialVersionUID" that must be static, final, and of type long: You can configure your IDE to: ignore this, instead of giving a warning.

Autogenerate an id As per your additional question "Can it be that the discussed warning message is a reason why my GUI application freeze? ": No, it can't be. It can cause a problem only if you are serializing objects and deserializing them in a different place (or time) where (when) the class has changed, and it will not result in freezing, but in InvalidClassException.

2 You can also let your IDE to autogenerate one. – BalusC Feb 18 '10 at 14:08.

It must be changed whenever anything changes that affects the serialization (additional fields, removed fields, change of field order, ...) That's not correct. It should be changed whenever you make a change that is incompatible under the rules given in the Versioning section of the Object Serialization Specification, which specifically does not include additional fields or change of field order, and when you haven't provided readObject()/writeObject() and/or readResolve()/writeReplace() methods that could cope with the change.

1 for your attention to details. – gulbrandr Feb 1 at 15:28.

Import java.awt. *; import javax.swing. *; public class JFrame10 extends JFrame { JCheckBoxMenuItem cb; JMenu file,edit; private static final long serialVersionUID=100L.

Any class that can be serialized (i.e. Implements Serializable) should declare that UID and it must be changed whenever anything changes that affects the serialization (additional fields, removed fields, change of field order, ...). The field's value is checked during deserialization and if the value of the serialized object does not equal the value of the class in the current VM, an exception is thrown.

Note that this value is special in that it is serialized with the object even though it is static, for the reasons described above.

– Roman Feb 18 '10 at 14:00 Yes, JFrame is a java.awt. Component which implements Serializable. Code never changes anything that affects serialization, only programmers do that.

I don't know a list that lists all changes that affect serialization. Check en.wikipedia.Org/wiki/Serialization#Java for a description of serialization in Java. – Thomas Lötzer Feb 18 '10 at 14:12 It is not serialized with the object.

It shouldn't be changed unless you want to break compatibility, or if you have already done so by departing from what it says in the Versioning section of the specification. That does not include adding or reordering fields. The correct reference is not Wikipedia but the Object Serialization Specification.

– EJP May 16 at 1:18.

The reasons for warning are documented here, and the simple fixes are to turn off the warning or put the following declaration in your code to supply the version UID. The actual value is not relevant, start with 999 if you like, but changing it when you make incompatible changes to the class is. Public class WorldSwing extends JFrame { JTextArea m_resultArea = new JTextArea(6, 30); private static final long serialVersionUID = 1L.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions