1

00:00:01,050  -->  00:00:07,670
In the last lesson in that the more we have seen that we can run into issues during the D.C. legalization

2

00:00:07,670  -->  00:00:09,080
process.

3

00:00:09,080  -->  00:00:13,700
So there is something more we need to know about D.C. validation process and that's something that we

4

00:00:13,700  -->  00:00:20,390
will see in this lesson we will also see how we can avoid the issue that we ran into during that Emel

5

00:00:22,310  -->  00:00:24,930
And here's the DC that can process.

6

00:00:24,930  -->  00:00:32,080
So we first read the serialized object and in the process GBM also tries to lower the corresponding

7

00:00:32,110  -->  00:00:33,880
class object.

8

00:00:33,880  -->  00:00:38,960
The class name of the serialized object will be stored with the serialized object itself.

9

00:00:39,150  -->  00:00:46,110
And so JVM looks at the class name and will try to load the corresponding class know D.C. delegation

10

00:00:46,110  -->  00:00:46,900
will fail.

11

00:00:47,070  -->  00:00:53,610
If for some reason the class cannot be loaded it could be because the GBM could not find the class file

12

00:00:53,620  -->  00:00:53,800
.

13

00:00:54,120  -->  00:00:57,020
Or it could be due to some other reason to.

14

00:00:57,250  -->  00:01:03,730
But if the class could be loaded successfully then as a second step GBM tries to compare the motion

15

00:01:03,730  -->  00:01:10,630
of the loaded class but the notion of the serialized object and the need to match a device it means

16

00:01:10,630  -->  00:01:17,160
that the class has evolved after the object was serialized and they are no longer compatible and due

17

00:01:17,220  -->  00:01:21,900
to this JVM with an exception NDC realization will fail.

18

00:01:22,150  -->  00:01:29,450
And this is what happened during the demo when the last lesson but if there is no motion mismatch then

19

00:01:29,450  -->  00:01:36,410
GBM would create space in the heap for the serialized object and recreate the object with the same state

20

00:01:36,420  -->  00:01:36,600
.

21

00:01:37,470  -->  00:01:43,560
So it's going to run that can strip it off the object because if that is done then it means that we

22

00:01:43,560  -->  00:01:51,210
are creating a brand new object that by Newsted and that is not what we want what we want is to recreate

23

00:01:51,210  -->  00:01:59,060
the object with the same state that the object had when it was serialized But if there is any norms

24

00:01:59,060  -->  00:02:05,920
Serializable ancestor in the inheritance tree of the serialized object then that ancestors construct

25

00:02:05,920  -->  00:02:14,310
it would be done along with any constrictors of all it's direct or indirect superclasses under super

26

00:02:14,310  -->  00:02:16,370
process maybe Serializable do.

27

00:02:16,670  -->  00:02:25,580
And that wouldn't matter so conceptus would run starting with the first Nahm Serializable ancestor unbe

28

00:02:25,610  -->  00:02:28,520
already know this as part of restoring state.

29

00:02:28,520  -->  00:02:36,840
Instance variables will get serialized did while Crunchie and variables will get default values so that's

30

00:02:36,840  -->  00:02:38,810
a B.S. legalization process.

31

00:02:40,420  -->  00:02:48,110
Let's not look at more specifics about worshipping every Serializable class gets a version ID which

32

00:02:48,110  -->  00:02:55,740
is computed from the classic structure on this motion ID is stored with that dot Busfield know it and

33

00:02:55,740  -->  00:03:03,190
the plastic took genius the Russian idea also genius on this motion ID has a name under the name Das

34

00:03:03,350  -->  00:03:12,000
serial quotient you ID as an idol of this Light That Is it as a bush an ID of a serializable class.

35

00:03:12,330  -->  00:03:18,850
So sort of wish an ID is specific to only Serializable classes on Hence we have the term CDO in the

36

00:03:18,850  -->  00:03:21,060
name of the ocean ID.

37

00:03:21,070  -->  00:03:29,370
So this motion ID will not be gender dered for non-C realisable process know in a seat an object is

38

00:03:29,370  -->  00:03:32,050
generated then the object is time.

39

00:03:32,210  -->  00:03:40,770
But the motion IAB that the class had in that instance of by and during B.C.E. realization I spark off

40

00:03:40,790  -->  00:03:47,140
Worsham comparison devotionally of serialized object will be compared with the Russian idea of downloaded

41

00:03:47,150  -->  00:03:54,950
to us so if the class has evolved after the object was serialized then obviously motion ideas were mismatch

42

00:03:55,190  -->  00:03:55,640
.

43

00:03:55,910  -->  00:03:57,520
Transition.

44

00:03:57,920  -->  00:04:05,220
And this is what happened in the last Dynel So the question would be how can we make D.C. realization

45

00:04:05,220  -->  00:04:13,730
to succeed even when the class has a world after serialization and the solution is to make the version

46

