Android Development for Beginners - Full Course

freeCodeCamp.org · Beginner ·🧒 Coding for Kids ·6y ago

Key Takeaways

Develops an Android app from scratch using Java

Full Transcript

hello everyone and welcome to the complete Android app development master class my name is mam I'm a professional Android app developer and I'm going to be your instructor for this course before starting the course let's talk about it for a few minutes this course is about 15 hours and by watching it you are going to learn a lot about Android app development but it is impossible to cover everything in just 15 hours for that I've recorded an extended version of this course which is about 60 hours and in that you are going to learn everything that you need for a successful career in Android app development you can find the extended course by clicking on the link down below this video let's see what we are going to cover in this video in this 15 hours you will start from the very beginning that means that even if you don't have any prior experience in programming you are going to do just fine we will cover everything in the course in the first section of the course you will set up the environment that you need for Android app development that includes installing Java Dev development kit Android Studio software development kit for Android app development and the emulator for testing your applications besid setting up the environment in the first section you will create a small application to get familiar with Android app development and each piece in an Android application in the second section of this course you will learn Java language Java is the most popular language for making Android applications and in this section we will take a deep look at that you will learn about different variables and operators loops and conditional statements different collections in Java concurrency and trading handling exceptions single tone pattern and a lot more you will also learn about objectoriented programming in Java that includes things like classes and interfaces inner classes and Abstract classes inheritance and polymorphism and a lot more we will end this section with a challenge so to make sure that you have learned everything we have talked about in the next section section you will learn about user interfaces you will learn about how to design modern layouts for your applications in this section we will talk about things like buttons and text views different layouts working with images and fonts showing a list of items with list View and recycl view we will talk about snack bars and card views adding animations to your applications and last but not least we will talk about material design in Android once again we will end this section with a challenge so to make sure that you have learned everything after learning Java and designing user interfaces you have the ability to create a lot of applications in the final section of this course we will create one real world application from scratch we will combine all of our knowledge about Android app development and we will create this application together in this section beside practicing everything you have learned so far you will learn about a lot more topics for instance you will learn about persisting your data which shared preferences and also you will learn how to show different websites in your application and of course a lot more you can also include this application in your portfolio if you want we are going to set up the environment that we need in order to create Android applications we are going to install few things first of all we are going to install Java development kit or as some might call it jdk after that we are going to install Android Studio and after everything we are going to create a virtual device in order to test our Android applications as you can see I have already downloaded jdk and Android Studio let's also see where we can get them from for jdk you can simply search for Java jdk and a link from Oracle website should pop up the first link from the Oracle web page is probably our needed link as you can see we are going to download and install jdk version 8 it's going to be enough for our purposes in this this course down in here first of all we need to agree to the license agreement and after that depending on your operating system you can download one of these versions I'm on windows so I'm going to download and install this Windows x64 version if you are not sure about this x86 or x64 you can right click on your my computer on your desktop in properties in here you can see the architecture of your CPU mine is 64bit for you it might be x86 depending on that select one of these two files just click on this download and the download should be started sometimes like here it might ask you to log to your Oracle account let's do that creating an oracle account is free and you won't be charged okay let's select sign in and as you can see the download has begin I'm going to select cancel in here because I have downloaded the jdk previously let's select that it's going to be a really simple uh installation process let's select next once again next once again let's click on next and as you can see we have successfully installed jdk let's click on this plow if you want to make sure that you have installed Java jdk successfully you can always go to your command prompt by going to start menu and typing CMD in here you can type Java Das version as you can see we are seeing some information about the version of java in installed on our system as long as it's 1.8 and higher we are good to go let's close our Command Prompt next we are going to download Android Studio for that we can go to developer.android.com let's see developer.android.com during the course we will come back to this website a lot because this is the official website for Android developers okay for downloading Android Studio just go to this Android Studio Tab and from here you can download one of the versions if you don't see uh your version of operating system you can click on this download options but in here I'm just going to uh click on the download let's say download Android Studio we need to agree to the terms and conditions and as you can see the download has started once again I'm going to select cancel in here because I have already downloaded Android Studio after the download is finished just click on that once again this is going to be a simple installation process let's select next in here make sure to check this Android virtual device let's select next in here you need to select a path to install Android Studio notice that installing Android studio and all of its sdks and also emulators sometimes might take something like 20 or even 40 gab so make sure to have at least 20 GB on the drive that you are going to install your Android Studio after that let's select next and install after the installation is finished just click on this next and let's start our Android Studio don't worry about these three projects that I have in here basically these are the recent projects that I was working on I have Android Studio installed on my system previously and I uninstalled it for this uh video but for you this list should be empty also along the way of installing Android Studio you might see some vses about selecting a theme or other preferences I didn't see them because I have installed Android Studio previously on my system those are not important depending on your preferences select one just if you see something like installing SDK uncheck that because we are going to install it in here together in order to install SDK you can come to this configure in here and uh you can select this SDK manager SDK stands for software development kit and for developing Android applications you need to install at least one SD DK once again as you can see I have installed two sdks in here Android 10 and Android 9 apis but for you this list should be empty and none of these should be checked first of all Let's uh check this show package details in order to see the package details for every SDK by the time I'm recording this video the latest version of Android is Android 10 or API level 29 to be precise I suggest that you always install the latest version but sometimes there might be some preview versions in here I don't suggest installing those because those can be buggy and uh those are not yet released on a stable channel so make sure to install the latest stable version if you want you can install the complete SDK but I don't suggest that because these can be memory and hard drive consuming and this can occupy a lot of storage on your device but the necessary things in here is first of all uh Android SDK version whatever the version of your API is so the first one also the sources for that version of SDK the second option Also I suggest that depending on the architecture of your system select one of these two version of atom mine was uh 64 architecture so I'm going to select this one if you are going to work with different Google apis for example if you are going to work with uh Google Map or YouTube apis uh check one of these for example these Google apis for atom 64 and also check one of these two Google API versions this is going to install at least one SDK on my system uh the Android 10 or API level 29 but if you want you can select and install multiple SDK versions basically this SDK versions and apis means that in what version of Android are you going to run and test your applications later on we will see that when we are going to run on our application on a virtual device we are going to need at least one SDK installing multiple sdks can be Memory consuming and also hard drive consuming but if you have the resources I suggest that you at least install the latest version after that install this API level 29 because there were a lot of changes specifically in the data storage structure also install API level 28 down in here install API level 26 and after that level 21 and also 19 because uh in this version of sdks there were a lot of changes and I'm just uh saying this because of my experience in Android app development but if you don't have the proper resources selecting one of these is going to be just fine after selecting what you need in here just click on this apply make sure to have a stable internet connection because it's going to download some stuff let's click on this apply in here you can see a dialogue that will show you some information about the stuff that are going to be downloaded and also the size of the download file let's select okay in here and our download should be started I'm going to skip the video in here until the download is finished after the downloading and installing all of the components that you have selected before is finished just click on this finish and let's see what else do we have in here okay we have successfully installed at least one SDK let's switch to this SDK tool and let's see what we need from here first of all once again check this show package details install one of these Android SDK build tools I suggest that install the latest version as you can see mine is installed in here 29.02 at the time is the latest version also down in here uh you need to install Android emulator mine is not updated so I'm going to update that the next two things that are mandatory are these SDK platform tools and SDK tools make sure to select those two also down in here we have this documentation for Android SDK this option is not necessary but uh it's going to help us a lot during our journey in Android app development later on we will see that these documentations will help us a lot when we want to debug something or when we Face some errors so I strongly suggest to install these documentations as well the other thing that is not necessary but I suggest to install is this hack installer it is going to be an accelerator for the speed of your emulator the native emulator in Android Studio can be very slow especially if you have a a low memory RAM for that reason I suggest you to install this hackam installer but there is one thing that I need to mention in here I've seen a lot of students having problem with this haxm installer I've seen them that they cannot install this haxm successfully this hackam cannot be installed on all of the CPUs and depending on the structure of your CPU uh this haxm might not be installed but there are some CPUs especially Intel CPUs that they have a special option in the devices bias specifically for this emulator accelerator if that's not enabled you may want to uh enable that in the Bios settings as well and also if for any reason you couldn't install this haxm installer this emulator accelerator and also for that matter the Android emulator itself there is no need to worry there is another way as well beside the native Android emulator you can install external emulators as well for example the one that I know that is working very well is called Jen Motion in here I'm not going to install that but I will put a link uh to download Jenny Motion in the description of this video and also beside all of these you can always install and test your applications on the real device that you have later on in the course we will see that how we can install and test our applications on our mobile phones okay after selecting everything from here just click on apply once again once again we are seeing the download information let's select okay and let the download begin once again I'm going to skip the video in here until the download is finished once again when the download and installing is finished just click on this finish and we have successfully installed SDK platforms and SDK tools just before I close this window Let's uh switch to this appearance in here from here you can change all of the preferences uh that you want for example you can change the theme Dracula is the Dark theme also we have this high contrast theme the intelligent theme is the light theme I'm going to stay with that because it's good for recording purposes if you want you can use custom fonts for the fonts of your windows is from here you can also change the size of your font I'm not going to do that also down in here you can change the font size also for the presentation mode uh if you want to change the size of your codes you can search for font in here uh I believe it's in this editor tab in here in this font you can see that mine is 18 you can increase or decrease that if you want okay uh let's delete this one and also let's minimize this editor I have another suggestion for you in here as well in this appearance inside the system settings inside the updates make sure that your updates are being checked from a stable Channel we have other channels like developer channels and beta channels as well make sure that you have uh the stable Channel others can be buggy okay that's it for installing SDK we will be coming back to this setting menu later on let's select okay okay now it's time to install at least one emulator for that we can once again select this configure this time we can click on this avd manager avd stands for Android virtual device as you can see once again I have uh two devices installed in here pixel 2 and pixel 3 this list should be empty for you but because I had Android Studio installed on my system I can see them let's select this create virtual device in order to create a new virtual device first of all you can create your own and customized Hardware by selecting this new hardware profile from here you can name your device you can select that if it's a phone or tablet you can set the screen size and resolution also then in here you can specify some Ram to it and all sorts of sensors and Hardwares I'm not going to create my customized device instead I'm going to install one of the predefined devices as you can see I have pixel 2 and pixel 3 in here let's select another device from here also from this left panel you can see all sorts of devices like TV Vos and tablets let's select one device from here I don't even know all of these devices let's just uh select this pixel XL select next okay from here you need to specify the Android version that is going to be installed on this device I'm going to install Android Q or API level 29 on this device so we need to download that first let's select download once again I think it's going to be a large file so I'm going to skip the download in here until the download is finished yes it's 1.1 GB okay the download and installing is finished just click on finish now we can select the downloaded API sometimes you might not see the version of API that you are looking for for that first of all you can always refresh this list after that you can check the second Tab and also the third tab but we are going to install Android Q on our device let's select next in here we can customize our device for example we can change the name of our device we can also change the default orientation for example the landscape and portrait I'm going to save with portrait in this uh show advanced settings we can do some more customization for example you can change the camera the network also down in here you can change the size of RAM and SD card and all sort of customization I'm not going to change any of these I'm just going to click on this finish and as simple as that we have inst a new emulator on our device okay let's close this window okay I think it's a good point to finish off this video in this video we have installed jdk we have installed Android Studio after that we have installed SDK and we have done some customization on the appearance and after everything we have installed a new virtual device we are going to create our first application we can do so by opening Android studio and selecting this start a new Android Studio project first of all in this window we can see some templates these templates are just some small applications that have uh some codes written to some level for example in this basic activity you can see that we have a small button and also a menu above in here we can see other templates in here for example a template for Google Maps we have a template for navigation drawer don't worry about all of the is because we will learn how to create all of these elements ourselves later on even we select this at no activity template but the Android team are nice guys and they have provided us these uh templates in a lot of these templates you can see the word activity don't worry about this activity yet if you remember from the content videos I said that we are going to have an entire session which we will talk about activities and fragments but for now you can think of activi ities as different part of your application for example if your application has different pages an activity is one of those pages this definition is not accurate it might not even be correct but for now we can think of an activity as a page of our application in our first application I'm going to save with this empty activity which has no element it's just going to create some files for us but if you want to save it at no activity you can do so as well once again and later on we will see that how we can create all of these templates ourselves okay let's select empty activity and let's hit next in here we need to provide some information about our application for example the name of our application I'm going to change the name of my application to let's say hello world as it's a custom among uh developers to name their first project hello world just for no reason the second part you will Define the package name for your application this package name should be unique to every application that is being released into the world later on when you want to publish your application to Play Store your application will be identified with this package name the convention in here is to provide the name of your website in backward for example my website is called make code.org so my package name is or. makeo do the name of my project don't worry if you don't have any website if you don't you can use something like com. example let's say com do example do the name of my project but since I have a website I'm going to use that in here I'm going to say or. makeer once again this package name should be unique to every application after that you need to define the path that you want to save your project if you want you can change this path by selecting this folder in here and uh select the path but in here I'm not going to change that after that you can select the language that you are going to work with Android applications can be written with Java language and also cutl language in this course we are going to sa with Java but if you want I am currently recording a new course about uh developing Android applications with cotlin uh feel free to check that if you want but uh let's select Java in here after that you need to define a minimum API level this minimum API level in here means that how many older Android devices can install your application for example if you click on this drop down in here you can see the list of different API levels right now the minimum API level that I can select is 14 but I can go up to API level uh 29 or Android 10 to be precise there is a balance in here if you select your minimum API level very high you can work with a lot of newer functionalities in Android but fewer devices will be able to install your Android applications for example if I select API level 29 which is the latest version only less than 1% of the devices can install my application if I select something like 19 you can see that 95% of devices by this time can install my application you as the developer should decide this balance for this course probably we are going to stay with API level 19 for most of our projects because I think it's a good balance and uh 95% is a good number leave this check empty for now uh also using Android X artifacts is mandatory uh since few months ago we will talk about it later on in the course let's hit finish and let's create our first project if it's the first time that you are creating your Android applications uh this process can be very slow because Android Studio is going to download some stuff for example the gradal file uh from internet so for that reason this process can be slow if it's the first time that you are creating your application the first thing in here that is noticeable is that Android Studio have created two files for us this uh activity main.xml file and this main activity. Java file these have been created because we have selected that empty activity template when we have created our project inside each of these files there are some codes once again we can create all of these codes if we don't select that empty activity but uh if you select that you can have some codes written to some level the other thing in here is this uh build pane down in here this build pain in here will show the progress uh of building your Android applications whenever you want to run your Android application whether that is in the debug mode which we will be working uh in our entire course or whether it's in the production level this building here will show the progress of building your Android applications I'm going to minimize it for now and let's talk about all the other stuff that we are seeing in here first of all let's talk about this project pain in here I can minimize and maximize that also top in here we have multiple options for example we have this project option this project option will exactly show the structure of files on your system for example you can maximize um every folder if you want to have access to this main activity. Java file you can go to app folder inside the sources inside the main folder inside the Java folder you can see that we have a folder in here in which uh contains the main activity Java file this is the exact hierarchy of files on our system if you want to make sure of of that you can right click on the name of your project and uh select showing Explorer this option in here it will open the Explorer on your windows you can see that we have a Hello World project don't worry about the others uh inside this project as you can see uh in the hierarchy we have this app folder inside this app folder we have a source folder main folder Java folder or make code hello world and this is the Java file that we are seeing in here so this project view will show the exact hierarchy of different files on your system there is another view in here and that's called Android view we are going to stay with Android View for the most of this course because it's much more easy for eyes to follow as you can see we have this app folder inside that we have this Java folder we have this package name and inside that we have this main activity it. Java file it's much more easy for eyes to follow different files also beside this app folder we have these gradal scripts down in here as well before I talk about these gradal scripts I need to talk about the structure of every Android application so in most Android applications there are at least two different kind of files the layout files which will uh Define the looks of your application the layout files in Android are called X ml you can see this activity main.xml file if you click on that you can see uh the layout of your application right now it has only one simple text the other part of every Android application uh is the Java file if you are developing in cotlin language there are cotlin files the Java or cotlin file in most cases will Define the logic of your application for example what happens if you click on a button or what to do with the users in inputs all of those will be handled in the Java or cutl files beside the layout files and Java files in every Android applications there might be some other files for example you may have some images and also some audio files as well those will be inside this resources folder for example inside the Meep map folders right now we have uh an icon for our application which is this simple Android icon other images or other files can be put inside this resources folder as well basically this resources folder is for the static uh variables or static funds on your application so these are the three main component of every Android application we have layouts we have the Java file and also we have the static files beside this we have uh this manifest file inside the Manifest folder this manifest file will specify some general properties for your your application for example you can see the icon of your application in here also you can see the name of your application which is Hello World in this case and some other properties or features about your application we will talk about this manifest file later on in the course but for now let's close it we have all of these different files in every Android application but uh for example when you are going to download some application from the Play Store you will see that we have only one file one APK file that's the final application that will be released how are we going to generate that APK file well in that case this gradal tool in here is going to be useful gradel is a build tool that will combine all of these files and other files and we'll create an APK file no matter if you want to release your application or if you want to test your application on an emulator you are going to need gr for that reason we are going to work extensively with gradal the other use of gradal is that if you want to use other people's code in your project as well for example if you want to use YouTube player in your project you will add its dependency inside this build. gradel file down in here just by writing one line of code gradel will download the code for YouTube video player as simple as that gradal will add the YouTube player code to your project and after that you can use it so gradal is a build tool that will handle the combination of every file and also other codes and will generate an APK file we will talk about different gradal scripts later on in the course okay let's close all of these extra files okay this was the project pain we can minimize or maximize this pain from here let's minimize that and let's talk about other pains available in Android Studio down in here you have some use useful uh pains as well for example this to-do is very helpful when you are creating or when you are developing Android applications todos are some works that you don't want to do at the time but you don't want to forget those works for example inside this main activity I can add a to-do as simple as that I can say to-do let's say complete this it's just for the developers to remind themselves or other colleagues to do something later on and as you can see this to-do has been added inside this to-do pane as well if you want you can check that it says that it's inside the main activity later on we will talk about how we can Define toos and also other kind of uh comments so this is one of the other pains the other one is this terminal down in here this terminal is like the command prompt in Windows or let's say terminal in Linux or Mac and it's very helpful if you are working with something like ADB or Android debug Bridge later on we will see the use of ADB in our projects also it's very useful uh for working with SQ light databases we will work extensively with this terminal in the database session after that we have this build tool here we have seen it when we have created our project you can see the progress of every application when it's going to be built in a lot of cases there might be some problem when we build our project and from here you can uh exactly locate the problem after that we have this lock cut in here it's going to be very helpful when we are going to debug our Android applications in fact we are going to work a lot with this lock cat okay let's minimize all of this for now above in here we have some menus uh we have file edit View and all of these uh we will work with uh most of them I believe in the course but uh it's impossible to work with all of them also there is is one thing that uh I need to say in here when you create your first application you may get some warnings for example a rendering warning or some other kind of warning if you get those probably there isn't something wrong with your application you just need to rebuild your project for that you can come to this build option in here and make your project once again in case if you get some errors at the first time that you create your application sometimes newer versions of Android Studio can be bugging and uh creating your project once again simply can solve your problem also there is another option from here from file you can close your project and reopen it that can be useful or in some cases you may want to invalidate your cache and uh restart Android Studio so if you get those warnings or errors you can uh try these three different ways in order to overcome uh the problem there is one very useful tool that has been added to Android Studio recently in the past few months and that's called uh Android profiler let's add that to this page down in here as well we can add that by going to this view tool windows and profile it's going to be helpful for monitoring the resources that your application is using for example the amount of ram the CPU that your application is using or even uh the amount of network that your application is using if you're run our application we can track the live amount of uh different resources that our application is going to use let's run our application and see it for ourself you can run your application by clicking on this green triangle from here but before that make sure to select the current app that you are working and also beside that make sure to select the device in the previous video we have created a virtual device and we can see the list of different uh virtual devices available I'm going to run my application on Pixel 3 API level 29 for no reason let's just run it if we click on this building here you can see the build progress I said that even if you are going to uh debug your application or even if you are going to run your application at the production process you can check the progress of build as well as you can see uh this uh emulator has been opened and we will see our application in a few minutes also from down in here you can uh see the current status of running your application right now it has created or built my application successfully and it's waiting for the device to turn on also if you check this lock cat in here you can see that there are a lot of things going on in here we will be using this lock cat extensively later on in the course for different debugging purposes let's minimize that also Al if you open this profiler you will see the live tracks of different resources that your application is using let's open our emulator right now we have this simple application in which has a predefined text called hello world and uh if you want you can check the amount of CPU or other kind of resources that your application is using it's going to be helpful when you are not sure how much resources your application is using let's minimize that for now if you want you can close your application with this uh red button in here you can stop it and also if you want uh you can turn off your device by long pressing this uh turn off button you can say power off and your device will be shut down as you can see we are getting some warnings in here right now these are not important uh but if you want to check them you can click on this event log and everything that happen since uh we click on this green triangle will be logged in here okay let's minimize that and let's switch back to our activity main.xml file and we have a lot of options in here as well right now you can see two different views of your application this white one is called the design view and this one in here is the blueprint view there are some slight differences between these two for example if you have some invisible item inside your activity that might not be visible inside this design view but you can keep track of that inside the blueprint view for now I'm going to disable this blueprint view because we are not going to work with that uh just for now in order to disable that you can click on this stack icon and you can say just design you can also minimize and maximize that by pressing this plus button in here and at the left panel in here you can drag different uh elements different user interface or UI elements for example if you want to add a button to your application you can simply drag it like this and this button will be added to your application as you can see right now because this uh element is clicked we can see different attributes at the right panel we have a lot of attributes for every user interface element the most important one is this ID above in here this ID is the unique ID of your element in which we will use it in order to have access to this button for example from inside our Java file later on we will talk about that if we click on our text view you can see that we have different attributes as well these are just a few attributes if you want to check the list of all of the available attributes you can click on these all attributes and you can see that there are a lot of them we we are going to get familiar with uh different UI elements in the UI session we have that uh I think in two sessions from now after the Java session we will be talking about user interface uh in specific details also when you are inside your XML file you have two views design view and text view design view is this view that we are working right now and if we switch back to text view you can see the exact value of every UI element in XML code XML is a markup language if you are a web developer you know the concept of a markup language HTML is also a markup language markup languages are just for defining some elements that user is going to see for example a button or text view you can see that there are a lot of attributes in here that the don't know anything about them yet we will be talking about them later on in the course so there are two ways of defining UI elements one is that you drag simple items for example a button uh to your design view or from the text view you can type it you can see that we have a button in here we can select the whole button and we can simply press delete and that button will be deleted you can see that we no longer can see that also if you don't have this preview enabl uh you can enable it from here let's just press contrl Z in order to get back our button and let's switch back to our design view I'm going to Define an ID for this hello text because later on inside my Java file I'm going to identify that and I'm going to work with that so by clicking on hello B you can see the list of attributes at the top we have this ID uh we can set an ID for our text view also if you don't know the difference between a text view edit text and all of these don't be worry text view is just a fancy way of saying a simp simple text you can Define the ID whatever you want for example in here I'm going to say txt message but notice that there are some conventions in here you can't use spaces when you are going to Define an ID also beside that you can't use some weird characters like a dollar sign or a hashtag sign the other convention in here is that you type the first letter in lower cases for example this T in here is lower cases and also after the first word uh you type the first letter of the second word uh in capital letters for example we have this m in here there are some just basic conventions among programmers by pressing enter we now have an ID for this hello world if we switch back to our text view from down in here you can see that for this text view an attribute has been added the ID attribute so no matter what you do inside your text view or design view they are basically the same but as as you can see right now we have some warning for this button the warning says that uh this button is not constrainted to anywhere that's because we are using this constraint layout for this whole XML file don't worry about this constraint layout yet we have other layouts like relative layout and linear layouts as well but for now just know that when you are using constraint layout which is the default case when you are creating an Android application you need to constraint or chain your different elements to somewhere for example if I don't constraint this button to anywhere it's going to be floating at the run time because of the different screen sizes we cannot know the exact position or exact place of this button and right now if we run our application probably this button will be moved to the place zero and zero which is exactly this corner in our layout in order to overcome this warning we can simply uh add some constraints by clicking and dragging as simple as that I'm constraining this button to the both edges of my um screen also for the top and bottom I can constraint that as well for the top I'm going to constraint that to this text View and for the bottom I'm going to constraint that to the bottom of my screen as you can see whenever I add a constraint an attribute will be added to this text view in here as well now we don't have that red warning also it's worth mentioning that uh by default when we have created this button when we have dragged that into our design view an ID has been added to it as well the ID of this button is just button we can change that if you want for example I can say BTN let's say hello or whatever you want but in an XML file the ID should be a specific to every element right now this button doesn't do anything in this video we are going to make our application a little bit more interactive for example we are going to change the text of this text view by clicking on this button for that we need to Define this text view in our Java file so that we could have access to its attributes but before I go further to my Java file I'm going to switch to F screen so that you won't be distracted with all of my icons down in here if you go to this view option in here down here at the bottom you can see that we have few options I'm going to go to full screen for the rest of the course I'm going to stay with full screen okay let's switch to our main activity. Java file as I said in the previous video you can see that we have some code written in here and that's because when we created our project we have selected the empty activity project for that now we have an empty activity which has an activity main.xml file and also Main activity. Java file in future we will see that we can create all of these files if we select no activity at the time of creating our project but in here we have these codes written to this level also we have this plus sign in here beside this import if you click on that you can see that uh we have imported some packages to this uh class if you want you can always minimize and maximize that uh import and for that matter you can minimize and maximize all of your methods for now now I'm going to leave these Imports like this so that we can see what we are importing into our Java file don't be worried about all of the new keywords that you are seeing in here for example this public class extend protected void we will talk about all of them later on in the course but for now just know that this uncreate method is going to be the start point of our application it means that when we run our application the codes inside these two cly Braes is going to be the code that will run from first once again don't worry about the term method that I used we will talk about that later on in the course so inside this uncreate method two things are happening we have this super. oncreate we are not going to talk about that right now and after that we are setting some content views by setting content views we are accessing to the activity main file you can see that we have this activity Main in here basically it means that this Java class is somehow related to this activity main layout file we will talk in more depth about this later on in the course but for now just know that up until this point in our code we have said that this Java file is related to this layout file after that we can write the codes that we need for example in here I'm going to access to that text view that we have created in the previous video for that I can say text view as you can see when I type something intelligate the ID behind the Android Studio is suggesting me some options there are a lot of options in here but the one that I need is going to come from android. widget package so in Java we have classes equivalent to the UI elements or user interface elements in our layout file if we are going to define a button we have that class in Java file as well in here we are going to use text view so we can import that in our project as well as you can see a new line of code has been added to our Imports this line of code is importing the text view from the diget package into our Java file next I need to name my text view the name is optional and you can name it whatever you want for example in here I'm going to say txt hello this is just a basic convention you can name your class whatever you want but we will talk about conventions later on in the course after naming your text view you need to locate the text view from inside the layout file and the way to do that is like this you can say is equal to there is a helpful method in every activity that is useful for finding different views by their IDs and that method is named find view by ID once again this method is useful to find different views different user interface elements from your layout files by their ID inside the parenthesis of this method we need to pass the ID of our text view from inside our layout file and the way to do that is like this we can type R R is a special class in Java which will give us the access to all of our resources our static files in our project once again it stands for resources let's select that we can say r. ID dot after that we need to add the ID of our text view which was txt message I believe this ID in here should be the exact ID that you have put inside your layout file for this text view you can see that the ID is txd message and we are using that to have access to our text view so this way by using this point view by ID method and after that passing the ID in this shape now we have access to our text view but you can see that there is one more error in here and that's because in Java every time you write a sentence you need to finish your sentences with a semicolon that's just syntactical and it really doesn't matter some languages does not require this semicolon but in Java you need to put a semicolon at the end of every sentence okay now up to this point we have our text view in our Java file now we can use it for example if we want to change the text of our text view we can say something like this we can type the name of our text view which is txt hello after that we can say dot don't worry about this dot operator we will talk about it in the next section in the Java section but for now just know that when you are typing dot on an object you have access to all of its methods and attributes for example in here I can say set text once again you can see that we have m multiple options let's import the first one inside the parenthesis of this method we need to pass a text and whenever you are going to pass a text statically whenever you are going to hardcode the text you need to pass it inside dable quotations let's pass a dable quotation inside this dble quotation I'm going to say hello this way now we have changed the text of our text view let's run the application and see if it's going to work remember that inside our activity main uh layout file the text is hello world inside our Java file we are changing it to hello let's run the application as you can see in here the text of our text view has been changed to hello still our application is not interactive we want to change the text when we click on this button not when we run the application for that we need to Define an event listener to be precise an onclick listener for this button so that when we click on this button the text of our text view changes there are multiple ways of defining an unclick listener for our button the simplest one is to do that inside your main activity layout file if you come down in here inside your button element inside the anchor brackets of your button if you type unclick you can see that we have an option in here let's pass a name in here for example I'm going to say on BTN click this name in here is going to be the name of a method in our Java file as you can see right now we are getting a red warning it's says that there is no such method in your Java file let's copy the name from here and let's go to our main activity and create that method so in order to create a method we need to do that outside of the scope of this uncreate method and inside the curly braces of this class I'm talking about these two we need to Define our method inside this class and the way to do that is like this we can say public void after that the name of our method which is on B and click a pair of of parentheses because it's going to be the onclick listener for our button we need to accept a view in here don't worry about this viewing here we will talk about all of these in Java session let's name this view after that we need a pair of curly braces for our method and in here we need to put the code that we need to execute when the user clicks on our button if you switch back to your activity main.xml file now you can see that the red error uh has been disappeared okay let's go to main activity. Java file I'm going to change the text of our text view to hello when the user clicks on our button so for that matter I'm going to move these two line of code uh to inside this method you can probably guess the behavior of our application right now let's run it once again and see how is it going to work you can see that the text still says hello world if you click on our button the text will change to hello this is okay but this is not entirely what we want it's just saying hello right now we want to say hello to the exact user for example we are going to get the name of our user and by clicking a button we are going to say for example hello masam hello Tom and something like that we are going to get the users input the way to get the users input is by using some element in our UI called edit text let's switch to design view you can add an edit text into your project by going to this text option in here you can see that we have multiple options the first one is for text view we have seen the text view it's uh this hello world text after that we have other options plain text password email and all of these these are all helpful uh for when you want to get different kind of users input but for our purpose in here we are going to use plain text plain text is just a simple text that we are going to get from the user let's drag that into our view if you take a look at the attributes in here you can see that its ID is edit text let's quickly change that let's say edxd name because we are inside the constraint layout we also need to constraint this uh edit text as well but before that I'm going to change uh the top constraint of this button I'm going to change its constraint from the bottom of this text view to the bottom of this edit text for that I'm going to drag the top constraint of this button to the bottom of this edit text now let's add some other constraints for this edit text as well for example for the top I'm going to constraint it to the bottom of my uh text View and also for the edges I'm going to go to the edges of the screen right now it's too close to our text view if you want we can add some margins for example in here I'm going to say 70 that seems to be better the other attribute that every edit text has is uh this text in here I'm talking about this attribute in here you can see that right now it says name if you want you can change that but in here I'm going to completely delete that instead I'm going to Define some hints you can see this hint attribute in here the difference between hint and text is that when you click on your edit text the hint will be deleted it's just a hint for the user to know that what he or she is going to enter inside this edit text for example in here I'm going to say name you can see that it's somehow grayed out okay now we have an edit text inside our layout file inside our Java file we need to have access to this edit text so that we could get the users input once again the start point of our activity and our application is this uncreate method so we can do that inside uh this uncreate method we can have access to our edit text like we did for this text view we can say edit text once again you can see that we have an equivalent class for this edit text as well also if you take a look at cut in here uh you can see that this line of code has been added to our class as well let's say edit text dxt name like before we can say is equal to find view by ID and once again we need to pass the ID of our edit text which I can say r. ID do edxd name to this point we have defined our edit text now uh we need to get the text of our edit text for that we can say edit text name do get text Tex you can see that we have this option but this is not enough we also need to do another level of conversion and we do that by saying do two string don't worry about this two string method yet we will talk about that later on in the course it's just for converting whatever the text is inside our edit text to a text that we can use in our Java file don't worry about that we will talk about it later on but there is a problem with our code in here we are going to get the user's name and we are going to say hello to to the user when we click on the button for that we need to have access to this edit text inside our on button click method but if you try to do that for example if you say edit text name you can see that everything is in red it means that you don't have access to that edit text inside this method and that's because something called scope in Java the scope of this edit text is this oncreate method within the curly braces of this uncreate method we can't have access to this element from from inside our on button click method in order to solve that problem we need to move these two line of code to inside our on button click method let's quickly do that inside our on button click method let's paste them but right now we are not doing anything with the users input we are getting the user's input but we are not doing anything with that we need to pass this line of code to the set text method let's quickly delete this line of code and inside the parenthesis of this set text method I'm going to pass that I'm going to say edit text name. get text. two string this way we are setting the text of our text view to whatever the text is inside our edit text let's quickly run the application and see if it's going to work this is how our application and this edit text looks right now if we click on that you can see that uh we can type something for example let's type my name and if you click on our button the text of our text view changes to Mason this is not entirely what we wanted we wanted to say hello to mam in order to do that we need to make some changes to our code also notice that I didn't put any double quotation in here and that's because we are passing this text dynamically to our set text method if we wanted to pass our text statically we need to put that inside double quotation but in here we don't need the double quotation if we want to say hello to the user we can say something like this we can say double quotation let's add a plus in here and inside these double quotations let's say hello Also let's add a space so that uh we could see everything better this in here is called concatenation in programming adding the two texts together let's run the application once again and let's type something in here let's say Mesa by pressing button this time you can see that the text has been changed to hello Mesa our application is now much more interactive okay this is our challenge we are going to create a registration form like this we are going to get the user's first name last name and email and by pressing this register button we are going to show them inside these text views let me quickly show what I'm talking about so if we have a first name a last name and also an email if we click on this register button we are going to show them inside these text views to the user it's just a simple application so that we can practice everything that we have have learned so far okay I want you to pause the video in here and create this simple application after you have created it come back to the video and we are going to create this exact application together I hope you solv the challenge but if not that's totally okay we are going to create that in here together also notice that whenever you run Android Studio you can see a list of recent projects in the left panel in here okay let's move on and let's create our project we can say start a new Android Studio project once again we are going to select this empty activity let's name our project in here I'm going to name it first challenge or let's name it registration form you need to specify a package name mine is fine uh change the save location if you want and also I'm going to stay with API level 19 okay let's create our project let's start by creating our layout file I'm going to close this Java file for now and let's also minimize this project L first of all let's delete this hello world text you can click on it and by pressing delete you can delete that in our registration form we need the three edit texts let's add them quickly in text we need to add three plain texts in here let's quickly add them we will constrain them later on don't worry about that right now three edit text and also we need a button let's add that as well we also need the three text views for the edit text let's also change their IDs for the first one I'm going to say edit text first name uh let's also delete this text and also add some hint let's say first name let's do the same thing for the other two edit texts sometimes when you are defining a hint or maybe a text attribute for your elements you can see some annoying dialogue like this in here you can avoid that by pressing the Escape key on your keyboard okay for the button first of all let's change its ID to let's say BTN register you can name it but whatever you want uh let's also delete this text and let's say register also you can see that we have this onclick attribute in here we can define an unclick attribute for our button from here or like we did in the previous video in our text view I'm going to Define that right now in here let's say on register BTN click later on we will create this method for the text views first of all let's change their IDs for example for the first one let's say txt first name all Also let's change the text to first name similarly for the other two okay let's quickly constraint all of these elements we can click on them for the first one I'm going to constraint it to the top edge of my screen and also both sides of my screen let's also add a margin top of maybe uh 100 that seems to be better for the next one I'm going to constraint it to the both edges of the first name edit text and also to the bottom of of my first name edit text at a margin top of 24 I'm going to do the same thing for this email for the button I'm going to do the same thing but I will probably change the top constraint also if you did a mistake when you are constraining your elements you can click on the constraint by pressing delete key you can delete the constraint let's change the top constraint to maybe something like 90 DP for the first name I'm going to constraint it to the both edges of my button sometimes it may not work just try once again and also the top constraint to the bottom of my button uh for the top constraint once again let's say 90 I think 90 is fine uh let's delete this top constraint because right now we are not seeing our last name text View and let's add it once again for the last name I'm going to do the same thing let's change the top constraint margin to let's say 24 same thing for the email okay this is going to be the look of our application and now that we have defined our layout file let's switch to our Java file and Define the behavior of our application I'm going to close this activity main.xml just before everything let's just copy this unclick attribute so that we don't make any mistake when we Define this method in our Java file in our project P inside Java folder inside our package folder inside our main activity. Java file I need to to create my onclick method once again I can say public void the name of my method which I've copied from my layout file inside the parenthesis I need to say view with capital V after that view with the lower V and now I have created my on button click listener once again don't be worri about the syntax of this method we will talk about it later on when we have talked about Java in here first of all I'm going to Define my text views if you remember we can do something like this we can say text View for the first F let's say txt first name is equal to find view by ID r. ID do uh txt first name I'm going to do the same thing for email and last name after you have defined your text views it's time to Define your edit texts we can do that like this we can say edit text for the first one let's name it edit text first name is equal to find view by ID r. ID do edit text first name once again I'm going to do the same thing for edit text email and also edit text last name okay now we have access to all of the UI elements that we wanted now let's change the text of our text views for example for the txt first name I can say something like this let's say txt first name do set text we have seen this in the previous video nothing new in here let's say first name plus the text of our edit text first first name we can say edit text first name. getet text. two string as simple as that now we are setting the text of our text view to the text of our edit text let's do the same thing for last name and emage edit text last name do set text let's say last name first of all plus edit text last name do get text do two string edit text email do set text uh sorry I have put the wrong element in here this should be txt last name not edit text last name same thing for the email txd email do set text let's say email plus edit text email. get text. twring that's all we need from our application let's just run it okay it seems like uh we have done a good job with the layout of our application I think it's just better to decrease the margin top of this register button and also this first name edit text so that we could see all of them better let's also test Its Behavior for the first name let's say Emma for the last name let's say Watson for the email Emma Watson gmail.com let's click on this register button and as you can see we are seeing the text that we wanted it seems like our application is working perfectly in this section of the course we are going to talk about Java for writing Java applications we are going to need an IDE IDE stands for integrated development environment Android Studio has been built upon an IDE called intell until few months ago you could have write and drawn Java applications on Android Studio but I think it was around July 2019 that you can no longer do that and that was because of a new release in gr I have recorded a video on that exact problem at the time and it's on my YouTube channel if you want to take a look at that just uh search for make code on YouTube and you will probably find the video let me quickly show that this is the video that I'm talking about Android Studio does not support plain Java code anymore what to do now and you can also see my uh channel name so make sure to check that if you need but basically what I was talking about in that video was that instead of Android Studio you need to use another IDE the most famous Ides that are available for writing Java applications are eclipse and intell in this course we are going to use intell because it's a lot like Android studio and also it's free in that video I have talked about how to install intell IDE make sure to check that if you need but it's a lot like installing Android Studio beside intellig you are going to need jdk Java development kit which we have already installed on our system you can get intellig ID from jet brain's website let's say intellig ID the first link from the jet brains website probably is our needed link just one thing that worth mentioning in here is that there are two versions a community version and also an ultimate version the community version is free and also it's enough for our need in this course so make sure to download that and after you have downloaded it and also installed it come back to this video to write Java applications I have intell installed on my system and I'm going to uh open it right now you can create a new project in here by saying create new project as you can see the process is a lot like Android Studio I have the ultimate version of intj ID and for that I can see all of these options these might not be available for you if you are using Community version but no matter what version you using you should see this Java option in here select that in here you need to specify the path to your uh jdk if you have installed jdk with me at the beginning of this course you should be good in here you can and just select the version of your jdk my version in here is 13 but we are not going to use all of the features of java 13 because Oracle does not support this version of Java for long term we are going to stay with all of the features of java 8 okay after you have selected the Java and your jdk let's click next we are not going to create our project from template so make sure to uncheck this option after that click next in here we need to name our project and also specify a location for the name of this project I'm going to say hello V also if you don't see these settings in here you have this more settings option down in here make sure that your module name is exactly your project name also feel free to change the project location if you need I'm not going to change that in here let's just click finish and let's create our project as you can see intellig ID is a lot like Android studio and the reason for that once again is that Android Studio has been built upon this IDE let's just close this tip dialogue and let's switch to full screen mode and let's go to full screen mode once again in intell ID you can see this project pain you can minimize and maximize that you can also move through the folders right now because we didn't use any template our folders are empty we can create our project like this by clicking on the source folder by right clicking on that selecting new package we can spef spe ify a package for our application in this case I'm going to say or. make code do let's say hello world and inside this package we can create our Java classes don't worry about the term class that I used we are going to talk about that in object oriented session but for now just know that we are going to need at least one Java class in order to run our Java applications by right clicking on our package and selecting new Java class we can create our class let's name this class hello as you can see a new Java class has been created in our package and also you have few lines of code let's minimize our project pain and let's focus on this hello. Java class basically what we have in here is the package that we are currently in which is or. make. hello world and also we have the Declaration of a class once again we are going to talk about classes later on in future videos in order to have a start point for our application we are going to need at least one method and that meth method is called the main method in order to create that method we can type psvm by pressing tab or enter we can have that method as you can see this green triangle has been added in here it means that now we can run our application from this point we will talk about the meaning of all of these near keywords later on in the course but for now just know that in order to run your Java applications you need at least one Java class in which has one method called main this main method is like the oncreate method of our activities now we can write our codes inside this main method for example in order to print something to the console we can say something like this we can say s o t or sound and by pressing tab or enter you can see this line of code system.out.print line or alternatively you can type this manually instead of using the shortcut you can say system notice that the S should be in Upper cases make sure to use the uppercase for S let's say c system.out basically this out means output in here it means that we are going to Output in something in this case we are going to print something later on we will see that we have an in as well in which we will get the users's input let's say system.out do print line you can see that we have print and print line for now we are going to use the print one we will talk about the difference later on in order to print something to the console you need to pass it inside the double quotation you can can say something like this for example let's say hello world now we have the simplest Java application that can be written let's quickly run our application in order to run our Java application for the first time we need to right click inside the curly braces of our main method and select run hello. main let's do that as you can see we are printing hello world into our console sometimes if it's the first time that you are running Java applications you may get some errors in here in in the most cases those error will be gone by rebuilding your project you can come to this build tab above in here and rebuild your project after the rebuild is finished you can run your application once again by right clicking and selecting run hello. m in most cases the error should be gone but if you had any other problem please uh ask them in the Q&A section of the course also notice that for the rest of this section we are not going to have any user interface it is possible to have a graphical user interface gu for your Java applications but because this is an Android course and later on we will talk about user interface in Android applications we are not going to use any user interface for our Java applications we are just going to understand the language okay now let's minimize our run pain from here and let's talk about the difference between print and print line the difference between print and print line is that when you are using print line after printing your text the cursor we'll move to the next line that is not the case with print in order to see the difference let's say system.out do print once again let's pass our hello Vol text and let's run our application to see the difference also if it's the first time that you are going to run your application you can right click inside the main method and click on this run hello. main or if it's not the first time you can click on this green triangle at the left or the green triangle uh on the top of your screen you can also see see the shortcut for Windows is shift plus F10 if you are using Mac or Linux you can hover over this green triangle and see the shortcut let's run the application and see the difference between print and print line you can see that the text has been printed but the cursor never moved to the next line if we switch these two line of code we can see the difference better let's switch them now print line is the first line and print is the second line let's run the application once again this time you can see that the two text has been printed in two separate lines okay now that we know the difference between print and print line let's talk about variables in Java but before I do that I'm going to comment these two line of code you can comment them by pressing control plus slash when you comment some code in Java it means that you are telling the compiler to ignore these two line of code the use of comment is for developers to remind themselves or other colleagues of something important for example in here I can say slash slash let's say do something something this line of code will be completely ignored the other kind of comment in here is like this we can say slash slash too after that we can say do something if we use this kind of comment with to-do at the beginning of your comment you can see that first of all the color will be changed to Blue and also if you click on the to-do tab in here you can see that you have one to-do in your file it's very helpful when you are working with multiple programmers by clicking on this to-do everyone can see the list of different toos there are more to comments we will talk about them later on in the course but for now just know that when you are commenting something that line will be completely ignored okay now let's talk about variables variables are useful for when you want to store simple data in your Java application for example if you want to store a number or a text variables are useful for when you want to store some small data in your Java application for example if you want to store a number or a text Tex if you want to store a number you would do that like this you can say int int stands for integer basically inside an integer you can store whole numbers for example negative and positive numbers plus zero and the way to define them is like this first of all you type int after that you need to name your variable for example in here I can say number this name in here is optional and you can use whatever you want after that you can assign a value to your variable for example I can say five in here this int is the data type of my variable this number is the name of my variable and this five is the value of my variable beside positive numbers you can also have negative numbers after you have stored your variables you can do some operation on them for example you can print them and the way to do that is like this you can say system.out.print line and after that you can pass your number or whatever is the name of your variable notice that in here I haven't used quotation basically whenever you are passing some text explicitly you need to pass the double quotation but whenever you are passing your variable you shouldn't pass any dable quotation let's run the application and see if we can see our number we can see that the value of our number is -5 in this case but inside integers you cannot have decimal values for example in here I can say 5.3 we will see other kind of variables in which you can use in order to store decimal number numbers but more on that in a few minutes the other kind of variable that you can use in order to store whole numbers is long let's see that as well we can say long we can name it my long is equal to once again let's say five let's also print that let's say system.out.print line and let's pass our L if we run the application we can see five down in here the difference between long and integer is that you can store larger numbers inside a l and also so a long variable will store more spaces in your devic's memory RAM to be exact inside an integer you can store numbers as large as the number of two to the^ of 31 but inside a you can store numbers as long as the number of two to the power of 63 that's the difference between long and integer but what if you want to store decimal numbers floating Point numbers for that you have other kind of variables the first one is a double let's see that we can say double let's name it my double let's assign it the value of 4.5 like before we can print it let's pass our double if we run the application we should see the number of 4.5 printed you can see that down in here so double is one kind of variable in which you can use in order to store floating Point numbers the other option is to use float let's see that as well we can say float let's name it my float once again the names are optional you can name your variables whatever you want we can say 4.5 in here once again but right now you can see that we are getting a red error in here and that's because floating Point numbers by default are double in Java it means that if you want to define a float number you need to cast your number to float the way to cast your number is like this after the equal you can open and close a parenthesis and inside the parenthesis you can say Float by casting you will explicitly tell the IDE that this is going to be a float number and not a double number okay let's quickly print this as well let's pass our float and let's run the application you can see that once again 4.5 has been printed once again the difference between float and double is that inside a float you can store smaller numbers and also the other difference is in the space that each one of these are going to occupy in the devic's memory R basically dble will occupy more space we won't be be using float that much in this course I just wanted to show you that float does exist in Java okay now we have seen numbers but what if we want to store different characters in Java for that we have a special kind of variable which is Char for example we can say Char my Char is equal to let's say m notice that when I've assigned this character to my Char variable I have used this single quotation that wasn't the case when we have worked with different numbers when you are assigning a character you need to use the single quotation like before we can print our character let's pass our character and let's run the application you can see M printed in here when you are using Char variable you can't have multiple characters for example in here I can't have Ma you can see that we are getting an error in order to store multiple characters we have another kind of variable in which we will talk about that in a minute but before I do that I'm going to show you just one more thing you can also store something like this in your character you can say back SLU 00 AE this is the special uni code value for registered symbol let's run the application and see what would be the result you can see that the registered trademark has been printed into our console when you are using a Char variable you can also assign uni code values as well you can search for different Unicode values for example if we want to show the copyright symbol we can say something like this we can say back sl00 A9 if you run the application we should see the copyright symbol feel free to search for other unicote values on the internet okay now let's talk about a string if we want to store multiple characters we can use a string we can say a string with capital S after that like before we can name our string let's say my string or let's name it name is equal to mayam my name like before if you want we can print our string let's pass name and let's run the application we can see that mam has been printed into our console but you may have noticed that there is a difference in here the color of this string is not blue like the other kind of variables that's because of a very important difference between a string and other kind of variables the other kind of variables that we have talked about so far are primitive data types but a string is a class in Java we will talk about classes and objects in Java but for now just know that when you are using a class you can have some operations on that for example if you type name you can say dot and you can see a list of different available methods we will talk about few of them later on in the course but you can see that there are a lot of them so the difference in here is that a string is a class but others are primitive data types there is one more kind of variables that I'm going to talk about in here and that's called Boolean let's see that as well we can say say Boolean my Boolean let's say is equal to true when you are using a Boolean that Boolean can have only true or false values these are the only two values that a Boolean can have once again like before we can print our Boolean let's pass my Boolean in here and let's run our application you can see that true has been printed as I said our Boolean can have false values as well let's run the application false has been printed Boolean is very helpful when you are working with conditional statements we will talk about conditional statements in the next video okay this was our talk about different variables in Java there are few more of these in which you can check at the Oracle documentation but probably you are not going to need the others these are all that we are going to use in this course okay now that we have talked about variables let's quickly talk about arithmetic operators as well but before that I'm going to comment all of these lines of code because these can be distracting the reason that I'm commenting these lines of code and not deleting them is that I'm going to upload the source code so that if you need you can check the source code okay let's move on down in here let's quickly Define two new integers I can say int a is equal to 6 after that let's say int B is equal to let's say two you can use operators in Java in order to perform some kind of operation on your variable we have different kind of operators the first one that we are going to talk about in here is called arithmetic operators let's quickly see them for example in here I can say int answer is equal to A+ B this plus is the first arithmetic operator that we are going to talk about in here this is going to add the value of B to a let's quickly print our answer and let's run our application you can see that the answer is eight it has has added B to a the other kind of arithmetic operator that I'm going to talk about in here is minus which you can guess its value it's going to deduct B from a the answer in here should be four you can see that four has been printed the other one is a star which is used for multiplying the two values together in here the answer should be 6 * 2 which is going to be 12 let's run the application and you can see 12 in here the other one is Slash which is used for division we are going to divide 6 by two let's run the application we can see that the answer is three the thing that you need to be extra careful with this slash operator in here is that the second number B in this case should never be zero let's quickly change the value of B to zero and let's see what would be the result let's run the application you can see that we are getting a red error in here we are getting an arithmetic exception we will talk about except exeptions later on in the course but for now just know that whenever an exception occurs our application crashes certainly we don't want that behavior in our application so be careful about the second number or alternatively you need to catch the exception that you think that might occur we will talk about exceptions later on in the course we have one more kind of arithmetic operator in Java and that's called remainder let's see that as well it's the percent sign the remainder operator is going to give us the remainder of a / by B in this case if we divide 6 by 2 the answer is three and its remainder is zero so right now if I run the application I should see Zero you can see that zero has been printed down in here but if I change the value of a to let's say five now the remainder of 5 / 2 is 1 let's see that if we can see one yes it has been printed from time to time this remainder operator can can be useful as well there is one more thing that I need to talk about the slash operator the division operator right now we can expect that if we divide 5 by 2 we should see 2.5 let's run the application and see if we can see that we can see that we are getting two as the answer and that's because we have saved the answer inside an integer if you remember at the beginning of this video I said that integers can only contain whole numbers if you want to have floating Point numbers you can use something like double but this in here is not going to work as well because the answer itself is an integer if you hover over the Highlight you can see that a ided by B is an integer if you want to cast your number to a double after the equal sign you can open and close a parenthesis and inside the parenthesis you can say double this way you have casted an integer to a double now if we run our application you can see that we are seeing 2.5 five so if you want to see the exact value of a division use doubles let's just talk a bit more about the plus operator and after that finish off this video so right now if I use a plus in here you can guess the answer 5 + 2 is 7 let's run the application we can see seven down in here we can also use this plus with different texts for example if I have two text in here let's say string first name is equal to let's say emmo let's also Define another text let's say last name is equal to Watson we can use the plus operator to add these two text together for example let's say a string full name is equal to first name plus our last name if we print our full name you can guess what would be the result in here we can see Emma Watson let's also add a space in here in order to see everything better Emma Watson has been printed this in here is called concatenating in Java adding two text together so you can see that this plus operator have two usages it can be used to concatenate two text together or whenever we use it with different numbers it will act as the addition [Music] operator we are going to talk about more operators in Java specifically we will talk about relational and logical operator before doing that let's quickly create our project by selecting create new project by selecting Java and clicking on next and next once again we can name our project let's name this project operators let's create our project and inside the source folder let's create our package let's say new package let's name it or. make code do operators inside our package let's create our main class let's let's name this class main inside our main class we are going to need our main method let's type psvm by pressing tab we have our main method before I talk about relational and logical operators let's quickly talk a bit more about arithmetic operators if you remember from the previous video when we have to find a new integer for example a and we assign a value to that we could have say something like this we could have said in answer is equal to a + 2 or instead of defining a new integer we can say a is equal to a + 2 it means that increase the value of I by two let's print a and see what would be its result let's run our application because it's the first time I'm going to say run main. hello you can see that the value of a is seven we can simplify this line of code we can say something like this I'm going to comment that and in here I can say A+ equal 2 let's also add some spaces these two line of code are exactly the same we can use plus equal in order to simplify the line six let's run our application once again you can see that the result is the same also if we want to uh increase a by 1 for example if you want to say a is equal to a + 1 we can uh do something like this we can say a + equal 1 or alternatively we can say a ++ that is possible as well this a ++ is going to increase the value of a by one if we run our application we should see six as the value of a you can see six down in here alternatively we can use minus as well we can say a minus minus it will deduct one from the value of a if we run our application we can see four in the console similar to that we can say a minus equal equal to let's say two for example in this case if we run our application we should see three as the value of a like minus equal you can also have multiply equal and also divided by equal it means that divide a by two and store the value or store the answer inside a this sentence in here is the simplified version of this line of code that I'm going to write we can say a is equal to a / 2 both of these lines are the same if you want to make make sure of that you can delete this line and you can run your application 5 / 2 is 2.5 because we are saving that inside an integer the answer should be two so we should see two as the value of our a and you can see two down in here before talking about logical and relational operator I just wanted to talk about these simplifications okay now let's talk about relational and to be specific comparison operators in Java comparison operators are useful for when you want to compare two things for example two numbers before that let's quickly Define two numbers I'm going to say int a is equal to 5 after that let's say int B is equal to let's say three after that we can say Boolean answer is equal to the first comparison operator that I'm going to talk about in here is greater than operator and the way to define that is like this we can say a greater than B I have saved the result of this comparison in inside a Boolean this left anchor bracket in here means greater than operator it means that if a is greater than b assign the value of True to this answer right now if we print our answer we should see true let's quickly do that let's say answer and let's run our application you can see that answer is true because a is five and 5 is greater than three the other kind of comparison operator is less than and that's this uh right anchor bracket right now A is not less than b so the answer should be false if we run our application we should see false in the console and we can see that the other kind of comparison operator that I'm going to talk about in here is useful for when you want to compare the equality between two integers and that operator is these two equal signs right now A is not equal to B so if we run our application we should see false into our console let's run our application and here we can false remember that when we are using two equal signs it means that we are checking for the equality of two number but when we are using a single equal sign like in here and above in here we are assigning a value to our variable let's change the value of B25 to see that if this is going to be true let's run the application now you can see that the answer is true we have other kind of comparison operators as well one of them is greater than equal when we use this left anchor bracket and also this equal sign it means that check if a is greater than b or if a is equal to B right now A is equal to B so this answer should be true if we run our application we should see true you can see that down in here we see true also if a is five and B would be something like three if we run the application we should see through once again we can see through but if we change the value of a from five to something like two because none of this condition is true right now we should see false let's run our application and we can see false the other comparison operator is less than equal and we use that like this we can use this right anchor bracket and equal sign this in here means that check if a is less than b or if a is equal to B right now A is less than b so the answer should be true if we run our application we should see true but if we change the value of a to something like five we should see false and we can see false beside this we also have another kind of comparison operator and that's this explanation mark plus the equal sign this in here means that check if a is not equal to B this explanation mark in here adds a negative meaning to our equal operator right now A is not equal to B so the answer should be true if we run our application we should see true and true has been printed okay these were the comparison operators that I was going to talk about feel free to practice them because we are going to use them a lot in our course next I'm going to talk about logical operators in Java but before that let's quickly comment this two line of code down in here let's define a new Boolean let's say Boolean answer is equal to let me write the syntax and I will talk about it we can say a is equal to 5 or let's say B is equal to something like two this is our first logical operator this in here means or you can add these two pipelines by using shift plus uh back slash back slash is somewhere above the enter in English keyword so in here this or operator means that if a is equal to 5 or if B is equal to 2 assign True to this answer if none of this condition is true so assign false to this answer right now A is equal to five at least one of our conditions are true so the answer should be true so if we print our answer we should see true let's run the application and you can see through down in here if we change the value of a for example to six because none of these conditions are true we should see false let's run the application and down in here we can see false the other kind of logical operator that I'm going to talk about is two and signs let's quickly see that as well this in here is and operator it means that assign true to answer if both of these conditions are true if a is equal to 5 and also if B is equal to two if one of these conditions is not true so assign false to answer right now none of these conditions is true so we should see false as our answer let's run the application and as you can guess we see false if we change the value of a to 5 and draun our application once again we should see false because the second condition is not true but if we change the value of B22 and run our application this time we should see true and we can see through down in here and these were the two kind of logical operators that I was going to talk about or and and now that we have talked about the operators that we wanted let's talk about conditional statements I'm going to comment these two line of code the first kind of conditional statements that I'm going to talk about is called if statements we can type something like that we can say if a pair of parentheses inside the parenthesis we need to provide our condition for example we can say if a is greater than three after the parenthesis we need a pair of curly braces inside the curly braces we can put our code for example let's say a is greater than three so in here we are saying that if our condition is true execute the code inside the curly braces if it's not true jump to after the curly braces for example in here let's say continue right now A is five and it's greater than three so we should see this text printed let's run our application you can see that a is greater than three but if we change the value of a to something like two and run our application we can see that we are no longer seeing this text in if statements we can also have multiple conditions for example in here I can say else and I can provide another pair of curly braces inside these curly braces I can say something like this I can say a is less than three right now A is two a is less than three so we should see only this uh text printed let's run our application you can see that a is less than three as for the condition you can provide your condition like this directly inside your uh if statement parenthesis or you can Define your Boolean before your if statement for example here if I say Boolean answer is equal to a greater than three now I can pass my answer inside this parenthesis I can say if answer is equal to True let's minimize this run pain for now this is going to work the same but if you hover over the Highlight in here the intell ID is warning me about something the first warning is that answer equals equals to True can be simplified to answer it means that I can delete this part this this is going to work exactly the same if we run our application we should see the same result a is less than three let's run our application and you can see a is less than three if we want to negate this answer we can add an explanation mark before our variable for example in here we can say if answer is not equal to true if we run our application we should see the first line you can see that a is greater than three this is not true because a is two but in here we have uh changed the meaning of this Boolean we have added a negative meaning let's delete this for now and let's run our application once again beside else you can also have an else if as well let's quickly comment this if statement and let's write another one then in here I'm going to say if inside this if statement let's check that if a is positive or negative I can say if a is greater than zero inside the curly braces let's print a is positive in here in instead of else I can use something like this I can say else if now we need to put another condition in here we can say if a is less than zero once again we need a pair of curly braces inside the curly braces we can say a is negative you can have as many else if cases as you want for example I can add another one in here but of course in here I don't think this if statement would mean anything but you can have as as many as you want but in every if statement you can have at most one else case let's delete all of these for example I can have only one else case this else is going to be the default case in this case if we use this else it means that a is not greater than zero and also it's not less than zero so it is zero and here we can safely say a is zero this is going to be the default case for our if statement right right now A is 2 so we should see a is positive let's run our application and as you can see a is positive let's change a to minus 2 if we run our application you can guess it we should see a is negative and we can see that down in here if we change the value of I to Z we should see a is zero and as you can see we can see that down in here so if statements are one kind of conditional statements we have another another one as well let's comment all of these the other one is called switch statement let's see that as well we can say switch inside the parenthesis of this switch statement we need to provide the variable that we want to switch on for example I can pass a in here after the parenthesis I can provide a pair of curly braces inside the curly braces I can Define different cases for example I can say in case a is equal to one after that we need a column and in case a is one we can uh print something for example we can say a is one also it's very important to provide a break after every case let's do that I will talk about this break in a minute but for now just know that after every case you are going to need a break we can Define as many case as we want for example in here I can say in case a is two let's print something let's say a is two after that we need a break we can Define another case for example for three let's say a is three in every switch statement we are going to need a default case as well and we can pass that like this we can say default and we can print something like a is not one 2 or three in the default case we need the break as well let's quickly add that right now the value of a is zero let's change that to two and you can guess it we should see a is two let's run the application and you can see a is two if we change the value of a to once again zero and run our application you can see a is not 1 2 or three let's also talk about this break in here but before that let's quickly change the value of a to one this break in here will cause our switch statement to break for example if we don't have this break in here at the first case which is AAL to one and if we run our application you can see that even though a is one we can see both sentences we can see a is 1 plus a is 2 in here because we don't have any break we didn't break out of the switch statement and we have jumped to the second statement so don't forget to have a break after each case in your switch statement we are going to talk about loops in Java but before that let me just say that that I have created my project I have added this package inside my source folder inside this package we have only one main class in which has this one main method I hope that you can come to this point by yourself if not please watch the previous videos on how to create a project and uh create your main class and your main method in programming Loops are useful for when you want to do a repetitive job for example if you want to print something 10 times like this in here if you want to print this hello 10 times you can just copy and paste it 10 times but in general it's a bad idea that you copy and paste yourself whenever in programming you are copy and pasting know that you are doing something wrong instead of copy and pasting we are going to use Loops in this video the first kind of Loops that I'm going to talk about are four Loops let me write it and we will talk about its syntax this is the general syntax of a for Loop first of all we write four after that we have a pair of parentheses inside the parentheses we have three statements in the first statement we are defining a new integer called I you can name your integer whatever you want and also we are initializing our I to have a value of zero the second statement is the condition of our for Loop we are going to continue this Loop until this condition is not met and the third state m is just a statement for changing the value of I every time that we look we will see in action what all of these mean after the parenthesis we have a pair of curly braces in which we can contain our code inside them for example if we want to print something like hello in here we can include that inside this pair of curly braces so what this for Loop is going to do is that first of all we are defining a new integer called I and we are assigning the value of zero to that integer after that we are checking our condition we are checking that if I is less than 10 in the first time that we are going to loop I is zero so this condition is met if this condition is true we are going to execute the code inside the curly braces in this case we are going to print hello after printing hello we are going to execute the third statement in this case we are going to increase the value of I by one for the next time that we are going to Loop first of all we are going to check our condition we are checking that if I is still less than 10 or not for the second time I is 1 I still is less than 10 so we are going to execute our code this circle in here is going to continue and continue until our condition is false when it's false we are going to break out of the for Loop so in this case we are going to print hello 10 times let's run our application and let's see if we can say hello 10 times you can see that we have printed hello 10 times it seems to be perfect instead of 10 you can put any number that you want in here for example you can say five if you execute your program you would see that hello would be printed five times instead of this five in here you can pass a variable for example if you had a variable before this for Loop if you had int a is equal to five in here later on we can pass a instead of five to this for Loop for example in here in instead of five we can say a if you run the application we should see the same result inside our for Loop we can also have access to the I itself for example instead of printing hello we can uh print I let's quickly print that as well and let's run the application you can see that we are printing the numbers 0 to four okay four Loop is one kind of Loops in Java the other kind is V Loop let's quickly see that as well once again I'm going to write the syntax of V Loop and we will talk about it after that this is the general syntax of a vo Loop first of all we type V after that we have a pair of parentheses inside the parentheses we have our condition in this case a less than 10 after that we have a pair of curly braces and inside the curly braces we have our code in this case we are going to print hello notice that we are not changing the value of a so this condition is always true and if I run my application right now we are going to stuck in an infinite Loop let me quickly run the application and see what an infinite Loop looks like but before that let me uh comment this for Loop you can see that no matter what happens we are inside an infinite Loop we are printing hello indefinitely in some cases this might be our desired Behavior but in most cases we probably do not want that we can exit our application by pressing on this red button we can also check our exit code which is -1 in a normal application we would get zero okay but how can we exit a v Loop there are multiple ways for that the simplest way is to change the value of a inside the V Loop for example after printing hello I can say A++ in order to increase the value of a so that it won't be the same every time that we are going to Loop through this while loop so for example for the first time a is five so our condition is true so we are going to execute these two line of code we are going to Loop through this cycle until a is 10 when that's the case this condition is no longer met and we are going to break out of the V Loop let's run the application one more time this time you can see that we have only printed hello five time and also this exit code is zero which which means that we have exited our application successfully without any error the other way that break out of a vo Loop is to add a break let me quickly add that this time after the first Loop we are going to break out of the V Loop it means that we are going to print hello only once let's run the application and in here you can see that we have printed hello only once inside V Loops we have another keyboard called continue let's go quickly see that as well I'm going to delete this break and before this print statement I'm going to put an if statement let's say if a is equal to 8 then let's continue this continueing here means that go to the next record of your V Loop go to the next round of looping it means that no matter what is the rest of the code inside the V Loop break out of the V Loop and go to the next record so for example in this case if a is five 6 or seven we are going to print hello but if a is 8 we are not going to print hello after that we are going to print hello in case if a is N9 if we don't want to stock in an infinite Loop we also need to change the value of a somewhere inside the V Loop for example before this if statement I can say A++ right now if I run my application I should say hello only four times because if a is 8 we are going to continue the Loop it means that we are going to jump to the next record and we are not going to print hello let's run the application and see if we can see Hello four times and as you can see we are saying hello four times so continue is a useful keyword for when you want to jump to the next record okay now that we have talked about V Loop let's also talk about another kind of Loops in Java the value of a in here is five if we change our condition to let's say a less than five we know that this condition is no longer true so we are not going to go inside the V Loop it means that we are not going to run the code inside the V Loop let's run the application we shouldn't see any hello printed into our console and as you can see we can't see any hello but in some cases you may want to go inside the V loop at least once no matter what the condition is for those situations you can use do wide Loops let me comment this V Loop and let's create a do V loop it's a lot like V Loops you need to type do inside the curly braces you need to put your code for example you can say system.out.print line and you can print hello after the curly brace you need to say V and inside the parenthesis you need to specify your condition for example you need to say a less than 5 after the parenthesis you need a semicolon of course in this case because because a is equal to 5 this condition in here is not true but even with that condition we should see this hello at least once because we are using two wi Loops let's run the application and let's see if we can see Hello as you can see we can see Hello only once so do vo Loops are useful for when you want to execute your code at least one no matter what the condition is we also have another kind of Loops in Java called for each Loops but I'm not going to talk about that in here because I think that if we know about different arrays and Collections and in regard to that if we know about objectoriented programming we will understand it much better so I'm going to talk about for each Loops after we have learned about all those stuff okay I think that's enough for Loops now we are going to have a quick challenge but before we have our challenge we need to know about two more things we need to know how to get the user's input and also we need to know how to generate a random number later on we will see that how these two are going to be useful in order to get the user's input you can use something called a scanner the syntax in here might not be familiar to you because we haven't talked about objectoriented programming but we are going to need that in our challenge because we want to have an interactive challenge if you don't understand the syntax just copy and paste the code that I'm writing in here in order to define a scanner you can type something like this you can say a scanner with capital S notice that it's coming from java.util package after that you need to name your scanner which I'm going to say scanner after that you can say is equal to new scanner once again with capital S inside the parenthesis you need to say system.in we have seen system.out which was useful for outputting something system.in is useful for when you want to get the users input now you have a scanner you can get a number number from user like this you can say int answer is equal to scanner do next int this one down in here by saying scanner. next int our scanner is going to wait for the user's input until the user enter some number we will see that in action in a minute but before that let's quickly output something for example let's say answer was plus the value of answer Also let's type something before our scanner let's say please enter a number let's run our application and let's see what these few lines of code are going to do you can see that we are saying please enter a number text and in here console is waiting for the user to enter a number for example I can save five by pressing enter you can see that answer was five and we have exited our application successfully so by using SC scanner you can get the user's input beside integers beside number you can also get a text from user if you want let's quickly see that as well first of all let's print something let's say enter your name after that I can say something like this I can say the string name is equal to scanner. next you can see that this next method is going to return a string don't worry about all of these new stuff method scanner CL classes object oriented programming we will talk about all of these later on but for now because we are going to need the user input we are going to figure out a way to receive that so by using scanner. next you are going to get the user's name and after that let's print something let's say hello plus the name of the user let's run our application once again in here first of all we need to enter a number let's add four after that scanner is waiting for my name let's say Mam and we can see Hello mam message so this way we can get the users input let's also see how we can generate a random number I'm going to comment these lines of code for now in order to generate a random number you can say something like this you can say random with capital r let's name it random is equal to new random and we don't need to provide anything inside the parenthesis after that in order to generate a random number we can say something like int number is equal to random do next int this method in here is going to generate a random number let's print that number let's say number plus the number let's run our application once again you can see that we have this random number it's also useful to specify a domain for your random number right now our random number is this weird negative number it might not be useful it's good to define a domain in order to Define that domain you can pass a number to this next int method for example if I put 20 in here and if I run my application once again the number should be somewhere between 0 and 19 if you want your random number to be somewhere between uh 1 to 20 you can simply add uh one in here we can say plus one let's run the application once again we can see nine this time this number in here is completely random it means that every time that we run our application we should see a different number you can see that we are generating different numbers okay now that we know how to get a random number and also how to get the users input it's time for our challenge here is our challenge we are going to create a game the concept behind this game is to generate a random number and ask the user to Guess that number continue asking the the user until you receive the correct number also to make everything more fun after five times of guessing wrong show a game over message to the user here is how our game is going to work first of all we are going to show a welcome message after that we are going to ask for the user's name and we are going to say hello to the user after that we are going to ask for the user's permission to start the game if we received a positive answer we are going to generate a random number and we are going to ask for the user's guess if the guess is correct we are going to show a congratulation message and quit the game if the guess is wrong we are going to ask again until we receive the correct number also as a hint to the user beside the first time every time that you are asking for a number tell the user to guess higher or lower for example if the random number is 10 if the user has guessed seven for the first time tell him to guess higher if if the user failed after five times show a game over message and quit the game this challenge in here is the combination of everything that we have learned so far so make sure to practice before watching the next video it's going to help you a lot okay go solve the challenge and after that come back to the next video so that uh you see my solution for this challenge see you in the next video I hope you solved the challenge but if not that's totally okay after all it's your first encounter with Java and it's the first application that you are writing in this video we are going to solve the challenge together let's start by creating a new project like before I'm going to select Java next once again next let's name this project guess me G let's create our project and inside our source folder let's create our package and Java file let's name this package or. make. guess me game new Java class let's name it main inside our main class let's type psvm and now we have our main method okay first of all we are going to show some welcome message to the user so let's say system.out.print line let's say welcome to Wonderland after that we are going to ask for the user's name so let's say please enter your name name or may I have your name after that we need to receive the user's name in which we need a scanner for that let's create our scanner let's say scanner is equal to new scanner system.in after that let's say string name is equal to scanner. next and let's say hello to the user let's say hello plus the name after that let's ask for the user's permission to start the game let's say shall we start in here I'm going to give the user two option and here are my two options let's say one yes and the other let's say no but in order to format my text a little bit better I'm going to add a special syntax in here in which you haven't seen so far by adding back SLT I'm adding a tab before this yes so this will be formatted with a tab let's add one in here as well nothing special just for formatting my text a little bit better after that I'm going to save the user's answer let's say int begin answer is equal to scanner. next int and after that I'm going to create a v Loop let's say V begin answer is not equal to one we are going to continue asking our question so let's uh copy this three line of code and paste them inside our V loop after that inside the V Loop we also need to store the new users's answer for that we can say begin answer is equal to scanner. next int this way we are not going to break out of this V Loop until the user's answer is one when it's one we have the permission to start the game after the loop it's time to generate a random number let's say random random is equal to new random after that let's say int X is equal to random. next int for the domain I'm going to say 20 because I want my number to be from 1 to 20 so I need to add a plus one in here after that it's time to ask the user to guess a number so let's say please guess a number and in here we need to save the user's answer let's say int user input is equal to scanner. next INT in here I'm going to Define three new variables and their usages will be clear in a minute let's quickly Define them first of all I'm going to save the times that user has tried the game so let's say int time TR is equal to Z initially after that let's define a Boolean let's say Boolean has bone initially it's false and after that a Boolean indicating if we should finish the game so let's say should finish once again it's going to be false initially after defining these three new variables I'm going to create another V Loop let's say v short finish is not equal to true then inside the V Loop first of all I'm going to increase the times that user has tried so let's say times tried Plus+ after that I'm going to create an if statement let's say if time TR is less than five then we have the permission to continue if it's more than five in the else case we need to break out of this V Loop for that I'm just going to say short finish is equal to true this is going to be the last line of our vo Loop so if we Loop once again because this condition is no longer me we are going to break out of the vo Loop but in case the times TR is less than five we are going to check that if the user's input is equal to the randomly generated number for that I can say if user input is equal to X then we need to change the value of hasb to true because user has won the game and also we need to break out of this vile Loop let's say short finish is equal to True let's add an else if Case to this if statement let's say else if let's say if users's input is greater than uh our X which is our randomly generated number we are going to tell the user to guess lower for that we can say uh guess lower and of course we need to wait for the new user input for that we can say user input is equal to scanner. next int we also need another case in here in case the number is uh less than x if that's the case we are going to tell the user to guess higher and also we are going to wait for the new user input let's say user input is equal to scanner. Next in we are done with this V Loop we will review what we are doing in here but after the void Loop we need another if statement we can say if the user has has won the game if that's true then we are going to show a message let's say congratulation and also let's say to the user in which try he or she has won the game let's say you have guessed in your plus time TR plus guess but in the else case first of all we are going to show a game over message let's say game over and after that we are going to say what was the number let's say the number was plus X this is our entire application let's review what we are doing in here first of all we are showing a welcome message to the user after that we are asking for the user's name we are creating a scanner and after that we are waiting for the user to enter his or her name after we received the name we are waiting for the user's permission to start the game we are saving the users input in here inside the V Loop we are making sure that we have the permission if we don't have the permission we are going to ask again and again until we have the permission after that we made sure that we have the permission we are creating our random number the random number is between 1 to 20 and after that we are asking the user to guess a number we are saving the user's input in here we have def find three new variables in here times TR has one and should finish next we are creating this V Loop it starts from here and ends in here the condition of this V Loop is while we shouldn't finish the game continue the loop first thing inside this V Loop we are increasing the time stri so if it's the first time because the time stri is initially zero we are changing that to one after that we are checking that if time stri is less than five we are comparing the user's input with the randomly generated number if that's equal to our random number we are changing the value of this has one to true and also we need to break out of this Loop so we are changing the value of this should finish to true but in case the user input is greater than our random number we are telling the user to guess lower and also we are waiting for the user's input but in case the user's input is less than our random number we are are telling the user to guess higher once again we are waiting for the user's input in case the time stri is greater than five we are just breaking out of the loop if that's the case the has one is still false so we are checking that in here if has one is equal to true it means that user has won the game so we are showing this congratulation message also we are showing that in which try the user has guessed the number correctly but in case if the user didn't want the game we are showing this game over message and also we are showing the random number let's run the game and see if everything is working fine we are seeing the welcome message after that it's asking for our name let's put mam we are seeing hello mam after that we are seeing the message for our permission shall we start or it was better to say Shall We Begin let's say to no once again we are seeing the message this this is our first V Loop also this format in here is because of that back SLT that I have used when I have created this text I'm talking about this one this back SLT In Here Also beside one and two if you enter any other number we should see this message once again so let's say three for example you can see that we are seeing the message okay let's say yes to continue the console is waiting for us to guess a number let's say 10 it says guess lower let's say five it seems like uh I have won the game in my second try okay let's run the game once again may I have your name let's say mesam yes let's begin let's guess another number it says that guess lower I'm going to guess higher in order to debug all the features of the game let's say 11 12 13 15 you can see that after five try uh I can see the game over message and I can see that the number was nine okay it seems like our application is working perfect just before I finish off this video let's change this message in here to Shall We Begin I think that's better okay this was our challenge I hope you solved it if you did do celebrate but if not that's okay later on in the course we are going to practice all of these many more times so that we make sure that we have learned everything everything that we see in the course okay I think that's a good point to stop the video in here just before I do that I'm going to say that in the next video we are going to talk about arrays in Java see you in the next video in this video we are going to talk about arrays in Java up until now if we wanted to store some simple data for example a number or maybe a text we could have used variables for example we could have said in a is equal to 5 but what if we want to store a list of different variables for example a list of names or a list of students for storing a list of variables we have multiple options in Java the first one that we are going to talk about in this video is called array let's see how we can have an array of for example strings for that we can say string after that we need a pair of square brackets after that we need the name of our array for example I can say students next I can say new string once again with a pair of square brackets this new keyword in here is simple English it means that we are defining a new array of strings inside this square bracket we can Define the size of our array for example if we want to store five different student names I can say five in here as simple as that now we have an array of size five after defining your array you can put some values into it for example I can say say students with an index of let's say one is equal to let's put my name in here Mesa this way we are assigning this value to the element in which has the index of one in our array there is a very important point in here and that indexes in Java start from zero so in here when I said students with an index of one it means that we are referring to the second element in our array if you want to assign some value to your first element in your array you can say students with an index of zero let's see that as well let's say is equal to for example Z we can keep doing this for all of our elements inside our array beside assigning values to your array elements you can also get the value of those elements as well for example in here we can say print the value of a student with an index of two you can guess it in this case it should Tom let's run the application and see if we can see Tom as you can see Tom has been printed this is one way of assigning different values to your array elements the other way is like this you can assign different values at the time of creating your array for example in here I can say a string array let's name it employees is equal to instead of saying new string array I can pass a pair of curly Brays and inside that Curly bra I can pass my value for example I can say mam or every other value that I want so these are the two ways of assigning values to your array elements like a string array you can also have other kind of arrays as well for example if I want to put some numbers inside an array I can say int with a pair of square brackets let's say numbers is equal to let's say a pair of curly braces and inside those curly braces I can pass my values let's say 1 2 through six when you are working with different arrays for Loops can be very helpful to access all of the elements inside your array for example if I want to print all of the values inside this numbers array I can say something like this I can create a for Loop let's say for in I is equal to zero I less than in this case the size of my numbers array is six so let's say six after that let's say i++ inside the for loop I can say print the value of numbers with an index of I this way I'm going to print all of the numbers inside my numbers array before running the application I'm going to comment this line of code so that we have a clean console as you can see numbers from 1 to six have been printed into our console so for Loops are very helpful when you're are working with different kind of arrays in here we have hardcoded this six but what if we don't know the size of our array for example if we get some values from our database or from our server in that case it might be possible that we don't know the size of our array how can we use for Loop fit arrays if we don't know the size of our array for that we can use a helpful property of different arrays for example in this case I can say numbers dot length this way we don't need to be worried about the size of our array we can just use it like this let's run the application once again and as before we have printed numbers from one 1 to six later on we will see that beside primitive data types and strings we can also have different kind of arrays for different objects for example for different classes in Java but more on that later on so using arrays is one way of having a list of different items but there are some limitations to arrays for example the size of our array after the definition is immutable let me show you what I'm talking about in here when we defined our students array we have set the size to be but what if we want to change the size of our array for example what if we want to define a Sixth Element for example if we say students with an index of five let's say Brian if you hover over this five you can see that array index is out of bounds it means that this element in here cannot fit in our array for example if we try to reach to that element you should see a problem let's say print the students with an index of five before that let's comment this line of quote and let's run our application as you can see we are getting an exception in here once again when we get exceptions it means that our application crashes and the exception type in here is array index out of bound exception it means that the six element does not exist in our array so arrays are immutable after you define them you cannot change their size this is one of the limitations of simple arrays in Java there are others as well for example you cannot do that much with your arrays later on when we use other kind of collections in Java we will see that we have all kind of operations uh on our array elements but I'm not going to talk about other kind of collections in here because I think that it's better to talk about them after we know about object oriented programming later on in the course we will talk about other kind of collections like uh array lists and Maps just before I finish finish off this video I'm going to write a simple application in which will help us to practice what we have learned about arrays before that let me comment all of these lines of quotes and let's start creating our application down in here in this application I'm going to simulate the contact application on the phone I'm going to show a list of different uh contacts names on a phone to the user and after that by typing the contacts name we are going to give the user that contacts number in order to simulate that first of all we are going to need a string array let's say string array names is equal to let's pass our names directly let's say Mesa after that we need a list of different numbers for that I'm going to create an integer array let's say numbers is equal to and let's initialize our array after that I'm going to show the name of all of the available contacts on the form so let's create a for Loop for INT I is equal to zero I less than names. length and i++ let's print the names inside our names array let's say print names with an index of I after the for Loop I'm going to ask the user to enter a name so let's say print let's say please enter a name after that we need our scanner so let's create that is equal to new scanner system.in after that let's get the contact's name let's say the string name is equal to scanner. next then I'm going to create a for Loop and inside that Loop I'm going to find the index of the contact so let's say for in I is equal to z i less than names. length i++ let's write an if statement in here let's say if name is equal to names with an index of I then inside this if statement we are going to print the contacts number for that I can say print numbers with an index of I but right now there is a problem with my code I'm not sure that if it's going to work fine or not and that's because of these two equal signs in here let's run the application and see if it's going to work let's enter a name in here let's say Sarah and as you can see nothing has been printed let's talk about these two equal signs in here if you hover over the warning in here it says that string values are compared using two equal signs not uh equal with a pair of parentheses the problem in here is that when you are using two equal signs you are checking for the equality of two strings by their reference I'm talking about their reference inside the devices memory RAM whenever you are storing a variable that variable allocates some space inside the device's memory RAM and that allocated space has some address and that allocated space has some reference in which we are comparing those two reference in here together so even if the value of two strings in here can be the same but the reference might not be for that reason it's not a good way to compare two strings bya using these two equal signs instead of using these two signs there is a better option for comparing two strings and that's the equals method let's see that as well in here I can say name do equals and inside the parenthesis I can pass the other string for example I can say names with an index of I if you remember from the previous videos I said that strings are not primitive data type and they are objects in Java and because they are objects we have some properties on our strings for example uh this equals method once again we are going to talk about method later on in the course when we talk about objectoriented programming but for now just know that there is a method called Equals in our string class in which we can use to check the equality of two strings by their values so now if we run our application we should uh get the s's number let's run the application in here once again let's say sah and as you can see we are getting the number let's also check that if you're getting the correct number Z is the second contact in our array and the second element in our numbers array is this number in which we have printed into our console it seems like our application is working fine okay I think that's enough talking about uh arrays in Java in the next video finally we are going to start talking about object oriented programming that's a very important topic and it's going to help you a lot to understand Java so make sure to don't miss the next two or three videos see you in the next [Music] video as I said at the end of the previous video in this video finally we are going to start talking about object oriented programming up until this point with the help of variables we could have defined simple data types for example if we wanted to have numbers we could have say int number is equal to 5 or similarly we could have defined characters texts and all sort of variables that we have talked about in previous videos but what if we want to have a more complex data for example how can we Define a car in Java or a phone or every other object that you can think of well that is possible with the concept of objectoriented programming in object-oriented programming you define your own objects the core component of objectoriented programming are classes right now you can see that we are inside a class this class is named main but but if we want we can create our own class as well let me quickly delete this line of code and let's create a new class for example inside my source folder inside my package on the package I can right click and by selecting new Java class I can create my class in here I need to name my class for example I can say phone notice that there is a convention you need to use upper cases for the first letter of the name of your class also you cannot have spaces or some strange characters as the name of your classes so in here I'm just going to Simply name my class phone notice that there are other options in here as well for example interface and Eno later on we will talk about them but for now let's just create a class the one that has the C Icon by pressing enter we can create our class this is how a class looks like it lives inside the package right now its package is or. make. oop section1 also if you take a look at uh the left pan in here you can see that a new class has been added into our package every class has the keyword class in its declaration also every class has a name and beside these two has an access modifier we will talk about access modifier in few minutes but for now let's continue on every class has a pair of curly braces in which we can put our code inside them a class is going to represent an object in this case we are going to repres represent a phone if you think of different objects objects can have different properties for example in the case of a phone a phone can have some amount of memory RAM it can have a screen size beside that it have a name and all sort of other properties that you can think of when you define a class you can have properties for your classes as well for example in this case if you want to give some properties to our phone class we can say something like this we can say a string name now we Define a property called name for our phone notice that I'm not initializing the property of my class in here I'm not giving a name to my phone and that's because when we declare a class we can reuse that class we can create multiple instance of that class with different properties for example if we Define a new iPhone the name would be iPhone if we Define another phone the name of that phone might be different so for that reason I'm not initializing the properties of my class let's add a few more properties to our phone object let's say int screen size beside that let's say int memory RAM after that let's say int camera so now that we have created this simple class we can instantiate it we know for sure that the starting point of our application is this main method inside our main class so if I need to instantiate my class I need to do it in here and here is how you can create an instant of your class you type the name of your class you can see that when I type the name of my class I'm getting some suggestions from intellig sometimes you may get multiple options and that's because different classes with different names can leave in different packages for that reason always take a look at the package that your object lives in in this case I'm going to just import this class after that you need to name your instance for example I can say iPhone next I can say is equal to new phone this way with the help of this new keyword we can create a new instance of our object now that we have created an instance of our class we can have access to the properties of our objects our class for example if we want to Define some property for our class we can say something like this we can say iPhone dot let's say name is equal to Let's name it iPhone 11 with the help of this dot operator you can have access to all of the properties or to be precise all of the fields of your class similar to assigning a value to your class's Properties or Fields you can also get those properties or fields and here is how you can get them for example if you want to print the name of our iPhone we can say something like this we can say print iphone. name if we run our application we should see iPhone 11 printed into our console and here is iPhone 11 similar to that you can have access to all of the fields of your class for example I can say iPhone do let's say memory RAM is equal to eight beside properties your classes can also have some behaviors for example in the case of a phone you can play some music with your phone or you can call somebody if you want to Define some behavior for your class you can use methods let's see them as well let's switch back to our phone class here is how you can define a method I'm going to write the syntax and after that we will talk about it first of all our method has a name in this case its name is play music after that a method can have an access modifier like we did for the Declaration of our class we will talk about this public in a minute after that every method can have some inputs for example in this case we are getting a string called track name later on when we use this method we need to pass some input to this method if you don't want to have any inputs for your method you can just uh pass a pair of empty parentheses but if you want you can have one or more inputs if you want to have multiple inputs for your method you can separate those inputs with a comma for example in here I can say a string uh album name but I'm not going to do that in here but you can have as many inputs as you want beside a name an input and also an access modifier every method can return something in this case it's void but if you want you can change it for example you can say a string as the return type of your method you can also have integers or other kind of primitive data types even you can return another class with your method but more on that later on if you don't want to return anything from your method you can use the keyword void like we did before we will talk more about the return type of every method later on but for now we are not going to return anything from this method so we are going to pass vo inside the curly braces of My Method I can put my code for example in this case I'm going to play some music or at least I'm I'm going to print something in this case I'm just going to say PL plus the track name now that I have created this method I can use it in my main class where I have instantiated my object for example in here I can say iPhone doplay music once again you can see that by typing dot I can have access to my methods as well right now I'm I'm getting a red error in here and that's because when I have created My Method I have set an input for it so when I'm going to use my method I need to pass a track name for example let's say our wings are burning the name of a track let's run the application and see what could happen you can see that we are playing some music so by defining methods you can have behaviors for your classes there are few reasons for using methods the first one is that you can reuse your method for example in here after this line of code I can say iphone. playay music and I can pass a different track name let's pass lamenting Cas this time if we run our application you can see that our methods are being executed one at a time so the first benefit of using methods is that you can reuse them the next one is uh for organizing our code for example imagine that you want to have some sort of calculation you can pass uh all the codes for that calculation into a method and by calling that method you can pass all of those calculations to a method and later on uh you can just call that method in order to do the calculation it's going to help us a lot for organizing our code also by using methods you can encapsulate things we will talk about encapsulation in later videos but in here inside your class you can Define your methods as private and that method will be accessible only from your class and not from outside of your class if you go back to main class you can see that we are getting red warning if you hover over the error it says that uh this method has private access so by using private methods you can encapsulate different behaviors for your own class okay now let's talk about this access modifier you can have access modifiers for your methods for your classes and also for the fields of your classes I can make this name private if I want as well basically we have three kind of access modifiers we have private we have public and also we have protected if you don't use anything as the access modifier uh it's equal to when you use public so there is no difference between public a string name or just a string name when you use public as the access modifier for example if I use public in here it means that this field is going to be accessible from other classes as well but if I use private in here let's say private if I go back to my main class you can see that we are getting a red warning it means that we can no longer use this property so by setting the access modifier of our field or method that field or method is only accessible from inside our class beside public and private we also have protected we will talk about protected later on in the course but private and public are the most access modifiers that we are going to use in the course for the access modifier of your class you can also have private let me quickly type that but usually you wouldn't do that right now you can see that we are getting a red warning in here and the warning says that modifier private not allowed in here you use private mostly when you use inner classes we will talk about inner classes later on in future videos but basically they are some nested classes inside other classes when you define them as private classes you can have access to those nested classes from the parent class we will talk about that later on when we talk about inner classes for now let's just change this one to public there are few reasons for using private as the access modifier of your fields or methods the first one is that you may want to limit the access of your fields or methods to the class itself and not other classes for example imagine that you are writing some code that you are going to publish for other Developers in that case you may want to protect your classes against changes for that reason you may want to change the access modifiers of your fields and also methods to private but now that we have defined the access modifier of this field as private how can we have access to this name from outside of this class there is a way to that let's quickly talk about it we can create public methods for example down in here I can say public as the return type of this method I'm going to say void for the name of this method I'm going to say set name as you can see when I use the keyword set I am getting some suggestions from intellig basically there is a convention among programmers to set the name of their Setter methods like this and intellig is smart enough to know the convention but of course you can name them whatever you want in this case I'm going to follow the convention so I'm going to say set name inside the parenthesis as the input of this method I'm going to say string let's say name inside this method I'm going to change the value of this name to whatever the name that I'm going to receive via this method for that I can say this do name is equal to name the keyword this is referring to the current object that we are in for example right now we are inside our phone object our phone class so by using this. name we are accessing the property of this class called name the second name in here is the input of our method so we are setting the value of this name to whatever we receive uh via the input of this method now because the access modifier of this method is public we can use it inside other classes for example from inside the main class if we want to set the name of our iPhone we can say something like this before that let's delete this line of code we can say iPhone dot let's say set name inside the parentheses of this method I need to pass the name of my phone let's say iPhone 11 so this way I don't have access to the field directly but uh by using the method I can change the value of that field but what if we want to get the value of this field well we can write another method and here is how we can create that method we can say public as the return type of this method I'm not going to say void because I'm going to return this name so I'm going to say a string once again there is a convention in here we can say get name we don't need anything as the input inside this method we are going to return something and here is how you can return something from a method you type return after that whatever you are going to return in this case I'm going to return this name so I'm going to say this do name once again this refers to the current object this. names means the name inside our phone object now that we have created this method inside our main class instead of saying iphone. name I can say something like this I can say iphone. getet name if we run our application once again we should see the name of our phone let's run the application you can see that iPhone 11 has been printed beside creating these kind of methods ourselves we have another option if we come down in here we can use the help of our ID we can right click in here we can go to this generate method similarly we can press alt plus insert you can see that in here we have a list of options we have getter we have set and also we have getter and Setter if we want to create gets and sets we can select that after that we can create the field that we want to create Getters and Setters for for example if we select uh camera and press okay you can see that IDE has created some codes for us you can see that these methods are almost identical to the methods that we created above in here because creating gets and Setter methods are very usual IDE can help us with the creating of them but why are we using gets and Setters well there are few reasons for that the first reason is encapsulation let's quickly talk about that a bit for example if we don't want to give others uh the permission to change the value of our fields we can delete the Setters in that case we only give them the permission to get the value of objects but not set the value of objects or vice versa we can create Setter methods for our class in that case we can set the value of our properties from other classes but we cannot get the value of those properties the first reason is encapsulation the other reason is that sometimes in your Setter and getter methods you may want to do some other operations as well for example if you are setting a name for your phone you may want to validate that name before setting it in that case you can have some validation before assigning the value to your property okay that's enough talking about Getters and Setters let's quickly change the access modifiers of all of these two private and let's create Getters and Setters for the ones that we didn't create any down in here after everything I'm going to press alt plus insert let's say gets and Setters and let's select both of them you can see that intellig has created these codes for us but because we have changed the access modifier of this memory RAM to private now we have an error inside our main class in here instead of saying iphone. memory RAM is equal to 8 I can say something like this I can say iphone. set memory RAM and I can pass eight what we did in here is one way of instantiating our object we have defined our object after that we have set different values for our object there is another way of instantiating your objects let's quickly see that as well so if I switch back to my phone class above the play music method I can create something called Constructor let's use the help of IDE for creating that Constructor once again I'm going to go to generate menu the first item in here is Constructor in here I'm going to select all of the fields and I'm going to press okay and as you can see this code has been generated for us this is called a Constructor in objectoriented programming our Constructor needs to have public as its access modifier it cannot be private after that the return type of this Constructor is a phone the exact item that we are in our Constructor does not have any name and as the input of this Constructor we are receiving all of the fields of our class we are receiving name screen size memory RAM and Camera inside our Constructor we are assigning different values that we have get via the input to the fields of our class now that we have created a Constructor if we switch back to our main class you can see that we are getting a red warning in here the warning says that expected four arguments but found zero it means that now that we have created The Constructor we need to pass the values directly to the parenthesis of this new phone and here is how you can pass them the first one was the name of our phone let's say iPhone 11 I don't remember the order of things but the next one was screen size let's say five I believe the next one was memory RAM let's say eight and the other one was camera let's say eight as well now that we have instantiated our object like this we don't need to directly set the fields of our class we can safely delete this also let's delete this as well in this line we are printing the name of our iPhone let's run the application and see if we can print the name correctly as you can see iPhone 11 has been printed so when you are using Constructors you need to pass the values of different properties at the time of instantiating your objects your class can have multiple Constructors as well for example if I come down in here and once again right click and go to the generate menu if I select Constructor this time I can select different items for example in this case I'm going to select only name and memory R if I press okay you can see that we have another Constructor which will only receive name and memory run but if you hover over this phone you can see that this Constructor is never used if we switch back to our main class we can create another phone and we can use the second Constructor let's quickly do that I'm going to do that after this two line of code let's say phone and this is the beauty of object oriented programming when you create a class you can reuse that class as many times as you want for example in here I'm going to Define an entirely new phone let's name this phone pixel let's say is equal to new phone this time I'm going to use the second Constructor for the name I'm going to say pixel 3 and for the memory RAM I'm going to say 16 you can see that the ID is happy with this way of defining a new phone now we have two different instances of our phone class having two different kind of Constructors for a class is called polymorphism in Java polymorphism has other types as well we will talk about it later on okay I think that's a good point to stop the video in here in the next video we are going to continue our talk about objectoriented programming there are many more things left that we need to talk about see you in the next video in the previous video we have talked briefly about classes what those are how can we create them and also what are the most usages of a class in this video we are going to talk talk about some important Concepts regarding to objectoriented programming the first of those Concepts is inheritance I'm going to talk about inheritance with an example because I think that would make everything easier to understand first of all I'm going to create a class called dog for this dog class I'm going to Define some properties for example I'm going to define a name let's say private string name after that I'm going to Define a color let's say private string color let's also Define the number of legs let's say private int legs and also I'm going to define a Boolean indicating that if a dog has a tail or not so let's say private Boolean let's name it has tail let's also create a Constructor for our dog class by pressing alt plus insert you can see the dialogue in here let's say select all of the fields let's also create some Getters and Setters for our dog class as well once again by pressing alt plus insert by selecting this getter and Setter you can create Getters and Setters let's also Define a method for our dog class as well I'm going to say public void let's name this method eat I'm going to indicate the eating behavior of a dog as the input of this method I'm going to receive a foood so let's say a string food and inside this method I'm just going to print something let's say eating plus our food okay nothing special is in this class first of all we have created these four Fields after that we have created The Constructor we have created our Getters and Setters and we have created this e method I will talk about why I'm doing all of this let's also create another class called bird let's say bird for this bird class class let's also have a name Also let's have a color let's define two more Fields one for the number of legs private int legs and also another one indicating that if our bird has a tail or not so let's say private Boolean let's say has tail for this bird class let's also create a Constructor and some Getters and Setters I'm going to create my e method for this bird class as well let's say public void eat let's get the name of our food and inside this method let's print something let's say eating that food you probably can see the pattern in here there are a lot of similarities between our bird and dog class both of those classes have four Fields they have a Constructor they have all of these Getters and Setters and both of them have this eat method in program in this is not efficient you basically are copy and pasting yourself instead of defining our bird and dog class like this we are going to use another Concept in object oriented programming called inheritance for that first of all I'm going to create an animal class and after that I will extend the animal class to this bird and dog let's see how we can do that inside my package I'm going to create my animal class let's say animal first of all let's add some Fields I'm going to use the four previous Fields let's also copy them from here and after that let's create a Constructor and Getters and Setters and our eat method don't worry we will reduce the amount of copy and pasting in a minute let's say public void eat string food as the input and let's print the name of our food now that we have created this animal class creating bird and dog class is going to be much simpler for that I'm going to delete all of the codes inside this bird class let's delete all of them this time instead of defining all of the fields and Constructors and methods I'm going to say extend animal this way we are saying that our bird is an animal we are extending the animal class and later on if we want we can customize our bird class as well but right now you can see that we are getting a red varning and the warning in here says that there is no default Constructor available in this package basically it says that you need a Constructor let's press alt plus insert in here and let's select Constructor and as you can see the ID has generated this Constructor you can also see that even though we don't have any fields in our bird class we are receiving some arguments in the Constructor but this Constructor has rather a strange syntax we haven't seen this super keyword so far basically this super keyword means that do whatever you are doing with these parameters in the parent class in this case our parent class is animal so this super is passing all of these arguments to the Constructor of our animal class it means that it's setting all of the values to the fields of our animal now that I have created my bird class like this if I want to instantiate it for example inside the main class I can do as before let's say bird let's name it Enix let's say is equal to new bird and as you can see the Constructor is waiting for our arguments first of all we need a name let's pass Nino we need a color let's say golden after that we need the number of legs which I'm going to pass through and a Boolean indicating if our bird has a tail or not let's pass through once again remember that in our bird class we didn't have any extra methods but in my main class if I want I can use some of the ga methods of our parent class in this case animal for example if I want to get the name of my bird I can say something like this I can say phoenix. getet name you can see that we have all of the getter methods let's run the application and let's see if we can uh print the name of our bird you can see that the name has been printed successfully beside getter and Setter methods you can also have access to all of the other methods that you have created for example if you remember inside the animal class we have created uh this eat method let's see if we can use it in our bird instance for example in here if I say phoenix. it I don't know what Phoenix is it but let's just pass meet and let's run our application and let's see if we can successfully execute the eat method and as you can see in here Nina is eating meat now that you have created your bird class you can also change the dog class as well for example in here I'm going to delete all of these codes once again instead I'm going to extend the animal class once again let's say extends animal you can see the red warning and that's because we need a Constructor you can see that the amount of similar codes that you were copy and pasting is a lot less right now the bird and dog class are basically the same but we know for sure that a dog and a bird are not the same they may have other fields and also other behaviors as well if you want you can customize your child classes as well for example inside my birth class I want to add another field I'm going to say private let's say int Wings you know that dogs do not have wings in here I'm going to delete this Constructor and I'm going to create it once again because I'm going to use the help of my IDE let's press alt plus insert in here I'm going to select wings and this time as you can see the Constructor has been changed a little bit the super statement is as the same it means that do whatever you are doing with all of these uh four Fields but because inside our parent class inside the animal class we do not have a wings field this Wings hasn't been passed to this super statement so we are setting the value of wings directly inside the Constructor of this bird class this way we can customize our child classes right now the dog does not have any uh wings field but our bird does but right now if I switch back to my main class I should get a warning and the warning in here says that you need to pass a win let's also pass that in here as well for example I'm going to say two we can also create getter and Setter methods for these wings as well for example inside our bird class down in here let's press alt plus insert and let's select getter and Setters now that we have created the Getters and Setters let's see if we can print the number of wings for example down in here I'm going to say phoenix. getet WIS let's run the application and you can see that two has been printed as the number of wings beside getter and Setter methods you can also have other methods inside your child class as well for example inside this bird class if I want I can define a fly method as well let's quickly see that let's say public void fly I'm not going to receive anything as the input let's just pring something let's say this do get name also if you remember from the previous video I said that this keyword refers to the current object that you are in in this case inside the bird class we don't have any get name method but because we are extending the animal class we can use this. get name let's say is flying so beside using Fields you can also customize your child classes with different methods let's see if we can call this method from inside our main class let's say phoenix. flly as you can see Nina is flying also beside defining new methods inside your child class you can also change the behavior of methods of your parent class for example if you remember inside the animal class we had this eat method I'm talking about this one which inside this method we are saying eating food inside our bird class if we want we can change that for example right in here I'm going to press r+ o you can see that we are seeing a list of different methods I'm going to overwrite this e method so by overwriting you are going to say that I'm going to change the behavior of this eat method from what is happening inside the parent class once again we are seeing this super keyword it means that do whatever you are doing with this parameter inside the parent class if you want you can delete this super statement completely but let it be for now we will delete that later on after after this super keyword I'm going to print another statement in here let's just say eating finished so this way we have changed the eat method inside our child class from what it was inside the animal class right now inside our main class we have executed this line of code phoenix. let's comment the lines after that so that we can see uh what's going to be the behavior of this eat method let's run the application you can see that we are saying eating meat and after that eating finished if you want to completely change the behavior of your method inside the child class you can simply delete this super. eat method for example in here I'm going to say chewing food instead of eating food so in both child and parent class we have this eat method but their behavior is different let's run the application and see if we can see the difference we can see that we are chewing meat so what we did so far is called inheritance in object oriented programming we have inherited the bird class from the animal class you can also continue this inheritance multiple times for example if you want you can inherit the dog object let's quickly create another class in here for example let's say shefer now in here I can say extends the dog class you can see that once again we are getting this red warning let's create our Constructor in order to overcome that uh problem you can see that even though inside the do field we do not have any field but inside our shepher class in the Constructor we need all of those arguments because the parent of this shepher class which is dog is the child of another class which is animal so you can do this inheritance as many times as you want you can also create another class and extend the shepher class but I don't think that mean anything in here I just wanted to say that you have that option okay I think that's enough talking about inheritance the other concept that I'm going to talk about is called polymorphism we have talked a bit about polymorphism in the previous video but uh let's talk more about it in here so in previous video I said that one kind of polymorphism is that for a class to have multiple Constructors for example inside our animal class if we had another Constructor in here which will accept different number of fields for example the first three now that we have two Constructor this is one kind of polymer orphism now we can create this animal class in two different ways basically polymorphism means having multiple forms but there are two more kind of polymorphism but before we talk about that let's uh delete this Constructor I'm not sure that if we are going to need that the other kind of polymorphism that we have used so far is about this eat method so inside this animal class we had this eat method but also we had it inside the child class which is bird but these two eat methods have different forms it means that we are doing different things inside each one of these methods this is another kind of polymorphism two methods inside a parent and a child class that are doing the same job differently we also have another kind of polymorphism and that's uh with the methods themselves we don't have this fly method inside our animal class but in here we can also have another method called flyy as well let's quickly see how we can create another method called fly I'm going to say public void fly but this time inside the parenthesis I'm going to receive some arguments for example I'm going to receive the speed as you can see the compiler is happy with this way of defining two different methods with the same name now if I switch back to my main class you can see that we are not getting an error but before that I think I should uncommon this line of code even though we are not getting err warning this in here it means that we are using the first fly method let me close all of the unnecessary classes inside the birth class we are using the first method but if you want to use the second method we just need to pass some arguments in here for example let's pass 100 we can have methods with the same name when we have different number of arguments or alternatively when we have different kind of arguments for example in this case we are uh passing integer but if we had another method for example uh in which we pass a string that method can have the fly name as well let's see that quickly let's say public void fly and inside the parenthesis I don't know let's pass a string let's just say name you can see that uh the compiler is happy with this way of defining a method with the same name so beside the difference in the number of parameters the kind of parameter is also important this in here is also called polymorphism using methods with the same name in different ways okay let's delete these two I don't think we are going to need them and I think it's a good point to stop the video in here in the next video first thing we are going to start talking about composition in objectoriented programming see you in the next video in the previous video we have talked about inheritance and polymorphism in this video we are going to talk about composition in objectoriented programming in previous videos I said that classes are useful for when you want to Define your customized data type for example imagine that you are going to create a car in that car you have multiple systems for example you have a system for a stereotype your car also may have some engine it can also have a fuel system if you want to simulate a car in programming you can create different classes for example for engine for a stereo system and also for fuel system and after that inside your car class you can compose all of those classes to have a car let's see how we can use composition in Java in my package I'm going to create a class called engine for this engine I'm going to have two Fields first of all I'm going to define a model so let's say private string model and after that let's have an integer private int I'm going to name this integer RPM RPM stands for round per minute it's just a property of different engines I'm going to keep it really simple so I think these two would be enough after that let's quickly create our Constructor and Getters and Setters let's create a car class and let's see how we can use this engine inside that let's say new Java class let's name it car for this car class I'm going to Define four Fields first of all let's pass a name private string name after that let's have an integer for the number of doors after that let's define the color of our car private string color and after that I'm going to include or compose an engine in here for that I can simply say private Engine with capital E and in here you can see that in my package I have an engine class I can import that into this class let's name it engine for the sake of Simplicity I have composed only one class inside this class but if you want you can create another class for for a stereo system and fuel system and everything else that you want but I think you would get my point if I use only one class after that like other classes I can create my Constructor you can see that this engine has been passed to our Constructor the same way that we have passed other data types like integers and strings we can also have Getters and Setters the same way that we had for uh previous classes now that we have created this card we can instantiate it for example inside our main class for example if I want to have a car object in here I can say car let's name it Mercedes is equal to new car as you can see the Constructor in here requires four Fields a name doors color and also an engine for the name I'm going to pass Mercedes AMG for the number of doors let's pass two for the color let's say silver but what should we pass as the engine in here well we can pass our engine in two ways first of all we can create our engine before this car class for example in here I can say engine let's name it engine is equal to new engine and I can pass a model and RPM for this engine to instantiate it for example I'm going to say reenal for the RPM let's say um 8,000 after creating our engine object we can pass it to the Constructor of our car for example in here I can say engine and like that we can create our car but the other way is to pass your engine directly to the Constructor of your car for example I can say new engine in here and I can instantiate my engine object directly inside the Constructor let's say rot and let's pass 8,000 now that we have passed it directly we don't need the first line of course we know that Mercedes wouldn't use renal engine but I think it doesn't matter in here now that we have instantiated our our car object we can have access to all of the fields like we did before for example if you want to print the name of our car we can say something like this we can say Mercedes do name or do get name to be precise but what if we want to get the model of the engine of this car well for that we can say something like this let's print engine model plus we can say Mercedes dot get engine this method in here after that we can once again say dot get model so this get engine method will return an engine object in which we can perform another dot operator on that let's run the application and see what would be the result first of all you can see the name of our car and after that you can see the engine model which is Renown also instead of using the methods of your engine you can uh get the engine object directly for example in here before the print statement I'm going to say engine let's name it engine is equal to let's say mercedes. get engine you can see the return type in here but whenever you are not sure about the return type you can press down the control key and by hover overing your method you can see the return type you can see the Declaration of your method which says public engine get engine it means that this method is going to return an engine object now that you have your instance of engine you can perform all kind of operations on that instead of pressing down the control key and hover over your method there is another option to get the return type and for that matter the Declaration of your method and here is how you can do that you can click on the name of your method and you can press down the control Q this way you can see some information about the Declaration of your method these kind of documentations are especially useful for when you are using a third party library or some built-in methods for example if we click on this print line method and press control Q you can see that the documentation is giving us much more information for example in this case it says that uh this method is printing a string and then terminate the line you can see some information about the method itself also if you want you can have this kind of information on the methods that you yourself create for example on this get engine method if we switch to our car class we can create some sort of documentation let's find that method and here is how you can do that you need to add a comment in here in previous videos we have seen how to create a new comment by using two slashes we could have uh create our comment but these kind of comments are not useful in here instead we can use a single slash and after that we can have two stars by pressing an enter you can see that uh we have these sort of comments as well these kind of comments are useful for when you have multiple lines and in here you can have some sort sort of information in which later on will be shown when you press control Q on the name of your method for example in here let's say uh Returns the engine of our car now that we have provided this information in here if we switch back to our main class on the Declaration of our method on the name if we press control+ Q you can see that in here we can see that information sometimes this kind of commenting can be useful as well but there are more to this this kind of commenting for example we can provide some links but more on that later on in future videos so this way of using different classes inside other classes is called composition in objectoriented programming once again if you have created some other classes for example a stereo system class and also a fuel system class you could have add them one by one in here as well but for the sake of Simplicity I've just included this engine this way we can compose different objects inside one class okay I think that's enough talking about composition let's talk about a keyboard in Java called null before that let's close this car class and let's comment all of these lines of codes there are sometimes that you don't want to instantiate your objects immediately for example down in here I can say car Mercedes is equal to I don't want to instantiate my car object in here like we did before instead I want to postpone that to few lines after this for that you can pass null values for your objects let's see null in here as well this null keyword in Java means nothing it means that this car Mercedes is nothing when the value of an object is null you cannot perform any kind of operation on that for example in here I cannot say Mercedes do get name for example we are not getting a compile time error it means that our application is is going to be created but if you take a look at the Highlight in here it says that this method is going to produce null pointer exception if you remember from previous videos I said that whenever null pointer exception happens your application is going to crash so the error in here is going to be a run time error and not a compile time error let's run our application and let's see what would happen you can see that in here we are getting a red warning in our console says java. l. null pointer exception in general we should always avoid exceptions in our application later on we will talk about how can we do that but for now let's just assume that we know whenever an object is null we cannot perform any operation on that for example we cannot use the methods inside that object so whenever you are not sure about null values for example whenever you are retrieving some data from a web server or from your local database first of all you need to check that if your object is null or not and here is how you can do that for example you can create an if statement before this mercedes. getet name I can say if let's say Mercedes is not equal to null I'm going to put an if statement in here in case our object is not null we are going to call this method but in the else case I'm going to print something let's say the car was n let's run the application once again this time you can see that we are not seeing the exception which is good but right now we are not doing anything helpful uh with our value being null we are just printing something sometimes this is the desired Behavior but sometimes you may want to check that what was the cause of your object to be n so null means nothing in Java okay let's comment all of these and let's talk about another keyword in Java called final so up to this point when we wanted to instantiate our object or variable we could have said something like this we could have said int a is equal to 5 for example later on we could have changed this a for example we could have said a is equal to 5 + 1 or a + 1 this way we could have changed the value of our variable but there are sometimes that you need to be sure that the value of your variable wouldn't change in those cases you can use the final keyword and here is how you can do that before the type of your variable you you can say final final in a is equal to 5 now if I try to change the value of my variable for example like before if I say a is equal to a + 1 you can see that we are getting a warning in here the warning says that cannot assign a value to a final variable so whenever you are declaring your variables and classes as final you cannot change the value of that variable or class let's also check the case when we Define our classes as final I'm going to comment these two line of code and down in here I'm going to say final let's say engine let's name it engine is equal to new engine let's pass a model and a RPM now if I try to change the value of this engine for example if I say engine is equal to new engine with other parameters for example let's change the RPM let's say 7,000 once again you can see the error the error says that cannot assign a value to final variable but there is a point in here when you declare your objects as final you cannot change the whole instance of that object but you can change the properties of your object for example in here if you remember inside our engine class we had two Setter methods which with the help of them we could have changed the value of two properties for example if you wanted to change the RPM we could have said something like engine do set RPM to let's say 10,000 you can see that even though we declared our engine as final we can change its properties we just cannot change the whole instance we can change its properties using final keywords can be useful from time to time okay I think that's enough for this video in the next video we are going to have a quick challenge to make sure that we have understand the concepts of objectoriented programming see you in the next video this is our challenge imagine that you are a doctor and you want to check on your patient in this application first of all you are showing the name and age of the user to the doctor and after that you can see a list of different organs in which the doctor can select the first organ is left OE let's select that in here you can see that we are seeing some details about the organ for example the name the medical condition and also the color of the eye after that we gave the doctor the option to close the eye and also if the eye is closed we are going to open that let's select one in here to close the eye you can see that left eye closed once again we are seeing the list of our organs let's select two in this case this time if I don't want to close or open the eye I can put any number beside one for example if I put two in here you can see that once again we are seeing the list of of different organs let's select three to see the heart once again you can see that we are seeing some details about the heart after that we have the ability to change the heart rate in a normal doctor patient situation this wouldn't be the available option but in here we just want to demonstrate some behavior for our heart organ so if we select one in here the scanner is asking for our new heart rate which I can put 75 and you can see that heart rate changed to 75 let's select a stomach once again you can see the details of the stomach we have one behavior in here which is digest if we select that you can see that digesting has be once again this is a hypothetical situation and in a normal situation you cannot order the patient to digest the food let's also select five in here to see the scheme this this time for the skin you can see that we are not seeing any Behavior instead we are just seeing some uh details after that once again we have our list in which if we put six or for that matter any other number we will close the application let's put six in here and as you can see application has been exited successfully by solving this challenge I want you to practice the object oriented programming Concepts that we have talked about in the past three videos so make sure to use them okay pause the video in here and go solve the challenge after that come back to the video and let's see my solution for the challenge as well here is my solution for the challenge first of all I'm going to create a package inside my source folder let's name it or. make. challenge inside this package I'm going to create my organ class inside this organ class I'm going to have two Fields let's say private string name and also private string medical condition I'm going to keep it simple so I think these two would be fine after that let's create a Constructor and after that let's create all of the Getters and Setters I'm not sure that we are going to use all of these Getters and setters later on if we didn't use them we just simply delete them beside these I'm going to have another method inside this class named get details let's see that as well let's say public void get details and let's print some details about this organ first of all let's say name plus this.get name after that let's print a medical condition of this organ as well medical condition plus this. get medical condition that's all we need inside this organ class let's quickly create our organs one by one first of all I'm going to create an organ called I let's say I inside this I class I'm going to have a string called color and after that let's have a Boolean indicating if the ey is open or not so let's say private Boolean is opened after that it's time to extend the organ class let's say extend organ in here we are using inheritance now it's the time to create our Constructor let's select both of these two fields and after that let's create all of the getters and Setters once again I'm not sure that we are going to use all of these Getters and Setters later on if we didn't use them we just simply delete them okay let's overwrite the get details method I can do that by pressing control+ o by selecting get details method now we can change this method for example in this case let's also print the color of the eye let's say color plus this.get color inside this I class I'm going to have two other methods as well let's see them let's say public void [Music] open inside this open method I'm going to change the value of this Boolean to true so let's say this dot set open and let's pass true after that let's print something indicating the I has been opened let's say this do get name you can see that we don't have any get name method inside this class we are using the get name from the parent class which is organ let's say plus opened let's have another method called close I'm going to say public void close once again first of all I'm going to change the value of the Boolean to false let's say this do set open and let's pass false after that let's print something let's say this. get name plus closed that's all we need inside this ey class let's quickly create another class for the heart let's say heart for this hard class I'm going to add another field called rate let's say private int rate it's time to extend the organ class extends organ and after that we need to create our Constructor after that we need to create our Getters and Setters I'm pressing alt plus insert to get that dialogue in case that's confusing for you after that it's time to overwrite the get details method by pressing control+ o and by selecting get details method we have that in here I'm just going to print the heart rate let's say heart rate plus this. get heart rate or get rate that's all we need to do inside this heart class let's quickly create a stomach class let's say stomach inside this stomach class I'm going to have a Boolean let's say private Boolean is empty indicating if the stomach is empty or not after that it's time to extend the organ class ex organ and after that we need to create our Constructor let's create our Getters and Setters and after that let's overwrite the get details method inside this get details method first of all I'm going to check that if the stomach is empty or not so let's say if this dot is empty I'm going to use the method in here if the stomach is empty I'm going to print something I'm going to say need to be fed but in the else case let's just print the stomach is full let's also create another method for this class called digest let's say public void digest let's just print something let's say digesting begin okay we are done with our stomach class let's quickly create the skin class as well for this skin class I'm going to Define two more Fields first of all I'm going to define a string for the color of the skin after that I'm going to Define an integer for the softness of the skin let's say private int softness this integer is going to be some number from uh 0 to 100 indicating the softness of the skin after that it's time to EXT stand the organ class and after that we need to create our Constructor next we need to create our Getters and Setters and after that let's overwrite the get details method inside this method let's also print a skin color let's say skin color plus this do get color that's all of our organs now we can create our PTI patient class inside my package let's create a patient class for this patient first of all I'm going to have a string for its name after that we are going to have an integer for the age of the patient after that we can create our organs for example I'm going to say private I let's say left I let's do the same for the right eye let's also have a part after that may be a stomach and a skin okay that's all of our fields for the patient let's create the Constructor and let's create all of the Getters and Setters we don't need any special method inside this patient class inside our main class which we need to create we can instantiated let's create our main class first of all in here we are going to create our main method after that we can create our patient object but before that let's minimize this project pain let's say patient let's name it patient is equal to new patient first of all we need a name in here let's say Brad after that we need the age let's say 28 after that we need the left ey which I can say new I for this I first of all we need a name let's say left I after that we need the medical condition which I'm going to say uh shortsighted for the color let's say blue for the is open Boolean let's say true we need the same thing for the right eye new eye let's just change the name to right ey Also let's let's change the medical condition to normal after that we need a heart let's say new heart for the medical condition let's say normal and for the rate of the heart let's just say 65 uh I think the next organ was a stomach so let's say new stomach the name would be stomach the medical condition I'm just going to enter a name of some medical condition I'm going to say PUD public uler disease in case if you are wondering and for the is empty let's say false after that we need a skin let's say new skin for the color of the skin or first of all we need the name let's say skin for the medical condition let's say burnt uh after that what do we need we need a color and also softness for for the color let's say white for the softness let's say 40 out of 100 okay that's our patient object now we need to create the logic for our application first of all I'm going to print the name and age of the patient so let's say print name plus patient. getet name after that do the same thing for the age we are going to receive the user's input so we need the scanner let's say a scanner scanner is equal to new scanner let's pass system.in also know that we know about objectoriented programming we know how this scanner is working this is just a class with this new keyword we are instantiating it inside the Constructor of this scanner we need this system.in whatever that is so this way we have created an instance of this scanner after that I'm going to define a Boolean let's say Boolean let's name it short finish and initially I'm going to set it to false later on we will see that how this one is going to be useful after that I'm going to create a v Loop let's say V should finish is not equal to True continue looping inside the V Loop I'm going to show a list of different organs for that I can say choose an organ in here I have two options I can use these system.out.print lines line after line or the better option is to use back sln let's see that as well first of all let's go to the next line in order to have a cleaner code in here I can say back sln this back sln moves the cursor to the next line the other one that I'm going to use in here is called back SLT this back SLT will add a tab to to our text later on we will see exactly what these two are doing okay the first organ is Left Eye the next one is right eye after showing this list to the user I'm going to receive the user's input so I'm going to say int choice is equal to scanner. next int we have seen this in previous videos so I'm not going to explain in here we are just going to receive the users input after that depending on this Choice I'm going to create a switch statement let's say switch on choice and let's create our different cases in case the user's choice is one first of all we are going to print the details about the left eye so let's say patient. getet left eye. get details next I'm going to give the user the option to open or close the eye for that I need to check that if the eye is opened or closed so let's say if patient. getet left ey dot is opened we need to close it or at least we need to give the option to close the eye let's print something in here let's say back SLT back SLT in order to have two tabs after that let's say uh close or close the ey next we need to get the users input in case if it's one we are going to close the ey so let's say if scanner. next int is equal to one then we need to say patient. get left ey do uh close eye or close but in the else case we are just going to continue to the next record in the else case of the first if statement this funing here in case the I is not opened we are going to show the option to open the I so let's say else we need the same logic we can print something back SLT back slt1 open the I next we need to get the users's input let's say if scanner. next int is equal to one we are going to say patient do get left ey do uh open in the else case we are just going to continue by continue I mean once again we are going to show the list of different organs okay that's our first case we also need a break in here let's write the second case the second case is the right eye we basically can copy and paste all of these logic but we just need to change the left eye to right eye so for example in here let's say get right ey okay we are done with our second case let's also write the case for the heart let's say case three first of all let's show the details of the heart let's say patient dog heart. get details after that we are going to give the user to change the heart rate for that let's say back SLT back SL H T1 change the heart rate once again we need to listen for the users input so let's say if scanner. next int is equal to one we need to ask for the new heart rate so let's say enter a new heart rate after that we need to save that heart rate so let's say int is equal to a scanner. next int after that we can say patient. get heart dot let's say set rate and let's pass our new heart rate but in the else case like before we are going to continue we also need a break in here let's quickly add that and also after changing the heart rate it's better to show some message let's say heart rate changed to plus patient. Gart dog rate okay that's our third case the fourth one was for the stomach so let's say case four first of all we need to print the details of the stomach patient. getet stomach. getet details for the stomach we had the digest option so in here let's show that option back SLT back SLT let's say digest let's say if scanner. next int is equal to one if that's the case let's say patient. get stomach. digest but in the else case let's just continue we also need a break in here let's quickly add that the fifth case is for the skin let's say case five for the skin we didn't have any option we just need to print the details let's say patient. get skin dog details of course after that we need to add a break in here I'm going to add a default case and if the user enters any other number than this five we are going to quit the application for that we are going to change the value of this short finish Boolean to True after that we need a break okay I think our application is ready to test let's see how did we do in here we can see the name and age of the patient which is good we can also see the list of our organs once again it's good let's select left eye we can see the details of the left eye and also we have this close the eye option let's put another number beside this one let's say two once again we can see the list of our organs let's see if we can close the left eye let's put one in here and as you can see left eye has been closed okay let's check the right eye it's working the same let's enter two in here in order to show the list of organs and let's select our heart we can see the hearts details which is good let's see if we can change the heart rate let's select one in here the console is waiting for the new heart rate let's say 75 and as you can see heart rate has been changed to 75 let's check it once again in order to make sure of that let's say three and as you can see the heart rate is 75 let's put two in in order to show the list of organs and let's select four in order to see the stomach if we can see all of the details of the stomach let's digest some food and as you can see digesting has begin let's check the skin which is five you can see that we are getting the details of the skin but we don't have any option that seems to be good and if we enter any other number than this five we should quit the application let's enter seven in here for example and as you can see application has been finished successfully okay it seems like our application is working fine let's just delete the uh getter and Setter methods that we said that we will delete if we didn't use them let's check the classes one by one first of all inside the I class everything that is grade out it means that we never use that for example we never use this set color method okay it seems to be good inside the heart class I I think we have used all of them okay that's fine inside the organ class we didn't need this set medical condition method and also we didn't need this set name method inside the patient class let's see what do we have in there and uh I think we didn't use any of the Setters of this patient class let's just delete them okay that seems to be good let's see what do we have inside the skin class and in here we never use these Setters and this get softness method let's delete them inside the stomach class let's delete this set empty method and in order to make sure of everything let's just run our application one more time okay it seems like we don't have any compile time error which seems to be fine okay that was our challenge about object oriented programming Concepts I will upload the source code at the links that you can see on the screen feel free to check them and also I'm more than happy to see your feedback about the code in the next video we will talk about collections in Java see you in the next video in previous videos we have seen simple arrays in Java for example if we wanted toore a list of different names we could have set something like this we could have set string with a pair of a square bracket after that we could have named our array and after that we could have initialized our string array like this inside the square bracket in here we needed to pass the size of our array for example five the other way was to pass our elements at the time of instantiating our array for example we could have set a pair of curly braces and inside those curly braces we could have passed our elements let's pass few names in here after that if you want wanted to have access to these elements we could have say something like this we could have said print let's say names with an index of let's say two for the third element which is Brad in this case if we run our application right now we should see Brad let's run it you can see that Brad has been printed but if you remember I said that using this kind of simple arrays in Java has a lot of limitations for example the first limitation is that their size is immutable it means that their size cannot be changed right now we have five elements inside our names array if we want to add another item inside this array we cannot do that for example we cannot say something like names with an index of five which indicates the six eleme

