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 abstraction and encapsulation?
Encapsulation is wrapping, just hiding properties and methods. Encapsulation is used for hide the code and data in a single unit to protect the data from the outside the world. Class is the best example...
Neval
will I get certificate
Better than certificate if you enroll with me you will get confidence and lot of practical knowledge...certifications dont matter after a period of time what really matters is your approach to a problem...
Sk.
Need to do java core and advanced certificate. Which books or pdf is need to refer?
Head First series of books on core java and advance java is good. Also Kathy serra scjp book, Khalid mughal scjp book is good for core java.
Prashanth
What are the difference between abstract class and Interface?
Abstraction : Hiding unnecessary details of object and shows only essential features of Object to communicate. abstract class : partially defined Object interface :Complete specification of Object class : Complete definition of Object
Ashish
How to stop session hijacking programmatically ?
Encrypting the session value will have zero effect. The session cookie is already an arbitrary value, encrypting it will just generate another arbitrary value that can be sniffed. The only real solution...
Mnaohar S

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

Ask a Question

Related Lessons

How 4 byte float can store 8 byte long values in java ?
long l = 12464545L; float f = l; (fine) int i = l ; (Error) if we see the how this magic happens as we know the answer lies in the floating point representation as in floating points values does not...

Observer Pattern in Java.
As I was going through the different source code files of the Java Util package, I found the implementation of the Observer Pattern ( see the Gang of Four books for more information on this pattern) in...

Finding a Majority Element
Problem Description Task. The goal in this code problem is to check whether an input sequence contains a majority element. Input Format. The first line contains an integer, the next one contains a sequence...

What Is Java? Explain The History Of Java
i. Ovierview: Java programming language was originally developed by Sun Microsystems which was initiated by James Gosling and released in 1995 as core component of Sun Microsystems' Java platform (Java...

JAVA Version History
Java Version History: There are many java versions that has been released. Current stable release of Java is Java SE 8. JDK Alpha and Beta (1995). JDK 1.0 (23rd Jan, 1996). JDK 1.1 (19th Feb, 1997). J2SE...
V

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