00:04:13,750  -->  00:04:19,360
ID constant even if Grassley wants NBC how that can be done.

47

00:04:19,400  -->  00:04:27,080
Let's get back to our demo cook here we are in the I will do more class once again and we're going to

48

00:04:27,080  -->  00:04:28,720
continue with where we left off.

49

00:04:29,030  -->  00:04:32,900
So in the last day more we made this change uncommented gender.

50

00:04:33,170  -->  00:04:40,720
So the class has evolved unbid that we had a version mismatch NDC realization has failed and we just

51

00:04:40,720  -->  00:04:48,610
mentioned that in order to resolve that we need to keep the and the constant so that can be done by

52

00:04:48,610  -->  00:04:55,290
declaring a constant CDL Worsham new ID as you can see here since it needs to be a constant.

53

00:04:55,300  -->  00:04:59,120
It has marked dust not big on final and it has to be long.

54

00:05:00,220  -->  00:05:04,780
On here as a senior Beauchesne you ID and we are using the name as it is.

55

00:05:05,030  -->  00:05:06,850
And it is assigned this value.

56

00:05:06,850  -->  00:05:13,650
And the question is can we get this value from on for that Java library comes with a tool called Silver

57

00:05:13,670  -->  00:05:14,130
.

58

00:05:14,250  -->  00:05:14,600
OK.

59

00:05:14,620  -->  00:05:18,330
And we are going to use that silver and we are going to pass.

60

00:05:18,340  -->  00:05:24,220
We are going to run that tool and we are going to pass this in can be passed on in the movie then we

61

00:05:24,220  -->  00:05:28,430
get done serial version of this particular class.

62

00:05:28,750  -->  00:05:33,130
So in order to do that let's just go back and start from the beginning.

63

00:05:33,190  -->  00:05:41,100
So let's just call this art and just keep this as it is me open my command prompt here.

64

00:05:41,530  -->  00:05:44,230
So I am and gee I read them all.

65

00:05:44,230  -->  00:05:50,530
So there is the current project and I'm in the bin folder because in the bin for dinner itself we have

66

00:05:50,530  -->  00:05:55,620
the classifiers OKB in the demo we how both SIRC unbent and within the bin.

67

00:05:55,630  -->  00:05:57,520
We have the actual classifiers.

68

00:05:57,550  -->  00:05:59,980
So we need to go into the bin folder.

69

00:05:59,990  -->  00:06:01,470
Let me just run this command.

70

00:06:01,510  -->  00:06:09,610
So it's called Silver and we are running it on the Iodo more dollars Serializable Demel because you

71

00:06:09,610  -->  00:06:11,640
didn't as a builder I was a nested class.

72

00:06:11,830  -->  00:06:13,990
We can access it this way.

73

00:06:14,070  -->  00:06:19,170
This silver is being is it is being run on that docked classified.

74

00:06:19,210  -->  00:06:25,870
So if you look into this folder I will falter here you will see I will do a moderate class as well as

75

00:06:26,200  -->  00:06:31,310
as well as I order more dollars Serializable Demel and you will see both of them.

76

00:06:31,360  -->  00:06:37,240
So we are running the seedier version on this particular Serializable nested class because we want that

77

00:06:37,250  -->  00:06:39,700
serial quotient ID.

78

00:06:39,700  -->  00:06:41,130
So on this if we run it.

79

00:06:41,140  -->  00:06:43,870
So this is what we get and it's already here.

80

00:06:44,020  -->  00:06:45,740
So it's just the same number.

81

00:06:46,120  -->  00:06:49,980
So I'm just going to uncomment this.

82

00:06:50,410  -->  00:06:54,990
Now let's just go ahead and say Run.

83

00:06:55,420  -->  00:06:57,110
Run configuration.

84

00:06:57,310  -->  00:07:04,010
Recall that we need to pass through here in order to serialize the object.

85

00:07:04,010  -->  00:07:14,080
So we are going to start from the beginning and I'll say apply here and run it and I go back there more

86

00:07:14,080  -->  00:07:16,880
and if I hit refresh it will see dark.

87

00:07:16,900  -->  00:07:18,590
That is the CD a lot easier.

88

00:07:18,670  -->  00:07:22,750
OK so Dr. template has done seat on this object now.

89

00:07:22,830  -->  00:07:33,860
I mean just go back so let's not involve the class so let's just do this Bartletts not regenerate there's

90

00:07:33,860  -->  00:07:38,780
not that research realize that blasts so let's go back and do it on configurations into arguments maybe

91

00:07:38,850  -->  00:07:50,810
modus So with this only desalinisation Isbel form and now you can see that despite uncommon doing this

92

00:07:51,540  -->  00:07:54,410
we did not get the exception that we had earlier.

93

00:07:54,580  -->  00:07:54,970
OK.

94

00:07:55,040  -->  00:07:59,720
And that's because we how hard coded the Russian ID.

95

00:07:59,750  -->  00:08:07,910
So even so the object serialized object has had this notion ID but the class has evolved and we hardcoded

