Welcome to this Java course for beginners. This course will help you acquire essential Java programming skills quickly and effectively. Starting from absolute scratch, you'll learn everything you need to know from setting up your tools to mastering the core components of Java 17. Whether you're aspiring to land your first programming job, or just adding another language to your coding repertoire. This course promises value at every step. Alex is an experienced course creator and he does a great job teaching the basics of Java in this course. Hello, my name is Alex and I will be an instructor in this course. In this course you'll learn Java, which is one of the most popular programming languages in the world, used by many big companies. So if you want to get a job or to build an app, Java should be your choice. For who is this course? This course is for complete beginners and also for experienced programmers who want to add a new language to their skills. So let's get started. Now it's time to download and install an IDE and for this course I'll use an IDE called IntelliJ IDE, which is an IDE made by a company called JetBrains. Now you may be wondering what is an IDE? An IDE stands for an Integrated Development Environment and is basically the tool that you're going to use to write our code in. An IntelliJ IDE is like a text editor but a very sophisticated one because it has a lot of features like highlighting our code, showing real-time errors and suggestions. You can run and compile your code just by a few clicks. In other words, it's making the process of writing code easier and better. Therefore, let's download IntelliJ IDE. So I'm going to open my browser, you should open your browser. And in the search tab I will type IntelliJ IDE, press enter. We click here on this link, download IntelliJ IDE because this is going to take us on the downloading page. And here you'll see two options, Ultimate, which is paid but has more features and Community which is free but has less features. And this is enough for our purposes. Also, you may have noticed that Windows is highlighted here. This is because the IntelliJ that we are going to download here is for Windows. But if you have Mac or Linux, you should download the particular version for your system. Now, I want you to pay attention at the latest version when I'm currently recording this video is. So it's 22.2.3. And if you look at the system requirements for this version, you need to have a 64-bit version of Windows in order for this version of IntelliJ IDE to work. Otherwise, it will not work. Now, let's download IntelliJ IDE. And now the downloading is starting on the top right-hand side. And if you have a different browser, you will see the downloading starting in a different place. Once the downloading is finished, just open this file. I'm going to close the browser. And now the installation will start. Now it's asking us if you already have to make changes to our device. Click on Yes. Here we need to click on Next. And this is the folder location where IntelliJ is going to be installed. You can change this location by clicking on Browse. And it will show you the folders where you can put IntelliJ ID. But I'm going to keep the default location. So I'm going to click on Next. Here I can create a desktop shortcut. So I'm going to check this to create a desktop shortcut. And I'm going to click on Next. And then I'm going to click on Install. And now IntelliJ ID is going to be installed. And as you can see on the left-hand side here, it already appeared. All right. Now the installation is finished. Just click on this box to run IntelliJ ID Comment Edition and click on Finish. And now if you see this window popping up, this is because it wants to import the previous settings of the previous installation of IntelliJ ID. But most of you will not have a previous installation of IntelliJ ID. This will be the first time when you install IntelliJ ID. So you need to click Do Not Import Settings and click on OK. And now IntelliJ ID is going to start. All right. So this is the welcome window of IntelliJ ID. And this is the place from which you're going to create all of our projects. Now let's go on the left-hand side where it says Customize, click. And we click here where it says Color Team. And we click on this drop-up menu. And from here, I'm going to select IntelliJ light because this is better for tutorials. But you can keep the dark team if you want. Also, I'll show you in a separate video how to add more teams, not just the teams provided by IntelliJ ID. Let's go back on the left-hand side, click on Projects. Let's click on New Project because we need to configure now the JDK. All right. As you can see here, it says that there is no SDK. And what that means is that, first, what is the SDK? SDK stands for Software Development Kit. And as you can see here, it says JDK. And JDK stands for Java Development Kit. And the SDK is basically the Java Development Kit, however you want to call it. What this thing is, this contains the tools that we need to, for our app to be able to run and compile our code. And this JDK contains those tools. So you need to click here where it says Download JDK. And the latest version, when you click on the Download JDK, it opens this window and you have version, vendor, and location. And for the version, we're going to choose version 17. And you now may be wondering why version 17 because the latest version is 19. This is because the version 17 is the version which has long-term support. And that means that it will receive bug fixes and updates for several lists to come without you needing to switch to any new version whenever it's released. Next, we have the vendor. And this is the company which provides the SDK. And I'm going to choose Amazon Coretto because it's a good vendor. Next, we have the location where the JDK is going to be installed. And you're going to remember this location. And then I'm going to click on Download and it's going to add the JDK. Because without the JDK, the IntelliJ ID, it's like an empty text editor. It doesn't have the tools to write our code and to compile our code or to run our code. So this is what the JDK is. It's like a packet with all the tools that IntelliJ ID needs in order to be able to write code and to run our code. Now I'm going to click on Download. And as you can see, it will download and it will be added automatically here. All right, so we have the JDK set up here. It's Amazon Coretto 17. And now we're ready to create our first project. But we're going to create our first project in the next video. So I'm going to click on Cancel here. And see you in the next video. All right, now it's time to create our first program. And there is a tradition in programming that our first program should be to output the text hello world in the console. And this is what you're going to do in this video. Therefore, I'm going to open IntelliJ ID. You should open your ID. Click on Create New Project on the plus button. And first to have the name and the name of the project, if it has multiple words, every word should start with a capital letter and you should not have white spaces. This way of naming is called Pascal case. So I'm going to type hello and with an upper case letter world because we have two words. For the language, you select Java for the build system IntelliJ. And as you can see here, it says there is no SDK. But if I click here, as you can see down here, it says detected SDK. So it detected the JDK that we installed in our previous video. And this will probably be the same for you. And if for whatever reason, it's not saying detect the SDKs, just go to our JDK and go to the folder where the JDK is and add the JDK here. But probably it will detect the JDK and you'll have the JDK down here, like I have. So I'm going to click there to have the JDK added. Then I'm going to click on create and our project is going to be created. Let's increase this. And as you can see, our project is creating, we have something on the left hand side down here, it's working. So we wait a little bit to set up the things. Alright, now our project is ready. And I want to focus on the left hand side. And this thing on the left hand side is called project pane. And here, what we are particularly interested is this src folder. So click on this greater arrow in front of src. And here we have this thing main. This is a class, we'll see what classes are in the future videos, not now. What you need to do here is double click on this main. And that is going to open this and you'll see some code here have this thing public class main then have this probably start to avoid main strings. We're going to talk about what is that and as you can see it also has this system that how that print line hello world. And if you run now this code that is going to be out within the console, but let's do it ourselves. So to output something in the console, we simply type here system that out that print line. And while we are typing IntelliJ ID is given us suggestions and saying system when I put that is saying Do you mean print line saying that? Yes. So yes, if you want to fill in that for you, so if we press enter, it will fill in that for you. And inside the parenthesis of the print line, I'm going to put double quotation, double or double pair of quotation marks. And the text that I want to be output in the console hello, in this case world. And very important is to have a semicolon at the end of the code because you don't put a if you don't put a semicolon, as you can see here, you have an underlying and it says that expect a semicolon. So you need to put a semicolon. So put semicolon. Now to run our program to see the output in the console, we can do it in two ways. We can right click inside the class, we're going to see what classes are. And we can click here run main, or you can click on this run button, which is up here on the top right hand side corner. So let's run it from here. Now it will open the console and it will output the text hello world. All right, so it opened the console and have hello world. Let's put an exclamation mark there. Let's run it again. And we have hello world. So what this thing does is takes the input that is passed here, and it will output in the console. And if I remove one of the quotation marks, look what happens. I have an error, because we need to put double quotation marks in order to work. So if I put here a single quotation mark, again, it will not work. You need to have double quotation marks around the text that you want to be outputting in the console. And this entire line of code, it's only job is to output whatever you pass inside the parentheses of it. In this case, hello world, but you can change this text. We can put here hello Alex, or type your name there. So if you run this, as you can see, it will say, wait, it will say hello Alex. So now it's printing hello Alex. And this whole thing that we have here, it's called a function. And we'll see what functions are in the future video. But a function simply is a collection of code grouped together, which can do a specific task. In this case, our function can do the specific task to output in the console this takes hello world. You type system dot out dot print line parentheses. Inside the parentheses, you put a double pair of quotation marks and the text that you want to be out with. And it's going to output that in the console. And in the future videos, because as you can see, we have this public started void, man, we have these strings, we have those square brackets, we're going to see what all of those are in the next videos. But for now, we create our first program, we output in the console hello world, and everything works fine. So now I'm going to end the video and see you in the next video. So as I said in the previous video, in this video, I will explain to you what all these code means. So first to have as you can see those public class and have again public and have static and void and all of those as you can see, they are colored in blue. And they are colored in blue, because this is the way in which IntelliJ is telling us to us that they are keywords. And a keyword is a reserve word which has a very specific meaning, which can not be used in other contexts than the context of a keyword. So first we have public and this is called an access modifier. So what this public is going to do, whatever comes after the public, it will be publicly accessible what this is what this public means. Next, we have class and we'll see what classes are in the future. But for now we need to know that every function because down here we have a function, every function that we use in Java has to be part of a class. So we have public the access modifier. So other parts of the code can access this class because it's public. Then we have the keyword class, which creates a class. And then we have the name of the class, the name of the class is main. Next, we have curly braces, as you can see, and the curly braces are used to create a block of code. And a block of code is as the name says, a block which contains lines of code. And the block of code begins here and it ends here. It begins with an opening curly brace and with a closing curly brace. And next down here we have again public but now we have public and we have static and void. And I'm not going to explain to you what static is for now because I will explain to you this in a future video because now I can't because it will make things too complicated. So we have public again for the function. And what this means is that we can access this function from other parts of the code because it's publicly so it's public. So this is also an access modifier. Then we have static. I'm going to explain to you in the future videos what this is. And then we have void. And this signifies the return type of this function that we have here, the main function. So what we're saying here is that we have a function which returns nothing. This is what void means. And this function main, as you can see, it's inside the class because all the code that you create in Java has to be part of a class. So this is why we have main curly braces and inside the block of the main we have the function. So the function is inside the block of the main. Now, next we have the name of the function. And the name of the function is main. And this function main, as you'll see, you can create your own function. But this is a special function because this is the entry point of your app. So every program that you create has to have a main function. Otherwise, the program will not work. So look what happens if I change the name of the function from main to A. And look what happens with the play button here and with the play button here, which we can use to run our code. So if I put main A, they both disappeared. So this is disabled and now this disappeared. Why? Because now we don't have an entry point. And when the Java compiler tries to run our code, it looks specifically for the main function to execute our code. And next we have parenthesis and we have the string, we have square brackets and arcs. And what we have here is called the parameter. Again, all of this is going to be explained in different chapters at the correct time, but not now. And then we have again curly braces. So we define now again a block of code. And inside this block of code, we have our simple statement. A statement is basically a complete unit of execution. So it's something which can be executed. This is what a statement is. So we have the statement to output this text in the console. And this is part, as you can see, it's inside the block of the main. So the block of the main starts here with the opening curly brace and ends with the closing curly brace. But this function, as you can see, it's part of the class, of the block of the main class. Because if I put this outside, let me show you actually, if I put this outside of the main, look what happens. So let's take it. Let's go outside the block of the main. So outside the curly brace, let's put it here. Now we have an error. And it says public start avoid main and have this class main. So it's telling us that we should put this inside the class. So if I copy this now, and if I paste it here, now everything was fine because all the code, all the functions, as you'll see, have to be in a class in Java. And then we have our simple line of code, which outputs Hello Alex in the console. So this is how all of this works. Again, if you feel confused by this, don't be because at the appropriate time you'll, I will explain each individual thing in great detail. For now, all we need to know is that you need to have this class main, you need to have this function main in order for your programs to work because all the code that you're going to write is going to be called from the main function, from the main function that we have here. And I didn't talk about this, this is called a parameter because functions can take input and can work with it. But more on that later when you're going to talk about function, function specifically. So this our discussion about what all of this code means. And again, don't, don't be, if you feel confused, it's normal. And if you have questions, just ask me and I will happy answer you. And I will end the video now and see you in the next video. So in the last video, we create our first program and it was a simple program. We just outputted the text Hello Word in the console. And if you want to make your program to do something useful, you need to store data. And to store data, you need to use variables. Therefore, let's create a new project. Let's call it variables. For the link, we select Java for the build system IntelliJ. Make sure to have the JDK selected here. And also make sure to make sure to have this add sample code. And this is going to add the class main and the main function for us. So let's click on create. All right, so now our project is created. If I double click on the class main, it will open the file for me. Now, let's pull this on the next line. Now, what we have here is the code that we had previously. And that is to output the text Hello Word in the console. And if you run this, you'll see outputted Hello Word in the console. All right, so the console opened and we have Hello Word. And of course, you can change this text to print something else. Let's say Hello Alex or type your name there. So if you run this, now it will output Hello Alex. Right, so we have Hello Alex. Now, the problem with this is let's say that I duplicate this line of code a few times. And I run this code now. Now it will output Hello Alex multiple times. So as you can see, it outputs in the console Hello Alex multiple times. And let's say that I want to change the value of Alex to a different name to put here Christian, let's say. In that case, we have to go in the parentheses of all the systems that are that print line. And we have to change the Alex in all the places. And a better way to do this will be to have something in which you can store Alex. And to call that in all the places where you want to use Alex, and when you want to change this value changes value once where the value is declared. And it's going to be reflected in all the places where it's called. And that is a variable. And we're going to look at the first type of variable, which is a string. And a string is a variable which can store text. So I'll type here string. Let's call it name equals, and we put double pair of quotation marks, Alex, and semicolon, of course. Now what I will do, I'll delete Alex from here. And I will, I will put hero plus, and I will I now I will call the variable name here. So I will type here name. And as I was while I am typing, you have a suggestion. And say it's saying, do you mean this V for variable name, which is of type string, which means that is storing text? And I'm going to say yes, press enter. So now if I delete those lines of code, not not all of them, if I delete only those lines of code, and if I press Ctrl D multiple times, now if you run this, we get hello, Alex, hello, Alex, hello, Alex, hello, Alex. And now we found to change the value of because because you know what we're doing here, we are outputting something in the console and we're saying hello, plus, so we are concatenating. This is this is what this this is how it is called, we are concatenating some string to some to some to some other string. So we're adding this this variable, which has the text Alex in it to the to the text hello. Now, if you want to change the value of Alex, you can go where to declare the variable and decide the double pair of quotation marks, I will type, let's say Christian. And now when I run this, it will be reflected in all the places where the variable is used, as you can see. So so now we're saying Hello, Christian, and all the places where where where the variable is used. So this is and this this type of variable string can only store text. So if I try to put here a number, let's say so let's delete the quotation marks, and I put three here, I can't because because so if I put even if I put semi colonist underlining and read and saying, require type string meaning text, and you provide it in which is a number. So this this string is a data type and data type means simply what type of data you can store what this is what data types data type mean means. So this string variable is so so or this variable name is of type string. And that means that you can put only text in it, you cannot put numbers to put numbers, we need to use another type of variable. So let's put here again, Alex, or let's put Christian. Now, let's say that I want to also output the age of this person. To do that, as you saw, we cannot put the variable inside the the the variable name because this of type string, what you need to do is to go to the next line, and we need to type here int. So now we are declaring a different type of variable. So now we're creating a different container, if you want, if you want to think about this like this, we create a different container in which we can put now num numbers. So with string, you can put only text in your variable, as you can see here. And now with int, you can put only numbers, whole numbers, and I will type here a number for the name of the variable. So first, we first we define the type int, the name of the variable number, and I'm going to put here equals, let's say 23. And now we have no errors, let's just put semicolon here. Now, let's also put here some more text. So let's put plus quotation marks, let's put a dot and let's say your your age is. And now let's call our variable. So let's, so inside the parenthesis, but outside the quotation marks, I will put plus, and I'll type here number. And let's delete those lines, of course, to duplicate this code again. So let's, so let's let it let you like this for now. So now if you run this, we have Hello, Christian, your age is 23. And let's put a space here to make it look more beautiful. So get Hello, Christian, your age is 23. So now we are concatenating this number to our string here that we have here. So this is what this plus is doing is taking this value and it's adding that value to in a way in what it is actually doing is converting this number in a text. And it's printing your age is 23. And then and then we have Hello, Alex, your age is 23. And we did this by using different types of variables. And as you'll see, there are other data types of variables that we can use to store data. But this these are the most common use variables, the most common use type of variables that you're going to use. So we have string for text. And we have int, which is the abbreviation for integer. And we have the name number and input the value 23. So this is our this is our introduction discussion about variables and see you in the next videos, we're going to look at other types of variables or other types of data that you can put in variables. So see you in the next video. Now it's time to look at the next data types that you can use in Java. And by data types, I mean, different type of data that can be stored in variables. And we're going to look specifically at two more data types for storing whole numbers. And we also want to look more closely at the int data type. So let's delete this code. Let's also delete the string variable. Now, what is an int? We know that an int is a type of variable which can store whole numbers, but how big the whole numbers can be so we can put anything here, actually, that we cannot put any number you want, there is a minimum and maximum value which can be stored in an integer data type. Again, integer data type is used for storing whole numbers. So if you put here 22.2, you will have an underline because now we no longer have a whole number, you have a number with a fractional part. So let's delete that. And now, to get the maximum value which can be stored in an int, we type integer with uppercase i, dot, and we type max value. And this line of code that is here, integer dot max value, we're going to talk about in the future video what is this. But for now, this is going to give us the maximum value which can be stored specifically in an int, in an integer data type. So I'll type here int max. And there is also a minimum value which can be stored in an int. So I'll type int min equals, I'll type again integer, dot, and I'll type min value and semicolon. Now, down here, I will add a print and system dot out dot print line. And I will print the minimum value and the maximum value. So I'll type here, but let's say that I type here simply, I put double quotation marks and I type max. What do you think will be the output? So if you run this, we get the text max because whatever you put inside the double quotation mark is considered as text as string. So it's not a variable which contains a value. So let's delete this. Let's put again double quotation marks and let's type the maximum value for an int equals and we're going to type plus and we're going to type our max, our max variable from above. Next, I'll press Ctrl D and I'll type here the minimum value. And here, I will change it to min. So I'll put here min. Now, if you run this, you get the maximum value for an int is you have this big number 2,147,000,000 and so on. And then we have the minimum value is minus 2,147,000,000 and so on. So those are the minimum and maximum values can be stored in an integer. If you try to put a number which is bigger than that, you'll end up with an error. So if I try to put here, let's put parenthesis here to make it more clear and I put max plus one. Look what happens. We get the minimum value output now because it's trying to fit, it's trying to put this number which is the maximum number plus plus one. It's trying to output that in the console and it couldn't and because of that, it outputted the minimum value. So let me show you more specifically how this error is called. So let's delete this, let's delete also. So let's put here plus one. So now we have a number bigger than the maximum value because you had to move on to it. And now if you hover over here and every time you see something gray out or it's color, that means the IntelliJ ID wants to tell you something. And here it's saying numeric overflow in expression. So it's saying in other words, hey, you cannot put a number bigger than the maximum value which can be stored in an integer. And if you do that, I will overflow and by overflow means that it will try to put that value in an integer but it's not going to be able and it's going to output the minimum value. So let's delete the one from it, from there. And now let's go down here and let's create another type of variable. Let's create now a byte. So we type byte and let's call this byte max value. I am calling byte max value because if I type here max, we'll have two variables which have the same name. And you can't have this because if you want to call one of the variables, the compiler or the IntelliJ ID does not know about which variable you're talking about. So let's call this max byte value. And now we'll get the maximum which the value which can be stored in a byte. So we're going to type here byte that max value, then I will press control, I'm going to put semicolon, I will press control D, control D. And I will change this to min byte value. So min byte value. Let's put min and let's change this to min. Min byte, min byte value. And this is again is going to return us the maximum value which can be stored in a byte and the minimum value which can be stored in a byte. So if you run this, actually we get nothing because you need to put something in the console. So let's copy those two that we have here. Let's paste it below. And let's change the maximum value for a byte. And here for a byte also. Let's call all variables. And as you can see, they are gray out now because this is, if you hover over, it says that variable max byte value is never used. So whenever you see something colored or gray out, that means that IntelliJ is telling you something. So let's call our variable here. So let's type max byte value and min byte value, so min byte value. Now if you run this, we get the maximum byte value is 127 and the minimum byte value is minus 128. And this is considered, those min and max for byte are considerably smaller than the Int. So the Int data type is much bigger than the byte. And there is another data type which is bigger than the integer data type. And we're going to look at that now. So let's look at the next data type which is bigger than an integer and that is called a long. So let's go down here. I will type long, so this is how we declare it, long. And next I'll give it a name. Let's say my max long value equals, and I will type here long that max value semicolon. And I'll type again long min long value equals long that min value semicolon. Now let's output in the console the minimum and the maximum value which can be stored in a long. So I'll type here system dot out dot print line. And I will type here or simply long or let's type long max value equals and put a space plus max long value. Control D and let's change to here should be long not log. Long long and let's change this to min. Now if you run this, as you can see the maximum value which can be stored in a long is much bigger than the integer and I don't know how to read this number. And this is the maximum number which can be stored in a long and this is the minimum value which can be stored in a long. But let me show you something interesting. So look what happens if I go down here. So I'll go down here with the code and I will create a variable also long called let's call it my number. And let's say that I try to put here a number which is let's put the maximum value which can be stored in an int. Let's put it inside the my long variable. So let's put semicolon. Okay so everything works fine now. But now if I increase this by one, look what happens. I get an error. And now you may be wondering hey but this number that we have here is much smaller than the number that can be stored in a long. So why you get an error? And this is the important part. This happens because the assume type which when you type literally a value when you type a number is an int. So this is considered to be an integer. This is why you have an error because if you have a rubber it says integer number too large. In order for this literal value because this is called a literal. And it's a literal because we type this ourselves directly here. And it will treat this as an integer. So no matter what we try to do it will always be an integer. To be treated as a long and to fit in a long we need to put L suffix at the end. So I put L. Now everything works fine. But can also put uppercase L. And sometimes it's good to use uppercase L to not be mistaken for the lower case L to not be mistaken with one. So this way you should use uppercase L. And now if you run this actually as you can see the error is appeared. And now everything works fine. All right. So those are the data types for storing whole numbers. In the next video we're going to look at the other data types called floating point data types. And with those floating data types we're going to store fraction numbers which have a fractional part. So see you in the next video. Now it's time to look at the next data type that you can use for storing whole numbers. And that is a short. And to declare a short variable just type short. I'm going to call it max. I'm going to put equals and then I'm going to type here short uppercase letter that marks value semicolon. Then I'll type short mean equals and here we're going to type short that mean value semicolon. Now I'll type here max that and look what I can do. I can put max.sout and it's going to print in the console the maximum values and it will generate the system that out the print line for us. And it will put the variable as parameter for our function. So if I press now enter as you can see it added sout. It's added our max variable inside the print line. Okay then I'll type here mean again that out sout sorry and now we're going to print the minimum value. And let's put a text before. So let's put some text here. Let's say max max short value equals plus max then mean short value plus and here we will put question mark plus mean. So let's put an equals here. So now if I run this. If the maximum short value is 32,07767 and the minimum for value is minus 32,07768. So those are the minimum maximum value that can be stored in a short. And depending on what you want to do you will use short value if you need a specific scenario. So now I'm going to end this video and see you in the next video. Now it's time to look at the next two data types for storing numbers more specifically for storing numbers with a fractional part. And those are called floating point numbers. And we have two types here float and double. And they differ in the first they differ in the size the float has a size of 32 bits and double has a size of 64 bits and and consequently a length of 64. And they differ in the precision. Double has a bigger precision than a float. And but first let me show you a problem with the code that I typed in the previous video. And the problem is that I forgot to call the mean long value in our code. What I did is that I called my log long value my max long value two times. So let's change this to mean long value. And now now everything will be fine. So now if you run this code. Now we have our minimum long value. All right, let's close this. And let's delete this code because you don't need this code. Now, to create a floating floating point now a number, we're going to use further float, we're going to type float. This is the keyword. Let's call it number equals and here I'm going to put 3.14, 3.14. Now if I put semi colon, I have an error. I have an underline and it says the required type float provided double. So we have a similar problem with the whole numbers where the assumed type is an int. Here with the floating point number, the assumed number is a double. So if you don't put an F to treat this as a float, it will think that it's a double. So if I delete the F, as you can see, it's thinking that it's a double. But if I put an F at the end, it will, it will treat it as it will treat it and it will be a float because you have a number as you can see it says float. Now let's create a double. And I will type here double number two, let's say, in a real app, you should give more discrete names. And generally, you should give a more descriptive name for your variables. And I will type here 2.0. That's all and semi colon. And everything will work fine. Now let's see what is the minimum and maximum values. And let's also, by doing this, see the precision of our floating and point of our float and double types. So I will type here first float. Let's delete the code that we have above. Let's call it max, max float value equals float again, that max value, semi colon. Let's press Ctrl D, let's change this to min. And let's change here to min. Let's add the system that out that print so S, the uppercase dot out dot print line. And I'm going to type maximum float number equals, and I'm going to put a space plus. And I'm going to type here when I refer our variable max float. Now I'm going to press Ctrl D. But now we need to be careful here to call our variables, not like in the previous example where I forgot. Let's type here minimum float number. And let's type here min. Now let's do the same thing for the double. So I'll type here double max double value equals again, we type double dot max value, I'm going to press Ctrl D, change this to min. And let's change this to min. And let's copy this code. Let's paste it here below. And let's change this to double. Here to double. And let's change this to the max double. And min double here. Now if you run this code, you get an output maximum float number. And we have this precision, this is the precision of the floating point number. And this is the precision of the double floating point type, for the type of double. As you can see, the precision for the double is much bigger than the precision of a float. And when to use one or the other, it depends on the scenario. If you need more precision, use double. If you don't need a lot of precision, you can use float. So this is our discussion about floating point numbers, about float and double, and see you in the next video. So far in our videos, we've only dealt with data types, which are store numbers, whole numbers, or floating point numbers. And now it's time to look at two different data types, and that is the char and the boolean data type. So I'll delete this code because I don't need this code. And the char data type, we're going to start with the char data type. You create it by typing char. You give a name like all variables. I'm going to call it letter. And in a char data type, you can store only one element, only one character. So I can put here, and we don't put double quotation marks, you put a single quotation marks, and you put our character that we want to store in our char letter. So we put A. Now if I add here a system.out.print, I'm going to type letter. Now this is going to print the letter A. So if you run this, as you can see, we have output in the console letter A. So this is the char data type. And you may be wondering, where is this useful? This can be useful in scenarios we say that you want to get the last key that was pressed by a user. You can use, in that case, char data type because it's good for that scenario. And next, let's look at the char data type. You cannot put multiple characters here. So if I put multiple characters, I have immediately an underlying says too many characters in a character literal convert to a string. So this is very important to have only one character in a char. In a char, you can store only one character. Next, the next data type that you can use is Boolean. And a Boolean data type can have only two values, true or false. And you're going to see Boolean data types used everywhere in your code. And usually you declare the name of the variable which is of type Boolean with ease. So ease active or ease playing or ease raining. So this is how it declared the Boolean variable. This is how it declared the names for the Boolean variables. So I'll type here ease active. And this I will type in camel case. And camel case means that the first word starts with a lowercase letter. And the next word starts with capital letter. So I'm going to type here is active. And I'm going to put equals. And now in this Boolean data type, you can put either true or false. Now if I put true and I go down here, let's put semicolon because it's expecting us to put a semicolon there. So if I type here system dot out dot print line, and the print is active, it's going to output in the console true because our Boolean variable has the value true. As you can see, you have a intro, if I put false, if I run the code now, we get false because now our variable itself has the value false. So this is the Boolean data type. And this is very, very useful in your code, as you'll see, you will use it in almost any type, any piece of code that you're going to write, you are going to deal with Boolean data types. So these are the data types that you can use in Java. And except in string, those, the other data types that we looked at, that we looked at, except in the string data type, are called primitive data types. And this has to do with how they are stored in memory. So I'm going to end this video now and see you in the next video. Now it's time to look at operations. And in Java, we have some operations that you can perform. And for that, I will create two variables. The first one is going to be an int is going to be called num one, and I will assign five to it semicolon. And then the next one is also going to be an int. And this is going to be going to have the value num two, and it's going to have the value three. Now, the first operation that we can do, we can type here print system. I wonder if there is not a shortcut to types, let me see, see, oh, no. So system dot out dot print line. So now we can first add those numbers. So I can add num one plus num two. So I can add those numbers. This is the first operation that we can do. So we get eight, because five was reset. Next, we can subtract. So I can put here num one minus num two. So we have two. Next, we can multiply. So I'm going to press Ctrl D. And to multiply with the asterisk sign. So now if I run this, you'll see five times three. And you're going to see 15. Okay, I'm going to press Ctrl D, we can also divide. So we can divide the input slash and can divide five by three. And it gave us five divided by three gave us one. So it's not showing the fractional part in order to show the fractional part, you need to declare one of the variables as a float key point number. So let's change this to float. Let's put on f here. Let's change this also to float to see how the result of the division looks. So if you look now, now I have 1.66. And now we're using float. So for our, for our, let me see if I put only in here and float there, see if we still get the decimal part. So we still get the decimal part because one of the number is float and the entire expression. So the expression or expression is something which returns a value. In this case, num divided by two is an expression because it returns the result, which is 1.666. And you can also check to see what if something is an expression by typing, I think shift Ctrl P, and if you click on this, so you have two options here. You can select num one or num one divided by num two. And this shift Ctrl P, this shortcut allows you to see what num one divided by num two is, what is a float, is an in. So if you press enter, as you can see, we have this pop up, which says float. So this entire expression is a float. It's returning a floating point number, which is this number down here, 1.666. Okay, but let's change it to a double to see because I said that a double has a bigger precision. So let's change it to a double. So let's delete that and let's run our code now. All right, so now we have 1.666. So it's much, the precision is bigger than the precision of the float. So this is good to have in mind. Let's change this back to int. Now one operator, which is because those are operators, and the thing which does the operation is called operator. The ones on each of the operation, it's applied respectively, num one, num two, are called operands. So this is simply their name. So the operands are the ones on which the operation is performed. The thing which performs the operation is called the operator. So I'm going to type down here, system.out, dot print line. And I will type here, and now I'm going to introduce, I will introduce an operator which is not so well known, known as outside the programming context. So I'm going to type modulus. This is how it's called modulus. And it's a per certain sign, per certain sign, three. And what this five modulus three is going to give us is the remainder. So it's going to, it's going to, it was going to give us the remainder of five divided by three. So if you run this, as you can see, we have two. So this is the remainder, five divided by three, and we have the remainder two. So this, this per certain sign is given as the remainder. So for, for the, but why I type five divided by three, let's type num one divided by num two. I don't know why I typed that, but it's okay. It's still the same thing. Only that previously I was typing the value, values literally there. Now, another thing that you can do is let's, let's press control D. And let's change this to, let's say plus. And let's put here times, let's say, or instead of time, actually let's put times four, four. So we have num one plus num two times four. So now if you run this, we get 17 because it first is doing the multiplication, which is three times four, which is 12. And then it adds five to it. And, and that is 17. And as you can see, the multiplication is done for the first because multiplication has precedence over the addition, but you can put, you can change the order of operation by putting parenthesis around the expression that you want, that you want to have it evaluated first. So I'm going to put parenthesis around num one and num two. So now we have five plus three, which is eight times four. So now if you run this, we get 32 now because now it's doing first operation inside the parenthesis. And then there is multi, multiply the result by four. All right, so those are the operations that you can do in, in Java, there is also something which is called abbreviation. So what you can do, let's say I can declare another variable here. So I'll type here and let's actually declare it down here. And let's call it my number equals to zero. What we can do here, I can type here my number equals my number plus one. And this, this will add basically to our number. This mathematically, this is not correct because you say my number is equal to my number plus one. But what we're saying here is what we are adding to my number one, and then we store the value in my number. And there is a short over way of writing this, we can write this in the following way. So we can delete this. And we can put here num, num my number plus equals one. And it's the same thing. Let's put semicolon. And we can do the same thing for the, for the other operation as well. So and we can put whatever number you want here. So you can put here four or so whatever number you want, you can put here. And those are abbreviation. So let's change this to, let's say, here multiplication, division, let's press Ctrl D. And let's also use modulus. And let's add a system dot o dot print between all of them to output the value in the console system dot o dot print my number. And let's do the same thing for the next one. So I'm going to copy this line of code. So let's copy this, Ctrl C, let's put a space, paste, space, spaced, again, a space, and paste. All right, so now if you run this, all right, so get in the output for and then get zero, zero, zero and zero. And we are getting this because first we declare this variable my number and assign zero to it. After that, we add to my number to the value zero, four. So I have now in my number the value four. On the next line, we are subtracting from my number, which has the value four, four, and that is going to give us zero. Then we're going to multiply four by zero and it's going to give us zero. So my number now also has the value zero, then we're going to divide by four and we're going to divide my number, which has zero. So we're going to return zero. And then we're going to take modulus four. So we take zero modulus four, and that is going to give us zero. So this is why we get four, zero, zero, zero in the output. Now, you can also increment your variable just by one using what is called postfix and prefix incrementation. And to show you how that works, I'm going to type here my number. Let's type down here and then let's assign it. Let's put a value of zero. Actually, it already has zero, but anyway, let's reassign zero to it. And now if I add a print line here, so if I add system.out.print, and let's say that I want to increment my number by one, what I can do is I can type my number. And this is called postfix incrementation, because we are incrementing at the end of the variable. So we are we're typing here plus plus. So now if you run this, we get zero. And now you may be wondering why we get zero, because as I said, I said previously that this is it's incrementing the value by one. Yes, this is incrementing the value by one, but it's incrementing with first outputs in the console, the value of my number, and then it increments the value of my number. This is why you get four. So if I add another system down here that out that print line, my number now is going to output one. So if I run this, now, as you'll see, we have one, but because because this is this is how postfix incrementation works, because I put here plus plus plus at the end of the my number, when system that out that into line, this would line of how this is executed, it first outputs the value of my number in the console, which is zero, and then it increments the value of my number by one. So this is postfix incrementation, you also will also have prefix incrementation. And this has a different effect. This first increments the the the value of my number, and then it returns the value of my number. So it's going to increment it by one, and it is going to return the value one. So it will be display one in the console. So now if I run this, I actually let me put some text to make it clear about what we are doing here. So let's put here prefix incrementation plus plus plus my number is okay, even though it's looking weird this. And let's add up here system that out that actually let's just do it like that. So this is prefix incrementation. Let's run this. As you can see, you have prefix incrementation, we have one. So this time, we didn't get like in the previous, like the like with the postfix incrementation zero, and then we need to go on the next line to add the system that out that print and to print the value because this increments the value of my number. And it also returns the value of my number directly here. And you can do the same thing using the subtraction operator. So you can type here minus minus, sorry, minus minus. So this is also prefix decrementation now. So let's put here four. So now if you run this, you'll see in the output, prefix incrementation and three. So we have prefix and incrementation and have three. And if I use postfix incrementation, so if I put here plus plus, you'll see in the output four, because that only increments the value, it prints the value and then it increments the value. So that's why I get here four. All right, so this is our discussion about operators. And there are other operators that you can use in Java. But in order to use those operators that are next, we need to first learn about if statements because they are used in conjunction with the if statements. And we're going to see what if statements are in the next videos. So before I end the video, let's clarify something because I did a mistake when I typed this code. And the mistake is that I, and also this is also a mistake because here it says prefix incrementation. But here we have postfix, we have the incrementation at the end. To be prefix, it should be at the start. So this is the first mistake. And the second mistake is that when I introduce the prefix decrementation, I didn't change the text to prefix decrementation, I kept the text incrementation, not decrementation, so decrementation. So this is what we should say. So let's press control D actually to type here prefix, also decrementation, but not prefix, but postfix, postfix decrementation. And let's change this to minus, minus, minus. And let's duplicate this line of code two times. And let's put here plus plus my number, and here plus plus. And I will change the text now to first to postfix. And this here, I'm going to change it to prefix. So this is what I should have typed for the first time, prefix. But now we should say incrementation here, incrementation, and here also incrementation. Right, so this is what I should have typed first, because in this way, this is the code, we have prefix decrementation, we have postfix decrementation, when at the end postfix incrementation, when it's at the end, and prefix incrementation when it's at the start. So now if you run this code, you'll get the corresponding answer. So you get prefix decrementation three, postfix decrementation three, postfix incrementation two, prefix incrementation and get four. So I'm going to end this video now and see you in the next video. So now it's time to look at the next operator that you can use in Java. But in order to use those operators, we need to first learn about the if statement. Therefore, I'm going to create a new project. And I will call this project control flow, you'll see immediately why. Java for the language for the build system IntelliJ, make sure to have jdk here. And last let this add sample code check because that is going to generate the main class and the main function. So click on create. We go inside the main class, we double click here, and we can delete this system data.print line. Hello world. Now, what is an if statement? Let's first talk about the flow of the program. So the flow of the program, let's press Ctrl Z actually, to show you. All right, so the flow of the flow of the program is linear. What that means is that the quantity executed line after line. So if I have multiple print lines here, all of them are going to be executed one after another. So if I run this, as you can see, all of them are executed one after another. And if you have more code here, thousands, hundreds of thousands of lines of code, if you put them in this way, so you don't use if statements, you don't use, as you'll see, loops and all of that, that code is going to be all the code is going to be executed line by line. But we, as programmers, we want to make the computer to make decisions. And with an if statement, what you can do is that you can break the flow of the program, which is linear, which is line by line. And you can say to the computer, hey, execute this particular section of code only if this condition is true. Otherwise, skip this particular section of code. So this is what you can do with any statement, you can impose a condition and based on that condition, some particular section of code is going to be either executed, or it's going to be skipped. So let's see how we can do that. So let's delete all of those systems that we have here. Let's declare a variable int, number, and let's assign 10 to it, semicolon. Now to use an if statement, we simply type here if, so we have if and put a space. And now it's expecting us to put opening parenthesis and closing parenthesis. But when you when you put opening parenthesis, the closing parenthesis is going to be is going to be added automatically. So if I press, if I put the opening parenthesis, the right parenthesis, as you can see, was automatically now inside the parenthesis, we define our condition. So what what condition we want to evaluate here. So I'm going to type here if number, so the variable that we define above, and now we're going to use an operator called equal to so when I put equals equals, so two equals. So this first equal is called the assignment operator, because what he's doing is assigning what is on the right to the variable on the left. And this is called equal the equal to operator because this what he's doing is checking what is let me put here, let's say 10. What this equals to operator is doing is checking to see if the content of the if the content on the left is the same as the content on the right. So it's checking to see if this is equal to this, this is what it's basically doing. And if that is correct, I'm going to put curly braces. And when I when I put left curly brace, and I press center, the right curly brace is going to be added automatically. So if I press enter, as you can see on the line seven, I think, yes, on the line seven, let me check. Yes, on the line seven, this right curly brace was at the automatically because I press enter. And now what we can do here, we can say we can and I discovered what is the shortcut for system dot out dot print line. So you don't need to type that all the time, you can simply types s o t. And you select this one, as you can see, you have s o t and select this one, which says print a string to system dot out. So let's select that. And we are going to see, we are going to say they are equal. So let's run this code. So we have the condition if the condition is true, the code which is inside the curly braces is going to be executed. So we have they are equal. But let's change this variable to something else. Let's change it to age. So let's go three factor age. Let's change the variable. And as you can see, it's changed every everywhere where it's used. So I'm gonna type here, age, and I'm going to press enter. Now I'm going to put for the age, let's say 18. And now I'm going to use another operator, which is greater than or equal to some amount greater than or equal to. So if age is greater than or yes, if age is greater than or equal to than 80, I'm going to output in the console, you can vote, you can vote. And let's add another print line down here. Please put an x in the bar lot. All right. Now, what we are doing here again, we check in to see if this condition inside the parenthesis it's true, if it's true, the code which is inside the curly braces of the wave. So all of this code is going to be executed. So if I run this now, because we are checking to see if age is greater than or equal to, we get true back. And we get true because the variable age has the value 18. And we also get true because here we are checking if is greater than or equal to 18. So it's not greater than 18, our age, because it has 18, but it's equal to 18. So this is what this operator is checking. So let's change the condition to let's change the value of the variable to 17 to see what happens. So now if I run this code, now our code is not executed because the condition is false. And the code of the if, the block of the if, if you want, the block of code of the if, which is represented by the curly braces, it's kept, it's not executed. But what we can do, we can add another thing called else. So I can type here else curly braces, left curly brace and press enter. And it's going to add the right curly brace on the line 10. And I can type here s o s o s o t. So the shortcut, let's say you can't vote, please come. Let's put it on the next line and to put something on the next slide, you put backslash n. And I will type here, please come in. And I'm going to put plus. And I will say 18. Let's put in parentheses, 18 minus age, and that is going to give us what, what age this person which tried to vote has. So if you run this, it says we can, you can vote. And then it says, please come back in. And let's put here's here's a lot to put the plus. And let's put years. And let's also put here, please with an upper case letter. So let's run this again. So we get you can vote, please come in one years. And let's put here a space one because I don't like how it looks here. So let's run this again. Okay, so we get we can you can vote, please come back in one years. And if I change this to, let's say 12. And if I run this, now the condition of the if is going to be again, false, and it's going to execute the else part, the else part is always executed when the if condition is false. And as you'll see, when the if conditions are false, because, as you'll see in the next video, we can chain more than one if in, you know, our program. So you get we can you can vote, please come back in six years. And this is correct, because he has 12 years and it needs another six years to wait in order to be able to vote. So this is what a new statement is, you can break the flow of the program. And now we can make the computer to make decisions based on conditions based on if something is true or something is not true. And this is inherently very powerful. So I will end this video here. And in the next video, we're gonna see how we can chain more ifs in our program. So see you in the next video. Now it's time to see how we can add else if statements to check for more than one condition. And first, I will delete this code because I don't need this code. I will declare another variable of type int is going to be called the year. And it's going to have the value of 2019. I'm going to put semicolon. And down here, I will type if parenthesis year, so our variable equals equals. So you never check if it's equal to 2019. We put left curly brace and press enter and the right curly brace was automatically. Next, I will type so it so the shortcut for system.out.printline is oot. And I will type here, the year is I'm going to put equals. And here I will type plus plus. And our variable here, which is declared above. And now I will use an else if to check for another condition. So I'll type here else if and you can type, you can type yourself else if or you can press this and it will add the else if with the curly braces and with the parenthesis. So if I press on that, as you can see it added the parenthesis, we're going to put our condition inside the parenthesis and also added the curly braces, the block of the else if. And here we're going to check for year equals equals to 2020. So 2020, we're going to check there. And if that is true, I'm going to output in the console the year is equals and I'm going to put plus year. Else we're going to type sot also and we're going to say all conditions failed because the else is going to be called only if all the conditions from above are going to fail. So I'm going to type all conditions failed. We're going to type here failed. Now if you run this, we get the year is 2019 because it first checked here if the year it's equal to 2019 and it's true because we put it to 2019 and it executed the block of code of the if which is this block of code and it outputted in the console this text by the system that output print line. If I change now the value to 2020, look what happens. 20 let's put there. Now if I run this, we get the year is 2019 2020 because now this condition or the condition of the else if it's evaluated to true and consequently the code of the block of the else if is executed, which is to print the output in the console. The year is 2020 and let's put a space here also here. And we can add another else if so I can go here. I can type else if and we put parenthesis and we push that down. So I'm going to press enter. Actually let's put curly braces and now I'm going to put that down there and I'll put here curly braces and you can put the else up here and now you can put another condition. So I can type here year equals equals let's say 2020 and if that is correct I'm going to type sout and the year the year is let's say equals space plus year and now if you run this we get in the output the year is to 2020 because this condition is evaluated to true and the code inside the block of the else of this of this else if is executed. But if I change this to 2020, if I run this now this will evaluate to true this condition and the condition of the second else if and it's going to output the code which is inside the curly braces of the else if of this particular else if that is here and we can go even further and you can put another else if and another else if there is not a limit to how many else if you can put and we can also check if a value is not equal to something. So we can check if year let's say that I want to check if year and now I'll introduce another parameter called the logical not operator and what the logical not operator is doing is switching the value of a variable from false to true and from true to false and when you want to check if something is not equal to something we put exclamation mark and equals. So now we're checking here if year is not equal to 2019 and that is going to be true because the year is 2022. So all right so we get in the output the year is 2022 and we get this because this condition evaluates to true our year is not equal to 2022 is not equal to 2019 and it's outputting the which is now the value of the year is 22 and it's outputting in the console the it's executing the block of code of the if and it's outputting in the console the year is 2022. This is why we get here 2022 because this condition it's true it's true our two operands year and 2019 are not equal and this is true and now with this I'm going to end our discussion about else if and you can put as many else if you wish and let me show you first now how we can use the logical not operator to switch a value from true to false and from false to true. So I'll declare here a variable called it's going to be a boolean so I type boolean and it's going to be called is active and I'm going to assign true to it I'm going to put semicolon and down down here I will type if is active I'm going to type S-O-T I'm going to say the user is active else I'm going to say the user is not active so I'm going to say S-O-T again quotation marks the user is not active now if you run this this will evaluate to true because this is equivalent to typing is active equals equals true and it's redundant you don't need to put it's active equals equal true because it's active already has the value true in it so it's implicit you don't need to type this in this explicit expanded form so because if you have a rover I think it's saying that it's equal to equal active it's saying it can be simplified to its active so let's simplify to its active and now if you run this you will get the user is active but look what what can I do I can put here if the user is not active and now the value of the is active is going to be switched from true now we have true is going to be switched from true to false now so now if I run this we get the user is not active because now it changed the value from true to false and generally you can put the logical not operator in front of any expression you want so if you have here a variable let's type here int let's say int my number let's say equals to 10 semicolon and if you put the logical not operator in front of any any expression and an expression as I said is something which returns a thing and if you put the logical not operator in front of any expression it will switch the value from true to false so if I type here if my number so if my number let's say is greater than or equal to 10 and it's true it's 10 let's actually put a bigger number to make it more clear so we're going to put 20 and because I put the logical not operator in front and I will put parentheses around the expression now this this condition is true so let's first let's first output the code without the without the logical not operator so let's run this and we get the user is active so let's put the user here because this condition is true but look what happens if I put this in parentheses so we surround our expression with parentheses to treat it like a single unit and we put a logical not operator in front of the parentheses of the my number but inside the parentheses of the if so I'm going to put the logical not operator and now I will run this and now if you run this as you'll see it will say the user is not active even though my number is greater than 10 is true but it's converted from true to false so this is what the logical not operator is doing so I think I'm going to end this video now and see you in the next video now it's time to see how we can nest an if inside an if or an if inside an else and I am particularly interested now in the else part because I want to have the output if the age is let's say 17 and 18 minus 17 is going to be one to say please come back in one year not one year and to do that I'm going to add another if here so I'm going to put if parentheses now the condition if 18 minus age equals equals one so if 18 minus age equals equals one then it's going to say please come back in one year all right so let's put the curly bases and now we have this inside the curly brace of date and let's change this from years to year else it is going to output like the previous like previously with the text years so let's copy this and let's paste it here now if you run this code now age is 12 so it will say please come back in and let's put here years because this will be executed if the age is if it if it is not one year until it can vote so it says please come back in six years and if I put 17 here and if I run this code it says please come let's let's put here back please come okay let's run this again but now our logic is working and you nested now as you can see and inside the else we nested another if and then else so this is how you can nest if analysis inside the elses or ifs so I'm going to end this video and see you in the next video and let's put a space here so let's run this okay so now it looks more bitter please come back in one year is saying now so now this condition is true it's executing the else part and we have our output so I'm going to end this video now and see you in the next video now it's time to look at the logical and and the logical or operator but first let me show you the less than or equal to operator so I will delete the logical not operator from here and I will delete the parenthesis around the expression and I will change now the value here to nine for my number variable and now I'm going to change the operator here to less than or equal to so we put here less than or equal to so now if you run this we get in the output user's octave because my number has a value nine which is less than 10 but if I put 10 it will also be true because we're checking if it's less than or equal to so we get the user is octave but if I put 12 here and I run this now we get the user is not actually because my number is not less than or equal to 10 now let's delete this and let's keep our variables the only thing I'm going to change the name of this variable to score all type score here I'll put equal to 100 now we will start with the logical end operator and let's say that I want to check two things I want to check if a user is active and I want to check also if the user has the score greater than or equal to 100 and if that is the case so if those conditions are true I want to have the entire expression to return true and I will open the next level in a game let's say so I'll type here if parenthesis and the first condition score is greater than or equal to 100 now to use the logical end operator we put 2 m percent science and then put our second condition if it's active equals equal true but you know that this is redundant from our previous video now what the logical end operator is doing so let's put the curly braces so I'm going to go left curly brace and enter to other right curly brace now what the logical end operator is doing is checking to see if what you have on the left the condition that we have on the left is true if and if the condition that is on the right is true only then the entire expression is going to return true so again the logical end operator will will only return true if both conditions are true respectively if the score is greater than 100 and this activity equals true and this can be typed like this because it's redundant so now I will add the sout and I will say you opened the next level now if I run this you get you get you I should say opened here you opened so now if I run this you get you open the next level because both conditions are true but if one of the condition is false it will the entire expression is going to return false so if I type for the it's active false let's now add an else here let's put curly brace press enter sout so let's type sout and I will type you are at the same level so now if you run this now the else part is executed because both conditions have to be true in order for the entire expression to return true this is how the logical end operator works and because its active is false it executed the else part and output in the console you are at the same level and if you want to make more clear which condition where is which expression is what are the expressions who can put parenthesis around the expressions like this but I think it's better to not have them in this case in this particular case now I will end the video and in the next video I'll introduce the logical or operator now it's time to look at the logical or operator and the logical or operator returns true if at least one of the expression is true so let's delete this code because I don't need this code I'll declare two new variables int num1 in a real app you should use more descriptive names I'm going to sign in five I'm going to put semicolon enter int num2 and I'll put equals to 204 semicolon then I will type here if num1 is greater than zero now we're going to use the logical or operator and to use the logical operator we put two vertical lines or in our second condition num2 also greater than zero curly braces left curly brace and press enter and the right curly brace is going to be added automatically I will I will type sout the shortcut for system.out.print line and I will say the condition is true I will also add an else here let curly brace opening curly brace and enter it and to add the right curly brace on line 10 and I'll type sout here and I'll say all conditions failed now if around this as I said the logical or operator returns true as if at least one of the expression is true and no and we have two expressions num1 greater than zero and num2 greater than zero and we get the condition is true the condition is true so if I change this to minus four now so now num1 it's not greater than zero but num2 is greater than zero because it has a value five the entire expression is going to return true so if I run this we get the condition is true even though our second expression num2 greater than zero it's false because the left expression num1 greater than zero is true the entire expression is evaluated to true but if both expressions or in maybe you have more than one more than two expressions if all the expressions are false then the entire expression is going to be false so now because I put here minus five and minus four and now we are checking if num1 is greater than zero and num2 which also checking that if is greater than zero because both now are having the value smaller than zero that is going to return false and it's going to execute the else part so we get all conditions failed so this is how you can use the logical or operator so now if I reverse this to five and if I run this we get the condition is true because at least one of the expression is true so again with the logical or operator if at least one of the expressions no matter how many expressions you have in order using the or operator if at least one is true the entire expression is going to be true and for the for the entire expression to be false it needs to be all the conditions have to be false so I'm going to end this video now see you in the next video now it's time to look at the next control flow statement that you can use in java and that is a switch statement and first I'll declare a variable called time and I will assign 10 to it then I'm going to type here the down here I'll type switch and in the parenthesis we're going to put our variable that you want to test that you want to test so I'm going to put time here here we put curly braces press enter to add the right curly brace on line seven and now we're going to we're going to test our case so switch time I'm going to type here case and now the condition let's say time 10 and then then we put a colon and after colon we put the code that you want to have executed so I'm going to put sout and we're going to say the time is plus time and we can also post something else here let's put let's say plus quotation marks backslash n I'm going to say time for coffee all right all right so after we we put our code we put break so we put break because if you don't put break let me show you so I'm going to go back I'm going to put another another case here let's say case let's say 12 and we're going to add also sout and we're going to say the time is plus time plus time and plus backslash n time for a run all right if I don't put break here look what happens so what this switch system will do will test this value against the branches that we have here so it will test to see if the value of time is equal either to 10 or to 12 if it's if it's equal to 10 then it's going to execute the code which comes below of the colon here so if I run this but without break look what happens without break without break the code is executed all the code is executed this is this is why you need to use break because when you said when you say break you basically stop the switch at one branch so put break and here also put break as you saw because if you don't put break it will execute all the branches so put break and it will only execute one branch so now if you run this just the time is 10 time for a coffee so now it's not executed also the second branch like it did previously so let me delete me let me delete this to show you so now without the break all the all the cases are executed one after another so we need to put break here in order for that to not happen break and here also break break all right let's press ctrl i'll tell format the code and you can have as many cases as you want so let's put another case here let's say case let's say eight let's put seven case seven one when i put sout sout the time is plus time plus quotation marks forward slash n is time to wake up up so now if you run this we get the time is 10 time for a coffee because it tested our variable here against this branch and it found to be true but if i change this now to seven if you run this you get the time is seven it's time to wake up and you can also have a default case so i can go here and the default is going to be executed all the cases from above are not true so you put default i'm going to type sout i'm going to say time to relax time to relax so if i put here let's say two and i run this now all the cases are going to be not one one one not not one of them is going to be true so it's going to execute the default and you can also put here a break too so this is how you can use the switch statement so let's make our switch states more flexible by getting the input from the user instead of typing here the literal the number literally typing the number here and to do that we need to use a scanner so i will type here private static actually i'm uh private is also an access modifier but we didn't talked about access modifier so let's let's use public because at least we talked a little bit about public so private sorry public static and we will see what static is in the future videos scanner we type here scanner scanner we will see what this in the future videos but basically with this we can get the input from the user we're going to put equals new scanner and inside the parameter we're going to type system dot in now what i will do here instead of putting two i will put here scanner dot next int and now dot this line of code that we have here let's put semicolon here semicolon all right so now this line of code that we have here is going to wait now for the input in the console here and it's going to take that input which is going to be an integer and it's going to put it inside our variable time and then we're going to test that that value against our branches that we have here all right so let's run our code to see what happens so let's run this code and to make it more interesting let's put also some some some text to say to the user to introduce to to input some to input a number all right so let's stop this let's close the actually let's put a sld here please or we're going to say what time is or it is what time it is so now if you run this this is what time it is and now we can pass something here so if i put here too it says time to relax so it's executing the default branch and if i run this again and again it's asking us what time it is and now we can pass input from the keyboard as you can see using this scanner that we have here scanner.next hint and by declaring here above this thing we're going to see what all of this is in future videos so i'm going to talk about classes and objects so now here we're going to say let's say 10 or let's put seven because we have seven here for the case but i didn't put a break there sorry let's put break otherwise it'll break so now if you run this again let's run this again what time it is let's put seven and again the time is seven it's time to to wake up and i don't know why it opened the console again so let's run this again what time it is let's put seven and again the time is seven it's time to wake up and then it says process finish with x equals zero and that means that the program successfully finished all the execution so this is how you can use a switch statement you can have as many switches you can have as many cases as you want here and it's important not to forget to put the break after you put the code that you because here we can have you can have a function which can do something so we can call a function here and so on but i keep it simple i just outputted something in the console so now i'm going to end this video and and i'll see you in the next video and you also see in this video you also saw in this video how you can get input from the user using the scanner and the scanner that next int to get integers so i'll end the video now and see you in the next video all right so there is one more thing that you can do with the switch statement that is that you can replace this switch statement with an enhanced switch statement so if you hover over the switch as you can see it's colored in this yellow color and if you hover over it says switch statement can be replaced with an enhanced switch so click here or it says replace with enhanced switch statement to see what happens so now we have our code written like this so we have case and i have the case then i have this arrow and the code which is going to be executed now if you run this code everything will work the same what time it is let's put seven the time is seven it's time to wake up as you can see everything works fine and you can also put curly braces around the code that you want to have so you can put opening curly brace here and closing curly brace and you don't need to put the break the break keyword and by this way by using the enhanced switch statement so this is very interesting let's put curly braces here also and here you can also put curly braces and with the enhanced enhanced switch statement you should use curly braces when you have multiple lines of code in our case we only have one line of code but if you have more lines of code here more code here if you have then you should use curly braces so this is how you can use the switch statement and as you can see it's similar to the classic switch statements the only difference is that you have case and it helps the case so you have the condition and then we have this arrow which basically says hey if this case if the case is 10 this arrow is saying hey execute the code inside the curly braces here so now i'm going to end this video and see you in the next video now it's time to start a discussion about loops and loops are used when you want to execute a particular section of code repeatedly and we're going to start with the first loop and that is the for loop so i'll go down here i'll type for and while i'm typing intelligence giving us some suggestions and we choose the first one and if you press enter it will add the parenthesis automatically for you but if you want to type yourself the parenthesis just put opening parenthesis and the closing parent is going to be added automatically so i'm going to put opening parenthesis now inside the parenthesis i'm going to type int i so we declare a variable now and we're going to assign zero to it so this is going to be the starting value of i it's going to be zero then we're going to put our condition we're going to put i less than or equal to 10 so this loop is going to be executed 10 times one is going to reach 10 one is going to reach 11 is going to be is going to stop so i'm going to put again semicolon and i'm going to put here because if you hover over it says condition i less than equal to 10 is always true and in order for that condition to be to be false we need to increment the i so i'm going to type here i plus plus so we need to increment the i i teach iterations so we want to put left curly brace and right curly brace now inside the curly braces we're going to put our code that we want to have executed 10 times so i'm going to type here s saut so and i'm going to put here i equals and we're going to refer our i for from our loop plus i'm going to put i here now if you run this we get in the in the console output that i is zero i or equals to one i equal to three because this now is executing the code inside the curly braces 10 times when it reaches 10 when it reaches when the value is incremented to 11 this condition is going to be false and the loop is going to stop so this loop will execute for a specific number of times so if i change here the condition to let's say 100 it will execute the code inside the curly braces 100 times so if i run this now we get 100 times our loop so this is what we can do so you have for the declaration the starting value then we have the condition and i plus plus and we can go even in the opposite order so i can put here i equals to 100 while i is less than or in here i can put while i is greater than or equal to let's say zero or let's put one or actually let's put zero and now we can decrement i so i can put here my i minus minus so now if you run this now you will see backwards the output so get 199 because we're starting with 100 we put the condition while i is greater than or equal to zero i minus minus so i teach iteration is going to uh subtract one for from i so it's going to be 99 99 98 97 96 and so on until it reaches until it reaches zero and then it decrements again and the i is going to be probably minus one and it will this condition is going to be false and it's going to exit the loop also you can use let's press ctrl alt l you can use if statements here so because i introduced now something called break so instead let's say that for whatever reason if let's say if i equals equals 50 i want to stop this loop how how how could i stop this loop so to stop the loop you just simply put here break and break is gonna as the name implies it's gonna stop the loop so when i is gonna be equal to 50 we're gonna put break and our our loop is gonna stop so if we run this get 51 and then it stop because when it reaches it reaches it reaches 50 it stops and you have 51 because this is a you have decrementation here let's change it to let's change it to zero let's change the condition to less than or equal to zero and i plus plus so if you run this oh sorry it should be so sorry it should be here let's say 50 so if you run this we get 49 and 50 is not pretty because when it reaches 50 it incremented the i to 50 but uh in i it will be 50 but it will not execute this sout to output i in the console so this how you can use the break keyword in our loop to stop the loop it can also use continue and continue is going to skip the code which comes after the continue so if i put here continue look what happens if i run this we have the same output because continue what it's going to do is going to skip all the code which which comes after the so whatever code comes after the continue keyword so the code that is down here is not going to be executed this what continue does and to show you more clearly how continue keyword works in comparison with the break keyword i'm going to change the condition if i equals equals to 50 because now if you look at the output is the same output like like when you had the break here so if i put break here and if you run this we have the same output so it's not illustrating correctly what is the difference between continuing keyword continue keyword and the break here so i'm going to change this condition now from i equals equals to 50 to i greater than equal to 30 and i less than or equal to 50 and i want to change this to 100 so now if i run this we get we get our numbers and when it reaches 30 as you can see it's skipping all the numbers and then it continues from the 50 because this is the condition that we're going to put here and now this illustrates better how continue works so continue continue is skipping the code it's not stopping the loop like break the lucky like break does so i'm going to end this video now and see you in the next video now it's time to look at the next loop that you can use in java and that is the while loop so i'll delete the for loop because i don't need the for loop and the while loop is used in situations where you don't know for how many times you want to loop but you know that you want to loop until a certain condition is true for example let's say that you want to display a dialogue while the user is typing something in an input so in those scenarios you use the while loop now to use a while loop just type while so we can press enter or you can type the word yourself and you put parenthesis and inside the parenthesis we put our condition and then put curly braces and decide the curly braces we're going to put the code which is going to be executed while the condition is true so as long as this condition is true inside the parenthesis the code inside the curly brace is going to be executed so let's say that i declare here a variable called let's call it in let's it's going to be of type p and it's going to be called number i'm going to put equals and i'm going to put zero there semicolon and here we can we can put the condition while number is less than or equal to to 10 when i execute the code and coincide inside the curly braces but now we need to increment the the number because otherwise this will be generate an infinite loop because this condition is always will always be true because you have zero and here we check to see if number is less than 10 and we are not incrementing the number at each iteration so now if you run this like this you get you get not nothing in the output but the the console is still running because now we have an infinite loop so let's let's close this by by clicking on the square red button so i'm going to hide the console now so it's very important to make the condition false and to make the condition false we're going to put number plus plus number plus plus here semicolon so now if you run this we get nothing because you don't output nothing but now we don't get the infinite loop so down here i'll type sout and i'm going to print our number so now if i run this we get one two three four five six seven nine ten and get also 11 now you may be wondering why you get 11 because the condition says that the number has to be less than or equal to 10 but we've also gotten the output 11 this is because when when the number have has the the value 10 you check to see if 10 is less than or equal to 10 and that was true and because of that now the value as i said is 10 it incremented the value so it incremented and now the value is 11 and then it output the value in the console this we get here 11 then it goes to the condition again it checks to see if 11 is less or less than or equal to 10 then that was false and because of that you don't see after 11 nothing the application is finished so this is the while loop and we're going to use the while loop a lot in our code there is also another loop called the do while loop and the do while loop is going to execute a particular section of code even though the first even though if let's say the the condition is false it will execute the code at least once and it will execute the code at least once even though if the condition is false so what i can do i can delete the while loop let's delete the while loop and let's type do we put do and we have curly braces and here we put while and here we put our condition let's say while number is greater than or equal to two let's say one or zero let's say let's put one and now this this here is false but but because now we're using the do while loop the code inside the do so let's put s out with here and let's print number now because you're using the do while loop the code is going to be executed at least once and then it's going to check the condition and if the condition is true it will execute again but you have this particular option with the do while that the code is executed at least once irrespective of the condition that is here so if i run this normally i should be able to output nothing but because you're using the do while loop we get zero in the output because if you press ctrl z and we we put the while loop and put here while loop is let's say less than or equal to okay so let's say while the the number is greater than or equal to one let's say greater than or equal to one now because this the value of the number is zero and here we check in the series if number is greater or equal to one this is not going to be executed so if you run this you don't get nothing in the output but with a do while loop so if i type here do and here at the end of the right curly brace we type while and we put number greater than or equal to one and put s o t here number now this is going to output at least once the the value of the number because i forgot the semicolon there so let's put the semicolon so let's put semicolon and let's run our code again let's close this and let's run our code again all right so we have let's run it again because i click on this debug so we get zero because the do while loop it all executes what is inside the block of the do at least once irrespective of the condition but what what we can do is we can we can also make the condition to be true by incrementing our number so we can put here while and i can put here number plus plus semicolon and now uh let's put while number is greater than equal to or let's put less than or let's put greater than or equal to um let's put less than or equal to let's say 10 so now if i run this now we get our 10 numbers out within console but again previously when i had this so let's let's control z a few times even though the condition is false the code is going to be executed at least once so those are the while and the do while loops that you can use in uh java and you also you can use the do while and with the while the continue and break keywords in the same way you use them uh inside the the for loop so you can use the break and continue keywords also in the while and do while loop the break to stop the loop and the continue to skip a particular section of code so now i'm going to end this video and see you in the next video now it's time to start a discussion about functions but first let's create a new project i'm going to call it functions it will be in pascal case without spaces for the language select java for the build system select intelj make sure to have the jdk selected here the version 17 and also check this box which says add simple code because that is going to generate the main class and the main function for us so i'm going to click on create now to create the project all right now our project was created now let's open the main class so double click on the main here inside of src folder then let's bring this down and now let's talk about functions so what are functions functions are a line or lines of code which are grouped together to do a specific task and so far in our videos we already dealt with functions the main functions as i said in a previous video is a function for which the java compiler when it tries to run our code it's looking to for this function in order to be able to run our code the print line function that is outputting something in the console it's also a function which takes some input and it outputs the input in the console so we've already dealt with functions now let's see how we can create our own functions and to create our own functions i'm going to go outside the parenthesis of the main function and i will type public so first we type this public this is an access modifier here next we type static i'll i will explain to you what static is in the future videos next we type void and void is the return type of the functions because as you'll see functions can return something and void means that you don't return nothing next we need to give a name to our function so let's call it say hello and this function is going to say hello next we need to put parenthesis as you can see on on the top both our functions have parenthesis and when you declare a function we need to put parenthesis we need to parenthesis because inside the parenthesis you can define parameters which can receive a value when you call the function but now we're not we're going to declare any parameter for now and then we put curly braces so put opening curly brace and the right curly brace so that did automatically and i press enter now what i can do inside the no have a function and it's called say hello what i can do now i can type here sout so our shortcut and i can type here say hello let's say hello alex so let's delete now this code because you don't need this code and let's run our code to see what happens all right so the console open but you don't have nothing in the output that is because if you look at our function say hello as you can see it's gray out and if you hover over it says method because functions in java are also called methods and the reason is because uh they are part of our class but we're gonna see we're gonna talk about this when we're gonna talk about classes and objects now it says the method or the function say hello is never used in order for our program to execute this hey this say hello function we need to call the say hello function from our main function because as i said the main function is the entry point so when the java compiler runs our code it's executing the main function and if the main function has code in it which needs to be executed it which needs to be executed it will execute that code if not it will just out it will just finish the program without doing anything without doing nothing because we didn't call we didn't type any code here so now what i can do here i can type say hello and while i am typing as you can see we have suggestions we have first sout our shortcut and we have then m and m stands for method or or let's call it methods from now on so our method say hello so you can you can click on this one and now it's going to be called from our main function so let's let's select that and let's press enter now what we're doing is we are calling the say hello function inside the main function so now when the compiler is going to run our code it will execute the code inside the main function which is to call the say hello function that is defined here and you also have this one usage and what this basically means is that it's only you it's only used here this way i think this this is what one usage is saying now if you run this get hello alex and we can change this text you can change to hello you wanna so now if you run this because now when this code is executed the main function is called and the code inside the main function is called and inside the main function we have another function say hello and this function is called and the code inside the say hello function is executed which is say you wanna so let's change this back to say hello alex now what we can also do we can call our function multiple times so i can type here control d a few times now if i run this we get hello alex multiple times so as you can see what functions allows us to do is to divide our code into chunks of code which are reusable so they can be called in many places in different places and in different scenarios so this this this is how this is basically how you can write a program because if you will just type all your code here do not make any sense you have you have to have some kind of structure and we have that structure using functions and if statements and so on now let's run this again now the problem now with the say hello function is that it's already saying hello alex it will never output anything else only if we we change this text it will display something else but as i said function like you can see here this function has a parameter this is a parameter defined here and you can also define parameters for our own functions so i can type here string so the type of the parameter let's call it name now when as you can see it immediately have added this underline here we will see immediately why now what we did here we define a parameter name so when we call this function we need to pass a value to this function for the name we need to pass an actual value and we're going to use this value inside our system.out.print line so instead of uh instead of say hello alex is going to say plus and i'm going to type name i'm going to put another plus quotation marks and the exclamation mark now what this is going to do when you call the say hello function it will it will receive a value for the parameter name and then it's going to say hello and the value which is passed to the parameter name so if i put here now now if you hover over the parentheses it says expecting one arguments so it's saying that it's expecting one argument a value but found zero so it's another word is saying hey you defined below here a parameter name now give me a value for that parameter so so i will be able to use it in your code so to use it in the in the here so i will type here let's say john so now if you run this it says it's saying hello john so now it's using the value that is passed here and as you can see you have also this name that it's saying it's saying the name of the variable which is name and we can call our function again so we can press control d and you can change it to let's say uh anna so now if you run this it will say first hello john and then hello anna because now for our second function when you call it the value is passed anna and when this system.out.print says execute it's using the value anna here so this is how functions or this how you can define a parameter for a function and you can define more parameters here you can put another parameter here and to define another parameter you put a comma to our first parameter and we type another parameter let's say age so we type int age and now we have those underlines because now it's a spacing value for the age that is defined here so we're going to say hello alex let's put plus quotation marks i'm going to type your age is and plus quotation marks not quotation marks sorry plus age so now this will receive a value for the name and for the age and it's going to use that value inside the head inside the print line and it's going to say hello the value which just passed for the name and it's going to say your age is and the value which is passed for the age so let's pass here let's say 23 and for anna let's say that we pass here 26 or 25 let's say now when you run this code get hello john your age is 23 hello anna your age is 25 so what it's doing here now it's using the values that are passed here these are also called arguments the value that you pass to the parameters so to the parameter name for our for our first call of the function we pass john and for the age you pass 23 and we got in the output hello john your age is 23 for our second function because because functions are reusable chunks of code you can call it again when we pass different values here we passed anna for the name and for the age 25 all right now i'm going to end the video and see you in the next video we're going to look at other things that we can do with functions so see you in the next video now it's time to see how we can return a value from our functions so i'll go down here i'll create another function so type public static now to make the function to return something we need first to say what you want to return so after the static keyword we put our type so what type of data we want to return in this case i'm going to return an integer so i'm going to put public starting int so compare this with the function that we have above above we have void that means nothing we don't return anything now we're having public starting int so this function is going to return an integer next we put a name let's call it getmax and this function is going to have two parameters int num1 comma int num2 and it's going to return the big the number which is the bigger number now as you can see we have another line our here and it's a missing return statement because now we need to return something but first let's check to see which number is bigger so check we type if num1 is greater than num2 then it means that num1 is the number which which is the bigger number so now we need to return that number back to the to the calling function and to return we type the return keyword and the value that we want to return in this case you want to return num1 which is the bigger number num1 else i'm going to put here else that means that the num2 is bigger so i'm going to return here num2 let's press ctrl alt l to format the code and let's delete those calls for our say hello function also let's put a semicolon here now if i call the getmax function here so i type getmax function and i put two numbers so let's say 10 and 5 put semicolon now if i run this code we get nothing this is because this function it's returning a value and you need to capture you need to get that value to put that value into a variable into a variable because it's returning a number so you need to get somehow that number in a variable here and then output it because if you press shift control p on this function so we select the function as you can see the whole function returns the whole function is considered to be an int because it's returning a number this way you have that pop up which says int now i'm going to type here int max equals so you put int max equals getmax and this is going to return the maximum value down we type s our ot and i'm going to type i'm going to output max and let's press ctrl alt l to format the code and let's run our code now now we get 10 so our function returns to be a number and if you pass a different value here let's say you put here one now and if you run this now we get five because what he's doing is taking whatever value are passed here for the parameters here and here then it's doing the checking it's checking if num1 greater num2 then it's returning that number and if that number is the number which is greater it's going to return going to be returned here by the getmax and it's going to be stored in the max variable then we're going to output that variable in the console another important thing to know about the return is that after the return the after you return from a function either by returning something or simply typing just return the function or the structure in which we are currently in is going to be left it's going to be stopped so if i try to put some code below our return let's say s our ot let's say uh this is some text we have this underlined and it says unreachable code delete a readable statement because when when you sell to the function return something at that point it it leaves the function and it's not executing any line of code which comes below of the return statement so this is very important to have in mind and if you just type return without returning something it will have the same effect and missing return value so let me change this to void to show you how even if you just type return so no no so let's put here all right so now we have it so if we just type just type return again it's saying unreachable code because after we type the return keyword either by returning a value or simply do just the return it's gonna it's gonna stop the execution of the function the function is not going to execute any line of code below of that so let's press ctrl z a few times here to undo the changes and let's also delete this because you don't need this and if you want to return something else simply just change the return type here so you want if you want to return a boolean type you just type boolean here you type boolean and now we have an error because it now it's wants to return a boolean if you want to return a char you just type here char so if you want to return a string you put here string and you will return a string value but now returning integer so this is why you have the those in red so it's up to you what you want to return depending on what you're trying to want to do so this is our discussion about return types and see you in the next video now it's time to start a discussion about arrays but first let's create a new project i'm going to call it arrays for the language select java for the build system intellij make sure to have the jdk version 17 here selected and i'm going to keep this checked add simple code to have the main class and the main function generated for us so click on create all right now our project is created let's open our main class let's push this on the next line and let's delete this code because you don't need this system.out.print line now what are arrays? arrays allows you to store multiple values in a variable without declaring separate variables for each volume so and to declare an array we type first the type so what kind of data you want to store in this array let's say that i want to store numbers so i'll type int and after the int you put square brackets and then you give a name to our array let's say that i'm going to call it numbers then i'm going to put equals and when i put curly braces and inside the curly braces we put our our elements of type int separated by comma so i'll put here one two three four five six actually let's use other numbers so i'm going to put 12 15 60 100 200 30 50 all right so now we have an array of integers stored in this variable numbers now how we can print those values in the console we can use a for each in this case but i'm going to show you also how to use the classic form later but let's first print the for each so we type for you put parenthesis and we type here int number colon in numbers so for every number in numbers you know numbers array from above i'm going to add s o t i'm going to type i'm going to print the number so now if you run this we have our numbers displayed in the console so everything works fine now one very important thing to know is that the index of the so our elements our integers so or our elements more generally are stored at indexes and the index of the elements is starting at zero so 12 is at the index zero so if i want to print the value let's say 15 i need to type here s o t and i will type numbers then square brackets and now we need to use the index where that specific number is and the index of 15 is one so if i run this we get 15 because it's it's this line of code is getting the value which is stored at the index one and you want another value put here let's say three so if you run this we get in the output 100 also another thing that you can do with with arrays is that you can get the length of the array so i can type here a classical for loop so type four and you can create you can create this for i you have this suggestion and it's going to generate for you the all the necessary code so if i press enter as you can see it generated all the necessary code so for i int if i press tab it moves to the condition and i'm going to put the condition numbers and you can get the length of this array so if i put the length and press again tab and here i will type sout and i will print i in the console not i we don't print numbers that i so get we're going to get the numbers at the index i but probably as you'll see we'll have a problem with this code so now if i run this we don't have any problem but if i put less than or equal to numbers that length so now if i run that now we get an exception it says index seven out of bounds for length seven so he's saying that because our elements are stored i indexes we have here one two three four five six seven elements but they are the last index is six and when we put here for i is less than equal to number that length we get with we try to get the index which is we try to get here the index seven here in this line of code and index seven does not exist so this i get this index seven out of bounds for length seven what we can do in this case we can put less less than without equal and the code it will work because it will it will get to the last element and it's not to go to it will not go for the last index or you can you can put here less than or equal to numbers but you can put here minus one so we're going to subtract one from the length so so so in instead of having number that line let's say which is seven the length when i have six which is the index the last in the index of the last element so now if i run this we get on the output our numbers and we can create another array so i can go down here and i can type string square brackets to declare an array i'm going to call it names or let's call it friends and i'm going to put equals again curly braces and here i'm going to define some names so let's say maria alex bita anna john steve all right let's put semi colon so now we have another array of friends now if i want to loop through this array i can use a for each so i can use a for each i'm going to press enter as you can see actually let's press ctrl because i don't like the formatting so for parenthesis for here i'm going to type the type string for string so type here string i'm going to type friend colon so for friend in free ends curly brace left curly brace and press enter to add the right curly base or the closing curly brace and i'm going to type here sout friend and now it's going to display all of all of our names using the for each so we get all of our names so let's put actually a space between our code here so let's put here print line not print line sout ut and let's put question mark and let's put backslash n that's going to add the space between our two outputs because we have two different outputs here one from the numbers array one one from the from the numbers integers array and one from the friends strings array so as you can see now we have a space which was added by this line of code and you can you can output the the values in the friends array using a classical for so i can type here for and we have the suggestion choose this one it will generate the for for you and i'm going to put for i equals zero i less than uh let's say friends dot length and that is going to return us the length of the array so for friends that length i plus plus i'm going to put type again then i'm going to type here sout and i will type friends and i will get the index out of each iteration so i'm going to put square brackets i and that is going to return us the element at this specific index so first the i is going to be zero we'll get the element maria then i is going to be incremented to one and we get alex then i is going to be incremented again and we will get bits and so on until it reaches the last element the condition fails and the loop stops execution so now if you run this so we get our numbers and then we get our names output and console so this is our discussion about arrays and you can use arrays with all the primitive types that we talked about and also with the string as you as you saw here so i'm going to end this video now and see you in the next video but let me tell you one more thing about arrays what you can also do with an array is that you can create here let's say another array let's call it let's also need and you can we can put square brackets let's call it numbers two and what you can do here you can type new int and you can define here a size of let's say seven elements or five elements and now if you want to add elements in this array you cannot only five elements but you can you cannot them using indexes so you type numbers two index zero equals and here we define an element let's say one and put semicolon and if i press control the a few times now let's change this to one two and three and let's change this to let's say four five sorry seven and let's say ten so this is another way to assign value to our array and here i passed five this is the size of the array so if i try to put let's say another i'll type numbers here again actually let's press control d again control d again control d and if you hover over it says it says the overwritten array element variable is already assigned to this value so let's delete this and let's change now the index to four and let's put here 24 let's type again numbers two and let's put square brackets and i'm going to put five and i'll put equals to 100 semicolon and now we're going to type the next index which is six we'll see what happens i'm going to put index six equals let's say 45 all right so if you hover over the five it says so let's hover over all right so it says array index out of bounds and is saying that because here we define only that you're going to create an array of with five elements and we added more than five elements so this way is saying array index out of bounds so we cannot do that so because we already have five elements here so we have one two three four and five so when we try to add here let's press tab numbers two and array five equals to let's say nine immediately shows this warning and it says array index is out of bounds because we define that we're going to put five elements and if you count what the number of elements we have here we have six elements we have one two three four five and six and because the size is five and we put six elements we get this warning so this is good to know and usually you will not assign values to arrays in this way you'll use you'll lose the curly braces because this is better and you can also replace an element without an index so you can use the index and you can put a different value in that index also another important thing to mention is is that after you created an array so after let's say i created our numbers array we cannot add new numbers in our array our array has a fixed size so if i try to put here numbers let's say actually let me i will not type the code but if you try to put another element inside this array it will not work because if i type here numbers and let's say that let's say let's say that i want to put let's say like i said i want to add something and i call add there is no add function for our array our array our arrays have fixed size and the size is it's uh the size is is given by the number of elements that you passed you when you first created the array and as you'll see in the future videos we're going to learn about arrays which can grow and shrink as you add elements to it so that for now we're going to look we're going to use only those so now i'm going to end this video and see you in the next video now it's time to do a challenge using the knowledge that we have accumulated so far therefore i'm going to create a new project i'm going to call it challenge challenge for the language java build system intellij make sure to have the jdk reverse transcending selected here and also make sure to check this box we have the main class and main function generated for us so now i clicked on creator and all projects are going to be created now let's go on the left hand side on the project pane in the front of this src click on this greater arrow in this greater sign and double click on the main class to open the main class and let's uh pull this on the next line now the challenge is to create a function which receives as a parameter an array and the function should an array of numbers and the function should return the the biggest number from that array of numbers that is the challenge so try to do it and then come and watch my solution so with this is my solution so i'll delete this i'll create a function public static and i'm going to put int because it's going to return an integer i'm going to call it get marks and it's going to receive an array so i'm going to declare here an array of numbers then i'm going to put curly braces and first here i'll declare another variable called marks and i will assign the first element from our from the array in this variable mark so i'll type here numbers square brackets zero so we'll put our first element there then i will loop through our array so i'll type for and i will use the for each loop for uh let's type int number in numbers and here we're going to check if if number so the number at this at this iteration is greater than our marks then that means that we need to switch you need to put our max i need to put this number in our max variable then i'm going to put max equals number semicolon and outside of the for loop we're going to return this number so we're going to type here return max semicolon now if i go up here here i'll type get marks and i'll uh i'll provide some numbers here let's say four five actually we need to provide an array so let's create directly an array here so we put uh we put uh curly braces inside the so double curly brace and inside the curly brace i'm going to put one two three four actually i can do that so let's create the array first so let's type here int numbers equals and i'm going to put here one two five seven eight nine nine twenty two it should be an array here and semicolon now let's pass those numbers here let's put a semicolon here let's store this variable let's store what let's store what the function is returning in a variable so i'll type int marks found if you want equals to get marks and i'm going to press control i'll tell the form of the code and down i will type s o t max found so we're going to output the maximum found so now if you run this the biggest number is 22 so we get 22 as the biggest numbers and if put here are other numbers like 77 100 150 zero if you run this our program works it returns 150 which is the biggest number from our array so this is the solution to the challenge if you have other solution that is okay because in programming you can find many solutions which can do the same thing so i'm going to end this video now and see you in the next video now it's time to start a discussion about object-oriented programming but first let's create a new project i'm going to call it op for the language select java for the build system in telegay make sure to have the jdk version 17 selected there and also check this as simple code to generate the code for us so click on create now project is going to be created and it was already created now let's double click on main and let's start a discussion about object-oriented programming so what is object-oriented programming object-oriented programming is a way of writing code in the way think about the real world so in the real world more specifically we have objects and those objects have two major characteristics the first is the state let's take for example a car the state of the state of our car is represented by the name of the car by the color of that car by the number of doors of that car and this is this is called the state next what what direct in real life have is functionality so a car is an example using the car example you know a car can move can stop can switch gears and so on so when you're trying to write code you will try to first create the state of an object that you're going to create and the functionality that that particular object has and in the real world if you want to build an object you first need to create a template a plan and the template and the plan is used to create objects with that plan but the plan is not an object it's just a plan for creating objects and in the plan you define the general characteristics you define the state and the functionality that a car will have and using this example with the car we're going to create a class and in programming for creating for the template the equivalent of a plan in real world to a plan in programming a plan in programming or template in programming is a class so we right click on src go to new and we go to new and select java class and i'm going to call this class car i'll press enter and as you can see it added this public class car and curly braces so now we have now we have the template of a car but with an empty template now you don't have anything written on this plan now to add some first to add first the state of a car i'm going to type a few fields a few variables they are called fields in the context of object-oriented programming so i'm going to type private string name then private string color or private string or private let's put here private string model so now we're creating the plan for creating a car and now we're creating first the state representation of of a car color and private string doors but this should be an integer the number of doors so doors all right so now we have the state of a car but now if you know how how how to we're going to use this this this thing that we have here to create an actual object we first need to create a constructor and as the name implies the constructor is used to construct an object and to create a constructor just type public the name of your of your class so car parenthesis and inside the parenthesis we define parameters first is going to be a string name second is going to be a string model third is going to be a string color so with this as you'll see with this constructor we're going to construct an actual object of type car so string color and the int doors now we put curly braces and press enter so now those are parameters which are going to receive a value they are not storing this they are not fields like the ones which are above here those are fields those are the ones which are going to store the state of a car those are simply parameters which their only job is to take whatever value pass here and assign it to the field of the of the of the class so what you need to do here now is to type this and this is used to refer the current the current instance and an instance is an actual object created with the model with the template car so you're saying here hey assign to this dot name so so assign to this name as you can see it's or it has this one usage because now we are using this in one we are using this on line eight so now using the field name and the field name is the one which stores the state i'm going to put equals name so the name that is going to be passed to the parameter here name is going to be assigned to the to the field name as you can as you can see here it's it has also a different color it has this this color because it's it's it's an intelligent way of telling you that this is a field so let's put semicolon and do the same thing for the next one so we have this that's the model equals model this that color equals color and as you can see the fields are colored this is this is how we can identify that this dot doors equals doors all right so now we have a template we have we have the state next we need to and this is the constructor as you see we're going to use this to to pass some values to the fields which are defined here which are defined which are taking the value from the so here we're gonna we're gonna create an object we're gonna the call this constructor and we're gonna pass some values to those to the name to the model to the color and the doors and after that the name the model and the color is going to be assigned to this dot name so it's going to be assigned to the field name to the field model and to the field color and to the field doors now now we created the state so now we have a template and we have the state next we need to add some functionality so I'll type here fun sorry not fun I'll type public and this is a method because it's part of a class so methods are part of a class not functions so I'll start public void I'm gonna call it let's say move I'm gonna have we're gonna put parentheses and curly braces and we're gonna put here sout and we'll say the car I'm gonna put plus when I use this dot car so this current this this dot name we're gonna type here so the current name which was which is for this particular instance when this function is gonna be called we're gonna say is moving so we're gonna put plus quotation marks is moving and you put down there then I'm gonna create another function public also void is gonna return anything stop and this is gonna stop the car and we're gonna have curly braces sout and it's gonna say the car has stopped and let's put also the car let's delete this the car and the name of the car plus this that's let's delete this and type it again so let's parenthesis and I'm gonna type the car plus this dot name plus has stopped so the car has stopped and this those functions are gonna be attached to all the objects that are gonna create using this template that we have now so let's put semicolon at the end so now we have a template we have the state we have the constructor and we have the functionality what this car can do now we need to create an actual object using the template and to create an actual object we go inside the main class the main is also a class as you can see and has a function we have but it's a function with each thing static we'll see what static is in future videos now to create an actual object with our template card that we created we're gonna type here car and while I'm dumping it'll just give a suggestion and do you mean car the car class that you created that template I'm gonna say yes so car I'm gonna call it this law and I'm gonna put equals and here to create a new instance we type and an instance is an actual object created with the with the car template we're gonna type new car so we create a new a new object now now we need to put parenthesis and now as you can see we have we have it's expecting us to pass some values for the name for the model for the color and for the doors and it's expecting us to do that because now we are calling the constructor those parenthesis are calling the constructor that is defined here so now this constructor it's expecting some values for its prop for its parameters to because it wants to assign those values to the fields name model color color indoors so here I will type but let's change this to car and here I will type first for the name Tesla which is a very nice car for the model and we're gonna put and now we're gonna put a comma and then on we pass a value for the next parameter for the model let's say s played and for the color let's say block and for the doors let's say for format three and put a semicolon now what we did is we created first a template this is the template for creating a car which has states and functionality and we also now created an actual object using that state we're using that template using that plan we created an actual object which has some specific values for its for its fields we has the has the name Tesla the model is played the color of black and the number of those four and we can create another car so I can type here car car too you can give a different name if you want here but I'm gonna call it car to gonna put equals new because with our plan we can create as many as cars as you want so I'm gonna put car and for the name let's say type Ford and for the model Mustang and for the color let's say red the number of doors too now what you having now is two objects two actual instances and this process of when when you create a new object is called instantiation because you are creating a new object and now we're having two instances two objects created created with our plan and car with our with our class car that is defined here so with the template we build it to to actual objects now I'm gonna end this video now and I'm gonna continue our discussion in the next video now it's time to start a discussion about getters and setters so what are getters and setters getters are used to get the value of our fields and the setters are used to set the value of our fields and we use getters and setters because we made our fields respectively the name the model and the call private so they cannot be accessed from outside in order to be able to interact with them you need to provide getters and setters and provide getters and setters we go down here and we go to code we go to generate and as you can see it's given us some suggestion is any saying do you mean do you want to generate constructor getter setter getter and setter so let's choose getter and setter let's use and let's choose getters and setters for all of our of our fields but first let me show you something so now if I want to print let's say the name of the first car which is Tesla I need to use what is called the dot notation so I need to type car dot but I don't have any any name here as a suggestion when I press that because that name is private so it cannot be accessed from outside of the class because the name is made here private you cannot access it from outside but if we generate getters and setters so let's press ctrl o or we go to generate go to code and generate so ctrl o actually let's go to generate we go to generate I'll let the insert this shortcut and we choose getter and setter and which is getters and setters for all of our fields and if you click on OK now we generated all this code and first you have the you have you have a getter we have a setter we have a getter we have a setter we have now getters and setters for our fields so now if I go here and I type car one dot and now I have get color get doors get model get name and those functions are called on this specific order that is created here so if I want to output something in the console now I can type here SROT and I can type car one not car one not not called car one car dot let's say get name let's see what you get in the output so now if you run this we get in the output Tesla because card the card that we created here as you can see is also as you can see the second car is gray out and that is because this variable car is never used so this very the interrogator is helping us now we got the name Tesla and if I want to get something else let's say the model color and doors I'm gonna press ctrl D and I'll type here get and instead of name model get color and get doors get doors let's delete the last system not out so now if run this this will display the the value for the fields of the first object which is this Tesla is played black and four doors so now if I run this get Tesla is played black and four so the car that get name is returning the name car that get model is returning the model car that get color is returning the value of the color because if you look inside the getters let's look at the get doors as you can see this is a function which returns the doors and which returns the number of doors for this specific object because the function get doors is called on this specific object that we create above we created here and we can call getters and setters for our now for our second object so let's print let's have the line between our two prints so let's put backslash n and let's simply copy this code ctrl C ctrl V and let's change car now to car 2 so car 2 because now we're getting the fill up value for the fields of the car 2 so now if run this as you can see we have first Tesla is played black for so this is coming from our first object that were that we created above and second to get Ford Mustang red into and this is the values for our second object which is stored in the variable car 2 so these are the getters you can also use setters you can use setters to change the values so we can type here a car so our first object that said and we can set a different name now so I can type here let's say I don't know let's say simply put here car now if I go down here and I add here car let me show you show you a shortcut to output something car that get name that is how to look what happens if I press enter as you can see it put it that it puts it that in it's added to our car like a name inside the print line without us needing to tie that so now if you run this we get Tesla is played black for then I get for Mustang red 2 and I get car so oh the value for our car what the value for our field the name of our first car object was changed to car so you can use the setters to change all the values but again you're not changing the value directly you're not calling the the property the property you're not calling the field directly and you change its value because that will break what is called the rules of encapsulation which basically means to not make to not let your code to be accessed from outside with the setter you just only you pass the of value let's say for the name you pass a value as a as a parameter as an argument and then that value is set to the to the to the field and in this way we don't you don't pass directly values and here you can also add some some checking here some verification but you can put some code here if the name starts with a specific letter to not add it and so on so as you can see you you don't access the the values directly from here because you're using the setters to set the values and the getters to get the value so you never access them directly but if you make you made you make them for public you give the LBI you're gonna be able to access them directly all right now I'm gonna go inside that main and I'm gonna end this video now and see you in the next video now it's time to take a closer look at constructors and Java but first let me show you how we can call the move and stuff function on our objects that we created so we can type here car one car not car one car that move so now we're calling the move function on the car object and car that stop stop and we can also do the same thing for our second car car to that move and car to that stop so now if you run this without that stop so now if you run this now get first we get the car tesla is moving the car tesla has stopped and let's change a little bit here to have a space so let's run this again so we have the car tesla is moving the car tesla has stopped so those functions are called on the on this specific object and then we get you get s lies played black and four for the fields and then get the car for this moving so heck if we have our second object the car for this moving the car for the stop and we get the value for our fields using the getters so you get for the most unread to and car now let's take a closer look at constructors and let's say that whatever reason the person which creates this object doesn't want to provide a value values to all of our parameters so here when you construct or object when you construct your object you using the constructor I cannot say let's say I cannot let the last parameter unfilled because it will show an earning so it expects a parameter so what you can do is that you can create a first let's say an empty constructor and for that I'm gonna type here public car and I'm gonna put only parenthesis and curly braces and now this empty constructor is gonna call the the the parent or the first constructor the constructor which does all the initialization and we're gonna pass for the name do we default we're gonna pass for the parameter default values we're gonna pass name for the model model for the caller caller for the doors for the doors are gonna put zero so if somebody from outside the class creates an object and is doesn't provide any value for our for our for our constructor those values are gonna be used for the constructor so this what is doing this and is calling the constructor which is here this is what this is doing this parenthesis default values is calling this constructor so now if I go here and I create another car so but let me delete this this code because it will make things confusing so let delete this code and if I go down here and now if I delete all the values for our car too as you can see everything is fine let's press ctrl G because I need the to output and the console the values for car to select the list those they delete as it is so now let's delete the values inside the constructor all right so now if you run this as you can see you don't have an ordering now because now it's using this constructor that we have here which is an empty constructor which is calling the constructor from above and it's passing the default values because now here not passing any values for the constructor so now if you run this we get the car name is moving the car name has stopped and get name model course so we get our default values because the empty constructor is called and then the constructor is calling the constructor that is defined here so we can also go and we can create another constructor here so I can type here public and provide the value only for the name public car and I will type string name I'm going to put curly braces and now I will type this and I will pass the name which is going to be pass here and for the next value I'm going to provide provide we're going to provide default values when I type color sorry model should be model color and number of those zero and I can do the same thing for with another constructor so I can provide another constructor and provide values only for the model model and color so model sorry string model and here instead of passing this default value we're going to pass model and I'm going to show you how all of this works immediately model semicolon semicolon here and here and here we have name it should be this one name all right and now let's press ctrl D no it's not working so let's copy this and let's pay let's paste it here so now I'm going to provide the value for the model and a value for the color so I'm going to type here string color so I'm going to type here color and model semicolon and now I can copy this and I will call the first constructor which is gonna but I don't need to do that because that we already have a constructor which provides the values for all the world of all the fields so if you create your object and you want to provide only the name you provide the name and the name is going to be assigned and the rest of the field is going to have going to have those three field values if you provide only the name and the model then in the color in zero is going to be the color in the number number of dollars going to be is going to be color and zero is going to have those default values and if you provide the name the model and the color but not the number of doors is going to have the number of doors is zero so if I go here and with look if I put here Ford now if I run this now it's using the constructor with so we have we have for the model color so it's using this constructor what is that constructor so it's using this constructor here because now we're passing a value name name for our for our class and the next ones are a defaulted and you can do the you can do here provide another value you say the model Mustang and now it's gonna use this constructor which is here this constructor and it's gonna get the name that we type the model that we type is gonna pass them to the primary constructor for to the parent constructor if one and for the color and doors is gonna have those default values and so on you can provide name could model and color and for the doors you're gonna be zero so this is how you can use multiple constructors with your with your classes and I will see you on the next video now it's time to start a discussion about inheritance so what is inheritance inheritance basically means creating a class using another class you know maybe wondering why is this useful this is useful let's say that you want to create a class B which is a slightly different from a class A and let's say that the class A has a lot of fields and functions which are particular to that class A because it's representing some something and instead of creating a class B and adding all the fields and functions and metals that the class A has you can inherit all of that and on top of that on top of that you can add the new functions and new new fields which are specific to the class B but they are not specific to the class A so this is what inheritance is therefore let's go down here and as you can see here I deleted the car class because I cleared the car class inside this file so I type class car and it's gonna have a few fields private string name private string model private string caller and private int doors now let's generate a constructor I'm not going to generate getters and setters because we're not going to use them so let's generate the constructor for all the fields now down here let's create but let's add two functions here let's say fun not fun let's type public void move and it's gonna say sout it's gonna say the v equal let's put here plus this dot name it's moving and now we're gonna get another function public void stop it's not gonna take any parameters it's not going to find any parameter and it's gonna say sout the vehicle has let's put here vehicle plus the name this that name the vehicle has stopped now let's create another class called plane so I'm gonna type class plane and type here private string name private string model private string caller private int doors and private int engines because the plane has more than only engine let's generate let's generate the constructor so let's go to code generate constructor for all the fields and let's copy those two methods that we have here and let's define for the plane to for the plane also now what we have now is first is that we have code repetition so we have both in both both classes we have the function move and the function stop and we also have fields which are common to those to the classes both classes have a name and both classes have a call or both classes have a model and it doesn't make sense to put all of this code inside of each class it makes sense to create another class called let's type here class and this could be gonna be called vehicle which is gonna represent a general generic vehicle this is what is gonna represent and here I'm gonna define some fields which are common to all the vehicles so I'm gonna type here private first name all the all the vehicles have a name so private string name and let's say private string caller so those are fields which are common to all of the vehicles which are common to also to the car and also are common to a plane so let's generate the constructor for our vehicle so let's generate constructor and all the vehicles are gonna move so they are gonna move in specific ways but you know that's all all vehicles gonna move so we can put here the move and stuff method and what I can do now here is I can delete those so I can delete those I can delete those here also and now what I can do I can type here extends so to inherit from a class we type the extends keyword and we type here vehicle so you put vehicle and now as you can see we have an underline because it's expecting to pass the values to the constructor of the class from which we are inheriting so it's expected to pass down some values here and because the name and the color are defined as fields inside the vehicle class we're gonna delete them from our so the name and the color is gonna be deleted from our from our class because they are gonna be used by the super class so I'm gonna delete that we're gonna name and so I'm gonna type here super and now we're gonna call the constructor of this class from which we are inheriting and we're gonna pass the name and the color so look now how how small our class has become because we inheriting all of that and you can do the same thing to the plane class you can we can inherit from the vehicle extends vehicle and again it's expecting some values too so let's delete the name because all vehicles have a name and all vehicles have a color unless let's just let the model and doors and engines because not all vehicles have not all vehicles have doors not all vehicles have engines with the butter plane has the doors and a model and engines now let's delete those from here let's do it from here so super means calling the constructor from the parent class from which we are inheriting from the super class if you want so I'm gonna I'm gonna pass to the super class the name which is pass here as a parameter and the color as you can see put semicolon now we'll look at this code how beautiful it is so we inherited the the state and functionality which a vehicle has and we inherited that in our car vehicle in an hour and in our plane vehicle and now what I can do up here I can go up here and I can type car let's call it car we're gonna be equal to new car and now we're gonna respect some values first gonna be the name again Tesla and let's put for the model as played and for the color let's say red and for the doors let's put for let's create another class and now let's create a plain class so plain plain equals new to create a new instance plain and I'm gonna pass some values here let's say boring and for the model I don't know what model okay I'm gonna type here simply model and there's gonna be let's say white and and let's say white and blue and for the doors let's put I don't know nine and the number of engines let's say four I don't know if this is a correct number but I'm just passing some values now if you go down here and you type car dot look what we have we have the function move and stop so we can call the function move and stop even though they are not declared inside the car class but because they are declared inside the super class we can use them inside our own class and we can do the same thing for plain I can type here plain so let's actually call them so car that let's pass move first car dot stop and let's say plain dot move and plain dot stop so now if you run this we get the vehicle Tesla is moving then the vehicle Tesla has stopped so as you can see it's using the functions defined in the parent class in the class vehicle and saying the vehicle Tesla is moving and the vehicle Tesla has stopped and then it's then it says the vehicle bearing is moving and the vehicle bearing has stopped now what we can do is that you can override those functions so we can we can override those functions inside our let's say like I want to override the fun the move function inside the the plain class because the plane is moving in a specific way what I can type here or let's press ctrl or and I can as you can see override move and stop so let's override the move and super that move means call the super method from the class from which we are inheriting and I'm gonna add here a saut which is gonna say moving by flying so what we did here is we we took the generic behavior which a vehicle has which is simply moving and we add the some new functionality some new behavior which is particular to a plane because the plane is moving by it's moving by by flying so now if you run this look what you're gonna see in the output we have the vehicle Tesla is moving the vehicle Tesla has stopped then get moving by fly flying so get this call and then it's using super that muscles it's calling the function from the parent class from the class from which we are inheriting and as you can see we have this override here so we're overriding that behavior and on top of the moving behavior that the generic class provides we add so new behavior and in in a practical case imagine that you have you have a view in Android and they want to to build let's say a round button we can inherit all the functions and fields and all that logic which makes a view to appear on the screen and we can add some new lines of course some new logic some new fields some new behavior some new methods which are gonna take that view and on top of that view is gonna change it in a particular way to make it a button so this is the power of inheritance and it's very very very used in in Android particularly in Android programming so now I'm gonna end this video and see you in the next video now it's time to start a discussion about the static keyword so I'm gonna go inside the car class and what I will do now is I will create a function public static void it's gonna be called display data but let's first remove the static to show you how how the static keyword works and we go back inside main now in order to call the display data function need to use an instance you need to use an object or create it with our class in order to call it so to call the function so if I type here card to that display data I can use it but without an instance I can't call that function so let's actually delete this code this code also let's delete this object so now if I type here car that display data as you can see I can call it because I have an object and the functions are the methods are attached to do with this object what you can do with the static the static here so if you declare this function as public static is that you can call this function without without an instance without need that you need needing to create a new object I'm gonna call I'm gonna say display data so now if I go inside main now if I type car dot and I have the stop or move functions and the getters and zettles but the the display data is not not it's not here so I am to to use the the display data function what I can do is I can type here car so the class and now I have the function display data because what the starting keyword does is it's making the function of it it's making the function to belong to the class and not enough to an instance of a class so it will belong to the class itself and not to an object created with the class as you can see here we just type the name of the class and display data and you can do the same thing with variables so I can type here public static let's say string text equals text and now if I go here what I can do here is I can type car dot text so now I can access those without without creating an instance of how car we just call them on the class because they they belong to the class and not to an instance of the class they are also called class variables and class functions and those which we don't have the the static keyword are called instance variables and instance for instance methods so this is how you can use the static keyword and scenarios where you can use it's let's say that you want to have some constants so you can create a class again you define your constants and in that class using the static keyword and then you call the class and the the constants that you want to use so now I'm gonna end this video and see you in the next video