What is a serialVersionUID and why should we use it

0 votes

Eclipse issues warnings when a serialVersionUID is missing.

The serializable class Foo does not declare a static final serialVersionUID field of type long

What is serialVersionUID and why is it important? Please show an example where missing serialVersionUID will cause a problem.

May 28, 2020 in Java by kartik
• 37,510 points
10,500 views

1 answer to this question.

0 votes

Hello @kartik,

SerialVersionUID is a unique identifier for each class, JVM uses it to compare the versions of the class ensuring that the same class was used during Serialization is loaded during Deserialization.

Specifying one gives more control, though JVM does generate one if you don't specify. The value generated can differ between different compilers. Furthermore, sometimes you just want for some reason to forbid deserialization of old serialized objects [backward incompatibility], and in this case you just have to change the serialVersionUID.

Hope this is helpful!!

answered May 28, 2020 by Niroj
• 82,880 points

Related Questions In Java

0 votes
0 answers

What is TypeScript and why would I use it in place of JavaScript?

Could you kindly explain the TypeScript language? What ...READ MORE

Nov 16, 2022 in Java by Nicholas
• 7,760 points
247 views
0 votes
2 answers

What is the use of toString method in Java and how can I use it ?

Whenever you require to explore the constructor ...READ MORE

answered Aug 23, 2018 in Java by Daisy
• 8,120 points
3,758 views
0 votes
2 answers

What is the use of @Override annotation in Java ? When do we use it ?

@Override annotation is used when we override ...READ MORE

answered Aug 14, 2019 in Java by Sirajul
• 59,230 points
3,074 views
0 votes
0 answers

What is a NullPointerException, and how do I fix it?

What are Null Pointer Exceptions (java.lang.NullPointerException) and ...READ MORE

Apr 26, 2022 in Java by Rahul
• 3,380 points
325 views
0 votes
2 answers
+1 vote
2 answers

how can i count the items in a list?

Syntax :            list. count(value) Code: colors = ['red', 'green', ...READ MORE

answered Jul 7, 2019 in Python by Neha
• 330 points

edited Jul 8, 2019 by Kalgi 4,023 views
0 votes
1 answer
0 votes
1 answer

Error: getExtractedText on inactive InputConnection warning on android

Hello @kartik, The warning appeared when the soft ...READ MORE

answered May 26, 2020 in Java by Niroj
• 82,880 points
4,873 views
0 votes
1 answer

What is the equivalent to a JavaScript setInterval/setTimeout in Android/Java?

Hii @kartik, As always with Android there's lots ...READ MORE

answered May 26, 2020 in Java by Niroj
• 82,880 points
3,175 views
0 votes
1 answer

What is the reason for no ConcurrentHashSet against ConcurrentHashMap?

Hello, There's no built in type for ConcurrentHashSet because you ...READ MORE

answered Apr 8, 2020 in Java by Niroj
• 82,880 points
1,057 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP