UrbanPro

Learn Java Training from the Best Tutors

  • Affordable fees
  • 1-1 or Group class
  • Flexible Timings
  • Verified Tutors

Search in

what is serialVersionUID , why it different for each bean? serialVersionUID = 42L;

Asked by Last Modified  

15 Answers

Learn Java

Follow 0
Answer

Please enter your answer

JAVA Interview and other

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...
read more
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: ANY-ACCESS-MODIFIER static final long serialVersionUID = 42L; 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. 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 deserialization. Therefore, to guarantee a consistent serialVersionUID value across different java compiler implementations, a serializable class must declare an explicit serialVersionUID value. It is also strongly advised that explicit serialVersionUID declarations use the private modifier where possible, since such declarations apply only to the immediately declaring class--serialVersionUID fields are not useful as inherited members. read less
Comments

Tutor

This id is used to identify the type of the class. This is required when you serialize and de serialize the object. If you have given a value to this id, this will be common for all the objects created out of this class. Please note this id is a static field.
Comments

It represents the version number of the class. It mainly used during serialization and deserialization.
Comments

Java/J2EE Corporate Trainer

Serialization is a mechanism in java where an object can be represented as a sequence of bytes that includes the object's data as well as information about the object's type. Once an object is serialized its written to a file which can later be again deserialized to recreate the object in the memory. Consider...
read more
Serialization is a mechanism in java where an object can be represented as a sequence of bytes that includes the object's data as well as information about the object's type. Once an object is serialized its written to a file which can later be again deserialized to recreate the object in the memory. Consider a distributed hosting platform where web application is deployed across multiple servers. Each server has its own JVM container and they need to share common data (for ex - session object data), to serve the incoming requests. This objective is achieved using serialization. Each serialized class is associated with a version number, called a serialVersionUID which is used during deserialization to verify that the receiver has loaded the very class that the sender had intended. In case the receiver has loaded a class with different serialVersionUID, than that of corresponding sender class, then it'll result in InvalidClassCastException. If no serialVersionUID has been assigned, a default value gets assigned by the compiler. However, as a best practice, it is strongly recommended that all serializable classes explicitly declare serialVersionUID since the default serialVersionUID computation is highly sensitive and may also vary across various java compiler implementations. read less
Comments

Technical Subjects & Programming Languages Expert

It represents the version number of the class. It mainly used during serialization and deserialization.
Comments

Sr. Communication Trainer

Bean is a container of java classes. some java classes are not updated in the serial version UID ...This is a kind of ID to tell about the latest version and the java classes contained in the bean.
Comments

Java J2EE

The serialVersionUID have to match during the serialization and deserialization process. The serialVersionUID is used as a version control in a Serializable class. If you do not explicitly declare a serialVersionUID, JVM will do it for you automatically, based on various aspects of your Serializable...
Comments

IT tutor

ANY-ACCESS-MODIFIER static final long serialVersionUID = 42L; serialVersionUID is a static final field. You can assign any number of your choice to it. serialVersionUID is a must in serialization process. But it is optional for the developer to add it in java source file. If you are not going to...
read more
ANY-ACCESS-MODIFIER static final long serialVersionUID = 42L; serialVersionUID is a static final field. You can assign any number of your choice to it. serialVersionUID is a must in serialization process. But it is optional for the developer to add it in java source file. If you are not going to add it in java source file, serialization runtime will generate a serialVersionUID and associate it with the class. The serialized object will contain this serialVersionUID along with other data. Even though serialVersionUID is a static field, it gets serialized along with the object. This is one exception to the general serialization rule that, “static fields are not serialized”. serialVersionUID is a 64-bit hash of the class name, interface class names, methods and fields. Serialization runtime generates a serialVersionUID if you do not add one in source. Refer this link for the algorithm to generate serialVersionUID. It is advised to have serialVersionUID as unique as possible. Thats why the java runtime chose to have such a complex algorithm to generate it. read less
Comments

Masters in IT from UK

I agree with Chinna
Comments

