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

Is it possible to learn java at home without coaching in one month?
It all depends on you. If you are already aware of programming then it is definetly possible to learn java at home. But if learn through a tutor then you can learn easily.
Pritom
0 0
5
I know HTML, CSS, and a bit of JavaScript. What should I learn next?
HTML,CSS and Javascript are Tools which are used for Front-End Web Development. The next step is to learn the following: 1)Learn Javascript Frameworks like node.js,react.js,angular.js etc. 2)Learn Back-End...
Inch By

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 is the difference between checked and unchecked exceptions?
The main difference between checked and unchecked exception is that the checked exceptions are checked at compile-time while unchecked exceptions are checked at runtime
Wren
What is the best book to learn data structures using Java?
There are several excellent books that can help you learn data structures using Java. 1. "Data Structures and Algorithms in Java" by Robert Lafore. 2. "Algorithms, Part I" by Robert Sedgewick and Kevin...
Shubham
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

Design Pattern
Prototype Design Pattern: Ø Prototype pattern refers to creating duplicate object while keeping performance in mind. Ø This pattern involves implementing a prototype interface which tells...

Android : Support multiple themes in an android application
If you are developing a theme based application to enhance user experience, then following steps needs to follow.We are taking example of an android application having 2 themes white and black.Step 1:Define...

How do i get best Campus / Off Campus Placement?
Companies are looking for Skilled Freshers. So build your technical skills while doing MCA / BTech / BCA / BSc (IT or CS) into below areas- 1. Strong your programming & debugging skills ...

How to create Rest web services in Java
Web services are web application components that lets two different applications to communicate over the network.Let if an application which in written java provides web services can be communicated through...

Tips of learning Java Language/Other Programming Languages
1.You should know the basic concept: If we talk about programming languages so basic concept are same in all the high level languages. So you should know the basic concept firstly then you can easily understand...
I

ICreative Solution

0 0
0

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