96

00:08:07,910  -->  00:08:09,330
the ocean ID.

97

00:08:09,440  -->  00:08:17,430
So when we run as a serial version let's run it once again so with this is with no change and you will

98

00:08:17,430  -->  00:08:20,660
see that it still has the same bush an ID.

99

00:08:20,730  -->  00:08:21,120
OK.

100

00:08:21,120  -->  00:08:25,620
So we are hardwiring the Russian idea here.

101

00:08:25,980  -->  00:08:31,370
So that's how you can ensure that because your position does not fit.

102

00:08:31,710  -->  00:08:35,520
But there are some changes and if you make those changes.

103

00:08:35,630  -->  00:08:37,360
Utilization still fit.

104

00:08:37,710  -->  00:08:43,320
For instance let's do this let's just make it NC realisable OK.

105

00:08:43,530  -->  00:08:51,490
No actually if you run version ID it will not be when See it says that it is not serializable because

106

00:08:52,030  -->  00:08:57,820
in order to because there is no emotion or devotion I doubt you will be generated only for Serializable

107

00:08:57,820  -->  00:08:58,750
classes.

108

00:08:58,760  -->  00:09:02,050
Q So the old version but also say that it cannot.

109

00:09:02,050  -->  00:09:02,660
It cannot.

110

00:09:02,700  -->  00:09:06,150
It cannot give us any question Id.

111

00:09:06,760  -->  00:09:09,810
Now that's just go ahead and run this.

112

00:09:10,030  -->  00:09:17,340
So with this change we will once again get this error which means that ABC Television has it.

113

00:09:17,590  -->  00:09:22,220
So there are certain changes that we can make on certain changes that we can not make.

114

00:09:22,450  -->  00:09:23,260
OK.

115

00:09:23,260  -->  00:09:30,130
So let's head over to our site and see what changes we can make and what we can not make.

116

00:09:30,440  -->  00:09:30,850
OK.

117

00:09:31,090  -->  00:09:37,110
And this class as available and the resources section on you can check it out on download on book critic

118

00:09:38,280  -->  00:09:40,890
so let's just go back to our sleights

119

00:09:43,650  -->  00:09:50,380
unhidden the changes that do not affect D.C. realization on most of these are about instance variables

120

00:09:51,610  -->  00:09:55,550
you can add or delete an instance variable to the class and that will not break.

121

00:09:55,660  -->  00:10:00,960
Between the audition process if you add an instance variable it will get the default value.

122

00:10:02,050  -->  00:10:08,630
You can also make an instance variable static you can change a transient variable and go nonconstant

123

00:10:09,280  -->  00:10:16,590
and the variable would still get the default value good NBC television you can also change access levels

124

00:10:16,590  -->  00:10:19,320
off the tables and duckbill don't have any effect.

125

00:10:20,330  -->  00:10:26,720
Finally you can all add classes to the inheritance tree and you can also REMAUT classes from the inheritance

126

00:10:26,720  -->  00:10:30,250
tree and that wouldn't affect the D.C. delegation process.

127

00:10:32,230  -->  00:10:38,980
And these are a couple of changes that do affect DC that position you cannot change the data type of

128

00:10:39,110  -->  00:10:40,390
an instance variable.

129

00:10:41,560  -->  00:10:43,700
We have to see the second one in our demo.

130

00:10:44,020  -->  00:10:50,640
That is you cannot make a CD and as a bluegrass non-C then visible but this rule is not for just the

131

00:10:50,640  -->  00:10:58,230
class itself but if the class includes one or more object graphs then none of the Serializable classes

132

00:10:58,380  -->  00:11:06,320
that dingo's object graphs can be made on Serializable So even if one class is made Nancy Serializable

133

00:11:06,500  -->  00:11:11,510
within an object graph then it would break the DCD tradition process.

134

00:11:12,430  -->  00:11:13,810
So that's about it.

135

00:11:13,810  -->  00:11:19,540
I would also suggest that you should try out all these genius in code and see the results for yourself

136

00:11:19,560  -->  00:11:19,670
.

137

00:11:20,910  -->  00:11:29,660
So to summarize serialization is useful for saving regular Java objects to devices like desk to recreate

138

00:11:29,660  -->  00:11:37,460
Java objects from their serialized form people from DC theorization and B use object output stream an

139

00:11:37,460  -->  00:11:45,460
object input stream process four-CD elevation NBC idealisation finally if you want the classes to evolve

140

00:11:45,610  -->  00:11:51,750
without affecting DC or they can then you can define a constant Silverbush an ID.

141

00:11:52,390  -->  00:11:59,680
But you need to bear in mind that DCR addition can still fail with certain genius so that's about it

142

00:11:59,680  -->  00:11:59,940
.

143

00:11:59,950  -->  00:12:02,570
Hope you enjoy learning about serialization.

144

00:12:02,640  -->  00:12:03,480
And thank you