6yrs exp in j2ee

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...
read more
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: - See more at: https://www.urbanpro.com/java/what-is-serialversionuid-why-it-different-for-each?id=138664&_from=showMessage#.dpuf read less
Comments

View 13 more Answers

Related Questions

What is the difference between Java and Advanced Java?
Java = Core + Advance(Servlets, JSPs & EJB)
Anu
Should we learn DBMS and RDBMS without any Java training?
java or i can say any programming language is not required to learn DBMS or RDBMS
Karthik
0 0
6
How to handle Circular dependency in Spring?
What I would like to do in this post is suggest 3 possible techniques for dealing with this problem. 1. Refactor your code This is probably the simplest and quickest way to fix this problem. Look at...
Saroj

Now ask question in any of the 1000+ Categories, and get Answers from Tutors and Trainers on UrbanPro.com

Ask a Question

Related Lessons

Java inheritance example
Answer these questions Answer the above question

Java
Java is a high level language which is far better than procedural languages like C, Fortran and Pascal. Java completely stands with the principles of OOPS (Object Oriented Programming Structure). The...
A

Abhisheak Saxena

0 0
0

CoreJAVA
Core Java Training High Level Course Content Trained by Java Architect 1. Core Java Programming Introduction of Java 2. Data types and Operators 3. Control Flow statements 4. OOPS and its application...
A

Java : Compile-time Versus Runtime optimization
While designing and development, one should think in terms of compile-time and run-time.It helps in understanding language basics in a better way.Let's understand this with a question below : What...
S

Interview Tip : Q1) Why Strings are immutable in java ? What happen if it was mutable in java?
As we all know that Strings in java are immutabe in nature, now the question comes why the creator made it immutable in nature, although this field used maximum in any java program. The answer to this...

Recommended Articles

Java is the most commonly used popular programming language for the creation of web applications and platform today. Integrated Cloud Applications and Platform Services Oracle says, “Java developers worldwide has over 9 million and runs approximately 3 billion mobile phones”.  Right from its first implication as java 1.0...

Read full article >

Designed in a flexible and user-friendly demeanor, Java is the most commonly used programming language for the creation of web applications and platform. It allows developers to “write once, run anywhere” (WORA). It is general-purpose, a high-level programming language developed by Sun Microsystem. Initially known as an...

Read full article >

Java is the most famous programming language till date. 20 years is a big time for any programming language to survive and gain strength. Java has been proved to be one of the most reliable programming languages for networked computers. source:techcentral.com Java was developed to pertain over the Internet. Over...

Read full article >

In the domain of Information Technology, there is always a lot to learn and implement. However, some technologies have a relatively higher demand than the rest of the others. So here are some popular IT courses for the present and upcoming future: Cloud Computing Cloud Computing is a computing technique which is used...

Read full article >

Looking for Java Training Classes?

Learn from the Best Tutors on UrbanPro

Are you a Tutor or Training Institute?

Join UrbanPro Today to find students near you
X

Looking for Java Training Classes?

The best tutors for Java Training Classes are on UrbanPro

  • Select the best Tutor
  • Book & Attend a Free Demo
  • Pay and start Learning

Learn Java Training with the Best Tutors

The best Tutors for Java Training Classes are on UrbanPro

This website uses cookies

We use cookies to improve user experience. Choose what cookies you allow us to use. You can read more about our Cookie Policy in our Privacy Policy

Accept All
Decline All

UrbanPro.com is India's largest network of most trusted tutors and institutes. Over 55 lakh students rely on UrbanPro.com, to fulfill their learning requirements across 1,000+ categories. Using UrbanPro.com, parents, and students can compare multiple Tutors and Institutes and choose the one that best suits their requirements. More than 7.5 lakh verified Tutors and Institutes are helping millions of students every day and growing their tutoring business on UrbanPro.com. Whether you are looking for a tutor to learn mathematics, a German language trainer to brush up your German language skills or an institute to upgrade your IT skills, we have got the best selection of Tutors and Training Institutes for you. Read more