1
00:00:00,210 --> 00:00:05,010
Hi everyone in this theater early on I'm going to talk about methods in Java.

2
00:00:05,010 --> 00:00:05,580
OK.

3
00:00:05,700 --> 00:00:08,850
So first we need to create a Java project.

4
00:00:08,850 --> 00:00:13,370
So just click on File New and then click on Java project.

5
00:00:13,380 --> 00:00:14,440
OK.

6
00:00:15,190 --> 00:00:22,380
And for the project name just type in here methods and then click on finish.

7
00:00:22,770 --> 00:00:25,700
So as you can see here our project is now created.

8
00:00:25,890 --> 00:00:27,640
So now we need a main class.

9
00:00:27,660 --> 00:00:28,330
OK.

10
00:00:28,380 --> 00:00:36,700
So just click on this as RC folder and then click on find new and then click on class.

11
00:00:36,730 --> 00:00:39,530
So for the class name just type in here.

12
00:00:39,700 --> 00:00:41,410
Meffert.

13
00:00:42,480 --> 00:00:43,300
OK.

14
00:00:43,630 --> 00:00:47,240
And for the package name we need a reverse domain here.

15
00:00:47,380 --> 00:00:55,180
Just type in here com dot your name dot project name OK.

16
00:00:55,590 --> 00:01:02,730
And for the modifiers to public and here to make sure that you check this checkbox here that says public

17
00:01:02,790 --> 00:01:04,220
static void main effect.

18
00:01:04,230 --> 00:01:04,810
OK.

19
00:01:04,950 --> 00:01:07,780
This is the starting point for running our Java code.

20
00:01:07,800 --> 00:01:08,390
OK.

21
00:01:08,520 --> 00:01:09,940
And then click on finish.

22
00:01:10,140 --> 00:01:13,340
So as you can see here our class is now created.

23
00:01:13,460 --> 00:01:21,660
OK so now let me actually delete this comment here and then in order to make this a little earlier Vider

24
00:01:21,780 --> 00:01:25,510
I just need to double click on the Smurfette Java tab here.

25
00:01:25,530 --> 00:01:26,000
OK.

26
00:01:26,010 --> 00:01:31,980
Our editor area is now much wider and we can write our codes inside the main method.

27
00:01:31,980 --> 00:01:32,460
OK.

28
00:01:32,550 --> 00:01:35,880
So I want to talk about methods in Java.

29
00:01:35,930 --> 00:01:46,170
OK so what are if it's a job or if it is a collection of statements that are grouped together to perform

30
00:01:46,380 --> 00:01:47,480
an operation.

31
00:01:47,600 --> 00:01:48,170
OK.

32
00:01:48,360 --> 00:01:55,880
You have been using methods in the previous tutorials like the main method that I told you about.

33
00:01:55,890 --> 00:01:56,440
OK.

34
00:01:56,580 --> 00:02:03,970
In this tutorial I'm going to show you what methods actually are and how you can create your own methods.

35
00:02:03,990 --> 00:02:04,610
OK.

36
00:02:04,830 --> 00:02:10,330
So our method is just a chunk of code that does a particular job.

37
00:02:10,430 --> 00:02:10,860
OK.

38
00:02:10,920 --> 00:02:14,700
But methods are set out in a certain way.

39
00:02:14,710 --> 00:02:18,530
You have a method header and I'm a fed body.

40
00:02:18,660 --> 00:02:26,910
The header is very you tell Java about what value you type if any the method will return OK and ain't

41
00:02:27,150 --> 00:02:29,370
value or double value etc..

42
00:02:29,450 --> 00:02:37,070
OK as well as the return type you'll need a name for your method which also goes in the header.

43
00:02:37,110 --> 00:02:44,940
Ok you can pass values over to your methods and these go between a pair of round brackets.

44
00:02:44,950 --> 00:02:48,380
OK the method body is where your statement goes.

45
00:02:48,410 --> 00:02:52,210
OK in Suydam effort body you actually put your own statements.

46
00:02:52,250 --> 00:02:59,930
OK so first let me point out that you must always create your methods inside the class.

47
00:02:59,940 --> 00:03:00,620
OK.

48
00:03:00,810 --> 00:03:04,580
And you can not create your methods inside other methods.

49
00:03:04,700 --> 00:03:09,960
OK so for example you cannot create MFX inside the main method.

50
00:03:09,960 --> 00:03:13,480
OK so now let me give you some real examples.

51
00:03:13,510 --> 00:03:17,710
OK we cannot actually create methods inside other methods.

52
00:03:17,730 --> 00:03:20,820
OK we can only create methods inside the class.

53
00:03:20,860 --> 00:03:24,810
OK so inside the method class as you can see here.

54
00:03:25,290 --> 00:03:28,650
In between those curly braces this is our method class.

55
00:03:28,650 --> 00:03:31,610
Ok here I can actually create my own method.

