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.  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.  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 eleme