1
00:00:00,210 --> 00:00:02,050
Hi everyone it is still Todi.

2
00:00:02,110 --> 00:00:06,160
I want to talk about how to write our code more professionally OK.

3
00:00:06,180 --> 00:00:14,450
In the previous tutorials I talked about objects and methods and how to use objects and methods together.

4
00:00:14,460 --> 00:00:15,060
OK.

5
00:00:15,270 --> 00:00:20,830
But in this tutorial I want to show you how you can write secure codes.

6
00:00:20,850 --> 00:00:21,460
OK.

7
00:00:21,630 --> 00:00:24,240
So first we need to create a Java project.

8
00:00:24,270 --> 00:00:24,840
OK.

9
00:00:25,020 --> 00:00:31,150
So in order to create a Java project you need to click on File New and then click on Java project.

10
00:00:31,170 --> 00:00:31,960
OK.

11
00:00:32,130 --> 00:00:39,100
So for the project name just type in here getters and setters.

12
00:00:39,300 --> 00:00:40,080
OK.

13
00:00:40,470 --> 00:00:42,460
And click and finish.

14
00:00:42,540 --> 00:00:48,300
So as you can see here our project is now created and then we need a main class for our project.

15
00:00:48,300 --> 00:00:48,650
OK.

16
00:00:48,660 --> 00:00:56,160
So just click on this as our RC folder and then click on find new and then click on class.

17
00:00:56,210 --> 00:01:03,360
So for the class name just type in here made and for the package we need a reverse domain here to just

18
00:01:03,360 --> 00:01:14,940
type in here come that your name dot project name OK getters and setters and then make sure that you

19
00:01:14,940 --> 00:01:16,510
check these checkpoints here.

20
00:01:16,980 --> 00:01:19,010
Public static void main method.

21
00:01:19,200 --> 00:01:21,550
And then click on finish.

22
00:01:21,660 --> 00:01:27,990
So as you can see here our class is now created and then let me delete this comment and then let me

23
00:01:28,260 --> 00:01:30,100
make this area right.

24
00:01:30,120 --> 00:01:30,870
OK.

25
00:01:31,380 --> 00:01:34,030
So now we can write our code here.

26
00:01:34,080 --> 00:01:40,920
So now I want to create a blueprint in order to show me how I can't exactly create dog objects.

27
00:01:40,920 --> 00:01:41,330
OK.

28
00:01:41,370 --> 00:01:44,190
So I need to create a class called Talk.

29
00:01:44,190 --> 00:01:44,870
OK.

30
00:01:45,210 --> 00:01:53,160
So in order to create a class I just need to click on this package here and then click on File New and

31
00:01:53,160 --> 00:01:54,860
then click kind of class.

32
00:01:54,870 --> 00:01:55,580
OK.

33
00:01:55,770 --> 00:02:04,470
So the name of our class is Doc OK and it's going to actually put this class inside this package.

34
00:02:04,580 --> 00:02:04,910
OK.

35
00:02:04,910 --> 00:02:10,670
Because we clicked on this package and it's going to put this class inside this package OK.

36
00:02:10,670 --> 00:02:14,740
So for the modifiers use public and then click on finish.

37
00:02:14,870 --> 00:02:18,480
So as you can see here our target class is now created.

38
00:02:18,500 --> 00:02:18,880
OK.

39
00:02:18,890 --> 00:02:27,290
And now that's our blueprint is created we need to put some instructions inside this class in order

40
00:02:27,290 --> 00:02:32,240
to show us the characteristics and behaviors of a dog object.

41
00:02:32,240 --> 00:02:41,000
So for example the characteristics of a dog are create some variables here at speed and I can assign

42
00:02:41,000 --> 00:02:44,610
a value to my variable for example number 70.

43
00:02:45,350 --> 00:02:49,060
And again and power.

44
00:02:50,030 --> 00:02:54,140
And then I can assign a value to my valuable for example number 80.

45
00:02:54,290 --> 00:02:58,570
And as you can see here these are the characteristics of my dog objects.

46
00:02:58,580 --> 00:02:58,990
OK.

47
00:02:59,030 --> 00:03:01,980
And are like objects have behaviors.

48
00:03:02,000 --> 00:03:04,000
So what are the behaviors of a dog.

49
00:03:04,040 --> 00:03:05,990
So for example a dog can run.

50
00:03:05,990 --> 00:03:06,350
OK.

51
00:03:06,350 --> 00:03:19,550
So here I just need to type in voit run ok and insert them and I can write them that out that print.

52
00:03:20,010 --> 00:03:22,930
And then inside the parenthesis I can't just type in here.

53
00:03:22,950 --> 00:03:23,310
Ron

54
00:03:25,950 --> 00:03:26,800
OK.