Original Description

Learn how to develop an android app from scratch in this full course for beginners. No prior programming experience required! Here is the 2nd part of this course (also free!): https://youtu.be/RcSHAkpwXAQ In this course, you will learn how to build a real-word Android application from scratch using Java. On the way to building an Android app, you will learn the basics of programming in Java and object-oriented programming. ✏️ Course from MeiCode. Check out his YouTube channel: https://www.youtube.com/channel/UCE3wAhsfp4wGRgHXIQjVx0w Extended 55-hour course: https://courses.meicode.org/courses/android2020 ❤️ Support for this channel comes from our friends at Scrimba – the coding platform that's reinvented interactive learning: https://scrimba.com/freecodecamp ⭐️ Course Contents ⭐️ ⌨️ (0:00) Course Introduction ⌨️ (3:12) Setup The Environment ⌨️ (18:52) Create Your First Application (Part 1) ⌨️ (43:53) Create Your First Application (Part 2) ⌨️ (59:20) Challenge ⌨️ (1:07:19) Variables and Arithmetic Operators ⌨️ (1:31:12) Relational and Logical Operators) Conditional Statements ⌨️ (1:47:43) Loops ⌨️ (2:04:13) Challenge (Create a Game) ⌨️ (2:16:00) Simple Arrays ⌨️ (2:27:51) Object Oriented Programming (Part 1) ⌨️ (2:49:30) Object Oriented Programming (Part 2) ⌨️ (3:06:02) Object Oriented Programming (Part 3) ⌨️ (3:19:41) OOP Challenge ⌨️ (3:43:56) Collections in Java ⌨️ (4:06:14) Static Keyword - Inner Classes ⌨️ (4:17:04) Interfaces and Abstract Classes ⌨️ (4:35:26) Concurrency - Exceptions ⌨️ (4:46:05) Singleton Pattern ⌨️ (4:56:00) Challenge (Part 1) ⌨️ (5:18:16) Challenge (Part 2) ⌨️ (5:39:40) User Interface Basics (Part 1) ⌨️ (6:04:21) User Interface Basics (Part 2) ⌨️ (6:33:09) User Interface Basics (Part 3) ⌨️ (6:58:39) Layouts ⌨️ (7:26:53) Images ⌨️ (7:37:32) ListView and Spinner ⌨️ (8:00:57) Different XML Files (Part 1) ⌨️ (8:29:41) Different XML Files (Part 2) ⌨️ (8:41:09) Material Design ⌨️ (8:59:58) Snackbar and CardView ⌨️ (9:16:51) RecyclerView (Part
Watch on YouTube ↗ (saves to browser)
Sign in to unlock AI tutor explanation · ⚡30

