 Hello guys, so in this video, we are going to learn how this basic program to print hello world works So let's try it out and here it opens now if I press on run You can see the hello world is printed on this screen Now you might be confused why we have put it double slash here Why we're using public main static void system dot out dot print even we are going to learn each of these Thing one by one Now let's see what are comments So these are called as comments So this whole line this whole line is called as comment anything marked with double slash is called as comment So suppose if I mark here also double select then you can call this line also as a comment If I mark here also double slash then you can call this line also as a comment Suppose if I remove this, okay, then you can't call this line as a comment So now we know what to call comment and what not to call a comment now. We'll see what is the use of these comments So the first use of these commit is if you do not want to execute a line of code Then you can make that as a comment So here earlier you can see hello world is printed due to this line was executed Now I don't want this line to execute it So I mark this with double slash and if I click on run This way you can see no output to print. Suppose if I put here like I Copy this and I put here and I make this like This let me 1 2 3 and I again copy this and Again paste it and this time I will make it like 1 1 1 1 and I will comment out this line Now if I run, let's see what happens So you can see only this line was executed this line and this line is not executed because they are made as comments So now we are clear with Why to use comments? So there is one more use which I Haven't explained you so the second use is that if you make a line as a Mostly we make a line as a comment So that if someone else is going to read your code after 10 years He will be able to understand your code more easily So there are two uses first use if you don't want to execute a line and the second to make your code easily understandable Now let's see what is a class. So here you can see This Sony code is called as a class why this is called as a class because this is declared with this class keyword Suppose if I remove this class keyword, then you can't call this Sony code as a class So here this is a class now. Let's have a look on some of the properties of the class So the first property is all the code of the program is written inside the main class Okay, so here is suppose I make this also It's suppose if I make one more class so to make a class I have to write first class keyword and if I make one more class like this So you can't this is not a main class this thing dog is not a main class but Sony code Sony code is a main class Why we have called this as a main class because the file inside which this code might be saved Has the same name as that of the class name Okay, so the name of the class and the name of the file will be seen That's why we are calling this class as a main class Now the property was is that all the code of the program is written inside the main class So here you can see right all of this code. We have written inside the main class Sony code only suppose if I do like this Suppose if if I make another class, okay Now if I do like this and if I come here and I remove this public keyword I Remove like this and I make it like this and I am going to remove This too. Okay. Now. Let's see what happened. So here you can see some error came up So make sure that you That whenever you write a code you write a code inside your main class only Don't write outside of it So this was a second property Now this property the name of the main class and the Java class should be the same So here you can see I have just showed you with this diagram Suppose you make a file with the name Sony code comm Sony code Dot Java and you save a class with the name Sony code and then you execute this well You will not say it suppose if you make the class name as mean dot Java Whatever you want. Just it won't be a Sony code Okay, then mean dot Java and you save a class with the name Sony code and then you run it. You will see error So this is the second rule which you have to remember with the name of the file and the name of your main class should be same Now in this code, let's see. What is this main function does? So the main function is mandatory in every Java program Suppose if I remove this main function, if I make it like MU AIN and if I learn this code Okay, so there's some error coming up. What that error is First I have let me remove this. I'll let me just reload this Just a minute Okay, so suppose if I make it like this, okay and Now if I do so here you can see it gives us this error mean method and not found in class Sony code So make sure whenever you make a Java program, you have a method with the name main So I'll remove that e now the method with the main is there. So we don't see any error Now why we use this main method The reason why we use this main method because the execution flow of every program starts from the main method So whenever the compiler Start executing code of this Sony code class it first come to this main method Then it start goes inside this main method and start executing the flow of the code So this is how main method work The last thing we have in a program which is spending for us is that system.out.println So whenever you want to show some Text on the console like here. I wanted to show hello world So what I just simply did I passed hello world inside double chords Inside into this println function that this println function has printed this hello world on the console So we use println function to print the output on the console So a print is done main is done classes then comments are done Now these things are pending like why we use public why we use static why use void and why we used ARJS as of now just learned that whenever you are making a main method you have to write public static void and String ARJS and whenever you declare a main class make sure you declare it with a public keyword Suppose if you remove this public and you run this you'll get an error. It says as public last not formed So these are the points you have to remember and as we move on in this tutorial I'll explain you each and everything why we are using public while we are using static while we are using void Now we will look what is a variable how to use a variable and how to create a variable So here in this code When this line execute a variable will be created and it will hold a value 20 So let's see how a variable will get created in the memory So when this line execute what happens in RAM, so this yellow part is a RAM in this RAM Memory location this white area is a memory equation will be created in that memory equation a value 20 will be stored as we're Assigning here 20. That's why in this memory equation a 20 is stored. This memory location is called as a variable So this age is not called as a variable this memory location is called as a variable this age is called as an Identifier as you can say the name of the variable So for the sake of simplicity We always called is as a variable but in technical terms age is not a variable It is an identifier or you can say the name of variable now what happened when this piece of code Executed a memory equation is created in a RAM and the memory location is having a value 20 And this memory equation will have some address So let's assume that addresses hash a1 to b4 and this address gets stored in this Identifier or you can say the name of a table now with this code executes what happens First here the value is stored in a variable that is 20 stored in an age variable And here when this value when this piece of code runs The value stored in the RAM is accessed and printed here. So here you can see age current 20 is printed So this is how a variable works and this is how a variable stores a value in a memory Now we are going to discuss What are data types and what are the different kinds of data types? So first let's see what is a data type a data type is a keyword that is used to decide What kind of data can be stored in a variable? so here We have a defined in this variable bar one and here you can see this end This end is a data type that is used to decide what kind of a value can be stored in this variable bar one So let's run this code and see Now here you can see I'm trying to store a fractional value in a variable Bar one as this variable bar one is declared with a inter data type So only a integer type value can be stored now when I run this code You can see a error is raised because we have already defined a variable with an inter data type So we cannot store a fractional value inside in this variable. Now, suppose if I store here a Integer value and if I try to run this code, let's see what happens So here you can see I did not got any error So this is what data type is Now, let's have a look on different kinds of data types So there are basically two types of data type The first data type is a primitive data type and the second data type is non primitive data types now suppose if you want to store a value like two two point four and These kind of value inside a variable then you can use primitive data types So there are basically eight types of primitive data types. Let's look at each of them in detail So first is our byte data type now here in this byte data type The range of number that you can store is from minus 128 to 127 You can store integer only so all these four data types like byte short int and long These all are used to store integer kind of values. These float and double are used to store fractional values So suppose if you want to store a value in a variable that is less than minus 128 and Sorry, that is greater than minus 128 and less than 127 then you can declare a variable with a byte keyword So let's look at one example. So here I have a int variable now here if I try to store minus 220 and if I run this code I Get no error, right? But if I try to store This minus two to two into a byte type variable and if I try to run this code You can see I got error because it Exceeded this limit suppose if I make this as minus 127 and Then I try to run this code. You can see no error got So if you want to store a number in this range, then you can use byte similar cases with short so shortest is used to integer value in this range and Int is used to store a integer value in this ring And similarly a long is used to store integer value in this range Now you might be wondering all these are used to Store integer value then why don't we use long all the time? So the reason why we don't use long all the time Because if you start to use long then it will start to consume large amount of memory your program will consume large amount of RAM That is not good. Your code won't be optimized. So it won't work fast So if you know that your variable is having a value in this range only then better to declare that with a byte And if you know that your variable is not going to exceed this range Then better declare that variable with int. Don't declare with that long or else your code will consume more memory If it consume more memory your code will become slow Now we have seen that these variables will use to store integer type of values Now what we'll do if you want to store a decimal value So suppose if I write here like 4.25 and if I want to store it into a byte variable You can see I got error. I cannot use byte int long and short So if I make here int also and I run this code You can see I again get error if I make this as short and Done this code. I will again get error and similar thing is going to happen with long Here I got error, but if suppose I make here is as float and Then I run this code you can see There is no error Now here you can see I have put it this F. You might wondering why I have put it this F So this is a rule which you should remember Whenever you assign a float value assign a decimal value to a variable that is declared with float keyword Always try to put F at the end or else you will get a error. So suppose if I remove this F From here and then try to run this code. You can see an error is raised, right? So always put a F when you decide when you Try to store a decimal value in a float type variable So this is float now the double so double is also used to store a decimal value Suppose if here I make it as like double do you be a read and for double you don't have to put F It's fine without F2 and you can see I'm able to successfully store a Decimal value. So what is the difference between float and double? So the first difference is float consumes only 4 byte of memory So if you know that your number is going to be short then better use float I'll solve it. I'll use you can go for double So this is the first difference the memory difference the second difference is that in float You have to put F and in case of double there is no F required the third difference is here you can see I have a Decimal value with Around seven numbers after point, but you can see in the output. I'm able to get only five numbers only So this is the point which you have to remember whenever you use float You can store a decimal a number after decimal up to five only only five decimal numbers are allowed But in case of float you can make this up to 15 decimal So this is a third difference Now comes Boolean so suppose if you want to store a true a false value a Boolean value in a variable You have to declare a variable with a Boolean data type and Suppose if you want to store a character enclosed in this single codes Then you have to declare a variable with a charm So this is we are done with primitive data types Now, let's have a look at non-primitive data type So non-primitive data types are just the class name So here all this char Boolean double float long these are not the class names But whenever your variable is declared with class name So here this var 1 is a class name So whenever your variable is declared with a class name Then this class here is called as a non-primitive data type Now why we use these non-primitive data type? Suppose wherever you find these kind of value that if you find a new Keyword after that you find at the name of the class Then you have to declare the variable with that class name only so that you can store the Reference of this object so what is object how object works? You don't have to worry in the coming lectures I am going to explain you what is object how object was as of now just understand this Whenever you find a class name declared with this new keyword You always have to put the class name here also as a non-primitive data type to store Whatever is written by this in this variable So this is all about our primitive data types and non-primitive data types Now we are going to learn about operators. So what are operators in your? While you were studying mathematics You might have studied the operators like plus or minus which are used to perform Edition on two numbers and a subtraction on two numbers in the similar way if Suppose the values are you can see the numbers are stored in variables like here you can see right Like 10 is a stored in variable a and 20 is stored in variable variable b Now you have to perform the addition of these two values that is 10 plus 20. So you can use plus Here like this. So this plus in Java is called as operator So this is what is operator now what this operator is doing This operator is performing the operation on the values stored in these two variables a and p So that is what operator do operator perform the operation on the values stored in the variables So here when I run this code you can see the Here a plus b is equals to 30 so plus operator returns 30 and that will be stored in C And here we print C. So this is what is operator now. There are four types of Major operators that are used in Java So first let's have a look at what are arithmetic operators So arithmetic operators are the operators that are used to perform arithmetic operations Like addition subtraction multiplication division So this plus is used to perform addition operation minus is used to perform subtraction Multiplication division and similarly we have modulo So let's have a look on each one of them here. You can see we have value 13 and 2 Now when you do 13 plus 2 you will get 15 So here I have done x plus y and I got 15 here In the similar way if you do x minus y you will get here 11 And if you do x into y That is 13 into 2 you will get 26 And this is a called as modulo operator What modulo operator do modulo operator returns the remainder Now when you divide 13 by 2 you will get a remainder as 1. That's the reason 1 is here Now here if you divide 12 by 6 you will get as 2 So this is how arithmetic operator works Now we have assignment operator Actually, there are a lot of assignment operators, but this assignment operator is the one which is majorly used So we are going to look into this only assignment operators are used to assign the value To the operand which is at the left So here you can see the value which is stored in variable y is now assigned to variable x Right here you can see Here I have a variable a and this assignment operator what it does it assign this 13 value to this variable a so when I was Trying to access the value from a here here I get as 13 So that's why assignment operators are used Now we have relational operators Relational operators are used to compare the values Here you can see to compare the values stored in variables Now let's look at the example Here you can see I was just checking whether x is greater than y or not And the value stored in x is 8 and the value stored in y is 4 Here what I got here. I got this as true. So what I was doing here I was comparing using this greater than operator I was just comparing whether the value stored in x is greater than y or not So that is why relational operators are used to compare the values. So there are these All relational operators equal to is used to check whether both the values are equal or not This will return True if both the values are not equal if This is used to compare if x is greater if this x is greater than y or not And similarly this is less than and this is greater than or equal to Okay, if suppose both the values are equal then also this will return Turn true and if suppose x is greater than y Then also this will return true And this is vice versa of this So here we are done with rational operators. Now we have logical operators these This and end and this are called as logical operator We call this operator as and operator and we call this operator as or operator Now let's see how these operators work So suppose you pass true here you pass true here And here also you pass true then you will get true and suppose you pass true and you pass false You get false just with end operator. You have to remember one thing if one of the Operand means if one or any one of the side is having false Okay, here also either it is having here false here false are both The false it will return false So to if you want to get true value from this and operator You need to make sure that both the left and the right operand are true or else you will get false And this is our or operator and or operator if one in our operator just Vice inverse of and operator and or operator if only one of the value If one of the operand is true You will get a true value. So here you can see here at least this is true So that's why we got this true and here. This is true. We got true here. This is true. We again got true Here you can see there is no true. That's why we've got as false So this is all about our operators Now we are going to learn about strings in java. So what is a string a string is Character sequence of characters enclosed in double quotes. So here you can see these characters Are enclosed in this double quotes. So this whole is called as a string and here we use A variable which is declared with a string data type to store the reference of this string Now, let's see few functions and operations that are mostly used on string So the first one is length So length is a function that is defined inside this string class So that's why we can use with this dot operator Now what this length function will do length function returns the number of characters Enclosed inside these double quotes as here Tesla have five characters. So that's where you can see this length function has returned five in here So this is what is the use of length Now, let's see plus operator. Now, suppose you want to join two string to get a new string Or you want to concatenate two string to get a new string What you can do you can just put a plus plus operator here and this plus operator will Concatenate two string return a new string and you'll get a new string like this elan musk Now a third Function is Charat now, suppose you want to access the element Of access the elements are I can say exist the characters of this string Then you can use charat function along with the indexes of the character in a string Now suppose you want to access the this element l So first of all you have to calculate the index of this l element the index of this l character is One now when you pass one to this charat function This charat function will return the character present and this One index and what it what is present at this one index that is l. So l will be printed here So charate index one colon l And here one is l is printed now suppose you if you want to print k Then first let's calculate the index of k So the index of k will be like e is at index zero l is at i index one o is at index two n is at index three m is at index four u five s Six and k is at seven So when you pass seven here at charat this will return k So this is what string is and this is Some few important operations and functions related to strings Now let's start with if else and switch statement So these if else and switch statements are called as conditional statements by they are used These conditional statements are used So if you have a need that you want to run a specific piece of code When the condition is met here What happens this code will run only when a is smaller than b And this code will only run when a is greater than b. Let's see this with an example So here first i'll just comment this code and i'll comment this out too. This i also i will comment This also i will comment now i'll run this code Here you can see Both of these lines that is this line and this line got executed and a is smaller than b and a is greater than b is printed Now my requirement is that this line should only run when a is smaller than b and this line should only run when a is greater than b So what i will do i'll just uncomment this So i have placed this conditional statement here And i have placed this conditional statement two in here now i will execute the code So here you can see a is greater than b is printed that is This line that is this line a is greater than b is printed now Suppose i make a is smaller than b that is i if i make this as one let's see what happened So here you can see this line is executed because right now a is smaller than b So this condition code executed So this is how conditional statements work Now let's see what are the different types of conditional statement So there are three types of conditional statement first is f then f else then comes a switch So let's see what is f statement. So this is the normal syntax of f statement This is how you can write the f block and inside here you can write the code Which you want to execute when the condition this condition Is true. So here if the value comes true, then only this code will run So let's see how f block runs Now here what i will do I will simply do like this System.out.println i'll copy this and i will Paste this so now you can see the value written by a equals to b So when i run this code here, you can see This line is executed By this is executed because a equals to b returned true. Here you can see true is printed now what happens if i make this as 2 b equals to 2 Now you can see a equals to b returns false as a equals to b returns false That's why The compiler does not came inside this if block. That's why this line is not executed. So this is how if block works Now let's look how if else statements work So this is the core syntax of a fails statement Here you will pass the boolean condition And if the condition is true this code will execute and if suppose this condition is false then This code will execute. Let's understand with an example So here I open this code Now again, what I will do I'll just copy this and I'll again paste it here I will copy this to and paste here Now if I run this see what happens So a equals to b equals to equals to b returns True as a equals to equals to b returns true So the code inside if block executes and a is equals to b got printed Now what happens when this a equals to equals to b returns false? So for that I'll make this as 2 And now let's see what happens So when this is returning false means here when false comes what happens the code inside else block execute That is a is not equal to b. So from this example You can conclude that when the condition is true The code inside if block execute when the condition is false then the code inside else block execute So this is how if else block works Now let's see a third conditional statement. That is switch statement So which is an alternate approach to if else statement So let's see how if else state how our switch statement works So here's our code Now I executed this score and you can see today is Tuesday got printed So means this line is executed So before we understand this code, let's look at the syntax of this code So this is how the syntax of this code looks like So if this expression If this expression here or this expression is our Tuesday means this a day If this expression is equals to one of the value value one or value two What if the value it is equals to it will execute the code what is what is written here So here you can see as a Tuesday Is equals to this Tuesday So that is why this line of code got executed and today is Tuesday got printed here Suppose here I make this as Monday Here if I make as Monday Now let's see what happens. I forgot to put in And now let's see what happens So here you can see as this Monday match with this Monday That's where this code is executed and today is Monday printed here Now suppose if I make this as Wednesday Let's see what happens So now when I made this as Wednesday, this code is executed And remember one thing you have to always put a break statement after this After the code of this case Now let's see what happens When the condition does not meet any of the conditions So we will understand with This example maybe we are with With this example we are going to understand So let me close this out and I will open this Here you can see I have a day as Friday And you can see if Here also we don't have Friday here also we don't have Friday here also we don't have Friday Now when I execute this let's see which code executes So now execute today is Sunday So means this code got executed So when none of the condition meets then the code present in the default block get executed So this is all about our conditional statements Now let's start with loops So there are two types of loops in Java that are mostly used So first one is for loop and the second one is while loop Let's understand how loops work with this example Now I'll come in this out And this also I'll come in doubt and this also I will come in doubt Now I'll run this code and let's see what happens So here you can see this and this piece of code got executed only once Now let's see what happens when I remove this comment and I will remove this too And I will remove this too And now when I run let's see what happens So here you can see one, two, three, four, five So this piece of code got executed For five times So this happened because of this loop So from this example, we can conclude that loops are used to Execute a piece of code repeatedly Now how these loops work when this loop terminate and how many types of loops are there in Java that's we are going to learn Now I will close this So there are basically two types of loop first is for loop and the second one is while loop So let's first understand the working of for loop So here is a code And now I will run this And this is what the output we got suppose if I remove this Then this will this will run only once So here also for loop is used to repeatedly execute this piece of code Now let's look at the working of this for loop so in this for loop In the first iteration as we have seen that This code executed five times So when this was executed first time means when this was printed, let's see what happened at that point of time So the first iteration This it was executed and this was executed And as the value of i is initialized to zero due to the execution of this line here zero comes and five into zero equals to zero what printed now In the second iteration The value of i is one. So here you can see the value of i is one. So how this became one This code executed at the last at the last here Here this code executed this i equals to zero plus one. So that's why here one came Before I move forward just Want to remind this that this code i equals to zero and i smaller than five this always executed before Before this before this curly braces and this Execute after this curly brace So here also you can see right i equals to zero and i is smaller than five executed before this curly brace And i i plus plus executed after this curly braces So as this executed after this curly braces. So the value of i became One so here you can see the value of i is one Now let's see what happened in second iteration in second iteration as Here we have one is smaller than five So here as we have one smaller than five, this will return true the loop will continue and again at the last We'll get i equals to one plus one that is Two and again here we will get two as again two is a smaller than five. This will return true The loop continues. We again print this Five into two equals to train and here the value of i will become three And this will go on and in this last second iteration. What happens the value of i will become five Now in the value of i is five. What happens? Java will try to come spare is five is smaller than five No, five is not at all smaller than five So this will return false as this written false This loop gets terminated the code inside these curly braces will not at all execute now So this is how a for loop works Now let's see how why loop works before we learn why loop how why loop works Let's see. What is the difference between for loop and why loop? So in for loop We have this i Int i equals to zero inside the curly braces And we have i smaller than five Also inside the curly braces and we have i plus plus also inside the curly braces Sorry, not inside the curly braces inside the parenthesis Now here you can see in why loop only i smaller than five is inside curly braces So this is the major difference that You cannot initialize and you cannot Increment a variable inside the parenthesis of why loop that you have to do outside or inside this while loop So here you can see I have done the initialization of variable i Outside this while loop and increment of variable i inside the while loop not inside the parent inside the parenthesis of this while loop Now let me run this code And see what happens. So as I run this code You will get the output like this now. Let's understand how we got this output So here I have this Now let's see what happened in the first iteration So in the first iteration In the first iteration first this i become equals to zero So the value of i will become equals to zero and here we will get True because zero is smaller than five And we'll get in the output as five into zero equals to zero Now here the value of i will increment and it will become i And the value of i will become one now in the second iteration second iteration again One is smaller than five. Yes one is smaller than five So this will again return to the code inside this will execute the value of i will become equals to two And again Here we'll get true again this code will run and here also again. We will run this Code inside the while loop and this will go on now in the last iteration what happens The value of i will become five now in the value of i is five is five is a smaller than five. No So this smaller than operator will return falls as this will return falls this while loop will terminate So this is how the for loop and while loop works In java, we have two types of statements break and continuous statements These statements are used to Interrupt the loop. So let's first start with break statement Break statement is used if you want to come out of the loop. That means if you want to break the loop Let's see how Now let me open this here when I execute this code You can see break at i Colon three is printed. So when this break is executed this loop The loop got baked So let me just comment out then we'll see how it works Now when I execute this let's see what happens. So i colon zero i colon one two three four it got printed till four Earlier what happened earlier this thing then got printed, right? So means the loop got Terminated when this break keyword is called. So we will learn We'll see how this whole break works. So let me uncomment this And I'll just copy this And let me just run this code once So here's the code with a break statement. So I'll put it here. So in our first iteration what happens I'll just move this up In our first citation this line will execute and here we will get zero and here again, we will get zero So this line of code will not execute at all because zero is Not equals to three and this code will execute here. I'll get zero Due to this i colon zero is printed here And here I again get zero And the value of i will become One Now let's see what happens in second iteration. So in second iteration Here so first of all this line of code will execute only in the first iteration because now we are inside value So that's why this will not execute after first iteration In second iteration what happens here in the at the last of the first iteration We had the value of one as Is one so here we will get as one I'll make this as one And I'll make this as one too. So i equals to equals to three And this is not equals to three. So this code will again not execute and here I have to put again one So that's why I got i colon one and here this will again become one and the value of i will become two Now what happens in case of third iteration? In case of third iteration Here I'll get three. Yes, three is smaller than five. So this condition is true We'll get inside this and I'll put three now three become equals to three So the code inside this if block will execute now when this code execute First of all break at i here. Here we will get as three So it will print break at i color three Now again this loop when it comes to this break statement The loop will terminate as the loop terminates. So this code will not at all print And the compiler earlier it was here after executing this code The call will come to here. So whatever the code you will write after this will execute This code will not at all execute even This while loop will not go to next iteration to So this is how the break statement works Now let's move on and see how continuous statement works So break is used to terminate the loop Now suppose if you wanted to skip a specific iteration of a loop Suppose here you don't want to print i colon one Then in that case you can use continuous statement. Let's see how So I'll close this out and I'll open this code And then we'll understand So first of all I'll just remove this And I'll run the code Without continuous statement. So here you can see this is what my output is and I'll paste this here And now suppose I just uncomment this code And now I will run this Okay, I got some error. I missed something What I missed what I missed so let me Do in this way Control c And just reload this Okay, so here this was our okay. So this thing I can't put it. Let me just comment it out Now I will run this code and see let's what happens. So this is my output with this continuous statement So here you can see I did not printed this I colon three I skipped this code at i equals to three so this Continue I used to skip this code when I this code when i is equal to three due to this I colon three is not at all printed here in the output. Let's see how this continue works I'll copy this I will paste it here And this is our first iteration in our first iteration first or I will get initialized We'll get here zero And as zero is more than five we'll come inside while loop is zero is equal to equal to three Zero is not equal to three. So we will not execute this code. I'll just some comment this code Now Let me move forward Little bit up Now here again, we will get it as zero So that's why I printed it got printed here. I colon zero Now here I again get at zero And this will become the value of I will become equals to zero Sorry equals to one So this is our first iteration. Now, let's see what happens in the second iteration in a second iteration And let me move little bit up And this code will not execute this execute only before We were not into while loop as we came into while loop. This code is not cannot execute Now the value of I here is in the last of the first edition the value of I became one. So here I will put as one One is smaller than five we'll come inside while loop This one is not equals to three will not print this Now here again, we'll make this as one And we will make this as a one two. So this will become Two as here I colon one is one. So we printed I colon one here Now we move to third iteration In third iteration here, this is a third iteration This You can see this was our two in the last of second iteration and make us two two smaller than five we come inside while loop Two is equals equals to three. No, T is not equals to three. So this will return fall this code will not execute And here we will again make this as two And here we will make us two And this will become as three now As here we have two. So that's why we got here I colon two Now again, I will copy this And I'll paste it here and this will become our fourth iteration What the value of I was in the last of third iteration? It was three So I'll make it as three. We'll come inside while loop and here we will get three. Yeah, three is now equals equals to Three So I'll just uncomment this code Okay, and here I'll make this as three This will also become as three. So here the value of I will be Value of I will be four And Now when this continue execute this piece of code when I is equals to three will not at all execute So I will just comment this out Here you can see the only this continue at I is printed I colon three is not printed here So that is how the continue statement works. Now, let's look at a fifth iteration two So for fifth iteration, I'll take this And here you can see the value of I was four. So here again, we'll get as four We'll come inside while loop And it's four equals equals to three. No, again, this code will not execute And this code will execute. That's why we got here I colon four So here we use continue to skip A piece of code at a particular value of I So that is how continue and break statements work Now we are going to learn about arrays in java So to create array, you have to use these curly braces This and this and this is how you can create an array Let's see within code So this is my code Now In this you can see this is how I have created an array using these curly braces So there are some rules while we create an array So what are those rules? Let's look into it. So the for only one rule is there the for the rule is That you should have only one type of element inside an array It can't be like you can have string also here or you can have a double type So if you have created a to store inter type of numbers, then you should have an array which store int only Suppose if I put here like string if I make this as a string And then I run this code you'll get an error Or suppose if I make this as string If I make this as string Then you can store only string type values inside this array I have to remove this And I have to make this as string See now if I run this code, I will not I'm it's still getting error s t r i n g String now, let's see So I did not got any error, but if I make this as like integer and then I run this code Let's see what happened. So here I got error. So whatever you have declared an array with you can have only that kind of elements inside it It's can't be that you can have elements of all different kinds inside the array So this is how you can create an array using curly braces and this is the rule which you have to remember Now let's first understand how to use an array Then we will see what are the different ways to create an array so here If suppose you want to access The element add index Zero so before we move on to index how to use index let's understand what index is So here you can see the element First the first element the element 10 is that position number one So I can write the position. So here I will write the position position I'll just comment this out So the position of element 10 Is one and the position of element 20 is two Similarly of three is three Three 30 is three And that of 40 is four and that of 50 is five Now let me copy this And put it here Now we will see what are indexes Indexes and how it starts In real world We say the position of element 10 is one But actually in java java starts to position these elements in an array starting from zero So here it will position the element zero at Position the element 10 at index zero and Java will position the element 20 at number One Similarly 30 have index of two And four will 40 will have index of four Not four it will have three and 50 will have an index of four So these are called as indexes Indexes are nothing but the position given by Java to these elements in an array Now let's see. So this is how we have created an array And we have stored its friends in this ARR variable And just one more point which I want to remind you whenever you create an array You have to put these square brackets If suppose I remove them and then I run this code you'll get this error But if I put this back and then I run this code I will not get any error. So make sure whenever you Define a variable define it with this Brace square brackets Now if you want to access the element 10, so you have to pass The index of that element like this So here I want to access the first element first element of this ARR array So what is the index of this first element? The index of this first element is zero So I passed here zero and I got here as 10 Now I want to access this last element So what I have to do first I have to calculate the index of this last element So the index of this last element is four and when I pass this four inside this ARR Then I get in return the element which is at the last position So the element at the the index four is 50. So I got that So this is how you can create an array and this is how you can access the elements of an array Now let's see How You can create an array using new keyword. So this is also one more way to create an array So I'll just remove this Because this is no more required and I will just comment out Here I have commented out now. Let's see a different way So here this has to be five Now if I run this code you can see I'm still able to access the elements of an array So it means I have created the same array which I have created here using this I have created using this method