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

Sir how is Java a pure object oriented programming language?

 

Java is not a purely object-oriented programming language. Lots of people say’s its object-oriented language but it is not true because Java supports primitive data type and does not handle multiple inheritances.
Ram
What are the best books to learn Java?
you can buy any book to learn java but for beginner's Herber Schild is prefer best
Prashant
0 0
6
Can we use pointer in java?
No, we can't. Java has reference variables which contains address of objects. The reference variables are substitute to pointers in java. But, we cannot perform mathematical operations on reference variables...
Manish
What is a complete list of topics of Core Java and topics of Advanced Java?
Core Java covers some topics like data types, OOP, operators, exception handling, swing, threading, and collections. Advanced Java covers some topics like web services, database connectivity, JSP, Servlets, EJB, etc.
Archit
0 0
5

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

Ask a Question

Related Lessons

Comparable vs Comparator
java.lang.Comparable java.util.Comparator For comparing some other object with its own object. Ex. I am comparing myself to some other employee. Method signature is: int compareTo (T object). For...

How to create a Singleton class?
How to create a Singleton class: Q) What is a singleton class? A) In simple words, a singleton class is a class which can have only one instance at any point of time throughout the application and provides...

How can everyone prepare to clear any Java interview?
Java interview your java should be much strong then J2EE. core java and Advance java is the basic foundation for Interview. Some of the topic about which you should know before going for a java interview...

Java and C trainer
Always think any conspect with real-time example like Object -- object must have states and behaviour then only we will call that thing is Object like fan is Object (rotating,color)

10 Cool SQL Optimizations That Do Not Depend On The Cost Model
Today, we don’t want to talk about cost based optimisation, i.e. optimisations that depend on a database’s cost model. We’ll look into much simpler optimisations that can be implemented...

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