55
00:03:27,460 --> 00:03:31,390
So as you can see here at the end of my statement I need to put in a semicolon.

56
00:03:31,380 --> 00:03:34,950
Another behavior of a dog is a dog sleeps.

57
00:03:34,990 --> 00:03:44,080
So here I just need to type in Voyt sleep and then I need to open and close my Mfat by using an opening

58
00:03:44,080 --> 00:03:48,760
curly brace followed by our closing curly brace and then inside the left.

59
00:03:48,790 --> 00:03:59,460
I just need to typing system that out that princeling and then inside the apprentice's I can write sleep

60
00:04:03,140 --> 00:04:03,880
OK.

61
00:04:04,310 --> 00:04:07,120
And then at the end of my statement I need to put in a semicolon.

62
00:04:07,130 --> 00:04:11,010
So these are the characteristics and behaviors of my dog objects.

63
00:04:11,030 --> 00:04:11,610
OK.

64
00:04:11,720 --> 00:04:18,000
And now that our blueprint is ready we can create objects from this class.

65
00:04:18,020 --> 00:04:18,570
OK.

66
00:04:18,710 --> 00:04:20,770
So inside the main class.

67
00:04:20,840 --> 00:04:22,810
So as you can see here this is our main class.

68
00:04:22,820 --> 00:04:23,560
OK.

69
00:04:23,960 --> 00:04:26,170
And inside the main method.

70
00:04:26,180 --> 00:04:27,980
So this is our main method.

71
00:04:28,010 --> 00:04:28,620
OK.

72
00:04:28,880 --> 00:04:31,490
We can create objects from this class.

73
00:04:31,490 --> 00:04:32,300
OK.

74
00:04:32,450 --> 00:04:36,370
So first I need to refer to the name of my dog class.

75
00:04:36,670 --> 00:04:37,170
OK.

76
00:04:37,260 --> 00:04:39,780
And then I need to give my object a name.

77
00:04:39,980 --> 00:04:41,760
So for example my dock.

78
00:04:42,220 --> 00:04:42,900
OK.

79
00:04:43,160 --> 00:04:46,000
And then I put an assignment operator here.

80
00:04:46,220 --> 00:04:49,050
And then I put this key vote here Neal.

81
00:04:49,460 --> 00:04:55,940
And then again I refer to the name of my class and then I put a pair of round brackets after my class

82
00:04:55,940 --> 00:04:56,130
name.

83
00:04:56,150 --> 00:05:00,020
OK so this is how we create objects from classes.

84
00:05:00,020 --> 00:05:00,430
OK.

85
00:05:00,500 --> 00:05:07,260
So now I want to actually access the characteristics and behaviors of my dog objects.

86
00:05:07,280 --> 00:05:07,890
OK.

87
00:05:08,090 --> 00:05:14,590
So inside the main class and inside the main method I have to actually to output the value of the speed

88
00:05:14,930 --> 00:05:17,990
instance variable of my dog object.

89
00:05:17,990 --> 00:05:26,750
So here I just need to type in the system that's out that land and then inside the prentices first I

90
00:05:26,750 --> 00:05:29,420
need to refer to the name of my object my dog.

91
00:05:29,480 --> 00:05:30,920
That speed.

92
00:05:31,190 --> 00:05:31,820
OK.

93
00:05:32,060 --> 00:05:37,020
And then I need to put in a semi-colon at the end of my statement aren't here.

94
00:05:37,090 --> 00:05:44,040
Are you want to actually output the value of their power or instance variable to the console.

95
00:05:44,090 --> 00:05:53,510
So I just need to type in system that out that Prince land and then inside the prentices first I need

96
00:05:53,510 --> 00:05:57,440
to refer to the name of my object that power.

97
00:05:57,930 --> 00:05:58,540
OK.

98
00:05:58,850 --> 00:06:05,210
And then I need to put in a semicolon at the end of my statement and I want to actually call the behaviors

99
00:06:05,270 --> 00:06:06,590
of my dog object.

100
00:06:06,620 --> 00:06:09,890
For example I want to tell my dog to run.

101
00:06:10,100 --> 00:06:15,160
So first I need to actually be fair to the name of my object.

102
00:06:15,170 --> 00:06:19,400
My dog got run ok.

103
00:06:19,430 --> 00:06:23,370
Or for example I want to actually tell my dog to sleep.

104
00:06:23,390 --> 00:06:29,510
So inside the main class and inside the main method first I need to refer to the name of my object that

105
00:06:30,070 --> 00:06:31,140
sleep.

106
00:06:31,320 --> 00:06:32,130
OK.

107
00:06:32,450 --> 00:06:39,950
So this is how you can actually access the characteristics or instance variables and the behaviors of

