 Hello everyone and welcome to the complete Android app development masterclass. My name is Meisam, 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 development kit, Android studio software development kit for Android app development and the emulator for testing your applications. Besides 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, singleton pattern and a lot more. You will also learn about object oriented 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 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 recycler 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 with 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 a 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 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 minus 64 bit. 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 into your Oracle account. Let's do that. Creating an Oracle account is free and you want to be charged. Okay, let's select sign in. And as you can see, the download has begun. I'm going to select canceling here because I have downloaded the JDK previously. Let's select that. It's going to be a really simple 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 clause. 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 dash version. As you can see, we are seeing some information about the version of Java 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 your version of operating system, you can click on this download options. But in here, I'm just going to 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 gigabytes. So make sure to have at least 20 gigabytes 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 video. But for you, this list should be empty. Also along the way of installing Android Studio, you might see some windows 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 you can select this SDK manager SDK stands for software development kit. And for developing Android applications, you need to install at least one SDK. 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 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 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 these can occupy a lot of storage on your device. But the necessary things in here is first of all, Android SDK versions, 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 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 Google map or YouTube APIs, check one of these, for example, this Google API is 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, the Android 10 or API level 29. But if you want, you can select and install multiple SDK versions. So 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 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 in this version of SDKs, there were a lot of changes. And I'm just 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 OK 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 tools 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.0.2 at the time is the latest version. Also down in here, 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 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 Hexam 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 low memory RAM. For that reason, I suggest you to install this Hexam installer. But there is one thing that I need to mention in here. I've seen a lot of students having problem with this Hexam installer. I've seen them that they cannot install this Hexam successfully. This Hexam cannot be installed on all of the CPUs and depending on the structure of your CPU, this Hexam might not be installed. But there are some CPUs, especially Intel CPUs, that they have a special option in the device's BIOS, specifically for this emulator accelerator. If that's not enabled, you may want to enable that in the BIOS settings as well. And also if for any reason you couldn't install this Hexam 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 GeniMotion. In here, I'm not going to install that, but I will put a link to download GeniMotion 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 OK 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 switch to this appearance in here. From here, you can change all of the preferences that you want. For example, you can change the theme. Dracula is the dark theme. Also we have this five contrast theme. The IntelliJ 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. 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. If you want to change the size of your codes, you can search for font in here. 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, 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 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 OK. 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 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 Neo 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 brand to it and all sorts of sensors and hardware. 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, various and tablets. Let's select one device from here. I don't even know all of these devices. Let's just 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 fire, so I'm going to skip the download in here until the download is finished. Yes, it's 1.1 gigabyte. 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 stay with portrait in this 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 sorts 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 installed 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, you 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 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 this, because we will learn how to create all of these elements ourselves later on, even we select this add no activity template, but the Android team are nice guys, and they have provided us these 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 activities as different parts 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. For now, we can think of an activity as a page of our application. In our first application, I'm going to say 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, 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 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 backwards. For example, my website is called mako.org. So my package name is org dot mako dot 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 dot example. Let's say com dot example dot the name of my project. But since I have a website, I'm going to use that in here. I'm going to say org dot mako. 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 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 Kotlin language. In this course, we are going to save with Java. But if you want, I am currently recording a new course about developing Android applications with Kotlin. Feel free to check that if you want. But 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 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 95% is a good number. Leave this check empty for now. Also using Android X artifacts is mandatory 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, this process can be very slow because Android Studio is going to download some stuff. For example, the Gradle file 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 activity main dot XML file and this main activity dot 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 if you select that, you can have some codes written to some level. The other thing in here is this build pane down in here. This build pane in here will show the progress 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 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 pane in here. I can minimize and maximize that. Also, topping 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 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 contains the main activity Java file. This is the exact hierarchy of files on our system. If you want to make sure of that, you can right click on the name of your project and 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 inside this project. As you can see in the hierarchy, we have this app folder. Inside this app folder, we have a source folder, main folder, Java folder, org, 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.java file. It's much more easy for eyes to follow different files. Also beside this app folder, we have these Gradle scripts down in here as well. Before I talk about these Gradle scripts, I need to talk about the structure of every Android application. So in most Android applications, there are at least two different kinds of files. The layout files which will define the looks of your application. The layout files in Android are called XML. You can see this activity main.xml file. If you click on that, we can see the layout of your application. Right now it has only one simple text. The other part of every Android application is the Java file. If you are developing in Kotlin language, there are Kotlin files. The Java or Kotlin 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 user's inputs. All of those will be handled in the Java or Kotlin files. Besides 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 Meetmap folders. Right now we have 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 variables or static files on your application. So these are the three main components of every Android application. We have layouts, we have the Java file and also we have the static files. Besides these, we have this manifest file inside the manifest folder. This manifest file will specify some general properties for 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 fellow 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 for example, when you are going to download some application from the Play Store, we 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 Gradle tool in here is going to be useful. Gradle is a build tool that will combine all of these files and other files and will 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 Gradle. For that reason, we are going to work extensively with Gradle. The other use of Gradle 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.gradle file down in here. Just by writing one line of code, Gradle will download the code for YouTube video player. As simple as that, Gradle will add the YouTube player code to your project and after that you can use it. So, Gradle 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 Gradle scripts later on in the course. Okay, let's close all of these extra files. Okay, this was the project 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 useful pains as well. For example, this to-do is very helpful when you are creating or when you are developing Android applications. To-dos 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. As you can see, this to-do has been added inside this to-do pain 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 to-dos and also other kinds of 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 for working with SQLite databases. We will work extensively with this terminal in the database session. After that, we have this build to-do 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 projects. And from here, you can exactly locate the problem. After that, we have this lock cat 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. We have file, edit view and all of these. We will work with most of them, I believe in the core spot. It's impossible to work with all of them. Also, there is one thing that 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 buggy and 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 restart Android Studio. So if you get those warnings or errors, you can try these three different ways in order to overcome 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 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 Profiler. 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 the amount of network that your application is using. If we run our application, we can track the live amount of different resources that our application is going to use. Let's run our application and see it for ourselves. 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 a device. In the previous video, we have created a virtual device and we can see the list of different 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 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, this emulator has been opened. And we will see our application in a few minutes. Also from down here, you can 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, 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 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 red button in here. You can stop it. And also, if you want, you can turn off your device by long pressing this 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, but if you want to check them, you can click on this event lock. And everything that happens since we click on this green triangle will be locked in here. Okay, let's minimize that. And let's switch back to our activity main dot 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 just for now. In order to disable that, you can click on this stack icon. And you can say just design. We can also minimize and maximize that by pressing this plus button in here. At the left panel in here, you can drag different 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 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 this all attributes. And you can see that there are a lot of them. We are going to get familiar with different UI elements in the UI session. We have that, I think, in two sessions from now. After the Java session, we will be talking about user interface 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 we 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 to your design view or from the text view, you can type it. We 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 enabled, you can enable it from here. Let's just press Ctrl 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 world, you can see the list of attributes. At the top, we have this ID. 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 worry. Text view is just a fancy way of saying a 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 team here is lower cases. And also after the first word, you type the first letter of the second word 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 you can see right now, we have some warning for this button. The warning says that this button is not constrained 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 change your different elements to somewhere. For example, if I don't constrain this button to anywhere, it's going to be floating at the runtime. 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 add some constraints by clicking and dragging, as simple as that. I'm constraining this button to the both edges of my screen. Also for the top and the bottom, I can constrain that as well. For the top, I'm going to constrain that to this text view. And for the bottom, I'm going to constrain 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 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 idea 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 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 follow 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 we have imported some packages to this class. If you want, you can always minimize and maximize that import. And for that matter, you can minimize and maximize all of your methods. For 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 extends 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 card devices is going to be the code that will run 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 dot uncreate. 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, intelligent 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 dot 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 widget 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's 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 parentheses 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. You can say R dot 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 TXT message. And we are using that to have access to our text view. So this way by using this find 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 multiple options. Let's import the first one. Inside the parentheses of this method, we need to pass a text. And whenever you are going to pass a text statically, whenever you are going to hard code the text, we need to pass it inside double quotations. Let's pass a double quotation. Inside this double 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 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 and on click 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 on click 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 on click, 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 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 on create 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 btn click a pair of parentheses because it's going to be the on click listener for our button. We need to accept a viewing here. Don't worry about this viewing here. We will talk about all of this 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 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 to inside this method. You can probably guess the behavior of our application right now. Let's run it once again and see how it's going to work. You can see that the text still says hello world. If we 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, Mason, hello Tom and something like that. We are going to get the user's input. The way to get the user's 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 this hello world text. After that, we have other options plain text, password, email and all of these. These are all helpful 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 edtxt name. Because we are inside the constraint layout, we also need to constraint this edit text as well. But before that, I'm going to change 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 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 17. That seems to be better. The other attribute that every edit text has is 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 user's input. Once again, the start point of our activity and our application is this on create method. So we can do that inside this on create 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 in here, you can see that this line of code has been added to our class as well. Let's say edit text, edtxt 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.edtxt name. To this point, we have to find our edit text. Now we need to get the text of our edit text. For that, we can say edit text name dot get text. 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 dot to string. Don't worry about this to 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 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 a scope in Java. The scope of this edit text is this uncreate method within the curly braces of this uncreate method. We can't have access to this element 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 user's 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 this 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 dot get text dot to 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 we can type something. For example, let's type my name. And if we 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 Mason. 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 to 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 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 Mason by pressing button. This time you can see that the text has been changed to hello, Mason. 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 you have a first name, 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 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 solved 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. 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 thing. 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 texts. And also we need a button. Let's add that as well. We also need the three text views. For the edit texts, let's also change their IDs. For the first one, I'm going to say edit text first name. Let's also delete this text and also add some hints. 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 keyword. Okay, for the button, first of all, let's change its ID to let's say btn register. You can name it whatever you want. Let's also delete this text and let's say register. Also, you can see that we have this on click attribute in here. We can define an on click 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. 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 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 my first name edit text. Add 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 90dp. For the first name, I'm going to constraint it to the both edges of my button. Sometimes it may not work. Just try it once again. And also the top constraint to the bottom of my button. For the top constraint, once again, let's say 90. I think 90 is fine. 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. 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 on click attribute so that we don't make any mistake when we define this method in our Java file. In our project pane, inside Java folder, inside our package folder, inside our main activity.java file, I need to create my on click method. Once again, I can say public void the name of my method which I've copied from my layout file inside the parentheses. I need to say view with capital V after that view with lower V. And now I have created my on button click listener. Once again, don't be worried 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 one, let's say txt first name is equal to find view by ID or dot ID dot 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 or dot ID dot 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 dot 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 name. We can say edit text first name dot get text dot to 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 email. Edit text last name dot set text. Let's say last name first of all. Plus edit text last name dot get text dot to string. Edit text email dot set text. 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 txt email dot set text. Let's say email plus edit text email dot get text dot to string. That's all we need from our application. Let's just run it. Okay, it seems like 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 at 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 IntelliJ. Until a few months ago, you could have write and run 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 Gradem. 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 search for Maycode 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, but to do now. And you can also see my 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 ideas that are available for writing Java applications are Eclipse and IntelliJ. In this course, we are going to use IntelliJ because it's a lot like Android Studio and also it's free. In that video, I have talked about how to install IntelliJ IDE. Make sure to check that if you need. But it's a lot like installing Android Studio. Besides IntelliJ, you are going to need JDK, Java Development Kit, which we have already installed on our system. You can get IntelliJ IDE from JetBrains website. Let's say IntelliJ IDE. The first link from the JetBrains 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 IntelliJ installed on my system and I'm going to 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 IntelliJ IDE 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 are using, you should see this Java option in here. Select that. In here, you need to specify the path to your JDK. If you have installed JDK with me at the beginning of this course, you should be good in here. You can 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 world. Also, if you don't see these settings in here, you'll have these 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, IntelliJ 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 dialog and let's switch to full screen mode and let's go to full screen mode. Once again, in IntelliJ IDE, you can see this project pane. 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. You can specify a package for our application. In this case, I'm going to say org.makecode. 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 we have few lines of code. Let's minimize our project pane 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 org.makecode.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 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 new 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 uncreate 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 SOUT or south. And by pressing tab or enter, you can see this line of code system.out.printline. 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 upper case for S. Let's say system.out. Basically this out means output in here. It means that we are going to outputting 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 user's input. Let's say system.out.printline. 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 devil quotation. You 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 dot 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 the most cases, those error would 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 dot main. In most cases, the error should be gone. But if you had any other problem, please 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 GUI 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 will move to the next line. That is not the case with print. In order to see the difference, let's say system dot out dot print. Once again, let's pass our hello world text. And let's run our application to see the difference. Also, if it's the first time that you're going to run your application, you can right click inside the main method and click on this run hello dot main. Or if it's not the first time you can click on this green triangle at the left or the green triangle on the top of your screen. You can also see the shortcut for Windows is shift plus F10. If you are using Mac or Linux, we 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 texts 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. This line of code will be completely ignored. The other kind of commenting here is like this. We can say slash slash to do. 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 to do. There are more to comments. We will talk about them later on in the course spot 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, 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. Besides 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 double 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 double quotation. Let's run the application and see if we can see our number. We can see that the value of our number is negative five in this case. But inside integers, you cannot have decimal values. For example, in here, I can't say 5.3. We will see other kind of variables in which you can use in order to store decimal 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 long. 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 long. And also a long variable will store more spaces in your device's memory RAM. To be exact, inside an integer, you can store numbers as large as the number of two to the power of 31. But inside a long, 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, we 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 devices memory run. Basically, double will occupy more space. We won't 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 m a. 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. We can also store something like this in your character. You can say back slash you 00 a. This is the special unique 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 unique code values as well. You can search for different unique code values. For example, if you want to show the copyright symbol, we can say something like this. We can say back slash you 00 a nine. If you run the application, we should see the copyright symbol. Feel free to search for other unique code values on the Internet. Okay, now let's talk about the 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. May some my name like before, if we want, we can print our string. Let's pass the name and let's run the application. We can see that may some 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 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 a 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 eight is equal to six. 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 plus b. This plus is the first arithmetic operator that you're 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 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. We can see that four has been printed. The other one is star, which is used for multiplying the two values together. In here, the answer should be six times two, 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 six 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 exceptions 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 divided by b. In this case, if we divide six by two, 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 five divided by two is one. Let's see that if we can see one. Yes, it has been printed from time to time. This remainder operator 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 five by two, 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 divided 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, we can see that we are seeing 2.5. 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 plus 2 is 7. Let's run the application. We can see 7 down in here. We can also use this plus with different texts. For example, if I have two texts in here, let's say string first name is equal to let's say MO. 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 texts 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 MO Watson. Let's also add a space in here in order to see everything better. MO Watson has been printed. This in here is called concatenating in Java, adding two texts together. So you can see that this plus operator have two usages. It can be used to concatenate two texts together or whenever we use it with different numbers, it will act as the addition operator. We are going to talk about more operators in Java. Specifically, we will talk about relational and logical operators. 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 org does may code dot operators. Inside our package, let's create our main class. Let's name this class main. Inside our main class, we are going to need our main method. Let's type PSVM by pressing tap, 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 int answer is equal to a plus two. Or instead of defining a new integer, we can say a is equal to a plus two. 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 dot 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 plus equal to 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 increase a by one, for example, if you want to say a is equal to a plus one, we can do something like this. We can say a plus equal one. Or alternatively, we can say a plus plus. That is possible as well. This a plus plus 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 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 divided by two. Both of these lines are the same. If you want to make sure of that, you can delete this line and you can run your application five divided by two 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 five. 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 inside a Boolean. This left anchor bracket in here means greater than operator. It means that if a is greater than b assigned 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 five is greater than three. The other kind of comparison operator is less than and that's this 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 see 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 b to five 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 kinds 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 true once again, we can see true. 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 you 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. Besides 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 these 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 five 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 backslash. Backslash is somewhere above the enter in English keyboard. So in here, this or operator means that if a is equal to five, or if b is equal to two, assign true to this answer. If none of those condition is true, so assigned 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 then 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 assigned true to answer if both of these conditions are true. If a is equal to five, 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 five and run our application, once again, we should see false. Because the second condition is not true. But if we change the value of B to two 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 parentheses, we need to provide our condition. For example, we can say if a is greater than three, after the parentheses, 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. We 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 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 if statement practices, or you can define your Boolean before your if statement. For example, in 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 IntelliJ 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 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 true. But in here, we have 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. Besides else, you can also have an else if as well. Let's quickly comment this if statement and let's write another one. Down 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. 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 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. In here, we can safely say a is zero. This is going to be the default case for our if statement. Right now, a is two. 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 two. 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 zero, we should see a 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 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 parentheses of the switch statement, we need to provide the variable that we want to switch on. For example, I can pass a in here. After the parentheses, 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 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, two 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 one, two 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 a is equal to one. And if we run our application, we can see that even though a is one, we can see both sentences, we can see a is one plus a is two. 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 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 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 fellow 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 for 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 eye 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 statement is just a statement for changing the value of eye every time that we look, we will see in action what all of these mean. After the parentheses, 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 look 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 one, 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 forego. So in this case, we are going to print hello 10 times. Let's run our application and let's see if we can see hello 10 times. We 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 we 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 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 print I let's quickly print that as well. And let's run the application. You can see that we are printing the numbers zero to four. Okay, for loop is one kind of loops in Java. The other kind is while loop. Let's quickly see that as well. Once again, I'm going to write the syntax of while loop, and we will talk about it after that. This is the general syntax of a while loop. First of all, we type while 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 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 negative one. In a normal application, we would get zero. Okay, but how can we exit a while loop? There are multiple ways for that. The simplest way is to change the value of a inside the while loop. For example, after printing hello, I can say a plus plus 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 look 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 while 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 means that we have exited our application successfully without any error. The other way that break out of a while 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 while 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 the while loops, we have another keyboard called continue. Let's 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 eight, then let's continue. This continuing here means that go to the next record of your while loop, go to the next round of looping. It means that no matter what is the rest of the code inside the while loop, break out of the while loop and go to the next record. So for example, in this case, if a is five, six or seven, we are going to print hello. But if a is eight, we are not going to print hello. After that, we are going to print hello in case if a is nine. If we don't want to stuck in an infinite loop, we also need to change the value of a somewhere inside the while loop. For example, before this if statement, I can say a plus plus. Right now, if I run my application, I should say hello only four times. Because if a is eight, 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 seeing 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 while 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 while loop. It means that we are not going to run the code inside the while 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 while loop at least once no matter what the condition is. For those situations, you can use do while loops. Let me comment this while loop and let's create a do while loop. It's a lot like while loops, we need to type do inside the curly braces, you need to put your code. For example, we can say system dot app dot print line. And you can print hello. After the curly brace, we need to say why. And inside the parentheses, you need to specify your condition. For example, we need to say a less than five. After the parentheses, you need a semicolon, of course, in this case, because a is equal to five, this condition in here is not true. But even with that condition, we should see this hello at least once because we are using do while 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 while 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 object oriented 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 object oriented 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 a scanner. After that, you can say is equal to new scanner once again with capital S. Inside the parentheses, you need to say system dot in. We have seen system dot out, which was useful for outputting something. System dot in is useful for when you want to get the user's input. Now you have a scanner, you can get a number from user like this, you can say int answer is equal to a scanner dot next int. This one down in here by saying a scanner dot next int, our scanner is going to wait for the user's input until the user enters 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 say five by pressing enter. You can see that answer was five. And we have exceeded our application successfully. So by using a 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 a string name is equal to scanner dot 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 classes, object oriented programming, we will talk about all of these later on. But for now, because we are going to need the user's input, we are going to figure out a way to receive that. So by using scanner dot next, we are going to get the user's name. And after that, let's print something. Let's say hello, close 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 may some and we can say hello may some message. So this way we can get the user's 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 dot 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 zero and 19. If you want your random number to be somewhere between one to 20, you can simply add one in here. We can say plus one. Let's run the application once again. You 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 user's 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 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 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 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're 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 game. Let's create our project. And inside our source folder, let's create our package and Java file. Let's name this package or that may code that 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, 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 options. 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 slash t, 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 a 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 while loop. Let's say while begin answer is not equal to one. We are going to continue asking our question. So let's copy this three line of code and paste them inside our while loop. After that, inside the while loop, we also need to store the new user'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 while loop until the user's answer is one. When it's one, we have the permission to start the game. After the while 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 one 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 x tried is equal to zero initially. After that, let's define a boolean. Let's say boolean has one. 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 while loop. Let's say while should finish is not equal to true. Then inside the while loop first level, I'm going to increase the times that user has tried. So let's say times tried plus plus. After that, I'm going to create an if statement. Let's say if times tried 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 while loop. For that, I'm just going to say should finish is equal to true. This is going to be the last line of our while loop. So if we look once again, because this condition is no longer met, we are going to break out of the while loop. But in case the times tried 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 has won to true because user has won the game. And also we need to break out of this while loop. Let's say should 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 input is greater than our x, which is our randomly generated number, we are going to tell the user to guess lower. For that, we can say guess lower. And of course, we need to wait for the new users inputs for that we can say user input is equal to a scanner dot next int. We also need another case in here in case the number is 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 inputs. Let's say user input is equal to scanner dot next int. We are done with this while loop. We will review what we are doing in here. But after the while loop, we need another if statement. We can say if the user has won the game, if that's true, then we are going to show a message. Let's say congratulations. 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 times tried 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 receive the name, we are waiting for the user's permission to start the game. We are saving the user's input in here. Inside the while 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 a random number. The random number is between one 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 defined three new variables in here time straight has won and should finish. Next, we are creating this while loop. It starts from here and ends in here. The condition of this while loop is while we shouldn't finish the game continue the loop. First thing inside this while loop, we are increasing the time straight. So if it's the first time, because the time straight is initially zero, we are changing that to one. After that, we are checking that if time straight 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 won 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 telling the user to guess higher. Once again, we are waiting for the user's input. In case the time straight is greater than five, we are just breaking out of the loop. If that's the case, the has won is still false. So we are checking that in here. If has won 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 may some we are saying hello may some 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 know once again, we are seeing the message. This is our first wide loop. Also this format in here is because of that backslash t that I have used when I have created this text. I'm talking about this one, this backslash t 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 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 may some. 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, 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 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 int a is equal to five. 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 a 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 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's indexes in Java starts 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, so we can keep doing this for all of our elements inside our array. Besides 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 be 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 brace. And inside that curly brace, I can pass my values. For example, I can say may some 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 one two 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 do let's say for int 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 plus plus. 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 one to six have been printed into our console. So for loops are very helpful when you are working with different kind of arrays. In here, we have hard coded the 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 loops with 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 to six later on, we will see that beside primitive data types and strings, we can also have different kinds 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 define our students array, we have set the size to be five. 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 kinds of collections in Java, we will see that we have all kinds of operations on our array elements. But I'm not going to talk about other kinds 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 kinds of collections like array lists and maps. Just before I 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 contacts names on a phone for 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 Mason. 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 phone. So let's create a for loop for int I is equal to zero, I less than names dot length, and I plus plus. Let's bring 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 dot in. After that, let's get the contacts name, let's say the string name is equal to a scanner dot 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 int I is equal to zero, I less than names dot length, I plus plus. 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 the string values are compared using two equal signs, not equal with a pair of parentheses. The problem in here is that when you're using two equal signs, you are checking for the equality of two strings by their reference. I'm talking about their reference inside the device's 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 to a strings while using these two equal signs. Instead of using these two equal 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 dot equals. And inside the parentheses, 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, this equals method. Once again, we are going to talk about methods later on in the course when we talk about object oriented 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 get Sarah's number. Let's run the application in here. Once again, let's say several. And as you can see, we are getting the number. Let's also check that if you're getting the correct number. Sarah 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 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 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 five. Or similarly, we could have defined characters, texts and all sorts 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 object oriented programming. In object oriented programming, you define your own objects. The core component of object oriented programming are classes. Right now, you can see that we are inside a class. This class is named main. 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 save 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 you know, 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 a package right now, it's package is org.maycode.op section one. Also, if you take a look at the left pane 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 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 sorts 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 we 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. Besides 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 instance 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 IntelliJ. Sometimes you may get multiple options. And that's because different classes with different names can live 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 dot 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 dot, let's say memory RAM is equal to eight. Besides 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 tracking 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 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 album name. But I'm not going to do that in here, but you can have as many inputs as you want. Besides 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, we 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 keyboard 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 void. 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 going to print something. In this case, I'm just going to say playing 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 dot play music. Once again, you can see that by typing dots, I can have access to my methods as well. Right now, 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 would 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 dot play music, and I can pass a different track name. Let's pass lamenting kiss 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 for organizing our code. For example, imagine that you want to have some sort of calculation, you can pass 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, 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 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, 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. Besides 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 a 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'm getting some suggestions from IntelliJ. Basically, there is a convention among programmers to set the name of their setter methods like this, and IntelliJ 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 a 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 dot name is equal to name. The keyboard, 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 dot 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 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 parenthesis 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 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 dot name. Once again, this refers to the current object, this dot names means the name inside our phone object. Now that we have created this method inside our main class, instead of saying iPhone dot name, I can say something like this, I can say iPhone dot get 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. Besides creating this 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 clicking here, we can go to this generate method. Similarly, we can press all plus insert, you can see that in here we have a list of options. We have getter, we have setter, and also we have getter and setter. If we want to create getters and setters, 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 camera and press okay, you can see that ID 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 getters and setter methods are very usual ID can help us with the creating of them. But why are we using getters and setters? Well, there are a 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 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 getters and setters. And let's select both of them. You can see that IntelliJ 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 dot memory ram is equal to eight, I can say something like this, I can say iPhone dot 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 playing music method, I can create something called constructor. Let's use the help of ID 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 object oriented 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, a 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, we can see that we are getting a red warning in here. The warning says that expected for argument spot found zero. It means that now that we have created the constructor, we need to pass the values directly to the parentheses 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 a 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 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 run. 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 three. 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 object oriented 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 about some important concepts regarding to object oriented 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 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 it, I'm going to indicate the eating behavior of a dog. As the input of this method, I'm going to receive a food. So let's say a string food. And inside this method, I'm just going to print something. Let's say eating class 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 each 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, 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 Julian, let's say has tape. For this bird class, let's also create a constructor. And some getters and setters. I'm going to create my eat 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 programming, this is not efficient. You basically are copying 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 a 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 warning. 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 keyboard so far. Basically, this super keyboard 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 Phoenix. 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 Nina, we need a color, let's say golden. After that, we need the number of legs, which I'm going to pass to 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 getter 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 dot get name, you can see that we have all of the getter methods. Let's run the application and let's see if we can print the name of our bird. You can see that the name has been printed successfully. Besides 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 this each method. Let's see if we can use it in our bird instance. For example, in here, if I say Phoenix dot 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 each 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 copying 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 bird class, I want to add another field. I'm going to say private, let's say int wings. We 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 four fields. But because inside our parent class inside the animal class, we do not have a wings field, these 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 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 wing. Let's also pass that in here as well. For example, I'm going to say to 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 dot get wings. Let's run the application. And you can see that too has been printed as the number of wings. Besides 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 print something. Let's say this dot 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 dot 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 dot Floyd, as you can see Nina is flowing. 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 control plus all, you can see that we are seeing a list of different methods. I'm going to override this eat method. So by overriding, 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 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 dot eat. Let's comment the lines after that, so that we can see 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 dot 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 shepherd. Now in here, I can say extend 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 problem. You can see that even though inside the dog field, we do not have any field, but inside our shepherd class in the constructor, we need all of those arguments, because the parent of this shepherd 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 shepherd 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 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 constructors, this is one kind of polymorphism. 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 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 birth. 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 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 fly 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 parentheses, 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, we can see that we are not getting an error. But before that, I think I should uncomment this line of code, even though we are not getting a red warning. This in here, it means that we are using the first fly method. Let me close all of the unnecessary classes. Inside the bird class, we are using the first method. But if we 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 passing integer. But if we had another method, for example, 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 parentheses, I don't know, let's pass a string. Let's just say name, you can see that 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 object oriented 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 object oriented 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 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 previous classes. Now that we have created this car, 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 and 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 to for the color, let's say silver, but what should we pass as the engine 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 Renault for the RPM, let's say 8,000. After creating our engine objects, 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 objects directly inside the constructor. Let's say Renault. 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 Renault engine. But I think it doesn't matter in here. Now that we have instantiated 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 dot name or dot get name to her size. 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 Renault. Also, instead of using the methods of your engine, you can 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 dot 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 hovering 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 kinds 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 kinds 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 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 create our comment. But these kinds of comments are not useful in here. Instead, we can use a single slash. And after that, we can have two stars. By pressing and enter, you can see that we have these sort of comments as well. These kinds of comments are useful for when you have multiple lines. And in here, you can have some 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 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 plus 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 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 object oriented 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 keyword in Java called now. Before that, let's close this car class. And let's comment all of these lines of quotes. There are some times 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 post one that to few lines after this. For that, you can pass null values for your objects. Let's see now 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 dot get name, for example, we are not getting a compile time error. It means that our application 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 around time error and not a compile time error. Let's run our application and let's see what would happen. We can see that in here we are getting a red warning in our console says Java dot lang dot 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 dot get 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 null. 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 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 null. 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, because I've said int a is equal to five, for example, later on, we could have changed this a for example, because I've said a is equal to five plus one or a plus one. This way, we could have changed the value of our variable. But there are some times 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 can say final, final int a is equal to five. Now, if I try to change the value of my variable, for example, like before, if I say a is equal to a plus one, 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 this to 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 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 7000. 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 we wanted to change the RPM, we could have said something like engine dot 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 object oriented 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 eye, 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 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 change 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 begun. 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 skin. This time for the skin, you can see that we are not seeing any behavior. Instead, we are just seeing some 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 exceeded 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 org dot mako dot o p 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. Besides 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 dot get name. After that, let's print a medical condition of this organ as well. Medical condition plus this dot 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 eye class, I'm going to have a string called color. And after that, let's have a Boolean indicating if the eye 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 override the get details method, I can do that by pressing control plus all 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 dot get color. Inside this eye class, I'm going to have two other methods as well. Let's see them. Let's say public void open. Inside this open method, I'm going to change the value of this Boolean to true. So let's say this dot set opened, and let's pass through. After that, let's print something indicating the eye has been opened. Let's say this dot 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 open. 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 dot set open and let's pass false. After that, let's print something. Let's say this dot get name plus closed. That's all we need inside this eye class, let's quickly create another class for the heart. Let's say heart. For this heart 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 override the get details method by pressing control plus all. 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 dot 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 extends organ. And after that, we need to create our constructor. Let's create our getters and setters. And after that, let's override 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 a 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 zero to 100 indicating the softness of the skin. After that, it's time to extend 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 override the get details method. Inside this method, let's also print a skin color. Let's say skin color, plus this dot get color. That's all of our organs. Now we can create our 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 eye. Let's say left eye. Let's do the same for the right eye. Let's also have a heart. 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 instantiate it. 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 eye, which I can say new eye. For this I first of all, we need a name, let's say left eye. After that, we need the medical condition, which I'm going to say short sighted. For the color, let's say blue. For the is open bullion, let's say true. We need the same thing for the right eye. New eye. Let's just change the name to right eye. Also, 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. 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 ulcer disease in case if you're 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. After that, but we need, we need the color and also softness 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 get name. After that, do the same thing for the age. We are going to receive the user's input. So we need a scanner. Let's say a scanner scanner is equal to new scanner. Let's pass system dot in. Also know that we know about object oriented 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 dot 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 while loop, let's say while short finish is not equal to true, continue looping. Inside the while 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 dot out dot print lines line after line. Or the better option is to use backslash and 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 backslash and this backslash and moves the cursor to the next line. The other one that I'm going to use in here is called backslash T. This backslash T will add a tab 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 dot 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 user's 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 dot get left eye dot 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 dot get left eye 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 backslash t backslash t in order to have two tabs. After that, let's say close or close the eye. Next, we need to get the user's input in case if it's one, we are going to close the eye. So let's say if scanner dot next int is equal to one, then we need to say patient dot get left eye dot close the 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 one in here in case the eye is not opened, we are going to show the option to open the eye. So let's say else, we need the same logic, we can print something backslash t backslash t one, open the eye. Next, we need to get the user's input, let's say if scanner dot next int is equal to one, we are going to say patient dot get left eye dot 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. So for example, in here, let's say get right eye. 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 dot get heart dot get details. After that, we are going to give the user to change the heart rate. For that, let's say backslash t backslash t one, change the heart rate. Once again, we need to listen for the user's input. So let's say if scanner dot 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 dot next int. After that, we can say patient dot 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 change to plus patient dot get heart dot get 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 dot get stomach dot get details. For the stomach, we had the digest option. So in here, let's show that option back slash t back slash t, let's say digest. Let's say if scanner dot next int is equal to one. If that's the case, let's say patient dot get the stomach dot 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 dot get skin dot get 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 these 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 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 heart 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 rates, 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 order to show the list of organs. And let's select four in order to see the stomach. We can see all of the details of the stomach. Let's digest some food. And as you can see, digesting has begun. 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 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 eye class, everything that is grayed 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 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 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 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 to store a list of different names, we could have said something like this, we could have said a string with a pair of a square bracket. After that, we could have named our array. And after that, we could have initialize 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 we 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 elements, we cannot assign a value to that. You can see that in here we have a red warning. And if we try to run our application, we get an exception. Let's see the exception. The exception in here is array index out of bound exception. Also, when working with simple arrays in Java, you don't have that much options. Later on, we will see that when we use different kind of collections, we can operate all sorts of operations on our collections, in which we do not have them in simple arrays. If we want to add a six element to our array, we can create a new array. And after that, we can copy all of the elements from inside this array. Right now for the situation that we have in here, if we want to add another item to our array, we can create another array with the size of six, after that we can copy all of these elements to that array. And after everything, we can add this new item. For example, in here, I can say a string array. Let's name it new names is equal to new string array with the size of six. After that, I can create a for loop let's say for int i is equal to zero i less than names dot length and i plus plus. Inside that for loop first of all, I need to add all of the names to this new names array. I can say new names with an index of i is equal to names with an index of i. This way, we can copy all of the elements from inside this names array to this new names array. After copying all of the elements after the for loop, I can say new names with an index of five is equal to Jerry. This way, we can get around this problem. For example, if I comment this line and run my application, maybe after that, print the six element inside our new names. We have a solution. But as you can see, this solution is not that much effective. Let's quickly print this. You can see Jerry has been printed in here. But as you can see, there are a lot of codes involved. And beside that, if your array has a lot of elements, for example, a million elements, this process can be really time consuming. Besides that, it can be resource consuming. If you are downloading this array from the internet. So this solution in here is not effective. Instead of copy and pasting the whole array, we are going to use collections. Let's delete all of these codes. In Java, we have multiple kinds of collections. The first of which I'm going to talk about in here is called array list. Let's quickly see that. So we type array list with capital A. After that, inside a pair of anchor bracket, or as some might call them diamonds, we need to define the type of our array list object. For example, I can say a string. After that, we need to name our array list. For example, I can say names is equal to new array list. As simple as that we have an array list. This is one way of defining your array list. There is also another way. Let's quickly see that. So instead of saying array list string, we can say list, you can see that the icon in here is different. It's an interface. We will talk about interfaces later on in the course. But for now, just know that there are two ways of defining your array list. Let's see how can we use this list to create an array list, we can say list of strings. For example, once again, let's name our list. For example, let's say students is equal to new array list. There is a slight difference in here. But I just wanted to show you both ways of defining your array list. Okay, let's delete this line for now. Right now, our array list is empty. And if you want to add some elements to this array list, we can simply say names, dot add, we can use this add method in order to add elements into our array list. For example, let's add one. You can use this add method as many times as you want. If I want to add another element, I can simply do that. So the first benefit of using array list is clear now, the size of array list is mutable. It means that we can change the size of our list. After adding some elements to your array list, you can get those elements by using the get method. Let's quickly see that. For example, let's print the first element. I can say names dot get, you can see that this get method requires an index. Once again, indexes in Java start from zero. So if I pass zero in here, it means that I'm going to get the first element. Right now, if I run my application, I should see Mason printed into the console, you can see that Mason has been printed. Also, when using array lists, you can also get the size of your array list. For example, if I want to print the size of my array list, I can say something like this, I can say names dot size, let's run the application and see what would be the result. You can see that the size of our array list is two, you have all sorts of options when using array lists, you can also clear all of the elements inside your array list. For example, I can say names dot clear, this clear method removes all of the elements inside your array list. After clearing, if I once again get the size of my array list, this time the size should be zero. And as you can see down in here, it's zero. If you want, you can also remove one element from your array list. Let's quickly see that I can say names dot remove this remove method requires an object. It means that we need to pass the whole element. So let's say Mason, for example. But before that, let me quickly comment this line because we don't want to clear our array list. And after removing Mason, let's print the first element inside our array list. Let's say names dot get, and let's pass zero as the index. As you can see, the first element right now is zero. It means that may some has been removed successfully. Let's see what other option do we have on our array list. Let's type names by typing dot, we can see the list of options. We can also check that if an option exists in our array list, for example, if I use this contains method, once again, it requires an object, let's say may some, let's print this whole line of code. This contains method returns a Boolean. So right now, if I run my application, because we have removed may some, we should see false. We can see that that's good. But if we change this to zero, we should see true. And through it is, you can also check that if your array list is empty or not. For that, you can print something. For example, you can say names dot is empty, we have this method. Once again, it's returning a Boolean. Right now we have zero in our array list. So it shouldn't be empty. And as you can see, we are receiving false. But if we remove zero before this line of code, we should see true. Let's quickly do that names dot remove. And let's pass zero. This time, you can see that true has been printed. You can also get the index of some element from inside your array list as well. Let's quickly see that before everything I'm going to comment all of these lines of code because I want to have a clear console down in here, let's say print names dot index off. And in here, I can pass my object. For example, I can pass may some right now may some is the first element. So we should see zero printed, you can see that it's zero. But if we don't have that element inside our array list, for example, if we pass Brad in here, we should see negative one. And as you can see, negative one has been printed. When you're using array lists, you can only have objects as the type of elements inside your array list. For example, in here, I cannot say integer, you cannot use primitive data types when you are creating a new array list. As you can see in the error in here, the error says that type argument cannot be primitive type. If you want to have an array list of different numbers, you can use the equivalent Java class. For example, in here, I can say integer with the capital I. And now I have an array list of integer. Right now, I am getting an error because I'm trying to add some strings to this integer array list. But you get the idea, we can use this integer class in order to have an array list. So in Java equivalent to every primitive data type, you have a class as well. We have seen this integer. Let's also check others. We can say Boolean. Similar to that, we can say long, we can also say double. And you can check the others yourself. But let's change this one to a string right now. The other option that you have when you're using array list is sorting different items. For example, if you want to sort different elements inside your array list alphabetically, you have that option. And the way to do that is like this. Let's see that down in here, we can say names dot sort. You can see that this sort method requires some comparator. Later on in the course, we will see this comparator. In fact, we will use this sort method in order to sort different elements in our array list. But for now, I'm not going to talk about this. I just wanted to say that you have this option. Okay, let's delete this. And let's move on from this part. Similar to simple arrays in Java, if you want to iterate through all of the elements in your array list, you can use for loops. Let's quickly see that as well. We can say for int I is equal to zero, I less than names that size this time, I plus plus. Inside this for loop, we can say print names that get with the index of I this way, we can print all of the elements in our array list. But before that, let's comment this line. And let's run our application. You can see that we can see both of our elements printed. Okay, that's enough talking about a release. Let's also talk about another kind of collection in Java called maps. Maps are useful for when you have some key value per data. Let's define a map and we will talk about what I mean by key value per. You can define a map like this, you can say map, you can see that map is an interface, we will talk about interfaces later on in the course, I believe in the next video. But for now, let's move on. You can also see that inside these anchor brackets inside these diamonds, we have this KNV, these two stands for key and values. So in here, if we say anchor bracket, for the first element, we need to pass the kind of key, the data type of our keys, for example, I can say string. And after that, we need to provide the data type of our values, for example, I can say a string once again for the data type of my values. Right now, I'm getting a red warning. And that's because it seems like the ID hasn't imported maps into my class, I can press alt plus enter. And if we take a look at above in here, it seems like we have imported maps into our class successfully. After defining the data type of your keys and values inside your map, you need to name your map. For example, I can say contacts. In here, I can say new maps. But if I do that, you will see that there are a lot of methods that I need to be worried about. There is a better way of defining your maps. Let's press Ctrl Z in order to undo the change. I can say new hash map. This time, you can see that this hash map is a class. And if we want, we can instantiate our map this way. This time, we do not have all of those extra methods. I don't intend to talk about hash maps in here. The topic is a bit technical, it's about the way that we are going to iterate through our maps elements. It's way above the talk that we have in here. I just wanted to say that you can instantiate your maps as different hash maps. Okay, now you have an empty map, which the data type of different keys is a string. And the data type of different values is a string as well. If you want to put some elements to this map, you can say something like this, you can say contacts dot put. This is the method that we are going to use in order to add some elements to our map. You can see that right now this put method is waiting for a key and also a value for the key. For example, I can pass a name, let's say maysam. And for the value, let's pass his email. Let's say maysam at maycode.org. This way we can add elements to our map. I think if I change the name of my contacts map to let's say email list that would be much more better. In order to change the name of some variable or class in Java, you have an option. You can select the whole name, you can right click on the name of your variable, you can go to this refactor in here, and you can use this rename or alternatively, you can use the shortcut which is shift plus f six. Let's select that. And in here, I'm going to delete this whole name, you can see that once I'm deleting this, it's deleting the name in both places. So let's say email list. And let's press enter. I think this name is much more suitable. Let's add another element to our map. Let's say email list dot put, let's say Brad. And let's say Brad at Gmail.com. Now that I have some elements in my map, if I want to have access to those elements, I can say something like this. For example, let's print this statement. Let's say email list dot. And once again, you can see that we have this get method which requires an object for the object in here, we need to pass the key. For example, if I pass Mesa, as the result, I should see the value of Mesa. In this case, I should see the email. Let's run the application. And let's see if we can print the email of Mesa. You can see that the email has been printed successfully. Like array lists, when you are using maps, you have all sorts of options. For example, if you want to get the size of your map, you can say something like this, you can say email list dot size. Let's run the application. And let's see if we can get to two has been printed. If you want to remove an item from your map, you can say email list dot remove. Once again, this remove requires an object. In this case, we need to pass the key. Let's pass Brad. And let's print the size of our map once again. This time after removing Brad, you can see that the size is one. You can also check that if some key exists in your map or not, the way to do that is like this. Let's print that first of all, we can say email list dot contain keys. Similarly, we have contains value, which you can guess it will check that if some value exists in your map. Let's try the first one contains key. And let's pass Brad in here, because we have removed Brad, we should see false. And as you can see, false has been printed. But if I change this to may some, we should see true. Okay, that seems to work fine. We can do the same thing for the values. Let's say email list dot contains value. Let's pass the may some email may some at may code dot org, because it does exist in our map, we should see true. And through it is, you can check other options yourself if you want, you can say email list dot. Once again, you can see that we have this clear option, it will clear all of the elements of your map, you have this is empty method, it will check that if your map is empty or not, the other option that you have in here is this values, you can see that this values method will return a collection. If you want to copy all of the values of your map, you can use these values and you can save it inside a collection. But I'm not going to do that in here. But to just show you, I'm going to say that there is an interface in Java called collection, this one in here, in which is the generic type of all of the collections available in Java. But more on that later on, when we sort different items inside our array lists, like array lists, you cannot have a primitive data type as the data type of your key or your values when you're using maps. For example, in here, I cannot say int. If you take a look at the warning, it says that type argument cannot be of primitive data type. Similarly, for the values, let's say int. Once again, you can use the equivalent Java class for these primitive data types, but you cannot just use primitive data types. Okay, let's roll back everything. Beside maps and array lists, you have other kinds of collections in Java as well. I don't want to talk about them in here because I think that for the Android course, these two are enough, and you don't need to know about others. But if you are curious, you can always check this Oracle webpage, you can see that we have sets lists and other kinds of collections. But honestly, these are not going to be helpful for our Android course, maps and array lists are just fine. As the data type of key values inside maps and also values inside the array list, you can also have different classes. Let's quickly see that as well. In my source folder inside the package, I'm going to create a new class called a student. Let's quickly see that. Inside this student class, I'm going to define two new fields, let's say private string name and private integer ID. Let's have a constructor and some getters and setters. Now that I have created this class, I can pass it as the data type of my array list. Let's quickly create another array list down in here, I can say array list of different students this time. Let's name this array list a student, let's say is equal to new array list. Now you can put as many as student as you want inside this array list. For example, let's say students dot add, let's say new student. Let's say may some with the idea of 15 maybe. So beside strings, other kind of customized data type is agreeable with the collections in Java. Okay, just before I finish off this video, I'm going to talk about for each loops in here. If you remember, when we talked about loops in Java, I said that there is another kind of loops called for each loop. I said that we are going to talk about for each loops when we know about object oriented programming and also collections in Java. So I think now it's a good time to talk about that you can create a for each loop like this you can say for instead of saying int i is equal to zero, I'm going to pass the data type of the list that I'm going to iterate over. For example, in this case, I'm going to say a student. After that, I need a name. For example, I'm going to say s. And after the name, I need a column. After that, I need the list or array list that I'm going to iterate. For example, in this case, I'm going to say students. Let's review everything once again. In here, first of all, we have passed the data type of the object that we are going to look into the name of that specific object is you can name it whatever you want. After the name, you should have a column. And after that, you need to pass the collection that you are going to look into. Inside this for loop, you can use this s in order to have some sort of operation on your object. For example, if I want to print the name of my students, I can say print s dot get name. Right now, our array list has only one student. Let's quickly add another. Let's say students dot add new student. Let's say Sarah with the idea of maybe 18. Let's run the application and see what would be the result. As you can see down in here may some and Sarah has been printed. So this s in here is like I in a for loop, but instead of being the index of the item, it's the item itself from time to times for each loops can be useful. And this is how you can create them. Okay, I think that's a good point to stop the video in here. In the next video, we are going to talk about some small concepts. For example, we will talk about this static keyboard that we have seen in the declaration of our main method. Besides that, if we had time, we will talk about inner classes, we will talk about interfaces and abstract classes. See you in the next video. In this video, we are going to talk about some small concepts that we need to know about. The first of those concepts is this static keyboard that we have seen so far in the declaration of our main method. I'm going to talk about that in another class. So let's create another class in my package. Let's name this class test class. You have seen inside the main class that we can have this static keyboard for our methods. But beside that, we can also declare our variables as a static as well. For example, in here, I can say public, let's say static. After that, I can say string, let's say name, we can see that it's working fine as well. I'm not sure if you have noticed or not, but as soon as I declared this string as a static, the style of this name has changed through italic. If I remove that you can see the difference. But what does it mean to have a static variable or a static method? Well, when you define your variables and methods as static, those methods and variables belong to the object itself and not to the instances of that object. We will see what I'm talking about. But before that, let's quickly have other variables in here. For example, I can say public int age, maybe another one public, let's say a string, a skin color. This variable doesn't mean anything. I just want to have some variables. Let's also create a constructor in here. Notice that when I use the IntelliJ generator to create my constructor, I do not see my static variable in this list. Once again, that's because the static variables do not belong to the instances of the object, it belongs to the object itself. Let's select these two. And let's create getters and setters. But as you can see, we do have a getter and setter for this static variable. Okay, now that we have this class, if we want to create an instance of that class, for example, from inside our main class, if we say test class, let's name it test class is equal to new test class, the constructor in here is waiting for an age and also a skin color, let's say 25 white, this way, we can create our instance of the class. But how do we assign a value to the name variable from inside our test class? Well, you can use the setter method. For example, you can say test class dot set name this method, and you can pass a name for example, may some but there is a warning in here this highlighted warning. What does that mean is that you can set a value for this name variable, even without instantiating your class. For example, in here, I can say test class with capital T dot, let's say name, or alternatively because the setter method for this name is static as well, I can say set name, let's use the first one, I can say test class dot name is equal to for example, Mesa, we can see that even without instantiating this object, we can assign a value to this variable. In order to make sure of that, let's move this two line of code to after assigning a value to the name variable, I can also delete this set name method safely. Now if I want to have access to the name variable of this test class, I can say something like this, I can say name plus test class this time with loyalty dot, let's say get name, let's run the application and let's see what would be the result. You can see that may some has been printed, even though we have set the value of this name variable before instantiating our object. So whenever you use a static variables, that variable will be the same in all instances of your class. For example, if I have another instance of this test class, for example, if I say test class, the second test class is equal to new test class, maybe another age and another skin color, let's say 30 black. If I print the name variable of this second test class, the result would be the same. Let's say second test class dot get name, or for that matter, we can say name, let's run our application. You can see that may some has been printed beside variables, methods can be static as well. Let's quickly define a static method inside our test class. Let's say public static void, let's name it print something. And inside this method, let's just print something. This static method like a static variable belong to the object itself and not to the instances of this object. For example, in here once again, I can say test class with capital t dot print something, you can see that we do not need to instantiate our object. If you run our application, you can see that something is printing. Okay, now we know the static variables and methods belong to the object itself and not to the instances of that object. But why would we want to use a static variables and methods? There are a few reasons for that. First of all, you may want to have a constant variable in all instances of your class. For example, imagine that you are creating a class for simulating different employees of a company. Inside that class, you may have some information about the employee, for example, the age, the name, email and everything. But beside all of those, you may have a field called company name. You know that in all instances of your employee class, the company name should be the same. For that matter, you may want to declare your company name field as a static. Also some say that using a static variables and methods is very memory friendly, because there can be only one instance of that variable or method in all of your application. So no matter if you have 1000 employees in your application, the company name field in all of those instances will occupy only some spaces as a string can. So using a static variables and methods is very memory friendly. But there is a downside when you are working with this static queue. Let's quickly see that inside our test class as well. Let's quickly create another method in here. Let's say public void. Let's name it print. Notice that this print method is not a static. And because this is not a static, now we cannot have access to that method from inside this print something method. For example, in here, I cannot say print, you can see we have a red warning in here, it says that non static method print cannot be referenced from a static context. Similar to non static methods, you cannot have access to non static fields inside a static method as well. For example, in here, if I try to print the age of this test class, you can see that we are getting a red warning in here. Once again, the warning says that non static field cannot be referenced from a static context. So you cannot use non static fields and methods inside a static method. Okay, I think that's enough talking about this static keyword. Let's quickly delete this class. Also, we need to delete all of these lines of code. Okay, now we know everything about this main method. First of all, its access modifier is public. It's a static method, its return type is void, its name is main. And also as the input of this method, we are receiving a string array called arguments. Because this main method is static, we know that there can only be one instance of this main method in our entire application. We are not concerned about the void in here. But we know that in order to run Java applications, we need a main method which is a static with this specific syntax. Okay, that's enough. Let's move on. The next topic that I'm going to talk about in here is inner class. Let's quickly see that in another class called test class. Inside our classes beside variables and methods, we can also have another class. And here is how we can define that class, we can say private, let's say class, I'm going to name this class test inner class. And here we have this inner class, like before inside this inner class, we can have other methods and variables. For example, I can say private string name in here, I can have a constructor for this class as well. Let's quickly see that you can see we can create a constructor, we can create all sorts of getters and setters. And we can treat this class as any other class in Java. But there are few differences between a class and an inner class. For example, if we have some fields in our parent class, let's define some, let's say private int age, and private string color, no matter what the access modifier of these fields are, we can have access to this inside our test inner class. But we need to do that inside another method, let's say private void, print age. Inside this method, I can say print, let's say age plus age, you can see that it's working fine. Even though the access modifier of this age is private, we can have access to that from inside our inner class. The same is for different methods of your parent class, no matter what the access modifier of those methods are, you can have access to them from inside your inner class. There are some times that you may want to use inner classes. For example, when you use inner classes, your code might be much more easier for us to follow. The other reason for using inner classes is that you can have this private access modifier at the declaration of your class. If you remember, we cannot change this public access modifier when we create our parent class. For example, in here, I cannot say private, you can see an error in here. And if you hover over that, you can see that modifier private not allowed in here. Besides private access modifier, you can also have a static classes. That is another benefit of using inner classes. You didn't have this option when you created your parent class. Let's quickly see that. If I say static in here, once again, modifier static, not allowed in here. So with inner classes, you can have private and static classes. In this course, we are not going to use inner classes that much. In fact, the first time that we are going to use it is when we know about async tasks. In most cases, we are going to define our async tasks as inner classes. We will talk about that later on in the course. Okay, I think that's a good point to stop the video in here. I did want to talk about interfaces and abstract classes in this video, but I think that's better to have that discussion in the next video. So see you in the next video. As I said at the end of the previous video, in this video, we are going to talk about interfaces in Java. interfaces are like a contract between two parts of your application. Let's see what I mean by that. You can create an interface like you have created a Java class, you can right click on your package by selecting new Java class. And down in here by selecting interface, you can have an interface. Let's name this interface car interface. If you take a look at your package, you can see that we have created this interface. And if you take a closer look, you can see that the icon for this interface is somehow different from the icon of classes in Java. This is the general schematic of an interface in Java. Like classes, interfaces lives inside the package, they have this public access modifier, we can name our interfaces whatever we want. And also they have this interface keyboard in their declaration. Inside interfaces, we can define our abstract methods. Let's quickly see an abstract method. I can say public, let's say void. After that, let's say print name. As the input of this method, let's just receive a name, let's say a string name. And that's it, you cannot have a body for your abstract methods. For example, in here, if I put a pair of curly braces, you can see that I'm getting a red warning. And the warning says that interface abstract methods cannot have body. So I can delete these two curly braces, and I can finish my sentence in here by using abstract methods, you are hiding the functionality of your methods. For example, in this case, we don't know what this print name method does. Instead, we are just defining some sort of contract. The contract in here is the signature of our method. We know that the name of this method is print name. We know that we are receiving a string called name. And also we know that the return type of this method is void. The signature of this method is a contract in which where we implement this interface, we are going to use this signature. Also, if you take a look at this public keyboard, you can see that it's somehow grayed out. If you hover over that keyboard, you can see that modifier public is redundant for interface methods. It means that it's not necessary in here. And the reason for that is because all of the abstract methods are public inside an interface. It means that you cannot have private or protected abstract methods. Inside your interface, you can have as many abstract methods as you want. For example, if I want to define another one in here, I can say void, let's name this one start. And I'm not going to receive anything as the input of this method. Let's define another one. Let's name this one move. And also let's receive an integer called speed. I created the first method so that I can show you how you can create abstract methods, and I'm going to delete that in here. So this car interface has two methods start and move. But how can we use this interface? Let's quickly see that as well. Inside my package, I'm going to create a Java class called electric car. And inside this electric car, I'm going to implement that interface that I just created. In order to implement that interface, I'm going to say implements at the declaration of my class. And after that, I need to provide the name of my interface. In this case, it's car interface. But once I do that, you can see that I'm getting a red warning in here. And for this red warning, we need to implement the two methods that we have created inside our interface. In order to implement those two methods, we have multiple options. First of all, we can click on this red light bulb. By selecting implement methods, we can implement the necessary methods. Or alternatively, if you don't see this red light bulb, you can click on the error. And by pressing alt plus enter, you can see the same dialogue. Or the other option is to come inside the declaration of your class. And by pressing control plus I, you can see the list of necessary methods. In this case, we have a start and move methods. Also, if you press control plus O, you can see the list of all of the methods that you can override. In here, you need to be a little bit careful because all of these methods are not necessary. The methods that are necessary are these two methods. If you take a closer look at the icon of these two methods, you can see that their icon is somehow not completed. These are the two methods that we need to implement or override. Let's select them. And in here, we have a body for this start and move method. It means that we can define the functionality for these two methods in here. For example, in the start case, I'm just going to print something. Because it's an electrical car, I'm going to say electricity flow started. Let's also define a field for this class. I'm going to say private string name. We can also have a constructor by pressing alt plus insert. Let's create that constructor. And let's also create getters and setters. Down in here, let's also define some functionality for this move method. Once again, I'm going to print something. Let's say this dot get name plus moves at some speed. Okay, now that we have created this class in which implements our interface, how can we instantiate our interface? For that, we can switch to our main class. And inside this main class, we can say car interface. Let's name it car interface is equal to in here, I have two options. First of all, I can say new car interface like we did for Java classes. But if I do that, you can see that we are overriding these two methods. Sometimes this might be our desired behavior. But in here, I'm not going to use this way. Instead, I'm going to say is equal to new electric car. This one, let's also pass a name, let's say Tesla, you can see that we are assigning a class to an interface. But how is it working? Well, because when we have created our class, we implemented this interface. Now, Java compiler is happy with assigning a class to this interface. Now that we have instantiated this interface, we can use its methods. For example, I can say car interface dot let's say start. And also let's say car interface dot move. We also need to pass a speed let's pass 60. Let's run the application. You can see that electricity flow started and Tesla is moving at 16 miles per hour. You can see that even though inside our interface, we didn't have any body, but we are printing some functionality when we call dot start method on our interface. If you want to make sure that this start method is happening inside your class, you can also print something else in here. For example, inside this start method, let's print the name of this class. I'm going to pass this. If you remember, I said that this refers to the current object. In this case, it's referring to this class. And right now if I print this, it will print the address of our class. Let's run the application. You can see the address of our electric car class. It means that this start method is happening inside our electric car class and not inside the interface. If you remember when we have talked about collections, we have defined array lists in two ways. One of those ways was to define our array list as list. For example, we could have said list, which once again, you can see that is an interface. For example, list of a string. Let's name it names is equal to new array list. Probably now you understand this syntax in here. It means that we have this array list class in which implements this list interface. If you want to make sure of that and see it for yourself, you can press down the control key on Windows, I believe it's command key on Mac. And by clicking on this array list, you can see the documentation for your array list class. Let's scroll a bit. Above in here inside the declaration of our array list class, you can see that we are implementing this list. Don't worry about this e in here, it means that we are going to accept any kind of object. But as you can see, we are implementing list. Okay, let's move on from here. Now that we have our interface, we can also have another class in which implements this interface. Let's quickly create another class. Let's say new Java class. Let's name this one fossil fuel car. Once again, in here, I'm going to say implements, let's say car interface, we need to implement two methods. Let's press control I, and let's select our two methods. Once again, let's define some functionalities for these two methods. For example, let's print something in here. Let's say explosion in cylinder cause the engine to start. Before I define some functionality for this move method, let's quickly add a field above in here, like before, I'm going to say private string name. Let's create the constructor and also getters and setters. After that inside the move method, I'm going to say this car is moving at some speed. Now that we have created this class, we can instantiate our interface inside our main class, like this, let's delete this line of code. In here, I can say car interface once again, let's name this one fossil car interface. Like before, I can say new fossil fuel car. Let's pass Mercedes in here, for example. Once again, you can see that Java compiler is happy with this way of instantiating our interface, because we have implemented this car interface inside both electric car class and also fossil fuel car class, we can instantiate our car interface in both of these ways. And after that, I can say fossil car interface dot start. And let's say fossil car interface dot move. Let's also pass some speed in here and let's run our application. You can see that both of these methods have been called in here. I have a point by defining two classes and implement the same interface in both of these classes. My point is that when you create an interface that interface is a contract between different part of your application. For example, in this case, I'm defining multiple kinds of cars. No matter what kind the car is, the contract says that this car should have a start and also a move method. So probably by now you can see the usage of interfaces. But there are a lot more two interfaces. For example, we can use something called callback interfaces. Callback interfaces are extremely useful for when you create event listeners like click listeners. And also they are useful for when you want to create some sort of connection between two different threads. We will talk about threads in the next video. Don't worry about that. We will see the use of interfaces. When we want to create a communication between two different threads. Also, it's worth noticing that you can implement multiple interfaces at the declaration of your class. For example, let's quickly create another interface in here. I'm going to name this one test interface. For this, let's just have a method in here. Let's say sorry for private, the abstract methods cannot be private. Let's say void print name. And let's receive a name. After I've created this interface inside, for example, my fossil fuel car, after implementing the first interface, I can add a comma. And after that, I can provide the name of my second interface. In this case, it's test interface. But once again, you can see that we are getting the error somewhere inside the declaration of our class, I can press Ctrl plus I, and I can implement my method. So you can have multiple interfaces implemented at the declaration of your class. Okay, I think that's enough talking about interfaces later on in the course, we are going to use interfaces a lot and their usage will be much more clearer. So hang in there. If something is vague, okay, let's delete all of these extra classes and extra interfaces. Let's also delete these lines of quotes. Now let's talk about abstract methods. For that, I'm going to create a new class inside my package. Let's say new Java class, I'm going to name this one test abstract class. If you want to make your class abstract, you need to add another keyboard between the access modifier and the keyword class. Let's add abstract in here, you can see public abstract class. And immediately after I've added this abstract keyword, if you take a look at your package, you can see that the icon for this class has been changed. This means that this is an abstract class. Inside an abstract class like interfaces, you can have abstract methods. Let's quickly see them. For example, I can say public abstract, let's say void, and let's name this one print name, let's receive a name string name. Once again, like interfaces, when you create abstract methods, you cannot have a body. For example, if I put a pair of curly braces, once again, I can see the warning in here, like before I can finish my sentence with a semicolon. The use of abstract classes is a lot like interfaces. But there are a few slight differences. For example, let's see the first difference. In here inside my package, I'm going to define a new class. Let's name this one test class. When we wanted to implement some interface, we could have set implements. And after that, the name of our interface, but when we want to use abstract classes, we can say extends, let's say extends test abstract class. Right now we are getting the warning again, by pressing Ctrl plus I, we can see the necessary method. So the first difference is between this extends and implement keyword. The other difference is that when you want to use abstract classes, you cannot extend multiple abstract classes. For example, in here, I cannot add a comma and add another abstract class. In another word, abstract classes does not support multiple inheritance. So that's the second difference between an interface and abstract class. The other difference is that inside your abstract class, you can also have non abstract methods. For example, in here, I can say public, let's say void, let's name this method print. Let's receive something in here. For example, let's say a string text. And because this is not an abstract method, we can have a body for this method. We didn't have this option inside an interface, we can have public non abstract methods inside an abstract class, like every other class, we can also have fields and maybe a constructor as well. For example, let's say private string name, let's create a constructor for this class, you can see that all is working well. So the other difference is that you can have fields constructors and non abstract fields. If you want to see the use of abstract classes like before, we can switch to our main class. And in here, I can say test abstract class, let's name it test abstract class is equal to new test class, the class that extends our test abstract class. After that, we can use the methods. For example, I can say test abstract class dot, let's say print name in here, we need to provide a name. Let's say Mason, but we didn't have any functionality inside our test class. Let's quickly define some functionality in here also know that I've switched to this test class because we have created a constructor inside our test abstract class, we need to create the constructor in here as well. But for the sake of simplicity, I'm going to delete all three of these, because I just wanted to show that these three options are available inside an abstract class. Let's print something inside our test class inside this print method. Let's just print a name. Let's run the application and let's see if we can see Mason printed into our console. You can see Mason has been printed. So once again, you can see that inside our test abstract class, we have this abstract method which does not have anybody. Instead, we have extended this class inside our test class, and we have declared the functionality inside this test class. You can see that there are a lot of similarities between interfaces and abstract classes. Sometimes the decision for using an abstract class or an interface can be hard. For that, let me show you an Oracle webpage in which may help you to decide better. You can see the address in here. I think if you check this webpage, it might be helpful. They say that use abstract classes when your classes are related to each other. Or the other case is that when you think that the class that is going to extend the abstract class may use some common methods or fields or also it may require some axis modifiers other than public such as private and protected. Or the other case is that when you want to declare some fields that are non static and non final, this option is also not available in interfaces. But they say that use interfaces when your classes are not related to each other. Or in cases that you want to use multiple inheritance, we can see that when we use interfaces, we can implement multiple interfaces. Once again, I suggest you take a look at this webpage, it might be useful. Okay, I think that's enough for this video. In the next video, we are going to talk about concurrency and threading in Java. See you in the next video. In this video, we are going to talk about concurrency in Java concurrency means doing things simultaneously and at the same time. For example, imagine that you are working with your phone and you are reading a book. At the same time, you may want to listen to some music simultaneously, you may be downloading some files from internet. This is called concurrency or doing things at the same time in programming. In Java, the first option that we have in order to create a concurrent programming is to create a thread. A thread is a unit of execution in your device as central processing unit or CPU. Basically, different threads come together inside something called a process. All of these processes will be handled by your devices CPU. By default, when you run your Java application, or for that matter, your Android application, a thread called the main thread will be created. Also, some might call this main thread, the UI thread, or the user interface thread as well. Later on, if you want to do some background tasks, for example, downloading a file, you will create a worker thread inside your main thread. The first option in Java that you have in order to create a thread is like this, you can say thread, let's name this thread is equal to new thread, like defining any other Java class. Let's finish our sentence in here. The constructor of this thread requires an interface. And that interface is the runable interface, we can pass that like this, we can say new runable, you can see that this runable is an interface. When you pass this runable interface, this run method will be created. Basically, this run method is the place that you put the code that you want to be handled inside a worker thread. For example, let's print something in here. And let's see if we can have a complete application. For example, let's say hello from another thread. In order to start this thread, we need to calm down after the declaration of our thread and say thread dot start. Let's run our application and let's see if we can see any result. You can see that our message has been printed into the console. But how do we see the difference between the main thread and this worker thread? For that, I'm going to write a piece of logic in here. For example, inside this run method, I'm going to create a for loop, let's say for int i is equal to zero, i less than let's say five and i plus plus. Inside this for loop, I'm going to print the value of this i. And after that, I'm going to sleep the thread, we will see how we can asleep the current thread. First of all, let's say print printing, let's say plus i plus, let's say in a worker thread. In order to sleep your thread, you have multiple options. The first one, and I believe the easiest one is to say something like this, you can say thread with capital T dot sleep. Inside the parentheses of this sleep method, you need to pass some numbers in milliseconds. For example, if I want to sleep my thread for one second, I need to pass 1000 milliseconds. This sleep method is going to cause our loop to wait one second for the next record. For example, in here, we are going to print zero. After that, we are going to wait one second. And after that, we are going to print one. But right now, as you can see, we are getting a warning in here. And the warning says that unhandled exception java dot lang dot interrupted exception. In the previous videos briefly, we have talked about exceptions, we will talk about them in this video later on. But for now, you just need to know that whenever an exception occurs, your application would crash. So because of that, we need to do something for this error in here, the easiest way to overcome this error in here is to click on the error and press plus insert. After that, select this surround with try catch, you can see that this code has been added. And our thread dot sleep method has been moved to this try block. Later on, we will talk about this spot. For now, let's move on from this part. And let's write the same logic inside our main thread so that we can see that the code inside the worker thread and the main thread can be executed at the same time. So basically, I'm going to copy this for loop, let's copy it from here. And inside the main thread outside of this run method, let's paste it. But in here, I'm just going to change this message to main thread. Let's run the application. And let's see if this code is going to work. As you can see, we are printing the value of I two times once in a worker thread and once in the main thread. It means that the code inside the worker thread and the code inside the main thread are happening at the same time. In this situation, we say that our application is asynchronous or it is concurrent. So once again, when you run your Java or Android application, one thread will be created by default in which we call that thread the main thread or the UI thread. After that, inside that main thread, you can create as many worker threads as you want. The simplest way to create a thread is to say thread thread is equal to new thread. And after that, we can pass a new runnable to the constructor of your thread in which we'll create this run method that will be executed in a background thread. But by this way of defining your thread, there are a lot of considerations that you need to be worried about. For example, you need to be worried about canceling your thread when the work is done. Also, there are all sorts of new concepts, for example, thread pools, deadlocks and interrupting your thread. I do not intend to talk about all of those concepts in here because in Android, we have all sorts of options available for handling background tasks. In fact, later on in the course, we have a complete section dedicated to handling background tasks in Android. We have options like async tasks, services, job scheduler and work manager, we are going to talk about all of them. But more on that in future videos. Okay, now let's talk about this interrupted exception that is happening in here. Basically, whenever an exception occurs, your application will crash and your application will be closed by the operating system. There are all sorts of exceptions that can occur. For example, the ones that we have seen previously, where arithmetic exception, null pointer exception, and the one that we can see in here is interrupted exception. So in order to avoid crashes, you need to do something about the exception. Let's comment all of these and let's see what we can do about the exceptions. Let's create an application in which we'll create an arithmetic exception. In here, I'm going to define two new integers. For example, let's say int a is equal to two, and int b is equal to zero. Let's print something in here, let's say print a divided by b. If we run our application right now, we should see an arithmetic exception. You can see that down in here. The thing that we can do about this exception is that to catch it whenever it happens. And we can do that by using a try catch block. Let's quickly see that. For example, I can say try. Let's move this line of code to inside our tri block. We can say try this in case some exception happens cash that exception. The kind of exception was arithmetic exception. So let's say arithmetic exception. Let's name this exception e. And inside the catch block, we can do something else with our code. For example, we can print something. In this case, let's say b was zero. Now if we run our application, we wouldn't get an exception. Instead, we are printing this message. Sometimes this message might not be useful. And in fact, in most cases, this message will be useful for debugging purposes, but it's much better than a crash. The kind of exception that we are catching in here is arithmetic exception. If we do not know the kind of exception, we can pass the generic term exception. If we pass this exception, it's going to accept all of the exceptions. If we run our application once again, we should see the same result. And here is the same result. The other kind of exception that we have seen so far was a null pointer exception that would occur when we do some operation on a null object reference. For example, if we had a string in here, let's say a string name is equal to null. If we do some operation on our name inside the tri block, for example, if we say name dot equals, let's say may some if we do that, we are going to get a null pointer exception because we have done this dot equals method on a null object inside the catch block this time instead of saying b was zero, let's say name was no. If we run the application, it's going to work fine because we are passing the generic term exception, but we can safely pass null pointer exception. Let's run the application, you can see that name was no. The other kind of exception that we just saw was this interrupted exception. It's going to happen whenever we interrupt the current thread. For example, imagine that inside a worker thread, you are downloading some file. At the same time, you may receive a phone call. If you don't cash the interrupted exception, you may get a crash. We have all sorts of exceptions. For example, we have all your exception, which stands for input output exception. We have class cast exception, we have all sorts of other exceptions in which we are going to talk about them whenever we face them. Also, on our exception, we have a useful method for debugging purposes. And that method is called print stack trace, we can say the name of our exception dot print stack trace, we will talk about this stack in future videos when we talk about activities and fragments in Android. But for now just know that this line of code in here is going to print something into our console that might be useful when you are debugging your application. Let's run the application in here. You can see the stack trace of your exception in here, it says that the exception occurred in line 34, which is this line. And you are also seeing the name of your exception. This is not an actual exception, you are just seeing some information about your exception. This in here might be useful for when you are debugging your application. Okay, I think that's enough talking about concurrency and exceptions in Java. In the next video, we are going to talk about singleton pattern in Java. See you in the next video. In this video, we are going to talk about singleton pattern. Basically, we use singleton pattern when we want to make sure that we have only one instance of some class in our entire application. In some cases, we may want such a thing. And here is how we can implement that pattern. For example, one case of using singleton pattern is when you are using a database in your application. Don't worry about the databases, we have a complete section dedicated to them. But in here, we are just going to create a simple Java class named database. Let's quickly create that inside our source folder inside our package. And we will see how we can implement that pattern. Let's name this class database. For this database class, I'm going to define a field, let's say private string name. Also, let's create a constructor and also getters and setters. Right now, because we have this public constructor, we can create as many instance as we want from this database class. But if you want to make sure that you have only one instance of this class in your entire application, you can create another field in here. For example, I'm going to say private static as the data type of this field, I'm going to specify the class that we are in. For example, in this case, I'm going to say database. So let's say private static database, make sure to import the one that comes from our package or that may code that singleton pattern. For the name of this field, it's convention to name it instance. And that's it. Now we can create a getter method for this field. And here is how we can create that field, we can say public, because we are going to use this instance inside this field, I'm going to say static, the return type of this getter method is going to be the class itself. So I'm going to say database, let's name this method, get instance, as you can see the suggestion in here, and let's have a body for this method. In here, instead of just simply passing this instance, I'm going to create an if statement, I'm going to say if let's say null is equal to our instance. If that's the case, I'm going to create a new instance, I'm going to say instance is equal to new database. Notice that we need a name for the constructor of this database. So I'm going to receive that name via the input of this method in here. Let's say a string name. And later on, let's pass this name in here. So if our instance is null, we are going to create a new instance. And after creating that, we are going to return it. We can say return instance. But in the other case, in case if our instance is not null, in the else case, I'm just going to simply return instance. Right now, if we use this get instance method, instead of this constructor, we are sure that we have only one instance of our database class in our entire application. For example, if we go to the main class, and if we try to instantiate our database, we can have only one instance, we can say database, let's name it database is equal to database with capital D dot get instance. Of course, we need the naming here. Let's pass a name. For example, let's say DB music. Notice that because we have declared this get instance method as a static. Now we can use this database class with this capital D. It means that we are not relying on the instance of this database class. Instead, we are using the object itself. But right now, someone can declare the database class as we did for any other class. For example, in here, someone can say database, let's name this one test database is equal to new database because in our database class, we have the constructor, we can pass a name in here. And if we do that, we have another instance of this database class. For example, let's say DB movies. In order to restrict users from using the constructor, I'm going to change the access modifier of this constructor inside my database class. I'm going to change this public to private so that this constructor would be available only from inside this class and not from inside any other class like this main class. Right now we have an error in here and the error says that the constructor is private. So by changing the access modifier from public to private, now we are restricting others from creating multiple instances of our database class. But because our constructor inside our database is private, we can use this constructor inside this get instance method as you can see in line 10 in here. Right now, because of this static keyword, and also because of this if statement that we have put in here, we are sure that we have only one instance of our database class. But there is also another point that we need to be worried about. And that's when someone tries to create multiple instances of our database from multiple threads. In some cases, if someone tries to create multiple instances of our class asynchronously, they might be successful in doing such a thing. In order to make our get instance method thread safe, we have an option in here. After this static keyword, we can add another keyword in which we haven't seen so far, we can say synchronized. This synchronized keyword will make our get instance method thread safe. It means that no more than one thread can call this get instance at the same time. So this is the whole single tone pattern. First of all, you declare a static field of the kind of your class, for example, in this case, database, after that, you create a get instance method in which is static once again, and also synchronized. Inside that get instance method, you are checking that if the instance of your database is null or not. If it is not, it means that it's the first time that you are calling this get instance method. So you need to create a new instance like we are doing in line 10. After that, we are returning the instance. But in the else case, we are not going to create a new instance, we are just going to return the existing instance. Besides this get instance method in order to restrict others from using the constructor, you need to change the access modifier of your constructor to private so that it would be usable only inside your database class. We can also make this if statement shorter. For example, in here, I can delete this whole else case. And I can delete this return instance from line 11 in here. And after the if statement, I can return that instance. So by the time we reach to this line 13, in which we are returning the instance, we are sure that our instance is not now, and we are returning either a new instance or the existing instance. Okay, I think that's enough talking about the singleton pattern. Later on in the course, you will see that this pattern might be useful from time to time. Before I finish off this video, I'm going to talk about one more methods available in every class in Java. And that method is called to string. Right now, we don't have any two string method inside our database class. But if we switch back to the main class, and if we say print, database dot to string, you can see that we have such a method. And if we run our application, we should see some information about our database class. Let's quickly run it. And let's see if we can see any result. You can see that we are getting the address of our database class. If you want, you can change this. For example, inside your database class, you can override the two string method down in here inside the scope of our class, we can press control plus all. And from here, we can select this two string method. Right now we are returning the super statement. If you want to change that we can delete this whole statement and we can prepare a string in here. For example, we can say a string text is equal to let's say database class. After that, let's add a line. And after that, let's print the name of our database. Let's say name plus this dot name. After creating this text, we can return it. For example, we can say return text. Now that we have overrided this two string method, if we run our application, we should see some other results printed into our console from time to time, this two string method can be useful as well. It's available in every Java class. And basically it will print some detail about that class. Okay, I think that's enough for this video. And for that matter, I think that's enough talking about Java, our Java section is done. And hopefully we have learned a lot. In the next video, we are going to have a quick challenge in order to make sure that we have learned everything that we have talked so far. But before I finish off this video, I'm going to say that with Java, you can do a lot of things. For example, besides writing Android applications, you can use Java in order to create desktop applications for Windows, Linux, and macOS operating systems. And also with the help of a spring framework, you can use Java in order to create enterprise web applications. There are much more to Java language. For example, you can use Java in order to create applications for quantum computers. You can also use it for data analysis purposes and literally everything else that you want. In this course, we have touched the surface of Java language. But if you want to know more, I'm currently recording a new course for Java language. And I'm sure that you will find that course helpful. Besides the Java course, I plan to record a complete course for a spring framework in order to create web applications. By the time you are watching this video, those courses may be released. So make sure to check them. Okay, I think that's enough in the next video. As I said, we are going to have a quick challenge. See you in the next video. Here is our final challenge for the Java section. I want you to simulate your phone's contacts and messages applications. Here is how our application is going to work. First of all, we are going to grid the user with some message. After that, we are going to show three options to the user. One for managing the contacts, another one for handling the messages, and another one for quitting the application. In case if the user selects the first option, which is managing the contacts, we are going to show these options. One for showing all of the contacts, another one for adding a new contact, another one for searching for a specific contact. One more for deleting a contact. And the last one is to go back to the previous menu, which was these three options. But in case if the user selects the second option, which is handling messages, we are going to show these three options. The first one is to see a list of all of the messages. The other one is to send a new message. And one last one, in order to go back to the previous menu, in which is our initial menu, which has three options. In case if the user selects these third option, we are going to quit the application. We haven't talked about databases and permanent data storage, but as a hint, if you want to store contacts and messages, you can use a static variables. Okay, pause the video in here and go solve the challenge. After that, come back and let's see my solution for this application. Okay, let's quickly see how can we create this simple application. First of all, I have created my project. And I have created this package inside my source folder. Inside this package, I have created this main class in which contains this main method. Let's continue from here. First of all, I'm going to create a new Java class called message. Inside this message class, I'm going to have three fields. Let's say private string text. Another one, let's say private string recipient. This recipient in here is going to be the name of our contact. Also in here, I'm going to define an integer called ID, let's say private int ID. This ID is not necessary for this application in here. But because in most cases, when you are working with databases, you have a column called ID in order to identify every unique message. I want to be as close as I can to a real world application. I just wanted you to see this ID field inside a model in which is a message. Okay, now that we have these three fields, let's quickly create a constructor. And let's accept all of these three fields. After that, let's create getters and setters. I'm not sure that we are going to need all of these getters and setters later on if we didn't use them, we will delete them. Also inside this message class, let's quickly create another method called get details. Basically, we are going to print the details of every message. So let's say public void. Let's name it get details. Let's say print. First of all, let's say contact name. And let's print the recipient. After that, let's print the text itself. Let's say message plus the text. We also need to add a plus in here. Sorry about that. And I think if we add a backslash n in here, it would be much better. After the text, let's also print the ID. Let's say backslash and ID plus our ID. That's it for our message class. Let's quickly create the contact class as well. New Java class, let's name this one contact. Inside this contact class, I'm going to have four fields. Let's say private string name private string number. You may think that this number should be an integer or maybe a long but because different numbers can have different formats. For example, they can have some parentheses or maybe some hyphens. I'm saving this number as a string. But if you want, you can always use integers or long. After name and number, I'm going to save another field in here. Let's say private string email. And after all of this, I'm going to have another field in here, let's say private array list of different messages. Let's name this one messages. So basically, I'm going to save different messages for every contact inside an array list. Okay, now that we have our four fields, let's quickly create our constructor. But in here, I'm going to create two constructors. Because at the time of creating a new contact, that contact does not have any messages. For that, I'm going to create another constructor in here, which will not accept an array list of different messages. This time, let's select the first three items. But because if I don't do anything about these messages, this array list will be null. Inside this constructor, I'm going to say this dot messages is equal to new array list. So at the time of creating a new contact, I'm saving the messages array list as an empty array list. Okay, now that we have two constructors in here, let's quickly create getters and setters. And also after that, let's create a get details method. Let's say public void, get details. We can also use two string methods. But in here, I'm just more comfortable with this get details method. Let's print all of the information about each contact. Let's say name plus this dot name. After that, let's print the number and email. Okay, that's it for our contact class. Let's switch to main class. And let's write the logic for our application. First of all, in here, I'm going to create an array list of different contacts. But I'm not going to do that inside this main method, because we are going to have multiple methods, and we need to have access to our contacts array list in different methods. For that, I'm going to define my array list above in here in the fields of this main class. I can say private static, because the methods that I'm going to use later on are static methods, I need to create this array list as a static. So let's say private static array list of different contact. Let's name it contacts. But this is not a good place to initialize our contacts array list, because this is not the place that our code will be started. We can initialize our contacts array list, for example, inside this main method. But before I do that, I'm going to also define a scanner in here, because we are going to need the scanner in multiple methods. So let's say private static scanner, let's name it scanner. After that, inside the main method, let's initialize our contacts array list. Let's say contacts is equal to new array list. As you can see in here, I'm going to greet the user with some message. Let's just print something. After that, I'm going to show these three different options to the user. Because I want to have a clean code, I'm going to show these three options inside another method. Let's name that method show initial options. But as you can see right now, I'm getting a red warning. And that's because I need to create this method down in here. So let's say private static void, show initial options. Let's print the options in here. After that, we need to get the user's input. And for that, we can use the scanner. So let's initialize our scanner. Right now, we have declared our scanner above in here, but we never initialized it. It's a good place to initialize our scanner in here. We can say a scanner is equal to new scanner. Let's pass system dot in. After that, we can say int choice is equal to scanner dot next int. Let's create a switch upon this choice. Let's say switch on choice. In case the choice is one, we are going to manage the contacts. Once again, let's do that in another method. Let's say manage contacts. Don't worry about this red warning, we will create this method later on. Let's also add a break in here. But in case the choice is two, we are going to handle the messages. So let's say manage messages. In case the choice is three, or for that matter, any other number, we are going to quit the application. So in here, I can say default. In the default case, I'm just going to break out of the application. Let's minimize this project pain for now. And down in here, let's create our two methods. First of all, let's manage our contacts. Let's say private static void, manage contacts. Once again, in here, I'm going to show a list of options. So let's print those options. Once again, we need to get the user's input for that we can use the scanner. Let's say int choice is equal to scanner dot next int. Notice that we are not initializing our scanner in here. And that's because we have done that inside this show initial options method. So by this time, we have an instance of our scanner. After that, once again, we need to create a switch on our choice. In case it's one, we are going to show all of the contacts. Let's create that method. Show all contacts. And also we need a break. Let's also write the rest of the cases. In the default case, I'm going to go back to the previous menu. So I'm going to once again, run this show initial options method, so that we can see all of these options once again. So in the default case, I'm going to say show initial options. After that, in here, we need a default as well. I'm saying default in here because I'm going to go back to the previous menu, in case if the user enters any other number. Okay, let's create these methods one by one. First of all, let's show a list of all of the contacts. I'm going to do that down in here. Also, instead of writing the declaration of your method, you can use the help of your ID. For that, you can click on the red error in here. And by pressing alt plus insert, the first option is to create this method. You can see that we have created this method successfully. The void is fine for the return type. And down in here, I can create the logic for this method. In order to show a list of all of the contacts, I'm going to simply create a for each loop. Let's say for contact, let's name it see inside our contacts area list. Let's just say c dot get details, the method that we have created inside our contact class. After the for loop, once again, I'm going to show the initial options. For that, I'm going to say show initial options. We are going to quit the application when the user tells us. That's all we need to do inside this method. Let's just minimize it for now. And let's create the second method, which is add new contacts. Once again, we can use the help of our ID inside this add new contact method, we are going to receive some users input. But before that, let's print something. Let's say adding a new contact. After that, let's say please enter the contacts name. Once again, we are going to use our scanner. Let's say a string name is equal to a scanner dot next. After we get the contacts name, we are going to get the contacts number. So once again, let's print something in here. Let's say please enter a contacts number. Let's say a string number is equal to a scanner dot next. Let's also get the contacts email, a string email is equal to a scanner dot next. After that, we need to make sure that the user enters something as the name, number and email of our contact. And don't just press enter and leave us with empty strings. For that, I'm going to create an if statement in here, let's say if name dot equals an empty string, let's say or if number dot equals an empty string, or if email is equal to an empty string. If each one of these is true, we are going to show some message to the user, we are going to ask to enter all of the required information. Let's say please enter all of the information. After printing this line of code, I'm going to recall this whole method, I'm going to start from the beginning of this method. For that, I'm going to say add new contact. I'm calling this method from inside the method. This is called a recursive call, you can see the icon at the left side in here. If you hover over that, you can see the recursive call calling a method from inside that method. So by this way of calling our method, we are starting once again from the beginning of this method. But in the else case, we are going to create our contact object. I'm going to say contact. Let's name it contact is equal to new contact. And after that, I'm going to pass name, number and email. If you remember inside our contact class, we had two constructors. And in here we are using the second constructor. We didn't pass any messages early list to this constructor in here. After creating our contact object, we can say contacts, our early list dot add. Let's pass our contact as simple as that. Now we have added a new contact. After this if statement, once again, I'm going to show the initial options. So let's say show initial options. Because once again, we are not going to quit the application unless the user tells us so. Okay, we are done with our second method. Let's see what else do we have in here. Let's create this search for contact method. The void is fine for the return type. Inside this method, first of all, we are going to ask for the name of the contact. So let's print something. Let's say please enter the contact name. Let's say a string name is equal to scanner dot next. After that, we need to make sure that we have received a name. So let's say if name dot equals an empty string, we are going to print some message, we are going to ask for the contact name once again. Let's say please enter the name. And after that, once again, we are going to use a recursive call. We are going to say search for contact once again. But in the else case, we are going to search for this contact inside our contact array list. For that, once again, I'm going to create a for each loop. Let's say for contact, let's name it C inside our contacts array list. Let's say if C dot get name is equal to the name that we just received. If that's the case, let's print C dot get details. Let's also define a Boolean before this for loop. We will see why I'm defining this Boolean. Let's say Boolean, let's name it does exist. Let's initialize it to false. In this if statement where we have found the contact, first of all, I'm going to change the value of this does exist to true. Let's say it does exist is equal to true. And after the for loop, I'm going to create an if statement, I'm going to say if does exist is not equal to true. Then we are going to print something. I'm going to say there is no such contact. After all of these logics, we are going to show the list of options once again. So let's say show initial options. Okay, that's it for our search for contact method. Let's also create this delete contact method. Once again, in here, we are going to ask for the contacts name. So let's say please enter the name, like before, let's say a string name is equal to a scanner dot next. Next, we need to create our if statement if name dot equals an empty string. We are going to ask for the name once again. And we are going to start from the beginning of this method. In the else case, we are going to look into our contacts are released. So let's say for contact see inside our contacts are released. Before I write the logic, let's also define a Boolean above in here like we did for the search for contacts method. Let's say Boolean does exist. Let's initialize it to false. So in here, let's say if I don't know why I set s in here, let's quickly change this one to see. So let's say if see that gets name is equal to the name that we have received. If that's the case, first of all, we are going to change the value of this does exist. Let's say it does exist is equal to true. After that, we are going to remove this contact from our contacts are released, we can say contacts dot remove. This remove method requires an object which I'm going to pass see the object that we are currently looking in this iteration. After the for loop, I'm going to say if does exist is not equal to true. Then we are going to say there is no such contact. And after all of these logics, we are going to show the list of all of the initial options. Okay, that's it for this method, let's minimize this one. So far, we have created the logic for the first option in our initial options. We have created the whole logic for this manage contacts. But right now in the logic for this manage contacts option, we have one or two possible point for multiple bugs. We are going to fix those two. And also we are going to write the rest of the logic for this application in the next video. See you in the next video. In the previous video, we have created the logic for this manage contacts option. But if you remember, I said that we have some issues right now with this manage contacts logic. And in this video, first of all, we are going to fix those issues. The first issue is inside this add new contact method. In here, we are adding the contact into our contacts array list. But before that, we need to make sure that we do not have a contact with this name saved on our device. For that before adding this contact to my contacts array list, I'm going to check that if I have such a contact on my device. So first of all, let's create a Boolean in here. Let's say Boolean does exist. Let's initialize it to false. After that, I'm going to create a for each loop. Let's say for contact C inside my contacts array list. Let's say if C dot get name is equal to the name that we just received. Inside this if statement, I'm going to change the value of this does exist to true. So let's say it does exist is equal to true. After the for loop, I'm going to check that if this does exist is equal to true or not. Let's say if does exist is equal to true. Then we are going to print something we are going to say, we have a contact with this name. After that, we are going to start from the beginning of this method. So I'm going to call this add new contact method once again. But in the else case, I'm going to add the contact to my contacts array list. So I'm going to cut this line of code from here. And I'm going to paste them inside this else case. Also after adding the contact to our contacts array list, I'm going to show some message to the user. So let's say name added successfully. Okay, that's the fix that we needed inside our add new contact method. Let's also change the show all contacts method a little bit as well. So inside this for each loop after printing the details of a contact, I'm going to print another line. And this line is going to be just a separator that will indicate the difference between different contacts. Nothing special in here. Okay, let's move on. And let's create the method that we haven't created in here. This manage messages method by pressing alt plus insert, we can create that method. First of all, we are going to show a list of options. So let's print something. After that, we need to receive the user's input, I can say int choice is equal to a scanner dot next int. And let's create our switch statement on this choice. In case it's one, we are going to show a list of all of the messages. So let's say show all messages. We will create that method in a minute. But in here, let's add a break. And let's write the other cases. In case it's two, we are going to send a new message. So let's say send new message. And let's add a break. In the default case, I'm just going to show the initial options. After that, in here, we need a break as well. Okay, let's create this show all messages method. In here, first of all, I'm going to save all of the messages from all of the contacts into an array list. So let's say a list of different messages. Let's name it all messages is equal to new array list. After that, I'm going to create a for each loop for contact C inside my contacts array list. Let's say all messages dot add all, we haven't used this add all method. But in here, we are going to do that. I'm going to say C dot get messages. So by using this add all method, we are adding all of the messages of one contact to our all messages array list. After the for loop, I'm going to check that if the size of this all messages is zero or not. So let's say if all messages dot size is greater than zero, I'm going to show the details of every message. So for that, I'm going to create another for each loop in here, let's say for message, let's name it m inside our all messages array list. Let's print m dot get details. And after that, let's also print some separator. But in the else case, I'm going to say that you do not have any message. After everything after the if statement, I'm going to show the initial options. Okay, that's it for this show all messages method. Let's also create the other method which is send a new message. In here, first of all, I'm going to get the contact or recipients name. So let's ask the user that let's say who are you going to send the message. After that, we need to get the name of our contact. So I can say a string name is equal to scanner dot next. After that, we need to check that if this name is empty or not for that I can say if name dot equals an empty string, we are going to ask the user to enter a name. So let's say, please enter the name of the contact. After that, we are going to have a recursive call. So in here, I'm going to say send new message. But in the else case, I'm going to check that if we have such a contact in our contacts array list. For that, I'm going to define a Boolean in here Boolean does exist is equal to false. After that, I'm going to create a for each loop, let's say for contact see inside our contacts array list. If C dot get name dot equals the name that we just received, let's say it does exist is equal to true. After the for loop, I'm going to check that if does exist is equal to true or not. First of all, let's write the else case. In the else case, I'm going to say there is no such contact. But inside the if block, if we do have such a contact, we are going to ask for the message itself. So let's say what are you going to say? Let's say a string text is equal to scanner dot next. After that, we need to make sure that this text is empty or not. Let's say if text dot equals an empty string. If that's the case, let's say please enter some message. And after that, we are going to start from the beginning of this method. So let's say, send new message, which once again is a recursive call. But in the else case, we are going to create our message object. And after that, we are going to add it to the contact that exists in our contacts array list. But if you remember inside our message class, we had a field called ID. Basically, whenever you are receiving these messages from a database or maybe a web server, this ID is unique to every message. In here, I'm trying to be as close as I can to a real world application. So I'm going to make this ID unique. In order to have a unique ID for every message, I'm going to define a field above in here inside my main class. I'm talking about here. And after that, we will increment the number of this ID by one every time that we create a new message. For that, I'm going to say private static integer. Let's name this one ID, and let's also initialize it to zero. After that, down in here, when we create our message object, inside this else case down in here, I can say ID plus plus. So because this ID is a static integer, whenever we increment its value, it's going to be unique for every message. So right now we have the name of our recipient, which we have received above in here. And also we have the message body, which is this text. And also we have generated this ID, which is unique. These are the three things that we need in order to create our message object. I can say message, let's name it new message is equal to new message. We need the text. After that, we need the recipient, which is name. And after that, we need the ID. Next, I need to find the proper contact to add this message to his or her area list of different messages. For that, I'm going to create a for loop. Let's say for contact, see inside our contacts area list. Let's say if C dot get name is equal to the name that we received. If that's the case, first of all, we need to get the array list of different messages of this contact. For that I can say array list of messages. Let's call this array list new messages is equal to C dot get messages. After that, we need to add this new message to this new messages array list. So let's say new messages dot add new message. Sorry, I have used this add all method, we need to remove this all. After that, we are going to save the current contact that we are looking into. Because later on we are going to remove this contact from our contacts array list. And we are going to update his or her array list of messages. And after that, we are going to add it once again to our contacts array list. So for that, I can say contact. Let's name it current contact is equal to C. Next, we need to say current contact dot set messages. And we need to pass our new messages array list. After that, it's time to remove the C from our contacts array list. We can say contacts dot remove. And we can pass the C object. Now that we have removed the previous contact, we can add the new one by saying contacts dot add. Let's say current contact. So this way we have added this new message to our specific contact and we have updated our contacts array list. Okay, that's the entire logic that we need in order to add a new message. Just after everything, after we are done with this method, we need to show the initial options once again. Let's minimize this method. And let's see what else do we have. I think we have covered everything and we are ready to test our application. So let's run the application. In here, we are seeing the greeting message, which is fine. After that, we are seeing the initial list of options. If we select one, we can see the options for managing different contacts. Right now, we do not have any contact in our array list. So if we select one, you can see that we are not seeing anything. It's better to print some message in here in case if we do not have any contact in our phone. For example, that says you do not have any contact on your device. But we will write that later on. For now, let's just see the other options. Once again, let's select manage contacts. This time, let's try to add a new contact. You can see that the console is waiting for a name, let's say may some the console is waiting for a number. Let's add some number. After that, we need to provide some email, let's say may some at gmail.com. And as you can see, may some added successfully. If you want to make sure of that, once again, you can check the list of all of your contacts by saying show all contacts. And in here, you can see the details of may some. Let's also add another contact. Let's say Sarah this time. Let's add a random number. After that, an email. This time, let's try searching for a new contact. So in here, if I say three, you can see that the console is waiting for the name of our contact. Let's type Brad in here. You can see that we are seeing this message. There is no such contact in your phone. Once again, let's try searching for a contact this time. Let's try Sarah. You can see that we are seeing the details about Sarah. Let's also try removing one of the contacts. Let's say for in order to delete a contact, let's say may some in here, we are not seeing any message indicating if that we have deleted may some successfully or not. But if we check the list of our contacts, we should see only Sarah. And as you can see, we have only Sarah in our contacts list. Let's also try this go back as well. So let's say manage contacts once again. This time, if I put any number beside one through four, for example, if I say six, you can see that we are going back to the main menu. Also, let's try adding a new contact with empty values. Sorry about that, I need to go back and select one. Let's say two in order to add a new contact. Let's don't provide anything for the name. You can see that the scanner is waiting for some input. But even if the scanner moves to the next line, we have write the logic in order to prevent adding an empty contact. Okay, that's good. Let's add me some once again. Let's add some number and some email. Let's see what we have inside the messages option. In order to see a list of all of the messages, let's press one. You can see this message, you don't have any message. Once again, let's go to the messages option. I entered two in here and let's try sending a new message. Who are you going to send a message? Let's say Sarah. What are you going to say? Let's say hello. It seems like we are getting a crash. And the crash happened because of this exception. Can current modification exception? Okay, let's take a deeper look into our code and let's debug our application for the first time. It seems like the exception occurred when we tried to add the new message. Also, you can see the line 99 in here. If you click on that, you will be navigated to that line. Yes, we have this exception inside the add new message or send new message inside this for loop. I think the error in here is happening because first of all, we are using this C to assign a new value to this current contact. And immediately after that, we are trying to remove this contact from our contacts array list. So this caused the concurrent modification exception. If you want to get over that exception, you can simplify this if statement. For example, in here, I'm going to delete all these three lines of code. So by this point, we have this new messages array list. We have added our new message to this array list. And after that, in order to update the array list inside this contact, I can say C dot set messages. And I can pass my new messages array list. So no need for removing and adding a new contact into our array list can currently let's run the application once again. And let's see if we are seeing the exception once again. First of all, we need to add a contact. So let's say manage contact, add a new contact. Let's provide a name and number after that some email. And now we can send a new message. Let's say messages, send a new message. Who are you going to send the message? Let's say may some. What are you going to say? After this line of code, we got the exception. Let's say hello. And this time, it seems like we have added or we have sent a new message. If you want to make sure of that, you can go to the messages option. And you can show the list of all of your messages. You can see that we have one message in which we have sent it to Mesa. Okay, that seems better. Once again, let's go to this messages option. And let's try going back to the main menu. So if I type three or any other number beside this one and two, we should go back to the main menu. For example, let's say four. And as you can see, we are seeing the initial options. For the last thing, let's try quitting our application. And as you can see, we have created the application successfully. Let's just fix the few errors that we had in the show all contacts method. If you remember, I said that we are going to show some message in case if we don't have any contact in our array list. So for that, first of all, I'm going to check that if we do have any contact. For that, I'm going to say if contacts that size is greater than zero. First of all, let's write the else case. In the else case, I'm just going to print. You do not have any contact. But in the if block, we are going to do the same thing that we were doing previously. Let's run the application one more time in order to see that these changes were effective or not. So right now, we do not have any contact in our contacts are a list. Also, you may be wondering why we are losing the contacts that we are keep adding into our application. That's because we are not using any permanent data storage like a database. We are using a static array list and that array list will be cleared when we close our application. For that reason, all of the contacts are being removed whenever we stop the application. So let's say manage contacts. And let's say show all contacts, you can see the message in here, you do not have any contacts. But it's better to show the list of initial options. Once again, after we print this line of code. So down in here, after this print statement, let's say show initial options. Okay, this was the last video of this section. And this was my solution for this challenge. Your solution is probably different than me. And that's okay, because there are multiple ways of creating the same application. Hopefully, you have practiced and learned everything that we have talked about in this section. In the next section of the course, we are going to switch back to Android studio and we are going to talk about user interface and how we can design a beautiful layout for our application. See you in the next section. What's up, everyone, I hope you're having fun. Before we start our talk about user interface, I just wanted to remind you that there is an extended version of this course that you can watch by enrolling in the extended course, you will have lifetime access to more than 60 hours of videos, you can ask your questions directly from me, and I will come back to you within hours, you will have access to all of the source codes that I write in the videos and also you can have access to all of the new videos that I upload. Just check out my code dot org format details about the course and don't forget to use free code camp as the coupon code to get 20% discount. If you want to get serious in Android app development, taking the extended course is almost a necessity. Okay, everyone, I just wanted to remind you that there is an extended version of this course that you can take without further ado, let's start our talk about user interface have fun learning. Hello, everyone, and welcome back. This is the user interface section of our course. And we are going to talk about a lot of concepts and tools that we have related to user interface. We are going to talk about a lot of UI elements and their attributes. We are going to talk about different kind of event listeners, for example, click listeners on different UI elements. We will talk about how can we create applications that is compatible with different screen sizes and also different languages. Besides that, we will also talk about material design and all sorts of stuff in the section of the course. Without further ado, let's jump into our project and let's implement some UI elements. As you can see, I'm no longer using IntelliJ IDE and I've switched to Android Studio. We needed IntelliJ IDE for the Java section of the course. But in here, we can switch back to Android Studio. Just in case if you forget how to create a new project in Android Studio, I'm going to start from scratch. Let's say start a new Android Studio project. In here, we needed to select a template. If you remember, I said that these templates are some applications written to some level later on in the course specifically after we talked about activities, we will see that how can we create all of these from scratch. But for now, let's just select this empty activity. After that, in here, we needed to name our project. For example, for this application, I'm going to say UI basics. I'm going to stay with this package name. I think it's fine. We needed a save location. Once again, the default is fine. And for the language, I'm going to say Java. For the minimum API level, as I said in previous videos, in the most videos for this course, I'm going to say with API level 19. After selecting all of this, let's just create our project by clicking on this finish button down in here. It seems like our project has been created successfully. Now that we know about Java, let's have another look at this class that we have created in here. But before that, let's minimize this run pain. As you can see, this is a Java class in our package. You can see that it's a class called main activity. This class is extending the app compact activity, whatever that is. Inside this class, we have this on create method, which is overrided, you can guess it probably because of this app compact activity. And also above in here, we have some imports. Right now, we are importing this app compact activity and also this bundle. Don't worry about this, we will talk about them later on in the course platform. Now you can see the general syntax of a simple Java class in here as well. If you remember, I said that when you create an activity, a Java class and also a XML file will be created. The Java part is responsible for the behavior of your application. For example, in your layout file, you may receive the user's input. In the Java file, you may decide to what to do with the user's input. Hopefully now that we know about Java, we can understand all of these much better. This on create method is a part of something called the activity lifecycle. We will talk about that in future videos. But for now, just know that this on create method is somehow like the main method inside a simple Java application. This is the start point of every activity. And right now, because our application has only one activity, this is the start point of our entire application. So this line 13 in here would be the start point of our code. You can see this super statement in here. Once again, it means that do whatever you are doing inside the parent class. In this case, the parent class is this app compact activity. For the time being, we are not concerned about that. But as you can see, we are passing this same instance state, which is a bundle to the super statement. Later on, we will talk about that. Also, it's important to know that inside activities, you have some inner methods, we didn't have this option in Java. For example, you can see this set content view method. You don't see the declaration of this method anywhere inside this class. But you can see that by using it, you are not getting any red warning. Similar to this set content view, we have a lot of other inner methods inside an activity. We will talk about them later on in the course. Okay, let's move on from this part. And let's start working on our user interface. I just wanted to have another look at our application and specifically this Java file. Now that we know about Java. Okay, let's close this Java file. And let's start talking about this activity main dot XML file. If you remember, in the first videos of this course, I said that XML is a markup language. Once again, if you are a web developer, you know the concept of markup languages. Those are just helpful for defining some elements that are going to be shown to the user. Before everything, let's quickly locate this file in our project. Right now we are inside the Android view. And if you want to find this activity main dot XML file, you can come to this resources folder. Down in here inside the layout folder, you can see the file. And if you switch to project view, you can go to your application folder inside the app folder inside the source folder. You have this main folder. And in here you have the resources folder. Once again, inside the layout file, you have this activity main dot XML file. Okay, let's switch back to Android view. And let's minimize this project pain for now. If you remember from the previous videos of this course, I said that whenever you want to define a layout file, you have two options. First of all, you can use this design view, for example, by dragging some items into your design view. You can have different elements and later on you can define some attributes for your elements. This is one way. But the other way is to switch to text view, and manually type everything that you need. In my opinion, when you are an Android developer, most of the times you are going to work with the text view. So in here, we are going to start from this text view. First of all, if you're not seeing this preview in here, you can always enable it and disable it from this preview option in here. If you have a low memory RAM, my suggestion is to disable this preview, because it's going to render the layout file in real time. And that's going to load a lot of pressures on your devices memory RAM and also CPU. For that if you have low memory RAM, disable this preview, it will speed everything up. Right now inside this simple layout file, we have this text view, you can see that when I click on this text view, this text view inside our XML file has been highlighted. It means that these are the same. I'm going to delete this text view for now. Let's select all of it and let's press delete. The next thing that I'm going to do is that I'm going to change this constraint layout. In future videos, we will talk about what a constraint layout is. But for now for a starter, I think it's better to start with relative layout. Let's select that. Also, if you have noticed, you can see that when we have changed the opening tag in here to relative layout, the closing tag has been changed to relative layout as well. Inside these opening and closing tags, I can have different UI elements. For example, if I want to define a text view, I can open an anchor bracket. And by typing text view in capital T, we have a list of options. Let's select the first one text view. Immediately after pressing enter, we are getting some attributes. So for every UI elements, you need at least two attributes a width and also a height. The values for these two attributes can be some numbers. But alternatively, you can see that we have other options in here as well. We will talk about this smash bar and wrap content in a minute. But for now, let's just select wrap content. Basically, it's going to wrap the content of this text view. For the height, let's also select wrap content. If you want, you can finish creating your text view by adding a slash in here. And that's it, you can have a text view. But if you want to have more attributes, you have a lot of options. For example, before this slash, I'm going to say, let's say text, you can see that we are getting a suggestion Android column text, let's select that. And in here, I can pass a text. For example, let's say hello world. As soon as I type this, you can see the text in the preview as well. So text is one of the attributes of this text view. Let's talk about the other attributes found by one. For example, right now, this text is at the corner of my screen. I don't like this. I'm going to change the position of this text view to the middle of this line. For that, I have multiple options. First of all, I can add some margin, in which we'll add a space between this text view at the edge of the screen. For example, I can save margin. And I can pass 50. For example, 50 DP DP is the unit when you are working with your layout files. We can see that we have some margin, but we can be more specific. For example, we can say margin top margin left margin right and also margin button. For example, I can say margin left. Let's say 100 DP this time. Margins are extremely useful. But in here, they are not going to help us because this is not accurate. We want our text view to be exactly in the center of our line. For that, instead of using a margin, I have a better option. I can say center horizontal in order to center my text view horizontally. As you can see, I can pass through or false in here. Let's pass through. And this time, and the text view has been centered horizontally. If you want, you can also center it vertically by saying center vertical and passing a value of true. You can see that it has been centered both horizontally and vertically. Besides these two, you also have another option. For example, in this case, I'm going to delete both of these attributes. Instead, I'm going to say center in parent, this one down in here. Let's pass through as the value of this attribute. This center parent is going to center our element inside its parent element. An XML file is like a tree. We have these child elements. And above them, we have the parent elements. For example, in this case, the parent element is a relative layout. If we want, we can have another relative layout in here, or maybe some other UI elements. And inside that element, we can have this text view. We can do these kinds of inheritance as many times as we want. So in this case, the text view is our child element. And this relative layout is our parent element. And when we use this center in parent attribute, it's going to center our text view in its parent element. Okay, let's move on from this part. If you want, you can also increase the size of your text. For that you can say text size, this attribute in here, and you can pass a number. For example, you can say 20 SP. When you are working with the size of your fonts, the unit is SP. You can see that it's larger now. Also, if you want, you can have some styles on this text as well. For that, we can say text style. This attribute, you can see three styles, bold, italic and normal. For example, let's pass bold. If you want your attribute to be both bold and italic, you can add a pipeline in here. And after that, you can say italic. This time, you can see both of these attributes in the same element. If you want, you can also change the color of your text. For that, we can say text color. And we can pass a color. But that color should be defined inside another XML file called color. Right now we have three colors, this color accent color primary and color primary dark. Basically, these are the names of some colors. Let's select the first one. And as you can see, the color has been changed successfully. But where does this color dot XML file locates in our project? Well, if you want to take a look at that, you can open the project pane. Inside the resources folder inside the values folder, we have these colors dot XML. You can see that we have some colors in here with the exact name that we just saw. Don't worry about this, we are going to talk about different kind of XML files in future videos. But for now, I just wanted you to see this XML file. So instead of passing a color from inside the color dot XML file, you can also pass the hexadecimal value of that color. For that, you can search the internet for something like HTML color picker. Let's search that. For example, let's select a green color in here. This one maybe. And in here, you can see the hexadecimal value. Let's copy that. And instead of passing a color from inside our color dot XML file, I'm going to paste the value of that color, you can see that the color of the text view has been changed to the color that we just selected. If you remember from the previous videos of this course, we have seen that when we wanted to have access to all of these UI elements inside our Java file, we needed an ID. Let's add an ID attribute for this text view as well. Let's say ID. The convention is to say add plus ID slash, let's select that. And let's define some ID. Let's say TXT welcome. The ID attribute should be unique inside every XML file. It means that two different elements inside the same XML file cannot have the same ID. Later on, we will use this ID in our Java file in order to have access to this text view. There are much more attributes to text views, but I think if we continue, we are going to get bored. For that, I'm going to move on from this text view. And I'm going to define a button after this text view. For that, once again, I can open an anchor bracket. And in here, I can say button with this capital B, let's select the first option. Once again, we have these two mandatory attributes. And in here, let's talk about the difference between this wrap content and match parent. Right now, if I select match parent, let's also select match parent for this height. You can see that this button is covering all of the screen. And that's because we have set the width and height to match parent. If you want, you can change this height, for example, to wrap content. And here you can see the difference, the width is matching the parent, but the height is wrapping the button's content. Let's also change the width to wrap content. Besides wrap content and match parent, you can always pass the values manually. For example, I can say 150 DP. You can see that the width has been changed. But this is highly discouraged because our application is going to be installed on devices with different screen sizes. Sometimes if we put some numbers for this, if we pass the values manually, we may not know the exact position of every element. And also sometimes, our elements might not fit in the screen in some devices. So for that matter, I'm going to change this one to wrap content in here. Also now that I have talked about different screen sizes, I'm going to say that in here inside this preview, you have this option called devices for preview. If you click on that, you can see a drop down. And from here, you can select different screen sizes. For example, let's select this one. And you can check the looks of your application in different screen sizes. For example, let's check a tablet. You can see that it's somehow different. Don't worry about this. Later on in the course, we are going to cover how we can have a consistent look for our application in different screen sizes. I just wanted to mention this option above in here. Like for the text view, we have a text option for the button as well. Let's say text. And let's say say hello. Similarly, we have the option to add some margins, but I'm not going to do that right now. Instead, I'm going to move this button to below this text view. For that, we have an attribute called below this one in here layouts below. And we need to pass the ID of the other element. For example, in this case, we need to pass the ID of this text view. I can say add plus ID slash. And I can say txt welcome. You can see that the button has been moved to below this text view. But this is not entirely what we want. We also need to center it horizontally. For that once again, we can say center horizontal and we can pass through. Let's also add a margin top. Let's say margin top. And let's pass, for example, 15 dp. That's much better. For both of these text view and button, you have another attribute called background. Let's also see that we can say background. And for example, we can pass a color. Let's pass the first color. You can see that the background color of this button has been changed somehow. You have the same option for the text view. If you want, you can apply that. I think this is an ugly color. So I'm going to change that. Let's see the other colors. Let's select this primary dark. Nope, this is not my color. Okay, this is better. You can always add the hexadecimal value of the color that you want in here as well. For different UI elements, we also have another attribute called on click, we have seen the use of this on click when we have created our first Android application. You can guess it, we are going to set an event listener for this button. And we are going to say what happens when we click on this button. So let's say on click, and let's pass the name of some method. For example, I'm going to say on hello, we can click right now, you can see that we are getting this red warning. And that's because we need to create this method inside our Java file. Let's finish creating our button by using this slash. And let's create this method inside our main activity that Java file. So let's open that file. In order to open some files, I can always switch to this project thing. Or alternatively, I can press the shift key two times, you can see that when I do that, I have a search menu. For example, in here, I can search for main activity. And if I press enter on the first option, we can open our main activity that Java file. This is just a helpful shortcut that we can use from time to time. Okay, we need to create the on click method inside the scope of our class and outside of the scope of this on create method. If you remember the signature of that method, it was something like this, we needed to set the access modifier to public, the return type was void. The name of the method is going to be exactly the name that we have passed in our XML file. Let's say on hello between clicked for the inputs of this method, if you remember, we had a view object with capital V. This view object is not important right now, we just need to know that we need to receive it as the input of this method. Let's pass view as the name of this input. And in here, we can have the logic to handle the click listener on our button. Also, if you have noticed when I added this view, a new import has been added above in here. Let's also minimize this import for now. This is one way of creating event listeners for buttons and also for that matter for different UI elements. We have other options in which may be more useful from time to time. They will take a look at them in a minute. But in here, let's quickly write some logic. For example, in here, I'm going to change the text of my text view. For that, first of all, I need to have access to my text view. I can say text view. If you take a look at your imports, you will see that this text view from the widget package has been added to our class. If you remember, I said that equivalent to every UI element, you have a class in Java. Okay, let's name this text view txt welcome. And let's initialize it. You can initialize it like this, we can say find view by ID, like this set content view method, this find view by ID is also another inner method inside every activity. Right now, this find view by ID method is waiting for some integer. And the integer is going to be the ID of our element. And here is how we can pass our ID. For example, we can say r dot ID. Once again, if you remember, I said that this are in here stands for resources, it's a special class in Java, and it will give us the access to all of the static contents in our project. So let's say the r dot ID dot, let's pass the ID of our text view, which was txt welcome, we believe. Now that we have access to this txt welcome, we can do some operation on that. For example, I can say txt welcome dot set text, we have seen this method previously. And inside this method, I can pass a text. Let's say hello again. Let's run the application and let's see if we can change the text of this text view. I'm going to run the application on pixel three API level 29, you can select whichever device that you want. Okay, right now, we can see the layout that we have created so far, which is honestly ugly. But don't worry about that, we are going to work on on our designing power. If I click on this button, you can expect what would happen, we are going to change the text from hello, what to hello again. Okay, there was nothing special in this video, I just wanted you to have another look at what we have done in the first section of this course, which was to create your first Android application. I just wanted you to have a better understanding on what you have done in that video. Also, we have learned about some other attributes in here as well. Okay, in the next video, we are going to continue our talk on different UI elements. For example, we will talk about edit texts. And also, we will talk about different ways that we can implement and click the snare for our button. Okay, see you in the next video. In the previous video, we have seen one way of creating an on click listener for our button. There are two more ways. And in here, we are going to see them. For example, in our layout file, let's quickly create a button. But before that, I'm going to change this constraint layout to a relative layout. Let's delete this text and let's create a button. Let's say wrap content and wrap content for the bits and wait, let's give it a text. For example, let's say, say hello once again, let's say center parent. And let's pass through we have seen this in the previous video. So I'm not going to discuss them. Also, we are going to need an ID, let's say, btn hello, you can pass whatever you want. So in the previous video, when we wanted to create an on click listener, we would have add this on click attribute. In here, we needed to pass the name of the equivalent method inside our Java file. But in this case, I'm going to use another approach. And for that, I'm going to delete this attribute. Okay, let's switch back to our Java file. And let's define this button. Inside my uncreated method, I'm going to say button. Let's name it btn hello is equal to find view by ID. Let's say r dot ID dot btn hello. For setting an on click listener for your button, you can use the equivalent method, you can say btn hello dot set on click listener, you can see that we have this method. Inside the parentheses, we need to pass an interface. In this case, it can be new view dot on click listener. If you take a closer look, you can see that this is an interface. Okay, now that I have passed this new interface in here, this on click method has been overrided. And inside this on click method, I can write my code. For example, if I want to print something into my console, I can say print. Let's just say hello. Let's run the application and let's see if we can see any result. I have opened this run panel in here. And if I click on this say hello button, you can see that hello is being printed in here. So this way by using this set on click listener method on our button, we can define the on click listener. Inside the parentheses of this method, we have passed this new view dot on click listener method, but there is also another way. Let's quickly see that. So instead of passing a new interface in here, I'm going to implement this exact interface in the declaration of my class. If you remember from the Java session, we can implement interfaces like this, we can say implements, let's say on click listener. There are two options in here. The first one is coming from Android dot view dot view package and the next one is from another one. We need the first one. When we implement interfaces, we also need to implement their methods. We can do that by pressing Ctrl plus I, we need to implement this on click method. As the input of this on click method, we are getting a view object. And now we can use this view in order to create different cases. For example, we can say switch on view or V in this case, it's his name. Let's say dot get ID. We are going to create our switch depending on the ID of this view object. And after that, I can say case, in case it's our dot ID dot btn hello, the exact ID that we have passed in here. In case this is the ID, let's write some code. For example, I'm going to copy this line of code from here. Let's also add a break and also a default case. Now that I have implemented this method at the declaration of point class, and also I've implemented this on click method, I can remove this between hello dot set on click listener method. Let's write it once again, let's say between hello dot set on click listener. This time, instead of saying new view dot on click listener, I can say this. If you remember from the Java session, this refers to the current object. Right now we are inside this class, which implements this interface. So this method down in here is happy with accepting this as the input. So how's the flow of things in here? First of all, we are setting the on click listener and we are passing the class itself as the interface. Whenever the user clicks on this button, this on click method will be triggered. A view will be passed to this method. In this case, it's a button. Later on, we will talk about that why a view and a button are equivalent. We are getting the idea of this view and we are creating a switch statement. In case the idea of this view is r dot id dot ptn hello, the idea of our button, we are printing this hello in here. If we had other buttons or for that matter other views, we can create different cases for them in here as well. Let's run the application once again and let's see if we can see the same result. Once again, if I click on this say hello button, we can see that hello has been printed into our run console. Also, I don't like to calm down in here inside this run in order to test my application. Instead, I'm going to show something to the user in our application. For that, instead of using this system dot out dot print line, I'm going to use another option called toast messages. Let's search for toast messages and let's see what those are like. So basically a toast message is something like this. This is not a permanent message and it will be disappear after a period of time. Let's quickly see that how can we define this in our code. So in here, I'm going to delete this line of code. Instead, I'm going to say toast. You can see that I have two options in here. The first one is a Java class, but the second one is a template. Basically, templates are provided by the ID that we are using. For example, in here, if I select this template, you can see that this whole line of code has been created. So we are using this toast class in which has this static method. Inside this static method, we are passing a context, whatever that is, we will talk about context later on in the course spot for now. So we are using this toast class in which has this static method called make text. We have three inputs for this make text method. The first is a context. Don't worry about the context yet. We will talk about that later on in the course spot for now. Just know that every activity in Android is a context. And because right now we are inside an activity, we can pass this as our context. The next input is a text. Basically, this is going to be the text that we are going to show. For example, let's say hello button clicks. After that, we have this constant in here, which is toast dot length short. Basically, this is just a constant for determining how long do we want our toast message. For example, if you want to see the other time periods, you can say dot, we have length long and length short. Let's select length short. And after this make text method, we have this dot show method, which you can guess is going to show our toast message. So before this, we have created our toast message. And after that, with the help of this show method, we are showing it to the user. In here, we have used the template. But if you don't want to use the template, you can always create your own toast message. You can say toast. This time let's select the first one. Let's say make text for the context let's pass this. We need the text in here, let's say second text. And after that, we need a constant let's say toast dot length long dot show. Basically, these two lines of code are the same. We just can't create them with the help of the ID. Okay, this time, let's run the application and let's see what would be the result. So this time, if we click on this say hello button, you can see that some toast message is showing down in our screen. And after that, it will be disappeared. I think toast messages is much better for our testing purposes. It's much better than this run paint down in here. Okay, let's close the application in here. And let's talk about this view that we are receiving in here. In a logical way, instead of this view, we need to receive a button, because we are creating our switch statement based on the ID of our button. But there is a point in here. If you press down the control key and if you click on this button class, once again, if you press down the control key and if you click on the class that this button is extending in this case, this text view, you can see that this text view class is extending the view class. It means that after two times of inheritance, our button is somehow a view. We just extended the view class two times. So at the end, a button is a view. If you remember from the Java session when we have talked about inheritance, for example, when we extended the animal class, and we created our dog class, we said that a dog is an animal. In this case, a button is also a view. For that matter, every UI element is a view, like text views, edit text, and also other UI elements that we will talk about later on in the course. So this in here proves that we can create an unclick listener for our text view and other UI elements as well. So this unclick method is not limited to our button. It's also worth mentioning that when you create your unclick listener this way by implementing the interface in your class declaration, you just need to create one unclick method for all of your UI elements. For example, if I had another method down in here, I could have passed the idea of that button to another case. And inside that case, I could write my logic. So I can have as many methods. And for that matter, as many unclick listeners for my view elements. Also, this unclick listener is one of the available event listeners. We have others as well. If you want, you can take a look at them by saying btnhello.set, let's say set listener. And you can see a lot of these options we have on click listener, we have on drag listener, you can guess the meaning of each one of these, we have set on hover listener in case if we hover over our button, we also have another useful one on long click listener, it means that if we long press on a button, let's quickly see this one. This time instead of implementing the on long click listener in my class declaration, I'm going to use the easier way by saying new view dot on long click listener. This one, you can see that in here we have a Boolean as the return type of this on long click method. This Boolean is just a callback indicating if we have long pressed our button. If you want your code inside this method to work fine, you need to pass through. Let's write some logic in here. For example, I'm going to say toast. Once again, we can see this context in here, but the format is somehow different. Because right now we are inside an interface, we are inside this online click listener interface. If we pass this, this will refer to the current object, which in this case is an interface, but interfaces are not context, and we need to pass our activity. For that matter, we can say main activity dot this, don't worry about this main activity dot this, if you didn't get that, I will talk about that later on in the course when we have talked about activities. But for now, just let's pass this as our context and let's create a text. Let's also change the time period in here to length long. I think I need to delete this case from here as well. Okay, let's run the application. So like before, if I click on this button, and you can see that we are seeing this message Hello button clicked, which is a simple on click listener for our button. But if I press my button and hold the key, you can see that we are seeing this long press message. So this time, instead of this on click, we have executed this set on non click listener method. You can also check the other event listeners for your view items later on in the course, we will check a few more of them. But in general, you can say btn hello dot set listener. And you can use each one of these that you want. Okay, let's move on from the event listeners. And let's define another UI element in our layout file. Before this button, I'm going to define an edit text, let's say edit text. For the width, let's say match parent this time. And for the height, let's say wrap content. You can see that it's something like this. If you click on that, this is our edit text. Let's also add a text in here. Let's say name. And name has been added. That seems to be better. Let's also center our edit text, I'm going to say center in parent. And I'm going to pass through. But right now we have a conflict between this edit text and our button. For that, I'm going to move this button to below this edit text. But before that, I need to give an ID to this edit text. Let's say ID, let's just name it edit text name. Let's finish creating this edit text. And down in here, inside our button element, I can say below or to be specific layout below. And I can pass the ID of my edit text before that I need this add plus ID slash, let's say edit text name. So this way we have moved this button to below our edit text. I think it's better to have some margins. That's a margin top. And let's pass 20 dp. That seems better. Okay, let's switch back to our edit text. I don't like the text inside my edit text because if I run the application. And if I try to type something in here, first of all, I need to delete this text. For that instead of this text attribute, I'm going to use another attribute called hint. I think we have hint at the first videos of this course. Let's just pass name. This time it's much better. So whenever I click on this edit text, and if I try to type something, this name hint will be disappeared. Also, if we want to decrease the widths of our edit text, we can pass a number in here. For example, we can say 250 dp, which is better in this case. But if you remember, I said that it's never a good idea to pass your widths and height manually, because in different screen sizes, you cannot predict the size of your different elements. For that once again, I'm going to change this font to match parent, I believe it was. And after that down in here, I'm going to add two margins. Let's say margin left to 50 dp. For example, I think it's better to change it to 100. And also let's add a margin right of 100. Adding different margins is one way, but we also have another way. Let's we can see that as well. So I'm going to delete both of these margins. Instead, at the declaration of my relative layout inside the opening tag, as you can see, this is our closing tag. And this is our opening tag. Inside the opening tag, I can define an attribute called padding. Once again, like margins, we have multiple paddings, we have padding bottom, padding left, right top. Let's just use padding in here. And let's pass 100 dp. So as you can see, the size of our edit text has been changed. The padding and the margin are a lot like each other. Just there is one difference. When you are adding a margin, for example, in the previous case, for our edit text, the margin would be added from the end of our element, for example, from here to the end of our screen. But when you are adding a padding, that padding will add some space from inside your element. For example, in this case, the element is this relative layout itself. And we have added the padding from inside the relative layout. So once again, margin adds the space from the outside of the element, but the padding will add the space from the inside of the element, you can use both of them depending on your need. Let's see what other attributes do we have for our edit text. Like a text view, we can change the color for this edit text as well. For example, I can say text color. And let's pass this color that we have in our color resources. Right now, we do not have any text inside our edit text. But as soon as we type something, the color will be changed to this color that we can see in here, we can also style the text by saying text style this one. We can say italic both normal. Or if we want to use two styles at the same time, we can add a pipeline. There is another attribute that we didn't have in text views. And that's called lines. For example, there are times that you may need a bigger input from the user. You can specify the number of lines in here. For example, if I say four, for example, now our edit text is going to accept four lines of inputs. In this case, I'm not going to use these lines. So I'm just going to delete that. The default number for different lines is one. With edit text, you can also define the kind of input that you are going to receive. For that, you can say input type this one. And you can pass one of this. For example, if it's a date that I'm going to receive, I can pass a date or maybe this date time. If I'm going to receive a number password, I can pass this number password. If it's just a simple text, I can pass this text, we have other options, for example, for different emails, and all sorts of options that you can see in here. For example, if I select this text password in here, and if I add some text instead of this hint, let's say text, you can see that when I type the text, it will change it to these dots. Probably you have seen this on your phone when you are trying to log into some application or some website, this will add some level of security. Also, when you define it to email, this text email address, when the user clicks on your edit text, the keyword will be prepared to type the email address. I'm not going to define any specific type of input. So I'm going to delete this one in here as well. And let's also change this one to hint. Okay, I think that's enough about edit text, we have all sorts of different options in which you can check them from here. As you can see, there are 1000 of these attributes. Okay, below this button, let's also define a text view. I'm going to say text view, wrap content and wrap content. Let's give it an ID. Let's say txt hello. After that, maybe some placeholder text. Let's just say hello. Let's also move it to below this button. I'm going to say layout below. Also, it's worth noticing that if you are not using a relative layout, for example, if you are using a constraint layout, you do not have this layout below option. This is one of the features of this relative layout. We will talk about that in a future videos. Okay, in here, let's pass the ID of our button. Let's say btn hello. Also, let's move it to center horizontal. And let's add some margins. margin top of maybe 30dp. Let's increase the size of this text by saying text size. And by passing, I believe 20 would be fine. I'm almost done with this layout file. Let's just go top in here into this code. And let's select this reformat code in order to rearrange our code so that if I publish the code, you would have the same code that I'm writing in here. Okay, let's switch to the main activity and let's define all these three items. Let's say edit text. Let's name it edit txt. I believe it was name is equal to find view by ID r dot ID dot edit text name. Let's also define our text view. Let's name it txt name is equal to find view by ID r dot ID dot txt name or txt hello was I think it's better to change the name to txt hello. But right now there is a problem with our code. We are instantiating our UI elements inside this uncreate method, which once again is the starting point of our application. But we are going to need these two UI elements inside this on click method. Because we are going to change the value of this text view, whenever the user clicks on our button. And if I try to have access to this txt hello for example from inside this method. If I type txt hello, you can see that I'm getting a red warning. You can see that the ID cannot resolve this symbol. It means that inside this method we do not have access to this text view. I'm not sure if I've mentioned this in the Java section, but the problem in here is occurring because of the scope in Java. So right now the scope of this text view is inside this uncreate method. And outside of that we cannot use that. If we want to have access to this text view inside both of these methods, we can say something like this, we can declare this text view in the declaration of our class as different fields. For example, above in here I can say private, let's say text view, this one. And let's name txt hello. But right now in here if I try to instantiate my text view, for example, if I say find view by id and I pass my ID, because this part in here is not a part of this activity life cycle. We are not going to instantiate our text view at all. We need to instantiate our element inside this uncreate method, which is once again the starting point of our application. So this way we are separating the declaration and instantiating of our UI element. I can put a semicolon down in here. And this time instead of defining the whole text view, I can use this field, I can say txt hello. This one is equal to find view by ID or dot ID dot txt hello. Now that I have declared this txt hello as a field, I can use it in both of these methods. For example, in here I can say txt hello dot set text. Inside this set text method, I'm going to need the text of this edit text. For that, I'm going to define this edit text as a field as well. So let's say private edit text. Let's name it edit txt name. And then in here, let's remove this edit text. Now I can pass this edit text, for example, to this set text method. Let's say hello, plus the edit text dot get text. If you remember from the first videos of this course, I said that we need a two string method as well. We have seen this two string method in different Java classes. It's just going to generate some text. In this case, if we delete this two string, and if we just pass this edit text name dot get text, if you press down the control key, and if you hover over this get text method, you can see that the return type of this get text method is an editable. We do not know what that is yet. But we just know that this is not a string. And in here we are going to need a string. For that, we need another level of conversion, we need to convert the editable to a string. So we can use this two string method. Okay, I think after a lot of talking, our application is ready. Let's just run the application and let's see if we can see the behavior that we wanted. Let's type something in here. Let's say Mason. And let's press this button. Hello, Mason, our application is working fine. And hopefully, we understand each piece of the code that we have wrote so far. Few minutes earlier, I said that different UI elements extend the view class. We have seen that for this button. Let's also check the case for this edit text and text view. We can first down the control key, and you can click on this edit text class. We can see that it's extending the text view. If you click on this text view once again, by pressing down the control key, you can see that it's extending the view class. The same is for the text view itself. If you press down the control key, and if we click on the text view, you can see that it's extending the view class. Now that we know both of these are extending the view class, we can create an on click listener for each one of them. And they run inside this on click method. If you want, we can create another case for each one of them. For example, down in here, for the edit text, I can say edit text name dot set on click listener. You can see that we have this option in here. And because we are implementing the on click listener interface inside our class declaration, I can pass this in here. Later on inside the on click method, I can create another case. For example, let's say case or dot ID dot, let's say edit text name. If that's the case, let's toast some message. Let's say attempting to type something. Before I run my application, I'm going to delete this toast because I'm not going to have a conflict between different posts. So this time, if I click on the btn hello, the text is going to be changed to hello plus the text inside our edit text. And if we click on the edit text itself, we are going to see this toast message. By clicking on the edit text, you can see the toast message down in here, that seems to be perfect. Okay, I think that's enough for this video. In the next video, we are going to talk about some other UI elements like checkboxes, radio buttons, and radio groups, and also progress bar. Just before I finish off this video, I'm going to say that I will upload the source code at my website at maycode.org slash codes. So feel free to check that if you need. Okay, see you in the next video. The first UI element that we are going to talk about in this video is checkbox. Let's quickly see that in our layout file. Before everything, I'm going to delete this text to you and also I'm going to change the constraint layout to relative layout. Down in here, we can create our checkbox like this, we can say checkbox for the widths and height, let's say, wrap content. You can see that this little checkbox has been added in here. If you want, we can add a text to this checkbox as well. Let's say text, I'm going to enter the name of a movie. So let's say Harry Potter, we can have an ID as well. Let's say ID. Let's name it checkbox Harry. So basically a checkbox is a box that we can check or uncheck. For example, in here, we have an attribute called checked. We can pass through or false for this. For example, if we say true, you can see the checkbox will be checked. Let's quickly add two more checkboxes. Basically, I'm going to copy and paste this one two more times. But this time, first of all, I'm going to change the text to let's say the matrix. And also let's change the ID as well. Also, I'm going to add another attribute. I'm going to move this new checkbox to the right of my previous checkbox. For that, we have an attribute called to write off layout to write off. Let's pass the ID of our first checkbox, let's say checkbox Harry. Let's also add a margin left, you can say margin left. And let's pass 15dp, for example, let's copy and paste this one once again. Let's change the text to let's say Joker. Let's also change the ID, let's say checkbox Joker. And also let's move it to the right of checkbox matrix. So this way, as you can see, we can have multiple checkboxes, you can check and uncheck them by default by setting an attribute of checked. Let's change the value for the Joker to let's say false. If we want to center this checkbox horizontally, we can add a margin for the first one. For example, we can say margin or margin left. And we can pass 25 for example. But as you can see, this is not accurate instead. What we can do is that we can create another relative layout and move all of these three checkboxes into that relative layout. Let's quickly see how we can do that. So inside my first relative layout, I'm going to create another relative layout. Let's say relative layout for the bits and height, let's say wrap content. Let's also give it an ID, let's say ID. I'm going to name this one movies relative layout. Now if I want, I can center this relative layer, I can say center horizontal, let's pass through. Besides that, let's add a margin top, let's say margin top of 20 dp. In other UI elements normally in here, we could have finished creating our element by adding a slash in here. But in this case, I'm not going to do that. Instead, I'm going to finish creating my first tag, my opening tag. For that, I can add a left anchor bracket. And as you can see, this closing tag has been created automatically. Now I can put my three checkboxes inside these two tags, the opening tag and the closing tag. Let's move all of them to inside those two tags. If you noticed, you can see that these three checkboxes are now centered horizontally. And also they have a margin top of 20 dp. That's because the parent layout, which is this relative layout has these two attributes. So inside XML file, you can have relative layout nested inside another relative layout. Okay, now let's see what can we do with these checkboxes inside our Java code. For that, I'm going to open my main activity dot Java file. If you are wondering, I'm pressing double shift in order to see this search menu. First of all, in here, let's define our checkboxes. Once again, I'm going to define them as fields, let's say private checkbox. For the first one, let's say checkbox Harry. In here, I have two options. First of all, I can create my checkboxes line after line. For example, I can say private checkbox. And for the second one, we can name it checkbox matrix or alternatively because the kind of these objects are the same, I can add a common here and I can define my second checkbox. For example, I can say checkbox matrix. Let's also define the checkbox Joker. And later on inside our on create method, let's instantiate them. Let's say checkbox Harry is equal to find view by ID or dot ID dot checkbox Harry. Similarly for the next two, if you want, you can have a click listener for each one of these checkboxes. For example, I can say checkbox Harry dot set unchecked changed listener. This is the listener that I need. Let's pass new unchecked changed listener. Once again, you can see that this is an interface. The exact name is compound button dot unchecked changed listener. Inside this interface, we have this unchecked changed method in which we receive two elements, the compound button itself, which is our checkbox in this case. And also this is checked Boolean. So in here, I can create an if statement, I can say if is checked. Let's show a toast message. Let's say you have watched Harry Potter. But in the else case, let's show another toast message. This time, I'm going to say you need to watch Harry Potter. Before I write the logic for the next two checkboxes, let's run our application and let's see what would be the result. Right now, Harry Potter is checked, but we are not seeing any toast message. And that's because the on click listener in here is going to react when we click on this checkbox. For example, if I uncheck this checkbox, we can see that you need to watch Harry Potter. Let's also check it. You have watched Harry Potter. But what if we want to see the toast message when we run the application without any clicking on our checkbox? For that, we have an option in here before setting this on click listener. We can check that if our checkbox is checked or not. For example, for that, I can create an if statement, I can say if checkbox Harry dot is checked. As you can see, this method is going to return the Boolean and as its name applies, it's going to check that if our checkbox is checked or not. So if it's checked, I'm going to show the toast message, let's copy it from here. But in the else case, I'm going to show another toast message. Once again, we can copy it from down in here. Let's run the application. As you can see, when I run the application without any clicking, I saw the toast message. So from time to time, this is checked method is going to be useful. I'm not going to define an on click listener for the next two checkboxes, because I'm sure that you got my point. Also, like in the previous video, instead of passing this new compound button dot unchecked changed listener, you can implement this listener at the declaration of your class, for example, in here. And after that, you need to override this unchecked changed method. After that, you can pass this instead of this new listener in here into your set unchecked changed listener method. But once again, I'm not going to go through that. Instead, let's switch back to our activity main dot XML file. And let's talk about another UI element. But before that, I'm going to minimize this relative layout. The next UI element that I'm going to talk about is radio button. Let's say radio button, this one down in here, for the width and height, let's say wrap content, you can see that this is this circular button. Let's move it to below our relative layout. I can say below or layout below. I think it was named movies relative layout. Let's also add two margins, margin left off, let's say 25 dp and also margin top of maybe 20 dp. Like checkboxes, we can also have texts. Let's say text for the text, I'm just going to say married. This is going to determine the marital status of the user. So that's what this text is about. Let's also give it an ID. Let's say radio button married. Like checkboxes, if you want to check this married radio button, you can say checked, and you can pass through. If you want to have multiple radio buttons, you can say something like this, you can copy and paste this radio button, but there is going to be some problem with our code. Before that, let's change the text and idea of this radio button. For example, in here, let's say single. And after that, let's change the ID to RB single. Let's also move this one to right of our radio button married. Let's say to write off radio button married. So the purpose of radio buttons in programming is that among multiple radio buttons, you can only select one. This is the difference between radio button and checkbox. When you have checkboxes, you can check multiple checkboxes. But when you have radio buttons, you can only have one radio button checked. But as you can see, our program is not functioning right in here. And that's because we need to group these radio buttons. And we can do that by creating another item in here called radio group. Before that, I'm going to delete these two radio buttons. Let's say radio group, this one, once again, for the bits and height, I'm going to say wrap content. Let's move it below our movies relative layout, layout below ID movies, real layout, a margin top maybe of 20 dp. And also let's center it horizontally, center horizontal to true. Once again, because I'm going to put some radio buttons inside this radio group, I'm not going to finish creating this radio group. Instead, I'm going to finish creating this opening tag by adding a left anchor bracket. Like a relative layout, you can see that now we have an opening tag and also a closing tag. Inside this radio group, I can have my radio buttons, let's say radio button, wrap content and wrap content. Let's give it an ID, let's say radio button married, a text maybe. And also let's change its default value to checked. Let's say checked through. Now we can have multiple radio buttons. Let's copy and paste this one. So as you can see, I never moved this radio button to below our first radio button, but it's moved automatically. If we change the ID to for example, RV single, you can see that even the both of these radio buttons are checked, but only one of them is showing the checked value. So when you are using radio buttons, only one of them can have a checked value. For that, I'm going to delete this checked attribute from the second radio button. And also I'm going to change the text to single. Let's also add another one. For the ID, let's say radio button in rail. And let's change the text to in a relationship. Let's also delete this checked attribute. Right now, our radio buttons are vertical. If you want, you can have horizontal radio buttons as well for that inside your radio group. You can have an attribute called orientation in which you can pass horizontal or vertical. If I pass horizontal, you can see that now we have our radio buttons horizontally ordered. I think it's better to have some margins between these radio buttons. So let's quickly add some margins. Let's say margin left of maybe 15 dp, I guess. And let's add another one down in here. Okay, now let's see how we can use these radio buttons and radio group inside our Java file. For that, I do not need to define my radio groups. Instead, I just need to instantiate my radio group. Let's say radio group. Let's name it radio group marathon status. But I believe I need to give an ID to this radio group. And I think I didn't do that. Yes, in here, I can say ID. Let's say radio group marathon status. In our uncreated method, let's also minimize this if statement and also this on click listener. And after the check boxes, let's instantiate our radio group. We can say radio group marathon status find view by ID or dot ID dot radio group marathon status. We can have an on click listener for this radio group by saying radio group dot set unchecked change listener. So this method is going to be called whenever we change the radio button selected. And inside the parentheses, you can guess I can pass new unchecked change listener, radio group dot unchecked change listener, which is an interface and it will create this unchecked change method. One of the inputs of this method is this checked ID in which we can use that. For example, we can create a switch statement on this checked ID. And we can create our cases, we can say in case it's our dot ID dot, let's say radio button married. So basically this checked ID is the ID of our radio button, whichever is selected. So in case if the user selects this radio button married, I'm going to show a toast message. Let's just say married. But in case it's our dot ID dot, let's say radio button single. Let's show another toast message. Let's also add another case for RV in well. As usual, let's also create our default case. And let's add a break. Let's run our application. And let's see if we can see any result. Right now this married is selected. If we select the single, you can see that the married one has been unchecked. And also we have saw the toast message. Let's select another one. You can see the toast message, which is perfect. Right now we have an on click listener for our different radio buttons inside this radio group. And depending on that button, we are doing something. For example, in this case, we are showing a toast message. But if you want to do something without clicking on these buttons, we can do something like this in our code. So before this set unchecked change listener, I can say radio group my status dot get checked radio button ID. As you can guess, this will return the ID of the checked radio button. And I can save that inside an integer. For example, I can say int checked button. After that, I can create a similar switch statement based on the checked button. So let's say switch on the checked button. And let's create our cases. I'm going to copy and paste the cases from here. Let's run the application. And let's see if we can see any result. As you can see, we are not clicking on any of these radio buttons, but we just saw the married toast, that seems to be perfect. In some cases, we might need to check for the checked radio button before clicking on them. I'm going to talk about another UI elements in this video. And that's called a progress bar. Let's quickly see that as well. Before that, I'm going to minimize this radio group. After that down in here, let's say progress bar, wrap content and wrap content. Let's give it an ID, let's say progress bar. Let's also center it, let's say center in parent, and let's pass through. Let's run the application and let's see what our application is going to look like with this progress bar. As you can see, an infinite progress bar is constantly circulating. This might be useful. For example, when we are downloading something from the internet, in order to make our progress bar visible or unvisible, we have an option. For example, in our XML file, if we want it to be not visible, we can say visibility, and we can pass gone. Also, we have this visibility attribute for almost all of the other UI elements. If we want, we can change it to gone, but by default, it's visible. Let's change it back to gone. Later on in our Java code, we will change this visibility to visible. And whenever we are done with it, we are going to change it to gone. Let's see how can we do that in our Java code. Before everything, let's minimize all of the extra methods and codes. And let's instantiate our progress bar. Above in here, I'm going to say private progress bar. Let's name it progress bar. And down in here inside the uncreate method. Let's say progress bar is equal to find view by ID R dot ID dot progress bar. I do not have any button in here in order to change the visibility of this progress bar. Instead, I'm going to change its visibility whenever the user clicks on the radio button single for that inside the radio group my total status listener inside the switch case, in case if it's RV single instead of sharing the toast message or after the toast message, I'm going to say progress bar dot set visibility and I can say visible. Instead, whenever the user clicks on this radio button in rail, I'm going to change the visibility of my progress bar to gone. Let's copy this line of code. And after the toast message, let's paste that and let's just change this constant to gone view dot gone. Let's run our application. Right now we cannot see any progress bar because in our XML file, we have added the visibility attribute and we have set the gone value. In case if we click on this single, you can see that we are seeing the progress bar. In case if I click on this in a relationship, you can guess the visibility will be changed to gone. There is also another form of progress bar. Let's quickly see that as well. So in my activity main dot XML file, I can define a style for my progress bar. Before that, I'm going to change the visibility once again to visible in order to see the progress bar in our preview. And after that, let's say a style. If I type horizontal, we can see this styling here, widget dot app compact dot progress bar dot horizontal. Let's change the width to match parents so that we can see it better. And also in here I have another option I can say progress. And I can pass an integer. For example, I can say 30. You can see that the progress of this progress bar has been changed to 30. This type of progress bar is extremely useful when you want to show the progress of something for example, downloading a file. Sometimes you may want to show that how much of the file has been downloaded. You can also set a maximum for your progress. For example, you can say max, and you can pass 100. Let's also add some margin left and right. margin left of 20 dp, margin right of 20 dp. Okay, now let's switch back to our job of oil and let's see what we can do with this progress bar. Before everything I'm going to delete these two lines of code, because I'm not going to make my progress bar visible or unvisible. Let's also minimize the switch statement and this whole listener for our radio group. After instantiating our progress bar, I'm going to create a threat. If you remember from the Java session, this is the simplest way that we can create a threat. Let's say threat threat is equal to new threat, we needed to pass a runnable, let's say new runnable. Inside this run method, I'm going to create a for loop. Let's say for int i is equal to zero, i less than 10, and i plus plus. For every time of looping, I'm going to increment the progress of this progress bar by 10. So let's say progress bar dot increment progress by, as you can guess, we need to pass an integer in here. For example, let's pass 10. After that, let's freeze this threat for half a second. If you remember from the Java session, we have used this way, we set threat dot sleep. But this way, there is a probability that we create interrupted exceptions. For example, you can see that we have an error in here and the error says that unhandled exception. There is also another way in Android, I'm going to use that in here, I can say system clock dot sleep. So this way, we don't need to create the try catch block. This wasn't available in Java, the system clock is coming from Android dot OS, we can check that by take a look at these imports. This one in here, Android dot OS dot system clock is the one that we just imported. After creating our thread, we just need to start it, we can do that after the definition of our thread, we can say thread dot start. So in here, we have created this worker thread in which inside that we are creating a for loop and for each time of looping, we are incrementing the progress of our progress bar by 10. Also, after each time of looping, we are sleeping the worker thread for half a second. Let's quickly switch back to our layout file, and let's delete this progress attribute, it was just for demonstration. So if I remove this one, you can see that the progress will change to zero. Let's run the application and let's see if we can see the progress of our progress bar. As you can see, we are changing the value of this progress bar for every half a second. If you want, you can also get the progress of your progress bar at any moment that you want. For example, in here, you can say progress bar dot get progress. As you can see, this get progress is returning an integer, which is the current progress of your progress bar. Sometimes you may need that. And here is how you can get that. Okay, I think that's enough for this video. Once again, like previous videos, I'm going to upload the source code at my website at maycode dot org slash codes. Feel free to check that if you need. And also in the next video, finally, we are going to talk about the differences between a relative layout, a constraint layout, and also a linear layout. I think it's going to help you a lot with understanding the layout files better. Okay, see you in the next video. In this video, we will talk about different layouts in Android. Specifically, we will talk about relative layout, we will talk about linear layout, and also constraint layout. Let's start by talking about the relative layout. Like before, I'm going to switch to text view in my layout file. Let's also minimize this project thing. And let's change this constraint layer to relative layout. I'm also going to enable this preview so that we can see what we are doing. First of all, let's delete this text view. And let's start from the beginning. So inside a relative layout, all of our UI elements are somehow related to each other. It means that the place of every UI element is relative to another layout, or maybe it's parent. Let's quickly create a text view and let's see the relativity in action. Like before, I'm going to say wrap content for the width and height. Let's also specify a text. Let's just say hello world. As you can see right now, the text view is placed at the left corner of my screen. If I want, I can change that. For example, you have seen in the previous videos that I can center this text view vertically or horizontally. For that, I can say center horizontal. Let's pass through. You can see that it's being centered. And this is the relativity that I was talking about. When we set this layout center horizontal attribute to true, we are defining a relativity between this text view and its parent. Let's also center it vertically. Or instead of these two attributes, I can simply say center in parent. Let's also give an ID to this text view. Let's say txt hello. Now if I define another UI element, I can place that related to this text view. Let's quickly create a button in here. Let's say wrap content and wrap content for the width and height. Let's define a text. Like before, let's say say hello. Also, let's define an ID. Now if I want to move this button to below this text view, I can simply say layout below. And let's pass the ID of our text view txt hello. I can center this button as well. For example, I can say center horizontally. And let's pass through. We can also have a margin. For example, we can say margin top layout margin top and we can pass some number for example 15 dp. Inside a relative layout, you can also have another relative layout. Let's quickly see that for example, in here, I'm going to define a relative layout. And inside that relative layout, I'm going to put three text views. After that, I'm going to move this text view this hello wall to below that relative layout. So I can say relative layout. For the width and height, let's say wrap content, you can say match parent, like other UI elements, we can define an ID for our relative layout. For example, I can say first relative layout. So up until this point when we wanted to create our UI elements after setting the attributes, because I've used this backslash in order to finish creating our UI elements. But in this case, because we are going to put some other elements inside this relative layout, we need to create an opening tag. And instead of using the backslash, I'm going to use the left anchor bracket. By doing that, we also create this ending tag. And inside this opening and ending tag, now we can put our UI elements. For example, we can pass our text views. Let's say text view, wrap content and wrap content. I'm going to fast forward everything for these three text views. Like before, we can place our three text views inside this relative layout correctly. For example, we can move them to write up each other. So for this second text view, I can say to write off, let's say txt name, let's also add a margin left of 10dp. Similarly, for the third text view, let's say to write off our txt last name. And margin left of maybe 10dp once again. Once again, this whole relative layout is placed at the left corner of our screen. If we want, we can use the center vertical or center horizontal attributes for this whole relative layout as well. So inside the opening tag of this relative layout, I can say center horizontal. And let's pass through. Let's also add some margin top, let's say margin top. And let's pass 100dp. You can see that when I use these attributes on a relative layout level, all of the UI elements inside that relative layout respond to those attributes. For example, in here, we have centered them horizontally and also we have added the margin. Now that we have this relative layout, we can minimize that so that we can see everything better. And after that, we can move this hello text to below this relative layout. But before that, I need to delete this center apparent attributes. Once again, you can see that it moves to the corner of our screen. And because we have set the layout below for this button, it moves as well. So in here, I can say layout below, and I can pass the ID of my relative layout. It was first relative layout. Let's also center it horizontally and let's pass some margin. Center horizontal true margin top, let's say 10dp. So my point in here was that inside a relative layout or for that matter inside any other kind of layout, you can have other relative layouts as well. Some of these attributes, for example, this layout below are specific to relative layout. And if you're inside some other kind of layout, for example, a linear layout and also constraint layout, you cannot use this layout below. During the course, we will see that which of these attributes are specific to relative layout. Before we move to the next kind of layouts, let's also switch to this design view. At the left pane in here, you can see this component three. As the name of this component three applies, this in here is showing us the hierarchy of different elements in our UI. So for example, in here, we have this parent relative layout. Inside that we have this first relative layout and also txt hello and btn hello. Inside our first relative layout, we have three text views. Sometimes when you have a messy UI, you may use this component three in order to keep track of different UI elements. Okay, let's switch back to our text view. And let's start talking about linear layout. Before that, I'm going to delete all of these. And let's change this relative layout to a linear layout. Inside a linear layout, all of the UI elements will be placed line after line. Let's quickly see that I'm going to define a text view once again, wrap content and wrap content. Let's pass a text. Let's say hello once again. Let's also give it an ID. That's a txt hello. So the first thing that is different inside a linear layout is that you do not have the center in parent center horizontally or center vertically attributes when you use linear layout. For example, in here, I cannot say center in parent, you can see that it's not available. If you want to center your UI elements, you can have for example, a relative layout inside this linear layout. Let's move on from this part. And let's add another UI element. Let's say button wrap content and wrap content for the text. Let's say say hello. And let's give it an ID. Let's say btn hello. You can see that even though I didn't use any attribute to move this button to the right of our text view, it automatically placed the right of our text view. And that's because we are using a linear layout. Inside a linear layout, all of our UI elements will be placed one after another. If you want, you can change the orientation of this linear layout so that the UI elements will be placed one after another vertically. Let's quickly do that. So in the definition of my linear layout, I'm going to pass an attribute in here, let's say orientation, and let's pass vertical, you can see that they have been placed vertically. There is also another attribute that I'm going to talk about in linear layout. Let's quickly delete this button and let's define another text view for the text, let's say name. And for the idea, let's say txt name. Like before you have the margins, for example, you can say margin top and we can pass any number that we want. But there is also another attribute in here, before I talk about that attribute, I'm going to give some background color for these two text views so that we can see the difference better. So I can say background, and I can pass a color for example, this color accent that we have in our color resource. Let's also set a color for the first text view. Let's say background, and let's pass color primary this time. So the attribute that I'm going to talk about is weight. Let's quickly see that. We can see this layout weight in here, and we can pass any number that we want. For example, I can say 20. Let's also pass a weight to this second text view and we will talk about it. Let's say weight and let's pass 80. For example, you can probably guess the usage of this weight attribute right now. It will give our attribute some weight according to the numbers that we have used. For example, in this case, the entire weight of our layout is 20 plus 80, which is 100. And it will give the first text view 20% of the weight of the whole layout. It doesn't matter what number you put in here. For example, in here, if I say two, and for the second one, if I say eight, it will work the same. Also, you can see this space in here. That's because we have this margin top. If we remove that, you can see that the whole layout will be divided accordingly. So this weight was another attribute that I was going to talk about. If I change this orientation to horizontal, you can see that it's working the same. There is not much to this linear layout. I just wanted to show you that there is one linear layout with some specific attributes, for example, this orientation and this weight. And in this course, we are not going to use linear layout that much. It's for simple layouts, but you can use it if you want. Before I remove all of this, I'm going to say that inside a linear layout, you can also have other layouts, for example, a relative layout or a constraint layout. Okay, let's remove all of these. And let's talk about constraint layout. Before that, I'm going to remove this orientation because it was specific to linear layout. Okay, let's say constraint layout. We have two options in here, widget dot constraint and widget dot constraint layout. This is the one that we are going to need. For this constraint layout, I'm going to switch to design view because I think it's much better to work with the design view. First of all, I'm going to enable the blueprint so that we can see the difference if there is any, you can click on this blue stack in here and you can select this design plus blueprint. We will talk about the difference between this design mode and this blueprint in a minute. Okay, for working with the constraint layout, you can drag your UI elements like before you can drag, for example, a text view. And as soon as I did that, you can see that we have four circles at the four edges of our UI element. Let's zoom in a little bit. You can see that the four circles are at the four edges of our UI element. Let's zoom out a bit. I just wanted to show you the four circles. Also, the shortcuts that I'm using in here is control plus plus in order to zoom in and control plus minus in order to zoom out. Also, at any time, you can use control plus zero in order to have a feed screen. It's also worth mentioning that if you have a keyboard that has some numbers and keys for the calculator, the plus minus and zero from the calculator keys are not going to be helpful in here. So the shortcuts are going to be only useful for when you are using the upper numbers and also the upper plus and minus. The most basic thing in a constraint layout is to constraint your UI elements right now, you can see that we have a red area in here. Similarly, we have the same error in our component three, it says that we need to constraint your UI element. In order to constraint your UI elements, you can drag one of these circles to, for example, the edge of your screen. So right now, we have added one constraint, if we search back to our text view, you can see that we have this constraint in here. I'm talking about this two line of code in here. Okay, let's go back to the design view. We can add another constraint, for example, for the right constraint of our UI element, we can add a constraint to the right edge of our screen. But still this constraint layout is not happy. It says that not vertically constraint. It means that we need to at least add another constraint in here. And now the error is gone. And it has been changed to some warning. If you want to center your UI element into the center of your parent, you can add another constraint, for example, from the bottom of this text view to the bottom of the screen. If you want to remove one of these constraints, you can just click on the circle and you can press the delete key. You can see that the constraint will be deleted. Let's press control plus Z in order to redo that. If you take a look at this attributes pane in here, you can see that you have a slider for this text view for different constraints. Right now the number says 50. But if you want, you can change that. For example, if you move it a little bit, you can see that the text view responds accordingly. It will move according to this slider. Similar to that, we have this horizontal slider in which you can guess we can move our UI element. So constraint thing, your UI element to the edges of a screen is one way, you can also add constraints to other UI elements. For example, if I have a button in here, let's quickly add that. And let's delete the constraints of this text view, all of them. Let's move it so that we can see everything better. This time, if we want, we can constrain this button to, for example, the bottom of this text view, you can see that it moves accordingly. You can also see that when I click on one of these circles, I can see all of the available targets. For example, I can constrain it to the right of my text view. Sometimes it might not work. And you may want to add that one more time. So this way, we have constrained that our button to the bottom of this text view and also to the right of this text view. If we want to make it center, we can add another constraint to the left of this text view. And both of these UI elements are now somehow centered. Let's also add a margin so that we can see everything better. So by clicking on one of your UI elements, you can see that in the attributes pane, we can add a margin for example, from top, let's add 32. If you take a look at this component tree in here, you can see that we have no error about this button, but we have an error about this text view. It means that we have all of the necessary constraints about this button. But we need to add some constraints about this text view. For example, we need to constraint it vertically, or maybe horizontally as well. Like before, we can add the constraints to the both edges of our screen. You can also see that when I add the constraint, this button moves as well. It means that no matter where this text view is, we want our button to be constrained to this text view. Let's add another one. Let's also add a margin top for this text view as well. I think 32 is not enough. So let's say 100. Let's also add another text view. And let's see other kind of constraints. So constraining your text views, for example, from top of this text view to the top of this text view, and from bottom of this text view to the bottom of this text view is one way of having two text views at the same line horizontally. There is also another way. I'm going to press Ctrl Z two times so that we undo the constraints, we can right click on one of our UI elements, and we can select this show baseline. Now you can see this baseline. Instead of adding the two constraints from top and bottom, we can select this baseline, and we can constraint it to the baseline of this text view. This time once again, they are at the same line horizontally. Let's zoom in a little bit. In order to navigate through all of your layout, you can press down the space key, and you can drag your mouse like if you work with Photoshop, you have the same ability. You can see that both of these text views are at the same line horizontally by adding some constraint to the baseline. Once again, the baseline is not available by default, you can right click and you can select this show baseline. Let's zoom out. So we have seen that we can constraint our UI element to both edges of our screen. But what if we want to, for example, have another line, for example, if we want to move this text view or constrain this text view to some other space beside these two edges. For that, we can right click on our layout. Down in here inside these helpers, we have these guidelines, add vertical guideline and add horizontal guideline. You can guess each one of these will create a line. For example, let's add a vertical guideline. Let's zoom in a little bit so that we can see better. You can see that this line has been added to our layout, we can move it. For example, we can move it to the right of our screen. As soon as I did that, you can see that we have some margin from the left side of our screen. You can see this triangle in here. If I click on that, it will change the margin from left to the right of our screen. Sometimes this might be useful as well. Right now, the constraint of this text view is the edge of our screen. Let's quickly delete the left constraint of this text view. And if we want, we can add this constraint to this guideline. For example, we can add it in here. Sometimes once again, it might not work. We can see the difference, the text view now constrained to this guideline instead of the edge of our screen. If you want, you can constrain this text view to this guideline as well. But before that, we need to delete this baseline constraint. Let's quickly delete that. Sorry, I deleted the whole text view. And let's constrain it to this guideline and also to the edge of our screen. If you want, you can also have multiple guidelines. We will add another one in the second. So for example, I can once again right click on the layouts by going to this helpers. I can add another vertical guideline. We can see that this guideline has been added. And I can use it like I've used this first guideline. We also have a vertical guideline in our helpers. We can add this horizontal guideline. We can guess it will add a horizontal guideline. Once again, we have this triangle in here. If we click on that, it will change the margins from top to bottom. Let's also constrain this text view to our guideline. Sometimes when you are working with different UI elements in a constraint layout, adding some constraint might be difficult. For example, in here, we don't have much space. For that, we can select both of the items that we want to add constraint. For example, this text view, and this guideline, you can select multiple UI elements by pressing down the control key. After you have selected both of them, you can right click. You can go to this constraint in here. We want to constraint our text view to which is the idea of this text view to our guideline. So I'm going to say top two, let's say bottom of our guideline tree. This way we can add a constraint. Sometimes where there is not much space to work with, you can use the right click menu by selecting this constraint, you can add the required constraints. But for that once again, you need to select the both of items that you want. For example, this text view and this guideline, or if you want to add the constraint from this text view to this button, for example, you can select this text view and this button. Right now, we have set the left constraint of this text view to this guideline, we can also move this guideline. For example, we can move it accordingly to right and left. You can see that once I move this guideline, the UI elements move as well. But depending on your system, this operation in here might be a slope because as you can see, we are tracking the live response of our UI elements. If you want, you can disable this live rendering, you can go to this I in here. And you can uncheck this live rendering. Let's zoom in a little bit. Now if I move this guideline, you can see that the UI elements themselves do not move. But we can see the outline of every UI element. So in some cases, when you do not have all of the required resources, for example, some large amount of memory RAM, you can disable this live rendering. But in here, you can see the difference between this blueprint and also this design view. You can see that when I move this guideline, the UI elements inside the blueprint view are moving accordingly. And that's because the blueprint view do not render our UI elements at all. It's just some blueprint of all of our UI elements. Later on, when we add some image view to our layout, we will see the difference much better. Okay, let's move on from this part. Sometimes when you're creating your layout files, you may want to have some sample data. Or as we might call it in programming, you may want to have some placeholders. For example, right now, the placeholder for this text view is this text view. If we want, we can change that. We can right click on our element. We can go to this set sample data. And we can select some text. We can see that we have these cities, for example, it will change the text of our text view to Shanghai, for example. Let's see others. For example, another popular choice is this date in here, you can see different formats. We can select that and we can have some sample data about the date. The other one is lorem ipsum. If you search on the internet for sample text, you probably get this lorem ipsum text. Let's select that. And we can have some sample text. And according to that, we can have this text on our layout. We also have the lorem text. Let's quickly see that. So instead of lorem random, we can select this lorem which is basically this lorem text. Before we finish off this video, let's also see the sample data for this image view as well. I know that we didn't talk about image view so far in the course, but we will talk about that in the next video. We can drag some image view to our layout. And first thing we need to set some sample data for our image view. For example, we can select from the avatars. Right now, this is the avatar that by default, we have selected for our image view. If you want, you can change that by right clicking and set some sample data. We can select another avatar or we can select one of these. For example, this background. Let's select another avatar. For example, this one, like before, you can constrain this image view, for example, to the both edges of your text view. Let's quickly do that. If you take a look at the attributes painting here, you can see that for the layout widths, we have set the widths to wrap content. We can change that for example, we can say match constraint. When we do that, the widths of our image view will change according to its parent constraint, which is this text view in this case. But there is also another difference when we change this layout widths to match constraint. When we do that, if you take a closer look in here inside this constraint widget, you can see that we have this line in here. Let's click on that. And once I do that, you can see that this ratio in here has been added. It's useful for when you want to show some images from the internet when you don't know the size or the ratio of your image. Right now, the ratio is one to one. If you want, if you want, you can change that. For example, you can say one to two, you can see that now the ratio has been changed. Or let's say two to one, the ratio of our image view responds accordingly. Also, you have the same option from above in here, layout constraint ID, which you can change this two to one to once again, one to one. Also know that you have used this image view, you can see the difference between this blueprint and this design view, you can see that in the blueprint view, we are not rendering the image view. And in the blueprint view, we are not rendering our layout. It's very useful for when you're working with constraint layout, especially if you do not have the required resources, for example, if you do not have large amount of RAM, you can always go up to this blue stack icon, and you can select this blueprint so that you have only the blueprint. Okay, I think that's enough for this video. In the next video, first of all, we are going to work with this image view element. See you in the next video. In this video, we are going to talk about images in Android. And I believe it will be a short video. As always, let's switch back to our layout file. And let's change this constraint layout to a relative layout. You can keep working with constraint layout, I'm just more comfortable with this relative layout. First of all, I'm going to delete this text view. And let's create our image view. This time, instead of wrap content or match parent for the widths and height, I'm going to put some number. For example, I'm going to say 150 DP. Right now, you cannot see any image in your layout file in this preview because we do not have any placeholder. But you can see the outline of your image. If you want to have some placeholder, you can say something like this, you can say source, this SRC, and you can address some image from your project. By default, you have some images in your project. For example, in your driable folder, you have this IC launcher background. Let's select that, for example. And as soon as I select that, you can see that we can see this green image in our preview. Later on, we will talk about this driable folder and other folders that are related to images in Android projects. So this is going to be a placeholder. And if you want, we can later on change this image in our Java file. Let's also give an ID to our image view. Let's say ID, let's name it my image. Let's also move it to the center of our parent. Let's say center in parent and true. So when we have addressed this image, we have used this at driable. It means that this image, this IC launcher background lives in our driable folder. If you take a look at your project pane in the resources folder, we have seen the layout folder in which we have this activity main dot XML file. But beside that, we have this driable folder. Inside this driable folder, we have some XML files as well. So if you take a look at this IC launcher background, you can see that we have this XML file, which at the end its result is this image or to be specific is this driable. Inside this XML file, we have some elements like vector path and everything. Don't worry about them yet. We will talk about them later on in the course but at the end, the result of this XML file is this driable in here. If you want, you can add other drivers in your driable folder as well. For example, if you right click on your driable folder by selecting new vector asset or image asset, depending on your need, you can add new drivers. Let's select this new image asset. In here, first of all, we can select the type of our image right now. It's launcher icons. If you want, you can change that. For example, you can see action bar and tab icons. So basically this way you can add some icons to your project. First of all, you need to name your icon. This is going to be the name that later on you will pass to your images. For example, your image view, you can see that we have passed this IC launcher background. That name is coming from here. IC stands for icon. It's the convention to name your icons with this IC. So let's say IC alarm. For example, in Android Studio, you have some icons. For example, if you click on this icon in here, this Android icon in here, you can see the clip art, you can see that there are all sorts of icons and you can use whichever you want. Also notice that these icons are available under this Apache license. So make sure to check that before you use them in your project. Because I've named this icon IC alarm, I'm going to select one of these alarms. For example, this one, let's select okay. And in here, you probably can see the icon. It's somehow white. If you want, you can change the color by opening this drop down and select a custom color. For example, let's pass black. Now you can see the alarm better. Also notice that there are multiple sizes of this icon. And that's because in different screen sizes, the Android system is going to select one of these sizes. For example, if it's a larger screen size with a large pixel rate, it will select one of these larger images. Similar to that, if your application is going to run on a smaller screen size device, the Android system will select one of these smaller icons. Okay, let's select next from here. Once again, you can see that in your resources folder inside the drival folder, multiple images, multiple drival files with multiple qualities will be added. And you can also see the output file. This is going to be the XML file when you create your drival file. Basically, this at the end is going to create that alarm icon. Let's click finish in here. And if you take a look at your drival folder now, you can see that we have this IC alarm, which once again is presented with five different qualities. Now in our activity main dot XML file, instead of passing this IC launcher background, we can pass IC alarm. So this way by adding some drival into your drival folder, you can add some images to your project. Similarly, you can add some images into your MIP map folder as well. Right now we have some images in here. For example, we have this IC launcher. And also we have this IC launcher round, which at the end will create a rounded icon. If you want to add some extra images into your project from for example, let's say your computer, you can add them into this MIP map folder. For example, I have prepared this PNG file. I can copy that. Let's say copy. And in my MIP map folder, I can paste that. Let's select the directory. And also let's name our file. It's also very important to note that when you are importing some images into a project, the name of your MIP map file, the name of your PNG or JPEG file shouldn't have any spaces. And also for that matter, they shouldn't have any upper cases. So the name in here, I think it's fine. Let's press OK. And as you can see, this may code that PNG has been added to my MIP map folder. Now that I have this image into my project, I can address that from inside the activity main dot XML file. For example, in here, instead of saying IC alarm, I can say make code. But because we have added that file into our MIP map folder, we are getting a red warning because we are saying at the driver. For that, I'm going to delete all of this. And I'm going to say at MIP map. And I can address make code. We can see that the logo has been added into our project successfully. So far, we have added these images and drivers in our project in this Android view. Let's also check the project view and let's see if we can locate different images in the project view as well. So you can guess that it's in our app folder, inside the sources folder, inside the main folder, inside resources folder, we can see all these drivers and MIP map folders. Once again, each one of these is going to respond to the quality of the screen of the user's device. So for example, if you want to locate this may code that PNG, because it was a high quality image, a high quality image, I believe it will be inside this MIP map. xx hdpi. As you can see it's in here. But if you want to have an application that responds to each one of the screen sizes and screen qualities correctly, you need to create images for each one of these qualities and add them into your project. Right now, if you take a look at for example, this mdpi, you can see that inside this folder, we do not have any make code.png. It's not going to cause any problem in order to show the images in different screen sizes. As long as there is some image with the name make code.png, it's going to show something to the user, but it may cause some bad user experience. Okay, let's switch back to our Android view. And let's talk about how you can change the icon of your application. But before that, let's quickly run the application and let's see what is the current icon for our application. Right now you can see that the name of this application is images. And if you take a look at the list of your applications on your device, you can see that the logo of these images is this rounded Android icon. This is the icon that we have seen inside our MIP map folder. So if you take a look at your MIP map folder, down in here, we have this IC launcher round, which is this icon, which at the end will be somehow rounded. And if you want to change that, you can go to your manifest folder, you can see that we have this Android manifest.xml file. If you click on that, you can see some general information about your application. Later on, we will talk about this manifest file and also other XML files in your project. But for now you can see that inside this application tags, we have two attributes, this icon and also this round icon. Both of them are addressing the IC launcher icon for now. If you want, you can change that. For example, in the devices that you are not going to show around the icon, you can change this. Let's quickly change this one and let's address our make code. Similarly, for the round icon, I'm going to pass my code. Let's run the application and let's see if we have changed the icon successfully. If you take a look at the list of your applications once again, you can see that the icon for this image application has been changed. Okay, I think that's enough for this video. In the next video, we are going to start working on the list view and also a spinner. So in the next video, we are going to show how can we have a list of different items. See you in the next video. In this video, we are going to talk about how we can show a list of different items in our application. For example, a list of different cities or a list of different students. For that first of all, I'm going to start talking about list view. List view is one of the options that we can use in order to show a list of different options. For that first of all, I'm going to close this Java file for now. And inside my XML file, first of all, I'm going to delete this text view. And after that, I'm going to change this constraint layout to a relative layout. If you want, you can work with constraint layout, but I'm more comfortable with relative layout. After that, down in here, I'm going to say list view. For the width some height, this time I'm going to say match parent. And as soon as I do that, you can see that in here in our preview, we can see a list of different items on our screen. These are just some sample data indicating that we are going to use a list view. I'm also going to add a margin top, let's say margin top. And let's say 100dp. Let's also give an ID. But before that, if you take a closer look in here, I'm not sure that if you can see this scroll bar at the left pane in here, but it indicates that we can scroll our list view in case if all of our items do not fit on the screen. So if we have a large amount of items, we can scroll over our list view. Okay, let's give an ID to our list view, let's say ID, I'm going to name it cities list view or cities list. And I think that's enough for now. Let's quickly switch back to our Java file. And let's initialize this list view. Like before above in here, I'm going to say private list view. Let's name it list view, or let's name it cities list. Down in here inside the uncreate method, I'm going to say cities list is equal to find view by ID, r dot ID. Also, if you have noticed, I'm using a shortcut for this find view by ID method. Instead of typing all of the method, I'm using FB shortcut. If you press enter or tab, you will get the whole method. We will talk about these available shortcuts in IntelliJ and Android Studio later on in the course. Okay, let's pass the address of our list view, let's say r dot ID dot cities list. After that, we need to create the data that we want to show in our list view. For example, in here, I'm going to create an array list of different strings. And later on, I'm going to pass it to this cities list view. For that, I'm going to say array list, this one in here, of different strings, let's name it cities is equal to new array list. And after that, I'm going to add some cities to this array list. Let's say cities dot add. And let's add some items. In here, I'm adding all of these cities to my cities array list manually. But in most cases, the list of your objects will be coming from the web server or maybe your database. Because we didn't talk about those stuff yet, we are going to hard coding them and we are going to pass them manually to our array list. Okay, after providing your data, you need to pass this data to your list view. But before that, you need to create an adapter. The purpose of the adapter is to fetch the data to your list view. Let's quickly see how we can create our adapter. There are multiple kind of adapters. But the one that I'm going to use in here is this array adapter. This is the simplest one. And we are going to work with that in here. Let's say array adapter of type string. Let's name it cities adapter. Let's say is equal to new array adapter. Inside the parentheses of this array adapter, we need three things. First of all, we need a context, which I'm going to pass this later on in the course, we will talk about context. But in here, because we are inside an activity, I'm talking about this main activity, and activities are context. So this one in here is going to work fine. So by passing this, we are passing our main activity as the context. Don't worry about that yet, we will talk about context later on in the course. After that, we need to pass a layout file for every item in our list view. So for example, if we are going to show the name of a city, we need a layout for that city in our list view, we can create our customized layout. But in here, I'm going to use one of the built in layouts. For that, I'm going to say Android dot r dot layout dot, let's say simple list item one. So basically, this is a built in a layout file in which we can use in order to show different cities in our list view. After passing the context and also the layout file for every item, we also need to pass the data. In this case, we need to pass the cities are a list. So let's say cities in here. And now we have our adapter for our list view. Once again, the purpose of this adapter is to fetch the data in this case, this cities are a list to our list view. After creating your adapter, you can say cities list dot set adapter. And you can pass your adapter. Let's say cities adapter. Before running the application, let's quickly review what we are doing in here. First of all, we have created our list view inside our layout file. After that, we have initialized it inside this uncreated method in here. After that, we have prepared our data. In this case, we have created this simple array list of different strings called cities. After that, we have created an adapter in order to fetch this cities are a list to our list view. And after creating the adapter, we have passed it to our list view. Let's quickly run our application. And let's see if we can see these items in our list view. As you can see, we have created this list view and also populated the data that we have passed in our array list. Also, if we had more data that wouldn't fit on the screen, the list view would be a scrollable. This layout in here for every item is this simple list item that we have passed in here. If you want to take a look at that, you can press down the control key in Mac, it should be command key. And by clicking on the simplest item one, you can check the layout file. You can see that it's a simple text view with some attributes. Nothing special in here. You can also make your items clickable. Right now, if you click on one item, nothing happens. But you can set a listener for each one of these items. Let's quickly see that. So after passing the adapter in here, I can say cities list dot set on item click listener this phone. And I can pass my interface, I can say new on item click listener. Notice that it's adapter view dot on item click listener, it's different from on click listener. When we pass this interface, we have this on item click method in which has some inputs. The one that we are interested in is this position in here. Basically, this is going to be the position of our item in our list view. Let's quickly see how we can use that. For example, in here, I'm going to show a toast message after clicking on each one of the items. Once again, when we create our toast message, first of all, we need to pass a context, because we are inside this on item click method which exists in another interface, we cannot simply pass this, we need to pass main activity dot this in order to reference to our context. After passing the context, we can pass our text for the text in here, I'm going to say cities dot get. And for the index in here, I can pass this position. So this way, we are going to get the city name that we have clicked on. We are using this position as the index in order to get the appropriate city name from our city's early list. Also, if you have noticed when I use this cities inside this on item click method, this final keyboard has been added to the declaration of our early list. As a reminder from the Java session, when you add a final keyboard at the declaration of a variable or an object, that variable or the instance of that object would be constant. It means that you cannot change that instance. But although we cannot change the instance of these cities after declaring it as final, we can use all of the methods inside that object. For example, we can use this dot at method, because we are using this city's early list inside this on item click method which exists in another interface, the city's early list needs to be constant. And this final keyboard has been added automatically. And if I remove it right now from here, you can see that we are getting this error done in here. And it says that your variable should be constant. So let's add the final keyboard once again. Also, let's add another text in here, let's say plus selected. Okay, let's run the application once again. And let's see if we have set on item click listener successfully. So now if we click on one of the items inside our list view, for example, this New York, you can see the toast message in here New York selected Berlin Berlin selected. Okay, it seems like our on item click listener is working fine. Once again, this on item click listener is different from the on click listener. If you set the on click listener on your list view, it's not going to work according to every item in your list view. Okay, I think that's enough talking about list view. You can work around list view if you want. But I do not suggest that because in Android, we have modern solutions for populating a list of different options. For example, we have recycler view, which has a lot of flexibilities. If you take a look at your layout file inside the design view, you can find the list view somewhere inside this legacy, you can see that in here. And it's inside this legacy because these days, almost no one uses list view, I just wanted to show how can you create a list view. The reason that you may want to avoid using list view is that list view does not have much flexibility. For example, you cannot customize the layout of every item in your list view. You can create a customized layout for every item. But in recycler view, you have much more flexibilities. And also the other issue is about performance. If you have a large amount of data that you want to show in a list, for example, if you have 1000 items, in those cases, you will see the performance issue when you are working with list view. recycler view has done a much better job when it comes to performance. We will talk about recycler view in one or two videos from now. But let's move on from this part. The other layout file that I'm going to talk about is called a spinner. Let's quickly see that. I'm going to define my spinner above this list view. So in here, let's say a spinner for the width and height. This time, let's say wrap content. Let's center it horizontally. And also let's add some margin top center horizontal through margin top, let's say 50 dp. Right now, you cannot see your spinner inside this preview very well. And that's because you do not have any data inside your spinner yet. Basically, this spinner is going to create a drop down menu. For example, if you click on this, you will see a list of different options. We will see that in action in a minute. But for now, let's just pass an ID for our spinner. Let's say a student's list, or a student's spinner, it's a better name. Also, let's move our list view to below this spinner, layout below, and let's pass the ID of our spinner. Let's initialize our spinner in our Java file. Like before, I'm going to come above in here and say private a spinner. Let's name it a student spinner. And down in here inside the uncreate method, I can initialize that. Let's say a student spinner is equal to find view by ID r dot ID dot, let's say a student spinner. Once again, like the list view, first of all, we need to create the list of items, the data that we want to show in our spinner. For that, I'm going to create another array listing here. So let's say a list of different strings. Let's call it a students is equal to new array list. After that, let's pass some data to this students list. Similar to when we have worked with list views, after providing our data, we also need to create an adapter. Once again, the purpose of this adapter is going to be fetching the data into our spinner. We can create our adapter like we have did for the list view. So in here, I can say array adapter of different strings. Let's name it the student adapter is equal to new array adapter. Like before inside this parentheses, we need three items. First of all, we need the context. After that, we need the layout file for every item in our spinner. Once again, you can create your customized layout file if you want, but in here for the sake of simplicity, I'm going to use a built-in one. So let's say Android dot r dot layout dot the layout file that I'm going to use this time is this simple spinner drop down item. When we created the adapter for list view, we have used this simple list item one. But in here, we are going to use this simple spinner drop down item. After that, once again, we need our data, which I'm going to pass my students array list. After creating your adapter, you can say students spinner dot set adapter. And you can pass your students adapter. Let's run our application and let's see what an spinner looks like. You can see the spinner above in here, it's going to generate a drop down menu. If I click on this triangle in here, you can see the name of the students that I have passed into my array list. Once again, these items can be also clickable. For example, if I click on one of these, we can take some action. Let's quickly see that how can we create an on click listener for each one of these items. So after setting the adapter down in here, I'm going to say students spinner dot set on items selected listener. This is different from the listener that we have used for the list view. For the list view, we have used set on item click listener, but it's not going to work in here. Instead, we are going to use this set on item selected listener. Let's pass our interface, let's say new on item select listener adapter view dot on item selected listener. And this interface is going to generate two methods on item selected and on nothing selected. The names are descriptive on nothing selected means that if you do not select anything inside your spinner, we are not going to work with this method and we are not going to write any logic in here. Instead, inside this on item selected, we are going to show a toast message. Once again, you can see that we have this position in here in which we can use it in order to, for example, get the name of that student. First of all, like before we need the context, because we are inside another interface, we are going to pass main activity dot this. After that, for the text, I'm going to say students dot get. And as the index, I'm going to pass position. Let's say plus selected. Let's run the application and let's see if everything is going to work. So in here, you can see that even though I never clicked on any item, I see the toast message. And that's because we have used this set on item selected listener. Once again, this is different from the on item click listener. I don't know why but we cannot use on item click listener for the spinner. If you try to use that, you will get an exception. Instead, the other option that you have is this set on item selected listener. Let's see if we can show the toast message. If we select another item, for example, Sarah, you can see the toast message down in here. This is one way of showing data inside your spinner. It's useful for when you do not know what data you are going to show. For example, if you are going to retrieve the data from a web server or a database to be precise, in case your data is dynamic. But in case you know the data previously, in case your data is static, you can use another way. Let's quickly see that. So before that, I'm going to open this project pane inside my app folder inside this resources folder. We have this values folder in here, in which inside that we have this strings dot XML file. We can create a string area inside this XML file. And later on, we can pass it into our spinner. Basically, this strings file is going to be the place that we put all of the static strings. For example, right now, you can see that we have this app name string in which we have used it inside our manifest file. Let's quickly see that inside this Android manifest dot XML file, we have this label attribute. If we click on the label, you can see that it's addressing the string file. And this is the name of our string from strings dot XML file. We know for sure that the name of our application is not going to change. For example, it's not dependent on some string from our database or the web server. So we have passed it in here. In the next video, we will talk about the usages of this strings dot XML file and also for that matter, other XML files in our application. But for now, let's create a string array statically in here. And let's pass it to our spinner. So inside this strings dot XML file, you can create two different kinds of items, you can create a string or alternatively, you can create a string array. The way to do that is like this, you can say a string array, you need to name your array. For example, in here, I'm going to say students. After that, inside this opening and closing tag, I can create different items. Let's say item. And inside these item tags, I can provide the value. For example, I can say Mason, you can copy and paste this item as many times that you want. Once again, don't worry, if you don't understand this strings dot XML file, we will talk about it in the next video. Now that we have created this string array, we can pass it to our spinner item inside our activity main dot XML file. Then we have created our spinner. We have an attribute called entries. This attribute in here, you can see that we have this at array students. This is the address of our string array in our strings dot XML file. Let's pass that. And as soon as I pass that, you can see that we have some sample data in our spinner. So now that I have passed the data to our spinner statically, I don't need to pass them in my Java file dynamically. For that, I can comment all of these lines of code. For example, from here to top in here. But right now we are getting an error inside this on item selected method. And that's because we no longer have this students array. If you want to show the name of the student when you select some item, instead of using the students array list, you can use another way. Let's delete this line of code. And let's create a new toast message. For the text this time, I'm going to say student spinner dot, let's say get selected item, you can see that this method is going to return an object. Let's say get selected item. After that, we can say dot two string. This two string is just another level of conversion in order to convert the object that has been returned to a string. After that, let's say plus selected. Once again, before running the application, let's review what we have done. First of all, we have created this string array. After that, we have passed it to our spinner statically. And after that, inside our Java file, we have created this set on item selected listener. Inside the on item selected method, we have created this toast message. And we are getting the value of every item by using a student spinner dot get selected item method. Let's run the application and let's see if we have the same behavior. You can see that we have some data in our spinner. If I select Brad, for example, you can see the toast message Brad selected. It seems like our spinner is working fine. So far, we have talked about different layout files. For example, this activity main dot XML, which is a layout file. In the next video, we are going to talk about other kinds of XML files. For example, this strings dot XML, or this Android manifest dot XML. Also, we have other kinds of XML files. In the next video, we are going to talk about them. Okay, see you in the next video. So far, we have talked about different layout files in our application placed inside this resources folder inside the layout folder. For example, we have talked about this activity main dot XML file, in which we have defined the looks of our layout file for our main activity. But in Android, there are a lot of other XML files. For example, at the end of the previous video, we have taken a look at the strings dot XML file. Let's close this and let's talk a bit about that strings dot XML file. As I said, it's placed inside this resources folder inside the values folder. You can see this strings dot XML file. If you remember, I said that this is the place that you will put all of the static strings of your application. Let's quickly see what I mean by that. So for example, inside my layout file, if I define a text view, we have a text view in here, let's give it an ID. Let's say txt hello. Let's go to our Java file and let's initialize this text view. Let's say private text view. Let's name it txt hello. And down in here inside on create, let's quickly initialize this text view. Let's see what would happen if we set the text of this txt hello manually. For example, in here, if we say txt hello dot set text. And if we pass hello, you can see that we are getting some highlights in here. And the highlight says that this string cannot be translated, use Android resources instead. If you want, you can have some more information about this warning. As the suggestion says, you can press control plus F1. And you can see a whole dialogue about this warning. Basically, this in here means that this text is going to be the same in all of the languages. For example, if you have an application that has some users around the world, this text is going to be the same in all of the devices, regardless of the user's language. As the warning says, you can define this text inside your strings dot XML file. Let's quickly see how we can use this strings dot XML file in order to localize our application. So in here, I'm going to define another string, the way to do that is to open a tag and say a string. After that, we need to name our string. For example, in here, I'm going to simply say hello. And for the value of this string, I'm going to say hello. Now I can pass this string to my text view inside my Java file. Instead of hard coding this text, I can say get a string. This get a string method like this find view by ID is an inner method inside every activity. We can use that because we are extending this app compact activity. So inside this parenthesis, we can address our string file. For example, I can say our string dot, let's say hello. Right now, the result is going to be exactly as before. For example, we are just going to show hello to the user. But the option that we have in here is to create another strings dot XML file inside our values folder. For example, in here, I can right click on my values folder, I can say new value resource file. I need to name this new XML file exactly strings, let's say strings. The name is important in here, it should be exactly the same. And in here you have few options, we will talk about few of them in here. But the one that we are interested in here is this locale. Let's select that. And let's add it to these chosen qualifiers. So basically, this locale is going to be useful for when you want to expose your application to different languages. For example, if you know that you have some users from Germany, you can translate your application this way for those users as well. Let's quickly see that if we can see German in here, you can see that we have this the German the stands for do it. In the right hand side, we can select a specific region. We know that there are multiple countries that spoke German. Let's select Germany. And let's press okay. If you take a look at your values folder, you can see that now you have this strings folder in which inside that you have two strings dot XML file. The names are exactly the same. But the second one is for the German language users. Right now this strings dot XML file for German users is empty. If you want, you can define some strings in here. For example, I'm going to define my hello text in here as well. Let's say a string. Let's name it hello. It's very important that this name would be exactly the same name that you have passed inside the other strings dot XML file. If you remember in here, we have this string called hello, we are going to name it in here hello as well. Now let's pass some value for this string. For example, the German translation of hello is hello, I believe. So inside this strings dot XML file for the German users, we have a string called hello. But the value in here is different from the one that we had inside the default strings dot XML. Now that we have created two strings dot XML file, because inside our main activity, we are using this get a string method and we are addressing our hello. If some German language user uses our application, the value of this text view would be different in different languages. Let's quickly run our application and let's see the difference. Right now, the language of this device is English. And because of that, we are seeing this hello text. But if we change the language of this device to let's say German, we should see hello. Let's close this application and let's quickly change the language of this device. And let's see if we can see the difference. So we can go to the settings down in here inside the systems, I believe, or system, language and input. Let's go to languages. And let's add another language. Let's search for German, or it's equivalent to do it. We need to select a region, let's select Deutschland. And also we need to make this do it as the default language of this phone. So let's move this to above this English. And now you can see that the language of this phone has changed to do it. If we run our application once again, we should see the difference. This time you can see that we are seeing hello instead of hello. Without changing a line of code, we now have an application that looks different in different languages. So these strings that XML file is extremely useful for localization purposes. If you want, you can add another string file. For example, once again, on our values folder, we can right click, we can say new value resource file. Once again, we can name it strings. And once again, we can select this local. And if you want, you can select another language, and you can do the same process. After creating your application, if you want to translate your application for another language, you can pass this strings dot XML file to maybe a translator. And ask him or her to change some of the values for your string files. As simple as that, you can localize your application for different languages. You can see that we also have an error in here. This error is not important. Basically, it says that you do not have an equivalent string for this app name. You can also change the app name in different languages as well. But we are not going to do that in this application. Okay, let's close all of these and let's talk about another kind of XML file in Android applications. The other XML file that I'm going to talk about is this colors dot XML file. Once again, it's placed inside this values folder. Let's take a look at that. You can see that right now, we have three colors in here, like a strings, this is going to be the place that we pass all of our static colors. If we want, we can define another color in here for that we can come between these resources tag. And we can say color, we can name our color, for example, let's say blue. And for the value, we need to pass a hexadecimal value, we can get that value by searching for HTML color picker, let's quickly do that. For example, in here, if you want a blue color, a lighter blue, maybe we can copy the hexadecimal value from here. And we can paste it in our project. We can see that at the left pane in here, we have this blue color. Now that we have this blue color, we can use it in different places of our application. For example, inside our activity main dot XML file, when we have defined this text view, we can change its color. We can say color or to be precise, text color, and we can address our color. For example, I can say add color slash blue. This add color is referencing our colors dot XML file this one in here. You can see that the color of our text has been changed to this light blue. Instead of searching for different colors on the internet, you can also define them another way. For example, you can copy this color accent color. Let's copy that. Let's paste it in here. And let's define a white color. But for the value of this white color, I can click on this square. And I can select a white color. For example, let's select this white. And as you can see, now we have a white color without searching the internet, we can get the hexadecimal values for different colors. Okay, there is not much more to these colors dot XML file. I just wanted to show you how you can define new colors. Let's talk about the other XML file in Android applications, which is this styles dot XML. But before that, let's close these two. And let's open this styles dot XML. Once again, it lives inside our values folder. So basically this styles dot XML file is the place that we define the theme of our application. Right now we have one style in here. Later on, we will see that where we have used this. The name of this style is app theme. But if we want, we can override this. For example, we can change the value of some of these colors if you want, or we can change other attributes. You can also define multiple styles. For example, let's copy this whole style. And let's paste it down in here. We need to name our style differently. For example, let's say customized app team. And let's override the previous style. For example, we have this parent attribute in here, which you can guess, it's implementing all of the features of this exact theme in here. If you want, first of all, you can change this parent. For example, let's take a look at the other ones. Let's say light dot. We have this no action bar in which we are going to use in future videos, we have these dialogues. I'm not going to change the parent in here instead. If you want, you can change some of the values of this color. So in different part of our application, we may use this color primary for different texts. The value of this color primary is right now, this value in here add color slash color primary. If you want, you can change that. For example, you can say blue the color that we just created. You can see that now the color primary in these two styles is different. For the first one is this dark green. And for the second one is this light blue. Now that you have defined this customized app theme style, you can pass it to let's say different activities in your application. It means that different activities in your application, different pages in your application can have different styles. For example, one of them may have some toolbar, some of them may not have that toolbar if you use another parent. Later on, we will see that how we can do that. Also, we will talk about activities later on in the course. Don't worry about activities if you don't understand them yet. So this styles dot XML file is the place that you define different styles for your application. We will be coming back to this styles dot XML file later on in the course, specifically when we talk about material design. But for now, let's move on from this part. I believe you grasp the general idea. The other XML file that I'm going to talk about is this manifest file this Android manifest dot XML file. I believe this is the most important XML file in every Android application. Basically, this is where you define the general attributes, the general features of your application. We can see that we have this manifest tag. Inside that we have this application tag. We have seen this icon and round icon previously. Basically, these are helpful for when you want to define different icons for your application. We also have this label, which is basically the name of your application that is going to be shown to the user. You also have a general theme for your application, which as you can see is addressing the style, the app theme style. If you want, you can pass your customized app theme. It will override all of the activities in your application. But in here, I'm not going to do that. Right now inside the application tag, you have one activity, which is basically our main activity. So basically every activity needs to be declared inside the manifest file inside this application tag as well. This activity in here has been added automatically because when we have created our application, we have selected the empty activity template. But if we don't select that template, one of the things that we need to do is to come inside this manifest file and declare our activity. Inside this activity tag, you have this intent filter tag. Don't worry about that yet. We will talk about that later on in the course, I believe in the broadcast receiver section of the course. But probably you can guess the usage of this intent filter from this launcher and main. It means that this main activity is the launcher activity when we run our application. Don't worry about all of these yet, these are just some basic properties, some basic features of our application. So beside activities, you need to define three other elements in the manifest file as well. So in every Android application, we have four main components, activities, content providers, broadcast receivers and services, we will talk about all of them later on in the course, but these are the four main component of every Android application. All of them needs to be declared inside the manifest file. So as you can see, this manifest file is very important. It contains all of the important features of your application. We will be coming back to this manifest file a lot during the course. So don't worry if you don't understand all of these new stuff that we are seeing in here. Okay, the next XML file that I'm going to talk about is menus. Let's quickly see them as well. So in your project pane inside the resources folder, you can create another directory for different menus. By default, you do not have that directory like we did have for different values and layout files, we need to create that directory, we can right click on our resource folder, we can say new directory. It's very important to name this directory menu. And after that, you can see that we have this menu folder in here, you can right click on that and you can say new menu resource file. This way you can create a menu dot XML file. For example, let's name this menu file main menu. Let's create this file and let's see what does it look like. Let's switch to text view. In here, you can see that we have this menu tag. Basically, basically, menus are useful for when you want to create some sort of menu in your application. And the way to do that is to come inside this menu tag, and create different items, I can say item, you can define multiple attributes for your item, but the one that is mandatory and you have to create that is this title, you can say Android column title, and you can pass a title for your menu. For example, we can say settings in here, you can see that some menu has been created in here. Later on, we will pass this menu to for example, our main activity to have some sort of menu in our main activity. The other attributes that I have in here is ID. For example, I can say settings menu. We also can have an icon for our menu item. But I believe we do not have any icon in our project yet. Before passing an icon, let's quickly create some icons in our drival folder, we have seen how we can create different icons, we can right click on our drival folder by saying new image asset, we can create icons. In the icon type, I'm going to say action bar and tab icons. For example, inside this clip art, let's search for settings icon. You can see that we have one icon in here. Let's add that. Let's change the name to IC settings. And let's change the color to black. Let's add another icon in our drival folder. New image asset like before. Let's name this one IC LR. Let's search for LR. The color is fine. Let's just create this icon. Now that we have these two icons, we can pass them in our menu file. For example, in this item, I can say icon. Let's pass our settings icon IC settings. Right now, we cannot see the icon of this setting in here. But if you want to see that you can define another attribute that's called show as action. So we have some values for this show as action attributes. If we say always, it means that we always want our menu items in the toolbar. You can see that we have other options. For example, we have this if room, it means that place them in the toolbar if there is room for this menu item. We have also this never it means that always show the menu items like this and never show them in the toolbar. Let's change the value for now to always. And let's create another item in here. So I can say item like before the title is mandatory. And also, we are getting a warning for the previous items title. Once again, it says that you need to define the title in your strings dot XML file. Like before, this is for the localization purposes. And the best practice is to create this settings title in your strings dot XML file. In your real world applications, make sure to do that. But in here for the sake of simplicity, I'm not going to do that I'm going to cope with this warning. So let's pass a title in here. I'm going to say alarm. Let's give it an ID. Let's say alarm menu. After that, let's give it an icon. Let's say I see alarm. Let's set the show as action attribute for this one to if row. You can create as many items as you want. But I think for this simple menu item, these two would be fine. Okay, now that we have created this menu file, let's see how we can pass this to, for example, our main activity. Let's close this file. Once again, it was placed inside our resources folder inside the menu directory that we just created. In order to show this menu in your main activity, you need to open the main activity dot Java file. And you need to override another method in here. So because we are extending the app compact activity inside this main activity, we have some methods that we can override one of these methods is this uncreate method. If you come outside of this uncreate method and press Ctrl plus all, you can see the list of all of the available methods, you can see that there are a lot of them. The one that we need in here is called uncreate options menu. If you type uncreate options menu, you can see this method in here, let's select that. And in here we have this method. First of all, I'm going to delete this statement from here this return super dot uncreate options menu. And I'm going to create or inflate my menu. For that, I can say menu inflator this class in here. Let's name it inflator is equal to get menu inflator. This get menu inflator is like this find view by ID method. It's an inner class in every activity. So basically, with the help of this inflator, we are going to inflate or create our menu. After accessing to our inflator, we can say inflator dot inflate. For this inflate method, first of all, we need to address the menu file that we just created. For that, we can say r dot menu dot main menu, the menu that we just created. The second argument is the menu that is being passed to this method. Let's pass that. You can see that the return type of this method is a Boolean. This Boolean is indicating that if we have successfully inflated our menu. By this point, we have inflated our menu. And after that, we can return true. This is all of the logic that we need in order to inflate or create our menu in our main activity. Let's run the application. And let's see if we can see our menu in our application. You can see that in our activity, we have these two items, this settings icon and this alarm icon. We can also set an on click listener for each one of these many items. Let's quickly see how we can do that. So we need to override another method outside of this on create options menu method. If we press control plus all. And if we search for an options item selected, this method in here if we select that, we can override that this time, I'm going to keep this super statement, we will talk why I'm going to keep that. As you can see as the input of this method, we are getting a menu item. This is the item that user is going to click on. And we can use it, for example, to create a switch statement, let's create our switch statement. So our switch statement is going to work on the item dot get item ID. If you remember in our menu file for different menu items, we have set different IDs. Let's quickly see that. In our main menu dot XML file, we have set ID for each one of these items. And in here, we are going to act upon those IDs. Let's create our switch statement. Let's say in case it's our dot ID dot settings menu. We are going to show a toast message. Let's say toast. For the text, let's say settings clicked or settings selected. After showing the toast message in here, instead of adding a break for this switch statement for this specific case, we can return something. Once again, you can see that the return type of this method is a Boolean as well. This Boolean indicates that if we have acted according to this item successfully or not, in here after showing the toast message, we are going to return true. So let's say return true. And let's create other cases. For example, in case it's our dot ID dot alarm menu. Once again, we are going to show another toast message. Let's say alarm selected. In here, I'm showing a toast message. But in a real world application, you may want to navigate the user to some other part of your application. But more on that later on when we know about different activities and fragment. Okay, after showing the toast message, let's return true once again. And also let's create the default case. In the default case, I'm going to return this super statement, because I'm not interested in other items beside these two. So do whatever you are doing inside the parent class. So basically, I can cut this super statement from here and I can return it in the default case. Before we run our application, let's review what we are doing in here. As the input of this on options item selected method, we are getting a menu item, we can use this item ID in order to create a switch a statement. In case the ID is the ID of our settings menu item, we are showing this toast message setting selected. In case it's alarm menu item ID, we are showing another toast message. But in the default case, in case if it's another item beside these two, we are passing the job to the parent class. Let's run the application and let's see if we have set the listener successfully. So for example, if we click on this settings icon, you can see that setting selected. If we click on this alarm, we can see alarm selected. It seems like we have done a good job inside this on options items selected method. Okay, I think that's enough for this video. In the next video, we are going to continue our talk about other kinds of XML files available in Android. See you in the next video. Let's continue our talk about different XML files in Android. In previous videos, we take a look at different XML files. For example, drawable files, layout files, some files inside our map folder, we have seen strings and colors and styles. Besides this, we take a look at menus and also our manifest file. Let's see what else do we have in here. Right now, our main activity has only one layout file, this activity main dot XML. But if you want, you can create more layout files for this activity. For example, right now, this layout is for the portrait mode. If you want, you can create another layout file for the let's say landscape mode. If you don't know what the portrait and landscape modes are, let me quickly show that. So right now, this is called the portrait mode. If we change the rotation of our device, this is going to be the landscape. I think I need to activate the rotation of this device. Let's go to the notification center. And from here, I believe this is the option. This auto rotate, we need to activate that. And now if we rotate our device, you can see that now we have a different look for our application. Sometimes this might work, but if you have a complex layout file that you want to show it differently in different rotations, you need to create two separate files for each one of these rotations one for the portrait mode and one for the landscape mode. Let's quickly see that how we can create another layout file for this main activity. So inside my layout folder on the layout folder, I can right click by selecting new layout resource file, I can create a layout file or alternatively, inside this activity main dot XML file from here, if you click on this icon, you can see that we have this portrait selected right now. If you want, you can create a landscape variation for the layout of your main activity. But before I do that, I'm going to add another text. And also I'm going to add some constraints to this layout file. So I'm going to move this new text view to below my hello, bold text. Let's quickly add some constraints. As I mentioned before, if your items are too close to each other, you can always select both elements. And you can use the right click menu by going to constrain and add constraint from here. But I'm not going to do that. Instead, I'm going to add some margin. So let's save 100. So for this simple application, this is going to be the look of my application in the portrait view. The two text views are placed after each other vertically. But in the landscape mode, I'm going to put the two text beside each other. Let's quickly create a variation for our landscape mode by selecting this great landscape variation. You can see that inside our layout file. Now we have two files inside the activity main folder, we have this activity main dot XML, which is for the portrait mode. And the other one, which is for the landscape mode. And now if you want, we can change this landscape. For example, I'm going to change the constraint of this text view. Let's delete all of the previous constraints. I'm also going to delete the constraint of this text view, the left constraint. Let's place this one in here and let's add some constraint. Also another point in here that you may find useful is that if you want to center your elements, for example, horizontally, you can select the two items, for example, these two, by right clicking on the item, and by going to this center, and selecting horizontally, you can center your items horizontally. So once again, this is the view for the landscape mode, the layout for the landscape mode. And this is going to be the layout for the portrait mode. Now if I run my application, I should see the difference. You can see that in the landscape mode, the two texts are beside each other. But if we change the rotation to portrait mode, the two texts are vertically after each other. So this way, by coming to this icon in here and selecting create landscape variation, you can create another layout file for your main activity. But this is not the only option, you can also create a night version in case if you want to activate a night theme for your application. I'm not going to do that. Let's quickly see how we can create that. So in here, I can go to this create other. And from here, I have all sorts of options. For example, if you want to create a night mode for our activity, we can select this night mode, you can pass it to this qualifiers. And for the night mode, let's say night, let's create this one. And let's take a look at our project. Now inside this activity main folder, you can see that we have three activity main dot XML files. The middle one is for the night view. If you want, you can change that. For example, you can change some colors. But I'm not going to do that in here. I'm just going to ignore this layout file for the night view. Let's see what other layouts we can create for our activity. So once again, I can go to this icon in here by saying create other, you can see that we have all sorts of options. For example, in here, we have this version, in which we can create different layout files for different versions of the Android on the user's device. Let's add this to these chosen qualifiers. And in here, we can put a number. For example, if we want our application to look different, in API level 21, we can put 21 in here, and we can create the layout file. Let's take a look at our layout folder inside activity main folder. Now we have this activity main dot XML, which is a specific for the version 21 of the API. This way, you can also create other layout points and you can change them if you want. Before I finish off this video, I'm going to talk about another kind of XML files in Android. Let's right click on our layout file. And let's select new layout resource file. And let's see what an include is. So for the file name of this XML file, I'm going to say trademark. And also I'm going to change the root element to let's say relative layout. Let's select okay. And let's switch to text view. Inside this text view, you can see that we have this relative layout. So basically, you use include whenever you want to reuse some layout file. For example, now I have created this trademark dot XML file in which I'm going to put an image view and a text view inside that. After creating this layout file, I can reuse this trademark dot XML in order to show this trademark in multiple activities of my application. So the use of include tag is to reuse your layout files. First of all, let's design this trademark dot XML. In here, I'm going to say text view or before that, let's define an image view. Let's say 15 DP for the bits and height. Let's give it an ID. And for the placeholder, I'm not going to import any image into my project. Instead, I'm going to use this IC launcher background which exists in our dribble folder. Let's also define a text view in here. Wrap content and wrap content for the text, I'm going to say developed by Mesa. After that, let's move this text view to the right of our image view. Let's say to right of logo. Let's add some margin left, maybe 10 DP. Let's style this text a little bit. Let's say italic and vote. Let's also change the size of this text view. Right now, the bits and height of this relative layout, this whole parent is match parent. In here, I'm going to change that I'm going to change both of these to wrap content we receive by when we use this layout file. And also I'm going to add another attribute for both of these elements. Let's center them vertically, center vertical for both of them, et cetera, it will place them at the center vertically. So this is our simple layout file in here, we are showing a text view and also an image view. If we want to show this layout file in multiple places in our application, we can use the include tag include tag is very useful for when you have a complex layout file and you don't want to write the exact same file twice. Let's switch to our activity main dot XML file. And let's see how we can use that trademark. So down in here after the text view, I'm going to say include. And I can add a layout attribute and I need to pass the address of my layout file. In this case, it's at layout slash trademark. As simple as that, we can include another XML file inside this layout file. If you want, we can also constrain this layout file, you can see that I can select this whole layout file. But right now, if I try to constrain my layout file, you can see that it won't work. You can see that it will be placed once again at the top of my screen. And that's because we need to override the width and height of this layout file. The way to do that is to come inside this include tag. And in here for my whole layout file, I need to define my layout widths and height once again. So for example, for the layout widths, I'm going to say wrap content for the height as well. I'm going to say wrap content. This way, you can see that now we can constrain our layout file, we just need to override the widths and height of our layout file. Let's also add two more constraints. I can use this trademark dot XML file as many times as I want in different parts of my application. That can be useful sometimes. Also where you are using include tag, you may want another tag. Let's quickly see that. So instead of this relative layout, sometimes you may see merge this tag in here. So basically, what this merge is doing is that it's avoiding redundancy. Let's talk about what I mean by that. So right now, these two elements have no idea about their parents, they do not know where they are going to be used inside a relative layout, a linear layout or a constraint layout. For that reason, because they don't know about their parent, you can see that our layout does not look very beautiful in here. But if you know for sure that where you are going to use this layout file, for example, if you are going to use this layout file inside a linear layout, we do not need to write the linear layout once again, you can use this merge tag in order to avoid redundancy. At the time of rendering your layout file, this merge tag will be ignored. And these two elements will be placed inside the parent that they are going to be used. Sometimes when you know for sure that where you are going to use your layout file using this merge tag can improve the performance when rendering your layout file. But in here, I'm just going to change this to a relative layout. Okay, I think that's enough talking about different XML files in Android, we have others as well. We will take a look at them later on in the course. But for now, I think it's enough. In the next video, we are going to talk about the material design library. See you in the next video. In creating Android applications, designing is an important aspect. And creating a beautiful layout will impact the number of downloads for your application on the Play Store and also it will impact the user's feedback. But sometimes designing can be challenging, especially if you are like me, if you are more interested in the code side of the application. But luckily, we have material design as a guideline for our designing. Despite being a guideline, material design also introduces some new components that we can use in our application. Let's check the material design website and let's see how we can use that in our projects. The website for material design is material.io. If you go to this developed tab in here, you can see that beside Android applications, you can also use material design for iOS app development, you can use it for web development. And also you can use it with hybrid development with Flutter. Let's go to the Android page. As I said, material design consists of two things. First of all, it's a guideline for designing your applications. Also besides being a guideline, you have some components that you can use in your application. We will take a look at those components in a minute. But before that, if you take a look at this theming in here, for example, if you want to check the guidelines for typography theming, you can click on this link. And after that, if you take a look at this material design guideline for typography, you will see some guidelines. Basically, these guidelines are helpful for when you want to design and create a beautiful application. Basically, these are some to do's and not to do's in order to follow when you are designing different applications. So make sure to check this webpage and their guidelines. In here, we are not going to talk about guidelines. Instead, we are going to take a look at the components. If you go to this components link, you will see that we have a lot of components. We are familiar with some of these components. For example, we have seen different buttons and checkboxes, but some of them are new. Don't worry about that later on, we will see a lot of these in the course. But let's take a look at a few components that we already know. For example, let's take these buttons. Down in here in this image, you can see that we have four different kind of material buttons. These are somehow different from the buttons that we have used already in our applications. Basically, the main difference is in the styling of different buttons. Similar to button, we have all sorts of other components. For example, we have checkboxes. For some of these components, we have also some documentation and guidelines for designing them. For example, if you want to check the guidelines for designing a checkbox, you can click on that link. And in here, you can see some guidelines. So make sure to check that if you need. But let's see how we can use these components in our applications. Before that, I'm just going to say that in this video, we are not going to work with all of these components. During the course, we will be coming back to this webpage and a lot of these components. But for now, first of all, we are going to start with material buttons. We will also take a look at the floating action button. This one in here, we will also take a look at the material card and things like snack bars. Later on in the course, we will take a look at the top app bars, bottom app bars, and also things like tab layouts and a lot more. Okay, instead of talking, let's implement this material buttons in our application. In order to use material design components in your application, you need to add a dependency in your application. We haven't used any extra dependencies in our applications yet, but let's see how we can do that. If you remember, I said that Gradle will combine all of the layout files, all of the Java files, all of the static resources in our application. And beside all of those Gradle will also use the third party libraries that we use in our application. One of those libraries that we are going to use in here and later on Gradle is going to handle combining it in our application is this material design. So we need to add this material design library in our project with the help of Gradle. In order to add the material design library, you can go to this develop tab. After that you can select this Android. And inside this documentation, you can go to this getting started. And from there, you can find the dependency that you need. In this page, you can see a step by step guide for adding the library, the material design library into your project. Make sure to read this page if you need but basically what they are saying is that first of all, make sure that you are using Google repositories in your project. Let's see where that is in Android Studio. In Android Studio inside this Gradle scripts inside this build dot Gradle, this project module, you need to add the Google repository. Google repositories has been added by default into our project inside these all projects. But if you don't see this Google in here, make sure to add that the next step after adding the Google repository is to add material design dependency, you can copy this dependency from here. And you can add it to your project. Let's copy that. This time we need to go to this build dot Gradle module app, this one in here. But before that, let's close this one. And let's also minimize all these extra pains. We need to add that dependency inside this dependencies in here. For example, you can add that dependency before all the other dependencies. Let's paste that in here. But we also need to change this line because right now we have this version tag in here. And this is not the version. It's better to always check the internet for the latest version of material design, you can also use the help of Android Studio. Right now I'm getting a highlight. If I hover over this highlight, you can see that the latest version available is 1.1.0. So instead of this version, I'm going to say 1.1.0. After adding this dependency, you need to click on this sync now. And after that, Gradle will download some files to the specific material design library files from the internet and it will add the library to your project. So let's click on this sync now before that make sure that you have an internet connection. It was somehow fast and now we can use material design components in our project. Also inside these dependencies, you can see that by default we have other dependencies as well. For example, we have this constraint layout, we have these dependencies for testing, and also we have this app compared dependencies, which help backward compatibility, but more on them later on. Okay, now that we have added this material dependency, let's see how we can use them. But before using them, I'm going to add a button in my layout file. Let's quickly see that. Let's also enable this preview. And before everything, let's delete this text view. So in here, I'm going to say button, let's say wrap content and wrap content. And let's define the text. Let's say say hello. Let's also change this constraint layout to a relative layout. And let's center our button. You can see that we are seeing the previous style for our button. Now let's implement material theme. And let's see how that changes the style of our button. So for that, I'm going to open my project pane. If you remember inside the resources folder inside the values folder, we have these stars dot XML. Let's open that right now we have this app theme style in which it's parent is this team that we are seeing in here. If we want to implement material team, we can change this parent. Let's quickly do that. And the team in here is going to be theme dot material components. We also have another team called theme dot material components dot light, this one in here, we will take a look at that in a minute. But in here, I'm not going to customize this team dot material components. So for that, I'm going to delete all these three items. I'm going to use all of the values from inside this material components team. So let's delete them. We just changed the parent theme of this app theme. But right now if we switch to our activity main dot XML file, you can see that we are getting this dark team. Somehow we also changed the style of our button. This is good for a night team. But in here I'm going to change the parent team to a light team so that we can see better. So let's select this light in here. And if we switch back to our activity main dot XML file, we can see that we are seeing this beautiful light team. Our button is now a start we have some round corners. The font is somehow different and also the spacing between the letters is different. We didn't change anything for our button element. But because we are using the material team as the parent team of our application, all of these styles have been applied automatically. We can also customize this button. For example, we can change the background color of this button. But before that, let's quickly add the color to our color resources. Inside colors dot XML, I'm going to add a new color. Let's copy this one. Let's paste it and let's change the name to let's say orange, for the value I'm going to select this orange color. Now in our activity main dot XML file, if you want to change the background color of this button to the orange, we can say background tint this one in here. And we can address our orange color. We can also change the text color of this button. But I don't think that's necessary. I just wanted to show you that you can customize your buttons. Let's delete this color. As you saw on the material design website, we have some styles for our button. Let's see other styles as well. For example, in here I can say a style. Let's search for material button. You can see that we have this on elevated button style. Let's quickly see that this is basically this style that we are currently using. It's the default case. Let's remove that and let's see others. We have this button style. We have this outline button. If you take a look at that, you can see that the style of your button is changed to some outline button. Sometimes this might be useful. We also have a text button. Let's quickly see that. This is the one material components dot button dot text button. It will change our button to a text button. Sometimes you may want to use this. I'm going to stay with the default case. So I'm going to delete this whole style attribute. So you can see that using material design is very easy. Basically, we just added the material dependency into our project inside this build dot gradle module app. After that, inside the styles we change the parent to this team dot material components team. And after that, we can use all of the elements from inside the material design library. If you add another element into your layout file, for example, a checkbox by default, the checkbox from the material design library will be used. Okay, let's move on from this part. And let's talk about some of the components that we don't have in our applications if we don't use the material design library. The first of those components that I'm going to talk about in here is called floating action button. Let's delete this button. And let's see that floating action button. So in here, I can say floating action button. We can see that we have two options. We have this floating action button, and we have this extended floating action button. Let's use the first one for the beat some height, I'm going to say wrap content. And as soon as I do that, you can see that we have this beautiful button in here. This floating action button is going to be floating on our layout file, even if, for example, we scroll the page, if you want, you can change the location of this button. For example, you can move it to down below in here. For that, I can use two attributes that we haven't seen so far. For example, I can say allowing parent bottom, and I can set it to true. We can see that as soon as I do that, its location will be changed to the bottom of our screen. We can also use another attribute called allowing parent end in order to move it to the right of our screen. Let's say true. And now you can see the difference. Let's also add some margins. Let's say margin. In here, we have two options, we can add this margin right, or alternatively, we can use this margin and if I use this margin right in here, I will get a warning. Let's quickly use that. And let's see the warning. For example, in here, I'm going to say 20 dp, you can see the highlight in here, if you take a look at this, it says that it's better to use margin and the reason for this is because some of the languages starts from right. So for example, if the language of your user is Arabic, in that case, this floating action button will be placed at the left of the screen. And if you add a margin right, it's going to put the floating action button to outside of the screen. For that reason, it's better to use a margin and so let's say margin and and let's pass 20 dp. You can see that we are getting the same result in here. We also need to add a margin button. Let's say margin button. And let's pass 20 dp. You can also add an icon for your floating action button as well. Let's quickly add an icon into our driver folder and let's add it for our floating action button. Let's say new image asset on our driver folder. And let's select action bar and tab icons. And let's select a plus sign in here. Let's search for add and let's add this one. For the name, let's say I see add. And also let's change the color. I'm not sure that if this is a white color for that, I'm going to use this costume color. And I'm going to use white right now the selector is on white. So let's say choose and let's create our icon. And now you can add the icon for your floating action button. But for some reason, I cannot use the source attributes, which is the attribute to pass an icon for your floating action button. I think because I've added this dependency in my project, I need to restart my Android Studio. Or the other option is to rebuild my project. Or the better option is to go to this file and invalidate your cache and restart Android Studio. Let's select that. Let's say invalidate and restart. Now that I have invalidated my cache, I can use the source attribute. So inside this floating action button tag, I can say source, this one Android source, and I can pass my IC add icon. You can see that as soon as I do that, this icon will be added to my floating action button. If you want, you can also change the color of this floating action button. For example, let's change it to the orange color that we have defined few minutes ago. For that, I can say background tint this one in here. And I can pass color orange. You can see that the color will be changed to orange. Also, you can see that we have some sort of border for this floating action button. If you want, you can also change that the way to do that is like this, you can say app column, background tint. And this way, you can pass your new color. For example, if you want to pass a white color, first of all, you can create that color inside your color resources. And after that pass that, or alternatively, you can pass the hexadecimal value of that color directly in here. For example, I know that hashtag fff is for the white color. So if I pass that you can see that we have a white color in here. And also you can see that the border of this floating action button is now white. So this Android column background tint is for the background color of your floating action button. But this app column background tint is for the border of your floating action button. You can also define another color in here. Let's quickly see that you can say repel color. This one in here app column repel color and pass a color. For example, once again, I'm going to pass white. This repel color is the color of the floating action button when you click on it. Let's run this application. And let's see that you can see that we have this beautiful floating action button at the bottom of our screen. And if we click on that, you can see some color. That white color is this repel color. Besides that, you may also have noticed that the color of this top app bar has changed as well. This is because we are using material components team in our application. Later on, we will see that we have a beautiful toolbar when we work with material design. We will implement that toolbar in our applications later on. But for now, let's talk more about this floating action button. You can also set an on click listener for this button if you want as well. But for that, we need to have access to this floating action button inside our main activity dot Java point. So for example, like before I can say private floating action button, this one that comes from material dot floating action button package, let's name it FAB. After that, we need to instantiate it inside our on create method. Let's say FAB is equal to find you by ID. But before that, we need to give an ID to our floating action button. I don't think we did that in here. Let's say ID. Let's just name it FAB. Let's say R dot ID dot FAB. After that, you can say fab dot set on click listener is fun in here and we can pass our listening. For example, let's show a toast message. Let's say fab clicked. Let's run the application. And let's see if we see the toast message. You can see that we are seeing the toast message, it seems to be perfect. There are also other ways of using these floating action buttons. For example, one way is to use a combination of floating action button and app or navigation. In that case, we will see that we can implement a beautiful style and a beautiful design for our application. But more on that later on when we talk about bottom upboard navigations. Okay, I think that's enough for this video. In the next video, we will talk about two more components in material design library. We will talk about snack bars and also card views. See you in the next video. In this video, we are going to talk about two more material components. The first of those components is snack bar. Before we start implementing snack bar, let's see what does it look like. So if you go to material.io in these components, in this listening here, you will see a snack bar. Let's see that. This is what a snack bar looks like. It's a lot like a toast message, but the style is a little bit different. And also inside the snack bar, you can have a button that will do some action. Besides that, you can make your snack bars to be indefinite. It means that they won't be dismissed until the user clicks on this action. Also, you can style your snack bar as well. For example, you can change the color of this text and also the color of this action button. As we will see later on in the course, snack bars are extremely useful when you're developing Android applications. In order to use snack bars, first of all, you need to add the material design library into your project. So let's go to this develop tab. In this Android section, let's go to the documentation getting started. And let's copy the dependency in our project inside the Gradle script build that Gradle. Let's quickly add that dependency for the version. If you hover over this, you will see the latest version, which is 1.1.0. After adding the material dependency, first of all, in my layout file, I'm going to do some changes. I'm going to add a button. And also beside that, I'm going to give an ID to my parent layout. But first of all, you may have noticed some changes in the looks of Android Studio compared to the previous video. That's because I have updated my Android Studio, and we have slight differences. Don't worry about that. We will talk about these differences in the next video. For this video, let's just implement our snack bar. The first difference inside this new Android Studio is that you no longer can see the text and design mode in here. And if you want to go to your text, you can go to this split view in here. Once again, we will talk about these differences. Let's give an ID to our constraint layout. Let's say ID, I'm going to name it parent. Later on in this video, we will see that why I'm giving an ID to this constraint layout. Let's also go back to our design view. And let's add a button. Before that, let's delete this text view. Let's quickly constrain T. And also let's change its text. I'm going to change it to show a snack bar. Let's also quickly change the theme of my application so that we can see the material button in our project like we saw in the previous video in our values folder inside the styles folder. I'm just going to change the parent theme in here. I'm going to change it to this team dot material components dot light. If you switch back to your layout file, now you can see that we are using the material buttons in my Java file. First of all, I'm going to initialize this parent, this constraint layout and also this button. Let's quickly do that. Let's say private constraint layout. Let's name it parent. And also private button. Let's name it btn show a snack bar down in here inside the uncreate method that initialize this to parent is equal to find view by ID or dot ID dot parent btn show a snack bar is equal to find view by ID or dot ID dot. I believe it's ID was button. After that, let's set an on click listener for this button. Let's say btn show a snack bar dot set on click listener. Neo on click listener. I'm going to hand the job to another method. So let's say show a snack bar. Let's quickly create this method down in here. Private void, show a snack bar, we don't need any input. And here is how you can show a snack bar, you can say a snack bar dot make without instantiating a new snack bar, you can use this static make method in order to create your snack bar. This make method needs three inputs. First of all, we need to pass the parent layout, the layout that we are going to show our snack bar inside that. In this case, our parent layout is a constraint layout. And as you saw, I have initialized that constraint layout in here. That's the reason I gave an ID to my constraint layout. Now in here, I can say parent. After that, I need to text that I want to show in my snack bar. For example, I'm going to say this is a snack bar. The third parameter in here is a constant that will indicate the time that you want to show your snack bar. And you can pass that constant like this, you can say a snack bar dot, you have three constants in here, this length long, length short, and also length indefinite, the long and short are descriptive. But if you pass length indefinite, you will show your snack bar indefinitely. And it won't be dismissed until the user clicks on that action button. Let's select this one for now, length indefinite. After this make method, you can call dot show method in order to show your snack bar. This is going to be a really simple snack bar and we don't have any action yet. Let's see if it's going to work. If we click on this button, we should see our snack bar. And here it is. It's a really basic snack bar. And we don't have any action beside that we haven't changed the style of our texts. Also because we have passed this length indefinite, there is no way to dismiss this snack bar. Let's quickly change this constant to length short. And let's see the difference. Now if we show our snack bar, you can see that it will be dismissed after a few moments. Okay, now let's see how we can add an action to our snack bar. But first of all, I'm going to change this constant to length indefinite once again. And before the show method, I'm going to call another method. That method is called dot set action. First of all, we need a text in here, this is going to be the text of our action. For example, if you want, you can say retry in here. After that, you need an on click listener, let's say new on click listener. This is going to be an interface and inside the on click method, we can do whatever we want when the user clicks on this retry text. For example, in this case, I'm just going to show a toast message. Let's say retry clicked. Let's see if we can see the action. As you can see in here, now we have this retry option. Remember that the length is still indefinite, but if we click on this retry, the snack bar will be dismissed. And also we will see a toast message. Let's also see that how we can change the color of these two texts, this retry, and also the color of the message of our snack bar. For that, once again, before the show method in here, I'm going to call another method. Let's say that set action text color in order to change the color of our action text. In here, you can pass your colors in two different ways. First of all, you can address the color from your color resources. If you remember in your project inside the resources folder, inside the values folder, you had these colors that XML file in which you have few colors inside that you can address one of these colors inside your set action text color like this, you can say get color. And after that R dot color dot, for example, color primary. Beside that, if you have noticed, we have some colors that are coming from the material design libraries. You can see that we have these colors as well. But for example, right now, if I use this color primary in here, you can see that we are getting this warning. And this warning says that you can use this method in API level 23 and higher. There is also another way to get our color without seeing this error. Let's quickly see that. Let's say get resources. This phone dot, let's say get color. Inside this method, you can address your color, you can say R dot color dot, for example, color accent. Let's also see the other way. Instead of using the resources in my project, I can use a Java class. So for example, instead of this whole method in here, I can say color with capital C, which is coming from Android dot graphics dot, let's say red. This way, we can get the red color with the help of this color class. So if you don't have this red color in your resources, you can also use this class. Okay, now let's see how we can change the color of the message of our snack bar. For that, I can say dot set text color this method. Once again, in order to pass a color, you have two options. In this case, I'm going to say color dot, for example, yellow. Let's run the application and let's see if we have successfully changed the color or not. Let's show our snack bar. You can see that the color of the message is yellow. And also the color of our action button is red. Okay, I think that's enough talking about the snack bar. Later on, we will use a snack bars a lot in the course. The next material component that I'm going to talk about is material card view. Let's quickly see what does it look like in material.io. Once again, inside this components tab inside these cards, you can see your card views. Let's scroll down a little bit. This is what card view looks like. You can use it to for example, show different items in your application. You can mix UI elements in form of a card. Besides that, you can also have some actions for your card view. Also, you can have some corner radius. And also you can have some shadow or elevation to be precise beside your card view. In this video, we are not going to implement the actions. We will do that later on in the course but for now, let's just implement a simple card view in our application. We have added the material design dependencies in our project so we can add the card view without any problem. But before that, let's close this style and colors. In my layout file in here, I'm going to add my card view below this button. Let's wish to split view and let's add that down in here. I'm going to define my card view. Let's say material card view. This one beside the material card view, you also have a native card view but the style is a little bit different. If you don't want to use the material card view, you can always go to developer.android.com and get the dependency from the Android X libraries for card view. But in here, let's implement this material card view. I'm going to enter my widths and height manually. For the widths, I'm going to say 100dp. I think that's fine. And for the height, let's say 200dp. It has an odd shape. I think it's better to change the widths to 150dp. Let's give it an ID. I'm going to say card view. After that, inside this card view, let's enter some elements. But before that, let's quickly constraint our card view. Inside this card view, first of all, I'm going to define a relative layout. For the widths and height, let's say match parent. The parent is this card view. So we are going to fit the whole card view. And inside this relative layout, I'm going to put my elements. For example, I'm going to put a text view, wrap content and wrap content. Let's also center it horizontally. For each text, let's just say hello. Let's also change the style of this code. Let's say text style. And let's pass bold beside that let's increase the size. Let's say 18sv. After that below this text view, I'm going to define an image view. You can see that in a card view, you can have multiple UI elements. For the widths of this image, I'm going to say 140dp. And for the height, let's say match parent. I'm going to move this image view to below this text view. So let's say layout below. But before that, I need to give an ID to this text view. Let's say ID, txt hello. Let's also add a margin top and let's center this image view. Margin top, let's say 10dp, center horizontal true. Let's also give it a placeholder. Let's say source. I'm going to pass this IC launcher. Okay, I think that's enough for understanding the card view. Besides that, in the card view element, you have other attributes as well. For example, if you want to make the corners of your card view radius, you have this option corner radius, card corner radius, you can save five dp, for example, right now you may not see the difference. But if we run our application, we will see the corner radius, you can also change the corner radius if you think that five dp is not enough. The other option that we have in here is this card elevation, in which we'll give some 3d shape to our card view some shadow behind our card view. Once again, I'm going to say five dp. You can also define this card view like any other UI elements in your Java file. Let's quickly do that private card view. In here, you can see that we have two options. We have this card view, which is coming from androidx.card view. And also we have this material card view, which is coming from the material design libraries. In here, we are going to use this material card view. But once again, the difference is only in this side. Let's name it card view. And down in here inside the uncreate method, let's initialize it. Let's quickly set an unclick listener for this card view. Card view that said uncreate listener. Decide that you can see that we have a lot of options in here. We will talk about them later on in the course. Set uncreate listener. Let's say new uncreate listener. Let's just show a toast message. Let's run the application and let's see what does our card view look like. Our card view looks like something like this, which is not that good. But we can do much better with the card views. We will do that later on in the course specifically when we talk about recycler view, the combination of recycler view and card view for its items will create a really beautiful layout file. We will see that I believe in the next video. But in here, you can see that we have this corner radius and also we have this elevation, which is this 3d shape for our card view. Besides that later on in the course, we will see how we can create an expandable card view. That means that we will have some button in here, for example, an arrow, in which by clicking on that we will expand our card view. And we will see some more information and maybe actions for our item in our card view. Okay, I think that's enough for this video. In this video, I just wanted to show you how you can create a snack bar and also implement this card view. In the next video, we are going to start talking about recycler view. In previous videos, we have seen list view for showing different items. But recycler view is a much more better option to show a list of different items. In the next two or three videos, we are going to see how we can use recycler views. See you in the next video. In this video, we are going to talk about recycler view, which as I said before is another option for showing a list of different items in our application. But before that, as you can see, I've updated my Android Studio and in here we have some changes. Before talking about recycler view, I'm going to show some of these changes in the newest version of Android Studio. I strongly suggest that you always keep your Android Studio updated, you can do that by going to this health menu. Down in here, you can check for different updates. And if there is any update available, you can see a list of different options. This in here is Firebase services, we are not going to use that. I'm going to cancel this update, you can see that I've also have some updates for my emulator and hacksome installer. I will update them after this video. But for now, let's just say remind me later. Also, if you remember from the installation videos, I've said that always check the updates from a stable channel. If you are not sure about your channel, you can always go to settings by going to this file tab in here, by going to settings. In here if you check for updates, you can see that my updates are being checked from inside a stable channel. We have others as well. These are for preview purposes. And it's basically for professional developers to check new features in Android and report some bugs if there is any to the Android team. But for you for the starter, it's probably best to check your updates from a stable channel. The first thing that is different in this newest version of Android Studio is the way you go to full screen. You can go to full screen by going to this view menu. And by going to appearance. From here, you can go to full screen. In previous versions, this option was somewhere down in here. Let's go to full screen mode. The other change that you can probably see in here is this component tree. The style in here is a little bit different. There are not much changes in here just the style. But there is a very important change above in here, you can see that down in here, we no longer have that design and text view mode. Instead, above in here, we have three options right now, we are inside the design view, we can also select this one to go to the text view. And in between these two, we have this splitter mode. As you can see, it acts like if you have enabled preview inside your text view, but there is a difference. Before that, let's quickly minimize this project pane. From here from inside this splitter view, you can also enable attributes. For example, if I select this button, I can see the text view of this button, I can see the design view of this button. And also I can see all of the attributes in here as well. This is going to be helpful, especially if you are using multiple monitors. For now, I'm just going to minimize this attribute pane. You can also change the size of this preview. Besides attributes, you can also enable this palette from here in which you can see all of different layout elements. And you can drag them directly into your design view. Once again, this is going to be helpful if you are using multiple monitors. The other thing that you can see in here is this resource manager, we had this resource manager in Android Studio 3.5. But there has been some improvements in this newest version. Basically, inside this resource manager, you can see all of the static resources inside your project. Previously, if you wanted to see different drivable items inside your project, you could have go to this project pane in here. And inside the resource folder, you could have checked your drivels. Now with this resource manager, you can have access to those drivels more easily. Also beside that, you can see different colors, you can see different layouts, midmaps, strings, and also if you click on these three dots in here, you can see all sorts of resources in your project. Also, if you want, you can use these resources directly from here. For example, right now in our layout file, we have this image view, which its source is this IC launcher background, which exists in our drivel folder. If we want to change this to this IC launcher midmap file, we can simply drag this IC launcher, and we can paste it in here, you can see that the source of our image view has not changed. Similarly, we can do the same thing for strings. For example, right now in our string resources, we have this app name string, we can drag that for example, instead of this hello, we can see that the text has been changed. Let's undo the changes. So from time to time, this resource manager can be useful. The other thing that has changed in this newest version of Android Studio is the font of my code. I actually don't like this font, and I'm going to change it to the previous font that we had in our Android Studio. For that, I can go to this file inside these settings. We can search for fonts. And in here, you can change the font. For example, I think I'm going to select this one. Let's press OK. And yes, it is the previous font that we had when we worked with different layout fights. Also, beside Android Studio, I've updated my Gradle tool as well. If you want to check that you can go to your project menu, you can go to this Gradle script. We have changed two things about the Gradle. First of all, if you take a look at this Gradle dot wrapper properties, you can see that you have the latest version of Gradle in here. And also beside that, if you go to this build dot Gradle project module, you can see that we are using the latest Gradle tools version. So beside Android Studio, I've updated my Gradle as well. Probably you wouldn't see any difference when you update your Gradle. In most cases, it's going to fix some bugs and also it may improve some performance. Once again, my suggestion is to keep everything updated when you're working with Android Studio. Okay, let's move on from this part, and let's talk about RecyclerView in Android Studio. For that, I'm going to close this project and I'm going to create a new project. Let's say start a new Android Studio project. Now that we have in here, Android Studio has a new update in these templates as well. For example, inside this TV, you can see that we have other options for different operating systems or for different devices, some new templates has been added. But we are not going to work with them like before, we are going to use this empty activity. Let's name this project RecyclerView or let's say RecyclerView example. It's interesting that in here we have this new option in here. It says use legacy android.support.libraries. So basically, before Android X, we had to use support libraries for having backward compatibilities in older devices. As you saw in the previous videos, the use of Android X was mandatory, but now in here we have this new option. I don't think we are going to use this legacy support libraries in our course, but it seems like we now have this option. Okay, let's create our project. And let's see how we can use RecyclerView. For that, we have two options. First of all, we can go to our activity main.xml file. As you can see, we have this RecyclerView option in here, but before using it, we need to download its dependency into our project. We can click on this download option in here, and it will be automatically added to our Gradle file. Or if you don't want to add it from here, you can always search for RecyclerView dependencies and add it manually into your Gradle file. Before I add this RecyclerView, let's quickly open our Gradle script, build.gradle module app. Down in here in these dependencies, you can see that we don't have any RecyclerView. Let's download this RecyclerView by clicking on this. You can see a warning in here, would you like to add this now? Let's say okay. It seems like we have added RecyclerView successfully. Let's check our build.gradle file. And then in here you can see the RecyclerView. But as you can see the highlight in here, this is not the latest version. For that reason, it's always better to check the internet for the latest RecyclerView dependencies. The highlight in here says that you have version 1.1.0 available. So let's change this one to 1.1.0. And let's sync our project. Okay, now that we have added this RecyclerView dependency, we can add it to our layout file. I'm going to switch to TextView from above in here. And I'm going to minimize this resource manager. First of all, I'm going to change this constraint layout to a relative layout. After that, like before, I'm going to delete this TextView. And let's add a RecyclerView. So you can say RecyclerView. This option down in here. For the width and height, let's say match parent, I'm going to match the whole relative layout. Let's also give it an ID. Let's say contact RecyclerView. As you can guess, I'm going to show a list of different contacts in my RecyclerView. After that, we can finish creating our RecyclerView. And if you enable your preview from inside this split view, you can see that we have these options inside this RecyclerView. I'm also going to add some padding to this parent relative layout. So in here inside the starting tag, let's say padding, and let's say 10dp. That seems better. After that, we need to initialize our RecyclerView in our Jolla file. So inside this main activity that Jolla file, first of all, I'm going to say private RecyclerView. This one that comes from Android x dot RecyclerView widget. Let's name it contacts RecyclerView. And down in here inside uncreate method, let's initialize it. Contact RecyclerView is equal to find view by ID or dot ID dot contact RecyclerView. When we have worked with ListView right after this point, right after initializing our ListView, we could have create an array adapter. And after that, we could have passed our array adapter to our ListView. But when we are using RecyclerView, we need to create our own adapter. Creating your own RecyclerView adapter is probably the most complex code that you have written so far, but we are going to go through each step together. Before creating our adapter, we also need a layout file. If you remember, when we have used ListView for every item in our ListView, we have passed a built in layout. In RecyclerView, we need to create that layout as well. So inside my project, inside the resources folder, inside the layout folder, I'm going to create a new layout resource file. I'm going to name this one contacts list item. I'm also going to change this root element to a relative layout. Okay, let's create our layout file. And let's switch to our text view. If you remember from previous videos, I said that when you are working with RecyclerView, you have all sorts of flexibilities in designing your items layout files. We will take a look at more complex layout files. But in here, I'm just going to add a simple text view. Let's switch to the split view so that we can see the preview. Okay, let's say text view, wrap content and wrap content. For the text, let's say contact name. Later on in our RecyclerView, we are going to change this text view. Besides that, let's also give an ID to this text view. Let's say txt name. I'm also going to change the height of this relative layout to wrap content because we don't want to occupy the whole screen for just one item in our RecyclerView. For that, let's change this font to wrap content. Let's also add some inters in here so that we can see it better. And also, let's add some padding. Let's say padding, and let's pass 10 dp. Sorry for that. Let's also give an ID to this relative layout, we will see how it can be useful. Let's just name it parent. So this in here is going to be the layout file for every item in our RecyclerView. Now that we have created this contacts this item dot XML file, we can create our RecyclerView adapter. For that, we need to create a Java class in our project. So inside our package, I'm going to say new Java class. Let's name this class contacts RecyclerView adapter. Let's create our class and let's see what we have in here. So first of all, before everything, I'm going to create an inner class inside this class. We will see what this inner class is. This inner class needs to be public, let's say public class. I'm going to name it viewholder because it's the convention. This viewholder class needs to extend RecyclerView dot viewholder this class in here. But as you can see, we are getting an error in here. And that's because we need to create our constructor. Let's quickly do that by pressing Alt plus insert. This inner viewholder class is going to hold the view for every item in our RecyclerView. For example, in this case, it's going to generate a new contact this item, in which later on, we will see how we can use this layout file and also all of the elements inside that. So basically, this inner class is responsible for generating our view objects. If you want to have access to elements inside your view object, you can add them as the fields of this inner class. For example, in here, I can say private text view. If you remember, we had a text view in our list item. The ID was txt name. Let's name it txt name. And down in here inside the constructor, let's say txt name is equal to find view by ID. But because we are not inside an activity, we cannot use this find view by ID method like this. Instead, what we can do is that we can use this view object that has been passed to this constructor. For example, I can say item view dot find view by ID. We can see that we have this method in here. So the only difference is that inside an activity, you can simply say find view by ID. But in here, because we are not inside an activity, we can use this view, we can say item view dot find view by ID. After that, we can address our text view. I can say r dot ID dot, let's say txt name. If you have other elements inside your layout file, you can add them like this one by one. We will see that later on in few minutes. But for now we are done with this interview holder class. Let's minimize this. And now we can extend the recycler view adapter at the declaration of our adapter class. The way to do that is like this, we can say extends recycler view dot adapter. We can see that we have this option. Also take a look at this VH in here it stands for view holder. If you import this adapter inside the diamonds, we need to pass view holder. There are also multiple view holders make sure to import the one that is inside this class this org dot make code dot your project name. You also have one in Android x dot recycler view. So make sure to don't confuse them. If you remember when we have used array adapter for least views as the data type of our adapter, we have passed a string. This view holder class is exactly like that. And we are saying that the data type of our adapter at the end is this view holder class, the class that we created inside our adapter. Okay, now that we have extended recycler view dot adapter, we need to create some methods, or to be specific, we need to implement some methods. For that, I can press control plus I. And as you can see, we have three mandatory methods on create view holder on bind view holder and this get item count method. Let's implement all three of them. We are also going to need a constructor for this adapter class. Let's quickly create that by pressing alt plus insert by going to constructor, we can create our constructor. Before explaining these three methods in here, I'm going to create a model in my project. As I said previously, in this video, I'm going to show some contacts inside my recycler view. And I'm going to create a model for those contacts. So inside my project, I'm going to create a new Java class. Let's name it contact. For this contact, I'm going to define some features. First of all, let's say private the string name. After that, let's say private string email. After that, I'm going to define a new string, let's say private the string image URL. We will see how this one is going to be useful. Basically, we are going to show some images from the internet by using the URLs. After that, we need to create our constructor. Once again, by pressing alt plus insert, we can do that. Let's also create some getters and setters. I'm not sure that I'm going to use all of them. Later on, if we didn't use them, I will delete them. Let's also create a two string method. This might be useful as well. Okay, now we have our contact model. Let's close this class. So once again, inside my recyclable view, I'm going to show a list of different contacts. Because of that, I need to pass the list of different contacts to this adapter class. For that, before everything above in here, I'm going to create an array list or to be specific, a private array list of different contacts. Let's say private array list of contacts. Let's name it contacts is equal to new array list. It's very important to initialize your array list. If you don't initialize it, you will definitely get an all pointer exception. Also, because we have set these contacts array list as private, we also need to create a setter method. So that later on, for example, from inside our main activity, we can set the initial data for our contacts. For that down in here, after the get item count method, I'm going to press alt plus insert. And by going to this setter menu, we can create a setter for our contacts array list. Later on from inside our main activity, we will pass our data via using this set contacts method. But there is a very important point in here. Imagine that you are getting your data, for example, the list of your contacts from a web server from internet, the list of different contacts that are coming from the internet may change during the time. So the list of different contacts inside your recycler view should be changed as well. If you want at any time, you can reuse this set contacts method in order to change the data inside your adapter. But in order to refresh the data inside your recycler view, you need to use another method inside this set contacts method. That method is called notified dataset changed this one in here. So basically the data set for our adapter in this case is our contacts array list. After changing the list of different contacts at any time, we are going to notify the adapter that the data set has been changed. This way, we can refresh our recycler view with the new data that we have received or passed to this adapter class. Okay, let's move on from this part. And let's start working on these three different methods. The simplest of these methods is this get item count, you can guess its purpose, it's just going to return the count of different items in your adapter. In this case, we know that the data in our adapter is a list of contacts. So we can simply return the list of our contacts, we can say contacts dot size. That's all we need to do inside this get item count. For some reason, recycler view needs the number of items inside your adapter. And in here we can simply return that. Okay, I think that's enough for this video. In the next video at the beginning, we will start working on these two methods. After that, we will see that how we can have more complex layouts in recycler view. And after that, we will see how we can use that image URL in order to show different contact images in our application. Okay, see you in the next video. Okay, let's continue our talk about creating a recycler view adapter. But before that, let's quickly have a review of what we have done so far. So first of all, we have added the recycler view dependency in our gradle script. If you take a look at build dot gradle module app, inside these dependencies, you can see that we have added recycler view. After that, we have added this recycler view in our activity main dot XML file. Inside this relative layout, we have this recycler view. After that, inside our main activity dot Java file, we have initialized our recycler view. After that, it was the time to create the layout file for every item in our recycler view. We have done that by creating a new layout file called contact list item in our layout folder. If you want to take another look, it's a simple relative layout, which contains only one text view. Later on, we will change this. After creating the layout file for every item, it was time to create our adapter class. We have done that by adding a new Java class. In our package, the name of that class was contacts recycler view adapter. Inside this class, first of all, we have created this inner class. We have named it view holder because it's the convention. After that, we have extended the recycler view dot view holder. We needed a constructor. So we have created this constructor in here. As I said in the previous video, this view holder class is responsible for holding the view items for every item in our recycler view. We can also instantiate all of our UI elements from inside our contacts list item dot XML file inside this view holder class if you want. After creating this view holder class, this inner class in here, we have extended the recycler view dot adapter class in which as its data type, we have passed our inner view holder class. When we extended this recycler view dot adapter, we needed to implement three mandatory methods. This uncreate view holder on bind view holder and get item count methods. We are going to talk about these methods in this video. But before that, we also created a model for our contacts. We have added that in our package. This contact has a name and email and also an image URL later on in this video, we will see that how we are going to show an image based on its image URL. After creating our model inside our adapter class, we have created an array list of different contacts in which we have named that contacts. It was also important to initialize this array list. I said that we are going to get an all pointer exception if we don't initialize our array list. Also later on when we create an instance of this adapter class, we are going to need a constructor. So for that, we have created this empty constructor. I believe later on, we will change this. Also in order to pass the data into this adapter class, in this case, an array list of contacts, we have used this set contacts method, in which we are going to call it from inside our main activity. After passing the data to this adapter, we have notified the adapter that the data set has changed, so that we can refresh the list of items in our recycler view. Also in the previous video, we have talked about this get item count method. Once again, it's going to return the number of items in our adapter. In this case, we have returned our contacts array list dot size. Okay, now it's time to work on these two methods. But before everything, let's close all of the extra classes and files. And let's start working on this on create viewholder method. As you can see, the return type of this method is a viewholder. It means that this method is the place to generate our viewholder, the place to instantiate our viewholder class that we have created down in here. In order to create our viewholder class, first of all, we need to create a view object, we can do that by saying view, this one in here, let's name it view is equal to if we were inside an activity, we could have said get layout inflator, but because we are inside a class beside our activity, we can't use that. Instead, we can say something like this, we can say layout inflator with capital L dot from this method in here, you can see that this from method is waiting for our context. You can also guess by the style of this from method that this is a static method. In here, we don't have any context, but we can use this view group in order to get the context. Let's get the context from this view group. And I will talk about it. You can see that the name of this view group is parent. So I can say parent dot get context. As you can see in here, we are creating a view object. And we are using this layout inflator to generate that view object. The job of this layout inflator is that to inflate a layout. For some reason, this layout inflator needs a context. So we can say dot from and inside that method, we can pass our context. The way to inflate our layout with the help of this layout inflator is that to use dot inflate method. So in here after this from method, we can say dot inflate. And after passing some arguments, we can generate our view object. In here, we need to pass three arguments. First of all, we need to pass the address of our layout file for every item in our recycler view. I mean that contacts list item dot XML file that we just created. So for that, I can say our dot layout dot let's say contact list item. After that, we need to pass our view group. In this case, its name is parent. Once again, I will talk about it. And also after that, we need to pass a Boolean. I will talk about that after I talked about view group. Let's pass false in this case. And now we have our view object. Okay, let's talk about these two arguments in here, this view group and also this Boolean. Basically, the view group is the parent of all of the layout files. For example, it's the parent of relative layout, linear layout and also constraint layout. This view group can be used to group different views inside it. If you want to make sure of that, for example, you can go to your main activity just for testing purposes. If we say private relative layout, let's name it relative layout. From the previous videos, we know that if you want to check some documentation in Android, we can press down the control key. And by selecting the class name, we can have access to the relative layout documentation and also declaration. In here, you can see that this relative layout is extending view group. So once again, view group is the parent of all of our layout files. But why we are passing this view group as one of the arguments inside our adapter class before talk about that, let's quickly delete this line of code, we have created this just to read the documentation and declaration. So in here inside this inflate method, we are passing this view group. Basically, this tells that where do you want to attach your view object. For example, when we create an instance of our adapter object from inside our main activity, because in our main activity layout files, we have defined a relative layout, this view group is going to be a relative layout. And this view object in here, our layout file for every item is going to be attached to that relative layout inside our main activity. That's also the reason why this view group has the name of parent in here. But what is this Boolean in here, you can see that the name of this Boolean is attached to root. And also I'm passing false in here, I just said that I want to attach my view object to its parent. I'm passing false in here because if we pass through, it will be a redundant job. We already passed our view group as the parent of our view object. And if we pass through, it's going to be redundant. We have this Boolean because we can also pass null in here. For example, if you're not sure about our parent, and about where our view is going to be attached, instead of our parent view group, we can simply pass null. You can see that the name of this argument has changed to root. So if you pass null, you're not going to be sure about the place that this view is going to be attached to. But of course, this is an option that you have. Once again, I'm going to pass parent. And for the Boolean, I'm going to pass false. So at the end of this line of code with the help of this layout inflator dot inflate method, we have our view object. Now it's the time to create our view holder object. And after that return it. If you take a look at the constructor of this class that you have created, you can see that this constructor in here is accepting a view. Now that we have our view object, we can create an instance of this view holder class. So above in here before the return statement, I can say view holder, the one that exists in our adapter class, not the one inside the Android extra recycler view. Let's say view holder, let's name it holder is equal to new view holder. And let's pass our view. After that, let's return our holder. So once again, the purpose of this method in here this uncreate view holder is to create an instance of our view holder class for every item in our recycler view. Later on, this holder will be passed to this unbind view holder method as you can see in here. And we can use it in order to change the properties of our UI elements. Let's see how we can do that. So inside this unbind view holder method, which I believe is the most important method inside every recycler view adapter, we are going to use the properties of our view holder class. For example, right now inside our layout file, we have only one text view. So if I want to change the value of my text view, I can say something like this, I can say holder dot txt name dot set text. And we can pass our text. You can see that in here we are able to use holder dot txt name. If you remember inside our view holder class, we had such a field. But also this field was private. If you remember from the Java session, I said that whenever you use inner classes from inside the parent class, you can have access to all of the private fields and methods of your inner class. In this case, inside this adapter class, we can use this holder dot txt name, even though it's private. Okay, but what do we pass inside this set text method? As you can see, beside this holder, we also are getting some integer called position. It's exactly like the position that we had inside list view adapters. This is going to be the position of the item in our recycler view. Once again, we can use this position in order to get the data, for example, from our contacts array list. For example, inside this set text method, I can say contacts dot let's say get. And in here as the index, I can pass position. Also during the time I've seen that the name of this integer was different. Sometimes it was named I sometimes it was position and also I think I've seen others. But basically, this integer is just the position of every item in your recycler view data set. Okay, after getting the corresponding contact, we can use dot get name, for example, in order to set the name of our contact to this text view. This is going to be the simplest recycler view that you can create. You can have all sorts of UI elements inside your list item layout file. And after that, inside this unbind view holder method, you can also set different on click listeners for each one of UI elements. But more on that in few minutes. So by this time, our adapter class is ready, we have done a great job. And we have created our recycler view adapter class. Now that we have created our recycler view adapter, it's time to switch back to our main activity and pass some data to this adapter class. So inside this on create method, we have instantiated our recycler view. After that, we need to create an array list of different contacts. For example, let's say array list of different contacts. Let's name it contacts is equal to new array list. Once again, I'm passing the data manually in here because we don't know anything about databases and web servers yet. In a real world application, these data are probably coming from a database or a web server. Let's quickly add some data to our contacts array list. As you can see, I've added some contacts into my array list. For every contact I've selected a name also an email. And beside that, I've got this image URLs from the internet. There is just one point in here. And that's regarding these image URLs. Sometimes when you're copying the address of some image from the internet, that address may not have an extension. For example, like this dot jpeg or dot png. Those images are not going to be useful in here. So make sure to select the images that have the extension of dot jpeg or dot png. Just because some students asked me before how to get the address of these images. Let me quickly show you one example. For example, in Google images, you can search for different images. And by right clicking on the image, you can copy the image address. For example, in another tab, you can paste the address, if it's ending with dot jpeg or dot png, you're good to go. Okay, after creating your contacts, it's time to create your recycler view adapter. For that, I'm going to say contact recycler view adapter. Let's name it adapter is equal to new contacts recycler view adapter. We didn't need anything for the constructor. So we are good to go. After that, we can use the set there method inside our adapter, we can say adapter dot set contacts, and we can pass our array list. After creating our adapter instance and setting the data, we can set this adapter to our recycler view. So down in here, I can say contacts recycler view dot set adapter. And I can pass my adapter. In a list view that would be the end of everything. And we could have test our application. But in recycler view, there is also one more step. We also need to set a layout manager for our recycler view as well. Let's quickly set that and we will talk about let's say contacts recycler view dot set layout manager. In here, we have few options. First of all, we can pass a linear layout manager. And we can pass that like this, we can say new linear layout manager, in which for its constructor, we need the context. This time, because we are inside an activity, we can safely pass this as the context. By setting the layout manager of our recycler view to a linear layout manager, we are saying that display the items in our recycler view in a linear fashion. The other option that we have is grid layout manager, we will take a look at that. But in here, this linear layout manager is by default vertical. If you want to change that, for example, if you want to have a horizontal view, you can do that, we will do that in a minute after running our application. So by this point, our application is ready to test. We have created our recycler view, we have instantiated down in here. We also have created this dummy list of contacts. After that, we have instantiated our adapter class. We have set the data inside this adapter class. After that, we have set the adapter to our recycler view. We also have set a layout manager for our recycler view. Let's test the application and let's see what does a recycler view look like. As you can see, the list of different contacts name are being shown inside a recycler view in my activity. If I had more contacts, I could have a scrolled my recycler view and I could have access to all of them. Right now, they all can fit on the screen. So this is not a scroll view. Let's quickly change this linear layout to a horizontal linear layout and see the difference. So in order to have a horizontal linear layout, after this context, you can say linear layout manager dot horizontal, this one in here. This is a constant in which you can use in order to have a linear layout manager. Besides that, you also have a Boolean in here. Let's pass that I'm going to pass false. As you can see, the name of this Boolean is reverse layout. If you want to reverse the order of items inside your recycler view, you can pass through in here. But I don't see any reason for doing that. So I'm going to pass false. Let's run the application once again, and let's see what a horizontal linear layout looks like. You can see that this time right now, we are seeing only one contact on the screen. And that's because when we created the layout for every item in our recycler view, we have passed match parent as the widths of the item. But if you want to see other items, you can scroll the window horizontally, you can see that we are seeing other contacts. So this is what this horizontal linear layout looks like. Okay, let's quickly see the other layout manager that I talked about. And let's move on from this one. The name of the other layout manager was grid layout manager. So I'm going to delete all of these. And inside this set layout manager method, I'm going to say new grid layout manager. For the inputs of this constructor, we need two arguments. First of all, we need the context. After that, we need the number of columns. For example, I can pass two in here. This two in here is going to divide our screen horizontally in two different parts, or to be specific to different columns, and it's going to show different contacts in those two columns. But before I run my application, I'm going to change one thing in the application in the contacts list item that XML file, I'm going to change the match parent attribute of my relative layout to let's say wrap content. You can see that for this widths, we have set it to match parent. I'm going to change that to wrap content. Okay, now let's run the application. You can see that the screen has been divided into two different columns horizontally. And we can see the contacts name in two different columns. So sometimes you may want to use this grid layout manager. Okay, now let's see how we can set an on click listener for each one of these items in our recycle review. Right now, if you click on each one of these items, they are not going to do anything. But if you want to set an on click listener, we need to do that inside our contacts recycle review adapter. Let's quickly open that class. It was in our Java folder inside our project folder. Contacts recycle review adapter. If you remember, I said that this unbind view holder method is the most important method in your adapter class. And inside this method, you can set an on click listener for every UI element that you want. Also, if you remember inside this contacts list item, I've defined an ID for this whole relative layout. If you want, you can set the on click listener on this text view. But I think it's better to define the on click listener on the whole relative layout. Because as you can see, we have this padding of 10 dp and some places in our relative layout are not going to be clickable if we set the on click listener on the text view. But because I'm going to define the on click listener on this relative layout, inside my adapter class, when I've created this view holder class, after creating the text view, I need to reference the relative layout as well. So I can say private relative layout. Let's name it parent. We also need to instantiate it inside the constructor. Down in here, I can say parent is equal to item view dot find view by ID. Once again, let's say R dot ID dot parent. After defining this relative layout, now you can have access to that inside this unbind view holder method. So for example, in here, I can say holder dot parent, which is the name of this relative layout. dot let's say set on click listener. You can see that we have this option. Let's pass our interface new on click listener. And in here, I'm just going to show some toast message. Let's say toast. If you remember when we have used this make text method on our toast, we needed a context. But in here, we do not have access to any kind of context. Once again, we will talk about context later on when we talk about activities in Android. But inside this adapter class right now, we don't have any context. So we have to pass it inside the constructor. For example, I'm going to define the context as the member variable above in here. Let's say private context. Let's name it context. And after that, I'm going to receive that where this constructor, let's say context. Let's name it context. Inside the constructor, I can say this dot context is equal to context. But now that I have changed this constructor, if I switch back to main activity, I should see some red warning. When we have instantiated our adapter class, we need to pass our context. Once again, because this time we are inside this activity, I can simply pass this. So this way inside our adapter, now we have a context. And when we create our toast message, we can pass that as the context. For the text, I'm going to show the name of the contact. So I can say contacts, the array list that we had, let's say that get once again, I'm going to use this position as the index. Let's say dot get name. Also, if you have noticed, as soon as I've used this position inside this unclick method, because we are inside an interface, this final keyboard has been added to the declaration of this integer. Let's also add another text in here. Let's say selected. Let's quickly run the application. And let's see if we have correctly and set the unclick listener on our relative layout. Let's click on the first one. Margot will be selected. Social Ronan social Ronan selected. It seems like our unclick listener is working fine. Okay, I think that's a good point to stop the video in here. I did want to talk about that image URL and how to show that in our recycler view. But it seems like this video is getting a little bit long. So I'm going to talk about that in the next video. Besides that, we will also talk about using a combination of recycler view and card view. The combination of these two will generate a really beautiful look for our recycler view. Okay, see you in the next video. In the previous video, we have created a functional recycler view. By functional, I mean we have created a skeleton of our recycler view. But right now it's very simple. If you take a look at your contacts list item that XML file, you can see that every item in your recycler view is just a simple text view. In this video, we are going to work around this and we are going to see how much flexibility we have when we are working with recycler views. The first thing that I'm going to do in here is that to use a card view instead of this simple text view and its parent, which is a relative layout, we are going to show our contacts in a card view. For that, first of all, we need to add the card view dependencies into our project. In previous videos, when we wanted to use card view in our project, we have added the material design library. And from there we have used the material card view. Instead of using the material design library this time, I'm going to use the native Android card view. Let's see where we can find that card view dependencies. So if you search for card view dependencies, you will end off with a link like this. Make sure to put Android X in your search because if you search for Android, you may get some link like this. Let's quickly take a look at that. In here inside these dependencies, you can see that you are using com.android.support library. We are not using support libraries in our project right now. If you remember when we have created our project, we have added the Android X artifacts. If you want to make sure of that, you can always check your gradle file. Let's quickly do that. So in my project pane, inside this gradle script in this build dot gradle module app. In these dependencies, you can see that we are always using Android X. If for some reason you are using the support libraries, you can implement this support libraries version. But because we are using Android X, this dependency is not going to be helpful for us. So make sure to include this Android X in your search. And the first link from the official Android developers website is probably our needed link. Down in here, you can see the dependencies, you can see that this time we are going to add the dependency from Android X packages. Let's copy this line of code. And let's add it into our project. So once again, inside this build dot gradle module app file, inside these dependencies, we are going to add our dependency. Let's quickly do that in here. And let's sync our project. Now that I've added card view dependencies into my project, I can use it in my layout files. For example, inside this contacts list item dot XML file, instead of this relative layout, I'm going to use card view. You can see that it's coming from Android X packages. If you remember, in card views, we had two attributes that can be helpful in here. The first one is card elevation. This one in here, which will give some 3d shape to our card. For example, if I say 5dp, we will get an elevation of 5dp. The next one is card corner radius. This one in here, which once again, I'm going to say 5dp, I will change these numbers if it was necessary. And also inside this card view, instead of this text view, I'm going to use a relative layout. The reason for the relative layout is that because I'm going to include multiple UI elements. And I'm going to use some of the attributes like layout below center horizontal and attributes like that. And those attributes are available inside a relative layout. So for that, first of all, in here, I'm going to create a relative layout for the width and height, let's say match parent. And I think that's enough for our relative layout. Inside that first of all, I'm going to move this text view. First of all, let's center this text view horizontally. Let's say center horizontal, and let's pass through. Besides that, let's change the style of this text. Let's say text style. And let's change it to both. After that, I'm going to create another text view. And I'm going to show the contacts email. Let's add that after this text view. Let's change the contact name to contact email. And let's change the ID to txt email. Let's also move this to below our contact name. Layout below, let's say txt name. Let's also change the style in here. Let's say italic. I think it's better to add some margin top margin top. Let's say seven DP. Also, I'm going to delete the center horizontal attributes. Okay, after these two texts, I'm going to show the contacts image. For that, I'm going to create an image view. Let's say image view. For the width and height of this image view, because I want to have a consistent image view, I'm going to put the numbers manually, because my images are coming from the internet. And I don't know anything about their size. For example, in here, I'm going to say 150 DP. I think that would be fine. For the height as well. Once again, 150 DP. Let's also give an ID to this image view. Let's just say image. I'm going to move these to below my contacts email. Let's say layout below. And let's pass txt email. Let's add a margin top. I think 10 DP would be fine. I'm also going to center this image view horizontally. So let's say center horizontal. And let's pass through. Let's also add a placeholder. I'm going to say source. And let's address one of our images in our package. I think this IC launcher background would be fine. Okay, I think that's enough for our card view. I don't think we need anything else. Let's just have a quick look of what our card view looks like. I think I need to increase this corner radius. For example, let's say 10 in here. That should be better. Besides that, let's increase this card elevation. You can play around with these numbers until you are satisfied. I'm almost done with this contact list item file. I'm just going to reformat my code so that when I publish this code, you and I have the same base code. For that, I'm going to go to this code tab in here. And down in here, I'm going to select this reformat code. You can see that the code has been rearranged. Okay, now that I have changed this layout file, we need to also apply the changes inside our recycler view adapter file as well. So down in here when we have created our view holder class, we need to address all of the new elements in our contacts list item dot XML file. First of all, we have deleted this relative layout and we have replaced that with a card view. So in here, instead of using a relative layout, I'm going to say card view. And let's also add our email text, I'm going to add it in the same line with this txt name. Let's say txt email. And let's initialize it down in here inside this constructor. So let's say txt email is equal to item view dot find view by ID or dot ID dot txt email. We also need to add some codes inside this unbind view holder method. For example, we are going to show the contacts email, we need to do that in here. Let's say holder dot txt email dot set text. Let's pass our contacts dot get which for the index I'm going to pass position. Let's say dot get email. Before showing the image view, I'm going to run the application and I'm going to see that if everything is working fine. So let's run the application. You can instantly see that with these few changes how much we have improved our layout. But right now this layout needs some modification. For example, we need to add some margin between these card views. And also we need to add a margin top for this txt name. Let's quickly apply that. So if I switch back to my contact list item dot XML file for this parent card view, I'm going to add a margin, that same margin top, or instead of margin top, I'm just going to say margin, I think 10dp would be fine. Besides that, let's also add a margin for this text view. Let's say margin top and let's pass 70dp. Let's also add a margin start for this email. So in here for this txt email, I'm going to say margin start this one in here and I'm going to say five dp. Let's run the application once again. You can see that it's much better now. You can also see the two attributes that we have added for our card views much better in here. First of all, we have added this corner radius. You can see that in here and also this 3d shape with the shadow behind our card view is for that card elevation attribute. Besides that, the reason that we are seeing two columns in here is because of that grid layout manager that we have passed to our recycler view. If you want to have only one column, you can change that. For example, inside our main activity, down in here instead of a grid layout manager, we can pass a linear layout manager. So in here, let's say new linear layout manager. And let's pass our context. Before I run this application, I'm going to make sure that I've centered my recycler view. Let's switch to our main activity layout file. And let's center our recycler view. Let's say center horizontal. And let's pass through. Also, I'm going to change the widths attribute in here to wrap content. Let's run the application once again. Right now, you can see that we have only three contacts in our screen, but we can scroll our recycler view. Let's quickly do that. You can see that if our item do not fit on the screen, our recycler view is a scrollable. Besides that, let's also check the on click listener. Let's click on this card view. And you can see that social run on selected. It seems to be perfect. Okay, now let's work on this image view. Let's see how we can show our images. For that we have multiple options. The easiest one is to use an external library called glide. Let's add that into our project. And we will talk about it. So if you search for glide dependency, the first link from this GitHub page is the link to that external library. Let's see what does it look like. Down in here, you should see the dependencies. First of all, we need to add these two into our repositories. Let's see if we have them in our gradle file. Let's open our project pane in the gradle scripts inside this build dot gradle project one. In these repositories, we need to add the main event repositories. Let's quickly add them. I'm going to copy this one in here. And I'm going to add it inside these repositories for all projects. Besides that, we need to add these two dependencies into our project. Inside this build dot gradle, this time module amp, we need to add the dependencies. Let's sync our project. And while it's sinking, let's also talk about this glide. So glide is an image loader library in which has developed by Google. So you can safely use it in your projects. Glide has a lot of functionalities in which one of them is to load images from the internet. Later on in the course, we will see other functionalities as well. But if you want to know more about glide, they have a documentation in here, let's click on this view glides documentation. You can read this page if you want, but we will talk about glide more later on in the course. Okay, let's switch back to our project. And it seems like we have added the glide library successfully. Let's close these two gradle files. Also, let's close this activity main dot XML file. And let's go to our contacts recycler be adapter dot Java file. So inside this on bind view holder method, I'm going to show the images of different contacts. For that, I'm going to use the glide inside this method. Let's see how we can use glide. In order to show images with glide library, you can say something like this, you can say glide with capital G. After that, you need to pass your context, you can do that by saying dot with for the context in here, I'm going to pass my context. As a reminder, we have get the context via the constructor of this class. In the previous video, I'm talking about this one in here. Now that we have our context, we can use it with this with method. After that, I'm going to say that this image is going to be a bitmap. So let's say dot as bitmap. After that, we need to pass the source of our image. In this case, we are going to pass the image URL for our contact image. Let's say dot load. And let's pass our contacts image URL for that. I'm going to say contacts dot get. Once again, I'm going to use the position as the index, let's say dot get image URL. After that, we need to pass the image view that we want to show our image inside that. I'm going to say that into. And I'm going to address my image view, which I can say holder dot image. But for that, first of all, we need to add this image inside this viewholder class, we never did that. So inside this viewholder class, first of all, I'm going to say private image view. Let's call it image. And let's also instantiate it inside the constructor. Let's say image is equal to item view dot find view by ID or dot ID dot image. This is the simplest way of using glide. First of all, we need to pass our context. After that, we need to say that it's going to be a bitmap file. After that, we need to pass the source of our image with this dot load method. And after that, we need to specify the image view that we are going to show our image inside that. This is going to work fine. But before I run my application, I need to do one more thing. We are going to load different images from the internet. For that, we need to add a permission into our manifest file for accessing the internet. So far, we haven't talked about requesting a permission, let's quickly see how we can do that. So in our project pane, inside the app folder, inside this manifest folder, if we open this Android manifest dot XML file, we can add our permission in here above the application tag. In here, I can open a tag. And the tag is going to be users permission, this one in here. And we need to specify the kind of permission. Let's search for internet permission. You can see this Android that permission that internet. Let's close our tag. There are much more concepts regarding these permissions, we will talk about them later on in the course. For some permissions, you need to create a UI a logic in order to ask the user to grant that permission to your application. But this internet permission is a safe permission. And if you add it to your manifest file, the Android system is going to grant it automatically. That's all we need to do in order to request for an internet permission later on, we will talk more about permissions. Let's just run our application and let's see if we can successfully show different images. You can see that we are seeing different images in here. But there was a problem when I ran this application after adding the permission for the first time. The first time I wasn't able to see the images and that's because we have changed our manifest file. Whenever you change your manifest file, you need to uninstall the application and install it once again. So if you are not seeing different images, make sure to uninstall the application and install it once again. After that, you should see different images. Let's also check the others. You can see that the images are loading from the internet after a few seconds. You can see that our recycler view, our card views and also the glide library is working perfect. The combination of these three will create a really beautiful layout for when we want to show a list of different items. And probably by now you can see the flexibility and all of the functionalities of recycler view. You can see that we can modify our layout files, our list item layout files, however we want. Okay, I think that's enough for this video. Just to see our recycler view better, I'm going to change the linear layout manager once again to a grid layout manager. And after that, we will finish our video. So let's change it back to grid layout manager and let's run our application once again. You can see that our recycler view seems perfect. Okay, I think that's enough for this video. In the next video, we are going to see how we can use different fonts for our text views. For example, an external font that we don't have in Android Studio. Okay, see you in the next video. In this video, we are going to talk about different fonts, how we can apply different fonts to our text view, whether that font exists in our project or whether we are going to add it externally. I believe this will be a short video. First of all, let's see how we can add an external font into our project. Before that, I'm going to go to this layout file and give an ID to this text view. Let's just name it txt hello. In order to add an external font in your resources folder, you need to create a new directory. You can right click on your resource folder. By selecting new Android resource directory, you can create that directory. We have done this when we have created a menu resource file. In here, you just need to define the type of your resource, you can search for font in here. And that's all you need to do. Now you can see that you have this font folder. And you can copy your external fonts into this folder. For example, I have prepared this font. But before adding this font into my project, I need to do some modifications. For example, I need to change the name of this font. In order to add this font into your project, you need to follow some rules. For example, you need to change all of the upper cases into lower cases. And also you shouldn't use hyphens. Instead of that, you can use underlines. So in here, I'm going to change the name a little bit. Let's change this upper A to lower A. After you have changed the name, you can simply copy your font. And inside your font folder, you can paste it. The name is fine. Let's just press okay. Now in your font folder, you have this Amsterdam dot TTF. If your font has some preview, you can see that by double clicking on your font. Okay, now that we have added this font, let's see how we can use it on our text view. Let's switch to our text view mode. And on this text view, we have one attribute called font family. This one in here. And now we can address our font, which is add font slash Amsterdam. Let's switch to split view. And let's see if we can see our font in the preview. You can see that right now the font hasn't been rendered. But I believe this will be changed when we run our application. Let's run the application. And let's see if we can successfully change the font of our text view. You can see that this beautiful font has been applied on our text view. Besides using your own funds in your project, you can also use some funds called Google funds. Let's quickly see how we can use them. So for that, I'm going to switch to design view and search for font family attributes in here. But before that, I need to click on this text view. Let's search for font family. You can see that we have this attribute. And beside our font, which is right now at font Amsterdam, we have this drop down icon. If we click on that, we can see that in Android, we have some fonts that we can use. But beside all of this, we have this more funds option. And when we click on that, you can see that we have a list of a lot of more funds. Also, you can see the source in here, it says Google funds. These Google funds are free and you can safely use them in your applications. You just need to add a license in your application somewhere. Okay, let's see what do we have in these Google funds. For example, we have this calligraphy or something like that that we can use. In here, you can see that we have two options create downloadable font and add font to your project. The first option means that you don't want to add the font to your project and you want to use the online font every time that a user uses your application. If you are creating an offline application, this option in here might not be that useful. Instead of that, I'm going to use the second option, which will add the font to my project. But it will increase the size of the final APK file. Also down in here, you can see this preview for some funds, you have a more than one preview, and you can select between them. But for this font, we have only this regular. Also down in here, you can see the license that you need to show somewhere in your application. For this simple application, I'm not going to do that because this is not going to be a commercial application. Okay, let's add this font into our project by pressing okay, you can see that this calligraphy font has been added into my font folder. I believe this will have a preview. So if I click on that, you can see a preview of your font. Now, if I run my application, I should see this font instead of this Amsterdam font. You can see that the font has been applied successfully. For some funds, you may have different styles. For example, regular or normal, italic, bold and both italic. Let's quickly see a font that has those styles. And let's see how we can apply those styles on our text views. So once again, I'm going to click on this drop down menu. And once again, I'm going to click on this more funds. The font that I'm going to use in here is called lobster two. If you click on that, you can see that in this preview pane, you have four options. I'm going to add them one by one into my project. For the first one, I'm going to name it lobster two underline regular. And also I'm going to add it to my project, I'm not going to make a downloadable font. Let's press okay. And let's do the same for the other three styles. You can see that now we have four different lobster two funds. If we want to apply them on our text views, we can do the same as we did for the other fonts, which we had only one font. For example, inside our text view, for this font family in here, we can pass the font manually by specifying the name of our font, or we can pass this styling job to the Android. For example, we can add a text style in here. And we can specify the style which can be italic bold or normal. Right now, if I select text style as bold, and if I change this lobster to bold italic to just lobster to regular, let's quickly do that. If I run my application, I'm going to get a bolder style for this specific font. Let's quickly run that. You can see that we have this bold font, but this in here is not accurate because we have added a style manually. This actually in here is using our lobster to regular font. And if we want to use specifically this lobster to bold font, we can create a font family for that. Let's quickly see how we can create a font family. So in my font resource folder, I can right click and by pressing new font resource file, we can create a new font family. For the file name, I'm going to put the font name, which in this case is lobster to let's create that. Inside this font family, I'm going to define for funds. We need three attributes in here. First of all, we are going to need the font itself. For the first one, I'm going to pass the lobster to regular font. After that, I'm going to pass a style for this font, let's say font style. You can see that in here we have two styles, italic and normal. In here, I'm going to pass normal. But if you want to pass a bolder style, you need to pass that as a font weight. Let's quickly see that. We can see that we have this font weight attribute in which we can pass a number. Basically, for normal fonts, this weight should be 400. I will show a link for where you can find the exact font weight that you need. But for now, let's just pass 400. And let's finish creating our font. After that, I'm going to create three more font elements. And I'm going to pass the other three fonts. Let's say font. Once again, we need to address our font. This time, let's say lobster to italic. For this style, I'm going to say italic this time. And once again, because this is not a bold font, we are going to pass 400 as the font weight. Let's quickly add two more fonts for the bold styles. You can see that for the normal bold font, I've passed normal as the font style. But for the italic one, I've passed italic. The only difference between a bold and a regular size font is in this weight. For the regular, we have passed 400. But for the bold ones, we have passed 700. Before we go further, let's quickly see where we can find the proper font weight. So if you search for font weight Android developer, you can see this font weight from the developer dot Android dot com. Let's quickly see that. And in here inside this companion properties, you can see different weights for different fonts. For example, we have passed 400 for the regular funds, which is the correct number. For the bold ones, we also passed 700. I believe in Android, you won't see much difference if you pass, for example, 500. When the funds are being rendered, the only difference is between this 400 and 700. So if you want, you can check this webpage. Okay, let's switch back to Android Studio. Now that we have created this font family, we can pass it in our activity main dot XML file. But before that, you can see that we have a lot of warnings in here. If we hover over one of them, it says that these attributes are only usable in API level 26 and higher. So if your application is running on API level lower than that, these font family won't be applied. I've seen that some people use app namespace instead of this Android. For example, you can say app in here. Of course, you need to add the namespace by pressing Alt plus enter, you can see that this new namespace has been added. I'm not going to talk about namespace in here, but basically it's like importing in XML file. In other programming languages, you also have namespaces. Basically, it will define that where this app attribute is coming from. So some people are using this app namespace. They say that if you use this app namespace instead of Android, the font family will be applied in lower API levels as well. But honestly, I didn't see that difference. So I'm going to change this one back to Android. And in my activity main dot XML file, I'm going to pass the font family. So in here, instead of passing lobster to regular, I'm going to pass lobster to this XML file that we just created. And now this way, we are passing the styling job to the Android system. So even though we are using this lobster to because we have set a style to bold in here, at the end, our font is going to be rendered to this lobster to bold. Let's run our application. And let's see if we can see a bold font. You can see that we are seeing the bold font. Once again, the difference in here is that this time we are using exactly this lobster to bold. But when we have passed lobster to regular, and we have set the style to bold, only the Android Studio increase the size. Sometimes there might be some differences between different font styles when the designer created the font. So this way of creating a font family is much more accurate. Okay, just before finishing this video, I'm going to show you how you can apply different fonts in Java file. For example, inside this layout file in the design view, I'm going to add a button. And by clicking on this button, I'm going to change the font of this text view. Let's change the idea of this button first of all to let's say btn change font. And also let's add some constraints. And let's change the text. I'm just going to say change in our main activity. First of all, let's initialize these two items. After that, let's set an on click listener for our button. Let's say that set on click listener, new on click listener. Before this on click listener, I'm going to create a typeface. And after that, I'm going to change the typeface of this text view inside this on click method. So above in here, let's say typeface, you can see that it's coming from Android graphics package. Let's name it typeface is equal to in here, we are going to get a reference to our font in our resources folder. If I try to get resources in here, let's quickly see that get resources that get font. And if I pass my font address, for example, if I say r dot font dot, let's say Amsterdam, you can see that we are getting a red warning in here. And the warning says that this method is only available in API level 26 and higher. You can overcome this problem by using resource compact instead of this get resources method. Let's quickly see that. So in here, I can say resource compact dot get font. First of all, we need a context, which I'm going to pass this. After that, we need to address our font, let's say r dot font dot Amsterdam. So instead of get resources, you can use this resource compact, which is a good option for backward compatibility. After you have defined your typeface inside the on click method, you can say txt hello dot set typeface, and you can pass your typeface. As simple as that, you can change the font of your text view. Let's run the application and let's see if everything is working fine. Right now, the font is lobster to if we click on this button, you can see that the font is changing to Amsterdam. It seems to be perfect. Okay, I think that's enough for this video. And also for that matter for this section of the course, there are a lot more concepts and tools that you have when you're designing your layout files, for example, you have navigation drivers, you have bottom navigation views, you have animations that you can apply in your application. But I'm not going to talk about them in this section of the course, because there are a lot more concepts that we don't know anything about them yet. Later on in the course, we will see a lot more tools for designing our layout files. Okay, in the next video, we are going to have a quick challenge for this section of the course so that we make sure we have learned everything that we have talked so far. See you in the next video. As I said at the end of the previous video, in this video, we are going to have a quick challenge. The purpose of this challenge is to make sure that we have learned everything that we have talked so far. And here is our challenge, I want you to create this simple layout file, you can think of this layout file as a simple registration form in which we are receiving the user's name, email, password, gender, and also country. Besides that, we have this image we're in here plus this button, which normally in a normal application, this button should navigate us to the user's gallery or maybe the camera in order to take a photo. But because we don't know anything about that yet. This button and this image view are just for showing purposes. These are not going to do anything. Just if you want, you can show a toast message after clicking on this big image button. Besides that, we have this license agreement text, which down below that you can see this checkbox. If everything works fine, when we click on the register, we are going to show a snack bar indicating that the user has registered successfully. But if, for example, the user leaves one of these edit texts empty, you are going to show a warning. Besides that, we are going to make sure that the user agrees to our license agreement. Okay, this is our challenge. As you can see, this is a simple layout file. I'm sure that you can do it by yourself. But as you can see, we are going to practice a lot of things that we have learned in this section of the course, we are going to work with a lot of UI elements. Besides that, as you can see, we are implementing material teaming. Also, we are going to show a snack bars. And beside that, we are going to see how we can initialize and work with our UI elements in the Java file. Feel free to use any kind of layout file that you want in order to design this simple layout file in here, I have used a constraint layout. But if you want, you can use linear layout or relative layout. Okay, pause the video in here and go solve the challenge. Whenever you are done, come back to see my solution as well. Okay, I hope you solved the challenge. Let's quickly see my solution as well. I'm going to start by creating a new project. For the name of this project, I'm going to say UI challenge. I'm going to save with API level 19. In this simple application, it shouldn't matter. Okay, let's start working on our layout file. But before that, I'm going to close all of my extra files and pains. As I said, I'm going to work with constraint layout. But if you want, you can work with linear layout or relative layout. Before everything, let's remove this text view. And let's drag all of our items. First of all, we need an image view for the image profile. For the sample data, I'm going to select one of the avatars. We also need a button. Besides that, we are going to need a material design components, we will add that in a minute. But before that, let's quickly drag all of our UI elements. We need four edit texts in here. The first two are going to be plain text. And the next ones are going to be password. The first two are for the name and email. Let's quickly add two passwords in here. The difference between this password and this plain text edit text is that when you type something inside the password edit text, it won't show the text itself. But you will see some dots. Also beside that, we need a text view for our gender text. After that, we need a radio group. Let's quickly add that. Inside this radio group, we need four radio buttons. Also, I'm not sure that if you have seen this way of dragging radio buttons in your radio group in the design view. Previously, we have seen how to add radio buttons inside a radio group in the text view. But here is how you can do that in the design view. Basically, you can use this component to refer example, I can drag my radio buttons to inside this radio group. Let's add two more. Let's also quickly change the orientation of this radio group. Let's search for the orientation in the attributes. This one in here, I'm going to change it to horizontal. Besides that, we need a text view for the countries. And also we need a spinner in here for selecting one of the countries. Let's search for a spinner. Let's quickly change the width of this spinner to wrap content instead of match parent. This is not match parent in here. It's just some DPs, we are going to change that to wrap content. Also, I think it's better to put it above in here, beside our countries text. And after everything, if you remember, we had a button, let's quickly add that. This is going to be our button register. Besides that, we need a text view in here for our license agreement. And also we needed a checkbox. Let's search for checkbox. And let's change the checked value of this checkbox to true. Let's search for checked. Or you can see that down in here. Also, I'm going to change the checked value of this radio button to checked as well. Also, let's quickly change the ID of our UI elements so that we can use them in our Java file. I'm going to fast forward the process of giving them an ID, basically, you can select your UI element, and you can change the attribute from this top right pane in here. Just to have a quick review, let's quickly see the idea of each one of them, because later on, we are going to use them in our Java file. This one is image profile. This one is btn pic image, edit text name, edit text email, edit text password, edit text pass, repeat txt gender. This one in here is rg gender for our radio group. The three radio buttons are named rb male, rb female, and rb other. This text view is called txt country. The spinner is called a spinner country. And this button is btn register. This text view in here is called txt agreement. And this checkbox is called agreement check. We are also going to need four more text views. If you remember, I said that when we click on this register button, we are going to make sure that we have received some input from the user. And if for some reason the user don't enter anything on our edit text, we are going to show some warning. And we are going to use text views for those warnings. So let's quickly add four more text views. I'm going to add the warning for each one of edit text above the edit text. Let's quickly give some ID to this. For example, for the first one, I'm going to say txt var name. You can guess the rest of them. This one is txt var email, this one txt var pass. And the last one is txt var pass repeat. Okay, now that we have the ID for all of these UI elements, let's quickly change their initial values. For example, for this text view, I'm not going to change anything. But for this edit text, I'm going to delete the text, and I'm going to add a hint. Let's search for the hint. Let's just say name. Sometimes like this, you can see some options which can be annoying by pressing the escape key on your keyboard, you can get rid of that suggestion. Let's do the same thing for these three remaining edit text. For this text view, I'm going to change its value to let's say gender. For the radio buttons, let's change the first one to male, the next one to female and the other one I'm going to name other. This text view in here, let's change it to countries or country. Let's change this button's text to pick image. And this one to register. Also this checkbox to I agree. Besides that, we need to change the value of this text view, but we are going to do that later on when we created our constraints. I'm not going to do anything about this yet. Also, I'm going to change the color of these four warning text views. Let's quickly do that. Let's search for color. And let's change it to some red color. I think this one would be fine. Now let's start constraining our UI elements. For example, for this image view, I'm going to constrain it to the left of my screen and also to the top of my screen. But of course, I need some margin. I will add that in a minute. Besides that the right of this image view to the left of my button. And also the right of this button to the right of my screen. Besides that, I'm going to constrain this button to the bottom of my image view. Similar thing for the top of my image view. Also, let's add some margin for this image view. For example, margin top, let's say 32, I believe is fine. And let's move it to left. But as you can see, when I move this image view to left, and this button do not move, I'm going to delete this right constraint. And I'm going to drag it from the left of this button to the right of my image view. Now let's constrain this image view to the right of our screen. And now we can move it. It seems better now for these text views. First of all, I'm going to add a horizontal guideline. So let's right click on our layout. And let's go to these helpers. And let's add horizontal guideline. Let's move this guideline to somewhere about here. I think it's fine. Besides that we need a vertical guideline. Let's quickly add that helpers at vertical guideline. And let's move it a little bit. Now let's constrain our edit texts. For example, this one to our guideline, I'm going to constrain this text view to this guideline as well. Also, I'm going to add a constraint from the top of this edit text to the bottom of this text view. But as you can see, these are too close to each other. What you can do is that by pressing down the control key, you can select both of them. And by right clicking, you can use this right click menu, you can go to this constraint, let's say edit text name, let's say top to the bottom of our txt warning name, you can see that now we have a constraint. Besides that, I'm going to add a constraint from the top of this text view to our horizontal guideline. So once again, let's select both of them. And let's right click constrain the txt warning name top to bottom of our guideline. I think I'm going to remove the margin in here, you can see that we have an 18 margin. Let's decrease that to zero, I believe is fine. Let's do the same thing for the rest of edit text and text views. For these three remaining text views, I'm going to add a margin top to the top edit text, but I'm also going to add a margin. Let's right click constraint txt warning email top to the bottom of our edit text name. Let's see what is the margin in here 15, I think I'm going to save it 16. Okay, let's do the same thing for the remaining two edit text and text views. You can see that everything looks better now. Also, if for any reason your computer is slow, you can always go to this icon in here, and you can disable this live rendering or alternatively, you can work with the blueprint view which you can show from this blueprint option in here. Let's quickly see that you can work with this one as well. But like before, I'm going to stay with the design view. Okay, let's add a constraint for this gender text. First of all, I'm going to constraint it to the top of this edit text constraint txt gender top to let's say bottom of our edit text. Let's also add a margin. I think a margin 24 would be fine. It seems too much. Let's say 16. Let's also add a margin to the left of our screen. Let's add a margin in here as well. For the radio group, I'm going to select the radio group from this component tree for the left constraint. I'm going to add it to this guideline. Also, I'm going to add a constraint from the top of this radio group to the bottom of this gender text view. Once again, I'm going to use the right click menu. Let's say constraint. It seems like I didn't select the radio group. We can always use this component three if you want. Let's select both of them. Let's right click constraint. Let's say radio group gender top to bottom of our txt gender. That seems to be better. Let's also add a margin. I think 16 would be fine for the country text. I'm going to do the same thing. For the left margin, let's say 16. Let's constraint it to our radio group constraint txt country top to the bottom of our radio group for the margin, let's say 16. Once again, for the spinner, I'm going to constraint it to the right of my country text view and also its bottom and top to the bottom and top of this country takes us back. But of course, we need a margin left. Let's quickly add that. For this register button, I'm going to constraint it to the three edges of my screen. But I need a margin button. Let's add 32. For example, I think that's fine. For this text view, I'm going to add another guideline in here. Let's quickly add that helpers at vertical guideline. I'm going to move this guideline. Let's move it to somewhere about here. And let's constraint our text view to this one in here. For the top, I'm going to constraint it to the vertical guideline. Let's also constrain this checkbox. I'm also going to constrain the top of this checkbox to the bottom of our text view. Let's add another guideline in here. This one is going to be a horizontal guideline. And let's move it down below this edit text. Now I'm going to add a constraint from the bottom of this checkbox to the to this horizontal guideline. It seems like we don't have a proper constraint in here for that. I'm going to delete this top constraint. We can delete a constraint by selecting the constraint and pressing down the delete key. Let's also add a constraint from the bottom of this text view to the bottom horizontal guideline. Also, I'm going to move it a little bit above. That seems better. Now let's also change the text of this text view and also let's change the visibility of this for warning text to gone. First of all, let's add the text for this text view. But you can see that as soon as I type the text in here, the text of our text view somehow occupies other layout files. And also it doesn't fit on the screen. If you want to fix that, you can click on these two arrow in here. And you can change the constraint to a match constraint. But we also need a margin. Let's quickly add eight in here. Also for the right. Okay, that seems better. Also, I think it's better to move this checkbox to above a little bit. Let's click on that. And let's move it above. Okay, that seems better. Let's quickly change the visibility of this for warning text views as well. Let's search for visibility. And let's change it to gone. Similarly for the next three text views. But now that I've done that, you can see that we have two small margins, we can increase that. For example, let's say 18 here. Similarly for the next two edit text, sorry for the repetition. Okay, that's about the size of our layout file. We also need to add some entry for our spinner. Let's quickly add them in our strings values in our resources in values folder inside the strings. I'm going to add an array string. Let's say array. Let's name it countries. And let's add our items. Now in our activity main dot XML file, we can pass this as the entries of our spinner. Let's search for entries. And let's address our countries array. Okay, that seems better. Besides that for this image view, we also need a source. Let's search for sourcing here. For some reason, we can't see sourcing here, let's wish to text view or this split view. And let's add it in here. Let's say source. And let's pass this mid map file that we have in our project. Before testing the application, let's quickly add the material design team. For that, I'm going to go to material.io. Let's go to this developed app. We have seen all of this before in this Android in the documentation getting started. Down in here, you can see the dependency. Let's quickly add that in our project, gradle script, build dot gradle module up down in here inside the dependencies. Let's add that we also need to add a version in here, which as you can see in the warning, the latest version is 1.1.0. Let's sync our project. And let's go to our styles and change the team of our application. I'm going to delete this team in here. And I'm going to use team dot material components dot light this one, we have used this previously in previous videos. Let's switch back to our activity main file. You can see that the style of our buttons has changed. Let's quickly test everything. I'm going to run the application on pixel three API 29. It seems like we have done a relatively good job. We just need to increase the size of this image view. For that, I'm going to change the width and height of this image view. I'm going to add them manually. Let's say 130 dp. I think that would be fine. Let's run the application once again. If you want, you can also decrease the size of this text view as well. Yes, that seems to be better. Your design might be different than mine. It's okay. It's probably better than me. I'm not a designer. But we just wanted to practice everything that we have learned. Okay, I think that's enough for this video. In the next video, we are going to switch to our Java file. And we are going to work on the logic of our application. See you in the next video. In the previous video, we have created this layout file, which isn't that bad. In this video, we are going to work on the Java file and the logic for this application. So for that, let's switch to our main activity.java file, and let's close our layout file. First of all, in here, I'm going to initialize all of my UI elements. Before that, let's quickly add a log. I believe it will be useful. Let's say private edit text, we had four edit texts. I'm going to fast forward the process of defining and initializing these UI elements, you can see that it's very boring. I'm also going to define a constraint layout element in here. Let's say private constraint layout. I'm going to name it parent. I believe later on, we will use this constraint layout to show a snack bar. I also need to give an ID to my constraint layout. So for that, let's switch to our activity main dot XML file in our split view. In the parent constraint layout, I'm going to give it an ID. Let's say ID, I'm going to say parent. Okay, now let's initialize all of these UI elements. I'm going to do that inside another method. Let's name that method init views. First of all, let's create that method down in here private void init views. First of all, let's add a log. Let's say you started, let's minimize this project vein and let's initialize. Once again, I'm going to fast forward the process of initializing these UI elements. I think I have a typo in here when I have set an ID for this ptn register. Let's quickly fix that in our layout file. If I click on this register button in here, you can see my typo. Sorry for that. I also need to change it in here. Okay, now that we have initialized all of our views, I'm going to set an on click listener first of all for my ptn peak image. I'm talking about this one in here. So after this method, I'm going to say ptn peak image dot set on click listener, neo on click listener. Let's just show a toast message. We haven't seen how to pick an image, for example, from a gallery, or for that matter, to take a picture using the devices camera. For that, we are just going to show this toast message. After that, let's define an on click listener for our ptn finish or ptn register. I believe I named it set on click listener neo on click listener. I'm going to do the job inside another method. Let's say init register. Let's create that method down in here. Let's say private void init register. Once again, let's add a log. Let's say start in here. First of all, I'm going to check that if the user has entered all of the data for that, I'm going to say if I'm going to create another method, I will create that in a minute. But let's say if validate data, if that's the case, we are going to continue. Let's quickly create this method down in here. And let's see what we are going to do inside this method. Private the return type is going to be a Boolean. Let's say private Boolean validate data. Once again, let's add a log. Let's say if edit text name dot get text dot to a string, if it's equal to an empty string. First of all, we are going to show the warning text. So let's say txt warning txt warning name dot set visibility. Let's pass visible. I believe we have seen this previously in the course. After that, we are going to return false. It means that we didn't validate the data. So we shouldn't continue our code in this method inside this if statement. Let's create three more if statement for the other three edit texts. If edit text email dot get text dot to string is equal to an empty string txt warning email dot set visibility. Once again, visible. Also, we need to return false in here as well. Also, in each one of these cases before returning false, we are going to change the text of our txt warning. Because if you remember, in the layout file, we didn't change the text of that warning text view. So I can say txt warning name, for example, dot set text. Let's just say enter your name. Similarly, for the other three cases. And after all of these if statements after all of these cases, if we reach to this point, we are going to return true. It means that the user has entered all of the data. So inside this validate data method, we are validating that the user filled all of the blanks. After that, inside this init register method inside this if statement, we are going to check that if the user agrees to our license agreement. So let's say if agreement check dot is checked, this option in here, if that's the case, we are going to continue. But in the else case, we are just going to show a toast message. Let's say you need to agree to the license agreement. But if the user reaches to this point, where the user enters all of the data and also agree to the license agreement, we are going to show a snack bar. Let's do that in another method. Let's say show a snack bar. Let's create that method down in here. Private void, show a snack bar. Once again, add a log. And down in here inside this method, first of all, we need to change the visibility of all of our warning texts, because those warnings are no longer valid. So let's say txd warning name dot set visibility. Let's say gone this time. Let's do the same thing for the other three remaining warning texts. After that, we need to show our snack bar. If you remember, we can do something like this, we can say a snack bar dot make. First of all, we need to pass our constraint layout, which is our parent in this case. After that, we need to text in here right now, I'm going to show a dummy text. For example, I'm going to say user registered. But later on, I will change this text. For example, I will show the details of the newly registered user. For now, let's say user registered. After that, we need a constant for the length of our snack bar. I'm going to say snack bar dot length indefinite. Let's also define an action button for our snack bar. I'm going to say dot set action. For the text, I'm just going to say dismiss. Let's also create an on click listener. Let's say Neo on click listener. For the time being, I'm not going to do inside this on click method later on, we will clear our edit texts. Let's finish creating our snack bar. But before that, we just need to show it. Let's say dot show. Let's run the application. And let's see if we have right everything correctly. First of all, let's click on this big image button. We should see a toast message. You can see that yet to be talked about. Let's enter some data and let's register a new user. Let's say may sound. Let's add an email. Let's enter a password. Let's retype our password. We also need to check that if these two are the same. I forgot to do that. I will do that after the testing of this phase of the application before registering the user. I'm going to uncheck this license agreement checkbox. Let's say register, you can see that you need to agree to the license agreement. Let's check it once again. And let's register this time we should see the snack bar user register. It seems like our application is working fine. If we press dismiss, the snack bar will be dismissed. Also, let's delete this email in here. And let's see if we get the warning text if we click on this register button, we can see that enter your email, we are successfully validating our data. If we enter an email in here, for example, may some at gmail.com. And if we click on the register button, we should see that the email warning text disappears. Okay, now I'm going to change the application. First of all, I'm going to check that these two are the same. After that, I'm also going to empty all of these four edit texts. When I click on this dismiss button, so that we can add a new user. Also, I'm going to change the text of this snack bar to the details of our newly registered user. Let's quickly do that. First of all, inside this validate data method, I'm going to add another if case, let's say if edit text password, this one dot get text to string. If that's equal to our edit text, password repeat dot get text to string. If that's the case, or let's change our logic, let's say if that's not the case. First of all, we are going to change the visibility of this txt warning password repeat. And after that, we are going to return false. Let's say txt warning password repeat dot set visibility. Let's say visible. After that, I'm going to change the text. I'm going to say txt warning repeat dot set text. Let's say password doesn't match. And after that, I'm going to return false. Okay, now that we have validated this data successfully. Let's go to this on click method. And in here, let's clear our edit texts. I'm going to say edit text email or edit text name dot set text. Let's just pass an empty string. Similarly, for the other three edit text. Next thing that I'm going to do is that I'm going to change the text of this snack bar. First of all, I'm going to create that text above in here inside this show a snack bar method. Before everything, I'm going to get the users data. For example, let's say a string name is equal to edit text name dot get text dot to string. Similarly, for the email, I'm going to say a string email is equal to edit text email dot get text dot to string. I'm also going to get the users gender and also country. Let's say a string country is equal to countries spinner dot get selected item dot to string for getting the users gender, I'm going to create a switch statement. Before that, I'm going to create a string. Let's say string gender is equal to an empty string. After that, let's create a switch statement on our radio group or radio group gender dot get checked radio button ID. Let's say in case it's R dot ID dot radio button mail. We are going to change the value of this gender string. Let's say gender is equal to mail. Sorry about that. Let's also add a breaking here. Another case R dot ID dot female. Let's say gender is equal to female. This default case should never happen. But just for security purposes, if something goes wrong, I'm assigning unknown to the gender string. So after this switch statement, we have all of the data about our user. Now we can create the text that we want to show inside this snack bar. Let's say a string, a snack text is equal to and let's create our text. First of all, I'm going to say name plus the name that we created, or we got from the edit text name. After that, I'm going to add a backslash and in order to go to the next line, let's say email plus the email. Once again, a backslash and let's also show the gender and country. Let's say gender plus the gender. Once again, backslash and and also let's show the country. Now that we have created this text, we can show it in our snack bar. So this time instead of this text, I'm going to say a snack text. Let's run the application once again, and let's see if we have fixed our application successfully. Let's test the different cases. First of all, let's check that if we see the warning, if we enter different passwords in these two edit texts. In the password field, I'm going to enter 123456. But in the reinter password edit text, I'm going to say 12345. If we click on this register button, we should see the warning text passport doesn't match. Okay, let's add six in here. Now they do match. Let's change the country to, for example, Switzerland. And also let's change the gender in here to female. And let's see if we can register a new user. In here, you can see that we are seeing the snack text that we have created, but we are not seeing all of it. We are seeing only the first two line. If you want to change the maximum line attribute of your snack bar, you can do that. First of all, you need to get the instance of your snack bar. After that, you need to get the text view of your snack bar. And after that, you can change the max line attribute on your text view. This way, you can override the maximum line attribute of the text view of your snack bar. But that seems like a lot of work. And we are not going to do that in here. We will do that later on in the course in other places when we use a snack bar. But in here, if you want to make sure that you have created your snack text successfully, you can simply log it. For example, in here, I'm going to add a log, let's say log D, let's say a snack bar text. And let's pass our snack text. But before I run my application and test this, I'm going to click on this dismiss button. If you remember, we write the logic so that we clear all of our edit texts. Let's click that and you can see we are now ready to register a new user. Let's run the application once again. And let's test this snack text. For that, I'm going to open the log cat. Let's enter some data in here. And let's click on this register, you can see the snack text in here, name may some email may some at gmail.com gender male country Norway, it seems like we have created our text successfully. Okay, I think that's enough for this video. I hope that you have solved the challenge. In the next section of the course, we are going to create the first of four of our applications. Now we know about Java. Now we know about user interface. And in the next section of the course, we are going to combine these two. And we are going to create our first real world application. Besides practicing everything that we have learned so far, we are also going to learn a lot of new stuff as well. So stay tuned for the next section of the course. And as always, see you in the next video. What's up, everyone, I hope you're having fun. Before we start creating our sample application, I would like to remind you that there is an extended version of this course that you can watch by enrolling in the extended course, you will have lifetime access to more than 60 hours of videos. You can ask your questions directly from me and I will come back to you within hours. You will have access to all of the source codes that I write in the videos. And also you can have access to all of the new videos that I upload. Just check out maycode.org for more details about the course. And don't forget to use free code camp as the coupon code to get 20% discount. If you want to get serious in Android app development, taking the extended course is almost a necessity. Okay, everyone, I just wanted to remind you that there is an extended version of this course that you can take without further ado, let's start creating our sample application have fun learning. Hello, everyone, and welcome back. In this section of the course, we are going to create the first application of the four real world application that I promised. It's important to say that in creating this application, beside practicing everything that we have talked so far, we are also going to learn a lot of new stuff. You will see them in action when we create the application. Okay, now let's talk about the application itself. We are going to create an application that will help the user to manage his or her library. In this application, we are going to show a list of different books to the user. And the user can see the details of that book later on if the user wants, he or she can add that book to different lists. For example, a list that indicates that the user has already read this book, or maybe a wish list, or also a favorite list, we will see all of them later on in the course. In the process of creating this application, we are going to practice all of our knowledge about user interface and Java. And beside that, we are going to learn about a lot of new concepts. After watching this section of the course, you can change the application that we create together and you can even publish it in the Play Store. So I highly suggest that you watch this section of the course and don't skip it. Okay, without more talking, let's create our project and let's start writing our application. I'm going to start with empty activity as before. Let's change the name of this application to my library. For the other fields in here, I'm not going to change anything for the package name. Once again, I'm going to put my website name in backward or that may code that project name, which is my library, the same location is fine, language is Java, and we are going to stay with API level 19 for the minimum SDK. We are also not using the support library. So I'm not going to check this option in here. Let's create our project. And let's start working on our layout file. Before everything, I'm going to add the material design library dependencies into my project because we are going to need them. For that, let's go to material.io. Let's go to this develop tab. Let's select Android from here documentation getting started. Let's copy this line of code. We have done this previously. So I'm not going to explain anything here. In our Gradle scripts, build that Gradle module app. In the dependencies, let's add that. And also the latest version is 1.1.0. So let's change this one. And let's sync our project. It seems like we have added the material components successfully. First of all, let's change the style of our application. In values styles.xml. Instead of this app compact team, I'm going to use theme.material components dot light. Let's close this. And let's switch to our activity main.xml file. Our application is going to have multiple pages later on, we will see how we can create multiple pages or to be specific multiple activities. But for now, this is going to be the first page or the first activity of our application. And let's quickly design that. First of all, I'm going to have a text view. For the name of this application. After that, I'm going to add a few buttons. One for the list of all books, I'm going to show the list of all of books by clicking on this button. I'm going to add five more buttons and I will talk about them. Let's also add an image view above in here for our logo. For now, I'm going to stay with one of our avatars. And also I'm going to add a text view in here for licensing. Let's give some ideas to our elements. For this one, I'm going to name it IMG logo, because it's going to be our logo. For the text view, I'm going to say txt name. But I'm not sure that we need an ID for this one. This button in here is going to show a list of all of our books. So let's say btn all books. Also, let's change its text to show all books or see all books. Beside that, I don't like that this text is in all caps. If you want, you can change that. You need to search for all caps. This text all caps. And you can change its value. Let's change it to false. Now you can see that this text is much more better. For the second button, I'm going to change its ID to btn currently reading because this button is going to show the list of the books that the user is currently reading. Let's say btn currently reading. And let's change the text to currently reading books as well. Like before, let's change the text all caps value to false as well. For the third button, I'm going to change its ID to btn already read because this button is going to show the list of books that the user already read. So let's say btn already read. Let's change the text to already read books. Once again, let's change the text all caps attribute to false. For the fourth button, I'm going to change its ID to btn want to read book. Let's say btn want to read, because this button is going to show the list of different books that the user wants to list. Basically, this is the wish list. Let's also change the text. Let's say your wish list. Let's change the all caps attribute. That seems better. The fifth button, I'm going to change its ID to btn favorite books. Let's say btn favorite. And for its text, I'm going to say see your favorites. Once again, let's change the all caps attribute. And for the last button, I'm going to change its ID to btn about by clicking on this about button, we are going to show a dialogue in which we'll show some information about this application. Let's say btn about. And let's change its text to about. For this button, I'm not going to change its all caps attribute because I think it's better this way. Let's also give an ID to this text view as well. Let's say txt license. I'm going to change its text to developed by mason at mako.org. I'm also going to change the style of this book to italic. Let's search for text style. Let's change this font to italic. Also, let's change the text of the first text view to the name of our application. I'm just going to put my library in here. Later on, we will change the font of this text view as well. Okay, let's add our constraints. Also, you can see that I'm using the constraint layout in here but feel free to use the relative layout or linear layout. I'm more comfortable with constraint layout. So I'm using constraint layout. Let's add our constraints. I'm going to add a margin top of maybe 70 dp for this image view. But before that, I'm going to move my text view because right now I cannot see that. Okay, now let's add the margin top. I think 50 dp would be better. Now let's constraint our text view to the bottom of our image view and also to the both side of our screen. We also need a margin top. I think once again, 50 dp would be fine. It seems too much. Let's say 40 dp. Let's constraint all of these buttons. For this one, I'm going to constraint it to the bottom of my text view and also to both side of my screen. I need a margin top, let's say 30 dp. After that, let's constraint the second one, I'm going to fast forward the processing here. Sometimes like this, if the items are too close to each other as before, we can select both of the items. And by right clicking, we can use this right click menu. Let's say we can currently reading top to bottom between all books. Let's add a margin in here by selecting our button. Margin top, I think 16 would be fine. It seems too much. Let's say 10 dp. Also for the second one, for this last text view in here, first of all, I'm going to constraint it to the bottom of my screen. And also beside that, I'm going to constraint it to the both edges of my screen so that it would be centered. Also, let's add a margin bottom of maybe 16 dp. That seems better. For this image view, I'm not going to use a sample data. Instead, I'm going to show the actual image. I have prepared an image in here on my desktop. Let's use that I'm going to copy this image. Let's add it into our mid map folder, resources, mid map, right click and paste. I think the name is fine. And let's switch to our split view. For this image view, if you click on that, first of all, let's delete this last attribute this tools source compact. And instead of that, let's use source. Let's address the image that we just added into our project. It seems too large. We need to pass the width and height manually. Let's say 150 dp. I think that's fine. And also 150 dp for the height. That seems a little bit better. For this my library, if you remember, we had an attribute called font family. Let's search for that in the design view. Font family. If you click on this arrow, more funds, let's search for a good font. Once again, these are the Google fonts and you can use them in your projects free of charge. I think this lemon font is good. Let's add fun to our project. And let's press okay. You can see that the font has changed. Let's also increase the size a little bit. Let's search for text size and instead of 14 SP, let's say 18 SP. That seems better. The next thing that I'm going to change in this layout file is the widths of all of these buttons. I want my buttons to have the same widths. Right now you can see that these have an ugly shape. If we click on one of our buttons, let's switch to a split view. Once again, let's click on that. For the widths, if we say 200 dp, I think that would be fine. Yes. For all of our buttons for the widths, I'm going to say 200 dp. You can see that it's much better now. Okay, this is going to be the layout for the first page of our application. Let's quickly initialize the necessary items in our Java file. By pressing double shift, you can search for main activity that Java file. And in here, let's initialize our UI elements. Let's also initialize these buttons down below inside this on create method. I'm going to do that inside another method, let's say init views. And let's create that method by pressing out plus enter. Once again, I'm going to fast forward the process of initializing these buttons by clicking on each one of these buttons beside this ptn about I'm going to navigate the user to another activity. Up until this point, our applications had only one activity which was named main activity. But if we want, we can create another activity in our application as well. We are going to talk about activities and fragment in the next video. But creating an activity is really simple. There are a lot more concepts regarding activities. We will talk about them later on. But in here, if you want to create an activity, you can do something like this. In your project inside Java folder, inside your project folder, you can right click on that by saying new activity. In here, you can see that you have few options. The names of some of these activities may be familiar from that gallery view from where we created our project. But basically in here we need this empty activity, you can also select this gallery, in which you will get the same dialogue when you created your application. Let's select empty activity. Once again, in here we can name our activities. The convention in here is that to use the keyword activity in naming and also, you cannot use spaces and also other strange characters. For the name of this activity in here, I'm going to name it all books activity, because this is going to be the activity that we are going to navigate the user. When the user clicks on that see all books button. So let's say all books activity. You can also see a checkbox in here, it says that if you want to generate a layout file for your activities, it is possible to create an activity with only the Java file and not the XML file. We will talk about that in the next section of the course, but in here we do need a layout file. So I'm going to leave this one checked in here. You can see that when I changed the name of my activity, also the layout name changed as well. In the layout name, you cannot use upper cases letter. And as you can see all the letters change to lower cases beside that you cannot have spaces. You have another option in here to indicate that if this activity is going to be a launcher activity, basically in every application, one of the activities can be launcher. Right now the launcher activity in our application is this main activity. It means that when we launch our application, this main activity is going to be shown. And for that, I'm not going to check this option in here. Also, if you don't check this option in here, if you changed your mind, you can change it in your manifest file later. But more on that later on in the course, the package name is fine, we are going to create this activity in our package. And for the language of this activity, once again, I'm going to use Java. Let's finish creating our activity. And let's see what happened in our project. So first of all, a new Java class has been added into our package, you can see that we have this all box activity dot Java file. Besides that in our resources folder, in the layout folder, we have this activity all books dot XML. Both of these has been created by the Android Studio. Beside that if you take a look at your manifest file, this Android manifest dot XML, you can see that in here we have a new line, we have a new activity tag in our application tag. It means that now our application has two activities. If you want to create your activities yourself without the help of Android Studio, that is possible. Basically, you can create a Java file. After that, you can create a new layout file. And beside all of these, you need to add this tag into your application tag inside the manifest file. Also, you need to link the Java file and layout file in your own create method. We will take a look at that in a minute. But instead of all of these, we have used the help of Android Studio. Okay, let's close this manifest file and let's switch to activity all books dot XML file. You can see that in here we have another layout in which we can design for this activity. In this video, I'm not going to design the layout for this activity. Instead, I'm just going to change its background color. If we switch to a split view in here. Once again, you can see that we have a constraint layout. And inside the opening tag of this constraint layout, I'm going to say background. And I'm going to pass a color. For example, I think I'm going to pass this color accent. I'm doing this because I'm just going to indicate that we have navigated the user from the main activity to this all books activity. Okay, now let's see how we can navigate the user. Let's close both of these files this all books activity dot XML file and also this all books activity dot Java file. I said that we are going to navigate the user to the other activity by clicking on this btn all books activity. So we need to create an on click listener in here. Let's say btn all books dot set on click listener. Let's pass new on click listener. And inside this on click method is the place to write the logic to navigate the user. In here, I'm going to use an object that I have never used so far. And that object is called intent. You can see that it's coming from Android dot content package. Let's import that. Let's name it intent is equal to near intent. It's a simple Java class that we have defined it like any other Java class. The constructor of this intent needs two things. First of all, we need to pass a context in here because we are inside this main activity. And hopefully by now we know that activities are context. We need to pass main activity dot this. Let's pass that main activity dot this. After that we need to pass the destination activity where you want to navigate the user to for example, I can say all books activity dot class. So this way we are saying that this intent is going to navigate us from the main activity to all books activity. After that, when we created our intent, we can call an inner method in here called start activity. You can see that this start activity needs an intent. And we can pass our intent safely. This start activity is an inner method like this fine view by ID, which exists inside every activity. Now if we run our application, we should see that when we click on this button, the user will be navigated to all books activity. Let's quickly test that. Right now you can see that we have few issues with our layout. First of all, we cannot see this license text view. For that we need to decrease the margins from here. And also beside that, this currently reading books text does not fit in our button, we will increase the width of all of our buttons as well. But for now, if we click on this see all books button, you can see that we are navigating to the other activity. Besides that, if we press this back button, once again, we will be navigated to our main activity. It seems to be working perfect. Let's quickly fix the issues with our layout. And let's finish off this video. In our activity main dot XML file. First of all, let's decrease the margins. For example, this margin top, I'm going to change it to 30 dp beside that margin top of this my library text. Let's decrease that to 30 dp. That seems better for all of my buttons. Instead of 200 dp, I'm going to say 230 dp. For example, for the first one, let's say 230 dp. Let's run the application once again. And let's see if we have fixed the issues successfully. The layout seems better. Okay, I think that's enough for this video. Just before I finish off, I'm going to say that you can check the source code for this application at maycode.org slash code. So feel free to check that if you need I upload the source code at the end of every video also would be very happy to see your feedback. Okay, in the next video, first of all, we are going to create a model for our books. Besides that, we will create a recycler view and recycler view adapter to show a list of different books inside the second activity. See you in the next video.