Example with SerialVersionUID:
Program 2:
C:\Users\jjatin\Desktop\Different Versions\All_Photos\Question
57\Program 2\color1.png
SerializationDemo.java:
C:\Users\jjatin\Desktop\Different Versions\All_Photos\Question
57\Program 2\color2.png
C:\Users\jjatin\Desktop\Different Versions\All_Photos\Question
57\Program 2\color3.png
Output:
C:\Users\jjatin\Desktop\Different Versions\All_Photos\Question
57\Program 2\output.png
Now, let’s add one more field ‘company’ and remove the transient
keyword from our Employee class. Here, as we are changing the
class structure, let’s see if we get the error of InvalidClassException
again:
Program 3:
C:\Users\jjatin\Desktop\Different Versions\All_Photos\Question
57\Program 3\color1.png
DeserializationTest.java:
C:\Users\jjatin\Desktop\Different Versions\All_Photos\Question
57\Program 3\color2.png
Output:
C:\Users\jjatin\Desktop\Different Versions\All_Photos\Question
57\Program 3\output.png
Some Points to remember:
Do'stlaringiz bilan baham: |