Playlist

Uploads from freeCodeCamp.org · freeCodeCamp.org · 0 of 60

← Previous Next →
1 React: Production Server Setup Part 2 - Live Coding with Jesse
React: Production Server Setup Part 2 - Live Coding with Jesse
freeCodeCamp.org
2 cookies vs localStorage vs sessionStorage - Beau teaches JavaScript
cookies vs localStorage vs sessionStorage - Beau teaches JavaScript
freeCodeCamp.org
3 Browser history tutorial - Beau teaches JavaScript
Browser history tutorial - Beau teaches JavaScript
freeCodeCamp.org
4 Graph Data Structure Intro (inc. adjacency list, adjacency matrix, incidence matrix)
Graph Data Structure Intro (inc. adjacency list, adjacency matrix, incidence matrix)
freeCodeCamp.org
5 React: Parameterized Routing with Next.js - Live Coding with Jesse
React: Parameterized Routing with Next.js - Live Coding with Jesse
freeCodeCamp.org
6 React: Dealing with jQuery Issues - Live Coding with Jesse
React: Dealing with jQuery Issues - Live Coding with Jesse
freeCodeCamp.org
7 setInterval and setTimeout: timing events - Beau teaches JavaScript
setInterval and setTimeout: timing events - Beau teaches JavaScript
freeCodeCamp.org
8 Browser and Device Testing - Live Coding with Jesse
Browser and Device Testing - Live Coding with Jesse
freeCodeCamp.org
9 Last Minute Updates - Live Coding with Jesse
Last Minute Updates - Live Coding with Jesse
freeCodeCamp.org
10 Post Launch Updates - Live Coding with Jesse
Post Launch Updates - Live Coding with Jesse
freeCodeCamp.org
11 React: Setting Up Google Analytics - Live Coding with Jesse
React: Setting Up Google Analytics - Live Coding with Jesse
freeCodeCamp.org
12 React: Masonry Layout - Live Coding with Jesse
React: Masonry Layout - Live Coding with Jesse
freeCodeCamp.org
13 Load Balancing Digital Ocean Droplets - Live Coding with Jesse
Load Balancing Digital Ocean Droplets - Live Coding with Jesse
freeCodeCamp.org
14 try, catch, finally, throw - error handling in JavaScript
try, catch, finally, throw - error handling in JavaScript
freeCodeCamp.org
15 Load Balancing: SSL Passthrough Setup - Live Coding with Jesse
Load Balancing: SSL Passthrough Setup - Live Coding with Jesse
freeCodeCamp.org
16 Graphs: breadth-first search - Beau teaches JavaScript
Graphs: breadth-first search - Beau teaches JavaScript
freeCodeCamp.org
17 React: Masonry Layout Part 2 - Live Coding with Jesse
React: Masonry Layout Part 2 - Live Coding with Jesse
freeCodeCamp.org
18 React: WordPress API Live Search - Live Coding with Jesse
React: WordPress API Live Search - Live Coding with Jesse
freeCodeCamp.org
19 Creating WordPress Custom Post Types - Live Coding With Jesse
Creating WordPress Custom Post Types - Live Coding With Jesse
freeCodeCamp.org
20 Dates - Beau teaches JavaScript
Dates - Beau teaches JavaScript
freeCodeCamp.org
21 Miscellaneous Front End Updates - Live Coding with Jesse
Miscellaneous Front End Updates - Live Coding with Jesse
freeCodeCamp.org
22 Merging a Pull Request from GitHub - Live Coding with Jesse
Merging a Pull Request from GitHub - Live Coding with Jesse
freeCodeCamp.org
23 React + Prettier + Standard JS - Live Coding with Jesse
React + Prettier + Standard JS - Live Coding with Jesse
freeCodeCamp.org
24 React: Sortable Responsive Table - Live Coding with Jesse
React: Sortable Responsive Table - Live Coding with Jesse
freeCodeCamp.org
25 Geolocation Sorting by Distance - Live Coding with Jesse
Geolocation Sorting by Distance - Live Coding with Jesse
freeCodeCamp.org
26 Tradeoff Matrix - Agile Software Development
Tradeoff Matrix - Agile Software Development
freeCodeCamp.org
27 The Definition of Ready - Agile Software Development
The Definition of Ready - Agile Software Development
freeCodeCamp.org
28 Getting first React job without experience - Ask Preethi
Getting first React job without experience - Ask Preethi
freeCodeCamp.org
29 React: Google Analytics Click Tracking - Live Coding with Jesse
React: Google Analytics Click Tracking - Live Coding with Jesse
freeCodeCamp.org
30 Submitting a PR to an Open Source Project - Live Coding with Jesse
Submitting a PR to an Open Source Project - Live Coding with Jesse
freeCodeCamp.org
31 Should I go back to school to get CS degree? - Ask Preethi
Should I go back to school to get CS degree? - Ask Preethi
freeCodeCamp.org
32 Hero Section CSS Changes - Live Coding with Jesse
Hero Section CSS Changes - Live Coding with Jesse
freeCodeCamp.org
33 Working Agreement - Agile Software Development
Working Agreement - Agile Software Development
freeCodeCamp.org
34 A day at Pennybox with Co-Founder Reji Eapen
A day at Pennybox with Co-Founder Reji Eapen
freeCodeCamp.org
35 React: Sorting and Filtering Data - Live Coding with Jesse
React: Sorting and Filtering Data - Live Coding with Jesse
freeCodeCamp.org
36 React: Sorting and Filtering Data Part 2 - Live Coding with Jesse
React: Sorting and Filtering Data Part 2 - Live Coding with Jesse
freeCodeCamp.org
37 React: Building a New UI - Live Coding with Jesse
React: Building a New UI - Live Coding with Jesse
freeCodeCamp.org
38 Definition of Done - Agile Software Development
Definition of Done - Agile Software Development
freeCodeCamp.org
39 Getting started with jQuery (tutorial) - Beau teaches JavaScript
Getting started with jQuery (tutorial) - Beau teaches JavaScript
freeCodeCamp.org
40 Making a React Blog with WordPress Content - Live Coding with Jesse
Making a React Blog with WordPress Content - Live Coding with Jesse
freeCodeCamp.org
41 React, NextJS, CSS - Live Coding with Jesse
React, NextJS, CSS - Live Coding with Jesse
freeCodeCamp.org
42 jQuery events - Beau teaches JavaScript
jQuery events - Beau teaches JavaScript
freeCodeCamp.org
43 React/NextJS Routing and WordPress API Custom Types - Live Coding with Jesse
React/NextJS Routing and WordPress API Custom Types - Live Coding with Jesse
freeCodeCamp.org
44 React: Working with API Data - Live Coding with Jesse
React: Working with API Data - Live Coding with Jesse
freeCodeCamp.org
45 React: Refactoring Components - Live Streaming with Jesse
React: Refactoring Components - Live Streaming with Jesse
freeCodeCamp.org
46 jQuery effects - Beau teaches JavaScript
jQuery effects - Beau teaches JavaScript
freeCodeCamp.org
47 More React Refactoring - Live Coding with Jesse
More React Refactoring - Live Coding with Jesse
freeCodeCamp.org
48 animate in jQuery - Beau teaches JavaScript
animate in jQuery - Beau teaches JavaScript
freeCodeCamp.org
49 "Finishing" My React Site - Live Coding with Jesse
"Finishing" My React Site - Live Coding with Jesse
freeCodeCamp.org
50 Starting a New React Project (P2D1) - Live Coding with Jesse
Starting a New React Project (P2D1) - Live Coding with Jesse
freeCodeCamp.org
51 React Project 2 Day 2: Learning Material UI - Live Coding with Jesse
React Project 2 Day 2: Learning Material UI - Live Coding with Jesse
freeCodeCamp.org
52 The Agile Manifesto - Agile Software Development
The Agile Manifesto - Agile Software Development
freeCodeCamp.org
53 jQuery: get and set with http, text, val, and attr - Beau teaches JavaScript
jQuery: get and set with http, text, val, and attr - Beau teaches JavaScript
freeCodeCamp.org
54 React Project 2 Day 3 - Live Coding with Jesse
React Project 2 Day 3 - Live Coding with Jesse
freeCodeCamp.org
55 The INVEST approach to product backlog items
The INVEST approach to product backlog items
freeCodeCamp.org
56 React Project 2 Day 4 - Live Coding with Jesse
React Project 2 Day 4 - Live Coding with Jesse
freeCodeCamp.org
57 Chickens and Pigs - Agile Software Development
Chickens and Pigs - Agile Software Development
freeCodeCamp.org
58 React Project 2 Day 5 - Live Coding with Jesse
React Project 2 Day 5 - Live Coding with Jesse
freeCodeCamp.org
59 jQuery: add and remove DOM elements - Beau teaches JavaScript
jQuery: add and remove DOM elements - Beau teaches JavaScript
freeCodeCamp.org
60 React Project 2 Day 6 - Live Coding with Jesse
React Project 2 Day 6 - Live Coding with Jesse
freeCodeCamp.org

Related Reads

Up next
Man Builds a Backyard Tiny House and Turns It into a Home Office | Start to Finish by @Elseweyr
AKLA GELEN
Watch →