Hi everyone in this theater early on I'm going to talk about methods in Java.
OK.
So first we need to create a Java project.
So just click on File New and then click on Java project.
OK.
And for the project name just type in here methods and then click on finish.
So as you can see here our project is now created.
So now we need a main class.
OK.
So just click on this as RC folder and then click on find new and then click on class.
So for the class name just type in here.
Meffert.
OK.
And for the package name we need a reverse domain here.
Just type in here com dot your name dot project name OK.
And for the modifiers to public and here to make sure that you check this checkbox here that says public
static void main effect.
OK.
This is the starting point for running our Java code.
OK.
And then click on finish.
So as you can see here our class is now created.
OK so now let me actually delete this comment here and then in order to make this a little earlier Vider
I just need to double click on the Smurfette Java tab here.
OK.
Our editor area is now much wider and we can write our codes inside the main method.
OK.
So I want to talk about methods in Java.
OK so what are if it's a job or if it is a collection of statements that are grouped together to perform
an operation.
OK.
You have been using methods in the previous tutorials like the main method that I told you about.
OK.
In this tutorial I'm going to show you what methods actually are and how you can create your own methods.
OK.
So our method is just a chunk of code that does a particular job.
OK.
But methods are set out in a certain way.
You have a method header and I'm a fed body.
The header is very you tell Java about what value you type if any the method will return OK and ain't
value or double value etc..
OK as well as the return type you'll need a name for your method which also goes in the header.
Ok you can pass values over to your methods and these go between a pair of round brackets.
OK the method body is where your statement goes.
OK in Suydam effort body you actually put your own statements.
OK so first let me point out that you must always create your methods inside the class.
OK.
And you can not create your methods inside other methods.
OK so for example you cannot create MFX inside the main method.
OK so now let me give you some real examples.
OK we cannot actually create methods inside other methods.
OK we can only create methods inside the class.
OK so inside the method class as you can see here.
In between those curly braces this is our method class.
Ok here I can actually create my own method.
So I just need to type in here.
Voit OK and the name of my Smurfette would be do something.
OK and then at the end of my Meffert name I need to put in a pair of round brackets.
OK.
And then I need to open and close my Smurfette by using an opening curly brace followed by our closing
curly brace.
OK.
So as you can see here are my fate is now created.
OK.
So what does this avoid hear me.
OK.
So here this void here is the return value of my method.
OK so first in order to create your Mefford you need to actually specify the return value of your method.
So as you can see here the return value of my method is void.
OK.
This means that this Smurfette return is enough.
Ok this void here means that my method is going to return nothing.
And my method is going to actually to just do something.
Ok this type of method is the most simplest type of method.
So as you can see here I must give my method a name.
OK this is the name of my method do something.
And then at the end of my method I need to put in a pair of round brackets.
After that I need to open and close my Smurfette by using an opening curly brace followed by our closing
curly brace.
OK so this is how you create MFL in Java.
OK.
And then inside them F-ed I can't put my statements.
So inside these two curly braces I can put my own statements.
OK.
So for example now I just want to output the value of some text to the console.
OK.
So I just need to type in here.
System that out that line and then inside the prentices I need to put in two double quotes and and then
inside the double quotes I can put in my text.
OK.
So this text comes from the do something Meffert.
OK.
So now if you on my project as you can see here it's going to show us nothing.
We need to actually call our Mefford from the main method.
OK.
That's the importance of the main method the main method is the starting point for running our Java
code.
OK.
Without this main effect we cannot actually run or execute our Java code.
OK.
So inside the main method OK I just need to refer to the name of our method.
OK so the name of our method is do something.
Ok so I just need to refer to this name.
So I need to type in here do some finish.
OK.
And then at the end of my Smurfette name I need to put a pair of round brackets.
OK.
And then at the end I need to put in a semicolon.
OK.
So as you can see here it's now showing us an error.
OK.
So first let me point out that in order to make the eclipse happy for now just put the static keyword
at the start of your Meffert creation.
OK.
Static void do something.
OK so I'll talk more about this static or later but for now make sure that you put the static keyword
before your method creation's.
OK.
So as you can see here the error is now gone.
So if I run my project now as you can see it outputs this value to the console.
This text comes from the do something method.
Ok this text is the result of execution of this line of code here.
OK.
And in line 9 as you can see inside the main method I actually called this method.
OK.
So first of and I actually ran my project.
It's gonna execute this main effect.
OK.
And then inside the main effect I actually referred to the name of our method to something and that
it's going to actually go inside the do something method and then it's going to execute this line of
code.
And as you can see here this is the value that is output to the console OK.
Now let me give you another example.
OK.
So first I need to put in the static keyboard.
OK.
Static.
And then I need to specify the return type of my method.
OK.
So the return type of My effect is void.
OK.
And then I need to give my method a name.
OK.
So the name of my method would be multiply two numbers.
OK.
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
of round brackets.
And then I need to open and close my Meffert by using an opening curly brace followed by our closing
curly brace.
So as you can see here are my fate is now created.
OK.
So now I can putting my statements inside this method.
OK.
So now I want to create some variables here.
So the first variable is it a.
And then I can assign a value to my variable for example number two.
And the second variable is in B and I can assign another value to the Suadi.
But for example number 6 and here I want to create another variable in order to sort of multiplication
of these two numbers.
OK.
So here I just need to refer to the name of my evaluable multiplied by B OK.
And then I need to put in a semicolon at the end of my statement.
OK.
And here I want to output the result to the Katsulas system that's out.
That's princeling.
And then inside Apprentice's and then inside the apprentice's I just need to refer to the result.
And then at the end of my statement I need to put in a semi-colon.