Hi everyone it is still Todi.
I want to talk about how to write our code more professionally OK.
In the previous tutorials I talked about objects and methods and how to use objects and methods together.
OK.
But in this tutorial I want to show you how you can write secure codes.
OK.
So first we need to create a Java project.
OK.
So in order to create a Java project you need to click on File New and then click on Java project.
OK.
So for the project name just type in here getters and setters.
OK.
And click and finish.
So as you can see here our project is now created and then we need a main class for our project.
OK.
So just click on this as our RC folder and then click on find new and then click on class.
So for the class name just type in here made and for the package we need a reverse domain here to just
type in here come that your name dot project name OK getters and setters and then make sure that you
check these checkpoints here.
Public static void main method.
And then click on finish.
So as you can see here our class is now created and then let me delete this comment and then let me
make this area right.
OK.
So now we can write our code here.
So now I want to create a blueprint in order to show me how I can't exactly create dog objects.
OK.
So I need to create a class called Talk.
OK.
So in order to create a class I just need to click on this package here and then click on File New and
then click kind of class.
OK.
So the name of our class is Doc OK and it's going to actually put this class inside this package.
OK.
Because we clicked on this package and it's going to put this class inside this package OK.
So for the modifiers use public and then click on finish.
So as you can see here our target class is now created.
OK.
And now that's our blueprint is created we need to put some instructions inside this class in order
to show us the characteristics and behaviors of a dog object.
So for example the characteristics of a dog are create some variables here at speed and I can assign
a value to my variable for example number 70.
And again and power.
And then I can assign a value to my valuable for example number 80.
And as you can see here these are the characteristics of my dog objects.
OK.
And are like objects have behaviors.
So what are the behaviors of a dog.
So for example a dog can run.
OK.
So here I just need to type in voit run ok and insert them and I can write them that out that print.
And then inside the parenthesis I can't just type in here.
Ron
OK.
So as you can see here at the end of my statement I need to put in a semicolon.
Another behavior of a dog is a dog sleeps.
So here I just need to type in Voyt sleep and then I need to open and close my Mfat by using an opening
curly brace followed by our closing curly brace and then inside the left.
I just need to typing system that out that princeling and then inside the apprentice's I can write sleep
OK.
And then at the end of my statement I need to put in a semicolon.
So these are the characteristics and behaviors of my dog objects.
OK.
And now that our blueprint is ready we can create objects from this class.
OK.
So inside the main class.
So as you can see here this is our main class.
OK.
And inside the main method.
So this is our main method.
OK.
We can create objects from this class.
OK.
So first I need to refer to the name of my dog class.
OK.
And then I need to give my object a name.
So for example my dock.
OK.
And then I put an assignment operator here.
And then I put this key vote here Neal.
And then again I refer to the name of my class and then I put a pair of round brackets after my class
name.
OK so this is how we create objects from classes.
OK.
So now I want to actually access the characteristics and behaviors of my dog objects.
OK.
So inside the main class and inside the main method I have to actually to output the value of the speed
instance variable of my dog object.
So here I just need to type in the system that's out that land and then inside the prentices first I
need to refer to the name of my object my dog.
That speed.
OK.
And then I need to put in a semi-colon at the end of my statement aren't here.
Are you want to actually output the value of their power or instance variable to the console.
So I just need to type in system that out that Prince land and then inside the prentices first I need
to refer to the name of my object that power.
OK.
And then I need to put in a semicolon at the end of my statement and I want to actually call the behaviors
of my dog object.
For example I want to tell my dog to run.
So first I need to actually be fair to the name of my object.
My dog got run ok.
Or for example I want to actually tell my dog to sleep.
So inside the main class and inside the main method first I need to refer to the name of my object that
sleep.
OK.
So this is how you can actually access the characteristics or instance variables and the behaviors of
your objects.
OK so now if I on my project as you can see these are the characteristics and behaviors of my dog objects.
OK.
So as you can see here I created a blueprint.
So this is our blueprint.
OK.
So let me now double click on this dog.
The job I have here in order to make this a little area of order.
So as you can see here this is our blueprint.
OK.
And then I created an object from this blueprint from the start class inside the main class and inside
the main method.
OK.
So this is our dog object that we created in line 7.
OK.
But there is a problem here.
My code is not secure enough.
Why.
Because as you can see here I shouldn't allow the main class.
So this is our main class ok.
I shouldn't allow the main class to access the characteristics of my dog object directly.
So inline 8 and inline 9.
I am actually accessing the characteristics of my dog object directly.
First I am referring to the name of my object and then I am actually accessing the instance variable
of this might like object directly.
This is not the proper way to actually write our codes.
OK.
There is something wrong here.
In this way our code is not maintainable.
So what should we do in order to solve this problem.
So in order to solve this problem we should use setters and getters.
For our instance variables.
OK.
So as you can see here inside the class these are the instance variables of our dog objects.
OK.
As I said before we call these characteristics instance about because these characteristics are owned
by the instances or objects of this class.
OK I want to show you how you can create get hearer's and setters for instance variables.
OK.
So what are these getters and setters for example if you want to access the value of this speed instance
variable we should use a method called getter.
OK so if I for example want to access the value of this speed instance variable I should use a method
called Get here in order to actually access that value.
OK.
We shouldn't access the value of this instance variable in this way.
This is not the proper way in order to access the value of this instance variable in this way.
OK but if I want to actually assign another value to my speed instance variable we should use a method
called setter.
OK so here I can actually assign another value to my SPI instance variable.
So first I need to refer to the name of my object my dog that speed and then I put an assignment operator
here and then I assign a value to my variable.
For example number 25.
And then I put a semi-colon at the end of my statement.
OK.