‫Instructor: Hi.
‫Within this lecture, we're going to learn about
‫statements and operators.
‫In fact, it's time to learn about if controls.
‫That is to say we can actually determine
‫what will happen if some condition holds in our code.
‫But before we learn that,
‫we have to understand some basic operations,
‫like greater than, less than, equal to, if not equal to,
‫some operations like this.
‫So within this lecture, we're going to learn about those.
‫And following, the next lecture,
‫we're going to deep dive into the if statements
‫and then loops.
‫So if you don't know what those terms are,
‫it's perfectly okay, you are about to learn it.
‫So I believe it's time to create a new Java class for us.
‫So if you're doing this with an activity
‫because of the errors that we have observed
‫in the previous lectures,
‫then you should create a new project.
‫But I'm going to add a new Java class from here
‫and I'm gonna call this Statements, okay?
‫So this is basically what we are going to do.
‫We're going to add our new main method over here
‫because, remember, this is our entry point
‫and this should be in every Java code
‫that we are trying to run over here.
‫So maybe you may want to pause the video
‫and try to write it on your own,
‫see if you remember.
‫So it says public static void main
‫and it takes some parameters called string array,
‫and we name that string array arguments,
‫and open curly braces.
‫Here we go.
‫Now, I believe it's good to start
‫with some mathematical concepts like adding or subtracting.
‫So in order to do that,
‫I'm gonna create a new integer and we will work on that.
‫So I'm gonna call this x and x will be five.
‫So what if I want to add something to this x?
‫Let me print this out so that we can see it,
‫it's current value over here.
‫Let me run this
‫so we can get rid of this old Logcat over here.
‫Yep, this is five.
‫So let me add something to this x,
‫like let me add one.
‫So we can do it this way, right, x is x + 1.
‫So if I print out x right now, I will get six.
‫First I get five, then I get six because I added one.
‫So that's basic, right?
‫But there is another annotation for this.
‫So if you come over here, you can just say x++
‫and this will do the same thing, basically.
‫So I don't really actually use this a lot
‫but if you see something like this, x++,
‫then just know that it's adding one, like this.
‫As you can see, x is now seven.
‫So, it's basically the same thing by saying that
‫with saying that x is x + 1.
‫In fact, we can do the same thing for subtraction as well,
‫so you can say x--,
‫so it will just subtract one out of x.
‫So if I run this, we will get six
‫at the end of the Logcat, like this.
‫So here you go.
‫Now you see how to add one and subtract one.
‫So let me do something like this,
‫x is x multiplied by five.
‫Do we get the result?
‫Yep, we get the result.
‫So it's multiplied six by five
‫and the current value of x is 30.
‫So, these are some basic operands of mathematics in Java.
‫And most of the time we get more than value, right?
‫For example, we can have this y equal to four.
‫Now I have an x and I have a y,
‫so I can compare them if I want, right?
‫For example, I can just say x is greater than,
‫so this is greater than sign,
‫as you might already know, y.
‫So what if I say that, what will happen?
‫What is x right now?
‫X is 30 at this point, right?
‫So it's definitely greater than y
‫and we get a Boolean out of that.
‫Remember Booleans? Now we get a Boolean.
‫So we can do the same thing with this
‫and we will get a Boolean again,
‫but this time it will be false.
‫And this is kind of basis of the if controls
‫that we're going to see in the next lecture.
‫As you can see, when we compare things, we get Booleans.
‫For example, let me change y to 30, okay?
‫The current value of the x is 30 as well.
‫So if I do this, x is greater than y,
‫then we will get false.
‫Now if I do something like greater than or equal to,
‫like this,
‫so x is greater than or equal to y,
‫so greater than sign and equal sign.
‫Now if I run this, I will get true
‫because now they are both 30,
‫so that's good.
‫So how do we compare if they're actually equal or not?
‫So we do this, x equal to y
‫but with a double equal sign.
‫So if we make one equal sign,
‫it means that just make the current value of x equal to y,
‫but if we do it like this, ==,
‫it means that if they're equal or not.
‫And as you can see in this case,
‫they're actually equal to each other
‫so we get true out of this.
‫So that's cool.
‫So how do we define if they're not equal?
‫So we do it like this, exclamation point,
‫it means negative, okay?
‫!= means it's not equal.
‫So, since they are actually equal to each other,
‫we get a false out of this one, as you can see.
‫There're couple of other operands
‫or couple of other operations that you should know
‫and these are called AND and OR operations.
‫So maybe you have taken some kind of basic philosophy
‫or mathematical courses in high school
‫and maybe you have learned about this.
‫So I'm taking notes over here
‫so that you can see how it's written as well.
‫So this is AND and this is OR.
‫And this sign is a pipe sign.
‫You can do it by Alt and something like question mark
‫or the right next to it on your keyboard.
‫You're gonna have to try it
‫because it differs with international keyboards.
‫However, it's there in your keyboard, okay?
‫So this is pipe sign and it means OR
‫and this is and sign and it means AND.
‫So, how do we use them?
‫For example, if I say x is three AND y is four,
‫now if I create a new z over here with five,
‫then I can compare all three of them.
‫For example, what if I say x is less than y, is it true?
‫Yep, is it true, right?
‫It's true because x is three, y is four right now.
‫It gives me true.
‫And what if I say something like this,
‫x is less than y and I can also add
‫another condition over here with AND operand
‫and I can say y is less than z.
‫So is y is less than z?
‫Yep, it's less than z and x is less than z,
‫so it will give me true.
‫And since I have used this and sign,
‫it means that both side of this AND operand should be true
‫in order to be getting true.
‫So if either of these conditions were not true,
‫then we wouldn't get true out of this equation, okay?
‫Both sides should be true in order to get true.
‫For example, let me do it this way
‫and you will see we will get false,
‫even though x is actually less than y,
‫z is not less than y.
‫But if I do something like this with or sign,
‫then any of the condition should be true
‫and the other condition doesn't matter at all.
‫As you can see, since x is actually less than y,
‫I'm getting true.
‫So, even though it's not true, z is not less than y,
‫I'm getting true because I'm using OR.
‫So either one of these is true,
‫it's good enough for me, I'm gonna get true.
‫So this is the basic difference between AND and OR.
‫In the AND operand, you should have both sides true.
‫In the OR operand, either one of these sides
‫is very good for us.
‫So let's stop here and continue it in the next one.