A free video tutorial from Fahd Sheraz
Lead Web Developer & Software Engineer | Instructor
4.3 instructor rating • 6 courses • 70,659 students
Learn more from the full courseKotlin Android Development Masterclass
Learn Kotlin, Android Development, Android Studio & IntelliJ IDEA from Scratch. Build Android Apps in Kotlin.
32:16:59 of on-demand video • Updated February 2020
- Build sophisticated Android Oreo Apps using Kotlin
- Quickly master Kotlin Programming language
- Become a Confident Kotlin and Android Developer who is hirable
- NEW Content and Updates will be added to the course frequently
- FULL SUPPORT - Your answers will be answered promptly!
English [Auto] In this video we are going to talk about variables. It's all going to go ahead here in create in new Koplin files so say New Cut and file going to name these variables definition. Say enter Now you notice we have a new file here. OK so I'm going to go ahead and get rid of all of this that's just junk. We don't need that. All right. So again I'm going to go ahead and say fun function and I'm going to say main This is very important because each Katlin file needs to have a main function which is the first entry point for the program. So we're going to say here args x ray and we're going to pass here straight. Of course we have to put we have to put our races there signify that we are creating a function. So anything that comes inside here will run when we run this program this project. So we are going to be talking about variables. OK. So variables are a very important topic in any any programming language you'll ever learn. Variables allow us to set spaces in memory and to say that this space is here we are going to put certain kind of information in whenever we want that information back we can refer to that spot or for that variable name. OK. So think of it as a little bucket where we can put information Gates or if we put information somewhere you want to be able to bring it back. Right. How do we create a variable. The first thing we need to do in cotland we so far that's the keyword we need to use to start with variables again var and we have to give right name right because we need to give a name that we can then use it to get the value that we have added to it. So we're going to say for instance name OK and we're going to say equals Partlow like that. The other thing you may have noticed already here is that with Katlin you don't need say my calling right in many other languages. You need to see my Collin's to signify that this statement here is ending. OK. So in Katlin no need for those. In fact if you add one you will have this little warning that say redundant semicolon. Perfect so. Now here what we did was create a variable. We start with var and we name names so we're creating that little bucket and we name it name and then we are assigning Paolo to name which means now we say print L N and we pass the name. Why do you think it's going to happen. All right let's go ahead and run this. And there we go. He says Paolo gha Now notice something here. This is called a string. OK. And we'll talk more about that the next video. So this ring essentially is a text. All right. So we put double quote whatever is inside double quotes is considered a string. So we're putting this string inside of our name. OK. Go ahead and create another variable can save var last name and we can say shown. And we can go ahead and say print line passing the last name. And you notice the moment we put a intelligent here is smart enough to say hey I think you meant you want this last name here variable right. So we don't have to type it out ourselves could just go ahead and say enter and voila. All right. Save and run. We should see Partlow shown. And naturally we can get by doing so said Vire. Again let's say what else dog's name can say do us something like that and we can go ahead and say pretty in line say dog name. There it is. All right. Enter the say this and go ahead and run. We should see Powell is shown doofus. Now you can start seeing the power of having these variables here because now we can infer by calling that name and we get the result we get whatever we've put inside of this pocket inside of the variable as you can see here we have Paul all in one line and is shown in the next line. So if you want to put all of these in one print line we can actually concatenate thing we can say plus and we say last name if we save these and let's give it a run again. We should see Pablo shown as you can see here we don't have a space between Parlow and the show. So what we can do to add a space we can just add a string an empty string. In fact we can put a space there and put it plus. Now this space here will be right as a string. But since it's an empty string will give us a space that we need. OK. Save this run and wish you'd see the Apollo space shown obviously we could have added a dog name as well here so we can say copy and we can even add other strings inside. That's concatenates class. And here we can say as a dog name I'm getting next line here and you can say dog name. All right. So now let's save this and run. We should see Poudre shown has a dog named doofus. OK. Now we constructing a string here but all of this is coming from our variable. All right. So go ahead and play around with this new knowledge that you have now. So go ahead and create different variables right. And give them different values and print them out and see if you can concatenate them or adding them together as we did here and add text in the middle as well if you want. And just to make it look something like this we had here at the bottom in our console. All right. I think you can manage it. OK perfect so I'll see you next.