56
00:03:31,740 --> 00:03:33,930
So I just need to type in here.

57
00:03:34,030 --> 00:03:41,220
Voit OK and the name of my Smurfette would be do something.

58
00:03:45,280 --> 00:03:51,820
OK and then at the end of my Meffert name I need to put in a pair of round brackets.

59
00:03:51,850 --> 00:03:52,360
OK.

60
00:03:52,360 --> 00:03:59,830
And then I need to open and close my Smurfette by using an opening curly brace followed by our closing

61
00:03:59,830 --> 00:04:00,580
curly brace.

62
00:04:00,580 --> 00:04:01,460
OK.

63
00:04:01,480 --> 00:04:04,710
So as you can see here are my fate is now created.

64
00:04:04,750 --> 00:04:05,190
OK.

65
00:04:05,290 --> 00:04:07,320
So what does this avoid hear me.

66
00:04:07,330 --> 00:04:07,710
OK.

67
00:04:07,750 --> 00:04:13,250
So here this void here is the return value of my method.

68
00:04:13,420 --> 00:04:21,690
OK so first in order to create your Mefford you need to actually specify the return value of your method.

69
00:04:21,940 --> 00:04:26,570
So as you can see here the return value of my method is void.

70
00:04:26,630 --> 00:04:27,290
OK.

71
00:04:27,490 --> 00:04:31,050
This means that this Smurfette return is enough.

72
00:04:31,110 --> 00:04:36,150
Ok this void here means that my method is going to return nothing.

73
00:04:36,340 --> 00:04:39,200
And my method is going to actually to just do something.

74
00:04:39,220 --> 00:04:44,540
Ok this type of method is the most simplest type of method.

75
00:04:44,560 --> 00:04:48,440
So as you can see here I must give my method a name.

76
00:04:48,620 --> 00:04:51,210
OK this is the name of my method do something.

77
00:04:51,430 --> 00:04:56,930
And then at the end of my method I need to put in a pair of round brackets.

78
00:04:56,980 --> 00:05:04,960
After that I need to open and close my Smurfette by using an opening curly brace followed by our closing

79
00:05:04,960 --> 00:05:05,580
curly brace.

80
00:05:05,610 --> 00:05:09,400
OK so this is how you create MFL in Java.

81
00:05:09,400 --> 00:05:10,080
OK.

82
00:05:10,330 --> 00:05:13,460
And then inside them F-ed I can't put my statements.

83
00:05:13,520 --> 00:05:17,550
So inside these two curly braces I can put my own statements.

84
00:05:17,590 --> 00:05:17,990
OK.

85
00:05:18,010 --> 00:05:23,670
So for example now I just want to output the value of some text to the console.

86
00:05:23,680 --> 00:05:24,240
OK.

87
00:05:24,490 --> 00:05:26,140
So I just need to type in here.

88
00:05:26,230 --> 00:05:37,720
System that out that line and then inside the prentices I need to put in two double quotes and and then

89
00:05:38,200 --> 00:05:40,950
inside the double quotes I can put in my text.

90
00:05:40,960 --> 00:05:41,780
OK.

91
00:05:42,310 --> 00:05:47,680
So this text comes from the do something Meffert.

92
00:05:47,740 --> 00:05:48,810
OK.

93
00:05:49,210 --> 00:05:54,710
So now if you on my project as you can see here it's going to show us nothing.

94
00:05:54,880 --> 00:05:59,030
We need to actually call our Mefford from the main method.

95
00:05:59,080 --> 00:05:59,960
OK.

96
00:06:00,130 --> 00:06:06,620
That's the importance of the main method the main method is the starting point for running our Java

97
00:06:06,640 --> 00:06:07,140
code.

98
00:06:07,170 --> 00:06:07,590
OK.

99
00:06:07,630 --> 00:06:13,390
Without this main effect we cannot actually run or execute our Java code.

100
00:06:13,420 --> 00:06:14,000
OK.

101
00:06:14,230 --> 00:06:20,150
So inside the main method OK I just need to refer to the name of our method.

102
00:06:20,200 --> 00:06:23,160
OK so the name of our method is do something.

103
00:06:23,200 --> 00:06:25,930
Ok so I just need to refer to this name.

104
00:06:26,170 --> 00:06:30,180
So I need to type in here do some finish.

105
00:06:30,580 --> 00:06:31,090
OK.

106
00:06:31,150 --> 00:06:38,080
And then at the end of my Smurfette name I need to put a pair of round brackets.

107
00:06:38,080 --> 00:06:38,670
OK.

108
00:06:38,800 --> 00:06:41,560
And then at the end I need to put in a semicolon.

109
00:06:41,860 --> 00:06:42,370
OK.

110
00:06:42,370 --> 00:06:45,270
So as you can see here it's now showing us an error.

111
00:06:45,280 --> 00:06:45,920
OK.

