I have the warning message given in the title. I would like to understand and remove it. I found already some answers on this question but I do not understand these answers because of an overload with technical terms. Is it possible to explain this issue with simple words?
P.S. I know what OOP is. I know what is object, class, method, field and instantiation.
P.P.S. If somebody needs my code it is here:
import java.awt.*; import javax.swing.*; public class HelloWorldSwing extends JFrame { JTextArea m_resultArea = new JTextArea(6, 30); //====================================================== constructor public HelloWorldSwing() { //... Set initial text, scrolling, and border. m_resultArea.setText("Enter more text to see scrollbars"); JScrollPane scrollingArea = new JScrollPane(m_resultArea); scrollingArea.setBorder(BorderFactory.createEmptyBorder(10,5,10,5)); // Get the content pane, set layout, add to center Container content = this.getContentPane(); content.setLayout(new BorderLayout()); content.add(scrollingArea, BorderLayout.CENTER); this.pack(); } public static void createAndViewJFrame() { JFrame win = new HelloWorldSwing(); win.setTitle("TextAreaDemo"); win.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); win.setVisible(true); } //============================================================= main public static void main(String[] args) { SwingUtilities.invokeLater(new Runnable(){ public void run(){ createAndViewJFrame(); } }); } }
However, it is strongly recommended that all serializable classes explicitly declare serialVersionUID values, since the default serialVersionUID computation is highly sensitive to class details that may vary depending on compiler implementations, and can thus result in unexpected InvalidClassExceptions during ...
Simply put, we use the serialVersionUID attribute to remember versions of a Serializable class to verify that a loaded class and the serialized object are compatible. The serialVersionUID attributes of different classes are independent. Therefore, it is not necessary for different classes to have unique values.
The serialization at 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.
The SerialVersionUID must be declared as a private static final long variable in Java. This number is calculated by the compiler based on the state of the class and the class attributes. This is the number that will help the JVM to identify the state of an object when it reads the state of the object from a file.
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 differentserialVersionUID
than that of the corresponding sender's class, then deserialization will result in anInvalidClassException
. A serializable class can declare its ownserialVersionUID
explicitly by declaring a field named"serialVersionUID"
that must be static, final, and of type long:
You can configure your IDE to:
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
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With