108
00:06:39,950 --> 00:06:40,950
your objects.

109
00:06:41,010 --> 00:06:51,870
OK so now if I on my project as you can see these are the characteristics and behaviors of my dog objects.

110
00:06:51,890 --> 00:06:52,430
OK.

111
00:06:52,580 --> 00:06:56,680
So as you can see here I created a blueprint.

112
00:06:56,690 --> 00:06:57,840
So this is our blueprint.

113
00:06:57,860 --> 00:06:58,580
OK.

114
00:06:58,790 --> 00:07:01,280
So let me now double click on this dog.

115
00:07:01,310 --> 00:07:05,500
The job I have here in order to make this a little area of order.

116
00:07:05,750 --> 00:07:07,910
So as you can see here this is our blueprint.

117
00:07:07,910 --> 00:07:08,710
OK.

118
00:07:09,110 --> 00:07:16,250
And then I created an object from this blueprint from the start class inside the main class and inside

119
00:07:16,250 --> 00:07:16,820
the main method.

120
00:07:16,830 --> 00:07:17,330
OK.

121
00:07:17,330 --> 00:07:22,080
So this is our dog object that we created in line 7.

122
00:07:22,100 --> 00:07:22,610
OK.

123
00:07:22,820 --> 00:07:24,730
But there is a problem here.

124
00:07:24,920 --> 00:07:27,830
My code is not secure enough.

125
00:07:27,830 --> 00:07:28,580
Why.

126
00:07:28,580 --> 00:07:33,670
Because as you can see here I shouldn't allow the main class.

127
00:07:33,710 --> 00:07:35,500
So this is our main class ok.

128
00:07:35,760 --> 00:07:44,450
I shouldn't allow the main class to access the characteristics of my dog object directly.

129
00:07:44,810 --> 00:07:47,490
So inline 8 and inline 9.

130
00:07:47,540 --> 00:07:53,030
I am actually accessing the characteristics of my dog object directly.

131
00:07:53,060 --> 00:07:58,840
First I am referring to the name of my object and then I am actually accessing the instance variable

132
00:07:58,860 --> 00:08:01,120
of this might like object directly.

133
00:08:01,130 --> 00:08:04,710
This is not the proper way to actually write our codes.

134
00:08:04,820 --> 00:08:05,080
OK.

135
00:08:05,090 --> 00:08:06,520
There is something wrong here.

136
00:08:06,590 --> 00:08:09,980
In this way our code is not maintainable.

137
00:08:10,130 --> 00:08:14,050
So what should we do in order to solve this problem.

138
00:08:14,060 --> 00:08:19,470
So in order to solve this problem we should use setters and getters.

139
00:08:19,580 --> 00:08:21,370
For our instance variables.

140
00:08:21,380 --> 00:08:21,880
OK.

141
00:08:22,010 --> 00:08:27,680
So as you can see here inside the class these are the instance variables of our dog objects.

142
00:08:27,710 --> 00:08:28,120
OK.

143
00:08:28,160 --> 00:08:35,240
As I said before we call these characteristics instance about because these characteristics are owned

144
00:08:35,510 --> 00:08:38,960
by the instances or objects of this class.

145
00:08:38,990 --> 00:08:45,240
OK I want to show you how you can create get hearer's and setters for instance variables.

146
00:08:45,260 --> 00:08:45,720
OK.

147
00:08:45,830 --> 00:08:53,600
So what are these getters and setters for example if you want to access the value of this speed instance

148
00:08:53,600 --> 00:08:57,020
variable we should use a method called getter.

149
00:08:57,110 --> 00:09:05,630
OK so if I for example want to access the value of this speed instance variable I should use a method

150
00:09:05,630 --> 00:09:09,560
called Get here in order to actually access that value.

151
00:09:09,560 --> 00:09:10,100
OK.

152
00:09:10,280 --> 00:09:14,980
We shouldn't access the value of this instance variable in this way.

153
00:09:14,990 --> 00:09:21,470
This is not the proper way in order to access the value of this instance variable in this way.

154
00:09:21,500 --> 00:09:28,670
OK but if I want to actually assign another value to my speed instance variable we should use a method

155
00:09:28,670 --> 00:09:30,000
called setter.

156
00:09:30,250 --> 00:09:36,340
OK so here I can actually assign another value to my SPI instance variable.

157
00:09:36,350 --> 00:09:43,010
So first I need to refer to the name of my object my dog that speed and then I put an assignment operator

158
00:09:43,010 --> 00:09:45,590
here and then I assign a value to my variable.

159
00:09:45,590 --> 00:09:47,120
For example number 25.

160
00:09:47,300 --> 00:09:50,680
And then I put a semi-colon at the end of my statement.

161
00:09:50,860 --> 00:09:51,290
OK.