112
00:06:46,180 --> 00:06:53,980
So first let me point out that in order to make the eclipse happy for now just put the static keyword

113
00:06:54,070 --> 00:06:56,450
at the start of your Meffert creation.

114
00:06:56,470 --> 00:06:57,100
OK.

115
00:06:57,160 --> 00:07:00,230
Static void do something.

116
00:07:00,240 --> 00:07:07,120
OK so I'll talk more about this static or later but for now make sure that you put the static keyword

117
00:07:07,330 --> 00:07:09,830
before your method creation's.

118
00:07:09,850 --> 00:07:10,520
OK.

119
00:07:10,960 --> 00:07:13,910
So as you can see here the error is now gone.

120
00:07:13,960 --> 00:07:19,400
So if I run my project now as you can see it outputs this value to the console.

121
00:07:19,510 --> 00:07:22,440
This text comes from the do something method.

122
00:07:22,470 --> 00:07:28,140
Ok this text is the result of execution of this line of code here.

123
00:07:28,390 --> 00:07:28,920
OK.

124
00:07:29,020 --> 00:07:35,290
And in line 9 as you can see inside the main method I actually called this method.

125
00:07:35,350 --> 00:07:35,980
OK.

126
00:07:36,100 --> 00:07:38,520
So first of and I actually ran my project.

127
00:07:38,720 --> 00:07:41,170
It's gonna execute this main effect.

128
00:07:41,170 --> 00:07:41,630
OK.

129
00:07:41,710 --> 00:07:48,200
And then inside the main effect I actually referred to the name of our method to something and that

130
00:07:48,220 --> 00:07:55,420
it's going to actually go inside the do something method and then it's going to execute this line of

131
00:07:55,420 --> 00:07:56,160
code.

132
00:07:56,230 --> 00:08:00,610
And as you can see here this is the value that is output to the console OK.

133
00:08:00,610 --> 00:08:02,800
Now let me give you another example.

134
00:08:02,800 --> 00:08:03,260
OK.

135
00:08:03,310 --> 00:08:06,420
So first I need to put in the static keyboard.

136
00:08:06,430 --> 00:08:07,000
OK.

137
00:08:07,000 --> 00:08:08,120
Static.

138
00:08:08,710 --> 00:08:13,880
And then I need to specify the return type of my method.

139
00:08:13,930 --> 00:08:14,650
OK.

140
00:08:14,800 --> 00:08:17,280
So the return type of My effect is void.

141
00:08:17,560 --> 00:08:18,150
OK.

142
00:08:18,430 --> 00:08:21,690
And then I need to give my method a name.

143
00:08:21,730 --> 00:08:22,100
OK.

144
00:08:22,180 --> 00:08:27,520
So the name of my method would be multiply two numbers.

145
00:08:28,150 --> 00:08:28,740
OK.

146
00:08:28,840 --> 00:08:36,130
So this is the name of our my first and then at the end of our Meffert name we need to put in a pair

147
00:08:36,130 --> 00:08:38,030
of round brackets.

148
00:08:38,290 --> 00:08:46,090
And then I need to open and close my Meffert by using an opening curly brace followed by our closing

149
00:08:46,090 --> 00:08:47,910
curly brace.

150
00:08:47,930 --> 00:08:51,040
So as you can see here are my fate is now created.

151
00:08:51,050 --> 00:08:51,510
OK.

152
00:08:51,560 --> 00:08:55,510
So now I can putting my statements inside this method.

153
00:08:55,550 --> 00:08:56,200
OK.

154
00:08:56,540 --> 00:08:59,780
So now I want to create some variables here.

155
00:08:59,810 --> 00:09:03,160
So the first variable is it a.

156
00:09:03,470 --> 00:09:07,580
And then I can assign a value to my variable for example number two.

157
00:09:08,030 --> 00:09:13,850
And the second variable is in B and I can assign another value to the Suadi.

158
00:09:13,850 --> 00:09:21,050
But for example number 6 and here I want to create another variable in order to sort of multiplication

159
00:09:21,080 --> 00:09:22,630
of these two numbers.

160
00:09:22,640 --> 00:09:22,990
OK.

161
00:09:23,000 --> 00:09:30,740
So here I just need to refer to the name of my evaluable multiplied by B OK.

162
00:09:31,040 --> 00:09:33,780
And then I need to put in a semicolon at the end of my statement.

163
00:09:33,810 --> 00:09:34,410
OK.

164
00:09:34,640 --> 00:09:39,890
And here I want to output the result to the Katsulas system that's out.

165
00:09:39,890 --> 00:09:41,120
That's princeling.

166
00:09:41,570 --> 00:09:48,280
And then inside Apprentice's and then inside the apprentice's I just need to refer to the result.

167
00:09:48,510 --> 00:09:51,690
And then at the end of my statement I need to put in a semi-colon.

