ssalamualaikum warahmatullahi wabarakatuh. Welcome to Amigos Code. My name is Nelson. And today I'm really excited to bring you this awesome course that I have for you here. So this is almost a four hour course that you have requested. So I'm gonna take you from the ground up and teach you Java in a way that when you see the examples, you will fully grasp the concepts. So that's the goal of the series. So this is actually two core series. So this is the beginning level. And then after that, we will follow up the second course, which at the end, I want to make sure that you can start writing applications. Right? Because that's the goal. Really? Right. So I want you to start building applications, applying for jobs, and you'll see that Java is not that difficult. So you've been requesting it for a very long time. And to be honest, I just took my time to package up the content, really careful so that I give you the best content ever. So I'm really excited. And I hope you are. And you should know that learning Java is very essential. So just so you know that Java is still the top five programming languages for this year. So you can imagine once you learn Java, the opportunities will be quite a lot. So without further Ado, let's go ahead and learn this awesome programming language. All right. So before we kick off this course, I want to make sure that you are part of the Amigos Code community. So go ahead and join the private Facebook group as well as the discord because they are over combined. I think around ten0 people all together and the community is growing and you should be part of it if you are not. So if you have any questions you can go and ask on the group. So that's the way of interacting with fellow students as well as with myself, then what I want to request from you is that you practice as I teach. Right? I don't want you just to sit there and just just watch what I'm saying and what I'm typing, because that's not the best way of you learning. Right. So I really want to add value. And please do take my advice. So practice as I teach this. So for now, without further Ado, let's crack on to kick off this course. Let's go ahead and learn about the Java Development Kit or simply known as the JDK, as well as installing it. So the JDK is simply an environment that gives us everything that we need to develop Java applications. And inside of the JDK, we have a few things. One, we have the Java runtime environment or the JRE, and this contains all the libraries and classes for us to develop these applications. But more importantly, inside we have something known as the JVM, the Java Virtual Machine. So this is what is actually responsible of executing your Java programs. I'm going to explain more about the JVM in a second. But for now, let's understand the JDK version history. So everything started back in 1995, where the JDK Beat was released, and then in the following year, the JDK one0 was released. So 1996, then all the way to March 2020, we have the current version, which is JDK 14. And I'm recording this video in July. But in September, a new version will be released, which will be the JDK 15. So you can see from 14 to 15, there is a six month gap. So let me now take a step back and go all the way to JDK one eight, which was released in March 2014. So from JDK one eight, since the Java nine was released in September 2017, a new version has been released every six months. So you can see from September 2017, JDK ten was released in March. So there's a six month gap between those two versions, the same with JDK eleven and twelve and the same with 13 and 1415 and 16. And finally, 17 and 18 and more versions to come. So as you see, there are many versions to choose from. So which one that you should be using and learning as a Java software engineer? Well, you can see that we have the LTS or long term support, and this means that that specific version has a long term support. So when it comes to picking a version to stick with, you should pick a version which has the longest term support. So in our case, the latest version that has the longest term support is Java eleven. So Java 17, you can see that that hasn't been released yet. So that will be only released in 2021 in September 2021. So the long term support for Java eleven will be until September 2026. And also for the Java one point, I as a longer term support, which will be up to December 23. So most companies when they choose a Java version, they will choose one which has a long term support. So you might go. And then, for example, all the features of Java 15, Java 16, but they don't have the long term support. So companies often they will not use those versions. So for you, it's best if you learn a version that has a long term support. All right. To download the JDK, navigate to Google and type JDK, and then download and pretty much click on the very first link. And right here you see that we have Java Se downloads. So Se stands for Java Standard Edition. So you have different flavors. If you are going to build enterprise applications, then you might use the Java EE version. But for this course, we're not going to build any enterprise applications. So we're just going to stick with the Java Standard Edition. So right here. Remember showed you that the latest version is the Java 14 right here. And you have a bunch of links. So let's find the long term support Java Se eleven. And right here you have the JDK download. So Oracle JDK and then download. So you might or might not see this message right here, but it simply says that the JDK license has changed. With Java, you have two versions. You have the Oracle JDK. So this is when for you to run Java in production, running your Java co to real users, you need to have a license or you can adopt to use the Open JDK. So for this course, we're going to use the Oracle JDK because nothing changes. So let's go ahead and scroll down. And right here you see that we have versions for Linux, macOS Solaris, and Windows. So depending on your operating system, go ahead and pick the Career Red version for me. I'm going to pick the Mac OS installer, and then I'm going to take this box download. And there we go. So you can see that it's asking me to create an account. So let me do that quickly. There we go. Now I'm going to create the account. So I've actually verified the account on my mobile phone. So let me close this. Let me log in, sign in, and there we go. So you can see that it's downloading. Now let me go ahead and pretty much click on the DMG and I'm going to double click on this file right here. And the installation process is very simple. So simply continue install. There we go. My password. And so you see that now we have successfully installed JDK eleven. So I'm going to move to trash. And there we go. One of the reasons that I pick Drive eleven is because it has long term support. So if you apply for companies, there will most likely be using Java eleven or Java 1.8. So usually companies that take long to upgrade these Java versions, and you can imagine the amount of software built on a specific version and then to upgrade the version. Sometimes it's not a really straight process, but feel free to experiment with our the versions that you see, everything that we're going to cover in this course will be applicable for every single version. So this is just something to bear in mind. You're not just tied to Java eleven. So this off. Now let's move on. In order for you to write Java applications, you need an IDE. So what? An IDE is simply a text editor with lots of features that facilitates the development of applications. So the most popular IDE for writing Java applications, it's called IntelliJ Idea. So I've actually got a free course on my website where I teach you everything you need to know about this awesome IDE for free. So go ahead and enroll to learn more about this awesome IDE. But for now, everything that I'm going to show you will be really straightforward. And then at the end of this course, I highly recommend you to enroll. Now let's go ahead and download IntelliJ. So I'm going to click on Download, and you have two flavors. So ultimate or Community. So the ultimate, you need a license for it. The community is free and open source. So again, you can pick the actual operating system, Windows, Mac, or Linux. For me. I'm on Mac. I'm going to pick Mac. And then I'm going to download the community. So here you can see the actual differences. The differences are mainly when it comes to writing enterprise applications, for example, using Spring or Java EE, Quarks, so on and so forth. And also we have swagger JavaScript and database tools. But to be honest, I always use the community because it does everything I need. So let's go ahead and download the community version. And there we go. So just give me a second. Right. So that has completed. Let me click on it and then drag this to applications. And there we go. So you have now successfully installed IntelliJ right now. Let's go ahead and configure IntelliJ quickly. So let me open IntelliJ. I'm going to open. And then I'm going to confirm continue. Don't send anything right here. You can pick the dark or light theme. So I'm gonna go with the dark theme. And what I'm going to do here is simply skip remaining and set defaults. There we go. Now, let's quickly configure IntelliJ to use the Java eleven version that we installed. So click on Configure. And then right here, you should see that we have a structure for new projects and then no SDK. So we're going to change that. So click on the drop down, and you can see that we have Java eleven, and then make sure that we have SDK default to eleven. So right here, you see that we can pick from different Java versions. Right. So 14 and then twelve, sign and so forth. But make sure that the actual project language level it is set to eleven. So now click on Apply. Okay. And one more thing that I'm going to do is simply increase the font size. So right here. And then right here, let me simply search for font and then into general. Right here, we do have the actual font. So I want to change this to something very big, so you can see exactly everything I do. So there you go. Now let me simply apply. And let me also click on key Map. And right here, I'm going to select the Idea Classic. So this is the key binding that I prefer when using IntelliJ. So this is the one I recommend to most people, but if you want to keep it as a default, that is absolutely fine. Now let me simply apply. And then. Okay. And there we have it. We have configured IntelliJ. All right. Let's go ahead and create our very first Java project with IntelliJ. So go ahead and create a new project. So click on the very first button. And then right here click Java Net. And then go ahead and click this box right here. So a command line app. So this creates a simple Java application that includes a main class or actually a main method. Now and then right here, the project name. Let's go ahead and simply say learning. And then and then Java. And you can see that we have a base package. So right here it says com company. So here you could just have your own domain or name. For now, let me simply say com Amigos and then code. I want to touch on packages later. But for now, just change that according to your domain or name. And if you don't have a name or domain, just leave it as default. And then pretty much just click Finish. And there we go. So you can see that now it's actually giving me some tips. So I'm gonna say do not show tips. So if you wanna learn all the tips, go ahead and check my website where I teach this awesome IDE for writing Java applications from start to finish. Now let me simply put this full screen and there we go. So right here, you can see that we have a couple of tabs on the top left hand side. So right here, I'm going to click on Project, and you can see that we have some folder structuring right here. So don't worry about this too much. For now, I'm going to teach you everything that you need to know in a second. But for now, let's go ahead and write your very first Java application. So simply type system, dot and an out dot print line. And then within quotes, simply say Hore, my first Java app. And let me delete this line right here. So simply remove that piece of code. And there we go. So I know I haven't explained what all of this means, but for now, just copy along, because I'm going to teach you literally everything about this programming language so that you understand. But for now, this line right here simply prints to the console. Here my first Java app. Also, one thing that I want to point out, make sure that you type exactly what I have. So system with capital s and then dot out println. And then within these parenthesis, make sure that you have double quotes and not single quotes. And also make sure that you have this semi column at the end. So if I remove that, you see that I'm getting an error right here. So it says expected semi column. So this is how Java programming language works. It's very verbose. You need to specify semicolumns and double quotes, unlike some other languages, such as Python or JavaScript. Now the way you run your application is simply by right clicking. And then you can simply say run Maine. Right. You can run main, or you can click on this Play button right here or this one right here or on this one right here. So top right corner. So there are many ways of running your application. So let's simply go ahead and pretty much just click on Play. There we go. And then run. Just give it a second. And there we go. So you see that right here. You have here my first Java app. And Congratulations. This is your very first Java application. It's very simple, but this is the beginning of your journey towards becoming a Java software engineer. Let me explain to you how the Java syntax work. So let's begin from line number one. So here you can see that I do have this keyword, so package, and you're going to learn about keywords packages, classes, methods throughout this course. But for now, I just want to show you how the syntax is structured. So for every single line that you have, you can see right here that we have semi column. So if I remove this semi column, this is actually an error. So you can see that if I try and run the program, this won't work. So if I run it, you can see that I do have an error. And it says expected and then semi column. So this failed to compile. And you're going to learn about compilation next. Now, if I close this, you can see right here we have public class. Again, don't worry about this because you're going to learn about classes. But what I want to show you is you see where we have the curly brackets. So this curly brackets means that inside of it we can have some other statements. So right here, if I cut this for now, so we have to open curly brackets and then close curly brackets. And inside you can see that we have this public static void main. So again, this is a method, and you're going to learn about a method. And you can see here. So we have again, curly brackets opening and then closing curly brackets. And inside we have systems or outdoor print line. And then you can see that we have a semi column right here. So this is because it's a single line. So if you have a single line, then you must start with single line here. You see that we have double quotes. So if you were to use single quotes, this won't work. So this is a string and you're going to learn about strings and strings. You must have double quotes. So I could, for example, say car. So this is a data type that you go into as well. But for now, just watch what I'm doing because I want to show you the actual syntax. So if I say Car, and then a equals to this time, I can use single quotes because of this data type right here called Char, whereas with strings, we must use double quotes. So what I want to convey to you is that throughout this course, I'm going to type some code, and what I want to do is to actually follow closely. So as I type, for example here, if I type a lowercase S, you can see that this is an error. Right. So the actual Java syntax is quite repose. So here this needs to be the actual capital S and a system. So when I type, make sure you type exactly what I have on the screen. Right. So also practice. I've been begging for you to practice throughout this course, and I always beg my students to practice, because that's the only way that you're going to learn Java. So if I remove this, and another thing that I want to tell you is that think of Java as learning a new language. Let's say that you want to learn Spanish, you need to learn the vocabulary, so on and so forth sentences, and basically the Alphabet, so on and so forth with Java is the exact same thing. So here, for example, we see you have package. So this is, for example, la or combo stats in Spanish. Right. And then you have public class, and then you have void. So basically these are keywords that you need to learn. Right. So think of Java programming as a new language that you need to know how to operate with it. Right. So how the syntax works. And also we have some rules. For example, as I said, the curly brackets, semicolumns. And, for example, here you have string. And then this is instead of curly brackets. So this is square brackets. So if I have, for example, this, it won't take it. Right. Because this is the actual syntax of this language. So as I said, make sure you follow closely and type exactly what I have on the screen. And if you have any issues, go ahead and let me know. And I'll be more than happy to assist. Join me in the next one. All right. Inside of IntelliJ, go ahead and expand the project tab. And inside expand the Learning Java folder. And then inside you should see SRC, which stands for source. And then inside you see that we have the package that we have created to com Amigos code or your domain. So let me expand that. And right here, you see that we have this class right here. So main, you don't see the actual extension, but right here you can see that it's called main Java. So let's actually invoke the compiler ourselves. So we see the actual Byte code, which then will be fed into the JVM. Right here. You see that we have the terminal. So go ahead and click on terminal. And this is my terminal. So right here, you can see that I'm inside of learning Java. And if you want to learn more about how to use your terminal command line, go ahead and check my website where I bought a free course teaching you how to use your terminal or command line, because it's a vital skill that you should have as a software engineer. So what we want to do is CD into SRC. So right here. So this folder SRC, and then come and then Amigos code. So navigate to the actual path that you have specified within your package. So now I'm gonna press enter. Now I'm going to type LS or Dir on Windows. And you can see that I do have this file right here called main Java, which is this file right here that you see. Now, what we want to do is actually invoke the Java compiler ourselves. So Java compiler comes with the JDK, and the way you use it is as follows, so let me press control. And then L to clear the screen or simply clear the way that we invoke the Java compiler is simply by saying Java and C and then space. And then what we want to compile. So we want to compile the main dot and then Java. And then if I press Enter, there we go. That's finished. If I type LS, you can see that. Now we have two files. So we have the main Java and main class. So what I'm going to do here is and also you can see that we have this file which popped up here. So what I'm going to do is actually click on main class. So let's open this class and see what it's inside. So I'm going to accept this. And right here, you see that. So if I collapse this, you'll see that this file is the exact same thing as our main Java. So this actually is a source code recreated from a dot class file by Intelligent ID. Right. And this is powered by this Fern flower decompiler. So this is actually is reading the Byte code and then transforming it into Java code. So what we want is to see the actual file. So right here, what I want to do is close this. And then in my tool bar, I want to go to view. And then right here, you see that we have show Byte code. So let me click on it and have a look. So this file right here, this is the actual Byte code which will be fed into JVM. So this is what the JVM understands. So right here, you can see that this doesn't mean anything to both of us, but the JVM understands. So from our point of view, we literally don't have to learn what all of this means. So you can see that it's using some machine code. But basically, this is what will be fed into the JVM. So that our program runs now that you've seen this Byte code from our main Java. So right here, you can see that this is compiled from main Java. Let's see how this file right here is fed into the JVM and then executed. So let me actually close out of this. So there's this little button on the top right hand corner, and there we go. So I can simply close this. Now, if you want to see Byte code for a different class, you know how to do it to run our Java program. Let's go ahead and open up the terminal again and let me clear this. And what I'm going to do is go back to learning and then Java. So CDA and Oops, dot, dot, dot. So I'm going back three folders. So right here. You see that now I'm inside of learning and then Java. Now, the way that we invoke the JVM to run our application is simply by running the main class. So every single Java program should have this class right here. And inside it should be this method public static void main string. And then you will learn about this and an arc. So this is an array. You will learn about a raise later. So every single driver program should have this class in this class contains this method. So static void main. And this is the main entry point to execute your program. So many other languages have the exact same concept. So now let's go ahead and invoke the JVM and actually need to be inside of SRC. So CD and then SRC. So inside of this folder right here. So, C, and you can see SRC. Let me clear the screen and to invoke the JVM, simply type Java, and then we need to specify the fully qualified name. So I'm going to explain what a package is in a second. But right here you can see that the package is com Amigos code. And inside we have the class called Maine. So we need to say com Domingos, and then code dot and then main. Now the main will refer to the main dot class. So if I run this, you can see that. Now we have here my first Java app. Now let me actually go back to com and then Amigos code, and let me simply RM and then main dot class. So now if I do an LS, we don't have it anymore. Let me go back to SRC and then clear the screen. And if I pretty much just run the same command, so Java, and then calm Amigos code. Maine, if I press enter, you see that could not find or load main class. Right. Because we deleted the file. So remember, what we need to do is simply CD into com and then Amigos code, Java, C, and then Maine, dot, and then Java. Enter. There we go. Now we have the main dot class again, CD, dot, and then dot, dot inside of SRC. Let me click the screen and then Java, and then com. Amigos code, and then domain enter. And you can see that it works. All right. So we've managed to compile using Java C on the terminal and then run our program. So right here, you see that we have this main class. Right. So what I want to do is, you see, we have this out folder. Right. So we have this out folder. So let me go ahead and delete that. So I'm gonna delete that. And then basically the purpose of an IDE, or in our case, IntelliJ, is to basically, I compile and run the application on the JVM instead of us having to do everything manually. Right. So this is why we have the play pans. So if I run the program, and if you notice closely at the bottom, it says building, and then. So you actually didn't see it, but somewhere around here, it was saying building, and then it run the actual application. Right. But now you can see that we have this out folder, so I deleted it. But we have this out folder. So if I expand this out folder, you see that we have production learning Java, come as code, and then check this out. So this is the actual main class, which then gets executed by the JVM, so that, you know, we don't have to manually compile our applications. I just wanted to show you how it's done behind the scenes, but IntelliJ will take care of things. If you have any questions, go ahead and drop my message. Otherwise, let's move on. Let's learn about packages. So when we created this project right here. So remember, we had to specify the package come and then do whatever domain that you have. So in my case, com Amigos code. So what a package is it's simply a way of you organizing your classes together? Right here. Let me simply show you that the actual package is simply a folder structure. So let me actually right click and then reveal in Finder. And right here. So hopefully you can see that inside of SRC, I do have com, and then a mini cost code. And inside we have these two files. So main Java and main dot class. So let's remove this main dot class because we don't need it. There we go. You can see that a package is simply a simply a directory structure that allows you to group classes together. So right here, we could go inside of the com Amigos code and create a new package. So let me go ahead and right click inside of this package. And then new. And then you should see that we have package, and let's simply name this package as full, and we're going to create a new package inside of the comics code package right here. And then bar. Now, what is called about packages is that you can nest them. So inside of Bar, you could have another package. And right here, let me simply say bar and the bar. And you can see that we have bar, bar, bar, bar. And again, inside of Full, we could also create another package but let me go back. And now you see that. So if I make this a little bit bigger, there we go. So you see that inside of bar, we have a net folder and inside of bar bar, it's empty. We don't have anything inside and inside of full, it's empty. So let me go back to IntelliJ and invite a full bar bar. Let's create a Java class and simply name as bar and make sure it is capital. So all classes in Java should start with per case, enter. And now you see that we have this public class bar. So you're going to learn about everything, but I just want to show you exactly how packages work. And again, let's go ahead and inside of who we can also right click and a new and then it doesn't have to be a class, but it could be a file, for example. But let's go ahead and create a class and simply name it as full and then enter. And you can see that now everything is organized. So packages really allows you to group and organize classes for your applications. So if I go back. So I just want you to see that this is just a folder structure. You have the bar or Java any side of full you have full or Java. If you have any questions on packages, please do let me know and I'll give you further explanations. So let me just close this food Java. And the same with bar Java within this class right here. So main Java, let's go ahead and about comments. So you saw that when we created this project, we had this line right here. So I think was right your and then code. And then here. So what this is is simply a comment. So if I run this main method, so I'm going to run it, you can see that we have here my first Java app. Now, comments are useful when you want to document your code, so they don't do actually anything. Right. So if I was to, for example, at four and then for and you can see that this line right here now becomes a comment. And when you run your program, comments are ignored. So let me show you. So if I run the program again, you can see that now we have nothing on the console because we have commented out this line. So if I remove the comment and then run again, you can see that we have or my first app. So obviously here you would say this prints to the console. So this would be your comment. Now with comments, you can have two types. You can have a single line comment, which is this one right here. Or you can have a multiline comment. So the way a multiline comment works is as follows, so simply type for and then star and then start again and then forward slash. So now from this point onwards, if I press enter. So in between the stars, if I press enter, you can see that I do get the stars. But basically anything that I type in between the opening line for multiline comment and ending line for multiline comment, I can type anything here. Right. So none of this will be executed. So right here. Again, let me simply say that prints to the console. And let me say this is a line comment, and you can even indent this if you want, just like that. But this is how you write a multiline comment. So comments are useful to document your code, and it should definitely have them when you have a piece of code, which is not trivial for the reader. So comments are there to help other developers when they see your code to understand the functionality of what you wrote. In our simple scenario, we simply have system dot out, dot print line or my first travel app. Right. I want to teach you about. Right. I want to teach you what variables are. So to illustrate the example, I've got this box right here. Right. So variable is simply a box. Just think of it as a box. Right. And inside of this box, you can store only and only one thing. Right. So for example, I could take this sticker right here and I could store inside of the box. And now if I want to access my variable. Right. I can simply refer to it. Right. So this variable or this box right here has a name, and this is how you actually get hold of it. Right. By its name. So if I remove this from here. So when you define a variable, you to specify the actual data type, and we're going to cover data types in a second. But you need to specify what goes inside of this box or variable. Right. For example, if I want to, I can take my phone. By the way, it's a pink phone. Don't laugh at me. I could take this phone and then store it inside this box. Right. So now I've got a variable that holds my phone. So variable is something that you will use quite a lot. And also, I'm going to show you later on arrays, which you can then store more than one thing inside. So for example, I would store both the phone and the sticker or a bunch of other things inside. Right. So we're going to cover that later when we work with arrays and also data structures, which is very important. But for now, just remember that a box, not a box, a variable conceptually, is just a box that you can store anything. Right. For example, if you want to store. So let me tell you, for example, these two letters. Right. So if you want to store, for example, a serious, not serious a sequence of characters, for example. Ka. Right. So this is a sequence of characters. Right. Just imagine, this is like a name. You could store that inside. Right now, any time that you want to find out the contents of this box, right? The actual value, you simply call its name, and then that will give you a just like that. So I hope you understand what variables are. And again, don't worry, because I'm going to show this in code, but I just want to see it first because I think it will make it easy for you to understand. Now, let me go ahead and jump into IntelliJ and show you how to work with variables. As I've explained a variable, it's simply a placeholder where you can store values. The way you create variables is as follow. First, you need to decide on the data type. So we drive. You have two options, you have primitive data types or reference types. And the syntax goes as follows, let's say that I want to create a box where I want to store a number inside. So I want to create a number inside. So here let's simply define first the data type. So I want to show you exactly data types and the differences between primitives and reference time. But here this is a primitive. So here what I'm saying is that I'm going to have a box of type Int. And now I need to name my box. Right. So in my case, I want to say number and then equals two, and then any value. So in here, let me see. Let's say 100. Now let me explain this again. So in here, this is the actual data type. So in this box, I can only store numbers. If I was, for example, to store a sequence of characters, for example, Amigos code, you can see that I'm not allowed to do it. So if I wanted to store, for example, Amigos code, which is a sequence sequence of characters, I'll simply need to have another variable. So this time just type string. So this is the actual data type for creating sequence of characters. Now I'm going to name my box equals to brand. No, but the actual variable. And then here I'm going to say Amigos, and then code. And it is as simple as this. So data type the name of your variable, and then the content inside. So remember, with variables, you can only store one and only value inside. And later, I'm going to explain how you can store more than one value inside of a variable by using arrays. But this will be later down the course. So there you have it. This is how you create variables. Now, as I said, you have two data times. When it comes to creating variables, you have primitives, which is, for example, Int or for example, or double, for example, if you wanted to store decimal numbers. So for example, 100.1, if I try with it, I'm not allowed to do it. Right, because this has decimal points. For this, I need to use the double data type. So we've got two data times we go primitive data types, which is simply for storing simple values such as numbers and single characters. And then we have reference types or objects to store complex data types. For example, if I want to find out the current date. So here I can use this data type. So date. And right here, just make sure that you have this import statement just so that it works. But I'm going to explain what this means in a second. And then here I'm going to say equals to and then new and then date. So you can see the way that we create. These are a little bit different. And this is because these are special. So anytime you see new, it's because it's a reference type. And this means that the data type in itself, it's more complex than primitives. So primitives are numbers and single characters. If you have any questions on how to create variables, please do let me know. But next, let's go ahead and learn about primitive data types. And then after that, we're going to learn about reference types. All right. So let me show you all the primitive data types. So we have Byte. And right here I'm going to specify the actual data type, and then I need to give it a name. So right here I'm going to say D, and then bite. Right. So this is the actual name. Now, you might be thinking, well, I could name this bite, but I'm not allowed because Byte is a reserved keyword in Java. The same with public static void class package. So I also name these, for example, package. I'm not allowed because it's a reserved keyword. So that's why I'm saying D. And then bite equals two. And then remember, the Byte stores whole numbers from -128 to 127. So if I say -129 try and store that this will not work. So this has to be 128. And there we go. And even if I put 129, you can see that IntelliJ is actually telling me that I need to provide an Int. So -128 the next one is short, so the short equals two. And this stores -32,002 plus 32,000. So I'm going to leave the actual table, so you can see the actual ranges. But let me just add silly numbers. For example, there we go. Oops, it's actually more than 32,000. So there we go. The next data type that we have is Int. So the Int equals two. And again, I it also stores whole numbers. So we can store something like this. And you can see that this is too big. So let me come and see on this. And this has to be lower than the actual Max number allowed. And then we have a long and then and then long equals two. If I paste the previous number, you can see that it should work on actually it works. But what we need to do with longs is add either a lowercase L or uppercase L. So I prefer uppercase L. And right here. So these four data types, they allow you to store whole numbers. And the difference really is the actual size in memory. Right. So Byte is one Byte. Sure is two bytes in is four bytes and longest eight bytes in memory, obviously. So this will take a bigger number. Therefore it requires more to be store in the memory. So as I said, these allow you to store whole numbers. Now, if you want to store decimals, this is when you use this when you use the float, and then float equals two. And then right here, I could, for example, actually let me simply say Pi. Right. I could say Pi equals two and then 3.4. Right. So it's actually bigger than that. But you can see that the float also is giving me an error. And this is because I need to say capital F or lowercase F. Then we have double. So I can say double. And then let me simply say double and then Pi. This is the name of the actual variable, and I can say 3.14 and then one five. So the difference between float and double is that float is sufficient for storing six to seven decimal digits, whereas the double is sufficient for storing 15 decimal digits. And we're almost done with the actual primitive data types. So next we have Boolean. So right here boolean. And let me say is and an adult equals two. And Boolean simply takes two options, either false or true. So boolean as to so true or false values, basically. And finally, we have the chart, and this allows you to store single characters. So name and then initial equals to. And let me simply say a for Amigos code and make sure that this is within single quote and double quotes. And there you have it. So if you want to print all of these values to the console, let's simply say system dot and then out dot and then print line. And you can see that this is too much. So let me show you a nice trick. Simply say S-O-U-T enter. And there we go. So you can see that we have system dot, out dot, print line. Now I'm going to print the bite. And then I want to press command and D a couple of times. So we have the short long in and then Pi and then double Pi Ops. And finally we have two more. So in an adult and then name initial. These are the variable names. So what I'm doing is simply print them out to the actual console, as we did with your very first program. So now let's go ahead and run this. So I'm going to right click and then run main. And there we have it. So you can see that we have all the values here. So one last thing that I want to show you is if I Scroll up, you see that sometimes these numbers can be really difficult to read. Right. So you don't know whether this is 78 million or 7 million or 78 billion. So on and so forth. Right. So what we can do is the following, right here, we can simply add an underscore. So this makes it easy for us to actually read the number. So right here you can see that this is 1901 and 89. So the Max was 32,000, I believe 32,000 something. So right here you can say 32. And then just like that, you can see that it's much easier now we can do the same here. So with integers. So three numbers at a time and the score there and the score there. And now you can see that this number is much easier to read the same with this one. So let's actually start from here and the score and the score and the score. And obviously this works also with doubles. So if I run this again, you can see that it still works, but the output doesn't contain the end this course. So underscore is mainly to help you visualize the actual number. This off for now, catch me on the next one. Let's learn about non primitive data types or simply reference types. These are very special because you as a Java engineer, you will create lots of these to build your applications. Majority of your code will be based of reference types. So let's go ahead and create this reference type. So simply type, capital S, and then string. And then let's simply say name equals two. And then Neil, and then string. So make sure you have the exact same thing that I have right here. So simply say string. And right here I'm going to say Amigos, and then code. Now I'm going to end this with semi column. Now, one difference between reference types and primitives is that reference types, they always start with uppercase. So remember, if I was to have Int, so this is a primitive, and then age equals two. And then let's say 20. Right. So you see that this it starts with a lower case. And the difference is that if, for example, I want to say age, dot, you can see right here. I'm not getting any attributes from this variable right here. So age. Whereas if I say name and then dot, you can see I've got many attributes and behaviors. So right here is blank lines, length, region, replace, so on and so forth. But if I say age, dot, I'm not getting none of that right here. If I delete that. And what a string is simply a reference type that allows me to store a sequence of characters. So remember, we had the chart data type. So let me type C equals two. And this takes, for example, a single character right here. So you can see if I type, for example, Amigos code. This does not work. So this is where you use the string reference type. There we go. So now I can go ahead and simply say south and then name. So remember, south gives us system dot out dot print line. Now, if I run this main class, you can see that I do have Amico code. Now, what is interesting is that I can say don't. And then right here, I've got a bunch of methods. Right. A bunch of methods. And I'm going to explain what methods are in a second. But for now, let's simply say two and then upper case. So now check this out. If I run, you can see that everything now is in uppercase. So Amigos code is in uppercase. Everything is in uppercase, which is awesome. So reference types, they give you built in behaviors. And if you build your own, you can define those behaviors, which I'm going to show you later in this course. And you see that I've used string. Right. But there are lots of built in data types. Remember when I said that the JRE comes with classes and libraries? So there are tons of these classes that we can use. For example, if you want to know the actual current date, you can say local and then date, dot and then now. And I need to store this into a variable. So let me simply say local date, which is the type, and then say now the variable name, and then south and then now. If I run this, you can see that this is the current date. But I can go ahead and say don't. And you can see that I do have, you know, lots of methods. So for example, get month and then run. And you can see that it says July. So this is a quick introduction to reference types. But I'm going to explain you further how to create your custom reference types. But next, let me go ahead and show you exactly what is the main difference between primitives and reference types. Let's learn about the difference between primitives and reference types. It's very important that you understand, and I'm going to make sure that you fully grasp this concept. So right here, let's start with primitives. So let's define a variable called A equals to ten. And let's go ahead now and define another variable called B equals two. And then A. Now what I'm going to do is change the actual value of A. So A equals two. And then let's simply say 100. And if I set both A and B, right. So right here, I'm going to say plus and then B. So let me actually add A plus here and simply say A here. And then this is B, just like that. So if I run this code and I'm going to show you exactly something. So right here, you see that A was initially ten. And then B we said that B equal to A, and then we change the value of A to 100. So here you can see that. And I'm missing actually equals here. So maybe some equals there. So here you can see that the final value of A equals to 100, and then B is ten. So what is happening here is that when we say that B equals to A, this value right here. So this value that goes into B is passed by copy. So it's copy of A, which means that if we change A, this value right here. So B is untouched. Let me demonstrate this using Keynote. Right. Somewhere in the memory in your computer, we have these addresses. So each address is where you store a variable. So in our case, we have a variable A, and this is a primitive, and we store the value ten. And then we said that we have a new variable called B, which was equal to A. Right. So what this does with primitives, it simply creates B in a different memory allocation. So 201. And then this is a primitive, and then the actual value. Ten. Right. So it just takes a copy from A to the new memory address. So this is what is happening. And right here, you saw that when we change to 100. Right. B isn't touched because B lives in a different memory address. However, this is a little bit different with reference types. Right. So to demonstrate the exact same concept with reference types, let's go ahead and quickly create a static and class and a person, and you'll learn about classes in a second. For now, just follow along. So right here, let's simply say that we have a string and a name and simply say person, and then string name and simply say this dot and a name equals to name. So right here. And this would semi Colum. So right here. This is a class that we can create reference types or simply objects. So right here, let's simply say person, and then simply say Alex equals to new and then person. And in past Alex inside there. Now let's go ahead and create a second person. So I would say person equals to Miriam, and then equals two. And then Alex. Now let me jump to Keynote to show you exactly what is happening here with reference types. It's a little bit different how these objects are stored in memory. So first we have person A, and this is the actual object. So this is somewhere in the member. So let's say address. 200. Right. So this is an object. Then what we have is Alex. Right. So we have the actual thing. Right. Alex. And this is a reference to our object. Right. So this is the main difference. So this is a reference to the object. And then we also created Mariam. Right. So this is also a reference type. And we said that Mariam is equal to Alex. So now instead of pointing directly to Alex. Right. So instead of the address two0, two pointing to address 201, it will simply point to address 200. There we go. And this tells us something very, very important. And let me actually show it to you. So right here, let me simply go ahead and say south. And I'm going to say Alex, and then name. And then right here, Miriam Oops plus. And then Miriam Dot and the name. Right. So here let me simply say south. And then before changing Alex, and let me grab this exact same thing here. And then here let's simply say after changing Attics, and in between, here, let's simply say that here we want to change Alex name. So here let's simply say Alex dot, and the name equals two. And then let's simply say Alexander. Right. So this is now the actual name. So remember, both Alex and Miriam are pointing to the initial object. Right. So now I've changed Alex dot name to Alexander. Right. So what do you think the value of Marian will be? And in here, let's run this program so we can see the actual output. So right here, you saw that Alex has the name Alex. And then we have Miriam. And then Miriam should have the name Alex. But now if I change only Alex, right. Only Alex name, we expect Mariam. Right. So Mariam to be untouched. So if I run this, there we go. So the output is that we have Alex. Alex. But then we change only Alex. Right. And right here, when we print Mariam name, it is also Alex. So this is because they are pointing to the same reference, the same if I change Mariam. Right. So here, if I say Miriam, so, Miriam, and then here Miriam. And if I run this, Alex will lose its name. There we go. You see that Alex. And then Miriam. Miriam. So hopefully this makes sense to you. This is something to bear in mind. If you have any questions on this, drop main message. Otherwise, let's move on. Right. I want to touch upon how you should name your variables. So right here, you said that actually named this as main. But when it comes to variable, you should name your variables in a way that they make sense. So in our case, we know that this is the actual number zero. So we can name this as number. Or, for example, if we have the Pi. So the value of Pi, we can say Pi equals two and then 3.1415. So this name does make sense because it represents something. But now let's go ahead and simply say that we have it and the number, and then right here equals two, and then one. So you see that now we have a clash. Right. Because this name right here has already been used for the number zero. So in this case, what we should do is simply name the size zero and then one. So you can see that this variable now tells us that the value, you know, basically the variable name corresponds to the actual value. You should name your variables accordingly. Another thing that when it comes to naming variables is let's say that we want to store the subscriber count for a given channel. So we're going to say in this case, Int and then subscriber, and then count equals two. And let's say that 1 million. So just like that, and this is 1 million. Now you see that this variable right here, it's very difficult for us to read. And what we should really be doing when we have two words for a variable name, we should be using Camel case style. So what this means is count will become a per case, just like that. So you can see that now this is much easier for you to read. And also the variables, they should never start with upper case. So like this. So subscriber count. So there are scenarios where it should be all upper case or none. And I'm going to show you exactly later. But remember, variables should always start with a lower case. And then if you have a second word, that second word starts with an upper case. So right here, let's say, for example, subscriber count, and then four, and then Amigos, and then code. So you can see that now, this is how I'm using Camel case to name my variables, because this is now easier for someone to actually read. Subscriber count for Americas code instead of being like this. So subscribe Oops count. And then for goes on. You see that this now is very difficult to read. So remember when it comes to name your variables, make sure that the name means something, and also make sure that you use Camel case for your variables. Previously, we've learned that if we want to have characters, we simply say A equals two. And then, for example, at the same, if you want a character, B, you put it within single quotes, and then you can add your character. But the problem here is as soon as I add something else, you can see that we get an error and this is not allowed. So this is when you use strings. So let me actually leave that line in there. So string is simply a series of characters. So right here, to create a string, we can simply say string. And right here, let's give you a name. So let's simply say name equals two, and then new and then string, and then add parenthesis, and then inside instead of single quotes. Right. So you see that with characters, we have single quotes, but with strings, we have double quotes. And right here you can add more than one character. So and then bright, whatever. But let me simply say Amigos and then code. Right. So you see that now we can have more than one character. So a chart data type only allows you to have one single value. So let me delete this. Now a string. So this guy right here. So this data type, it is a string. And this comes by default with Java, allows you to store values, but you can perform a bunch of things. So remember before. So if I go ahead and simply say south and then name. So right here, let's bring the actual name. So let me run this. There we go. So you can see that we have Amigos code. Now this data type, Ie string is a class. And then right here, we simply say name. So name. Now is an object. So it's an object of type, string and objects. They have behaviors associated with it. So right here. Remember, we sent two and then upper case. So this is a behavior. And what this is, the actual term is a method. So this two upper case is a method which simply upper cases every single character in this sequence. So if I run this, there you go. You see that now everything is uppercase. I can also say, let me actually duplicate this line just like that. And right here we can say two and then lower case. If I run this, you can see that right here, we have Amigo code, uppercase, Amigos code, lowercase. So strings are really powerful, and you will use them quite often to store text. So let's actually keep on exploring some methods right inside of the string object. So this guy right here. Name. So if I say south and then name. And you can see that there are tons of methods right here. So right here, let's simply say that we want to grab the very first character. So right here, we have car at and then this guy right here. So this method takes a number. So it takes an integer. So if I press command P, you can see range index. So it takes an integer. So let's say I want the character at index zero. If I run this there, we have it. You can see that we have a. So if I want the character index one, you see that will get M right here. Now, let's also say that you want to check whether this variable right here. So name contains the word code. So dot and then contains and then within. So right here, it takes a string code. Right. So this is another string. So if I put this so you can see properly. So I can simply say string, and then code equals to new and then string and then code. So now I can simply pass my variable. This stick is the exact same thing. So if I run this, you can see that now this returns a boolean, true or false. Right. So indeed, Amigos code contains the word code. So if I say contains the word code that will fail. You see that it is false. So there are a bunch of methods that we can use with strings. So remember, this is the actual data type. So we've learned about reference types. This is the actual name. Right. And when you say new and then string, this gives you an object. So this guy right here becomes an object, and then you can invoke these methods inside of your object. So we're going to learn more about objects. I'm going to show you exactly how to create your custom objects. But for now, just know that whenever you see a data type that starts with a capital letter, you know that it is a class where you can create objects, and then you can invoke methods inside of that object. Right. So one last thing I want to talk to you about strings is because they are so used throughout your programs. This two right here. So new string can be dropped completely in the same way the actual parenthesis surrounded. So it becomes just like that. And that also becomes that. So there is no need for us to say new. So I'm going to explain what the new means later on. But for now, just know that whenever you work with strings, you don't need to say new. And then strings. One final method that I want to show you is let's say that you want to compare whether name is equal to code. So we can do that. So south. And then I can say name dot. And then guess what equals. There we go. And then code. And this will give us true or false. And you can see that it is false. Of course it isn't. Right. So Amigos code is not the same as codes. So this is offer strings. If you have any questions, go ahead and let me know otherwise. Let's move on. Now that you understand where a package is and how they work, let me know, introduce you to this package keyword. So this package keyboard simply tells us that we are inside of com Amigos code. Right. So remember that we define this when we created our project. So we have a folder called Com Amigos code. Now with package, you will see another keyword called import. So let me go ahead and simply type local and then date. So you see, right here, we have local date. But then we have Java dot and then time. So if I try date, for example, you can see that we have date classes. Right. And they come from different places. So one comes from Java Util, and the other one comes from Java SQL. So this day right here, you should be using it when working with databases. So dates for databases. And in this one when working with non SQL dates. But basically, if I select the first one, you can see that we have this import statement right here. This simply says from this package. So Java dot util, give me this date class so I can use it. Right. So now I can simply say date equals to new and then date. Right. The same with local date. So local and then date and then equals to new. Oh, actually, this time is local, date equals two, and then local date, dot. And then now with local data is a bit different the way that you create them. So you're gonna learn about the new keyword. But for now, just follow along, because I just want to teach you this import statement. So now we have imported from two different packages. So Java util, actually, this is Java out and then Java time. And from it, we have local date as well as the date class. So let's do another one. So local and then date time. And you can see that this time the package is the same. Right. But a different class. So you'll see these imports simply when you want to bring in classes that belong to different packages. So let me just name this, and this will be like that now. Right. So this is the way that you should really be importing these. But as you see, my IDE is actually doing the import for us. Right. So we don't have to manually know where each class lives, because I just need to type the date, and you see that we have auto completion. Right. So for example, if I also type a string, you can see that we have Java dot Lang. Right. So Java Lang. So this actually is an interesting one. So let me see it as a string, and then S equals to new and then string. So right here, you see that we have no import statement, anything that comes from Java Lang. We have no import statements. So let me show you also that another way that you could use a class is by simply sane. So right here, I'm going to take this. I'm going to cut it and then put it here, just like that. So this is the exact same thing. So the same here. So I'm going to cut this, then put it here, there, and then there, and then there. So if I put this on a new line, so you can see. So you can see that this is the exact same thing. Right. But usually we engineers, we won't write stuff like this because we want all the import statements at the very top. Right. So the only reason why you might want to do this is, for example. So if I put this back, so I'm going to I just press option and then replace with qualified the same here. So option and then enter replaced with qualified import and the same here. So the only reason why you want to do the import explicitly is when, for example, you have two dates. So remember. So right here, if I say date, you have date from Java SQL. Now, if I press enter, you can see that my IDE, it's smart enough to know that there is already this class from Java Util. So therefore I cannot have basically you cannot have this line right here. So import. And then that right. Because now it doesn't know which date it should use. Right. It gets confused. So the only time that you actually do this is when you have two classes with the exact same name, but they live in different packages. So again, the name of the variable cannot be the exact same. So let me simply say date, SQL equals to and then Java do SQL, and then date, and it should be new and then end with semi column an inside. Actually, we have to pass a number. Right. So the actual date. But you see that this is the actual fully qualified name. So I hope that now you understand what these import statements mean and when you should use the fully qualified name, if you have any questions on packages, go ahead and let me know. But don't worry about all of this code right here, because I'm going to teach you exactly step by step what a string is, what the neo keyboard is when object is so on and so forth. You're going to learn everything throughout this course. But for now, let's move on. Right. Let's learn about the reserve keywords and what it means and why it's important. So reserve keywords are keywords which are used for the language itself. For example, package public, class, static void. So what this means is let's say that we have a variable. So it and let's say that we want to name this as public. Right. And it equals two and then zero. So this does not work because public, it's a reserved keyword. So right here I could simply say number. And you can see that this works because number is not a reserved keyword. So there are a lot of these keywords. So you will learn, for example, the final keyword. So the same if I was to say void, you can see that it doesn't work. Right. If I was to say final, final is a reserved keyword. If I also say class, you can see that it does not work, actually. So this guy right here. So, Maine. So this works. So if I say Maine, this works because this is the actual method name, and we're going to learn about methods later on. So the takeout really is that you should be aware of the reserve keywords. And as you start to learn more and more about this language, you will get to know them and recognize as you see them. But you know, the good thing is IntelliJ. The IDE is here to help you. Right. So if you make a mistake, it will actually tell you that it's a reserved keyword. So remember, you cannot use reserve keywords to name your variables. Methods classes, so on and so forth. All right. Let's learn about arithmetic operations. So you've learned about primitive data types. So in. And then let's simply say ten equals two and then ten. So let's also create another variable. So Int, and then two equals to Ashley, two equals to two. Right. So now what I can do is actually perform some arithmetic operations on these two numbers. So I can say it, and then addition equals two, and then ten, and then plus and then two. Right. So this now will store the result of both of these two variables. So there is no need actually for having variables for this. So the reason why I'm actually creating variables is that you see how to use multiple variables. But this could be, in fact, just like this, ten and then two. Right. So if I South this and then addition and then run, you can see that we have twelve. So in fact, let me simply do this. And right now you can see that I can simply log to the console ten plus two. So let me duplicate this line. And if you want to subtract ten minus two, run, it should be eight. There we go. If you want to multiply two numbers together, you simply use the star and then run. You can see that this is 20. So twelve 820. And finally modulus. So the mod. Right. So right here. If I run this. So ten more two. This is zero. Right. So how many times two goes into ten. So two goes into ten, two goes into ten five times, and the remainder is zero. So if I was to change this to three, three goes into ten three times, and the remainder is one. So if I run this, there you go. You can see that we have one. So right here, you see that I'm actually performing operations on two numbers, but you could definitely do it on more than two numbers. So right here, I could say ten plus one plus two, or actually, let's say plus 90. And right here, if you remember. Butas so body multiplication, addition, the actual order that these are applied, this works the same way. So if I was to add plus and then seven, so the order of this is ten times two and then plus seven, so. 27. So if I run this, you can see that we have 27. So if you want to actually group them together, you can simply add parenthesis in between. So right here. So you can see that this will be the same. So if I run it 27, but if I was to remove the parenthesis there and then say that this now should be two plus seven. Right. Which is nine and then nine times ten, you can see that the result now is completely different. So it's actually using the Badman. Right. So body or brackets, and then orders, division, multiplication, addition, and subtraction so let me actually have a comment right here. So body orders, division, multiplication, addition, and the subtraction. So this is the actual order. So this is what's happening here. So for example, to add plus or minus and then ten. So now there is actually I didn't actually run this. So let me actually run it. So you see that it is 90. There we go. 90 instead of 27. For now, if I add minus and then ten, there we go should say that should be 80. Right. So, you know, be aware of apartments. And it's the same way that you've learned at school. So this is pretty much how you perform arithmetic operations based on numbers. So we actually use whole numbers. But this could also be, for example, three, actually, let's say 4.5. It's the exact same thing. Whether it is whole numbers or decimals is the exact same thing. So you can perform arithmetic operations on numbers. Right. So you saw how to perform arithmetic operational numbers. But we have a class that allows us to perform extra operations on numbers. And the class, it's called math. So this is the class. So this class comes from Java Lang. So if I press enter, you see that we have no import for Java Lang. Remember that I said that these classes right here, we can perform certain we can we can invoke methods. So right here, if I say dot, you can see that we have a bunch of methods that allows us to work with numbers. So right here, let's simply use the absolute. So ABS. So what this means is if I pass minus ten, and let me actually surround this with south, just like that. So if I run this, you can see that this becomes ten. So basically, if you have a negative number, it turns it into positive. Let's look at some of the other useful methods. So math and then dot. So right here, let's scroll down. So right here, we have Max. So let's use Max. So basically, Max takes two numbers. So let's simply say three point and then six and then ten point eleven. Right. So this will give us the Max number between those two. So in fact, let me simply surround this again. We print statement. There we go. Run it. You can see that the Max number between 3.6 and ten point eleven is ten. So you can even pass whole numbers. So six and 1010 is the Max number. So if I duplicate this line, and then instead of Max, I simply have min run it. You can see that the mean now is six. So let's have a look at a different method. So south and then math, dot. And let's use the power. So power means power. So what is 5.0 and then power 2.0. So if I run this, you can see that it is 25. I can move the the decimal numbers. So it works with whole numbers. As well. If I run it, you can see that it is 25. So this actually returns a decimal. So if you want this to be a whole number, we can simply do this. So we can have it like that. So basically within parentheses and then simply say it. And then this will actually take the result of this and then put it as whole number. So if I run it, you can see that. Now we have 25. So let me actually look at some of the methods. So south and then math, and then do. So if I Scroll down. So basically, we have lots of these methods. You have round, you have sign, you have square root, square root of 25. You guessed it. Right. It is five. There we go. So 5.0, if you want, if you want it to be an integer, you can simply add this bit right here. And what this means is it's called casting. Right. So we are casting the result to an integer. So again, let me do it and then close that. And this is casting. So if I run it, you can see that it is five. So another thing that we have inside of the math class is right here. If I Scroll down, basically, you can go through this and use whatever you need. So we have subtract. We have two degrees to radians, and we have the. So this one will show you the actual value of Pi. I've been creating a variable that contained the value of Pi, but it wasn't this long. Right. So right here, you can see that I can see math, Pi, and then run it. And you can see the value of B right here. So this is how you can perform some extra mathematical operations on numbers. Right. Let's learn about the comparison operators. So what that allows us to do is to compare values. So let's simply say that we have an integer value and then highlight. And then age equals to 18. And let's simply say Int. And then Maria, and then age equals two and then 20. Now, what comparison operators allows us to do is to perform basically operations on these two numbers, actually two or more numbers. So right here, if I want to know whether Harlot's age is less than Miami, I can simply say boolean. And then is he older than Miriam and then equals. So we can see that this is a very long variable name. But you've learned how to name variables correctly now. So right here, I can say had age and then bigger. So the greater sign, and then Mariam age. There we go. Now the result of this will be either true or false. So this is why I do have a boolean right here. So if I simply south this, and then it's highly older than Mariam. And in fact, let me just take this right here and then put it here and then delete the line above. If I run the program, you can see that no is not so hard, is not older than Mariam. Now I can do the same, but I can inverse the sign so greater. So the way I remember this is less. So this is the less sign looks like an L. Right. So L for less. If I now say that Halid age is less than Mariam age, you'll see that yes, indeed it is true. And we can also say that actually check whether Hale age equals to Mariam age. If I run it, you can see that it is false. But if I change Had age to 20 and then run the program, you'll see that these two lines right here. So line number eight and line number ten are false and hold indeed equal to manage because they are both 20 years old. The final comparison operator that I want to show you is almost the same as equal. Right. So perhaps you want to say not equal. So you can say not with an exclamation Mark and then equal. Right. So this says old age not equal to Mariam age. So if I bring this indeed, this is actually false. Right. Because they are indeed equal. But if I change holes to 21, you'll see that now Had is older than Mariam and the age is different. So right here. So true and true. Finally, right here where we say that Holid age is bigger than Mariam. We can also say bigger or equal, right. Or less. Right or equal. Right. So right here, if I change to both 20, you'll see that both this line, this line and this line will be true. So if I run it, there you go. So you can see that we have true, false, true, true, and the false. So this is pretty much everything about the comparison operators that you're going to be using with Java and so that, you know, all of these expressions right here. So greater, greater or equal, less, lesser, equal equals not equal. They are referred as Bolling expressions because they are the return true or false. Logical operators allows us to combine multiple bowling expressions. So right here. Remember that this returns true or false. Right. But what about if I want to say that Haled age is bigger than Mariam and something else? Right. So I want to combine multiple bowling expressions, so that's what logical operators are. So in fact, let me delete all of this. Right. And let's create a boolean. And then is an an adult equals to false. Let's create another boolean, is and then student equals to true equals to true. Just like that. What the logical operator allows us to do is to follow. So we can say right here. Let me simply set to the console. So system the print line. And inside let's say that we want to check that is adult equals to true and is shouldn't also equals to true. So for that we can simply say is and then adult. And then the logical operator that we have the first one is and and then is shouldn't. Now what this will do, you will check if the first one is true. So if the first pulling expression is true, it will continue to the next one, and then it will check whether the second bullying expression equals to true. So basically and means that all the expressions must be true. Otherwise the final output is false. So if I run this can see that it is false. But now if I change it adult to true and then run it, see that now it is true. But let me go back and then say false here. So let's learn about the or. Let's say that you want to check either one of them have to be true and not everything. That's when you use the or. So this is the or. So either one. Right. So you can have 1 million bullying expressions that evaluates to false. But if you have one bullying expression that evaluates to true, the whole condition is true. So if I run this, you can see that now this is true. And the final logical operator I want to show you is or. So right here, if I pretty much wrap all of this, so I'm going to wrap all of this. Right. So we can wrap things. And now this is another bullying expression. So this whole thing will return true or false. So right here, let me also say that. So let me have a second variable here, and what I want to say is boolean. And then is Amigos code member. So if you're not part of the Amigos Code community, make sure to to check it out. So right here I'm going to say true. Let's say that you are. And now I can say so let's say and is Amigos code member. So if I put this on a new line so you can see everything. So if I run this, this will be true. Right. Because this evaluates to true and this evaluates to true. Right. So now change is student to false and then run it. The whole whole thing should be false. There we go, because this is false. And remember, and whenever you use and it means that all the budding expressions must be true, which is not the case. Now the last logical operator I want to show you is how you flip the value. So let's say that right here you say is Amigos code member. Right. So let's say that I want to say is not Amigos Code member or not an adult, or is not a student. Right. You can do that by simply flipping the actual value. So right here, I'm going to change my condition to say is not an adult or is a student. So right here is not an adult, it's true by putting this exclamation Mark it will flip the value. So now adult will be true. And in or so we don't care about this anymore, because as long as this one is true, then this whole statement or this whole building expression is true. Right. And then is Amigos code member. So let me run it. You see that we have true. Now, if I say and is not Amigos code member, I want to flip it. But you can see right here. Currently you are an Amigos code member. So if I run it, there we go. You can see that it is false. Right. So this evaluates to true, but then this evaluates to false. And with and everything must be true. One last thing that I want to show you is you might sometimes be tempted to say south, and then is an adult equals. So we learn about the comparison operators. So it equals and then to true. Right. So you might be saying, oh, I want to check whether this variable right here equal to true. Right. And this will either return true or false. So if I run this, you see that it is false right here. Right. And if I run equals to false, you can see that this will return true. Right. But you don't have to do that. Right. Because the value itself of this variable is true is actually a bullying. So what you can do is simply get rid of it. And you can say is adult. And then this will tell you true or false. False is not an adult. And then if you want to check whether is not an adult, you simply flip the value. As we learned with the exclamation Mark, run it, and then it's true. Right. So it's not an adult, is indeed true, because is adult. Right here. So this variable currently is false. And this is all about logical operators. So just bear in mind that you can combine this. We need many things. So for example, if I was to say south, and let me simply say ten, so here I can say ten greater than eight. Right. Four. And then let's say two less or equal to two. Right. So we've learned about these expressions, and you can see that now I can also say and and then is an it. So basically you can combine most of these things together. And remember, we've learned about strings. So right here, let me simply say string, and then name equals to and then Mark. And then I can also say, and so let me put this on new line, just like that. Oops. And then say and and the name contains let's say that the name contains the letter. Right. So you can see that we can combine these expressions with everything that returns a boolean. Right. So this returns a boolean. So name contains returns a boolean is adult. And here you are actually comparing numbers, and then you have an or sign with another number ten greater than eight or so. Basically, let's say that we want to group these together. So let's group them. So I want to group this. And that right. So let me actually put this like this, so you can see exactly. So there we go. I think this is much it like this. There we go. So I'm saying is this expression, is this pulling expression true and is adult, and the name contains M. So if I run this, you can see that the whole expression is false. Right. So this is because is adult is false. So let's actually flip this is and is not an adult, and then run it. And you can see that now the whole expression is true. So there we go. This is all about logical and comparison operators. Right. Let's learn about if statements. So if statements allows you to execute certain sections of your code, depending on the result of your boolean expressions. So let's create a variable. So let me simply say it, and then age equals two, and then 17. And let's say that we want to print the console whether this age right here is an adult or not. Right. So it's for the sake of it, to say that for you to be an adult, you need to be 18 or over. Right. So if it's less than 18, we say you are not an adult, and then if you are, we say, yes, you are an adult. So to do that, we simply use the if statement. So if statement works like this. So if an an inside right here, we pass a boolean expression, in our case, I'm going to say he and then if H is greater or equal to 18. Right. If it's greater or equal to 18, we know that it's an adult. So let's simply log to the console, and then a actually he. Right. So he I'm an adult. So if I run this, you can see that we get nothing to the console. We literally get nothing. So basically this condition right here, this was false. Therefore, it didn't execute this condition. So remember that we've learned how to flip values. Right. So let's say that we want to group this and that like that. And let's say that you want to check that this condition must not be true. So for that, you can flip the value like that and then run it. There we go. Now you can see that or Amanda, but this is not the case. Right. Because the age is actually 17. So if I go back and remove that, so the way that you can then say, if it's not an adult, then do something else. Right. So right here, I could simply say south, and then I not an adult. Right. So I could do this. But if I run this, you can see that I'm getting I am not an adult. But even so, if I change this to 18 or actually 18, run it. You see that I'm getting here. I'm an adult, and I'm not an adult. So basically this line right here. So line eleven gets executed regardless. Right. Because it's not part of this if statement. So if you want this to be part of this if statement, you can say else. Right. And then right here, if I go back, I actually put this line inside, and then this. There we go. So now this is what a if statement looks like. So here I'm saying, if it's an adult, you print this. Otherwise you print I'm not an adult. So if I run, we should only have now one statement. There we go. Hey, I'm an adult. If I change this to 17 and then run it, there we go. You can see that it says I'm not an adult. We could also combine these. So let's say that I want to. So I'm going to grab this line for now. I'm going to say else. And then if so now I'm actually having a second bully expression. Right. So if age is bigger or equal to 18, do this, and then I'm having a second F. So if age equals to 17, actually, let's say 16. So if it's between 16 and 17. Right. So if he is greater or equal to seven to 16, and then and and then he is less than 18, we want to simply log to the console South, I am almost an adult. And then finally, right. So let me actually run this. So you see the output. So there we go. I'm almost an adult. But now if I change this to 15, you can see that we get nothing to the console. This is what you use. The else condition for Elf is the last block if none of the above conditions are met. So if I run this, you should see that I am not an adult. And again, we've used if statements with numbers. But if statements are used with any pollen expressions. So you saw with if statements, you can do if and then else, if and then else, you can get rid of the this part right here. So if I remove that. So if and else. Right. So if you have an if statement, which is really simple, if you have this scenario only. So I only advise when you have this scenario where you have one if statement, actually, you are evaluating one bulling expression, and then you need the else if the initial condition is not met. So you can do something like this. So I'm going to replace this whole thing with I'm going to say string. So I'm going to store actually the value. So this value right here into that variable. So right here, I'm going to say message equals two, and then I'm going to say age greater or equal to 18. So if this is the case. Right. I'm going to say question Mark, if this is the case, the value of message will be or I'm an adult. And if I put this on a new line, so you can see properly and then else, this is when you put the column right here, and then this other message, just like that. And then like that, just like that. And there we go. Now I can say south and then message. So you can see that this is actually much neater instead of having something like this. Right. But as I said, this should be only used when you are evaluating just one bullying expression, and then you need a default value. Right. As soon as you have else. If so else is. Right, then things become really complex. And also, if you have let's say right here, you have two print statements. Right. So South, I'm happy. Right. So if this is the case, then definitely you can't use the ternary operator, because with linear operators, you cannot have. So right here, you see these braces everything that you do inside here. So this is the actual logic. You're not allowed to do it with ternary operator. So ten were price is when you want to return a value. Right. As soon as you want to mix logic inside and your if statement becomes too complex, then do not use this. But let me just show you that. So right here, if I delete that if I run it, you should see that I am not an adult. So it's just printing this part right here. But as soon as I add 18, you can see that it's printing. Now this value. And this is all about the ternary operator. If you have any questions on this operator, let me know, and I can give you further examples. All right. Let's learn about this switch statement. So switch statement falls under the same category as the if statement, but a little bit different. So let's say that we have a string. And right here, I'm gonna name this as gender equals two. And right here, let's simply say female. Old Apple case. So female. Right. So what switch statement allows us to do is, for example, let's say that we want to check whether the gender is female, male or prefer not to say, right. So those three. Right. We could actually do it with if statements. Right. So we could say if and then gender and then equals and then female. And then right here, we could say else and then if gender equal, and the male. And then again, so else. So you can see where this is going. Right. If and then gender equals, prefer not. And then say, and then we also should have an else. Right. Else. And then this is when you say, I don't recognize the gender. Right. We see that this is how we would do it with if statements, and the way that we can do the exact same thing with switch statements is as follows. So let me go ahead and simply say switch, and I want to switch on the gender value. And then inside, make sure you have these curly braces. And now I can say case. So when the case is female, and then and then right here, simply type break. For now, same type break. And then I'm going to say case and then mail and then type break. And in case, let me just grab this. There we go. And then say break. And then for the L part, you simply type default. And there we go. So basically you can see that this is kind of neat. Right. So if you compare with this, this is a bit neater. So you should really be using switch statements when you are switching or you are performing an if condition only on one value. Right here. All right. So you actually switch the gender, and then you check if it's female male, prefer not say as soon as you start having complex comparison of operators and greater and bigger than this, then you shouldn't really be using switch statement. So right here, you could also go ahead and type this out. Right. A female. So again, let me simply say male and then prefer not say just like that. And then right here, south unknown, and then gender. And there we go. And if I run this, you see that I am a female. If I change this to let's say female, lowercase, run it. You see that it doesn't know the gender. So if you want to tackle that, you can say dot and then to upper case. So if you receive something in lower case, you always try to match it to upper case, run it. I'm a female. And if I type, for example that see that unknown gender. Right. So one last thing here is you see this break statement. So this is actually only in Java eleven. I think in Java twelve above, this has been fixed and not needed anymore. But basically this simply says, if this is the case, right, do whatever is before the break statement. Now in our case is the actual system system dot out dot print line. And then when you reach this line, break out of this switch statement. So this is something that you actually need for versions below Java twelve. So we are using Drive eleven, so we still need it. So remember, and there is no need for the default branch right here. There is no need to have the break statement. So as I said, switch statement should be used only when you are switching on single values. So right here, these are the expected values that I have. Right. So as soon as you want to start combining, for example, gender, I equals to female, and then and the area. So you cannot do this with switch statements. Right. So switch segment is very powerful and need, and it should be using it when possible. So right here, you can see the equivalent for if statement. Basically, you can achieve the same thing with if statements, but the switch is much neater, and you should use one or the other when possible. If you have any questions on switch statements, let me know, and I'll give you more examples. Let's learn about a race. So far, we've been able to create variables as search, so Int, and then zero equal to zero, and then in, and then one equals to one. So these two variables right here, they are independent from each other. Right. So this has a different address in memory, the same as this one. Right here. So what arrays allows us to do is to create one variable that holds more than one value. So instead of us declaring these variables and having these two numbers independent, we can simply create an array and then put both zero and one inside of the array. Let me go ahead and simply say that I want an integer, and the way you create an array is by simply adding the curly braces, and then simply say numbers. Now here simply say equals to new, and then Int, and then simply put the curly braces. Again. The final thing that we need to do is to specify the size of our array. So when I mean size, I mean, how many items that this array can have? So in our case, you can have two items. So we want to store both zero and one inside. So now I need to end this with semi column, and now we have an array. So let me first go ahead and actually print this array right here. So you can see the actual contents in it. So to print an array simply say south capital A, and then arrays, and then dot, and then two, and then string. And then simply say numbers. Now let me go ahead and run this. So you see that this is our array. So currently when we initialize the array with two spaces. Right. So you can see here. So zero and then zero. So this is the actual size of the array. So if I also increase this to two or actually three. Sorry. And then run again, you can see that we have now three zeros. So currently we simply created an empty array. And by default, every single number inside of the array which is initialized is zero. So in here. So if I was to, for example, say that I want an array of boolean, so bullying and the bullying. So this is how you say I want an array of bullying. Remove that. And then if I run this, you see that the default for bullying is false. So if I was to say that I want an array of strings and then new and then string just like that, and then run it, you can see that the default is no. So this is how you actually determine the actual data type inside of the array. So in this array, we want to store numbers. Right. So this is why I have it right here. Now, the way that we add numbers inside of this array is as well, simply say numbers and then curly brackets. And then at the position zero, the zero position is the first one. I want to put the number zero. We can also say numbers and then position two. So this is position two. We want to store the actual one. So number one and then number, and then opposition three. So this is two. I want to store the actual number two. Right. So a raise it from zero. So this is zero index, one index, and then two index. Right. But the overall size is actually three, but the index starts from zero. So this would be actually two. Right. Now, if I run this program, you will see what's going to happen. There we go. So now we have stored in our array zero, one, two. So if I also say in position one, I want to store the number two. And then here I want to store zero. And then the last position is one. If I run this, there you go. So you can see that. Now we have two0 and one. So with arrays, when you initialize the size, so size three, you cannot change it. Right. So this is now a fixed size. So if I was to say numbers and then three equals to, let's say 44 or 34, and then run it, we should get an error. There we go. So you can see that we have an error, and it says a raise out of bound index. So this is an error, and we have uncovered errors. But just know that because the size of the array is actually three, it can only have three items in it. As soon as you try to add a fourth one, it will throw an error. So let me simply remove that line and then run the program again. And you can see that now it's working. So the last thing that I want to show you is right here. Let me delete that. You see that this is one way of creating a raise, but we can do all of this in one single line. So we can simply say Int, and then numbers equals two, and then add curly brackets. And in fact, this should be like this. Right. So we're saying that we want an inte Ray, and then here we want to and then zero, and then one. So the cool thing about this way of creating the actual array is that you don't specify the size. So it's whatever number of items that you add to this array, that will be the actual size. So in our case, three will be the size. So if I was to comment all of this and then run the actual program. Again, you can see that we have the exact same output. Now I can go ahead and add a full item here. Let's add 100 as well. Run this, and there we go. So you can see that we have an array of 2014 and 100 and the actual indexes. So this is zero index, one index, two index, three index, and then four index. If you want to print the actual size of the array, you can simply say south, and then simply say numbers and then dot. And then we have a property right here called length. So that will be the actual property of this array. And this will tell us how many items are inside of the array. If I run the program, there we go. So you can see that we have five elements inside of this array. Now, obviously we have an array of numbers, but we could also have, for example, an array of strings. So string and then names, or Ashley curly brackets to denote an array. And then names equals two. And then here. This has to be in double quote, because the data type of is strings. So here let's simply say Ali. And then let's simply say Maria. Now let me actually print this system auto print line Oops, so south and then arrays, dot and then two, string, and then names. Let me also print the actual size. So south, arrays, dot, and then. Oh, actually not raised by the actual names, dot, and then length. If I run the program, you can see that we have this array this time only contains Ali and Maria, and the size is two. So there we go. This is how you create and use arrays. If you have any questions on arrays, please do let me know. But they are very useful when you want to store more than one value at a given time. So remember with a simple variable. So if I was to have this it. And then let me simply say N for number. So here I can only store one value. I cannot store more than one. So this is when I raise come to rescue when you want to store multiple values in it. If you have any questions, please do let me know otherwise. Let's move on. So now that you know how arrays work, let's say that you want to grab this last element right here from this array. So the way you do it is as follows, so you simply say numbers. And then right here, remember that we've learned that if you want to add a particular number, a particular number at at a given index, you simply pass the actual index. So in our case, this is the index 0123 and then four. So we want to grab the item at index four just like that. So now obviously we need to store this into a variable because this now gives us the integer value. So let's simply say in and then simply say 100 and then equals and then numbers and then four. Now let me simply say south and then 100. Run. Here we go. We have 100. Now let's say that you want to grab the number four there. So let's go ahead and simply say Int. And then four equals two. And then numbers. And then guess what? Index. And then three. Right. So let me actually now do a south here and then four, and then run the program, and we get four right here. So if I was to change this to 90, now that value is 90, and also the variable name doesn't match the actual value that we are getting from the array. Right. But you get the point. So let me actually go back on. That leaves four. Now if I was to try to access index five, like before. Right. So this array can only contain five elements. But here I'm trying to retrieve index five. So this is index 01234, and then index five is non existent. So if I run this program, this will fail. So check it out. So you see, in this error array, index out of bounce. So just be sure that whenever you're trying to access an index from an array, it is within the actual range inside of the array. Now here I can simply say four. And let's say that, you know, just for the sake of it, you want to grab the last index. So but let's say that you have let's say you got four here, and then you have 90, and then you have 78. Right. So let's say I want to grab the last index. So I don't account really all the indexes. So I can simply say numbers and then length. And remember, the length will give us the actual number of items inside of the array. So here 123-4567 eight. If I run this, this should fail. Yeah, this should fail. And this is because remember, for us to grab the index, we need to start from the zero index. So here I need to say minus and then one, and then run the program. And now we get 78 right here. And there we go. This is how you retrieve elements from an array with a given index. So next, let's go ahead and learn about loops. Right. Let's understand what I plus plus means, and I minus minus. So if I get rid of this and let me go ahead and create a new variable, so Int. And then simply say number equals to zero. So now I can say number and then plus plus, and then simply print the actual number. So number. So this is the following. So you see that this simply says, take the current value of number and then plus plus simply says in incremented by one. So this is the exact same thing as same number and then equals two. And then take the current value of number, and then plus and then one. So this is the exact same thing. So if I run it, you can see that we have one the same weed minus minus. So right here, if I say number, minus, minus minus, and then run it, you can see that we have minus one, and this is the exact same thing as take the current value of number and then minus one. If I run it, you can see that it's the exact same thing. And if I go back. So if I press Control Z there. So you see the actual loops again, there we go. So here this is exact same. This is what I was doing. Right. So here I could say I and then equals to I, and then plus one is the exact same thing, but I plus plus is the actual short and version. Right. I plus plus. So in here. So let me simply remove this. So if I paste that again, so if I say, oh, actually a number plus plus. Right. So number plus plus that increments it by one. But if you want to increment by two, this is the way that you do it. So number and then plus and then two. Right. So the I plus plus is only a short hand. When you want to increase the number by one, there is also another way of actually increasing numbers. So instead of using number plus one or plus two, plus three, you can simply say, so number equals two, and then actually plus in an equal, and then the actual number. Right. So here I'm saying number plus equal and then one. So this increments the number by one, I can say five. So if this initial number is let's say three, so the output of that will be eight, there we go. So if you want to decrement the number, you can simply say is equal and then five, run it. You see that it's two. So there we go. So basically this is the exact same thing as number equals to a number minus five. And finally, if you want to increment or decrement by one and only by one, this is when you say number and then plus plus or number, and then is if you have any questions on this top my message. Otherwise, let's move on. Right. So you saw how to loop through arrays using this for loop, and this is the for loop. So in Java we have something called Enhanced Full loop and have simply means that it's a better version of you looping through arrays. The Enhance Full loop works as follow, simply say four, and then here simply say it. So this is the actual data type, and then simply say number, and this is the actual variable, and then say column and then numbers. So basically I'm saying four numbers. Take the individual numbers one by one, and then put it inside of this variable. Right here called number. So now open and closed, called the braces. And I can simply say south. And let me simply say south. Here enhanced for a loop. And now I can say number and then run it. You can see that it's the exact same thing. So it has follow up to zero one for 100 490 78 77. So this loop right here. So this loop right here and this one are the exact same thing. But the difference here is that with this loop, right, I do have access to the index value. Right. Whereas in here I don't have access to the index, I only have access to the actual number itself, which means that, for example, here, if you want to, for example, if you want to check the next neighbor right inside of this array. So the next neighbor of two is zero, you can't do it with this. But with this one here, you can you can simply say I, and then plus, and then one. And this will give you the next neighbor. Right. So this is something to bear in mind. So this enhanced Polo doesn't give you access to the actual index. So you saw that we have numbers, but this also works with a string array. So string and the names. I always forget the actual brackets, and the name equals to right here. Let's simply say Anna, and then Ali, and right here. So now this has to be string so that's the individual data type inside of each element. So string and then string. And then here this will be name, or you can name it as n whatever you want. Right. But as we learn how to name variables, they have to mean something. So name. And then here simply say names, which is the actual array, and then simply print name. So this guy right here. So if I now run the program, you can see that we have an and Ali, let me teach you something very nice that you can do with your IDE. So you see that for us to create a loop, we simply have to say four and then int I equals to zero. So four, I plus plus. And you get the idea. So instead of us doing that, we can have some help of our IDE. So let's say that we want to loop through numbers. So from left to right, simply saying numbers, and then do and then four. And check this out. So you have four, I, four, R. And then the actual normal actually not normal, but the enhanced full loot. So for I, so four. And then I am going to pick that one. And you can see that we get everything filled in. Right. So let's try the other one. So numbers dot, and then four, and then R. So this is the actual reverse. Right. So from right to left, enter. And there we go. So you see that this is much quicker. Right. So this is why IntelliJ. It's amazing. And you should really be using awesome ideas like this one. So finally, if I say names, dot, and then four, and this is the enhanced full loop. Enter. And there we go. So you see that I was able to create these loops in seconds. So there is another way that you can loop through a Ray. And let me quickly show you. So this is more on the advanced side. But I still feel like I should teach you so that you know that there are many ways that you can loop through a race. So go ahead and simply type Arras, dot the stream. And as I said, this is more on the advanced side. So simply say numbers and then dot, and then for each, and then simplify and then simply type system, dot out, and then column, column, print line. So again, this is on the advanced side of things. And I don't expect you to learn this, right. But this is one of many ways that you can loop through a race. So here, if I want to loop through names as well, simply say names. And if I want this, I should see that we have the actual output right here. And this is a beautiful code. But as you progress through your journey in learning Java, I want to make sure that you understand this as well. But this was just a bonus tip. Do. But this was just a bonus tip that I wanted to give you this off. Now join me on the next one. By now, you should be familiar with looping and indexes so on and so forth. So let's say that you want to loop so names and then four. And this is the enhanced for loop. So here let me simply say south and then name. So if I run this program, you should see that we have Bob Ashley, let's start from here. Anna Ali, Bob and Mike. So what the break keyword allows us to do is to simply break out of the loop. So if I was to simply type break in here. So this will give me an error. Right? Because by this point, so this will break and then this line will never be executed. So if I change the order now, you can see that we will print once and then break out of the loop. So we should see only Anna right here. So if I run this, there you go. You can see that we have an so we could do something more clever. So let's simply say if and the name equals and then Bob. So if the name equals to Bob, we want to break out of the loop. Right. So now we should go and print Anna Ali, and then if name equals to Bob, we simply break. So here let's simply say south and then name. Right. So if the name equals to Bob, we're going to break out of this loop. Otherwise, we're going to print the actual name. So if I run this, we should see only Anna and Ali. There we go. Anna and Ali. So as soon as we reach Bob, we break out of this loop, and then Bob and Mike will never be printed. So that's the function of break. So break simply breaks out of any loop. Now, the continued keyword is a photo. So right here. So let me simply say if name dot and then starts with an A. So if the name starts with a. So right here, see that we have Anna, Ali, Bob, and Mike. Right. So what continue does. So if I simply say continue. So what continue does continue. Instead of breaking out of the loop, it simply goes back to the beginning of the loop. So in this case, we have name starts with A. If that's the case, we basically we're not running anything after this line right here. Actually. Sorry. So anything after this line right here. So if this line is executed, we simply go back to the loop and then run everything again. So for this example, what's going to happen is the first time that the loop goes around. So this is Anna starts with a continue. And then this line right here is never executed. And then it goes and he checks the second one. Ali starts with a yes. Don't execute this line. Right. So don't execute anything that comes after continue. And then Bob does. Bob starts with a no print. This line means with a no print this line. So if I run this, we should only see Bulb and Mike. There we go. Bug and Mike. So there we go. This is how you use the break and continued keyword. If you have any questions, go ahead and drop a message. Otherwise, let's move on. Let's learn about the while loop. So the while loop allows us to loop while a bowling expression. Evaluates to true. So the syntax is as follows. So while and then parentheses. And then right here, this part right here. This is the actual bulling expression. So right here. If I say false, you see that IntelliJ is telling me that this is an unreachable statement. Right. Because if this is false, this won't be executed. But if I change this to true, you can see that. Now I can say south. And then here, let me simply say high. Right. So if I run this code, this will run forever. This again will run forever. So if I run it, you should see on the console that we have high. And you can see here is just running forever. So this will never stop. So what I'm going to do is I'm going to pretty much just stop, because this is actually consuming lots of resources. And I'm going to declare a variable. So let me say simply end and then count equals two and then zero. Now, here I'm going to say while count is less or equal to 20, I'm going to print the value of count. So I'm going to say actually count, and then plus and then account. And then in here I'm going to increment the value of count. So I'm going to say account and then plus plus. Now if I run this, this should only run 20 times. So there we go. So count 20. And you can see that it ran exactly 20 times. So in the event account equals to let's say 21, run it. You can see that this does nothing because 21. So count is actually bigger than 20. So therefore this won't be executed. So this is how you use the while loop. So basically, while pretty much just runs your loop, while the Bolding expression is true. As soon as the Bolding expression is twelve, then it primer breaks out of the loop. The final loop that I want to teach you is the do while loop. So as you saw previously, the while loop simply executes the block of code inside of the curly braces while a condition is true. So if I run this, so you remember what we've done before, you see that it brings all the numbers from zero to 20. If I say that this is 21 and then run it, you can see that this does nothing. So let's say that we want to print the number at least once inside of the loop. So we want to know the current number and then perform the actual loop. So this is when we have the do while loop. So do while loop works as follows. And then right here, I need to grab all of that and then move these parenthesis here. So basically it's a little bit different. But you can see that now if I put this inside, and what this loop is saying is that no matter what, I'm going to do this at least once while this condition is true. So at least once. Right. So remember, we change this to 21 with a while loop and nothing got printed to the console. But now if I run this program, you see that we have at least 21. Right. Because this is actually executed at least once. But then obviously this condition is false. So then it doesn't execute this piece of code again. So if I was to change this back to zero, this will work in the exact same way. So there you go. So zero to 20. And basically it's just printing this, increasing the value of count. And then checking, is count less than 20? Yes. Do this again is countless than 20. Yes. Until Cow is less or equal to 20. And then he pauses. But the difference between the normal while loop. So this while loop. So while and the true. And this one right here. So let me collapse this. So the difference between do wild and while is that door while executes no matter what, at least once. So this block of code here is executed at least once, whereas the while loop it doesn't. So if you need something to be executed at least once, then use do while loop. Otherwise, just use while loops. If you have any questions, drop my message. Otherwise, let's move on. Right. Let's go ahead and learn about the scanner class. And basically, the scanner class allows us to take user input from the console. So let's create a very simple program that takes the user name and then print to the Council, Hello. And then the actual name. So go ahead and simply type scanner, scan. And this comes from Java Util, and make sure it's capital S and then scanner. So right here, you can see the import statement from Java Util scanner. And then let me simply name these scanner equals to new and then scanner. And then within parentheses, simply type system, dot, and then in lowercase in just like that, we have now this variable right here, which is an object, and I'm going to explain objects what objects mean in a second. But this variable right here now can take user input from the console. So if I rent this program, you see that the program runs, and in the console, nothing happens. And then the process finishes. So the program just exits. So what we're going to do is actually say south. So let's simply say south. And then what is your name? And what we're gonna do is to take the actual user input, we will simply say scanner, don't. And then next and then line. So next line means take the actual string that comes from the console. So right here, you'll see this in a second. So right here, and then user. And the name. Now, if I run this program, you can see that we have what's your name, but the program does not exit because it's just waiting for user input. So let's simply say I go and then code enter, and I can see that the process has finished. So now we know that this user name variable right here contains Amigos code or whatever comes from the console. So let's simply say south, and then Hello. And then plus username. So if I run this, what's your name? I'm going to type this time. Maria, enter. And you can see that we have a low Maria. Now, let's also take the actual age. And then from the age, we want to calculate the actual year of birth. So for that, let's simply have south again. And let's simply add some spaces here. So we want to have how old are you? And then right here, we're going to use the actual scanner again, dot, and then next, and then Int. So we want that to be a number. We're going to store that into a variable. Age equals two. And then what we're going to do is simply subtract the current year minus H. And that will give us the year that the person was born right here. Let's simply say local and in date, dot and then now dot and N minus years and an age, and then dot and then get in a year. So this now returns the actual year that the person was born. So now I can go ahead and simply say south, and then you were born in and then plus year. Now let's run the program. So if I put this a bit bigger. So what's your name? So let's simply say Ali. And then Hello, Ali. How old are you? Let me simply say that AI is 21 and then enter. There we go. You were born in 1999. Let's also say that we want to check whether Ali is an adult or not. So if I say if and an age is less than 18, you want to say south and you are not an adult. Else I want to take the exact same print statement and then simply say you are an adult and then put a smiley face. There we go. So if I now run this program, there we go. What's your name? Let's say in this time and then see a loan. How old are you? Let's say she is 25. There we go. So you see that you were born in 90 95 and you are an adult. If I run the program again and then the NAB, how old are you, 25 or actually not? Let's say 17. There we go. You were born in 2003 and you are not an adult. Maybe we could put a sad face here. Right. And there we go. So I just wanted to show you how to build a very simple program that takes user input from the console. Now you know how to use the scanner class. If you have any questions, go ahead and drop my message. Otherwise, let's move on. Let's learn about methods. So methods is simply a block of code which only runs when it's called. We can pass data into a method. This is known as parameters. In intel, methods are used to perform any logic. When I mean logic, I mean actions, whether it is to transform some data or any piece of code that does something. So we have two types of methods we have built in methods, and these are methods provided by the Java runtime environment. And then we have user predefined methods. So those are methods that we build ourselves. So just an example. So right here. So check this out. So you've seen that system Oops, no system tray, but system dot out dot and then print Ellen. So print Ellen is a method. And right here. So these parenthesis simply implies that we are invoking the actual method. So I sent that with methods, we can pass some data, and these are known as parameters. So right here. You've seen that we've been printing to the console. So here let me simply say Hello and then run this. There we go. So you see that we have Hello. So this method right here. So this method print Helen is provided by default. We didn't write this method ourselves. So the same width. For example, if I create a string variable, so string. And let's simply say brand equals two. And then Samsung. And right here, let's go ahead and simply say south. Right. So print a lens. So we are invoking this method. And then let's simply say brand dot, and then two upper case. So here you've seen this as well. So this also is a method. So right here, we have these two parentheses. Right. Which denotes that we are invoking the actual method. And in this method we are not passing any data. So this method simply transforms this data. Right here. So this one right here. So Samsung. So basically it transforms it into upper case. If I run it, you see that everything is in uppercase. So let me show you one more method. So right here. If I say brand dot and then contains. Oh, actually. So basically, right here, you can see that there are lots of methods. Right. And then let's say that starts with. So right here. So starts with. And then let's simply check whether it starts with S. Right. So we are passing some data into this method right here called starts with. And what this method returns is a boolean starts with a S equals two. And if I now start to the console, that variable and run it, you can see that it is true. I can change this to lowercase S, run it. It is false. So I can take this. And let me just take that and then delete this line and then print it inside inline. Sorry. And now I can duplicate this, and I've got ends with. So right here. Let me actually change this to Apple case. So now if I run this, I see that starts with capital S. True. Ends with lowercase S is false. I change that to lowercase G. There we go. So true and true. So if I type Brand, and then do you see that we have a bunch of these methods, so we don't write any of these methods. So this is given to us by default. So with Java, there are many classes, such as the string class that comes with a bunch of methods that we can use. And throughout your journey in learning Java, you will start remembering these methods as you use them again and again and again. So next, let's go ahead and write our very own method. Let's go ahead and create a Char array. And in here, let's simply say, lettuce equals two. And then right here, let's simply add some letters. So. And then A and then B and then C. And then finally D. Right. So let's have D actually two times actually three times D. So we have so two times B, one time, one time, and then D three times. So let's create a method that will count the number of occurrences for any given letter. So right here, outside of this main method. Right here. So this in fact. So the public studied void main is a method, and you can see that the parameters are a string array, so called arc. So this is more on the advanced side of things. But don't worry about what this actually means and where it comes from, because you will learn that in later courses. So right here, let's go ahead. After the main method, for now, simply type public and then static, and then it and then count, and then letters, and then occurrences, and then open curly brackets. And for now, simply return. So let's return zero for now. Right. So public means that this method is accessible by other classes. So you'll learn more about the access modifiers of a method. Static means that this method belongs to a class. Again, don't worry much about it because you'll learn this later and then Int. So this it is the actual return type of this method. So right here, I'm saying return zero. So if I also say 0.0, this doesn't work because I've told this method to return an integer. If I wanted a double, I could say double. You can see that now this works. So simply say it. And then here for now, that simply return zero. Now, right here. This is the actual name of the method. And you've learned how to name variables. Right. And I said the way that you name variables and methods, they are the exact same thing. And you should be naming your variable methods. Camel case. Now in here. So two sets of parentheses. This is what we can pass into this method right here. So for now, we're not passing anything, but just follow along. Now, what I'm going to do here is simply invoke this method. So I'm going to call the method the same way that we invoke system dot out, dot print line. I'm going to invoke this method. So here I'm going to say count occurrences, and there we go. So now I'm actually calling the method. So if I run this, nothing happens. Right. Nothing happens because this method is not doing anything, really. So he's just returning the actual value zero. So here I could say Int. And then count equals two. And now if I simply print the actual count value, so count and then run, you can see that we have zero right here. Right. So if I also change this to minus one, run it. There we go. See that we have minus one the same if I was to log so south. So inside of the method. So method. And then let me copy that was invoked. So I'm saying that every time that you invoke this method print this and also return minus one. So if I run this, there we go. So you can see that method count occurrences was invoked, and then minus one is the actual return, which we are printing in line number nine. Now, the way that you can pass data inside of your method is as follows, so in here. So in this set of parentheses, what I'm going to do simply say that this method will accept an array of characters. So I want to say car, and then this will be the array. And then I'm going to say letters. Now, this method will receive this array. And in here you can see that we have an error. So this is actually red. And this is because it's saying expected one argument, but found zero. Right. So here what I'm going to do is simply take my letters and then pass letters here. Now, you can see that the data type is an array of characters. So if it was, for example, to pass a string, this will not work if I was to create an array. So an array of strings, and let me simply say names actually equals two and empty for now. So if I was to pass names inside, this will not work unless I change this to string. So this will match the actual data type, and this will work. Now, let me actually go back there we go. So there we go. So I'm going to go back here. Now let me pass letters inside. And this is how we pass data inside of our method. Next, let's go ahead and implement the actual logic that will count the number of occurrences for any given letter. Right. So we want to find out how many times, for example, the letter A appears in this array. So in our method, we are accepting the array. Right. But we also need to accept the actual character that we are looking for. So here I'm going to say comma. Then this will be a chart. And let me actually put this on a new line. So you see everything properly. So this will be a chart. I'm going to name this as search, and then a letter. Right. Now, again, this is complaining because I need to pass a letter. So I'm gonna say comma. And then again, this has to be a character. So a character of type car, right. Now, I do have both the actual letters inside as well as the search letter. So in our case, the letters is the above array. And then we want to search for letter A. Now, let me remove this print line. And what I'm going to do is simply say south. And then I'm going to say arrays, dot to string, and then letters. And I also south the actual search letter. Right. If I run this, you should see that we have printed the actual array. And then this is what we pass into the method. So if I was to, for example, search for the letter B or actually, right there we go. So this is the array. And inside of this array, we want to search for the letter Z. So now that we have those two arguments coming into our method, let's go ahead and do some search. So what we're going to do is use a four loop, and this will be four, and then car and then C, I and then lettuce actually let me simply say letter, there you go. And right here, we are going to do a comparison between the search letter that comes into our method against every single letter in this array. So here I'm going to say if and then letter and then equals to search letter. We want to do something. Right. We want to do something. So what we want to do is actually increment counter. We need to keep track of a counter that will tell us how many times that a letter appears in our array. So here, just before the for loop, I'm going to create a variable. I'm going say it, and then count equals to zero. So initially, this will be zero. So if the letter right that we are looping through is equal to the search letter, and when you say count plus plus, some going to increment count. And to be honest, this is all. Now, the last thing that we have to do is simply to return the actual count. There we go. And this is our method right here. So now if I run the actual method. So this main method, and you can see right here. So right here, we are passing the letters, and then we are searching for. So if I run this, you can see that Z appears in our array zero times. Right. Now, if I go ahead and search for A and then run this, I should appear two times. Let's search for the can capital D, and there we go three times. So one, two, three, and then appears one. And let's try an N does not appear. Therefore, it's zero. So there you have it. So we've built our very first method, and you can see that this could be really anything that you want. And this is what programming is about. Right. So programming is about you solving problems by creating methods and then writing algorithms inside of those methods. Right. So an algorithm is simply a sequence of steps to solve a problem. So here this is our algorithm. Right. We are searching for a letter and see how many times that appears in an array. This is just a quick introduction, or this is just a quick introduction about methods. There is more to it, which I'm going to show you later. But if you have any questions, go ahead and drop a message. Otherwise, let's move on. All right. Now, let's learn about classes and objects. So a class is a blueprint to create anything that you want. Right. I remember I used to really struggle with this concept, but I want to make sure that you really understand this concept. So let me just take this lens right here. So if you see, this is my Sony lens. Right. What a class is a class is a blueprint for creating these lenses. Right. So for example, whether it's Sony or Cannon, they have their own machines for creating lenses. Right. So those are the actual blueprint, how these lenses are constructed. Right. So that's a blueprint. You define basically a template of how to create lenses. And then from that template or that blueprint, you can create multiple lenses. So then you have the actual template. You say, now I want this lens right here. Right. And then from that same blueprint, you can create this other lens, but with different attributes. Right. And these two individual lenses, right here. The these are the actual objects themselves. So this is an object is an object is anything, literally anything that you can think of in the real world. So here we have a lens. So this is the actual object. Right. So what creates these objects are the actual classes or blueprints. So the same with I would say, for example, this sticker. Right. You could literally represent this in code. Right. So here you could say, for example, the color, the text, so on and so forth. So with classes and objects. Right. So when you define classes, and I'm going to show you exactly in a second. So with classes, they have two things. They have the attributes. So these are the things that define the actual objects that you want to create. For example, this lens. Right here. So the attributes would be, for example, the color, the aperture. Right. So those would be the actual attribute, whether it is prime or not, the brand. These are the attributes. Right. And then the behaviors is what this lens can do. Right. This lens can focus. Right. And also in combination with the camera, it can take pictures. Right. So this can focus. And I think basically, if it's prime or not, then you can actually Zoom as well. Right. Another example is, for example, my phone. Right. So this phone right here. So technically, I could represent this in code. Literally. I could represent the same code. I could have a class that defines the template for creating mobile phones. Right. And then I could create a bunch of objects. Now this all of a sudden is actually the object that was created or instantiated from a blueprint. Right. And in software, everything is based on classes and objects. And on the second part of this course, you will learn about Oop so object oriented programming. And this is where you'll see, like, you can literally define objects for everything objects. You could represent anything in the real world, anything in software, basically anything you want. So this is an intro of classes and objects. If you have any questions, go ahead and let me know. Next. Let me actually show you this in Right. Let's go ahead and create a blueprint or a template. Right. Actually, let's go ahead and create a class that allows us to create lenses. So you saw that my lens, right. Is a Sonic lens, is prime, and the focal length is 85 mm. So we can represent that in code by creating a class. So a class is a blueprint. And then from that class, we can create the actual object, which will be the actual length. So to create a class, go ahead. And right here, after the public static void main method, go ahead and simply say static. And then class and the lens, and make sure that you have these curly brackets. So now inside of this lens, we can define some properties. Right. So we know that a lens has brand. So we're going to represent this as a string. So string, brand. And let's also say that we have the focal length, so focal and a length. And we can also know whether this is a prime lens or not. So, boolean and then is prime. Now we have the actual properties of this class. Right. So now we need a way for us to actually create objects by passing some properties. So let's go ahead and simply say lens. And then within parentheses, simply say string, and then brand, string and the focal length. And then boolean is prime. So let me put this on a new line so you can see everything. Now add curly brackets. And this guy right here, it's called the constructor. So the constructor is how we construct these objects. Right. So what I'm going to do here is simply say this dot, and then brand equals to brand. And then this dot, and then focal length equals to focal length. And then this dot is prime, equals two is and then prime. So when I say this, I'm referring to the current instance of the current class. So you're going to see this in a very second. So this now is our blueprint. So this is our template for creating lenses. Right. So just bear in mind that the reason why we are using the static keyword is because we want to be able to use this class inside of this public static void main. So there are better ways of creating classes. I having a file with this class in it. But for now, I just want to keep things very simple and in one place, now that we have the blueprint for creating lenses or the blueprint or the template for creating lenses. Next, let's go ahead and create two lenses based off this template. Right. To create a lens based off this template right here. So class, lens. Let's do the following. So let's go ahead and simply say lens. And here let's go ahead and simply say lens, and then one equals two. And then new and then lens. So you've seen the new keyword. Right. So as soon as I say new, this variable. Right here. So this guy right here is the actual object. So this is the real thing in the real world that we are modeling. Right. So that we are representing. So this is the actual lens now in the constructor. So this guy right here. So this guy we said that we accept the brand focal length and its prime. So the brand let's simply say that this is Sony. And let me put this on a new line. So you see everything properly and then comma. And right here, focal length. Let me simply say 85. And then miles. And next, whether it's a prime lens or not. So let me simply say true. Right. So this is a prime lens. Right. So that's the big lens that you saw. So there we go. So this now is the actual lens. So this is an object. We've done it. We actually representing something in the real world. Right. So the template now allows us to create as many lenses that we want. Literally, we can create thousands of lenses. Right. And this is what happens in the real world. So the actual the actual blueprint for creating lenses. So these are like in factories. They have all these machines that can create a bunch of identical lenses. Right. But they can tweak a few things. They can change the color. They can change the actual focal length. So on and so forth. Right. So we are doing the exact same thing with our blueprint or template. And then here when we say new lens, and then we pass all the information about the lens that we are building, then we have an object. So this guy right here. So you see that we have brand and the column. So don't type that, because this is IntelliJ helping us to know what the name of the argument should be, ie. So right here. So it's basically taking this name right here and then saying that the first argument is called brand. So then it just helps me to know that this is a brand. So I could say Canon, for example. Right. So Canon. Right. But don't type brand. So basically I'm saying don't do this brand and then column and then don't do that. Right. So if you don't see that, it's because IntelliJ is not giving you the suggestion for your argument. So here let me see to say Sony, and let's create a Netherland. So I'm going to copy this and then paste that. I'm going to say lens, and then two. So the other one was 830 meal. And finally, let's go ahead and create a third lens. And this will be lens, and then three. And for now, let's simply say Cannon. And then the focal length will be 24 to 70 and then M. And then this is no prime lens. So simply say false. So there you have it. So now you can see that we have three lenses. So now that we have these three lenses, next, let's go ahead and actually print the console the actual attributes for each lens. So let's go ahead and create or actually let's simply say south and then lines, and then one actually one like that. So let's simply say south and then lens one, dot and then brand. And then let's duplicate this two times. And we want the actual focal length. The actual is prime value. And let me grab all of this again. And then let me simply paste that in have some space here. So you see exactly everything. So lens to and this will be lens. And then two actually not three, two. And then let's copy again all of this, and then put it here. And then lens three. And then this should be three, just like that. Now let me go ahead and simply run this program. So if I expand this and let's add some spaces. So south print line, and then south print line here. So let me run it again. There. You have it. So if I expand this, you can see that we have on the console, lens one, and you can see the details. So Sony 85 true for whether it's prime or not, then we have Lens two, it's Sony 30 M M and also prime three, Canon 24 70. And then false is not prime. So hopefully you can see that how classes and objects work. So right here, we could actually have more information. Right. So, you know, we have the brand, but we could also, for example, include the actual model. Right. So string and then model. We could also have string and then color and then perhaps the actual price as well. So price. And then and then the actual weight. So the actual weight of the lens. And you can see that we can model this with a bunch of properties. Right. So when I say we can model anything that you think of in the real world into code, I mean, you can. So this is how you do it with classes and objects. So this is just an introduction about classes and objects. But I'm going to show you later in my other course exactly how to build classes and understand the properties and behaviors, and also have the methods and the best practices for creating classes. So this is all for now. If you have any questions on classes and objects, please do let me know. But remember a class. So this class right here is a blueprint for creating objects. And what an object is is something that models something in the real world. This all for now. Catch me on the next one. All right. So I just want to give you one more example of classes. So you saw that before. We represented the actual passport and a number as a string. Right. So let's say that we have this passport number. Right. Now, technically, there is more twit when you want to represent a passport. So you've got the country, you've got the expiry date, you've got the issue date on and so forth. So let's go ahead and actually model a passport. So right here. Let's go ahead and say static and then class and then password. So make sure the class starts with uppercase. So here passport. Now we can have the actual number. Right. And then let's also have for now the actual expiry date. So we're going to represent this as local date and the expiry and then date. Right. Now let's go ahead and have a constructor so that we can create multiple of these. So passport. And we're going to have a string and a number. We're also going to have local date. And then this will be the expiry date. Now this don't and then number equals to number. And then this dot expiry date equals to expiry date. Right. So this right here refers to the current instance of the current class. The same with this local date, expiry date. Now that we have a passport. So again, you can have more than these two attributes. I'm just keeping it simple for now. Now that we have a template for creating passports, let's go ahead and create a passport passport. And let's say that we have UK passport equals to new and then passport. So number two. Oh, actually, let's just keep it simple. One. Oh, actually, let me put, like, a real number. So let me put this on a new line, just like that. So number 1234 and then expiry date. So this is local date and then dot of and then we have to pass the actual year. So 20, let's say 2025. And then one and then one. So that's the actual month and a day. Now let's go ahead and another passport. So passport and the US passport equals to new and then passport. There we go. And let me grab all of that. So just going to grab that and then put it there. And let's change this t0999. And you can see the expire date. Let's say that this is 2030. Right. Just like that. So we can actually have one more property here. And that is the actual country. So string country. And then here string and in country. And let's also pass country here. So this dot and country equals to country. And I put this on a new line so that you can see everything. And now we have an error because we have to pass the actual country as well. So this will be England. And then let's simply say UK and in here. Oops, not there. So here and then here. So now we have USA, just like that. And there you have it. I'm missing actually a comment there. So this is just another example of classes so that you see that we can represent anything that you want. Really? So if you have any questions and classes, please do let me know. And I'll try and give you more examples. Right. I want to congratulate you for reaching this far and completing this course. So I absolutely had fun teaching you Java. And the next step for you is to enroll to my Java Essentials course. So in Java Essentials, we're going to continue what we've learned in this course. And I'm going to touch upon more advanced concepts, the goal release, just to keep on improving your Java knowledge. And at the end of that course, you will fully grasp this language, allowing you to start building applications on your own, using, for example, frameworks such as Spring Boot, Quarks, and many others. So it was a pleasure teaching you Java. And before I forget, if you're not part of the community, go ahead and join the private Facebook group. As well as discord. The community is growing, and I would love you to be part of it. This is all for now. Give me a thumbs up so I can keep on providing courses like this and also subscribe to my channel. I'll catch you on the next one. Salam Malik.