High students in this tutorial you're going to go ahead and create our first Android application.
So let's create a new Android studio project so we can start in your Android studio project and for
the application I'm just typing here.
App number free.
OK.
And the company damend you can specify the company domain here the package name the project location
and then just click next and here for the minimum STK choose API 16 Android 4.1 jellybean for phone
and tablets.
So this could be next.
And then here too is basic activity next.
So let me tell you that the differences between basic activity and interactivity is that by using the
basic activity you get the menu options for free.
You can see these menu button here at the right hand side the top right hand side here.
So about using any activity you don't get this option but you can add it later.
So I'd prefer to choose this one here for now.
Choose basic activity and then just click on next and then he can specify the activity name last name
title and the many resource names so you don't have to change anything here just click and finish.
So let's wait a little bit here.
So now as you can see our project is created and still the great deal built is running so let's wait.
OK.
So now it's actually configuring the product for us.
And now the project is ready.
So now let's actually go to this activity under limited access and so as you can see here it is the
android view.
And then inside is a race for lower left shoulder here just double click and it's activity underly minute
example select is a floating action button and then press until the key on your keyboard.
Now let's go back to content underline minute X amount selectees hello world view and then present it
here on your keyboard.
So now I want to design the user interface of this application.
So first let's actually close this activity underlaid minute example tap here at the top let's double
click on this content underlayment and examine.
And now you can see that we have these components resection.
We have this relatively out right.
Let me show you here.
So this is actually a relative lay out here.
So let's add a linearly out or linearly or vertical to this relatively flat.
So this pallet section let's search for the layouts for them.
So this is really as follows.
And let's select this linearly as vertical here and just drag it here into this relatively outhere and
just put it here at the center horizontal here and center vertical so you can see these dotted lines
that are actually showing us that where we can actually put our linearly out.
So just put it here at the center and now we can see that the layout width and the layout height of
are linearly out vertical is actually match parents.
So you can see that the orientation is vertical.
This is really important.
So now you know that what why we have these distances here and that's because of the padding attributes
of the relatively out inside these text top you can see these attributes here these values.
So let's go back to the design top here at the bottom.
Now I want to add some text views to this play out here.
Is linearly I-30 card.
So now let's actually scroll to the top and this palette section.
Select this text view and just drag it and put it in so it is linearly out vertical.
So now we can see that I actually put this takes you hit Enceladus linearly aesthetical Enceladus up
componentry here.
So let's select this text view and for that little tweet here you can see that it is much aperient.
Let's change it to rap content and the idea of height is also the content.
So it is good content.
And let's actually specify an ID for the states.
So the idea is going to BTX the Vaun and the person enter on your keyboard.
So now all you want to put this takes you in the center horizontal or key in the center horizontal of
this linearly or 20 cut.
So in order to actually change the position of this takes you inside linearly with vertical I must change
their layout.
Gravity.
Why.
Because this takes inside is linearly.
I swear to God and this means that this takes is actually the child of this linearly out or in other
words this linearly out is actually the parent of this text view.
So now I want to actually change the place of this text and put it under a certain horizontals of this
linearly.
So let's go to view all properties section here and let's select one of these properties and let's search
for layout gravities we just type in here lay out gravity.
And now this is really Earth gravity attribute.
Just open it.
Let's check this.
Check this check box that says Center horizontal.
And now we can see that this text is actually centered horizontally inside this linearly aesthetical
this is very important.
But if you have another attribute and that is called gravity.
So let's actually find to the gravity attribute.
So let's see what is that.
That's scroll down here.
In order to find it.
So here it is the gravity attribute.
And you can see.
So what is this gravity attribute.
We have less gravity and we have gravity What's the difference.
The difference is that if you want to change the place of your user interface component inside a parent
you have to change the layout gravity attribute.
But if you want to change the content or the child of your component you have to change the gravity
attribute to what's this actually let me give you an example.
So for example I have this text right.
I have this text view.
Let's set the layout to actually match parent for this text view.
So now as you can see the layout with this picture is actually match the parent.
Now I want to change the gravity attribute so this is the gravity attribute.
Right.
So I told you that the gravity is going to specify the location or the position of the contents of your
component here inside the child.
So you can see that this is actually it takes a view which is going to be the parent and the text.
So this takes you is going to be the child.
Right.
So now when you change the gravity of your takes view is going to change the position of the child which
is going to be the text.
So he can't say Center.
So let's actually find the center checkbox.
Let's take the search box that says Center if a tick tick box now it's going to put the text of this
text at the center.
The 66 books now.
And now you can see that the text of this text view is now at the center right.
And that's because of this gravity attribute.
So let me actually scroll to the top here and let's change them.
They have to be much much apparent to the content again.
So now let's find out gravity Alice unchecked is chapbooks center horizontal here.
Let's take it.
And again as you can see it is actually on the left hand side of this linearly I-30 cut right.
So let's select this linearly as vertical.
Inside this componentry section is like this linearly I swear to God.
And now I can actually find the gravity attribute here.
So this is the gravity attribute and if you want to search for it just select one of these properties
and just type in here gravity OK and this is the gravity attribute and now OK.
So this is the let linearly with vertical which is going to be the parent.
Right.
That takes you inside this linearly Athletica it is going to be the child.
So if I actually change the gravity attribute of this linearly I was vertical.
It is it is going to change the position of the child which is this takes a view.
So I can actually for example check this checkbox that says Center.
So now we can see that this takes view is actually on the center of this linearly as vertical or for
example I can unticketed checkbooks again and I can take the box that is centered horizontal and now
we can see that this view is actually in the center horizontally Enceladus linearly with Westacott.
So that's the difference between linearly out excuse me that's the difference between length gravity
and gravity.
Lay out gravity is going to specify the location of your user interface components according to the
parent and the gravity attribute the gravity a is going to specify the location or the position of the
child inside that parent.
Right.
So we're going to actually create some more examples about that.
So now what ever actually what ever that takes views that I am going to add to this linearly aesthetical
is going to be under center horizontally.
Why.
Because for the linearly Elsworth vertical gravity attribute I said this centered horizontal so it's
going to set the position of the children of this linearly as vertical and the center horizontal.
So let's add another text view to this linearly as vertical and release it.
So as you can see the layout is much apparent.
Let's change the mass path into the content.
Now as you can see it is at the center.
Let's actually change the idea of these takes you to t x the two and then precedented on your keyboard.
Let's add another takes you to these this linearly vertical so just select takes a view and put it here
inside this linear they are square circle.
Now let's set the lay out feet to wrap content.
Here.
Let's actually change the ID to what the free takes the free and then person until January.
So let's also change the text of these text views.
So let's select selectees first text.
This takes the.
And let's find the text attribute which is this one.
And just typing here takes one text one and the person until January both Let's select selectees takes
you second takes you and for the text attribute just type in your text to and then present until your
keyboard selects a first text view here and for the text attribute just typing in here text free and
then present and help you on your keyboard.
Let's add another text view to this linearly as reticle so just select the state's view and just drag
it here into this linearly as vertical.
And now for the layout read here.
Let's pass the value A-rab content and now it is actually under center horizontal of this linear swastica
select is text view.
And for the ideal it's actually pass the value to 64.
And that person interregional keyboard.
And for the text attribute let's set the value text forth and then press enter key on your keyboard.
Let's add another takes you so inside these widgets for just select the states and put it here inside
these linearly as vertical and then release it.
So for the lay out again let's pass the value or content for the ID.
Let's say that this value is going to be to 65 and then press enter on your keyboard and for the text
for the text strip you're just open here a text file and then press that international keyboard.
So now we have these text views right.
So now let's select all this takes us inside this componentry section just select one of these takes
us here and you can actually hold down the commentary on your keyboard.
So if you are using a Windows machine you are unique to actually hold down the control on your keyboard
and then select all these takes views here and now are these takes views are selected.
Right.
So now I can actually change the padding attributes of these text.
So what is the padding.
The padding is actually the inner space of our component our user interface components.
So our views does have an inner space.
Right.
So let me show you that space silicates.
Look at this this view here.
You can see this Innerspace space on the right on the bottom on the left and on the top.
This is actually called the padding.
Let's select or this takes music and so you can actually hold the shift key down on your keyboard and
select all of them at once.
And here you can see these padding attributes here inside this property section.
Just open it.
So we have this padding we have padding bottom padding and padding left right.
Startup So we have this padding for all directions left right top button.
So for the padding for all directions let's pass the value.
For example 10 and the person entelechy on your keyboard here.
So now we can see that we have actually passed the value of 10 DP for the padding attribute of all these
fixed views and you can see that the inner space for all in all directions is actually increased.
So now you can see our text use here.
So let's select all these are all of these six again.
And now I want to talk to you about the margin attributes so what is the margin the margin is actually
the outer space.
It is the opposite of padding.
So when I say Margene I mean the outer space of this actually takes you to this space that is actually
outside for example outside of this right hand side of the space view outside of the top top of the
stakes view.
Outside of this a of the state's view and outside of the bottom of this text view.
So let's select all this takes views and inside the properties section you can see the lay out margin
right.
So for the left margin that's passed the value for example 15.
Right.
And then press energy interview on your keyboard so you can see that we have a margin for all directions
by them and left right start up.
So when I say lay out Margene is going to actually put them 15 DP at actually 15 DP for all directions.
And then person until Zhenyu keyboard.
So now you can see that the out in the outer space is now increased.
So you can see these outer spaces this distances between these takes.
Here is now increased.
So now I think that's enough for the design of this application.
Let's go to main activity that you have a file here.
So as you can see again we have this piece of code that is related to the floating action button.
We actually already deleted this floating action button inside our activity underlayment at XM and so
we don't need it.
Now just to just highlight this piece of kit and that person on your keyboard.
Now you can see these piece of codes these codes actually uncreate options menu Mefford is an option
item selected.
I'll talk more about this later.
So let's actually delete these codes that are related to the menu options menu.
Just actually delete them and we only have the main activity class and the opening and closing curly
brace of dismay and anti-vehicle.
So this is really important and we have this uncreate Meffert here.
So the opening and closing curly blocks of this uncreate.
So let's actually go straight into this uncreate method.
And now you want to actually create objects of type complext view.
So we created these text views here inside our view.
These are the objects right.
So the only thing that we need to do inside our main activity class is to just refer to these objects.
So for example this takes you here this is actually an object right.
So let's go to main activity that of a file.
And inside is uncreate method.
First of all I just need to revert to the name of the text view class.
Right.
So then it now I need to specify the name of this variable.
Right.
Then what is valuable is going to be the one.
So as you can see our DNA that I doubt that I should be used for my variable is the same as the ID.
You don't have to specify this name actually as the same as the ID.
You can actually change it but I prefer to name it like this.
He actually won and then I put an assignment operator here and I just put up her apprentices.
And here I talk more about casting later in the practices.
We must actually cast this object that we are going to create.
Actually if you are going to to be fair we must test this object to a text object.
Otherwise the compiler is going to think that we are referring to a view object instead of takes your
object and after this practice is so in so the practice is you just refer to the name of the textbook
class in order to let the compiler know that we are actually referring to a text object.
And if you are 100 percent sure about that if you actually say that you are referring to our text view
object and you don't actually refer to a text view object your application is going to crash.
OK so and here I can't just say I can find view by ID or dot ID that Id dot what the vote.
So as you can see we have this art class that is actually auto generated for us and this art class is
going to have all these IDs that be specified inside the content.
Underlining that exemplified so never change the contents of this art class.
You don't have to actually even change a simple piece of code inside this class and neighborly you should
do that.
This class is actually an auto generated code.
And it's going to hold the IDs for assets and lots of other actually values.
So if you have this idea from this class that we actually specifying inside the content underly mandates
them.
So if we actually click on this content underlayment that example tap and if I select is text one you
can see that the ID is 361 right.
So let's go back to our Java code an activity class.
So TXI the one.
So now the autocomplete feature actually helped us to choose this one and then person and then put a
semicolon at the end of your statement.
So what we have done here first we actually cast this object to a text object in order to let the compiler
know that you are actually referring to a text view object.
And I said OK I want to really first with that object and say the view right find view by ID or are
you that he is the one.
So that's why I've specified IDs inside this content underlining that exemption.
Otherwise we would not be able to actually interact with this object from the job because this is really
important.
Let's go back to our main activity class.
So our That did a 360 once in its we actually finding into that object.
And here we are saying that we are actually fitting to a text view object.
So now that we have this piece of object at the right hand side of the assignment operator here we are
assigning that object to this.
He asks the one valuable because of they takes you.
So this one is just a valuable placeholder for holding this object on the right hand side of the assignment
operator.
Here let's create and other valuable tactics used to take a few takes the two assignment operator and
I put a pair of practice's takes view again we need to cast this object to a text view object find view
by id artist Id that itx the two semicolon.
So we have six takes views I think right.
Not five.
So let's actually create them here.
So again takes you to the free assignment operator and I put a pair of prentices.
Again I need to cast this object or two I'll take your object find your ID are taught ID thought TXI
the free semicolon.
Let's create another variable of latex VTX the for assignment operator.
Let's test this object to a text view object find view by id r that ID that DX the fourth semicolon.
So as you can see I put a space here.
It doesn't really matter if you put a space between this cast here and this value.
You can actually just put it in this way.
And finally even if you actually create 65 assignment operator again you need to cast this object to
a text view object find view by ID or that Id DOT takes the word ph the five semicolon.
So now that we have these variables that are actually referring to are three objects inside the content
under limited example we can actually a mini late are takes viewers here from our job codes.
So let's see how we can do that.
So here let's create a variable of type stream.
So first we must specify that data type or verbally.
And now I need to specify the name of my body so I can say that the name is actually my street value.
This is the name of the value the value of a lecture the assignment operator and at the right hand side
of this assignment operator I can put actually two coats and in circles I can see Android.
Programming is fun and then put put an exclamation mark at the end semicolon.
And here I can actually say he likes the board.
So I am going to refer to this.
He asks the one variable that holds that that is actually holds up that holds this takes two objects
right.
Takes the one that set next.
I am calling this method set takes and this takes the one object and I can pass a value as an argument
to this set text method so that this can actually show that it is going to put that value on the text
view one on the text the one on the screen.
So tasty want that said text.
And here you can see my stream value.
So am I actually passed this value but that halts this thing value to this method.
So remember this if it needs a value of 3 and we must pass a value of type String actually.
Let's run an application now.
And let me show you.
So just select one of these devices and then just click on OK let me show you the emulator.
So now you can see that our application is actually running on this emulator and you can see disvalue
and programming is one.
So this value is actually in place of the next one.
Right.
So if we actually go to this content under the limited exempli you can see that the first text is takes
one.
So you can see this value here and reprograming is one.
So by just referring to the ID of this takes one here 261 I could actually manipulate the text of this
takes one here so text the one that said text.
And we just need to pass a string value to this method in this way.
We are changing the text of the text what the programming is fun.
So now let's actually add some more quotes here.
It's really fun.
So this time I am going to the first to this t XTi two so I can say 1:54 that sit text at inside Apprentice's.
I want to use one of the string methods.
One of this thing class action team efforts.
So these are not going to be Street class misfits this is going to be actually instance methods of this
thing class.
So here I am going to refer to this string variable or a string instance.
So remember this is actually the string literal.
Right.
So if you are assigning this string literal to this variable so this is called and is and is a string
instance actually.
So here I can say is the prentices I can say my string value.
So now you want to call Osteen's Meffert on this instance.
So now as you can see we have lots of methods that we can call on this streambed object and this string
instance for example Chad could point at or lots of other methods for example this one index of index.
So we're going to use some of them here or the last index of as you can see here and you can see that
the data type of the parameter that this method has for example last index of my faith and the length
of it it is going to actually give you the number of characters inside that string.
So let's actually choose this one Chad at and then select it and that person and entered on your keyboard.
This method is going to return a value of type chat.
So now I can actually I need to pass a value of that integer to this method as you can see if it actually
hover in here.
Inside this prentices it is Sharratt it instantly cannot be applied so we must pass a value of that
integer here.
So I want to the character add index.
For example 0.
Right.
So remember in programming we always count from number zero.
Right.
So what does that mean.
So look at this string leader right here.
Android programming right.
So if you want to count the number of characters that we have inside these codes I must start from number
zero so the 8 is going to be zero.
The end is going to be number one and the D is going to be number actually 2.
So this means that it is inside the index 0 and is inside an index number one the is inside the index
number 2 and so on.
So when I say a maestro valued the chad at zero This means that give me the character at index 0 of
this stunningly the rule as you can see I am actually referring to this variable that holds the string
literal.
So I am calling this may 5th and this string literal right when I referred to my body but am actually
I want to access my value.
The value of this value.
So this means that I am actually getting to that value.
So Chad at 0 is going to actually give us the character.
So let's run our application now and let's see what happens.
Let me show you the emulator.
So as you can see our application crashed.
Why.
I'll tell you why.
Because this method Septic's needs a value of type string.
And this method Chad at here is going to return a value that is of type chat or a character.
So we must convert this returned value to an R to see value.
So after this value here I just need to put a plus operator and then I can just put two codes in in
order to actually convert this return value to a string value.
So plus operator and then Cotes.
So let's run our application again.
Let me show you the emulator.
So now we can see this a here right.
So the AA is actually inside the index 0 of this string right here.
So you can see the value here.
Let's go back to actually two and three studio.
And now I want to actually call another method of this think class actually so now I can just refer
to the name of this at XTi free this time takes the free variable that holds the free object so takes
the free Dot said text.
And now again I am going to refer to the name of this Mycenean Value-Added bell and this time I will
actually use this method substring.
So as you can see we have three different versions of substring method.
The first one only accept one argument which is going to specify the beginning index.
So let's actually first choose this one.
The second one is going to accept two arguments.
Let's first select this one substring.
And now you may ask that OK what's the difference between parameter or argument.
So the parameter is going to be when we actually create that method.
We say that we are actually specifying a parameter for that method.
Right but the argument is going to be the actual value of that up prime.
The other method actually may be called that Meffert.
So are these parameters or arguments are actually used interchangeably so don't worry about that.
It's the value that we passed to effect.
OK.
Just let's make it simple.
So my string value that substring.
And I just need to pass only one value which is going to have actually of that integer.
I need to pass a value of integer at this substring if it is going to return what value of string.
So how do I know that this method I try to return a value of string.
So let me delete this method again.
Let me call it again.
That substring.
So as you can see look at this move it's a substring accepts a value of type Integer.
And as you can see it's prime.
Your name is begin index right.
And it says string.
So this string here means the return type of the Smurfette This means that this method is going to return
a value of 3.
So let's use this method.
And now over to pass the for example index number 2.
Right.
Let's see what happens.
Let's run the application and let's see what happens.
Just click on run.
Let me show you the emulator.
So now as you can see our application is actually running on the simulator.
I look at this video it says DROITE.
So what's this.
So I said OK.
Number two is going to be the beginning index and I called Ismir for it.
So look at this value.
Look at this single row.
So let's look at the index number two.
So it is index number one in is actually the index number is index number 0 right in index number 1
and D is index number 2 and the past index number two to the Smurfette right.
So you can see that the A and the end is actually eliminated and did from this starting point from this
begin index the to the end is actually on the screen is actually outputted on the screen.
Droite programming is what is fun.
So that's it.
That's what this Meffert does.
That's the job of the Smurfit.
OK.
So let's actually use that method that substring method that actually accepts two arguments.
So here are generally first of these three XTi for optical itx the four that said text and I can refer
to the name of this variable missing value that substrings So I want to choose this method that actually
exits two arguments.
So you can see these variations between these two men.
It's sort the first one exits only one argument and the second one accepts arguments.
So look at this here we can specify the beginning index and the end index.
So what does that mean.
For example let's pass the value.
For example 5 comma.
And now I need to specify the end index so the end index is going to be for example.
OK.
Nice.
Let's run that application now and let's see what happens.
Let me show you the emulator and now look at this video.
It says all the space.
So let's find the index 5 inside the string leader.
So 0 is 8 and is 1.
These two are is actually free.
Right.
Or is four and why is.
So this is this starting index.
So you can see this right here.
Right.
And d d we have D here.
So we have also this d here let me show you the emulator.
So we have this D.
And we have this space here.
And look at this one as you can see it at the end index is 9.
So the R is index 5 D is index 6.
This page is also a character right.
So it is going to be index number actually 7.
The DP is going to be index number 8 and here there are is going to be index number nine.
Right.
So we only have actually the peak.
So we have what we have of 5 6 7 8 and or is not actually output to the screen.
Let me show the emulator or is not outputted to the screen so the ending index is not going to be actually
out with at the end an index is going to be eliminated.
Only this thought the index actually through the ending the ending index but not including the ending
index.
So only the starting index and the characters between this strange starting index and the ending index
is going to be out with it but not including the ending index such as are.
So if you actually look at this singly there are the character that is actually in the index on actually
index number 5 is.
So let me show you the emulator.
So it is printed.
Are you actually out with it to the console.
So why is five D6 space is servant and P is 8 right.
Or is night or is nine.
Right but are is not output to the screen.
So this means that R is actually eliminated and only a d p ideaspace p.
So you can see this value here.
So the value that is inside of the index nine is not out with it.
It is going to be actually ignored on the distraint five six seven eight not including the index the
ending index.
So hopefully that makes sense.
Now let's actually use another method takes the file this time data set text.
So now inside Apprentice's I am going to refer to the name of this variable my string value that index
of just they've been here indexed up and you can see different versions of this method.
So look at this method.
I want to actually use this method that accepts a value of types think.
Right.
And if it returns a value of an integer.
So this means that we must actually convert this value that we get from the Smif with which is that
integer 2 us think values so that we can output this value to the screen.
Otherwise our application is going to crash.
Why.
Because this it again is going to return a value of that integer.
Let's use it and then press on it on your keyboard and inside the prentices.
Now I need to put just two coats here and I want to get the index of a specific character that we have
inside this stunning leader.
So I want to get the index of this exclamation mark.
So inside the codes I just put this X and an exclamation mark here.
And finally I need to actually convert this integer value that we get from this method to a string value.
So just put a plus operator and then two coats.
Let's run our application now and let's see what happens.
Let me show you the emulator.
And now you can see that it says 26.
These are.
Here is actually in the index 26 inside this string literal.
So let's count.
Let's see if it is correct or not.
So DA is in the index 0 in is 1 2 3 4 5 6.
We have a space here 7.
This is actually 8 9 10 11 12 13 14 15 16 17 18.
We have a space here 19 20 21.
Again we have another space 22 23 24 25 and 26 correct.
It is actually an index 26.
So by using this method you can actually get a specific index of a specific character inside your string
literal.
Right.
We can also pass over word instead of character to this method.
So for example I can't say what is right or I can't say programming programming.
So it's going I should look at this for and it's gonna go inside this string.
And it's going to find disport in say this is stunningly the.
And it's going to give me the index of the first character of this word.
Inside is Stingley.
So this is inside is in the index 8 index number 8 of this string.
So it's going to return number eight.
So let's run an application now.
Let me show you the emulator.
So now as you can see you can see this value here number eight.
So it is actually the index number eight.
Right.
So this is how this index of a method works.
And let's actually comment out on this.
This piece of quote here because I want to actually teach you some more important concepts here.
So let me just come at it as wide as he can so I actually used the multiline comment here.
Slash's thought and I started with this slash start and then I actually ended ended it with the start
slash.
And finally I have stood inside this uncreate Meffert.
Right.
So now I am going to talk about the concept of casting.
So what is casting the means temporarily converting a type to another type if it is possible.
Right.
So look at this piece of cloth you look at these examples.
Here we are actually saying that OK we are going to find the view by the ID that we passed to dismember
it.
Right.
For example 61.
So it's going actually go inside its content.
Underly minute exam is going to look at the flight and it's going to find the oddity 61.
And here I am saying that I am a hundred and fifty percent sure that this text view is going to be of
type of text view object view.
As you can see it's this find view why I did not find the text by ID right.
And here I am saying that I am a hundred and fifty percent sure that the view that you are looking for
is actually of type text view.
That's what testing means.
I am actually temporarily saying to the compiler that it is going to be off the text view and there
is no doubt about that.
So now I want to actually give you some more real real world examples about casting.
So let me create just a one line comment and just typing here casting.
Right.
And here I can just type in here for example.
I can't just say a byte.
So this is you know but what is this by right.
It is actually an integer value and it's going to only hold an integer value or only between the minus
actually negative 428 and positive 127.
So it is going to only actually hold a very small integer value.
So this is the byte type.
And I can give it our name.
So for example I can say small in value small and value.
This is my very which is of the byte and I can assign a value to this valuable.
So here I can for example say number 25.
Right.
So remember I can only assign a number between displaying to minus 2 and 201 128 and one hundred and
twenty seven.
So dot dot dot.
So this range 127 positive right.
So here at this point it's ready but only holds a value bet into in this range.
So now I want to create a variable of type integer.
Right.
So here the name of my variable is going to be in value.
So you know that means that data can hold a lot more larger value.
Right.
And here I can actually cast these bytes to an integer value how I can put a pair of practices and I
can put integer here and I can refer to the name of this small value small in each value semicolon.
So what happens if I don't poods this casting here.
Nothing.
Why.
Because by still is an integer value but byte can only actually hold a very small range of values right.
But integer can can hold a larger.
Actually the range of values.
So I can actually cast Templer really this small value to an integer value.
So I just put a pair of practices and I just refer to the name of this.
But it's very valuable right.
So in this way the compiler thinks that this small interval is actually an integer value not an not
a byte value but an integer value and it's going to assign that value to the value value of it.
So that's what testing means.
Actually let me give you some examples here.
So I'm going to create a variable of type float so I can say float and the name of my variable here
is going to be float value float value right.
Assignment operator and here I can assign the value for example Number seven point eight.
Here's this valuable right.
So as you can see this value here is of type float and if you just put up this symbol value here the
compiler thinks that you are assigning a value that is of type double.
So you must explicitly let the compiler know that you mean float by just putting the character F after
that at the end of your Actually your value your float value your decimal value.
So I just put the child character in.
And now the compiler is satisfied the error is gone.
If you don't put this here and now as you can see the compiler is complaining and it says OK we are
we found that we must assign the value float but we found the value double here.
So just putting it in order to satisfy the compiler.
Now I want to create a variable of type integer.
So here I can say it and I can say that my number the name of my variable is going to be my integer
number right.
I put an assignment operator here and here I want to again use casting.
So I put a pair of prentices.
I put integers here right because I want to assign a value of integers to this value but right now I
can refer to the name of this variable flautas value a semicolon.
So what does this mean.
Let me actually just delete this casting here.
And now the compiler is showing us an error why if it actually hovered over this error it is incompatible
types required.
Ain't found flawed.
What does this mean.
This means that we have evaluable of that integer so we must assign a value of that mean to set this
value about right but we assign a value of type float to this value.
So how we can solve this problem how we can satisfy the compiler.
So here I just need to use the casting.
It just has this value to an integer value and the compiler is now satisfied.
And now this float value is temporarily not actually for the entire life of this variable.
Just temporarily It's just temporarily converted to a value of type integer.
So this means it's going to actually delete this decimal value.
If you cast this value to an integer value it's going to temporarily just delete this symbol value and
it's going to assign only number 7 to this value but integer.
So let me actually printed these values.
Let me just output these values to the screen.
So here I can say TXI the one that said text.
And now I want to output the value of this float value to the console.
So here I can say floats value.
So because this is actually the value of a float and the Smurfit Septic's needs of value of strength.
I just converted to a value of typesetting by just putting this plus operator and then two cards.
And this is also called concatenating.
So you are all already familiar with this concept right.
So now let's let's actually run an application.
Let me show you the emulator.
So now it says seven point eight.
So you can see this value.
Now I want to output the value of the small integer number variable which holds again.
This floats value here but you are casting to an integer data type.
So here I can see to the.
That said text.
And here I can see my integer number.
OK my integer number again because of that integer I must actually converted to a single value so just
put a plus operator to cults.
Let's run an application.
Let me show you the emulator.
Now you can see Number 7 here that this symbol value is actually the Eliminators here but you can only
see number 7 and that's what this testing means.
And in order to let you know that it is only temporarily temporarily cast it to an integer value.
I am going to print.
I am going to output this value to the console again.
So to use the free that said text float value plus operators to close.
Let's run an application again.
Let me show you the emulator.
And now you can see that it is still seven point eight right.
So that's as easy as that.
That's the concept of casting in programming.
So now let me give you an other real world example so that this concept becomes a second nature for
you.
OK so here I am going to create a variable of type float again.
So floats are the data type is going to be float and the name of my variable is going to be my float
my float number.
Assignment operator and I put a value of a float.
I actually assign a value of that float to this value.
So for example zero point seven or 0.9 semicolon.
So now again it's written as an error.
So I just put.
I just need to put the F character here in order to satisfy the compiler.
Let's create another variable of type float.
The name is going to be.
So let's change this name to my first my first floor number let's change let's give a name to this variable.
My second my second floor number
right now I can put an assignment operator here and this time I can put a value for example.
Fifteen point eight if semicolon I can I actually assigned this value to this valuable my second floor
number.
So now I am going to create a variable of type integer.
It resolved with an assignment operator.
So now I am going to actually assign the multiplication of these two values together so here I can see
my Fluke my first floor number multiplied by my second floor number semicolon.
So now it's going to show us an error.
And again because these two variables are of type float here and as you can see the result is going
to be that float.
So this is this is an integer.
So here we must again cast this value this result to an integer value.
So in order to do that I'll just put this expression inside the practice's here and now after this assignment
operator again I put another pair of practices and I put integer here inside the apprentice's.
So that it's going to actually execute this expression here first.
And the result of this operation here the result of this multiplication here is going to be cast to
an integer value and it's going to it's going to be assigned to this result variable.
So let me actually print these values to the concert.
So let me first just cast these codes.
Let me just excuse me that any comment out of these quotes here because I want to actually use the actually
the tea XTi here.
So now I can say to Stephen that said text is the that said text.
So now I can see my first floor number plus two coats right and now I can say to the two that said text
and inside the apprentice's I have the first of the name of this variable.
My second floor number plus two coats and finally takes the free.
That's a text.
And here I am going to out with the result to the screen result plus two coats.
Let's run our application again.
Let me show you the emulator and you can see these values the first value is forty point nine The second
floor value is fifteen point eight.
And the result is 61.
Why.
Because if you actually cast a result of this operation here to an integer value and we assign that
integer value to this value but.
So when you cast the results to an integer value it's going to actually eliminate that this small part
of the value.
And that's why it is only 61 here.
So let me actually show you another example here.
So for example we have actually over the bed for example my resort.
For example my value my value assignment operator and here I can say two point seven multiplied by five
semi-colon.
So what happens here as you can see the first value is a float.
But our second value is of type Integer.
And the result of multiplication of a float value and are an integer value is going to be what a float
value.
So that's why it's actually showing us an error because the result of this operation is going to be
of a float and it's going to actually be as good as it is.
It's going to be picked up and so if we actually put the result of this operation is going to be off
that float and float cannot be assigned to a valuable asset that integer.
So again we must actually put this expression inside Apprentice's.
And finally we can has this result to an integer value here and I can output this value to the console
CTX the four here that said text my value plus two coats.
Let's run an application now.
Let me show you the emulator.
I know it says 14 and that's really great.
So now we have actually and other kinds of sort of for example we have two variables of that integer.
So here I can say is are in our first value first int value assignment operator for example Number 10
semicolon in.
Let's create another variable and a second int value assignment operator.
Number 20 is assign a semicolon.
And now I can say 8 my results.
So our result is actually and the name is going to be resolved.
So remember you cannot actually use the we actually use the word spy and right so for example that the
word it is already used by Android and you cannot use this name in order to name your radio.
So you have to use unique names that are not used by Android itself.
So that name is going to be into value
right assignment operator.
And here I can say that for example.
So now this is going to have a floor to this and I can't name this valuable as a floor resort.
Excuse me a flawed result.
And OK so the name is not resolved and Hillary can say first into you for example plus or multiply multiplied
by a second value a semicolon.
So now as you can see it doesn't show us an error right.
So that's what's the problem here why it doesn't show us and we hear the result of this operation is
going to be off that integer.
Right.
This means that if we actually assign for example a number of free to this variable which is of type
float here it doesn't show us an error.
Number three is actually integer.
And I can also print can also output this value to the console.
I can say at 65 that said text flow result plus two quotes here.
You don't have to actually cast this value to a float value.
This integer value to awfullest value let's let's see what's the problem with the application.
Now let me show you the emulator and it says free point zero.
So it converted this value to our float value automatically.
The Android converter of integer value that we assign to this variable is free which is that integer
we assigned it to this variable of type float which its name is float result and we output this value
to the console.
So it is three point zero.
So it is already actually converted to a value of that integer this number of free here.
Right.
So for example if we actually multiply first value here multiplied by a second in value the result is
going to be of the integer right.
But when we assign it to this value but of type float it is going to be converted to a value of type
float.
So it is going to have a decimal value.
So let's run our application now.
Let me show you the emulator and now it says two hundred point zero.
So you can see this decimal value here.
It is still has the symbol value last resort.
So I think that see that is for this tutorial and I taught you lots of important concepts in this tutorial
so make sure to practice on these skills and make sure to create an application the same as mine in
order to practice these skills.
In fact that's an assignment for you.
So that's it.
If you have any questions about the concepts that I taught you in this lesson please post the discussion
in the course and then I'll do my best to answer all of your questions.
Thank you very much for watching and I'll see if the next tutorial.
And by the way I am actually updating the course and this app number free that I actually created here
is the updated version of the app number free app free actually that we have all of in the course so
I am going to update that course.
So thank you very much.
And I've seen the nice tutorial you.