1

I confuse about the serialVersionUID somebody tell about if I am not define the serialVersionUID It will be impact the performance so I need to conclude my knowledge about this

From my understand, In the Java Compiler If you need to have communicate between 2 class or you need to use the object communication between 1 task to 1 task. It should be generated the serialVersionUID in sender and receiver when the sender send the object put the serialVersionUID into the object and then received validate the object if it 's correct receiver will be continue the process if not It will throw the exception

So If I am not put the serialVersionUID so java compiler will be define it in runtime from my understand so I think It is not impact the performance when the Java is executed

I hope my understand should be correct If not Please help another one in this site to suggest

Thank you

user207421
  • 305,947
  • 44
  • 307
  • 483

3 Answers3

4

The answer for such details always can be found in specification.

If a serializable class does not explicitly declare a serialVersionUID, then the serialization runtime will calculate a default serialVersionUID value for that class based on various aspects of the class, as described in the Java(TM) Object Serialization Specification.

For more visit java.io.Serializable.

The answer is it will but real question how much ?

The answer for this question can be found in this article Into the mist of serialization myths.

The conclusion is that the impact is not so relevant, but the cost of code management can be greater. As always final answer for this type of question depend on the project scale and the environment where the application will work.

0

First of all serialVersionID should be generated/added to classes that implements Serializable interface and it helps during deseralization of objects. So, you don't have to worry about possible performance issues, but definitely you should consider providing serizalVersioItd to your Serializable classes.

In this thread you can read about purpose of serialVersionID.

Community
  • 1
  • 1
pedjaradenkovic
  • 241
  • 1
  • 9
0

So If I am not put the serialVersionUID so java compiler will be define it in runtime from my understand so I think It is not impact the performance when the Java is executed

That statement doesn't make sense. The compiler can't do anything at runtime. If you omit it, the JVM will calculate it, once, when the class is first used by any specific ObjectInputStream or ObjectOutputStream.

The overhead is not significant.

user207421
  • 305,947
  • 44
  • 307
  • 483