Transcript for:
Comprehensive Overview of Java Programming

welcome to Amigos code in this Java course I'm going to teach you the foundation of this awesome programming language called Java Java is a programming language which is used by companies such as Google Facebook Twitter Spotify AWS and a bunch of other startups to power their backend systems it's a language which will stay here for a long time and taught at universities boot camps foreign [Music] because Java is a mature language it has lots of libraries and packages which are very standardized and it has an amazing Community Java is a language which is not going to die anytime soon and you should know Java because you will open the doors to learn many other programming languages if you're new to my channel literally just take one second and smash the like button also subscribe literally subscribe so I can keep on providing content and courses like these without further Ado let's start this crash course okie dokie let's go ahead and understand what exactly is Java Java is an object oriented programming language meaning that you can take anything that you want literally anything so let's just take for example this cup in here and this remote in here so we can turn everything into an object so programs in Java they are based of objects so you create a bunch of objects and then you connect those objects together right so we try to model something in the real world and also things in software as you see later in this course but basically everything is an object for example a sequence of characters is an object and later you'll learn about strings and all the other classes for example working with dates as well but you'll see how everything is an object Java was created by James Gosling in 1995. so it's been some time really and um you might be thinking right so Java is you know quite old yes indeed it's quite old but it's used throughout the industry if you want to build Enterprise applications so the cool thing about Java is that it's established already it's a language which is established there's already patents and it's a safe language if you want to build large-scale applications so Java is a must Java is a must there's a famous quote that says that Java runs on three billion devices and that is I think I'm not too sure how how accurate they are but you can see that Java is popular so you'll see the uses of java in a second but Java is very similar to C plus plus so if you've done some C plus plus before Java will be very easy um this is because you know with Java you don't have to manage the members so all of that is done by um the language itself whereas with C plus plus you have to you know allocate deallocate memory and you know it can be a little bit challenging for beginners to to do this right also I think it's it's very important to stress out that C C plus plus so these are the mothers of all languages but I also add to add in Java after C plus plus because once you learn Java you'll see that the rest of the languages so you take python you take JavaScript you take golang you take many other languages you'll see some similarities in it some similarities and with Java you learn a bunch of constructs that when you move through those languages you'll be like wow this is a piece of cake so Java is a must so this is what they teach at universities and yeah so this is why I'm teaching you because you know I want you to learn Java so that you go off and you know find a job and throughout your career you'll realize that you know a language is just a tool and Java it's the perfect language for beginners and finally Java is very popular so you can build back-end applications you can build front-end applications I think still maybe a little bit of mobile apps today but now all of that is Shifting to kotlin and yeah so Java is very popular lots of companies are hiring Java developers so it's a language that you should have under your toolbox that's all for now catch me on the next one so before we continue Eddie further I just want to say that this course is part of the brand new course which I've just released on my website and it was a course that I did teach at a boot camp for over a year many students of that course they managed to go off and secure jobs and yeah so I was like you know what let me just um take whatever I'm teaching to these students and make it available at a very cheap price and also online right so if you want to watch the videos again and again and again the way I teach as if I was teaching for a boot camp it's there for you also there's something called The Amigos called textbook with a bunch of exercises and code examples that you can use alongside with the course we also have a private Discord Community where you can join and if you have any questions or you're stuck or you want to suggest some ideas we'll be there throughout the entire course so you're not alone currently there's a 20 off so I'll definitely take advantage as many people already did and I'll say this is the right time for you to invest in yourself you've seen how Tech and programming is becoming very popular and the the sad thing is there's a bunch of jobs out there but not enough Engineers so what are you waiting for let's get started so what can you build with Java well the list is huge but let me show you some of the things that you'll most likely be doing with Java you can build mobile apps for Android so even though Now new applications are being built with kotlin which is a a another language but you'll find that there's still some large applications which are still built with Java but technically speaking I think you're going to be reusing kotlin if you you you write a brand new application but nevertheless Java still used for Android you can also build desktop applications using Java Swing which is kind of also if you ever went to the airport and you've seen these really ugly uis um most likely is Java Swing so Java FX is yet another way that you can build desktop applications which a better UI but I think you'll see majority of old applications are using JavaScript which Java you can build Enterprise applications so let's say that you want to build for example a bank you can't build a bank with Java so here we're talking big large scale applications you can pretty much think of any idea that you want to build and you can use Java if you didn't know Java was used to build Minecraft so here from Wikipedia Minecraft is a Sandbox game developed by Mojang I'm not sure if I'm pronouncing that name correctly the game was created by Marcus Notch Pearson in the Java programming language so this was like back in the days and you can see um what what a programming language is basically but Java was used to build the initial implementation of Minecraft nowadays I'm not sure what they use but it's a popular game you can also build cloud-based applications so if you learn about the cloud later AWS Azure Google Cloud you can build cloud-based applications such as serverless applications and all the types of applications using Java also web applications so the Java language is um so cool because you can actually build an entire web application so backend front end everything using Java to be honest right but I'll show you what is the best approach for you to build applications but you can see that you can actually build a lot with Java so there are more other things that you can absolutely build with Java but these are some of the things that you'll be developing with Java so you saw some of the things that you can actually build with Java but let me tell you with Java what you're going to be building most of the times and this is the beauty of java really so Java is a language mainly for the back end so the business logic so the brains right and we'll talk about more front-end back-end and whatnot but front end is what the user sees so the buttons um the the color the interaction that the user has for example on a web page and the back end is the actual business logic so it's actually the brain so you don't see that but for example if you try and and buy for example a mobile phone and you don't have enough credit right so that logic of saying right so you don't have enough credit your card is now declined so all of that is in the back end so Java is a language use most of the times for the blanket if you try to build for example uis user interfaces with Java I don't recommend you to do that because there are other options JavaScript is the the most used programming language for UI and then you have the Frameworks react view angular and all this right but Java is used mainly for the back and don't even try games as well so for games back in the days yes but games you might want to try for example C sharp um and also if you're building for example you know small applications like command line applications and whatnot I would you know try and stay away from using Java so Java is mainly for the back end where later you'll see um with spring boot so upon completion of this course you'll see how we're going to build um a restful API where you've got a client so these could be um you know you using a web application on a web browser and then you have um the client sending a request to the back end and then all of this so all of this here is where Java kicks in right so Java takes a request then you have the business layer this is the end-to-ear architecture and you learn all of this later but basically here you kind of make your business decisions and then you have the Dao layer where you can actually store data against any database of choice whether it's a relational database a file or a list or a nosql database and then you actually send a response back to the client so the client the client sends a request and then the server right so the the API sends a response so all of this is stuff that you don't see so this is the back end and Java it's mainly used for the backend I'm not going to teach you Java for swing nor Java FX nor games and whatnot I'm going to teach you what Java these days is used for which is to build Enterprise applications and in fact let me show you what I mean I used to work for this company here called Stalin bank and I actually joined you know early stages when it was actually a startup about 50 or maybe say engineers and I've helped him to build majority of you know the the the the back end systems some UI as well would react and JavaScript but they now so they are very big company now right so you see that you know we Java they went and they built a bank this is a bank which runs just on your phone and it's incredible to see that you know with Java you know if you look at the code base there's thousands and thousands and thousands that or actually over a million millions and lines of code uh just with Java right so if you want to build Enterprise application with Java you can see that you know starting Bank they've done it there are many other startups that use Java because you know the demand for Java Engineers is is quite High there's many Engineers that know Java and yeah so whether it's a big or small companies they usually tend to use Java because it's very easy um and there's lots of people to hire and whereas if for example you were to say right so now I want to use golang for example to to build an application not many people know golang or experts um in in goal line because golang it's language which hasn't been around for for many years whereas Java it's been around for many years the the the patterns are already established the tools are already there this is why people use Java so it's very popular among startup and actually one application which which actually you might be surprised if you know IntelliJ and this is what we're going to be using throughout this course IntelliJ is actually built with Java so this is the best IDE for writing Java and other languages basically um but it's the best IDE for the jvm IntelliJ and all of this so the UI so even the UI is actually built with Java Swing and it's amazing how I don't even know how they've done it but it's amazing so IntelliJ it's amazing and that's what you're going to be using throughout this course I wouldn't recommend you to go and build an IDE with Java because it's going to be costly to you and um yeah I don't know I don't know I don't know I just feel like you know it takes a lot of effort and um you know guts to actually build something like this with Java cool so that's all for now catch me on the next one okey dokey now we are almost to a point where we're going to be able to write our very first Java program but first how do we even write Java code so how do we basically write code for the Java language well we can pretty much use any text editor to be honest so we could use notepad plus plus we could use Sublime Microsoft Word if you wanted to but don't don't don't don't do that yeah so when it comes to Java there are a couple of Ides and text editors that you should really be using so one of them is Eclipse so when I started back in the days long time ago Eclipse was the most popular IDE for writing Java code but since time has moved on IntelliJ IDEA now is the preferred choice for writing Java code so the integration that it has to offer the tools they are amazing and it's the one that I recommend to everybody and people even when they switch from Eclipse to IntelliJ is like night and day trust me then we also have Visual Studio code now Visual Studio code is kind of nice as a text editor and it doesn't come with you know all the support that eclipse and IntelliJ come right out of the box because you kind of have to install a bunch of plugins here and there now you could use Visual Studio code but you need to know what you're going to install in order to make a fully fledged IDE because Visual Studio on its own is just a text editor so for this course we're going to use IntelliJ IDEA so as I said the most popular IDE for Java is IntelliJ IDEA and this is by jetbrains so jetbrains is a company and they not only have IntelliJ IDEA but they have a ton of other cool Ides now for IntelliJ there are two versions available we've got the Community Edition so this is free this is free and they have the ultimate edition so the ultimate edition is really great once you start to build web applications with spring Boot and connecting to databases and whatnot because it has all of that integration in the IDE itself but for this course we're going to use the Community Edition which is absolutely free and it has everything that we need in order to complete this course but then later we're going to switch to ultimate and luckily for you actually I've got some friends that jetbrains and I do have a coupon code that you can redeem so that you can get Ultimate Edition for three months if you also are a student you can get Ultimate Edition for free or if you're a teacher if I'm not mistaken cool so let's go ahead and download and install IntelliJ okie dokie in here I'm within the official webpage for jetbrains.com forward slash ideas so this is the official page for IntelliJ now in here it tells you why you should use IntelliJ so enjoy productive Java and you can see that it's quite slick to be honest DUI if I scroll down it gives you a bunch of Integrations framework specific assistance productivity boosters so you can automate stuff and you can see that it's kind of cool and in here what people say about intellitrade also the companies all the new features in here so on and so forth now IntelliJ right here it's mainly for Java developers and this is only true when you use the Community Edition so if I click on download from here or here so you'll see that there are two versions so the ultimate edition or community so the Community Edition is for jvm and Android development so this is what I've just said and we have ultimate for web and Enterprise development and you can see the differences in here so the ultimate right here supports Java kotlin groovy scholar and there's also a bunch of plugins that you can install for example if you wanted to go development you can install a plugin for go or python so on and so forth but here you can see the features which are common to both IntelliJ ultimate as well as the Community Edition now the ultimate where it really shines is for example if you are working with spring Jakarta ee Java ee Micronaut quarkus and other Frameworks also it gives you an hdb client that you can test your rest apis and then here is supports so JavaScript and then in here it has support for JavaScript typescript HTML CSS node.js angular react View and I believe there's some other Integrations as well this one is kind of cool database tool and SQL so you have a SQL GUI client within your IDE which is kind of nice and then remote development and collaborative development and I think for the Community Edition it allows hosts up to three guests and sessions length up to 30 minutes so I will show you this later on but it's kind of cool so if you're working within a team and you want to do some paid programming this is a really good feature that you can use from within internet so this is pretty much IntelliJ and I don't think I did mention but for the ultimate version you have to pay and it comes with 30-day free trial and to be honest I think in my opinion it's really worth it because as a professional software engineer I've been using IntelliJ for many years now and it's one of those ideas that yes you definitely have to have it if you are serious about software development and if you are serious when it comes to increase your productivity also there is the Community Edition and to be fair I've used the Community Edition for many years before I actually made a switch to Ultimate Edition so I would say start with the community and then try ultimate but once you learn Community then everything will apply to Ultimate and as you saw you'll just get a bunch of more features especially if you're working with spring and you're doing lots of database work then it's really worth it and especially if you are one of those developers that really like to have one IDE for all of their development then ultimate it's a no-brainer but if you for example like to have maybe IntelliJ just for the back end and then vs code for the front end and any other type of work then you should go with Community But as time progresses you kind of just want to stick with one IDE because it's all about increasing productivity once you learn this IDE well enough you'll see that it's a game changer now you can download IntelliJ from for Windows Mac OS or Linux by clicking the these buttons in here but this is not the best way for you to install IntelliJ and instead you should use toolbox to install toolbox click on developer tools and in here you should see plugin and services click on toolbox app and in here you can see that toolbox allows you to manage your Ides so it's available for Intel Mac OS as well as Linux so download and install according to your operating system so for me I'm on Mac OS Apple silicon I'm going to save and there we go now if I open up the downloads folder and in here let me just open up this DMG file and to install just take this and drag it inside of applications and job done I can close that and then eject and now to open it up just search for toolbox there we go and then open and I'm going to disable notifications and have a look now toolbox is open and we can install all the plugins through this app so if you want to upgrade downgrade and add some configuration for your Ides this is the best way of you doing it so you can see the list of all the Ides in here now the one that we are interested is IntelliJ IDEA Community Edition now I do recommend to start off with this one right here so the ultimate because it gives you all the tools for pretty much every single language out there and for now what we're going to do is start off with the community and then I'll switch to Ultimate so not everyone will be able to afford the ultimate so let's just start with the Community Edition because it has a lot of similarities and once you know Community Edition then ultimate will be almost the same thing but with extra features also what I didn't tell you is that you can basically if I click on this clock in here settings if you want you can create a jetbrains account through here and then you can log in so that it registers your settings and all the ideas that you have so if you switch computers then everything is synced up so for now I'm not going to do this and I'll do that later when we install IntelliJ ultimate so let me go back to tools and then install IntelliJ IDEA Community Edition so this will take a while so I'm just going to fast forward things so you don't have to wait so there we go and now I can open up IntelliJ Community Edition so just give it a second and in here I'm not going to send anything for now and there we go so you can see that I can actually import some configuration if I have but in here I'm not going to do anything and beautiful stuff and we have successfully installed IntelliJ okey dokey so as we begin this course we're going to start from the basics so what I want you to do is take your time don't rush it literally take your time and follow step by step if you have any questions or anything is unclear do let me know because I want to make sure that you gain the most out of this course so as the course progresses and Things become more difficult don't you worry again because we have a special Discord group just for this course where we can ask questions and also you can ask me questions if you are stuck but sit back relax take your time and if you don't understand something first time just watch the videos again and again and again until it makes fully sense I'm also going to be giving you exercises so don't you worry so we're gonna start off really small really simple but then as we progress through this course it will become more challenging but that is the whole point of this course because I want you to learn and go off and secure jobs and if this is a course which you are doing as part of your new job or maybe an intern or a grad scheme you will be fine trust me cool I'm super excited let's get started So within IntelliJ let's go ahead and create a new project and make sure to pick Java so you see that there are other project types but in here let's pick a Java project then for the SDK in here what I'm going to do is for you it says that there is none available or if it's red go ahead and click on it and then download jdk and here you can download a specific version So currently 17 is the latest as I speak and is the one that has the long term support as well so I think it's 17 as well as 11 and 1.8 these are long term support so 17 in here so if you see 18 for example what I want to do is you can pick any of these versions because everything will work but to make sure that everything works smoothly just follow along with the same version so 17. then the vendor I'm going to leave the default but you can have all the renders such as eclipse ibms on and so forth so I'm just going to stick with Oracle open jdk and then here I'm going to say download but obviously for me it's already installed so let me just cancel and then next and you can see that we can create a project from template I.E a command line application and for now let's just take this box in here and you can see it says simple Java application that includes a class with main method so next and then in here you can give it a project name so you can maybe just say Java or learning Java or your name anything really so here let's just say for example Java and for the base package name in here com Dot and then change this to your name or company so here I'm going to say Amigos and then code and then finish and there we go at this point you can see that on this side we have the project window so if I expand it you can see that we have a couple of folders so we have idea so this is mainly for IntelliJ so this is where all the configuration is for IntelliJ then we have SRC so this is where all your Java code should be if I open this up you can see that we have com dot Amigos code so this is the base package that we've just defined before and then here we have main so main so this is the name of the class that we have on this side this is where we write our Java code and basically the rest is IntelliJ slow here if I Collapse this you can see that this now takes the entire screen if I want to put it back I just press again and sometimes you might not see none of these panels so it's because of this button so here you can see that I can hide all of that and if I put it back you can see that all the panels come up and there we go next let's go ahead and write our very first Java program together in here we have this class called Main and there's a bunch of things in here which I want to make sure that you fully understand the meaning for example package public class public static void Main and then this write your code here so on and so forth but for now I just want to make sure that you can basically run your very first Java program so here let's type together after line six just say system Dot and then out Dot and then print Ln at this point I'm going to add double quotes So double quotes and then I'm going to say hello and then Java and I'm going to add an emoji and let me just select this one so now in order for us to run this code you can see that we have few play buttons so we have one play button in here another one here another one here and if you look carefully here so this class has also a play button which means that you can right click and then say run also if I right click on this side I can just say run so there's a couple of ways that we can run our Java code so let me just run it from here run Main and check this out so here we have hello Java and then our emoji so this is pretty much your very first Java program also if I hide this and let me duplicate this line and instead of saying hello Java I'm going to say 10 and then plus and then 10. let's just run this once more and there we go so you can see that we have hello Java and then 20. so this is the result of 10 plus 10. now this right here allows us to print to the console so this is our console in here so as I teach you and run all of the examples the output will be in this console which is accessible on this tab right here so the Run tab so I can click on it and you can see that it pops up I just want to make sure that you can run your very first Java program without no issues if you have any questions on running your code please do let me know otherwise catch me on the next video so let me open up the terminal within IntelliJ and in here I'm inside of java so this folder is the exact same thing as this one and what I want to do is to CD into SRC now within SRC what I'm going to say is Java C so this basically is using the Java compiler and I want to compile the class which lives under com forward slash Amigos code slash and then we have main.java so even though you don't see a DOT Java file extension in here but here have a look main.java so this is the file that we are working with now the Java extension this is what you and I we write so this is what we understand and in order for the jvm to run our code it needs the byte code so here if I basically press enter and you should see that now in a second there is a main.class now let's invoke the jvm I.E we want to run this code by saying Java and then you can say com forward slash m equals code forward slash and then Main and in here you don't need the dot class extension so it just knows that you want to run your class if I press enter have a look this is the exact same thing that we did before also instead of saying forward slash you can say dot so dot in here so com dot amigosco.main just like that and this works because this is the fully qualified name for this class right here because it lives under this package com dot Ami equals code and more on packages later so if I run this you can see that this also works now this is it it's super easy what IntelliJ does is so if I basically run this once more have a look so when we press the play button have a look so here the command which IntelliJ uses is so basically it finds the executable so Java right here and basically it passes some arguments so here Dash Java agent and if I scroll all the way to the right have a look it says class path so this is where to find all the classes when you run your Java code and in here it says users let me equals code ID project the Java out production and then Java right so this right here is our project and then it says right so under this class path find the class com dot amigoscode dot main so this is what we just did manually but IntelliJ is doing that for us now the compile classes are stored inside of the out folder have a look out production java.com Amigos code and then main so this is the class right here so this is the class file which is compiled if you have more classes in here everything will be compiled into this out folder so that IntelliJ can then invoke this command to run your application next let me go ahead and show you how to view the byte code another thing that I want to show you is that if for example we have any issues with our code so let's say that we are missing a semicolon in here now you can see immediately IntelliJ is telling me that there is something wrong going on so here this is red the package is also red the project is red this folder is also red and also here it's red if I pull my mask in here have a look it says semicolon expected now what I want to show you is if I try to run this you can see that it failed to compile so let me just delete this out folder for now and have a look if I try and run this so if I open up out folder there is no classes inside of this folder because the compilation failed so if we can compile it means that we cannot run our code so literally if you have any issues with your code you have to fix every single error that you have in order to compile your code so here if I add this back and then run it you should see that now we should have main dot class in here so the same thing if I just let's say that I'm missing this opening bracket in here so here if I basically from the time you know let's just open the terminal and let me clear the screen I've just pressed the up Arrow I want to compile the Java file and have a look it says that error reach end of a file while parsing and then you can see where it's telling you where the error is so the same thing if I try and run this through here we should get reach end of a file while parsing so this is something that you need to bear in mind is that if you have any issues with your code then it means that you cannot run it so let's say that I also have a new and then class so we haven't learned about classes but let's just say that you have a class called Foo in here now if this class has also problems so here now you can see that there is an error and even though the error is not present in this file called the main so have a look this file everything is fine but if I try to run it have a look it says that it failed to compile in here and it says that this is expected so here what we are doing now is we are basically just fixing the compilation error so here I've just added that and it fails to compile so if you want to just compile so here IntelliJ has this feature in this menu right here so if you click on I think it's build and then have a look you can build the project and it will basically try to compile and the same thing it just fails so something to bear in mind is that if you have any errors in any of the other files right so if you don't have an error in main but you have an error in some other file that you need to fix all of those errors before you can compile your code right so you can only run your code if it has no errors now when I mean errors I mean syntax errors right so you saw for example if I say in here let's just say for example 10 and then space 10. so this is not a valid code right so this is not a valid code therefore it will fail to compile and you won't get the byte code for it but if I basically have a plus in here this is fine if I try and run it you can see that it works because no other file has any errors so this process of fixing all of these errors sometimes you'll hear people saying that I have to fix all of the compilation errors so compilation error means that if there's a problem with your code or you're missing for example a bracket or a comma for example and you can see that this is red if I try to run the code it doesn't compile in here the build fails and I need to fix all the compilation errors so let me just fix one in here and off we go so if I run this we now fixed all the compilation errors and our program rents before we move any further let me talk about this method right here which is really really important so public static void main string arcs now all of this might not make sense to you and that's because I didn't explain but hopefully by the end of this course you will fully understand what all of this means but for now all the way to be aware of is that public static void main this is a method and it's a very special method because this method is the main entry point for your Java program so if you don't have a method called public static void main then your code will not run so have a look if I basically change this from public to let's just say remove that you can see that now I cannot run my code so I can right click have a look no way for me to run this code also from here right click no way to run this code so if I say public go back so now you can see that I can run the code so it's very important that you always have public static void main so this method in here and then whatever code that you have inside it will be executed so here if we run this once more you can see that we have hello Java now later down this course you understand how to structure your code correctly so that you can have multiple classes on and so forth but for now all I want you to know is that this is a very special method and it's the main entry point for your application now here you can see that we have public class main so this can be called anything so here if I rename this so right click refactor and then rename I can say for example full right here refactor so this can be anything literally any name so if you have this method then this will be the main entry point and the syntax should be exactly as it is in here public static void main parenthesis string and then these square brackets and arcs and you can have all of this code inside and this is what's going to be executed in here you see public static void public class package don't worry I want to teach you all of this in a second let me just press command Z and I want to have this class named as main so this is a better name so main basically means for the main class which contains the main method if you have any questions please do let me know otherwise let's move on let me walk you through about the Java syntax and how it works so in here have a look let's just start with this line so here package com dot Amigos code and then have a look in here we have semicolon now every single line so if it's not a method not a class it will end with semicolon so here semicolon the same here semicolon and the same here semicolon if the semicolon is missing have a look you saw that this will fail to compile then in here have a look we have public class Main and then curly brackets now IntelliJ has this really nice feature where we can basically toggle down have a look I can toggle this if I basically collapse this have a look I can see that I think if I remove that Yes actually it doesn't work for main basically this opening curly bracket has a corresponding closing curly bracket so there is actually a really nice plug-in so if I go to IntelliJ IDEA preferences and navigate to plugins and I think it's the bracket rainbow brackets so let's just install that and I'm going to restart my IDE and you can see that it has 6 million downloads by the way so it's quite popular there we go my IntelliJ has restarted and now we have rainbow brackets installed and check this out so if I close this you can see that now this right here is yellow right so this is yellow if I open this one up have a look this now is red so this is basically easier for us to see all the matching brackets so for example if we have so in here inside if I say if and then true again we're going to learn about if statements later but now this time it's not going to be green but instead it's going to be blue so this is a nice plugin that I think you should use so that you understand which closing bracket belongs to its corresponding opening bracket and when it comes to brackets we have two types we have curly brackets which are these ones so curly and we also have these ones which are square brackets in here so let me just delete this if statement because we haven't touched if statements and let me also close this because we haven't learned about if statements but on brackets so here opening closing and within this this right here is a method so this is the method body in here so within this method this is the method body within this public class so everything within it is the class body now it's very simple you have curly brackets for each one you have a corresponding closing for this course we're going to be printing out lots of things to the console and what I want to show you is a quick shortcut that we're going to use to speed up this line right here so system.out.printline here allows us to pass anything within it to be printed in our console so if I run this right here you should see that we have hello and then 20. now this is kind of long-winded so I don't want to be typing here all the types of system dot out dot print line so instead less together type s o u t and you can see that we have a couple of live templates in here but just pick the first one so South enter you can see that it gives us this shortcut in here so if you hear me saying South I just mean printing out to the console so this actually prints a new line so if you don't pass anything so here let's just say South so have a look at the output before so hello Java 20 if I put a south or system.out print line in between it will give me a new line so have a look if I run this you can see that now we have an empty line in here so I just wanted to basically let you know about this awesome shortcut and if you want to learn about IntelliJ and master it because I think if you want to step up your game and be a pro uh what you do then you should know this ID the inside out and knowing this ID Inside Out is like having superpowers catch me on the next one also within IntelliJ have a look package public class public static void and all of these are basically orange so in Java we have a bunch of these keywords which are used for the Java language and they are known as reserved keywords I.E keywords which are used specifically for Java so if we were to try to use these keywords for building our program then we can't use them because they are only used for the Java language itself so if I was to say for example here a string and then public have a look equals to and then maybe this right so here you can see that immediately this is an error because public is a reserved keyword but if I say Publix so Publix is not therefore we don't get an error and let me see what the error says so let me just try and run it and have a look so Java not a statement so this is not a statement because this is a reserved keyword the same with void there we go so this is a reserved keyword so let me show you the list of all reserved keywords and in fact let me just delete this and if I show you the list so this list is actually taken from w3schools and have a look we have abstract assert Boolean break byte case catch Char class you've seen this one continue columns do double else and you can see a bunch of them exports final float 4 if and long new package public so you've seen public requires and you can see that it's a big list but I would say no need to memorize all of these because you'll get exposed to majority of them throughout this course now that you know how to get up and running with Java let's focus on the foundations for this awesome programming language so Java as I said is one language that if you know it well enough then the rest will be easy to follow so the first thing I want to show you here is comments so have a look in here write your code here so this is a comment that allows you to document your code so this right here doesn't get executed and it can be anything that you want so here I can say for example Foo bar for example and this is just a comment so it allows me to basically just document a piece of code and maybe I want to come back to it later so that I understand or maybe I want to leave a comment for someone else right so this method does x y z or this variable is used for x y z so this is what comments are used for now in here have a look if we run this program nothing happens because this right here is just a comment it doesn't get executed now what happens if we basically just stick forward slash in here and forward slash in here so if I run this have a look nothing is printed to the console and this is because right here we told the Java that this should be a comment and I said that if we put a comment then everything that proceeds can be literally anything so if I go back command Z in here a couple of times and this is basically single line comments if you want a multi-line comment you can just basically so in here let me just put this same level as this so this is a single line comment so single line comment and if you want a multi-line comment you just say forward slash star and then if I press enter I will look we've got opening and then close and this now is a multi-line and then common so you can see that it expands across multiple lines and there's no limit really to how many lines you can have but this is how you add a multi-line comment so again these are only used for documentation purpose and they have no effect when you run your code let's go ahead on about variables a variable allows us to store a value into a placeholder which we can later use it for example if you want to store two numbers you can store them into a variable and then add them together and you can store the result of a bank into yet another variable and then you can print it out so here let's say that you want to store whole numbers so what we are learning here is Primitives so pre me so Primitives allows us to store simple values so here let's say that I say int and then number and then one equals 2 and then 20. I can also store number two so int number two equals to 20 and if I want to now I can basically perform addition on these two numbers so if I print and then say number one plus number two in here and if I run this you should see that we have 40 in here so a variable so this is a variable so this is a variable yet another variable we can actually take the result so we can take this also in here so let me just cut that say int result equals to and then number one plus number two and here I can print the result so result and this is the exact same thing there we go 40. now let's just basically cover this so here int this is the data type this is the variable name and this is the value so you have to say equals and then the value and always end there with semicolon the same here end number two 20 and then the same here now int so this is a data type that allows us to store whole numbers if you want to store decimal numbers there's a data time for that so maybe you want to store the value of pi just say double and then pi equals to 3.14 there we go if you want to store true or false I.E booleans you could say Boolean and then is and then adult for example equals 2 and then false so in here this only takes true or false if I try and put a number for example three this doesn't work so if I say true and the same here if I try to pull a true value in here this data type only allows us to store decimal numbers the same with integers so if I say 20.0 this doesn't work because an integer allows us to store whole numbers if you also want to store in here a character you can say Char and then maybe we want to store the letter A equals so here I've just named the variable a and the value will be single quotes and then any letter in here so these variables in here they are Primitives and Primitives allows us to store simple values later we'll cover reference types which allows us to store complex values but for now just know that if you want to store simple values use Primitives so for example numbers whether a value which is true or false or a single letter or a decimal number so on and so forth next let me show you the difference between int double Boolean and the rest of the primitive data types so Primitives allows us to store simple values I.E whole numbers decimal values characters and in here you can see the list of them so Boolean byte short Char and long float and double now what is the difference between all of these well the difference is that for example if you take double and Float so these allows us to store decimal values but float allows us to store big numbers therefore taking more space in memory let me show you the table so have a look so we have the type the size minimum maximum and there's an example in here so byte in here the minimum number that I can have is between -128 and 127 So within IntelliJ if I create a byte variable so byte and I'm going to say n equals to 127. have a look so this works but if I say 128 it doesn't work so I cannot fit a number bigger than 128 into the byte variable so here the next data type that allows me to store whole numbers bigger than 128 is a short right here so short and short so if I show you have a look minus 32 000 plus 32 000. so as soon as I say a number for example forty thousand for example so four zero zero zero I cannot store a number bigger than 42 000 or actually just 33 right so I think it was 32 700 I think but if I say 33 I cannot store right here and the next data time that allows me to store whole numbers bigger than this is and so have a look int so int now allows me to store really big numbers also if you want to store numbers bigger than this so this is the maximum here you can use long so these allows us to store so byte short int and long allows us to store whole numbers then we have float and double four decimal numbers and you can see the minimum right here and the max as well for both sides and then we have character and Boolean so Boolean allows us to store true or false values nothing else now generally speaking you will never use byte nor short and most likely int all the time if you need bigger numbers then this right here you should use long and then double so float or double for decimals characters and Boolean and the reason why you've got these data types in here is because before we used to have a constraint on the memory RAM so people used to code these programs and because they didn't have enough storage on the ram then they had to use these data types but these days this is not an issue so in my case for example my Ram so I've got the Mac M1 Pro and I've got 32 gigs of RAM which is not an issue and have a look at the size in here so this is bits so 8 Bits is 0.125 bytes so this is literally nothing so integers right here so 32 bits is four bytes and again this is literally nothing and if I show you the conversion and in this website it gives us the computer storage unit so small is to largest bit is an eighth of a byte so have a look byte one byte right here a single byte stores eight bits so this is what I was showing you in that chart so a kilobyte equals to A Thousand bytes megabyte one million bytes gigabyte 1 billion bytes and then we have terabyte which is one trillion so on and so forth so in my case I have 32 gigabytes IE 32 billion bytes so if I have a bunch of these variables for example an integer then basically you can see that these days memory it's not a problem but these are primitive data types and they allow us to store simple values let's say that we have this integer variable right here called amount now the question to you is can you tell me what number is this and you have two seconds well your time just had lapsed now sometimes when you want to represent really big numbers it's really good for you to use endless scores to help you recognize the number especially if it's a big number so in here you kind of have to know okay so three zeros here another three zeros here yet another three zeros and it's one billion so what we can do instead is we can use and this course so here if I say end this score and then end the score in here and and the score in here now have a look now this number is much easier for you to read now on this course it doesn't really actually add in this course but it's more forwardability so if I was to print the variable called amount and then run it you can see that it still prints the number without and discourse so this also works for decimal numbers so here if I change this from an integer to a double so double and in here I can say dot zero zero and you can see that is still works so if I run this you can see that this is the double representation so because this is a very big number that's why we get it like this but for example if I was to let's just say uh 1000 so in here just one thousand just like that and let's just say 31 for example have a look so now we do get the number probably formatting you can see that this is much better to read and it's what you should use when you want to represent big numbers let me teach you about the arithmetic operators that Java has to offer so they allows us to perform common mathematical operations such as addition subtraction multiplication division so on and so forth so if you have two numbers so here let's just say int and then number one equals two and then 10 and let's also have number two so in number two in here and I'm going to touch on naming these variables in a second but for now just name them as this and let's also say that this is 20. if I want to add these numbers together let me just print to the console I can say number one and then plus number and then two if I want to subtract these numbers I just say minus if I want to multiply these numbers I can say times if I want to divide I can just say divide so this is a divide symbol in here so 10 divided by 20 and let's just change this number so that we get a proper result so let's just say 2 for example and in fact let me just make 3 in here and finally I want to show you is the modulus operator so here let me just duplicate this and in here I can say modulus so this is the percent sign so this is saying how many times number two can go into number one and then the remainder is basically the result so what is left so 3 can go into ten three times and the remainder is one if I run this in here you can see that I go you can see that I get thirteen seven thirty three and then one now if you have done any Maps since primary school and what not you probably know about bodmas so ball mess which means so let me just put this here so brackets order and let me just put this on a new line in here so have a look you've got brackets order division multiplication addition and subtraction so if for example in here say here south so here I can have brackets and then I can say 2 plus 2 times and then brackets three divided by one and then I can say times and then two for example right so here I'm using multiplication but this could be any sign so first will be this then this and then the result of it so two plus two four three divided by one is three so four times three twelve times two twenty four so if I run it hopefully there we go 24. so you can see that the bodmas rule does apply so this is pretty much it next I want to show you the plus plus and minus minus operators in here let's say that we want to increment this number right here by 1. we could do the following we could say int and then increment equals to and then number so we're taking the value of number and then plus and then one if I want to decrement I could just do the same but say de crement and then minus and then one if I print both numbers so South increment and decrement and then run this you can see that we have one and then minus one so basically we started off with zero zero plus one one and then if we want to decrement 0 minus one it's minus one in here now there is a shorthand for it and that is using the plus plus as well as the minus minus operators so the way they work is as follows so here let me just comment this out to you so that you have it for reference so let me just indent first and in here I'm just going to add a comment so forward slash and let's just add a closing in here so the way it works is so if I say south in here so I'm not going to store the valley into the variable itself but instead I can say number and then plus plus now if I run this have a look this gives us zero in here and what this is saying is return the value and then increment by one which means that if I say south and then number run this have a look we have zero and then one so this is saying return the value and then increment by one so by the time we print the value will be zero and then increments for the next use the next use is here line number seven and the value is one if you want you can have plus plus before the number so here if I just duplicate this in here and let me paste this and let's just say in here int and then number two so you can have both references so here I'm going to say number two just like that now so this should be zero so here if I want to increment immediately and then return the number this is how you do it so basically here it says increment and then return the value of it so by the time it does this this will be 1 Returns the value so when we print will be one and the next time will also be one if I run this have a look so we have one and one so this is the increment operator similarly we have the decrement operator again let me just add a comment forward slash and Then star and let me just push this in here just like that and I'm going to say increment operator plus plus and let's basically take the exact same thing and we're going to do four decrement so decrement is as follows so if I basically duplicate this and then just paste it here and uncomment this there we go and then remove this so this works as follows so here I say instead of plus plus I say minus minus so this is saying now return the value and then decrement so this will be zero and then the next time that it prints the number will be -1 the same if you want to decrement and then return you say minus minus B4 so if I run this you can see that we have zero minus one minus one and then minus one so this is pretty much it so let me just add a comment in here as well so you have it for reference so this is the decrement so decrement operator and this is using minus minus if you have any questions please do let me know but keep this in mind because later we're going to use this with loops that's all for now catch me on the next one when working with Java we can use these comparison operators to perform comparison on Primitives this sign right here is the less sign less or equal greater greater or equal equals not equal so this is exclamation mark and then equal so in here if I print to the console so let's just take a number so 10 I can say whether 10 is greater than 10 I can duplicate this line I can say 10 is greater or equal to 10. I can say 10 is less than 10. less or equal I can say equals and then finally not equals now the result of this operation right here returns a Boolean so if I run this I will look we get a bunch of booleans back and we've done booleans so here 10 is not greater than 10. 10 is greater or equal to 10 which is true then 10 is not less than 10 10 is less or equal to 10 gives us true 10 is equal to 10 and obviously 10 is not equal to 10 so this gives us false so you can basically so what I was saying is the result of this is a Boolean so here you could store the results so for example Boolean and then I'm going to say is adult and let's say that the age is 15 and we want to know where the 15 is greater or equal to and then 16. so this is the limit so for you to be an adult you have to be at least 16. and this with semicolon and then print is adult if I basically just add another space here so an empty print line and then run this have a look it's false in here so this age right here or this number is not bigger or equal to 16 if I change to 16 this will give me true now and anything above 16 will be true but you see that the result now is stored within this Boolean data type and we'll basically learn if statements later so that this will make fully sense why we need booleans but for now just know that we have these comparison operators and we can perform comparison on Primitives and more specific numbers if you have any questions drop me a message otherwise let's move on let's say that you want to increment a number other than just by one so how do you do it so you saw that if I say south and if I have number two for example if I say plus plus and run this you should see that we have 11 right so number two currently is at 10 plus plus in here it says increment and then return the number in here if I say plus plus on this side it Returns the number first and then increments so here plus plus so this should be 10 instead of 11. but let's say that we want to basically increment this number right here by you could say for example so here int result equals 2 and then let's say number two plus and then two right so this now increments the number by 2 in here so if I print the result instead here we should have 12. so have a look 12. but what I want to show you is that you can use a shortcut to perform things like this so instead what you can do is you can get rid of all of this and now I can say number two Plus equal and then the increment so here if I say one you should see that if I print number two now instead of result I should get 11. if I say 2 in here I get 12. now I could actually use this number in here so plus equal and then this one and this will be the same 12 but the cool thing here is that you can change this sign to say for example times right here so basically take the current value of number two and times it by the value of number one so if I run this we should get 20 there you can also divide if you want so you can take this and then perform a division just like that and 10 divided by 2 is 5 you can subtract so run it 10 minus two is eight you could also perform the modulus so here mod so 10 more 2 is going to be zero and the weirdness this is it now let me just add a comment in here so you see exactly what's going on so here if I just have a comment here so let me just put this just like that and in between I'm going to paste something and this is so that you have for reference so X Plus equal Y is x equals to X Plus y so basically this is what we did so here have a look number two modulus equal number one is the exact same thing as saying number two equals to number two mod and then number one is the exact same thing but we're just using the shorthand so let me just press command Z there a couple of times and there we go if you have any questions on this please do let me know otherwise catch me on the next one before we move any further let me teach you how to properly name your variables so so far you've seen that in here if I have a variable called goals so here I'm going to say int and then goes equals to and then zero so this right here is the name of my variable now you can see that the way that you can name your variables you could pretty much just do it the way you want so here I could say G so capital G and then maybe capital S for example or L my bad right so goals so this is the name of my variable and if I want to refer to it I could just say south and then goes in here so capital G goes and if I just run this so you see that this works there we go this is zero now this name right here it's not great because there is a naming convention that we should follow when picking the name of our variables so one your variables you have to have a meaning behind it so for example if I was to say full in here fool doesn't mean anything right so it doesn't represent anything but instead if I say goes this now makes more sense instead of using capital g o l s so you can see that I'm actually starting everything in lowercase this is the case where so here where the name of your variable is composed of one name if it's composed of multiple names I let's say number of goals for example so number and then of goals so I didn't teach you this but let me just basically show you that you could say of and then goals so right here so this is camel case syntax where the first word starts with lowercase and then the beginning of the second word so all starts with uppercase and Then followed by lowercase and then the same for the rest of the word so here goes is another word so this starts with uppercase the rest is lowercase so this is the recommended way for us to Define our variables and it's known as camel case this right here is for integers for booleans if you have booleans for example so here the way that you define so let me just say booleans so for booleans you kind of use for example is so let me say Boolean and then is adult so here I'm actually asking a question is it adult it could be true or false right here or maybe we can say has so you kind of always want to ask a question has and then cat for example true or false right so either use is or has four booleans so this is mainly for variables and then you have functions or methods and then classes and they kind of follow the same pattern but you'll see those throughout this course this is all for now catch me on the next one so you've learned about Primitives which allows you to store simple values now let's learn about strings and then I'll show you reference types so strings actually it's a reference type but it's a special one and I will explain this later but in here strings allows us to store a sequence of characters I.E text so if you want to store for example brand so string brand equals two and then Amigos code so here let's just send this with semicolon and this variable right here called brand has the value of Amigos code so this is a SQL serve characters now here you can actually add anything so I can add spaces I can add gibberish if I wanted to but basically within double quotes So you open double quotes and end Double quotes you can put any text that you want so this is when you want to store for example sample emails you want to store names any text that you can think of you should use strings to do so if I now say south in here I can say brand and if I run this have a look you can see that we have Amigos code in here so this is cool if you want to so let's just say that we have two variables so here I'm going to say string and then I'm going to say Amigos equals to so this is the name of my string variable I'm going to say Amigos and I'm going to have a second variable and this time I'm going to say that this is code and the contents within it I'm going to say code if I want to concatenate these two so IE I want to concatenate Amigos Plus Code I can say Amigos plus and then code so with strings the plus sign concatenates these strings together and for Primitives remember it adds them together so here if I run this you can see that we have Amigos code now what I meant was so here if I have one right so one and one so this will be one plus one you'd expect it to be two but because these are strings it's just going to concatenate these two strings together I.E the result will be 11. if you want to concatenate symbols you can do it so here I can say Plus and then here and the string right here and I'm going to say plus so now this will show one plus one so you can see that it's not even adding these two numbers together but instead it's concatenating the strings so it's kind of cool now let me just go back for a second here and this was Amigos and then code now the cool thing here is that with strings if you want to for example let's say that you want to uppercase the result of brand so here I can say dot and then we have a bunch of methods available to us so have a look two locations two uppercase bytes equals substring content indent index of is empty and split starts with strips on and so forth so let's just say for example I want to uppercase everything so uppercase so two uppercase and we're going to learn about methods later but here have a look brand you say the name of your string or your variable dot to uppercase have a look at the naming convention that we've learned and then parenthesis this is invoking the function if I run this you can see that Amigos code all in uppercase if I duplicate this and I want two lowercase I can say two lower case and run it have a look all in lowercase if I want to let's say get a portion of my text I can say south and then brand Dot and then substring so this is another method and here it says the beginning index as well as the end index so here for example if I wanted to just print code for example I need to pass five so here hopefully I got this correct actually no it's meant to be six so six and now I have code because this is the zero index one two three four five six index so we basically start from six onwards if you want to print from zero all the way to five you can say zero comma and then five so if I run this this time we have Amigo if you want Amigos you just say six run it and have a look Amigos if for example you want to check whether your string is empty you can say south and here I'm just going to add this string like this and let me just add a couple spaces in there I can say dot and then is so remember the name in conversion for booleans so this returns true or false so if I say is empty if I run this we get false it's not empty because we've got white spaces but if you want to check whether is blank I.E there is no text in between you could say is and then blank now this should return true have a look this is true so if I duplicate this and as soon as I put for example a letter so a so this is no longer blank have a look so this is false now and also it's not empty because you've seen empty means that no strings at all if for example here you want to get rid of all these spaces so let's just basically run this so only to see that we have spaces at the beginning and then at the end so two spaces you can say dot and then trim so trim will remove all trailing spaces so if I run this have a look now we got rid of the spaces from the start as well as the end so these spaces in here so strings are really useful for storing sequels of characters and with them you have all of these methods that allows you to manipulate your string if you want to concaten these strings together use the plus and then all of these methods here you can actually explore and see the functionality available to you that's all for now catch me on the next one in here I mean the official documentation for the Java specification and it contains the documentation for the API and you can find this link in the description of this video so what I want you to do is type string and the first one java.lang dot string and what you'll see in this page is so it says module base package class is a string so remember we used a string to store a sequence of characters it gives you what a string is and whatnot this is an example of how to create a string and this is equivalent to having a character array in here and we'll basically learn about arrays later but for now you can see information about how to use the string for example and print line how to concatenate how to substrings on and so forth but more importantly if you scroll down in here you've got fields Constructors keep on scrolling down and you'll see method summary now this is where you find a list of all methods for the string class so have a look in here it says method chart and the description so in here if I scroll down we've used two lowercase here we go two lowercase and you can see that converts all of the characters in this string to lowercase using the rules of the default Locale so the same with substring have a look substring returns a string that is a substring of this string and you've got two versions so one that takes only the beginning index and the other one that takes the beginning as well as the end index so what I want to show you is that in this page basically this is where you find information about the documentation for the entire language so we've learned about strings and if you want to learn how strings work and the available methods this is the place to go and it's quite extensive so in here we are looking at strings but there's a bunch of other classes modules and packages that you're going to see throughout this course so as you saw with reference types they are used to store simple values so in here if I have a variable called int and then H equals to let's say 21 this is it so you can see that it's one single value in here and nothing else now when we write programs we want to store complex values and this is when reference types and objects come into play so let's say that you want to store a coordinate for example the value for x and y so there is a class called point in Java so this is from java dot awt so the first one and I'm going to show you exactly what these Imports are so if I press that and at the very top you can see that we have an import import java.awt dot star I'm going to explain what this means later but for now just follow along so this allows us to use this point class now I'm going to say that this is point a equals to new and then point now at this point I can store the value for x so if I press command P have a look it says in X and into y so you can pause the X and Y coordinates so here let's just say 10 comma and then 10. now one thing to note is do not type X colon and then 10. again do not type X colon and then 10 nor y colon so this is IntelliJ so if I show you so I'm going to press option and then enter and I'm going to say do not show hints for current method and you can see that that's gone now but I like to show the hints so this helps me to understand exactly what goes where so at this point I will look we've got this point right here called a and this is an object so this point in here is an object and I'll come back to reference types in a second so why they are known as reference types but in here point a is an object and it is because it stores more complex information so with an integer I can only store a number but with this point I can store two numbers I can store the coordinate for X as well as the coordinate for y so that is the main difference between reference types and Primitives now if I want to print the value for point a I can say south and then you can use sound and then I think V there we go and it says point A Plus and then point a and if I run this have a look what I get so I've got point a and this is the value so this is the value here so it has this string right here which is the fully qualified name so it's a point that contains the value x equals to 10 and Y equals to 10. so this is cool so maybe if you want to write a game for example this class is kind of useful right so you can imagine writing the snake game so you would use a point class so a point allows us to store both X and Y coordinates and it's known as an object so this right here is an object and similarly to a string so if I say south and then point a I can say dot and have a look we've got some methods available as well so get X get location get Y 2 string equals distance so if you want to know the distance between points you could use this right here and some other methods and also have a look move so I can move for example move so maybe we've got a snake and snake is moving from point 10 and then 11 so it's moving up so this is how you do it and I basically need to remove that just like that and I don't need to print this there we go so if I was not to print again so let me just duplicate this once more run it you can see that now we've moved this point in here so again this is the difference between Primitives and reference types so these allows us to store more complex values and you'll see a bunch of these examples throughout this course so we're going to use a bunch of objects and everything should make sense now let me actually dive deep into the actual difference between Primitives and reference types as well as objects so that everything makes fully sense and how they are different let me explain the difference between reference types and Primitives and how they are stored in memory so before you saw that we had this int variable age right here and then we have a point a object so this point a right here it's an object and then we did print this and we also moved so let me just get rid of these so we don't need this for this video now this primitive right here and this point a which is a reference type they are stored in memory as follows so when we run our Java application it looks like this in memory so we have the stack which is used for memory allocation and the execution of a thread and it follows the lifo data structure last in first out and again under the structures we'll cover the structures and what this means but all I want you to know is within the memory stack we have something called a frame now a frame contains all the data for one function call and it only exists during the execution time of a function including any references and then we have the Heap in here so this is a space used to store objects new objects are always created in the Heap space and references to these objects are stored in the stack memory so let's start with the Primitive that we have created so this one so this int age so Primitives are always stored in the stack so IE when we run the program we have a frame for the main method so this is the main method and inside we have a frame and this will hold basically all of this so for H it will store the value in it in there so int age equals to 21. so you can see the actual value for the Primitive is stored within the stack so Primitives are used to store simple values then we have a point so this point right here which is an object so this guy is an object and more specific this contains a reference to the object so what I mean is within the memory stack we have a new frame for point a and have a look point a now contains the following information so it contains int x equals to 10 y equals to 10 and point a equals have a look this number right here it's not the actual value for it so this is a reference to where the object itself lives so it's a reference to the point a so this is the object itself and you can see that the Heap is used to store objects now within the stack so point a it's a reference it's a reference to this object with then the Heap so have a look references to these objects are always stored in stack memory so point a it's a reference to the object which is stored within the Heap now let's say that we have a second Point called point B for example so in here let me just duplicate this and I'm going to say that this is point B now this is going to create a new frame I.E in the stack so we have a frame and we have the value so 20 and 20 let's just reflect these so 20 and 20 so x 20 Y 20. and this Frame contains all the data for the point B so when we create a new object this creates a frame now have a look we have The Primitives so here in X the value and why the value and then point B contains the memory to where the object lives so this is a reference to somewhere in the Heap that points to the object right here so it points to the object itself so x 20 y 20 and the same for the previous point and to be honest this is it now with a string it works a little bit different and we'll cover strings later but let's say that we have a string called brand equals to Amigos and then code so what's this going to do is within the stack is going to create the brand and this will be equal to you can see that it's not the value so it's not the value so strings also they are references and strings a little bit different but again as I said I will fully cover strings later but this will refer to a place inside of the string pull within the Heap and it will refer to the string itself Amigos code and to be honest this is the difference between Primitives and reference types so with Primitives the value itself is stored within the memory stack so have a look we have age and I think I actually don't need the data types in here so let me just get rid of this so it's much easier for you to reason about so just like that if you see x equals to 20 and the value is stored in here you know that this is a primitive so the same for a Boolean the same for a chart the same for a double right so all of those are Primitives so the value for them are stored within the stack and for objects it stores the reference to where the object lives inside of the Heap and if it's for a string it's a little bit different because they refer to the value within the string pool but again more on this later if you have any questions on this please let me know but throughout this course you're going to learn about objects and whatnot and hopefully all of this will even make more sense but if you have any questions please do let me know otherwise let me teach you yet another important concept which is pass by value okie dokie now let me teach you about a race so far you've seen that if we want to create a variable so for example int and then number in here we can only store one number inside if you want to have another number you have to create a new variable called number two for example equals to something else now an array is a data structure and we'll learn more about data structures later in this course but arrays allows us to store multiple values inside of one variable so here you have to specify the data type and then you put these square brackets and then you name it so here I'm going to say numbers equals to new and then int and in here you have to specify how big is this array so how many elements can this array hold so here let's say that this can have only three integers inside now if I want to add a new integer inside I can say numbers and I need to add square brackets and now I need to specify the position so arrays indexes they start from zero so zero is the first element so here I'm going to say that at position 0 I'm going to add the number one and let's duplicate this and here I'm going to say position one I want to add let's say 33 and then position 2 in here I want to add let's say six for example so now you can see how we are adding multiple numbers into this array if I want to print the contents inside of our array we can say south and inside I'm going to say erase dot to string and then pass numbers inside so if I put this on a new line so you see things properly so this function here basically prints out our array because if we print the array on its own we get a random number so here if I run this have a look you can see that this is our array so position 0 it's one position one we have 33 and position two we have number six and in total we have three elements inside of our array so if I remove that and then just print numbers I will look we get this gibberish so if you want to see the contents inside of your array you just say erase dot to string and at the very bottom it does Imports this and we'll talk more about packages later but it Imports this package so that you can invoke this method and more on methods as well now let's say that we want to change so here I'm going to say three so at position three we want to add six so if I run this this will fail so this will throw an exception and we're going to learn about exceptions later but if I close this so here we cannot access this index so this gives us an index out of bounds because the size of our array is three and remember the index from 0 so 0 1 and the next one is two just like that one thing to bear in mind with arrays is that once we Define the size we cannot make it bigger so here we can only have three numbers and if you want to add a fourth one it's impossible so here if you want to say numbers and at index three equals two so this will be the exact same thing so this will be arrays out of bounds so we cannot change it so if I delete this and what I want to show you now is if you want to find out the length of your array you can say south and then call the array so in our case numbers Dot and then length if I run this this gives us three so this is the size of our array now if I close this and what I want to show you is you see that in here this is how we initialize the array so in here and then we added three numbers but what we could do is basically on this line in here I'm going to say int and this is an array I'm going to say numbers and then two equals 2 and then here so at this point curly brackets I can specify numbers so here 0 comma five and then comma five maybe six eight and I can add as many numbers as I want and in here we have one two three four five elements inside so if I say south numbers two Dot and then length run this you can see that we have five so this is the length of our array so this syntax is a shorthand version of this because here we have to specify the index 0 we pass one index one we pass 33 but here we can just do it in line then if you want to change for example this value in here so this is five so you want to change that for example to 55 you could just access the index of numbers 2 and then add index so that'll be one so zero and then one equals to 55. now what I'm going to do is just before I change that I'm going to say south and then arrays dot to string and I'm going to pass the numbers two just like that and then I'm going to duplicate this so you see the before and after so just like that run it and you can see that have a look before 5 was here but then we change it to 55 and the length is 5. so this is pretty much a raise now you see that here we have integers but this could be any data type that we want so if you want a double for example so if you want to work with decimal numbers you say double and now so nothing changes because these are still decimals if I run it you should see that we have 0.0 if you want to store strings for example so here maybe you want to store a list of names so string and then name or actually names equals to and then here you can say Jamila for example and here maybe Alex so now this array in here contains a list of names so have a look the data type curly brackets the variable equals two and then the pattern and and then depending whether you initialize the array like this or as we did in here now this is pretty much an overview about arrays but later we'll cover data structures in detail and you'll get to work with the Rays a lot more but for now just remember that arrays allows you to store multiple values inside of one variable if you have any questions drop me a message otherwise let's move on let me go ahead and talk to you about the null values within arrays previously you saw that this is one way of initializing an array so this array right here currently is empty so you saw that if you want to add for example a number at a particular index you just say numbers for example equals 2 and then two so what I want to show you is if I say south and then arrays dot to string and then pass numbers I want to show you the default values for this primitive array if I run this I want you to see that we added position 0 or index 0 we added two in here so the rest is filled with zero so for Primitives the default value for arrays is zero similarly if I say in here so two and if I say 27 for example run this so you can see that now this is 27 and the rest is zero so this is for Primitives now sometimes you might want to have the default values for your array to be a value other than zero so in that case what you can do is you can just say arrays Dot and then fill so you say numbers and then what do you want to fill it with I want to fill this array with -1 so if I run this now have a look so the default value now is -1 and then position 2 or index 2 we added 27. so this is for Primitives what about objects so here if I create a second array and I'm going to say string array and then names equals to new and then string and within here I'm going to say that I want to have two oh actually three so the same size as the other one now let me just say names and within position one we're going to add Jamila now if I duplicate this line in here and then bring it down and instead of numbers I'm going to print names in here so now have a look actually this meant to be three let's just say three so we have three slots as the one in here but now have a look so the default value now for objects is no IE reference types right so here this is no and now just bear in mind that whenever you are working with reference types this is actually referring to an empty object but I'm going to cover this later down but all I want you to know that for Primitives the default value is zero and for reference types default value is null in here so obviously you could also go and fill the array so here if you want to fill that with something so here if I just duplicate this line bring it right here and then say names in here there we go and here I'm going to fill it with for example Foo if I run this you should see that we have full instead of no this is pretty much everything for this video if you have any questions drop me a message otherwise let's move on so we've just learned about arrays and later we'll focus more on arrays When We Touch on data structures but arrays is one of many data structures that allows us to store and manipulate data now from now on all the way to the section on data structures we're just going to use arrays because arrays are the building block for all other data structures and you've seen that if we want to access an element we need to know the index and as we Loop if we want to get the previous or the next element or even if we want to get the the elements in reverse then we have to use the for loop with an i um counting down so on and so forth right so I'm going to use arrays for the upcoming exercises because it will teach you how to think instead of using lists which you'll see later they are much easier to work with but for now let's just work with arrays for the exercises and throughout the examples because as you become more comfortable with the race moving forward you will be in a better position if you have any questions please do let me know otherwise let's carry on so you've learned about arrays and what I want to show you is let's say that you want to print every single element within this array you could say south and then the name of the array so names and you pass the index 0 and in here we can duplicate this couple of times so this would be one two two and then three if I run this you can see that we have James Nadia Sophia and Alex if I add an extra name for example sale and now I need to basically add a another South statement or print line statement if I add more names then I need to basically fiddle with this now this is cumbersome and you should never do this so basically from here you saw that with loops we can generate a number from 0 to any number right so what we can do instead is if I comment this out and instead of doing that we can use a for Loop so we say four and we can say int I equals to zero and we're going to keep on looping while I is less than names Dot and then length so this gives us the length of this array in here so this will be one two three four five so therefore this will give us five so let's just leave names.length because if we add another element in here this will basically work out the length for us then here I want to basically increment I by one so I plus plus so now that we have all of this in place if I want to print each name I can just say South the name of my array which is names and then square brackets and inside I can just pass I so if I run this you can see that this still works and the cool thing is if I add a new name for example here let's just say Aisha and if I run this we should see Aisha in here now one thing to bear in mind is that this right here is very crucial so don't say equals because arrays index they start from zero so this is index 0 and let me just take this one and then two three four and then five in here now the length of this array is six right so length equals to and then six there we go now if this is less or equal then it means that at index six we don't have anything at index six and therefore this will fail in the last iteration so if I run this have a look it will give us Java array index out of bounds exception and we'll learn more about this but have a look index 6 out of bounds for length 6. so when looping you have to be really careful so this should be less and you start from zero now if you want to reverse the array you can just basically flip these values so I'm not going to do this because I want to say you an exercise where you're going to have to reverse an array but you've seen how to do it before and this is pretty much it so this is how you Loop through arrays using this for Loop let's take a break from loops and arrays and I want to teach you how to use if statements within Java if statements allows us to execute a block of code based on a condition and the condition is either true or false so if the condition is true we execute the piece of code otherwise we can tell it to execute another piece of code so in here if I say if this is the command and here I'm going to have parenthesis and I'm going to say true so if true I'm going to print this code runs so if I run this have a look you can see that it says this code runs if I say false and then run it you can see that nothing gets executed because this condition is false therefore it doesn't execute any piece of code that you have within the curly brackets I can also have the else statement so if this condition is false I can say else this is the default so here I'm going to say south this code runs when false and this is when true so if I run this I will look you can see that this code runs when false if I switch this to true in here this piece of code will be executed and this will not so anything that you have Within These curly brackets won't be executed so if I run this we should see this code runs when true now bear in mind that if you have for example here south and then code outside if this piece of code in here will always execute because it's outside of the if condition right so if it performs this right here and then it carries on in here right so if true print this line and then carry on the execution of the program so if I run this have a look so we have this code runs when true which is this piece of code but if I change which is this piece of code but also have a look code outside if which is this line so if I also have for example South and then hello as well so this will also print have a look cold outside if hello but here this is executed because of this line in here but if I say false this is no longer executed but this condition in here so therefore we'll get a different result so if I run this you can see this code runs when false and then we get the same result for line 11 and 12 because this is outside of the if statement so this is the general idea of if statements what I wanted to do next is how to use if statements with conditions all right now let me go ahead and teach you about packages in Java so have a look in here we didn't cover packages yet and line number one you can see that we have a package com dot Amigos code and this was done when we did create our project so if I open up the project tab have a look we have SRC and then we have com dot Amigos code and then inside we have main so this menu here is this main.java where we've been writing all of our code now a package is nothing but a folder that allows you to structure your application again a package is a folder that allows you to structure any given project so what I want to do is within SRC I'm going to right click and then you should have an option open in and then finder or Explorer if you are on Windows I think so finder and this brings up inside SRC and evolution we have com click on it we have Amigos code click on it we have main.java so you can see that a package is nothing else but folders so have a look com dot Amigos code and then main.java in here com dot Amigos code and then main.java so even though that you don't see fault slashes in here you can think of a package as a structured folder that allows us to organize our code and within your classes the first statement is always a package so a class and we'll cover more classes later but you should see that everything that lives within this file should belong to a package so the package name is com.amigos code so if I change this to for example without D or E you can see that it doesn't know which package are we talking about because the name of this package is com.amigos code therefore this should also match next let me go ahead and show you how to create packages in this section let's focus on understanding what are methods and hopefully you'll see how we're going to start using methods from this point onwards to start building our programs so a method is a block of code which only runs when it's invoked we can use methods to reuse code that can be shared across the entire application I.E if something that you are constantly doing over and over and over again you can just build a method and then invoke that method all the time so I've basically gone ahead and deleted all the other packages and classes and I only have this class called main the one that we've been working so far and I'm going to collapse this and let's just look into this class in here called Main so we haven't learned about classes in detail but here within this class we have public static void main so this is a method now more on this method later but when we build methods we have to specify few things so here I'm just going to have a comment for each so the first thing that we need to specify and if I put this as a multi-line comment just like that so the first thing that we need to specify is the access modifier then we also need to say whether the method will return I.E the return and then type then we give it a name so name followed by parameters if any so optional parameters and I'll show you what this means in a second then we need the method body so method body and also optional return value so this is basically how we build methods now let's quickly have a look at this main method right here so that you see what all of this means so here access modifier you've learned about access modifiers I.E public private protected or default then we have return type so you've learned about static so static means that it belongs to the class but here void so this right here is a return type so let me actually say that in here so optional static so here we have void right so void means that this method does not return anything we have main so this is the name of the method optional parameters so here we only have one parameter and the type of way it's an array we have the method body so the method body is anything that goes within the opening curly brackets and close curly brackets so here this is the body and then we have optional return value so since this method does not return anything therefore there's no return value so this says void meaning that it doesn't return anything so this is the general idea next let's build our own method let's together create a method that adds two numbers so we want the method that adds two numbers so here let's just basically say private the reason why I'm playing private is that anything that can use this method that we are about to create has to live within this class so it doesn't have to be public private static and then here the return type for this will be an integer let's have a look so access modifier private optional static static the return type we want this method to return an integer now let's define the name so the name can be anything that you want so here I'm going to say add and then we have optional parameters so the parameters are these so here I want this method to take an integer called number one followed by another integer called number two or in fact let me just say n 1 and and two so I can just save some space so N2 in there and then I need the method body so method body goes like this and have a look now I can do anything that I want so here I can perform my business logic and then have the return value so since this method returns an integer I need to return an integer so here all I want to do is I want to create a variable so I'm going to say int result equals to N1 plus and then n 2. so I've got my result now I can just say return and then result there we go so you see that this method here has the return because we have an integer here and this integer is the return type so it accepts two numbers performance Edition and then it Returns the value so here if I want to return for example a string I cannot do this because this method here returns only integers but if I want to change this to string for example you can see that now this works so I want this method to return the integer result so let's just leave it like that now the way we're going to use this method is within our main method this is where we've been running all of our programs let's just say int and then result equals to and then add and at this point I can pass two numbers 10 and 10. there we go now I can just print to the console result and if I run this we should get 20 right here so hopefully you can see how this is coming along so the benefit of this method is that now we can just call it as many times as you want and then pass any two given numbers so here let me just call this result and then two and then pass 100 for example and let's also print result and then two so you can see how this now allows us to reuse this piece of code over and over and over again so this is one method that basically is private it returns an integer this is the method and it has two parameters in here now remember static so here if this is not static then it will fail so we cannot even run this if I try to run this it will fail to compile have a look cannot be referenced from a static context and that's because before remember I said that the only thing that can be accessed within a static context is a static instance is a static method or attribute or creating an instance of this class called Main and then we can invoke it so remember I said before the other way is to say Main main equals to new main and then here we can say Main dot add so main dot add and this works but let's not do this because we haven't learned about objects and whatnot so let's just remove main.add from here and let's just keep static for now so public or actually private static and then int so if you have any questions on this simple method please let me know otherwise let's carry on learning about methods for this exercise what I'm going to do is to create a method that will calculate the rental yield so on this website in here I can actually you know plug in some values so let's say that my monthly rent is 1 000 pounds and this could be dollars it doesn't matter and then let's say that the original price of the property is one hundred thousand if I calculate you can see that the rental yield per year is 12 percent now what is the formula so here you've got an example if your monthly rental income is 1 300 your annual so you times that by 12. and then the value of the property then what you do is you divide the total rental income per year divided by the total amount for the property so what I want you to do is create a method that allows you to calculate rental yields think about the access modifier for that method think about the name of the method think about the parameters of that method the return type and test your method to make sure that indeed it does work but I'll give you the solution next okie dokie for this section we're going to talk about classes and objects you've seen that we've been using strings and other data types throughout this course and we created objects right so we have the actual class which is the blueprint and then when we say new and then the actual keyword so whether it's a new string or a new date and whatnot at that point we create a new object now in programming everything is around objects right so as we build code we want to model things in the real world so let's just take a look at this mobile phone so this is an iPhone right here and we can actually model this through a class so class is the blueprint and then from that blueprint we can create a bunch of objects I.E phones right so let's in this section first understand basically every single bit that you need to know in order for us to create a class and we're going to focus more on models so representing things in the real world phones people cars so on and so forth right so we're going to focus on that first understand everything that we need to understand and then later we'll learn about different types of classes right because there are classes for different purposes there are classes for us to model the real world their classes for us to perform the business logic there are classes that allows us to store data so on and so forth don't worry we're going to cover step by step but for now let's learn about objects and classes or classes and objects cool let's carry on as you've seen in Java you will mainly be having a bunch of classes and then connecting them to each other this class right here so public class Main with this main method is a special class because it contains this main method and you've learned about the main method so this main method here is what the jvm looks for in order to run the application now from this section onwards I'm going to explain everything you need to know about classes and hopefully you'll also get an exercise where you have to connect classes together and whatnot but right now what I want to do with you is I want to create your very first class so let's just start with a class within this main class but later I'll show you how to have our class in its own file so here let's together say class and here I'm going to say cat now this class cat in here we're going to Define some properties and behaviors so let's have a property and here we're going to say string name so this is the name of the cat that we want to represent and now let's define a behavior that all classes that we instantiate from this class will have so here we're going to say void and then meow and for now what I'm going to do is so inside of this meow method I'm going to say south and here I'm going to say name Plus and then let me just say colon and then meow and then three dots so to be honest this is it so we have a class in here with one property so this is the property and then this right here is one Behavior so classes are made of properties and behaviors so this is one property this is one Behavior now the way I'm going to teach your classes is I'm going to teach you basically the bad way of doing things and then I'm gonna build upon it so that you understand why we do things right so we have this class now let's try and basically use it so here if I say cat and then I'm gonna say cat equals to new and then cat just like this so this right here is the type and neocat is our class so the same way that you saw with new string or integer or a date for example so basically we are doing it for our own class which is a cat now this right here doesn't work because currently we have a class inside of a class and basically in order for us to use this class inside of a static method as before we have to add the keyword static and now this works the next thing that I want to do is I want to say cat Dot and then have a look we have the name but also we have the meow so this is the field and this is the method so the behavior so let's just invoke this and let's run it and you can see that we have null and then meow so we actually are almost there and I'm actually showing you how to do things the wrong way but at the end of this section you'll have a full understanding of classes next let me show you why this is now oh my goodness you've managed to mate this far congratulations so if you have any questions or anything that you didn't understand throughout this video please comment down below let me know and join the private Discord and Facebook group where a bunch of other students so we have a community of about 50 000 people will be there to help you as I said there is a 20 off this course so this course is about 24 hours so I would say definitely go and take advantage and yeah I'll see you inside smash the like button subscribe and I'll catch you on the next one