Kotlin Programming Full Tutorial with Android Development Project | Android Studio | @SCALER

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hi everyone I'm somya a software engineer at red hat and an educator today we are going to learn cotland from a scratch this is going to be a complete crash course on cotland but before we Deep dive into the tutorial make sure you check out our free master classes by industry leading expert on scalers event page link is in the description in this module I will explain each and everything about cotland if you already know any other object oriented programming language like C++ Java Etc or even if you are a complete beginner in the tech world don't worry at all I will make the concepts super duper simple for you you will understand even the complex Concepts very easily so first of all I will talk about what is cotlin why cotlin and where cotlin is used so let's get started talking about what is cotlin so cotlin is a statically typed object oriented language it targets mainly three platforms mainly three things number one jvm that is Java virtual machine and Android as well as Java Script okay so I mean in the Android domain cotlin is doing something crazy I mean anything which Java can do it can handle all those stuff and on top of that it provide plenty of extra features it's simple sweet precise and I mean a lot many features are there I will share with you the entire timeline of cotlin how it came into picture why it is used where is it used and in 2023 24 is it a good idea for you to learn cotlin or not so it can do anything with Java can and it combines objectoriented and functional program programming features so if you have already read about oops that is objectoriented programming language you know you would be knowing some of the you know features like encapsulation inheritance what are classes objects and so many things are there right so it's somewhere combines the features of both objectoriented as well as functional programming languages but remember that it is objectoriented language and not functional language okay it was developed and maintained by jet Brains it's open source yes the code is publicly available and it was released under a apach to OSS license so this is kind of history of cotland when it was launched way back in 2016 so yes it is a fresh uh new programming language in the tech world and as soon as it was launched about 156k that is 1 lakh 156,000 000 developers were using cotlin and its use case has been rapidly increasing I mean you can see from 2016 to 2017 there's a significant rise and this Gap in just one year is just incredible so I mean you yourself would be thinking if so many developers are adopting uh cotland they are using it so obviously there would be something special in this language AG right and one of the reasons of this significant rise from 2017 to 18 is in Google iio in Google iio 2017 cotland was declared as the official language for uh developing applications for Android development so that might also be one of the reasons of this significant rise this language is modern it is pragmatic uh what pragmatic means is it is not very much based based on theoretical stuff it believes in practicality I mean um it you know works on is stuff like if you notice old programming languages maybe Java or any such thing for that matter so they are somewhere heavily based on theoretical Concepts right but it is pragmatic it focuses on the Practical use cases I mean if you go on developing application right so obviously as a developer you want many uh stuff to be automated you want something to be taken care by the language itself right maybe null safety uh or those crashes which we get in our application because of minor mistakes so yes it is based on practicality and yes obviously it is modern programming language and this is the timeline of cotland in 2010 the project was started so the logo was also kind of not finalized they started it with this something similar to Java I mean we use a kind of you know uh coffee and that Java symbol if you are aware of right so it was based on something um it they were trying to make a logo something similar because obviously cotlin is based on kind of top of java it provides everything that Java provides you and obviously there are plenty of extra stuff that cotlin can hand for you so yes in 2010 it was started in 2016 cottin 1.0 was released and then 2017 as I told you uh in the slide uh that it became the official language for Android I mean official support for this was declared by Google in their event Google IO and then in 2018 quarin 1.3 and yes I mean uh year wise every Time new release keeps on coming like in every programming language or if you talk about Frameworks as well if you go in JavaScript react any domain for that matter so obviously so many releases updates are always there right the same is true with cotland as well cotlin is a programming language for jvm for Android browsers as well as native so these are kind of main focus areas where cotlin is heavily used right uh jvm Java virtual machine Android your Android applications so if you know there are three kind of applications which are developed that is totally based on the operating system I mean uh if you talk mainly there are two types of operating systems right uh the first one is obviously Android and second is IOS so the application developed for Android platform they are Android application the ones which are developed on uh for iPhones Etc they are uh called you know uh they're called as iPhone applications I mean that go live on App Store while the application that we develop for the Android platform they go live on Google Play Store right so yeah for both of these for this one uh Swift or objective c such languages are used and for developing Android applic ations qulin cotlin Java these are used and nowadays there is also concept of developing or writing code on and uh yes that application will run on all kind of platforms all kind of operating systems so if you code in Dart flutter Etc so yes I mean you can develop uh application that works on Cross platforms as well all right let's move ahead head and yes again summarizing it is objectoriented cotland is objectoriented language and a better language than Java but still it is uh still be fully interoperable with Java code I mean there are plenty of big live projects which uh have mix of both the files the uh Java file as well as coron file I mean many of my friend who uh are working in some of the startups Indian startups like menra PM Etc so they what they are doing their Android application the big softwares that they have written are heavily in Java and now they are slowly migrating from java to Quin why because I mean you will understand yourself after the end of the module one it provides a lot many extra features it's so crisp simple precise if I am writing any piece of code in 10 lines using Java then I can do the same thing in cotland in maybe five or less than five lines I mean it is this much precise and developer friendly as a developer you will love this language Scotland it is sponsored by Google and announced as one of the official languages for Android development in 2017 so I already told you that coton is pragmatic it has good tooling and uh yes it is from jet brains uh toolings like it has code completion navigation refactoring inspection so all those features which are there for any old uh any you know industry standard programming language everything you can get with cotlin as well with cotlin as well so in Android Studio which is used for developing Android application you will get some uh inbuilt facilities inbuilt options of conver converting the code into quadland let's say if you wrote something in Java you save the do Java file right you will get the option to convert that do Java file directly into cotlin with the help of those plugins with the help of those options which are provided to you in the software in the N studio and yes it can be easily mixed with Java code you can have Java and cotlin both the codes both the files in just one project it is possible and that's why and how so many people are able to use it because if let's say it was not possible to keep both the files together then obviously those big softwares those big open source projects and the companies like menra Etc who are uh changing themselves who are slowly migrating from java to colon they they would have not done that right it is only possible because they both support each other and they both can stay stay in the same project yes it is modern concise safe and expressive I will explain each and every concept why it is concise safe everything uh soon so the this is the extension the plug-in which I was talking about so you can easily convert your Java file into cotlin with the help of these inbuilt functionalities okay and yes it is concise because it drastically reduce the amount of boiler plate code that you write and it is safe it avoid entire classes of Errors like null pointer exception so if you have been writing code in Java if you have been developing Android applications especially in Java you would be knowing about the pain that the you know uh null pointer exception errors uh give you so with the help of qulin you will stay safe there and it is interoperable as well 100% with job it support Android browser as well as native and yes it is tool friendly it provide excellent tooling uh because obviously it just coming from jet brains and Jet brains has a good history of providing good IDs good languages Etc so it is concise then Java you would need to write approximately 40% fewer lines of code when compared to Java and yes it is uh interoperable with Java and you will never face any difficulty using cotlin in any Java project it is feature Rich as well it provides several Advanced feature like operator overloading Lambda expression string templates so down the line in the coming modules I will be explaining all the advanced concepts as well so yes stay tuned and it is very easy it is easy to learn programming language if you have uh come from maybe Java background C++ Etc you would find it very very easy to learn coton I mean everything everything is almost same as compared to those languages a bit of here and there syntax changer it's much more simple smooth and developer friendly now that you have a bit of idea of what is Scotland and how it is better the entire timeline history of how it came into picture how many developers started using it and in 2017 it was announced as the official language for Android all those things you have a basic idea of Gatland right its features everything now let's talk about where cotlin is exactly used so if you remember in the earlier sites as well I told you there are three major application of cotlin the programming language so you can use it to build Android applications cotland can also compile to JavaScript making it available for the front end and it is also designed to work well for web development and server side development as well and if you remember I told you it works well for jvm as well that is Java virtual machine right awesome cotlin used by industry gen so these are some of the organizations uh that are heavily relying on cotlin as the programming language Pinterest corer brains atashian Gradle and the list is really very long so the applic of cotland the programming language is vast I mean uh when I was in university so I contributed to several programming uh you know projects open- Source projects and they were heavily using cotland I mean they were kind of slowly migrating from java to cotlin in um GCI that is Google code in 2019 I was one of the mentors for two projects me organization andab b.org so both of these organization the open source organization had good number of Android projects mobile app projects and they were written in Java so in that competition in that open source program basically uh Google codin a lot many issues were there which were just about converting the feature written in Java into cotland and like developing new enhancements and adding fixes fixing bucks Etc a lot many issues were there and heavily cotlin was being promoted so yeah I mean cotlin is now in 2023 24 it has been already well tried tested by so so many developers and yes it's a good decision to go ahead with cotland especially if you target to learn how to build native application native Andro application so now let's talk about how we can set up the cotland development environment okay so there are two things number one is the cotland playground which is so simp simple and easy it's just uh URL uh which you can you know click you can open and you can start writing your cotland code there so you won't need to download anything in your laptop in your system and yeah I mean it's very fast you just write your code to just you know understand the syntaxes like how uh variables are created in cotland how this thing that syntax everything is done you can try test test everything in the cotland playground and apart from that the second way is obviously IDE so any IDE uh which supports Java on which you can you know write Java code that will perfectly work fine for cotton as well you can either use intellig you can go with eclipse eclipse any ID for that matter you can use okay yes I mean uh let let me first help you take a tool of cotton playground and after that we will do the ID thing as well so if you open up your favorite web browser and just type cotlin playground so the first link that you will get your cotton playground that is play. cotland l.org this is the official uh link from the cotland language the platform itself and if you scroll down a bit the second link that you see here is from Android why because I already told you that in 2017 Google IO Quon was announced as the official language for developing Android applications right so they also are popping up the try cotton and practice what you have learned so far type your code in the window below and click the button to run it so we will first go with this one the official coton playground so this is the interface it's pretty simple and uiux is also quite appealing right so here different versions of cotlin are available uh you can see it is for jbm for like for different uh things you can try it out so basically let me explain you what is written over here so fun is a keyword in Quon like in Java you would have heard about the final keyword right so in the same way fun is a keyword to create functions in cotland to create functions we have this keyword fun okay and then main is the name of the function here and here in the braces we can pass parameters don't worry at all if at this point you are not understanding these words like functions parameters Etc so I'll explain it when we go back in iPad so right now I'm giving you a tour of playground the coton playground okay fun is a keyword main is the name of the function you can give it any name for that matter and and then this is the curly braces uh to pass the parameters right so uh meanwhile in the comment section do one thing let me know if you already know any other programming language if you already are aware of any programming language then it will be very easy for me to explain things I mean uh you already would be knowing what are functions and why do we pass parameters in function Etc if you already know then let me know in the comment section okay I'll read all the comments so fun uh the keyword name of the function and then we'll pass the parameters this is the opening and the closing curly braces okay basically and this is the body of the function to write comment you can just follow the old uh method uh just two slashes yeah and this is the body of the function body of the function and then I want to print hello world so whenever we learn anything new so the first thing that we do is Hello World be it if we are going to learn app development so hello world application or hello world code in C++ Java so in school days in 11th standard I learn C++ at that time also the first code that I wrote was hello world right and yeah I mean this is kind of the standard culture of the tech world so print Ellen with the help of this I am going to I'm telling that okay I want to print something right and then I giving it the message that I want to print hello world okay so if I run it you will see a simple message here that is Hello World okay because obviously right now I just have this uh print Len line so as you can see it is showing you the message hello world if I change it to let's say hello from Scala and if I run it again so it should now show hello from a scaler so yes this is the output message that you are able to see here so you got a basic overview of the playground right so maybe in the other modules when I'll teach you everything we'll start with variables what are variables water functions everything we'll discuss in detail in cotlin the syntax okay so before that let me also help you understand the ID part as well just in case you don't want to do a stuff here uh on the Cotton playground then you can also install any ID so let's say I want to install intellig so install intellig so basically I had in intellig installed already but I uninstalled it to show it to you I mean how you can go about it okay so this is the uh official website from jet brains uh installation guide is available here depending upon which operating system you are using when Windows Mac you can follow the instruction okay for Windows this is the set of instruction that you can follow right now I am on Mac so I have the experience of using all the three operating systems and yeah like all have uh their own pros and cons so since I am on Mac OS so I will follow this instruction so I will download the dis image from the toolbox all right so I'll go here and the DMG this is available here I'll just click on download thank you for downloading and just click save so it will do the download for me and after that one thing that you must have is install Java so if I go and type here terminal so if you open up your terminal and uh type Java version so right now Java is installed in my machine in my laptop Java 19 is installed so if it is not installed in your laptop make sure you install Java as well okay so install Java just write this and yeah man after that you will get plenty of uh you know handy articles blogs so this is from java.com how do I install Java so you can follow either of this okay if I click this one so I mean for any installation be it uh intell be it git Java anything you will get a good number of resources available because before you already thousands of developers have written code right perfect so this is the instruction to download Java for Windows and like yeah based on again which operating system you are using you can install it you can go ahead and read this documentation as well they have explained it quite in detail with the screenshots Etc right so right now I'm not on windows so I can't show you exactly how to go about installing on Windows but obviously these tips are pretty much simple and easy to understand like on the intell the official website itself you will get all the details based on your operating system okay so if I open it up uh the file that I install so I just have to drag it into the applications folder and after that I will search for intellig intell okay let's maybe come in the uh launch pad and here okay it install the tool toolbox for me the complete toolbox let's see um okay so right now I have an a studio by this shed PR the toolbox install right I want to install the first one that is intellig idea this is Ultimate right if you scroll down this Community Edition is something which we want okay so ID e for Java and cotlin enthusiasts install Okay so it is downloaded downloading it is installing in TJ for me okay once the installation will be done I'll open it up and write the write a short quick program in cotland to explain everything to you so that everything is crisp and clear in your mind okay so intellig is now installed in my laptop in my machine and now I will try to create a new project and I will write the code in cotlin programming language and run it and show you the output okay so I hope till now everything is clear you you got to know what is Scotland playground it's super duper simple I mean the website is there you just have to write your code right quite easy and after that if you want to do the same thing in ide for that you can install any ID if you already are using any like eclipse or anything you can uh write your code there as well and make sure in you have Java installed in your laptop in your uh system system for installing let's say if you want to code on intelligy only intellig idea make sure you download the community version only all these tips are explained here in detail now I'm not sure which operating system you are using so let's say if you're on Linux you can download the tal extract and like everything this step by step everything is written here here you have to download.exe run the installer and wizard would be there you just just have to follow the you know uh next next steps kind of thing so I hope this much part is clear right and you can do a standalone installation as well directly like um instead of the intell the jet BR the toolbox like right now what I did I installed the toolbox app and from there I installed the intell community version you can do direct installation as well of intellig idea uh you can just use uh these set of instruction the bullet points which are written here right uh a lot many options are available here all right perfect so after the installation let's now click on new project and uh here you can see I mean a lot many options are here generators are available here and before that let me show you a brief of this as well so uh ha customization options are available if you want to change the theme to light dark to anything you can do that for now I prefer this and this is the font size like uh the size of the uh code which you will be writing plugins are here you can install plug-in based on your needs and then uh this is learn section you can learn to program uh you can start and blah blah lot new options are here tip of the day Etc so for now let's click on new project okay I will name it hello coton hello cotlin project this is the location wherever you want to save your project you can do that right and this is the jdk so uh basically in my laptop uh I showed you earlier as well when I write Java version in the terminal uh Java 19 is installed so it picked up the same jdk you can add jdk as well you can download jdk as well you can do multiple stuff here and and yes then uh Android uh ID plugin cotton multiplatform a lot many options are available for you here right you can go ahead with this as well for now I want to keep it simple uh okay they are expecting so if you see here it is expecting uh some like Maven Arch type Etc that is because we select Ed here the generator MAV right for now we we don't want to go ahead with any generator we just want a simple new project in cotlin so I just have to go here in new project in here I will write cotland hello hello cotlin or anything you can give it the name test as well because it is your maybe the first program written in coton right so hello cotland this is the name of the project and after that this is the location you can change it based on your requir comment language I want to uh write code in Cartland this time Bill system and jdk is 19 if you haven't yet install Java you can do it directly from here as well download jdk and it will do it for you and uh it's up to you if you want to add sample code or not for now I will and uh let's go ahead and click on create so this will create a sample project for me a sample cotland project in which U some sort of sample code will be present because I clicked uh yes in that uh option right so if I maximize this they are telling me what's new in intell for now I'm not interested in that so this is your project all right uh this is your uh simple cotlin code so you saw the same similar thing here in cotland playground as well and you are doing the same stuff here in int till now till now if you have faced any issue any bug in installing in downloading the IDE or while creating the project let me know in the comment section I will come I'll help you in resolving the issue okay so here if you see there are multiple options available on the just notice the cursor of my mouse so here you can see Hello qulin the directory is there inside that you have multiple folders idea folder is there for now that is of no use for us this one the SRC folder is very important for us okay inside this you have Main and then cottin folder inside cottin folder we will be creating all our new files okay new files for now only one file is there main. KT main. KT okay so yes you have mainly these options here inside hello cotlin SRC and then main this is the most important one okay main. KT is there so fun again is the keyword main is the name of the function and then we are passing some argument here argument of parameter here and that is name of the parameter is ARS and that is of this type okay I'll simplify it don't worry at all and then this is print L to print something try adding program arguments why so for now I'm removing this and this is your hello world code now if you want to run it you can see here multiple options are available this is the Run button run main. KT if I click on it so you can see here let's click on Cross so here it is trying to build something and this is your output this is your simple crisp output okay so if I write here maybe uh if you want to create let's say another function you can do it fun uh test you can pass parameters and body and uh like that you can go about it right and I can just call this function here uh like main is the driver function so whenever I click on run no so the compiler that searches for this method the main method the main function so it will line by line go and execute everything so as soon as I click on the Run button the compiler will check for hey where is the main function main function here it is here at line number one so it will execute the line number two that is it will print hello world and after that I'm calling the test function the test function right so it will call the text test function uh I will say learning is uh fun and rewarding I mean when we learn something new then only we get results out of it right we get some good projects in townships shops scholarships and so on so again I will click on run and U yes so you can see Hello World it executed the second line and after that it called the test function here and uh it executed line number seven that is learning is fun and rewarding process finished with exit exit code zero that's it I mean you got a basic idea of how to run the cotton code in Cotton playground as well as in an IDE as well so simple no if you're facing any issues once again I'm saying just pause the video go ahead and write down in the comment section what is the issue you are facing and we are here for your help okay awesome so now let's move ahead and um what I will do is I'll do the screencast again and try to explain you even more significant even more advanced concepts around cotton okay so let me do this screencast so we have got the idea of what is Scotland playground IDE also we are aware so uh develop vment environment for development as I told you Java is needed and any IDE so we installed intellig idea Community Edition right perfect so you would be thinking why is Java needed if we are writing the code in cotland right so if you are maybe a non-technical person or maybe from the tech domain only and you are for the first time learning cotlin I can understand you I can feel you You' be like hey somia like we are going to learn cotlin we are WR going to write code in cotland and why are you asking us to install Java because cotlin is a jvm language now this is going to be very interesting for you to understand I mean if you're going in any interview Etc also this is very important concept so listen to me very carefully now so this is kind of usual process if we write code in cotland dokt and if you compile it it is converted into bite code it is converted into bite code and same same thing happens with Java if you write code in Java and if you compile it it is converted into bite code okay it is converted into bite code and after that um if you run it like JM can run it and so on the kind of uh the process is very much similar to how we do in Java uh basically jdk is Java development kit and jdk is a mix of it is a combination of jvm and other libraries Etc this is just for your theory knowledge don't don't get confused too much I'm just going to explain why we installed Java I mean why we installed jdk okay it short answer long story short is because Scotland is a jvm language now let me help you understand what is a jvm language and why is scotl a jvm language okay so what is a jvm language uh Java virtual machine is a virtual machine which enables a computer to run Java program as well as other programs written in any other language which which which can compile to bite code okay which can compile to bite code so basically jvm is a machine which run any program jvm is a machine jvm is a machine which can run any program which can run any program that is compiled into bite code bite code so we just got to know we just got to know that cotlin code can be compiled into bite code right so jvm is that machine which run any program which can be compiled into bite code so obviously indirectly it means jbm can run cotlin code as well if you save any file in cotlin language if you write code in cotlin and if you compile it so it will be converted into bite code and jvm is one such machine which can run all such programs which are uh you know present in bite code so cotlin also when comp compiled is converted into bite code and Java as well as Java as well when compiled uh is converted into bite code so Java and coton both of these can be converted into bite code and jvm just need bite code to run the program that's it that's it I mean a jvm compatible language is a programming language that can execute perfectly on jvm or indirectly you can say which can be compiled into bite code which can be compiled into bite code so jvm language is any language which can be compiled into bite code and we know that cotlin can be compiled into bite code and therefore cotlin is a jvm language it's so simple and so easy okay jvm can run anything uh which can be converted into bite code and cotlin can be compiled into bite code perfect so here are these steps which I already did uh these are a kind this is a kind of summary for you if you are facing any issue in installing Etc so the step one is you have to install Java Java I mean Java it is not mandatory but like uh yes kind of uh minimum you should have is this and then IDE installation is Step number two you can install any ID I mean this is not just not only these three any ID okay if you already are using any ID you can check that as well uh this is a bit of theory here you can just take a screenshot of this we wrote the hello world program right we wrote the hello world program let me explain you what that uh was so fun I already told you this is a keyword this is the name of the function and then inside parameters we can pass so sorry inside uh the braces we can pass some parameters right we can pass parameters this is name of the parameter and after the colon this is the type this is the type of parameter then inside curly braces you have the body of the function inside which you can write anything whatever you want it to do so main is the entry point Main is the entry point of any uh program R in cotlin okay jvm looks for this method the main method while running your program I already explained this to you that main is the driver function okay I mean whenever you will compile it the jvm will look for main method then it will l L by line execute everything perfect so now let's talk about variables how can you create variables in cotland so let's say let me give you a simple example we recently did a shifting right and the the company which we had agal Packers and mover what they did is uh they kind of created boxes and they wrote some stuff on that like a kitchen study books something like that so kind of some data was present in the box and they gave a name to that they gave a name to that let's say five is present or some stuff is present and if I call it with the name of a score so kind of uh this is the purpose of variable I mean to hold data I mean some data is present in this box this box this box How will I know that I mean how will I call them so I have to give them some name I can call them a b c CD like you have a name right Samia Rahul akanga critica so many names are there right everyone is known by their unique name so in the same way to store data uh we have variables okay simple box that holds the data each variable has a name to access the data now the question is can it be reassigned or not so here is the real thing uh in cotlin we have two things where and well to create variables okay let's say I want to um create a variable name and give it the name scaler okay give it the name scaler so name is a variable and the data is a Scala right I can also create variable marks okay let's say this is your marks in mathematics out of 100 I'm giving you 99 okay so variable and value right this is uh the data this is basically your data and to access this data to access your name I'm giving it I'm creating a variable okay this is your variable to access I'm giving it a name like uh to the boxes I am giving names right in the same way to access some sort of data I'm creating names so there are two things as I told you where and well in cotland so if you create a variable using the keyword Val so it will be kind of constant you won't be able to reassign it you won't be able to give any new name uh let's say if I write Val name is equal to scaler right scaler so I can't do like name is equal to scaler Academy why because Val is constant I mean if you are creating something uh using Val that means in the entire project in the entire project the data uh the value of this variable will not change will not change if you want to make it changeable then where name is equal to scaler and then maybe later in the project you can name it a scaler Academy something like that right perfect so where and well that is um very important concept uh in Cotton let me quickly show you with the help of code as well so let's say if I am writing here uh let's remove these extra functions for now I'm removing it yeah so let's say I want to create a variable name and I want to give it name es Scala okay I want to print the value of this print uh name okay print name that's it so uh as of now if I let's say give it the name Scala it will print Scala very obvious right if I want to change the name later to maybe scaler Academy I can do that very easily here now if I run it now if I run it you will see here I will see scal Academy right if I change it to Val it will throw error what it is saying it is saying that Val cannot be reassigned this is what I just told you that Val cannot be reassigned if you are creating a variable using Val keyword you cannot change its value in the project if you are creating a variable using Val keyword you can change the value anytime I mean right now you named it name uh scal Academy you can again change it to uh maybe cotland cotland from Scala learning cotlin from Scala okay learning cotlin from Scala and if you run it you will see that only so learning cing from a Scala so as simple as it looks and now let's get back and uh uh see some more advanced concepts here basically these are not Advanced it these are fundamentals I me how to create variables talking about data types now there are types of data right now what I did I created name variable and gave it the value scaler Academy right that was of type a string that was of type A String if I want to store marks if I want to store my marks um let's say in physics 97 so this is of type integer right so these are the data typ types in cotlin integer floating Point Boolean character if you just want true or false Boolean is there for integers short in Long bite float double floating point and then in character care a string right these are the data types and these are some quick facts about cotlin let's quickly check it so once we will uh go on and on create more and more projects or files in cotlin we will write more code in cotlin you will understand uh you know these data types in detail let me show you one more thing like uh there are two things basically that you can do in cotland you can specifically tell it the type as well you can tell it that hey you are of type string you are of type string whoops you are of type string even if you don't tell it it is a smart enough it is a smart enough if you are writing something in double quotes then obviously it's obvious that okay you are writing you're giving uh value of type A String right let's see I want to write here I want to create here marks variable so I can either explicitly tell it that hey you will be of type end and then give it a value 98 and then maybe print it okay so here uh I mean I'm explicitly telling it that you are of type int if you want to do it it will automatically understand that okay this is of type integer if I do 98.0 decimal right so this is floating uh value right floating Point double float Etc so yes let's get back um you will understand more about data types as we write more projects and files okay in cotland so cotland does not need a semicolon to end statements you would have noticed um by now it is null safe so um I'll show you some real example that will help you understand better how it is null safe so in uh Java if you have the experience of writing code if we call something which has null value like let's say if I'm calling uh test do object or something like that and if something is null here and there it will throw null pointer exception right and that will uh crash your application so it is null safe and uh it has no Primitives no properties felds you can take a screenshot of this and you can study the quick facts about cotlin from here these are kind of theoretical stuff and yes I mean uh as of now till now you have created your hello world project in Cotton you have uh executed you compiled your first project you know what is jvm language you know the basics of it how to create variables in cotlin where well the keywords right if we talk about operators in cotlin there are three types of operators in cotland arithmetic operators relational operator and increment and decrement operator so talking about arithmetic you have mathematical modulus like uh modulus is for you know quotient like let's say if we are doing 13 modulus 2 right so 13 / 2 is 2 6 12 1 so one is the modulus here remainder okay remainder so yes I'm me arithmetic operators very much simple I'll show you by writing the code then there are relational operators greater than less than Etc and there are pre and post increment operators as well so let me show you the concept of operators by writing code okay so let's jump into the IDE now IDE so uh let me remove all this piece of code and um show you like how we can deal with operators in cotlin okay so let's say I have a uh variable a it has value 10 variable B it has value five okay so I can do multiple operations here like a + b whoops inside this inside this A+ b or you can do print Ln Ln a minus B okay A minus B and the same way you can keep on writing um like you can write other uh operators as well you can try multiplication division everything a into B multiplication right print Ln a / by B a / B and if we run it so it should show us the value of all these you can see uh 10 + 5 is 15 it is showing us 15 then 10 - 5 uh is 5 then 50 and Division 10 by 5 is 2 you can also print here a modulus 5 that will a modulus B sorry uh that will give you the value of the remainder right you can see here it is zero because uh 10 divided 5 0 is the remainder right perfect and yes that way you can uh try out other operators as well these were arithmetical operators rational operators are also kind of same let's say you want to check if a is greater than b or not right they are telling that uh this is obviously like true because 10 is greater than five so let's check what it prints here so it is printing true right you can in the same way test out other relations as well like is a less than b so uh it is obviously always false because 10 is not less than five right so in this way I mean multiple relation operators are there you can check if this is equal a is equal to b or not that way you can check out other operators as well relation operators so these were arithmetical operators these are relational operators right and now let me show you the magic of increment and decrement operator right so um if I do A++ this will do exactly what a is equal to a + 1 will do so basically a ++ or maybe a minus minus these are increment and decrement operators okay and here as well you have two things post increment okay let me explain you here so pre-increment pre and post okay uh let's first understand what is pre pre means before right so if you write plus plus a so what it will do is print Ln let's say print Ln and Plus+ a okay whoops Plus+ a so um here as soon as you write plus plus a it will quickly quickly increase the value of a it will print 11 here okay it will print 11 let's run and check so it printed 11 right if you write Plus+ after a that is your post increment uh let's write it here only this is your pre okay whoops whoops whoops this is pre this is coming before the variable name right if I write Plus+ after the name of the variable so what it will do as of now it will uh remain same I mean A++ so at this point it will show me the exact value of a and if I print it later then it will tell me that hey the value is now 11 I mean it will increment the value but after some time right print so see here it printed 10 and then 11 okay and once again if I do here Plus+ plus plus a so it will at that point only immediately it will increase the value here also it will print 11 and here as well it will print 11 right now it is 10 and 11 you can see right 10 and 11 if I run it again so it will tell me 111 okay so basically that is the power of pre post okay and plus plus means it will increase the value by one and minus minus means it will decrease the value by one very simple and a straightforward nothing uh you know nothing confusing here let me know in the comment section if all the uh pointers still here are clear variables you now know how to create where a is equal to this right Val also you can use if you want the value of B to not change in the project you can call well that's it and then you talk we talked about three types of operators as well arithmetic operator relational and these are pre and post increment and decrement operators right so yes I mean I hope by now you have got a basic idea of cotlin we talked about the basic stuff and in the coming modules we'll Deep dive into more advanced concept classes and objects in cotland cotlin is an language object oriented programming language and uh it is a paradigm which allows us to solve problems with the help of objects which represents the real world entities this is object oriented programming language and in such languages object play very very significant role and classes and objects are kind of integral part of such programming languages so if you talk about classes in General so class is a blueprint or a template you can say and objects are the real thing you create objects in your program and they interact with each other to complete the work this is a bit of theory and might be right now you are not clear of what exactly classes what exactly objects are right so I'll give you some examples and that will help you understand things in way better manner Okay so if you see this picture it contain Mobile 1 2 and three right and all these are different in terms of their size Color battery type and features right might be uh this is phone from Mi company Oppo and so on right but can you imagine what is the general thing about all these three types of phone so yes all these three are mobile phones right if we want to put all of these in one category we can say mobile phone and these three the Oppo phone Mi all these are mobile phones cell phones right so if we have a class of mobile phones then we can have objects 1 2 3 which are of different companies right so this is how the concept of classes and objects are to make it more clear to you let's say if you have a class of car of car type then inside this you can have multiple objects right you can have uh object of type Ford you can have object of type BMW you can have object of type tataa Etc I mean so many cards are there right so yes I mean that's how the concept of classes and inside that objects all the objects will be uh you know somewhere related to that class like all these are related to this class mobile phone these all are mobile phones only right in the same way all these objects object 1 2 3 are of the same type they are car only but obviously the features the color everything will be different the price and all those stuff right perfect so before you create objects in C cottin you need to define a class A class is a blueprint for the object we can think of class as a sketch or prototype of a house it contains all the details about the Floors doors windows Etc based on these descriptions we build the house house is the object okay since many houses can be made from the same description we can create many objects from one class might be in uh two objects the only difference is of color they're all same but uh they are of different colors right perfect how to define a class in cotland now let's see the syntax of classes in cotland very important so we use the keyword class okay we use the keyword class and after that class name based on your need let's say if you are creating a class for car you are creating a class for people for objects anything for that matter right so class keyword this is keyword keyword and then this is the name of the class name of the class right and then inside this you can have multiple properties uh you can have member functions you can have variables like for people class you can have name as one of the variables age gender and so on right awesome so I hope the concept of class is a bit clear to you now right you would have got a basic overview or of idea of what classes are if car is a class then you can have objects of uh objects like BMW Ford and so on right in the same way if you have person as the class you can have multiple objects object person one person two and so on awesome here is an example of the same this is class lamp and inside this you have some member functions as well as some variables right so this is where is on this is of type Boolean private is the uh modifier visibility modifier I'll talk about it shortly so where keyword you already know is on is a variable and we have given the value false to it so lamp is on is on a kind of variable which tells if the lamp is on or off right true means is on false means it is not on and then we have member functions as well uh we have we have uh turn on function so obviously if you'll call this function then the lamp will be turned on if you you will call turn off function then the lamp will be turned off right perfect so here we defined a class named lamp the class has one property is on defined in the same way as variable obviously we just saw this and you have two member functions as well turn on and turn off these two are the member functions these two are functions and here we have one V one variable all right moving ahead classes objects properties member function Etc can be can have visibility modifiers obviously like we just saw private here private by default they are public so for example the is on property is private here this means the is on property can be be changed from only inside the lamp class that is that variable is private that can only be changed from inside the that class in which it is created in which it is declared other visibility modifiers include like private obviously you just used uh visible from inside the class only public visible everywhere protected visible to the class and it's sub classes as well internal any client inside the module can access them so you will understand more about uh these modifiers Etc once you'll start writing code more and more code right so if you do not specify the visibility modifier it will be public by default as I just told you and in the of program turn on and turn off member functions are public whereas the is on property is private so basically they are saying is on property is private but these two member functions turn on and turn off are public because we haven't given any visibility modifier to them now let's talk about cotlin objects before that I hope you would uh you remember the syntax of classes basically you just have to do like this class keyword will be there and then the name of the class name of the name of the class based on your needs and inside this you can have data members or you can call them data of variables and apart from that you can can have data functions as well you can have data functions as well moving ahead let's now talk about cotlin objects when a class is defined only the specification for the object is defined no memory or a storage is allocated so uh we just created this class lamp right so when the class is defined there is no kind of memory or storage is created for that class if you want uh to access the members if you want to access the members defined within the class like is on or turn on turn off if you want to access these you need to create objects okay objects of the class and uh the syntax is pretty simple so you know that this is the class okay class lamp one second yes so this is the class lamp till this point this is main function whenever I'll compile the program so that the uh compiler what it will check it will first of all check the driver function that is the main function now if you see the first piece of code here first line of code here number one well which is a keyword L1 is equal to lamp basically here I created L1 object of lamp class okay what it will do is it will create some storage for uh for us I I mean if I want to let's say access the property is on so I can say L1 dot is on L1 dot is on if I wanted to access let's say this function turn off so turn off something like that using the dot operator using the dot operator this one is called dot operator I can access the data members and the member functions inside the class okay awesome so this is the way we create uh the objects Val or where anything name of the object object one two whatever you want and after that the class whichever class you want to call something this like lamp Okay this program creates two objects ele and L2 of class lamp the is on property for both the lamps will be false the is on property for both the lamps L1 and L2 will be false because obviously in the starting while we created the class lamp we set the value of this variable is on as false moving ahead how to access members I already explained you you can access properties and member functions of a class by using the dot notation do operator for example L1 do turnon this statement calls turn one turn on function for the L1 object let's take another example so L2 dot is on is equal to true so basically what we are doing is we are calling the Ison variable from the L2 object and we are setting its value as true because initially it was installed as false right so here we try to assign true to is on property of L2 object note that is on property is private and if you try to access Ison from outside the class an exception will be thrown right now here is an example of cotlin class and object again so this is the same example if you see so this is the content of of the class lamp we have turn on function we have uh the turnoff function apart from that we created a new function that is display light status right depending upon like we'll pass some a string variable and then we'll check if is on is equal to true then it is on otherwise it's off so here it's important to understand what we are writing okay let's see so function main is the first thing to be executed when the compiler runs a program right so Val L1 is equal to a lamp basically we created L1 object of lamp class and then we have L2 object of lamp class so L1 do turn on we are calling L1 do turn on so it will uh go and do this Ison is equal to true so for L1 the value of Ison is true right so when I will do L1 do display light status so is on is true so it will print that that this lamp is on right L1 lamp is on and for L2 I'm calling turn off so the value of Ison will be false and therefore when I'll call display light status by passing the L2 object and obviously is on is not is equal to true so it will print lamp is off perfect it's very simple I mean behind the scenes also is very important to understand so let's say when you are creating uh an object uh like Mustang Beetle anything uh for any of these classes like if the class name is car so as soon as you create the object memory is given memory is allocated to the uh particular class depending upon how many member functions how many you know variables are present in that particular class and let's now write uh some classes some objects in cotland to understand this concept in even better manner perfect so now let's create a class uh of name maybe you can create my class in which we will create objects and classes and see the syntax of classes and objects in cotland right so I'm going to create new and here is cotland class and file I will name it my class and it should be of type file then I'll write function main because obviously main function is the most important thing I mean whenever you will click this Green Run button so main function is the first thing which the comp compiler executes right so here we will create object of the class object of the class we know the syntax very well before creating the object of the class obviously the very first thing is we have to create the class itself right so the syntax of creating class is very much simple and straightforward you have to use the keyword class and after that the name of the class so right now I want to create a class of name person and here what you can do is like we uh in the syntax read that we can have curly braces right and inside the curly braces we can have data variables we can have me member functions and like variables as well as functions right of that particular class so here if you see I can have curly uh I mean simple parenthesis as well and inside that I can pass on values when while creating the object of the class right so what I will do I have the person class so person class can have variables like name of the person age of the person gender of the person and so on right so let's say I want to create variable name okay so where name uh which should be of type string okay and after that where H and that should be of type int and so on you can create multiple variables here right name age and depending upon the person class what kind of variables member functions it can have you can create go on and on right these are the properties the data variables and you can create these inside the class as well but for the E I created I passed these here itself just uh in next few minutes I'll teach you why I did that and why it's important in cotland and how it's related to the concept of Constructors as well okay perfect and and here I will create one function can vote okay can vote whoops can vote and I will accept the age variable age variable the parameter and inside this I'll check if age is less than 18 then I will print here I will print cannot vote can not vote else if the age is uh like I can simply go on writing else if the age is greater than uh if it's less than 18 then cannot vote otherwise print Ln I will say can vote okay can vote awesome so I have the person class ready and inside that I have one function can vote and the two properties two data members are name and age okay either you can pass these variables inside the person class or the way I have done it in the parenthesis as well so I'll create object of the class person so where object one or you can say person one so obj1 is equal to person and here I have to pass some properties right so the first name I'm giving here samama and I'm giving here age 22 okay and after that to call other you know member functions variables I'll say object one dot you can see here I have multiple options I can call name age or can vote so I want to call can vote and I'll pass here 22 uh so if I run this piece of code you will see that it will print can vote why because the age passed here is 22 right 22 so what it will do it will call this function and it will check here if age if 22 is less than 18 it is not less so will come here and print can wot okay so it's as simple as it looks creating a class the synx is very simple the class keyword is their name of the class inside parenthesis you can pass some variables and you can do the same thing uh like after you know creating the class person and inside like function can vote is here right so you can similarly have some variables here as well name and so on so it depends on you I did it because I want wanted to you know pass values here via the object only while creating the object it looks it's look it looks better I mean depending upon the use case you can change the way you create the class you can change the way you create the objects and so on and now let's get back to the iPad and I'll teach you some more important Concepts around oops around classes and objects so now let's talk about Constructors in codin yet another very significant concept right right so cotland Constructors a Constructor is a concise way to initialize class properties to initialize class properties like uh I just now created the person class and inside that I had properties like name age Cano Etc so if I want to let's say initialize the values like name age and there can be like multiple values so for those uh Constructor is very important if anyone ask you what are Constructor so they are very handy they are concise way to initialize the class properties it is a special member function that is called when an object is created when the object is instantiated however how they work in cotlin is slightly different in cotlin there are two types of Constructor primary Constructor and the secondary Constructor so talking about primary Constructor the primary Constructor is part of the class header itself this is uh a good example here class person and then we have variables here first name and age and this is the class body so the block of code surrounded by parenthesis is the primary Constructor itself this much block of code this much piece of code which is surrounded by the simple parenthesis that is primary Constructor in cotland okay so I just created The Sim similar kind of of class right so in that the class header itself is containing the primary Constructor right the Constructor declare two properties first name read only property as it is declared using the keyword Val okay and then we have age that is read write property since it is declared with the keyword where I hope you remember where and Val which I taught in the starting of the course in module one right so this is again example of primary Constructor uh function main is here I created person one the object of the class person I passed Joe 25 as the value of the parameter first name and age right so here I'm trying to get the value of the uh person and the age as well so person one object do first name and object. AG it will print the value of the variables right perfect perfect primary Constructor and initializer block so the primary Constructor has a constrained syntax and it cannot contain any code so as you just saw the syntax of primary uh Constructor is quite like restricted kind of only this much part I mean after the name of the class in parenthesis you can pass parameters that is the primary Constructor it is in the header of the class while creating the class so it cannot contain any code we just saw to put the initialization code not only code to initialize properties initializer block is used it is prefixed with init keyword and if we try to modify the above example so it will look something like this function main right we passed we created one uh object person one for for the class person and we passed two values so here we passed Joe and 25 right then I have first name and age as the data member for the class person then I have initialize a block in it and inside this what I'm doing I'm initializing the first name you can see here first name is equal to fame. capitalize and then age is equal Al to person age whatever we are passing here so the value of first name will be like if we if assume this is the value so JW in capitals because we are capitalizing here and 25 right and if you print here so obviously you will get the value which we passed right perfect so I mean it is the example of initializer block in it if you want to initialize something not only initialize ization but you can do much more than that you can use in it block because we saw that the um kind of Freedom given to primary Constructor is quite constrained right so you can use the init blocks as well and moving ahead when you run the above program the output will be first name Joe and age is 25 AG is 25 so here parameters F name and person AG inside the parenthesis accepts value Joe and 25 obviously these F name and person age they accept the values which we pass from here right and uh after that when person one object is created however F name and person age are used without using where and well they are not properties of the person class they are not properties of the person class the person class has two properties first name and age page as declared here inside the class person and when person one object is created code inside initializer block is executed so if you ask when this init block is executed it is executed as soon as you create the object of the object of the person class when person one object is created the code inside initializer block is executed the initializer block is block not only initializes the property but also PR prints them okay but also prints them so I hope the concept is clear now the F name and personage inside the parenthesis that is uh this one they accept the value that we passed from here while creating the object and when the object is created it executes the init block which is here right awesome and here is another way to perform the same task so we have the function Main and in this we are creating person one object object which is of type uh which is for the person class right and we are passing two values here and if you come here you can see F name and person age they are here to accept the values that we are passing while creating the object and here uh first name and age I I'm initializing them I'm initializing them inside in it I'm just printing a stuff I'm just printing a stuff to distinguish the Constructor parameter and property different names are used used like f name and first name Person AG age Etc it's more common to use these kind of variable names so when you will run the program which is written here so output will be something like this and when the object of the person class is created Jo and 25 values are passed as if the person is a function and that's the beauty of classes and objects in cotland like here we created the class in the way a function is is created right and that's why it was able to accept the values when we passed while creating the object the same thing is written here this initializes the first name and age properties of person one object to Jo and 25 respectively moving ahead primary Constructors they're very simple and easy to understand they're kind of inbuilt I mean in the class header only the primary Constructors are there if we talk about cotlin secondary Constructor so in cotland a class can also contain one or more secondary Constructor they are created using the Constructor keyword using the Constructor keyword secondary Constructors are not that common in cotlin they are not heavily used but yes it's important that you understand what are cotlin secondary Constructors the most common use of secondary Constructor comes up when you need to extend a class that provides multiple Constructor that initializes the class in you know different ways so here you can create a secondary uh construct in cotlin this way here is the syntax so let's say the class name is log right if you want to create secondary Constructor use the keyword Constructor Constructor and then you are passing one parameter then Constructor keyword and you are passing two keywords here two uh sorry parameters here here the log class has two secondary Constructor but no primary Constructor at all you can extend the class in this way uh if let's say class log is there it is having two Constructors right you you have or log another class which is inheritance is basically going on here it is inheriting from log class right which is created here so you can see I me uh that can inherit the constructors as well from the parent class here the Constructors of the derived class or log calls the corresponding Constructor of the Base Class log and for that super keyword is used here as you can see super keyword is used right so I mean secondary Constructor in Cotton is not that heavily used I mean very less and to create you have to use the Constructor keyword that's it that's it apart from that primary Constructor are very common and you just saw multiple examples of it it's kind of you know uh primary Constructor it is one of the concise way to initialize the class in cotland and the synx you understood already moving ahead moving ahead by now you know how to create class in cotland how to create objects and when objects are created then only some storage is allocated right and you can call the data members the member functions of the class using the object only you know how what are Constructors and types of Constructors in cotland moving ahead let's talk about cotlin Getters and Setters so in programming Getters are used for getting value of the property and similarly Setters are used for setting the value of the property if I want to let's say set the value of some variable to maybe scaler right so I can simply do that with the help of some syntax and that's what we are going to see what are Getters and Setters in cotland so in cotland Getters and letters are optional and are autogenerated if you do not create them in your program so if you do not create them in your program they will be autogenerated right so how Getters and Setters work the following code in cotlin if you see so class person and V name we are creating a variable of type a string and we are giving it default value right this one is equivalent to this piece of code class person we have we have name variable of typee a string and we have some default value here so if we are not creating getter seter by default it is being created there if you see here get is equal to field getter and uh Setter in this way set value and field is equal to Value so in if you write this much piece of code you can assume that Getters and Setters are by default created in the background in cotland example let's understand this one quite uh lengthy piece of code but it's very very simple I mean nothing you know difficult is there whenever you feel that any piece of code is difficult just start executing it start doing dry run of it and it will become very very simple for you to understand so obviously fun main the compiler will start from here Val Maria is equal to girl so basically what we are doing here we are creating Maria object for the class girl right Maria do actual is age is equal to 15 so I'm calling the actual age the actual age parameter so let's see how many parameters are there in class girl so age is there and then actual is age is there right for age we have written some piece of code Getters and Setters right so here get is equal to feel and set is equal to Val value and field is equal to 18 if value is 18 otherwise something like this right they have written a lot of Getters and Setters code right so let me erase this and now let's see here so maria. actual age is 15 so if I'll print this obviously I should be getting 15 and I'm getting 15 only right I'm getting 15 but if you see here maria. age is 15 and uh for age I can see I have Getters and Setters available here so it is doing some change here if value is less than 18 so for me it is less than 18 only so it is saying that uh field is equal to 18 I mean it is changing the value and that's why when I'm later on printing maria. AG I'm getting 18 as the output 18 as the output right same way let me again do a dry run of the other piece of code that will help you understand better so here what I'm doing is I'm creating Angela object of type girl right Angela do actual age is equal to 35 I'm setting the I'm calling actual age and I'm setting its value as 35 so when I'm I will print it it should give me 35 it should give me 35 right this much part is clear after that angela. AG is equal to 35 but here if you see 35 will be passed right so if value is between 18 and 30 this will be the case otherwise otherwise uh I will fall in this case because the value here is 35 right and 35 is neither less than 18 it is neither between 18 and 30 so obviously this piece of code will be executed value will become value minus 3 that is 35 minus 332 so when I will do angela. H so 32 should be printed and yes 32 is printed at the end right so basically uh what we are trying to do here we are trying to write Getters and Setters on our own by default Getters and Setters are obviously always there but here we are trying to do some extra piece of stuff using Getters and Setters these are also not kind of heavily used but yes you must know what Getters and Setters are basically Getters are used for getting value of the property and Setters for setting the value of the property moving ahead late in it in cotlin it's very very important I mean in one of my interviews as well I was asked about this what is late in it in cotlin okay so if you see here I'd prefer explaining this with the help of uh one you know uh practical code so basically late in it if you try to break it down late meaning late later something which is done later on and in it means initialization initialization right so it means we are somewhere telling the compiler or the system that I will initialize this late now I'm saying I'm I will initialize this late what is this here so whenever we create variables right whenever we create variables in cotlin so uh in the class they ask us to either initialize them either give them some value as they will throw error that the variable is not initialized right so if in case I don't know the value of the variable in the starting of the program in the starting of the project but later on maybe I'll give it some value so in those cases I can put late in it I can put late in it that hey I will give it some value I will initialize the name variable but later on in the program later on in the project let me quickly give you an example and that will make things better and easy for you to understand so let's say I I'm taking this example only okay I have the main function and I have the class person inside class person if let's say I want to create one um variable profession okay profession so you can see it is throwing some error that property must be initialized I should give it some value uh this is of type string still it is throwing the value right that it must be initialized but at this point I don't know the profession right and I don't want to keep it empty so I can add here late in it and the error is gone right basically I told the compiler I told the system that hey I will give some value to profession uh but later on late in it I I will initialize it but later on in the project so later on when I feel like okay I can give this value to profession I can give that right so this is the use case of late in it it if you break it down into two parts late and in it it will become self-explanatory for you perfect and now let's get back here and try to understand some more significant Concepts let's talk about inheritance in cotland now let's talk about inherit inheritance in cotland inheritance is one of the key features of objectoriented programming it allows user to create a new class from an existing class the existing class is called the base class and the new class is called the derived class the derived class inherits all the features from the base class and it can have additional features of its own as well so for an example let's say if you are creating a person class or maybe if you are creating a vehicle Class A Better example so inside the vehicle class you can have uh like uh not inside exactly but if let's say uh let me write here if Base Class is your vehicle so you can have multiple derived classes that can inherit a stuff from the vehicle class like car bus car bus truck Etc all these are Vehicles right so these can also be some classes which will be derived class of the Base Class the parent class right so why inheritance is so important in programming or in general in like in this language as well so suppose in your application you want three characters a matth the teacher a footballer and a businessman since all of the characters are persons they can walk and talk however they also have some special skills a math teacher can teach maths a footballer can play football and a businessman can run business you can individually create three classes who can walk talk and perform their special skill right like math teacher talk walk and teach math footballer talk walk and play football and businessman talk Walk and Run business these three are the methods here so in each of the classes you would be copying the same code to walk and talk for each character if you want to add a new feature it you need to implement the same code for each character once again right this can easily become error prone you know while copying while doing duplication of code Etc it would be a lot easier if we had a person class with basic features of a person like walk talk eat sleep and so on and apart from that if there any special function if there are any special feature of any character uh any you know class then you can add the extra function just in that class right this is done using inheritance how so this is now person class the base class it has the basic things that every person needs like talk walk eat sleep and so on apart from that you can have math teacher class play fo football class run business uh you know uh these math teacher footballer businessman these classes and inside this you can have such method teach math or run business play football Etc basically what we are doing here is person is the base class person is the base class and all these math teacher footballer and businessman all these are the derived classes all these are the derived classes so instead of implementing these functions in each and every class n teacher footballer businessman what I did I created a single class that's it and every time you will create something you can just inherit a stuff from there you can inherit these functions from there so using inheritance now you uh don't implement the same code walk talk and eat for each class you just need to inherit them right so for math teacher that is arrived class you inherit all features of person and you add a new feature teach math similarly for footballer as well you inherit all the features of a person and add one more extra feature play football and same goes with the businessman class this makes uh your code very clean and understandable and extendable as well it's important to remember when working with inheritance each derived class should satisfy the condition whether it is a base class or not in the above example math teacher is a person every footballer is also a person you canot have something like businessman is a business right I mean obviously the concept is clear here uh when uh you are creating sub classes out of the base class it's important to understand that when while working with the inheritance each derived class like math teacher football or businessman each derived class should satisfy the condition whether it is a base class or not right so here is the example person is the class here and then basically we are writing the same thing in code as well we have class person and inside this we can have multiple function then we have class matth math teacher which is inheriting stuff from the person class this is all Alo inheriting this is also inheriting this is the syntax of inheritance if you are creating a class XYZ and you want to inherit from class base so you will write something like this and then inside curly braces you can add extra stuff for XYZ right so notice the keyword open before the Base Class person the keyword open here is important it's important by default classes in cin are final final me means cannot be changed or are constant right if you are familiar with Java you know that a final class cannot be subclassed by using the open annotation on a class compiler allows you to derive the new classes from it so if I remove open keyword so you cannot create uh or you cannot uh derive things from here I mean you cannot use it as Base Class okay aome so you now know the significance of open keyword as well so employee is one class it is having name age salary as functions inside this you have uh some more classes I mean some separate individual classes which are kind of uh deriving a stuff which are derived class of the employee Base Class this is the base class here Base Class here and all these all these are the derived class so these derived classes like web developer Android developer and iOS Developer these derived classes will have all the features of the Base Class employee they all will have name age salary and apart from that on top of that they will have some special features of their own as well like web developer will know how to design website they know how to design Android apps and they know how to design iOS applications right so here is the example you can take a screenshot of this as well let me tell you what we are trying to do here so this is the main function T1 we are creating object of math teacher class we are passing here 25 and Jack 25 and Jet then I'm saying T1 do teach maths so it will print I teach in primary class right I teach in primary class and if you notice here if you notice here we are before that before that we have these two extra lines as well my name is Jack and my age is 25 how and why it is coming it's very important it is coming because uh whenever you create object of this math teacher class so obviously I mean alongside math teacher it is uh a derived class of this Base Class person right of this Base Class person so here as well you are kind of passing 25 and Jack and whenever the object of this class will be created so obviously they have in it block and we know as soon as the object is created the init block is executed that's why we are printing this we are printing this and after that we are printing whatever is written inside the math teacher class inside the math teacher class so when the object T1 of math teacher class is created when this is done T1 object of math teacher class is created the parameters are passed to the primary Constructor to the primary Constructor in cotland in it block is called when the object is created I just told you since math teacher is derived from the person CL class it looks for initializer Block in the Base Class person and executes it right since let me repeat it since the math teacher is derived from the person class it looks for initializer Block in the base class in the base class it tries searching for the init block and it also executes it if the math teacher had init block the compiler would have also executed the init block of the derived class right next the teach math function for object T1 is called using this statement the program works similarly when object F1 of footballer class is created it will execute the init block of the base class that is the person class and after that the play football method is called using f1. play football same story is true here with this as well if you create F1 object if you create F1 object for foot then it will search for init Block in the parent class the parent class is person and the init block is this right so it will execute my name is this and my age is this and after that we are calling F1 do play football right so it's it's simple it's just that you should know the theory part of it right if we are performing inheritance then what is the order of calling which function when if two init blocks are there if the init block is in parent class as well as in the derived class then init block of the parent class will be executed first and after that the init block of the derived class will be executed right important note for cotlin inheritance if the class has a primary Constructor the base must be initialized using the parameters of the primary Constructor so uh both derived classes have two parameters age and name so they are giving the uh kind of they are explaining with the help of uh the example so if you look at this example F1 is uh the object we are creating one uh object for footballer class and footballer class is basically derived class of the person based class right of the person based class and footballer has in it method of its own as well so here the primary Constructor of the derived class has three parameters primary Constructor of the derived class has three parameters right age name and club and the base class has two parameters age and name note that both parameters of the base class are initialized are initialized so when you will pass value for the footballer class so this will also be initialized whatever value you are passing here accordingly it will take values for the base class as well in case of no primary Construction each base class has to initialize the base or delegate to another Constructor which does that and here is an example of that again uh I mean here they are using the concept of uh secondary Constructor and which once again is not heavily used in Cartland but you must know the um kind of significance of it right so if you look at the function main we are creating P1 object for for Au log class for a log class and we are passing here bad password the uh value right the Constructor so here you can see we we don't have any primary Constructor so in case of no primary Constructor each base class has to initialize the base using super keyword using super keyword or delegate to another Constructor which does that so in this case because no primary Constructor was associated with or log you can see in the con Constructor in the secondary Constructor we are passing values right so that if we are giving values while creating the object it can process it somehow right so by now you know the concept of inheritance as well right and now is the time we talk about cotlin visibility modifiers as well earlier as well you would have seen using uh seen us using private public all those keywords right by default all the variables member functions inside a class are public but yes uh explicitly if you use private or protected keyword then obviously they will behave that way so visibility modifiers are keywords that set the visibility of classes objects interfaces Constructors functions properties and the Setters you cannot set visibility modifier of Getters as they always take the same visibility as that of the property so these are visibility modifiers inside classes and interfaces you can take a screenshot of this public public private protected internal the words are somewhere self-explanatory public means visible to any client who can see the declaring class private means visible inside the class only and protected means visible inside the class and its sub classes and internal visible to any client inside the module that can see the declaring class basically you should have an overview of what these keywords are and if you override a protected member in the derived class without specifying its visibility its visibility will also be protected so yes I hope all the concepts that we studied in uh this module are clear to you we started with we started with classes and objects right which are literally very important Concepts in any programming language we understood what are Constructors type of Constructors in cotland secondary and primary Constructors all right after that we also understood the theory part of Getters and Setters right Getters and Setters Laten it very significant keyword in cotlin late in it in cotland it is the keyword is self-explanatory late in it whatever we want to initialize later not immediately right so if you want if to create a variable and you want to give it a value later on you can use the late init keyword in the class and apart from that we talked about inheritance we talked talked about inheritance in cotland which is very much same as in any other programming language and then visibility modifiers as well visibility modifiers so yes I hope these concepts are clear to you and uh in the coming classes in the coming modules we'll be creating some exciting projects as well using the cotlin programming language cotlin standard libraries and Android application development today I'll teach you about this concept Concept in cotland programming language so let's get it started the very first thing is and the very basic control flow is if else so let's say if you are writing code and you have to print something you have to perform a set of operation based on certain condition like if XYZ is happening then perform this piece of code let's say if it is raining then print it is raining or maybe show an image which tells the user that it is raining so something like that right so it is completely based on condition if something is happening then perform these actions else otherwise if another action is happening then perform other piece of uh you know execute other piece of code Etc so if it is raining take umbrella otherwise no rains you can enjoy your day so if you have to write piece of code which are about these conditions and actions then you can use if else now let's look at the syntax of if else that's very very easy so this is the syntax of if else if certain condition is true then run this piece of code otherwise else you can run other piece of code right so it is very very simple uh if you want to write if else you just have to do if this piece of code is correct if this condition is correct then execute this much line otherwise else you can execute this piece of code written over here right and you can put multiple conditions as well like if this is true then execute this then again you can put some condition else if this is true else if you can keep on adding else if and then in the end if none of the conditions are true then you can simply write one else Block in which if none of the if conditions are true then that will be executed perfect let's move on and I want to quickly show you how you can write your code in this way if we want to use if else so I'm using the same project that we created in the last module module one okay new co uh new page new file and I want to name it if else or you can name it control or something like that control flow anything whatever you feel comfortable you can name it that way so I'm writing if else and now what I will do is one again class F else and um what I will do here like if you check at the main function that we wrote yesterday so we had one function Main and inside that we simply did some print operation we did increment or and post increment pre-increment Etc so today let's do one thing I want to remove want to remove the class and here I will write all the code okay perfect so I want to write here how if else works so if I'll I'll create one variable where animal okay where animal in the beginning I will pass empty string okay and maybe I can ask the user as well to give some input that if the animal is dog cat anything like that you can right now predefine on yourself as well right so if I can check if animal is equal to let's say cat then we can do print Alin print the animal is the animal is a cat right else else if animal is animal is dog so you can see it is giving me lot many hair HS that hey Samia you can improve this piece of code or that piece of code right so I'll tell you I mean what hints it is giving us the animal is a dog right that way you can go on and on like depending upon the condition depending upon the use case you can add more and more conditions so first thing here it is saying that you can make this uh variable Val because the value is not getting modified in this proc project in this piece of code but it depends on me I mean I might change its value so I want to keep it we okay now if you see here so it is saying that condition this is always false because obviously animal is not is equal to cat and here it will say it is always true so let's try to print and see if it's working if this piece of code is working and you can see here we got the output the animal is a dog obviously because the value of animal the variable is dog right if I write here cat so obviously it will print the animal as a cat right so this is very very simple I mean I just wanted to explain you the syntax of if else this control flow syntax uh if else syntax is too too easy okay now let's get back to iPad let me do a screencast again and here if you see so there are uh there are some kind of rules which you should follow they are not not exactly rules but a good programmer should always follow these standard rules and regulations right you should avoid cascading if else in cotland let's say if you have multiple conditions like if animal is equal to this then this then if animal is this like let's say five to six if conditions are there right depending upon the value of a variable then you should use when instead of if else so if you see here if number is equ equ Al to zero then they are printing zero if number is one then one something like that right so instead you should use when keyword when is a keyword when is a keyword in cotland and instead of multiple cascading if else in cotland you should prefer using when keyword perfect so the syntax is something like this when number is zero then print zero if number is one then print one else you can print minus one right it's so easy as compared to F Els I mean in F Els you were writing a long piece of code I mean you were saying if number is equal to zero then do this this so it's very very easy as compared to if else cascading if else so you can be very simp you can simply write I will tell you the syntax here as well so when this condition is true when this uh value is there so you can be like when X let's say I have X variable right so if x is equal to 0 then perform this operation if x is equal to 1 then perform this if it's two then this if it's minus otherwise like I can be like if you the value is completely different else you can print any value here right so this is the syntax of when in cotlin and here they have decompiled the same concept in Java so in Java instead of when we have switch if you are coming from the Java background you can relate to this very much so basically switch in Java is very very similar to when in cotland perfect I hope the concept is clear now so in Java we used to write something like the this switch number so here it will check the value of number if it is zero it will execute the K zero if let's say it's one it will execute case one and it goes on right in the same way we have the when keyword in cotlin it's a kind of switch in cotlin okay you have switch in Java so the same concept is implemented in cotlin using the concept of when Perfect all right awesome so it's pretty much it and moving ahead now let's talk about loops loops are again very very significant concept I mean if you have studied any object oriented programming language you would have studied Loops indeed I'm pretty much sure about it and the syntax is the concept is very very much same as in other languages so if you already know any other language it's going to be super duper simple for you you'll be like okay somia ma'am like it's so easy I can write the code before you even teach right it's literally that much easy so yes uh we just finished decision making like U if you have to perform some operation based on some decision you will be using IF else you can use when as well and if you want to perform a set of operation multiple times multiple times I'm repeating in that case you use Loops the word Loop is self-explanatory right if you have to execute a set of a statement multiple times then in that case you have to you have to use the concept of of Loops for example if you have to print high developers five times or if you have to print I am learning 10 times then in that case you will use the concept of Loops because it doesn't make sense to write uh print Len print Len High developers 10 times like this right you can do the same thing instead of 10 lines in inad of 10 line you can do this in two to three lines right so if obviously we want to be smart developers right we want to write code that takes less piece of code and uh less piece of lines I mean you want to do something in less uh number of uh lines of code like in Java we used to write 7 to 8 to 10 um lines for the same concept but in qulin we are trying to squeezing it so that the developer experience is good overall right perfect so now the very first thing is cotlin while loop this is the syntax of while loop while some text expression is true then you keep on executing the code which is inside the body of the while loop okay uh if you are a beginner in coding obviously right now you'll be feeling like this is tough concept or something like that but trust me I mean I'll tell you the like example and everything it will become super duper simple for you okay so here is is an example of cotlin while loop let's say you want to print something five times they are printing uh some line something like that five times okay so this is the function main okay inside this we are going to write our code our code so we created a variable where I is equal to 1 and then while I that is this variable is less than or is equal to 5 you have to have to keep on printing this thing and every time you are inside the V Loop you are incrementing the value of i as well so let's quickly do a dry run of this and that will make the concept very very easy for you to understand okay so the very first thing in the first iteration what will happen I is equal to 1 right so in the first iteration it is 1 here it will check while I is less than equal to 5 is 1 less than 5 obviously so I'll come inside this Loop I'll print line I will print line and what is the value of I it is 1 right it is one right now after that I will do plus plus I that is that is the next time I will check uh like I did Plus+ I it is pre-increment so the value of I now is I is equal to 2 so when I will again after this I'll come again here right I'll come again here it will check is 2 less than equal to 5 yes it is so I'll come inside the Y Loop and I'll print line the value of I right now is two right now it is true and then I'll after executing this I'll execute this Plus+ I so now the value of I is 3 plus I Plus+ I means Plus+ I means I I is = to I + 1 right basically I'm incrementing the value of I that's it now it is three I'll again go here I'll check while I is less than equal to 5 is 3 less than equal to 5 obviously so I'll come here I'll print this line three and then plus plus I now the value is now the value is four I'll again I will again come here is 4 less than equal to 5 obviously yes so I'll print here line 4 okay and after that after executing this I'll increment the value of I I will be now equal to 5 and again I will I will come here and I will check is five less than or equal to 5 obviously it is equal to so I'll come and execute this line so it will be line five and then plus plus I so now the value of I is equal to 6 I'll again check is 6 less than or equal to 5 no the condition is now not true so I'll come out of this y Loop I'll execute that line of code which is just after the Y Loop right that's it you are done so the uh like output of this piece of code will be line one line two line three line four and line five to quickly check let's write this piece of code in our uh editor as well this is our cotlin directory I'll create here a new file and I'll call it we were studying y Loop right so I'll name it while and I want to create a file okay so function Main and after that let me increase the size for you H function Main and after that inside the curly braces I want to write the while loop right I want to write the code for while loop so I just executed while loop I used a very simple example right so let's say I want to use the same example that we had last time okay you can use the concept of that animal thingy as well so I want to teach you with the help of let's use this only concept function main so where I or we can create any variable like a b c anything so in the starting let's name give it the value one and I want while while a is less than or equal to 10 okay while a is less than or equal to 10 I want to perform some set of operation the operation is I want to print something whoops line is dollar a Okay so basically uh this is a very this is beauty of cotlin I mean if you are under double codes right if you are using a string and you want to print the value of a variable as it is so you can use the dollar symbol okay you can use the dollar symbol so line is this and after this I'll increment the value of a that's it let's execute this piece of code and see if we did the execution correctly and and yes we did so line is 1 2 3 this is exactly how we executed this piece of code so in that sample code we were given five right so now let's run it yes this is exactly same as what we did right this is exactly same as what we wrote and now let's get back to iPad I screencast and um so I hope while is clear now how while Loops are written the syntax is very very simple okay the syntax is very simple once again I'm writing while this piece of code is correct this piece of code is correct this statement is true this condition is true you can execute whatever is written inside the while loop body this is the body of while loop body of while loop okay so usually whenever we have some variables or something like that let's say you want to execute some piece of code till the uh till it is true right I mean let's say if you have a variable a and you want to execute it till it is less than or equal to 100 then you should have some you know increment or decrement some sort of expression here maybe plus plus a or minus- a something like that otherwise there will be no end to the while loop I mean just imagine it just do a dry run of this it's very important if you want to understand some concept no it's important that you do a dry run of that it helps you understand the concept in a very easy manner in very clean and crisp manner so after y Loop uh I mean here is another example of Y Loop only if you are writing a program to compute the sum of natural numbers from 1 to 100 so this is function main again and inside this we have some piece of code right some piece of code so in the beginning sum is equal to zero and I is equal to 100 so they want to compute the sum of natural numbers from 1 to 100 so while I is not is equal to zero what they are doing they are doing sum is equal to sum + I and every time every time it is inside the Y Loop they are doing decrement they are doing decrement so this this is short hand sum plus is equal to I this exactly means sum is equal to sum plus I okay and then in the end they are printing the value of the sum so if you try to do a dry of this this is exactly uh you know this will exactly do what we were doing in the last example of Y Loop so let me give you one or two dryon of this so in the beginning sum is equal to 0 I is equal to 100 right so next time it will will come here it will check is I not is equal to 0 um meaning is 100 not is equal to 0 that's obviously true so I'll come inside the v body and now sum will be equal to sum + I so that is 0 + 100 is equal 100 and then minus- I so I is equal to 99 okay then next time uh I'll go here I'll check is 99 not is equal to Z obviously true so I'll do here s is equal to sum plus I sum right now is 100 and I is 99 so it will do this summation and then plus minus- I that is 98 so it will keep on doing this till the value of I become zero so starting from 100 it will do it till I is equal to I is not is equal to Zer right till I is equal to 1 it will do it so we will get the sum of first first and natural numbers first 100 natural number from 1 to 100 we will get the sum perfect moving ahead now we have another important thing after while loop we have do while loop okay this is exactly same as y Loop there are few changes here and there the do y Loop is similar to Y loop with one key difference the body of doy Loop is executed once before before the text expression is checked so you will understand this once you see the syntax of doy Loop so do this piece of action execute this piece of cod action whatever is written inside this uh body of do while while this text expression is true so in while loop what we were doing we were checking the text expression before executing the body right here we will execute the body first and we will check the text expression if it is true or if it is not true later on right here is an example of cotland do well the program below calculates the sum of numbers entered by the user until the user enters zero and to take the input from the user we are using the read line function the read line is inbuilt function and with that we are taking the input from the user okay all right so here if you see this is the piece of code right so this is function Main and these are the arguments this is the opening and closing braces for function main so here we have a sum variable which is equal to zero then we have input variable which is of type string so we are performing this piece of this set of action while in input is not is equal to zero so until the user will enter zero as input we have to perform this action so we are printing enter an integer then user will print it uh we are getting the input in the input variable using read line function okay and then we are doing sum is equal to sum plus we are converting the input into integer so whatever input user will keep giving we will keep adding it let's say if I enter five so five plus next time 10 + 1 until I press zero it will keep on adding So In Sum what will I have at the end I will have the value of all the input that the user has given right and then finally at the end I will be printing the value of the sum variable so it's as easy and as simple as it looks let's quickly write do while loop so that it becomes clear okay let me keep the iPad here and we will write do while loop as well as while to so while we you have already seen how the concept of while is right so here we are testing uh the value before executing the piece of code right that is the only difference between while and do while we write the text expression at the end in case of do while okay perfect so let's say um I have a variable V index and the value is maybe seven okay so I want to perform some action here do something while while a certain condition is true while index is not is equal to index is not is equal to zero till then you have to perform some set of action okay perform a set of action perform a set of action till or you can say until or while while the value of while the value of index is not equal to is not is equal to zero okay perfect and that action can be anything like you can just go on printing the value of index okay so the value of index is dollar I will use the dollar sign and then index the variable perfect and as I told you in case of Loops we always have to you know deal with the values of the variable as well if you are Ching the value of index every time and in the beginning it is seven so it's important that somewhere inside the body of the DU while or the while loop you have some increment or decrement operation with that particular variable so here uh the value is seven and I want to print this line at every value of index like 7 6 5 until it becomes zero so what I will do here is I will simply do minus minus index I have to decrement it okay if I execute it so you can see I me the other piece of code this one is also getting executed here in the beginning the value of index is 7 then the value of index is 6 5 4 3 and it keeps on going right perfect and moving ahead now let's uh check the other loop as well so mainly there are three Loops in any programming language we have already checked while and do while right and now is the time that we check for loop as well so the C for for Loop in cotland is again very simple for is a key word okay for some item in collection you can uh I'll teach you I mean this is the basic Syntax for this piece of statement you have to execute these many lines of code okay let's see some example and that will make it clear so let's say you have to iterate through a range of values okay through a range of value so this is the main function inside this for I that is in between 1 to 5 right if the value of I is between 1 to 5 then go and keep on printing I okay if the value of I will become let's say minus one or 0 or 7 6 anything then I will not execute this piece of code okay in this case the value will be the value will be from 1 to 5 okay because obviously I'm telling it that okay if uh the value of I is between 1 to five four we have the four Loop here we have the four Loop here and inside that we are telling that I is in this range in this range then only this piece of code will be executed right perfect and here is another example of for Loop only of for Loop only so we have a text cotlin okay we have a text qulin this is a string right this is of type A String so for every letter in the text for every letter like for k o t l i n what I'm doing is I'm iterating over this string over cotland I'm printing each and every value for letter in cotlin okay letter in this text the for the very first time it will have the value k then it will have the value O then t l I'm just you know printing it so for Loop is heavily used in itating as well it rating over a string itating over arrays and so on okay so let's quickly write for loop as well so that the concept is very crisp and clear in your mind okay so here let's say I have a variable okay where name is equal to a Scala okay and here what I will do is for each text for each text in name I want to print it okay print Len print Len print print Ln I want to print this whoops each text so if I run it you can see S C A the name is spelling is correct and here you can see s c a l e r okay it is one by one printing the value of each character which is there in this given string okay in Java or in other languages what we used to do no uh we used to do something like this like I have U I have this habit of creating variable I is equal to zero okay and I mean we used to learn for Loop in this way only I learned in the first language was C++ so I learned this way only I is equal to Zer or maybe you can initialize it here as well let's say whoops so where I is equal to zero and till I is less than or equal to uh till I is less than or equal to so basically the syntax won't be true for this cotlin right let's try it let's try it okay and then so we used to have three kind of uh you know statements here uh but this is exactly not how this is not exactly how in cotland do that if you go and check on the net as well the snex of uh synex of Loop in cotland in cotland so you will see I mean earlier we used to do it this way we used to have one initialization then control and then increment kind of uh you know variables but in cotland this is exactly how you do things so if you look at the standard syntax of for Loop in cotland so as I told told you it is like this only for let's say you have an array of cars right this is a cars array and I haven't yet taught the concept of array to you all but in the coming modules in the next topics I'll teach about array as well so let's say if you have a cars variable that is area of Volvo BMW for these are some car uh names right so for X in car for each car value you are kind of going in the for Loop and printing each and every value of the car right whatever is there inside the array perfect and let's now come back to iPad and I'll teach you some more Concepts around it so I hope by now you know the syntax of while loop you know how to use do while loop and as well as you know the concept of for Loop right for Loop is also so very much a straightforward it's very very simple right for each letter in this string we can be like printing each we can go on printing each letter right so it's as simple as it looks so if else you already know now and after that you have three main Loops while loop do while and uh the last one is for Loop there is a very small difference between while and do while loop in while loop you check the test condition in in the beginning and in Doh you test that condition at the end after executing uh the body of the do while loop perfect let's now talk about functions in cotland if we are learning any new programming language then obviously function is a very very important concept function is a block of code to perform certain functionality it helps in reusing the code let's say in your project in your application if there is a set of a statement which you want to write um like more than once then the function concept comes very very handy the synx is like this you have to write the fun keyword and then the name of the method whatever the name is like in the previous examples that we just saw we were writing main function right and then inside curly braces inside curly braces we can write whatever we have to write right like print Ln hello world hello from scaler something like that right moving ahead this is again in brief the syntax of function fun the keyword and then name of the function you should always try to give meaningful names to your function and then in curly braces you can give it parameters like uh variable where a where B where C whatever based on your use case right so you can pass your parameters and then and then there will be return type of the function okay you have this is the basic standard syntax of function you can take a screenshot of this as well and then inside curly braces you have some piece of code some statements to execute and then finally return the result return the you know return a value which is of type this let's say if you are saying here that you will return int so the type of result variable should be int only should be int only okay so an entry point of a cotlin application is the main function main function is very very important okay whenever you will click on that run green button in the IDE know so that IDE the virtual machine that will search for the main function so uh this is the main function it will come and it will see okay print and H hell world is written so it will execute that line okay after that let's say you are making a function call you are calling a function and the name of the function is ADD Okay add so it will go and check if there is any function fun add or not so it will go and check if add function is there inside that whatever you would have written that print Ln uh hello from add function everything will be printed Okay so so another form of main function accepts a variable number of a string argument so this was a function in the uh parameter list we had nothing right so here fun Main and inside parameters we are passing a variable the name of the variable is ARS the name is ARS and this is the type of the variable type of the variable type can be either int it can be string it can be Boolean so here it is array of of strings right and then in curly braces we are printing something we are printing something moving ahead we have a function with the two int parameters and int return type okay so fun the keyword the name of the function is some inside curly inside simple braces inside parenthesis we have two variables variable a variable B okay these are of type int and the return type is also int right so what we are returning here we are returning the sum of a + b we are returning the sum of a plus b the return time is Al return type is also int uh right so if I have to let's say I have a function fun main okay fun Main and inside this I want to call the sum function how will I do that I will say sum and let's say I want to do a sum of seven and five so I'll call it this way so it will go here it will uh pass here 7 and five okay then it will return 7 + 5 is equal to 13 right 7 + 5 is equal to uh sorry 12 okay so this way it works right a function body can be an expression as well uh it's return whoops so a function body can be an expression as well it's return type is inferred so basically here what you saw is inside the body of the function we just had one line of code so you can write fun some is the name of the function two variables A and B of type int is equal to a + b is equal to a + b so it's as simple as it looks I mean if you have one line of code inside your function go ahead and use this syntax right equal to and that's it okay a function with two int parameters and int return type so here you have another example fun sum is the keyword and sum is the name of the function not keyword sorry and then you have two uh parameters here return type is also two this is exactly same what we saw here so they are writing complete code we have main function we are printing sum of three and five is then we are calling here what we are doing this is how you call function call a function so uh whenever you click on that Green Run button so it will will search for main function right it will search for main function it will execute this line that is it will it will print sum of three and five is and then the next line is line number seven will be executed it is saying print Ln print whatever this method sum 35 returns right so as soon as the compiler will see this that okay it is the main function is calling some function it will directly jump here it will directly jump here and it will pass here three and five okay and then it will return 3 + 5 8 so here what will be printed the value that you will get here is eight so it will print8 so sum of three and five is 8 as simple as it looks a function that returns no meaningful value so you can use unit as well let's say if your function is not returning any value you can either leave it empty or you can ask it to return unit you can ask it to return unit print Ln sum of a and b is this much okay unit return type can be omitted as well so this and this both are same okay both are same you can see here the fun keyword is here fun keyword is same print Su the name of the function and then both have two parameters A and B it is saying that the return type is unit that is it will not return anything and if you don't write unit then also it's the same and then you are printing here sum of A and B is this perfect all right so now let me teach you function over loading as well it is another very significant concept okay so if in the function if in the function the name is same name of the function is same but parameters are different but parameters are different let's say if in this example right print some the name is same if let's say the type of this is float and not int the type is float so this is the best example of function overloading the name of the function is same but either the parameter type the number of parameter like a b you can have one more C here so either the number of parameter is different or the type of the parameter or the return type is different then that will be the function overloading example so either number of parameter is different or the type is different okay okay for example this is one of the best examples you can see here uh fun function name function name is same list of parameter uh parameters one parameters 2 and return type so I mean the function name will remain same either the number of parameters or the type of parameter or the type of return type will be different perfect now let's quickly write some code to understand the concept of functions in even better manner okay so what I will do here I'll create one more file here uh Quin file okay Quin file I'll name it function function fun main main is very very important okay main is very very important function Main and I will say here print Ln I want to perform I want to perform addition of operation okay addition operation so what I will do here is might be that I might need to add two values multiple times in my project so I'll uh instead of writing here A plus b or something like that what I will do and I have two values here where a is equal to 9 and where B is equal to is equal to maybe 19 okay perfect so I can either do print l in I can go here I can write uh a plus b okay A + B but what happens is let's say you have to do addition again in your project right so many times I mean you'll need to do the same thing a plus b a plus b so what I'll do is I'll use the concept of function I'll create a function fun sum fun sum fun is the the keyword sum is the name of the function and I will here pass some parameters pass some values so if you remember what was the syntax of the uh function in cotland let me show you again screencast so this is how you write it you um simply have to pass the parameters this way name of the variable and then the type of the variable right so let's do that thing here let's do that so let's say the name of the variable is where one whoops where one that is of type in and where two that is of type that is of type int again so and I want uh this function to return integer value only okay so it will return return on V 1 + V 2 let's see if I create one more function sum and I have V one again but this is of type float and v two again and this is also of type float and I want to return float okay and return here whoops return V one plus v two okay so the these two functions and they are the best example of function overloading the function name is same the type of the the type of the variables the parameter is different and return type is also different so what I can do here is I want to call sum method I will say print and whatever value you are getting sum so if I pass integer values so automatically this one will be called okay if I pass here some float value like uh 9.8 and uh and 16 in decimals this is also in decimals right let me see here if I change it to double double and double so it is it this one will execute this sum method and here you are passing integer so this Su method will be called let's run it and see if it's working working fine or not and you can obviously because you are manually giving the value so you can remove it so I want to perform addition operation 17 and uh 26.6 Perfect all right so you got to know here the concept of function overloading the concept of functions in cot Lan it's very simple I mean the synx is literally very simple let me know if you are facing any difficulties till now till this point now let's talk about arrays in cotlin another very important concept whenever you're going to learn any programming language arrays are very important so how do you create or write arrays in cotland where you already know the keyword name of the array then array of 1 2 3 so basically this is a syntax standard syntax where name of the array then array of this is keyword here this is keyword here So What are keywords here this is keyword this is also keyword and then you have to give the name to the array and the values it depends on you right these are not keywords so it's as simple as it looks so here what will be done uh zero index one index 2 index 0o index one index two index at zero index the value is one at one index the value is two at two index the value is three okay to create an array use the function array off and pass the item value us to it so that array of 1 2 3 creates an array 1 2 3 alternatively the array of nulls function can be used to create an array of given size filled with null elements okay quot an array declaration using array of function once again so this is my array one okay these all are keywords uh these are the name of the array that you can decide array of is again keyword okay and then values you have to give so my array one array of 1 10 4 6 15 it is like 1 10 4 6 15 index 0 1 2 3 4 and then array of int same thing array of a string uh in curly braces you can pass the type as well so here you have the array of a string and then array of mix of integer and a string values perfect and here uh array set function example is given to you so basically this is your function main right some argument here ARS is the name of the variable and this is type opening and closing so aray one array of 1 2 3 4 array 2 array of long type okay 11 12 13 14 so it is saying right now it is 11 12 13 14 okay 0o index 1 index 2 index 3 index I saying and this is array 2 and the array one is 1 2 3 4 index 0 1 1 2 3 now I'm seeing array 1 do set at zero index set five so I will remove one and I'll set five here okay array 1 2 is equal to 6 so at index 2 that is this one you have to write six so I'll remove it and I will override it okay array do set zero index so array 1. set at zero index set five so I did that at second index set six so I did that okay perfect then array 2 do set at second index 2 so here I will write two uh sorry I will write 10 at second second index they are asking me to write 10 then array two at third index write eight at third index write eight that's it that's it and to iterate over the array I can write for each element for each element in Array one array one curly braces and print Ln print Ln each element print Ln each element that's it that's it this is what they have done for each element in Array one print an element okay for each element in Array two keep on printing the element so one by one they will print each and every value of the array okay so this is the array one so first is is five and this will be the output five then print and then I'll go here again this is 2 then six and then four this is how it will Traverse over your array using for Loop for each element in the array print each element perfect and here is another example of cotlin get function okay let's say you want to get the value at index one so this is AR one right array 1 1 2 3 4 and I'm saying here I'm saying here array 1. get zero so it is asking me to print the value that is at index 0 so 0 1 2 three so I will print one okay I will print one output one then I'm saying uh print l in Array one two print whatever is there in the array one this is your array one okay array one whatever is there in Array one at index 2 at index two so 0 1 2 I will print three three that's it that's it right perfect so I know I hope you have got the set function do set as well as if you have to directly retrieve the value you can say name of the array and then inside a square bracket you can pass the number the value of the index so now let's quickly understand AR concept by writing code as well right practice makes a person perfect so let's quickly write AR code and um yes function Main and inside the function main I will create an array so where okay and the name of the array you can name it um my array okay my array is equal to array off now this is keyword where is keyword here array off is keyword my array is variable I can name it anything I can give it any name array of let's say 1 2 SE six n anything whatever you want 7 five blah blah like that you can go on about it right now if I want to the very first thing if I want to print all the values of my array how I will do for uh element for element in my array I will create curly braces and inside for for loop I will say print Ln I can just uh you know keep on printing the elements one by one if you run it you will see 1 2 6 9 75 in the output you can see 1 2 6 9 75 that's it if let's say I want to change some of the values so we just saw how we can do that my array do set and index uh you can see here it is telling me uh if you press command P so give index and then the value so I want to change let's say six to something else so 0 1 2 the index is 2 and I want to change 6 to 15 okay 15 and also I want to change another way of changing is let's say I want to change the value of five so I'll check what is the index of five so 0 1 2 3 4 and five is the index of five right maybe I'll create one more value here one more value and call it U 77 okay I want to change 77 0 1 2 3 4 5 6 so I want to change the value which is at sixth index 2 to um 87 okay and again I want to check if these actions were performed in the right order in the right way so I'll say here print Ln print Ln new values of array new values of the array and then I will then I will run this uh file I will run this piece of code so you can see here 1 2 69 7577 okay for the first for Loop and after I ran the set method after I changed the index six right so you can see here the new values are like this at index 2 it is now now 15 and at index 6 it is now 87 okay you can again do something like this print Len if you want to get uh get value at a given Index right at a given index so the value at uh the value whoops the value at index 4 is four is and you can simply write here dollar and then let's not go in dollar I mean let's do it this way my array doget and whatever the index you want what you can write four okay so you can see the value of index 4 is 7 and you can see it is seven right perfect so let me do a screencast once again and let's summarize everything that we have learned so far so we studied the control flow the control flow for decision making we have if else we have when right for Loops we have three things that is why Loop then do while and then for Loop right after control flow we studied the concept of functions functions we talked about function overloading as well and then finally we saw how arrays are created how we Traverse over array how we get set array in cotland right all right so see you in the next module till then keep writing uh code in cotlin the more you will write the more fluency you will achieve and yes over time you'll feel that these syntax these piece of code are very very simple okay so go ahead write the code and push it on GitHub and show us show the internet show the world that okay you are learning something new tell on LinkedIn tell on Twitter tag escaler tag me so yes when you learn in a community you will will see more people around you as well posting things that will keep you motivated right to uh learn things you will see that okay other people are also doing things you can accept 30 days of cotlin challenge as well and every day you can pose that okay today I learned this that day I learned this something like that right so in today's lecture let's talk about Android development and cotlin so Android development is basically developing mobile applications Android app development and Android is the operating system and app is the applications that we use and development so basically Android development is about developing application mobile applications for specifically Android operating system okay like we have uh mainly two operating systems Android we talk about OS then Android is there and we have IOS right so there are Android applications and for that we have Android operating system we have iPhones for which IOS operating system is the uh significant part right so in Mobile domain in mobile application development these two are the main kind of operating systems so we have Android app developers we have IOS developers and there is cross platform as well that is you write the code once and it will run on all the platforms but many of the you know native feature and specific to operating system operating system specific feature native feature that are called generally they are kind of compromised in the cross platform domain perfect so today we will talk about how you can create applications how you can uh you know use cotland language specifically how you can use cotland language to create applications we will understand this part and this will help you in making lot many projects as well using the cotland language so let me tell you a bit of history as well so in the beginning Android applications and like if you are using an Android uh phone you would be having many applications like Gmail zamato Amazon YouTube and so on right so in your phone you have so many Android application so when I was in university so I was a bit confused like how these applications are cre created how these are developed and out of curiosity like I did a lot of research on how to develop such application when we click on a button like send so the mail is send when we click on pay uh or complete order then we are able to make order as well onato Amazon and so much more right so I mean I very I was curious since the beginning how to go about it how to create an application which has so so many exciting feature game apps are there Etc so basically I was doing uh mainly I was learning Java programming language in the beginning for DSC Etc then when I did research so I realized that okay for developing Android applications also Java is used and later uh cottin was announced as the official language for this so basically they are very much like you know brother and sister if you already know Java so cotlin as I told you earlier as well it's very easy to learn and after the last three lectures of this series you would have already got a good understanding a good idea what this language is cot is so simple so easy to understand you now know how to write the basic stuff well where for Loop why Loop so many things you already know right now if you start making projects you will you know even Deep dive into that language you will have something to show in your resume as well to the interviewer that okay I have created this project in this this particular language right so let's get started and see what all softwares what all softwares are needed if we want to create project or if we want to create an Android application using cotland language the beauty of java and cotlin combined together is that you can have Java as well as kt. cotlin file in the same Android project as well so today what we will do is we will use the software and this is very popular ID very popular software for developing applications Android application it is Android studio and apart from that to run our application to see how the application is looking either we will use emulators only I'll teach you what these are or you can use your Android phone as well for this you will need to connect USB in your in your with your laptop okay perfect and if you are going to use phone then you will need to make some changes in your settings as well let me quickly show you what changes if you're going to use your mobile phone to run the application that you will be developing you will be creating with me in these tutorials then for that you will need to make some changes in your phone very simple changes obviously just go on set go in settings about phone and you will see an option build number here click on build number multiple times it will show you a toast like this you are three steps away you are two steps one step away from becoming a developer and then it will finally show you you are now a developer that is when you have to stop clicking on build number apart from that also click on developer options and enable debugging USB debugging so that you are able to easily you know connect with your laptop and run the application directly from Android Studio the software that we will use to create applications Perfect all right so now let's get started and install the software that we will be using I'll show you quickly how to go about it so you just have to write install Android Studio so if I open up my Android Studio so that is right now electric I mean there are multiple versions so this is electric Al 2022 something right so I would highly recommend using that only so that you have the same experience because in every version in every new release of Android Studio they make some changes here and there and I mean the UI also I have heard like recently developers few developers were complaining that okay the new launch P Studio that is so so different from the old ones Etc so um let's do one thing Android Studio install Android Studio install whoops install and you see uh you'll get the official link here right they have Cod Labs as well well using Cod laabs also you can understand understand the process of installing they have multiple steps here it's very simple it's like downloading or installing any other software in your laptop like you would have installed any other IDE like intj Eclipse Chrome Google Chrome right so in the same way it's very very simple and easy to understand what you can do is if you open up this first link so are explaining everything here okay so if you want you can read it based on which operating system you are right now I'm on Mac so I have used R Studio on all operating systems on Windows on Linux on Mac everything okay so if I go here so they are showing me the latest which is giraffe I guess yes end Studio giraff this is the latest release but uh I I mean it's my habit I give some time to to the latest release I want other developers to use it and once I'll see less complaints about it then only I switch the new ones so right now I have electric e only uh e and I'm happy with that so what I'll do is you can go in more downloads are available in the download archives so let's click on this and uh and there are showing some stuff here so I'll say I agree to the terms and now they're showing me the list of all the releases so if you see what I have right now so that is Android electric e let me search Android stud and this is electric electric e 2022 do 1 do 1 do p one this one so this year only this was released in Jan so I did an update from that time since that time so if you click on this you will see for all the operating systems they have the zip they have the uh you know files available you can install from here installers are available here for mac Apple silicon Intel for Windows every everything is available here for you right so you can just download it for Windows 64bit you can just click on this uh ZIP file you can do the download you can do the installation so I would prefer I mean if you use the same version as I'm using otherwise you'll see a bit of you know difference here and there in the software perfect so now after uh after you'll be done installing this after after the installation is completed you have to open up your Android Studio so I opened it up and it looks something like this okay it looks something like this if I click on new project here so you will see multiple options available here all right basic activity basic activity material three bottom navigation activities so you would have used many applications with bottom navigation so what does it mean is if you remember using Amazon or zomato so they have multiple options at the bottom like profile section is there and then Amazon pay is there a lot many stuff four to five are there I guess as far as I remember in the bottom navigation of Amazon app right so in the same way there are multiple activities if there is something uh you know if you want to just create Google Maps kind of a stuff location stuff then you can start with Google Maps activity as well here you will get all the default code itself you just uh will be need to uh you know you just will need to change the logic whatever you want to make in your application for now what I will do is I will choose an empty activity and click on next Okay click on next so this is the name of your project you can change it the way you want okay so right now this is kind of your first application right step number one is you have to install Android Studio okay and already if you have been following this these series of lectures so you would have already installed Java in your local machine I assume right if you want to confirm you can open up terminal just click on search and open up terminal and there you can write Java version and it will show you the version if you have not installed Java it will show you it's not installed right so yes basically you have to install Android Studio the steps you just saw you have all the guide you have all the steps available here right you can install the same as I have right now in my system or you can choose any other as well that's that's completely fine so what you have to do after this is so this is your empty activity right you have to give name to your project like shopping app music app and so on so uh today I will write first app okay perfect and then this is the package name this is the package of your application and this is the location where your applications your Android apps codebase complete codebase will be saved okay you can change it if you want by clicking on this but right now I'm happy where it is saved because I myself created this directory language we are going to use cotland today yes not Java cotlin because we know the reason reasons I mean uh it's I have been teaching you these reasons only since the last three lectures I won't repeat it again this is the minimum SDK I'm leaving it as it is and let's now click on finish so once you click on finish so it will take some time to prepare the project for me it takes less time because the storage the internet is good depending upon how your Hardware is how your laptop is and how is the internet speed it can take 1 2 3 minutes but usually it is fast you can see here I mean in the backgrounds many things happen a lot many gridle bills a lot many processes so if you are seeing this software for the first time if yes first of all go and let me know in the comment section below that yes you are seeing this software for the first time and I can completely relate with you if you are a firsttime if you are first time I'm opening this software Android Studio it will be very very confusing for you to understand which component is where what feature is where a lot many things are provided here you know so many icons are given so many options are on this side everywhere so many features are there so let's do one thing leave everything on me don't take tension I'll explain you each and everything very clearly just keep looking at the cursor of my mouse okay I'll make everything super duper simple for you so right now you can see we have two files open here I'll close them for now okay I'll close them for now and now if you look at the left side at the top left this is the right side right and this is the top left so here you can see multiple options are given to us right right now I'm in the Android section okay and I have two main directories here one is the app directory the other is PR scripts directory all right if I open up the app directory I can see there are three more directories what they are so these three are very very important let me tell you in manifest in manifest you will have Android manifest.xml file so basically all the important information like the icon of the application so if you use some software or some application in your Android phone so you would have seen they have a bit of you know a stylish kind of Icon like zato has its own unique icon and sometimes during sale season they change the icon as well they change it to show the sale word or something like that so in manifest directory you will get to see the icon you can change the name of the app from there and you would have seen if you have installed a new application and Android application so you would have seen many times they ask the user for some options like uh you know do you want to give location permission do you want to give Gallery permission this permission that permission so all those things all those things are added in this file that is your Android manifest file how will you add user location let's say in my application I'm using uh location or maybe internet so uh I ask the user if they can provide me with such a specific you know uh permissions so I can ask you user for camera permission right uses permission and then camera permission apart from that this is your application tag and inside you have multiple stuff you can see I icon label and then depending upon how many screens are there in your mobile application we will have them here this is one Activity one activity means one screen one screen okay uh if I create another screen like let's say on clicking a button I want to go to another screen then I will create one more activity I mean it by default it is created and you don't have to do anything this is the name of the activity main activity and then there are some intent filter so this intent filter says that this is the launcher activity that is this activity will open up the first it will be the first to open up whenever you click on the logo of the app okay if I'll keep this intent filter in any other activity then that will become the first activity to open up perfect so I hope the first directory is clear to you in the app we have three directories manifest is clear to you what how it's so significant why it's so significant Right Moving ahead we have the Java directory now so in the Java directory as the name is a bit self-explanatory all the code part everything related to code the logic will come in this directory inside Java also you can see you have multiple directories right this is the name of the package com. example. first app if you remember first app is the name of your project name of your application so this is your first directory then they have Android test directory then test directory other so basically inside this Java directory the first and the most important one is this one which you see at the top inside this you can see right now we have main activity in the same way if you click on right button right Mouse button you will see you can create more activities here like new cotland class new Java class you can go on about creating new activity in this directory as well perfect so let's now do one thing you now know that okay Java is for the logic part for the code part and inside this first directory you can keep on adding multiple Java files Scotland classes Etc I mean all the new screens uh the logic of all the new screens will come in this particular subd directory and now if we talk about the resource directory so here as well you will see so many options drawable is basically for keeping stuff for keeping your pictures uh values designs all those files let's say if in my application I want to put images multiple images and I want to use those images maybe as icons or something like that then all those stuff will come here in the drawable directory after drawable directory you have the layout subd directory in the layout all the design part will come here so right now you can see you have activity main.xml which says hello world right so in the same way as we will go on creating more and more designs in our application like you would have seen multiple screens while using any application if I take the example of maybe Spotify itself so the very first is the splash screen activity and then they have the main page main activity where they have bottom navigation bottom navigation multiple options are there like search icon if you click on search button then a new page new screen is opened up so that way I mean all the design screen will come here in the layout subdirectory okay right now only one is here I can go on and I can keep on creating more layout resource file in this okay perfect so in the resource you know dyable where we keep icons pictures Etc layout all the design all the XML files will be inside layout directory and then you have a MIP map you can see I'm in the logos that we are using right now default logo is this so different ratio different pixel expect ratio all those stuff are added here so I'll close it MIP map and then values in this you have colors.xml strings.xml so what happens is let's say in your application in your design you are somewhere using the app name right so instead of writing the app name every time if you if there are some values which you feel will be used multiple types then you can just put it here and you can call this name and the value will be here this is key and value if you know key value pair so this is kind of the name and the value is this okay so I can just use this thing and whenever let's say if I right now the name is first app and later on if I want to change the name to my first app maybe so if let's say the name of the app is used multiple times in the logic part then then I won't need to go on and change everywhere my first app if I if let's say I'm using App name only app name only this keyword then whatever change I'll make here it will reflect it itself right I hope you got the point that I I not supposed to change the name everywhere I can just use the keyword this and if I make the change here it will be ref reflected everywhere wherever I'm using this particular keyword right I'm closing strings.xml now and this is your colors.xml the kind of same story uh you can't and you are not supposed to remember all the hexade decimal codes right whatever is the hexa code for purple blue red as a software Engineers as a developer Android application developer obviously no one expects you to know all these codes right so this colors.xml is here you can add all the colors which you want to add which you want to use in your application and then you can directly pick it up from here with the name so this is same as a string.xml this is the name and this is the value key and value and once you use the name you won't need to write the value everywhere right perfect let's close this as well this is the theme and you have one more XL this is not much this is not very important closing the values directory now after values XML not of much use so right now till now you have uh studied what is Manifest right inside that we have this file very important it contain all the user permission activity details icon everything logic part in Java directory in resource mostly design stuff specifically in layout the the XML part will will come the design part will come drawable pictures images Etc and after that let's now see what's here in Gradle scripts in the Gradle scripts all the important dependencies all the details about which dependency you are using in your app will come for an example like if you open the build. gdle this one so it contain all the plugins that you are using in your application okay for now you don't have much to do with this but and it's important in for your application and this is again another bill. crle uh module uh for module that was for project right so here if you see all the important information like what is the target minimum SDK what is the version name version code and so on and here is the list of dependencies that you are using in your application let's say you want to uh you want to you know use some third party library to beautify your application to make it look more aesthetic to make it look more beautiful simple clean then in those cases you can add here your own dependency you can add implementation and whatever the name of the dependency is you can search for the such dependencies on the internet like if you want to add onboarding a screen some tutorial kind of a stuff for your application you can uh use such dependencies okay let's now close it it and after that some more files are there I'll not uh talk about many of those uh you know which are not of that that much use in the beginning in the starting otherwise you will get overwhelming that will become confusing for you right now the knowledge that you have about these whatever we have in the app directory in the gr scripts that's more than enough you have a basic idea of which directory which file is used for which purpose right and in the same way uh if you see here this these options right so this is your make project button if you want to you know run your application then you can use uh one second you can I you can either use emulator or you can use phone as well your Android phone right so if you want to add emulator right now I have pixel and Nexus these two available devices these two emulators if you want to add more then you have to go in device manager and you can see option create device here right if you click on create device so this will create a virtual device emulator is basically same as your phone it looks like your phone but it will run here in Android studio and if you have less Ram in your laptop like uh maybe less than 4 GB then I would recommend not running emulator because that will slow down or that will hamper your development experience while using Android studio okay and uh yes you can choose whatever phone you want to choose here pixel uh you have uh NEX so many options are here you you have to click on it whatever you want and then click on next after that you have to choose a system design you have to download it and then next and finally finish will be there okay so I'm clicking on cancel because I don't want a new device right now I'm happy with these two okay I'm closing this and here this this is the Run button and clicking this you will run your application so for now these are good enough I mean apart from this you have multiple other option like if you want to debug your application uh you want to run your application with cover coverage or I mean these are kind of repetitive options again I'll teach you I mean in other lectures how to debug application how to add debugger coverage etc for now you don't need to worry so much about that this is sync your project with cradle files device manager and so on and in the at the bottom also you can see multiple options are avilable Version Control for git for people who are working with their team G is obviously very important so this is for that and uh the most important thing here is this log cat so if you run your application and you see it is crashing so you can see the log report everything all the details here with the help of the lock cat okay perfect right now I'm closing it and um yes uh you should know how to read lock at that's very important once again so if I go ahead in my Java folder this is my main activity right so it is saying real files have changed sink now let's sync now all right sync is done so you can can see now this run button is enabled as well so if I without doing any changes without making any changes let's see what is in the main activity so it it is hello world right so without doing anything after creating a new empty project a new empty project if you click on the Run button it will run whatever it has that is it will show you this thing in your screen right your screen so once again this is your design part let me show you what all is here so basically uh this is your XML part this entire code is written in XML okay like we have multiple components we have uh views each thing like button text view image these are views right so we will add all these design components in our application to make it look beautiful there are layouts uh whenever you have to design your screen so you have multiple layouts like constraint layout is there frame layout or you have linear layout relative layout lot many layouts are there they have depending upon use case uh you can use either of them okay so inside the inside the constraint layout right now you have one text View and that text view is having the text hello world you can see the text here so if you see the uh just look at the cursor of my mouse so you can see here at the right top there are three option code if I click on code only the XML part will be there split I can see the design as well as XML part and if I click on design just design so I will have the design you can drag and drop stuff as well from there right but now I don't want a button so I left it there and here as well you can see multiple options are available these are for tracking and dropping the design components directly into your screen if you want or if you prefer uh doing the code here writing the code here and then looking how the changes are happening in your uh you know in your screen and you can use the exml part as well both are good both are simple for the first time obviously it will be a bit confusing it will be a bit difficult for you but over time with time it will all become very simple you'll get used to see this software it's it's very obvious I mean uh when we were in the first standard in Nursery then even ABCD was so difficult for us right but now it seems so easy I mean a b c d we know how to go about it right my nephew is in Nursery he finds all these things so difficult I mean uh he's having trouble learning a for apple all those stuff so it's the same story I mean uh with time once you will know what this software is how uh these features work then it will become very easy for you as well okay in the beginning it looks difficult I completely understand because the software is a bit overwhelming I mean there are so many options here that it's obvious for anyone to get confused if I click on run button here it will use this Emulator Nexus 5x API 31 very old very old uh uh looking uh you know phone is this is this is very old looking phone but yes let's see I mean if our application is working fine or not so you can see here at the bottom some background tasks are going on some grle bills are running and once it will be completed then I'll get to see my project my application here on the emulator it takes some time to perform the tasks like radle bills are running right now in the background and you can see they are now launching the app okay install is success suful finished in one second and yes this is your hello world application so congratulations you just ran your hello world application so if you have installed Android Studio if you have got a basic idea of what Android Studio is you now know that which directory is used for which purpose if these many things are clear and you are done running your hello World application go ahead in the comment section and let me know that you are done till this point and till this point if there are any doubts any concerns in your mind about this software about Android app development let me know and I'll try to answer it I'll myself check the comment section and answer it okay so I'm minimizing this one and now what's coming in my mind is now that you have a basic idea of what the software is how how the software works so let's use the knowledge and uh build something interesting right you just build hello world application right so how about building something new I mean uh something simple and creative uh with the help of which you will get the knowledge of few extra important topics as well in Android development so let me do a screencast and share my thoughts with you what I'm planning so I'm thinking to help you build your application your Android application in which we learn some important Concepts um starting concepts of Android development as well so what I'll do is I'll create an application okay I'll create an application I will add two buttons here I will add two buttons here okay one will be cool the other button will be hot so when I click on cool the background color of this screen will become blue when I'll click on the hot button then the uh background color of this app should become red okay makes sense uh red or maybe black whatever you feel better red or black okay and after that what I will do is I'll have uh another button okay I'll have another button because that will help you understand one more significant concept so if it'll be left with time in this lecture then I will add one more button and on clicking this button it will show the text next and once I'll click on this button then I will be directed to a new screen and this is one of the most significant one of the most important learning for you in your Android app development Journey if you're writing the code in cotlin or even even in Java so you it's very important in Android application development how to move from one screen to the other screen very significant okay so you will understand that as well so first let's try to create this much and after that if we'll be left with time then I'll show you this part as well otherwise this will be covered in the next lecture perfect okay so let's get back to Android studio and here you can see this is the small piece of code that we have right so this is the class main activity name of your class and this is extending app compact activity you studed inheritance as well right so app compact activity if you click on this this is uh inbuilt class uh this is already there are in the studio they have multiple methods they have multiple stuff here in this class I'm closing it now so I'm extending this class and you if you notice this is main activity. KD it is cotland class but it is extending app compa activity which is dot which is dot Java it is a Java class right so you can see the beauty of the compatibility between cot and Java they are literally like best friends right so this is your first line class main activity and which is extending app compat activity your class begins here your class begins here this is the opening B braces this is the closing braces and after that you are overriding a function obviously you are overriding from this method on from this class only which is your parent class you are overriding on create method fun you already know the syntax I mean I don't need to go deep into the syntax fun means this is function name of the function is on create inside this you are passing a parameter the parameter is of type bundle like you have flow double int name of the parameter is saved instance State and then you have the opening and the closing braces again all right this is super do oncreate super Doon create basically you are using the super keyword to call the Constructor of uh that particular method right and then the most important thing is the set content View and r. layout. activity main here so basically what's happening here you are telling that hey main activity hey you class I am attaching you with a layout okay so whatever logic I'll write here in your class that should be linked with activity main.xml this will be your design part and I will be the logic okay set content view I mean you are setting the view for the content that is r. layout. activity main okay perfect and one more quick thing is whenever you open up your application whenever you run your application so the first method the first method that is called is the oncreate method always remember this whenever you run your application the first method to open up the first method to be called is the on create method and after that you have on start on whatever however the flow is multiple methods are they like on pause on resume on Destroy and so much more right the life cycle of Android application is very very important concept very important in terms of theory as well if you're going to give interview for software engineering role for let's say Android team of any company then obviously you must know the life cycle of an Android application that's very important okay awesome and these are some packages here which we have imported and as of now like whatever you are using the app compare activity is imported bundle is important this is app compat activity this is the bundle the type of this parameter all right so now what I will do is I will write some code here before that I want to create a stuff in this design right first obviously I'll design and then I'll write Logic for that particular design so I'm going to remove this text view okay and this is your constraint layout I will change it to linear layout because that is easy especially while teaching because in constraint layout you have to spend a lot of time in constraining the views like if you have a button you will spend time in putting it in the right position dragging dropping Etc so I'm using linear layout here and linear layout should be in the vertical orientation not not in the horizontal orientation so orientation vertical okay perfect after that after that what I have to do is I will drag a button here drag and drop a button here and this is the button two that's it for now so this is the button one which says cool okay and this is the button which says hot so here in every view you will see one ID parameter okay you will see one ID option right so what basically this ID is um it is a unique name for that particular view like you have a unique name of yours I have my unique name somia is my name right uh everyone has a unique name your friends your relatives everyone call you by that name right in school as well you are given a specific unique role number R number 1 2 23 29 39 and so on so in the same way in the same way this is the ID and every view has its own ID why this is so important because I will call these views if let's say I have to say on clicking this button I want to perform this action then I should know the name of the view right name is BTN cool okay so on clicking BTN cool I want the background of this to be changed to blue color right so I'll write that code with the help of this ID only and this is BTN hot this is Ban hot oops perfect and uh after that I want to change a bit of its look I don't want it to be at the top so gravity Center whoops layout gravity center after that I I want to give it some margin top 100 DP or even more 250 DP okay A bit better and this is the width and the height uh this is again very important like match print and wrap content are the two most significant values for width and height so width means with if width is Mage parent that means it will occupy all the space available if I change the WID to wrap content it will only occupy the space which it wants I mean cool only needs this much off a space if I change it to let's say cool something like this it will expand accordingly right so basically wrap content is something which will take only that much amount of a space in which it is fine to show the data right Mage print it will take all the space available okay and I can give it a fixed value as well I can make the width let's say 200 DP fixed value like this right I can change the uh I in the same way I'll do the same thing with this as well so that consistency is maintained right width is 200 DP okay it is not reflecting the change we want we need to change the gravity as well for that one second okay cool so this is cool button this is hot button you can uh give some spacing as well between them you can put some padding more margin all of this stuff there are so many interesting things when we talk about Android development I mean it itself uh it is in itself a very detailed and very you know vast topic design in Android development contains so many things I mean you can create designs you can be a pro and use Photoshop Etc as well while using XML so yes I have worked with sever startups as well for their Android projects done freelancing as well so I know I mean it's it's quite it's very fun to do this stuff uh creating design using Photoshop using a lot many platforms are there which assist you in creating beautiful designs right so for now I want only these stuff in my application I'll come here in the main activity now the very first thing is I want to find where my activity is so there are two things either you can use find view by ID or you can use the binding concept both are good uh modern and fancy uh is The Binding thing which is specifically for cotlin developers right but another way is generic ways you can create a variable okay V or we can keep Val as well because we don't want to change it right so Val button hot okay whoops button hot is equal to I want to find the button where the button is so find the view by its ID and this is a button and then r. ID do BN hot okay and then Val whoops Val button cool is equal to find view by ID this is also again a button and then r. ID r. id. BTN cool okay perfect this mat is done now what I have to do is it is showing some error it is saying that uh the activity main does not contain the ID button H but we know it does contain if you if we do click on this it is directing me to it so once you'll run it it will be fine I mean it takes some time to process this it's completely okay okay it will not throw any error button hot dot set on click list now basically when I click on this button I want to perform some action so button hot do set on click list now in the same way button cool do set on click list now so on clicking these I want some oper some you know something to be done some action to be performed so on clicking button hot I want I want to change the background color I want to change the background color of the whoops of the app to Blue okay and uh again on clicking uh the hot uh okay on clicking button hot I want to change it to Black oops and uh I want the background color to become blue when I click on button code okay so let's write the logic for this when button H is clicked uh button H do set on click listener I have to change the background color right for that we have a specific method set set background color but but we can't directly use that method I mean we have to tell on which view do we want to apply that particular method like button H do set background color I can change the background color of my button using this right now I want the background color of this whole screen to be changed that is this complete layout right button is only in this much area this linear layout is occupying the whole area right so I'll give it an ID ID linear layout okay linear layout and after that I'll come here I'll Cate create a variable for this as well linear layout is equal to find view by ID this is my linear layout and then r. ID r. id. linear layout okay perfect so now I will say linear layout I want to change your color I want to set your background color to something as specific to pick the background color either I can either I have to remember the hash the code kind of thing or I can use the r do color dot uh whatever color I want to use for this I want to use black right uh so I have that was the purpose of this resource then values then colors.xml file you don't have to remember all the codes you can just directly use them okay and then again linear layout do set background color set background color and here I want to give R do color dot so on clicking button cool I wanted to change to Blue right I want to change it to Blue they have multiple options here I don't know which is correct which is not so I'll click on the Run button okay the app ran successfully if I click on button hot so it is changing its color to this okay it is changing the color to this and if I click on cool it is changing it to Blue okay looks good and if in case you want to hide this uh action bar you can do that as well support action bar do height and if we redun this so now it shouldn't show you can see it is not showing me the action bar support action bar do hiide okay cool and hot okay if you want to change if you want to change or use other color you can do that it takes some time to pick these and now you can see the the r. ID these errors are gone in the same way these will be gone it takes some time to process to understand that where are these uh you know layout files or where these IDs or colors are located okay so yes with this you created your second application after hello world right you added a bit of logic here and there and you Chang the color as well so I'll see you in the next lecture where we will do a bit of more Advanced things around Android application development I'll teach you more advanced stuff this is very basic and we are on top of the hour for this lecture so in the next one we'll see you again and we'll create some amazing applications and until then uh show it on the internet whatever you have created tag me tag scaler tell us what you are learning and we will be happy to help you always if you have doubts queries anything around the these topics drop them in the comment and I'll check the comment myself and will try to answer as many questions as I can we will see how we can use this language cotlin language to create projects how will we write code for you know some real world kind of applications and projects using cotlin see the so the idea so the idea in my mind is to create a travel kind of application travel app so basically the thing is I am from Delhi and being a delight a proud Delight I would say I would love to show you all the top places to visit in the capital of India using an application so it will be very much like u a gallery kind of application you can see a dynamic photo application photo frame application so what I will do is we'll have name of the app or title something like that here a text view here okay this will be your text view text View and apart from that I will have pictures here pictures of the top places to visit okay uh which will be changed dynamically uh like we'll have some button uh picture as well as here we will have text to explain a bit about the place or maybe just the name of the place okay so this will be the place the we can show maybe top five or top three places to visit in the capital of India and then here the name of the place okay and after that after that I will have two image buttons image buttons are also views okay so they have some icon associated with them so here I will have two image buttons two image buttons one that will ask me to uh you know go ahead I mean click on next so when I click on next the image two then three four like that will be shown okay and this will be the previous button when I'll click on the previous button then I expect my code to work in a way that it shows me the previous image okay so let's say if I have 0 1 2 3 4 like five top places images right so on clicking if let's say current image is one current image is this one when I click on next I want to go on two when I click on previous I want to go on zero if I'm at three then on clicking next four should be shown on clicking previous two should be shown if I at zero this is very interesting case if I'm at zero on clicking next one will be one will be shown and on clicking previous button I want it to show four okay I want it to behave like a circle in the same way for four as well if previous will be clicked if if previous button is clicked I want three third image this image to be shown and if next is clicked I I will not say like no image was present I will then show the image number zero okay sounds good I hope this much part is clear so this is the plan in my mind I want to create an application like this which is like a travel photo app you can say travel photo app which changes picture dynamically on clicking on button Etc perfect so let's write the code this will be more about I would say logic and less about design Etc like design will be also there but you need to understand the Core Concepts which I will be teaching today they are very significant so let's create the project and write the code in cotland okay so let me keep the iPad here and um let's go on so new project okay after new project I want empty activ activity only empty activity and here we will write the name of the project okay I can call it travel travel photo app travel photo app okay and then this is the package name save look I won't change anything and this is Scotland click on finish and it will quickly prepare the stuff for you it will prepare a default main activity for you main activity KT activity main.xml and here you can see at the bottom some downloads were happening and that's done so I'll close this and now what I will do is let's first create the design okay so I'll go in activity main.xml and here I see that right now I have a constraint layout inside which I have a text view right so my aim is my aim is to create a simple image photo album kind of thing right travel photo app so here I will change the layout to linear layout first and then I will have orientation vertical or orientation vertical the very first thing I want is one text view here okay and in this text view I'll write travel D travel photo app or something like that travel photos app travel photos app okay and you can put some styling here not some a lot many stuff text style you can make it bold you can increase the size of the text right now it's so so small that it's not even uh readable right text size I want it to be 25 DP okay and uh I want to change the gravity as well gravity as Center perfect and let's give a margin of 3dp okay so that some breathing space is available for it okay travel photos app and after that what I will do is I will create one I'll pick one constraint layout okay constraint layout will be in the layout section so constraint layout drag and drop and inside this inside this I will put one image view so this is the image view I'll put it here I want to collect the images right I want to show the images of the places so one second let me let me copy and paste the images into my drawable so my drawable folder how can you open the drawable folder so if you click on Project here resources and drawable so here you if you write click and um open in finder so this is my drawable I will paste all the images here pick zero pick one pick two pick three and P four okay so this is of India Gate this is K Minar it seems Lotus Temple red f and okay this is Lotus Temple and this one is uh I guess actra Temple so we'll see it zoomed as well in the application okay so on previous and next I want different images with different names to be shown right what can we do is let's again pick image View and now I want to show pick zero first okay this is the pick zero I will constraint it in a good manner in the right way so like this and this one should be attached here and this one should the bottom should be constrain there perfect now what I will do is I want to I want to give a specific width and height to my constraint layout okay right now it is taking too much SP or what can I do is I can create the buttons I can create the buttons in linear layout in a linear layout okay so I want to keep those two image buttons and horizontal linear layout okay for that what I will do is I'll go in layouts and linear layout horizontal I'll put this here at the bottom okay I don't want to want it to be inside the constraint layout so I'll undo this action and I'll put this in here but but it should not be at the top it should be at the bottom right it should be at the bottom here cool and inside this I want two image buttons okay and uh let's give it a fixed height okay maybe 300 DP looks okayish or maybe you can do 350 DP all right and then after this I'll go again in the design section this is my linear layout horizontal and I will drag and drop two image buttons here image button let's search for it image button image button one so in this I will show the next Arrow okay next and previous so we have multiple options here this is there okay and then I want another image button and I want to show here previous for previous they are showing this I want double back back arrows okay so uh this is this is forward button right this is the one I want I guess perhaps yes okay cool so I think we swapped it all right it should be in on this side on right left we we'll change it okay and after that at the end what I'll do is this is your linear layout it should not be match parent it should be WRA inent this should be in the opposite order this and then this perfect this is your BTN next okay and this is your BTN button this is your BTN previous okay BTN previous and BTN next all right right and last but not the least we want a text View at the bottom this text view is again very important it will tell us the name of the place tv text view name of the place I'll try to pick the same styling as we had for this okay text maybe I want to make it 20 DP only and margin 10 DP cool and here this is India Gate so I will write India Gate awesome so I think we are good what else you can do is you can maybe uh put a background for this text view dark colorish kind of color something like that to make it look better okay background if we say black then text color we'll need to change to White you can give some you know Corner radius all those stuff as well that is usually uh an attribute for image uh for buttons normal buttons but here also you can create I mean you and create an extra XML for that okay cool so if I run this much I think it should look good it should look the way we want it to look and after that we will jump to the logic part okay so let's run it and see if this much part is working fine or not and then we will come in the main activity and write the code here so it is running La succeeded and woohoo it's it's looking good and now we have to write the logic if we click on on next then next button should be visible uh sorry next image should be visible if we click on previous then last travel image should be visible right okay so let's get into the logic part now so the very first thing I want a variable a variable which tells me that which image are we on so what I'll do is not well I'll create well current image current image is equal to zero so in the beginning I'll assume that I'm at the zeroth image and depending upon on which button we are clicking next previous blah blah we'll keep on changing it okay we'll keep on changing it now let's come here and we know that we have to perform some action on clicking previous and next button so let's create them quickly uh Val next Val next is equal to find view by ID this is your image button right so write image button then r. ID dot BTN next this then Val previous is equal to find view by ID this is also your image button right so create image button here and then r dot if you see here do command P you will see this is a integer type so let me tell you this is very important so all the images or maybe all the views like this is your text view this is your image view button or like whatever this these are so each and every thing here they have their unique name we know like this is your pick zero okay this is your pick zero so they have their unique ID they have their unique name apart from that when we do this right when we do this so r. ID do button next this is an integer address that is associated with that particular ID with that particular ID with each ID like pick zero I'll try to show pick one as well pick four five or maybe if you look at this this is B previous B next so each and every ID has its own address with the help of which it understands and that address is an integer format this is that is an integer format r. ID do previous okay BTN previous sounds good this much part is clear now on clicking next do set on click listener I want to perform some action I want to get the I want to get the next image I want to get the next image and in the same way when previous is clicked uh previous do set on click listen now I want to see the I want to see the previous image now it is all going to be very very interesting if you are is scared of logic mathematics don't be I'll make it all super simple okay uh you just have to think smartly and I explain everything how can we go on the next image and all those are stuff so if you notice in our drawable folder in our one second where is the drawable folder so in our drawable folder the names of these pictures it is like Pi Z pick one pick two pick three pick four like that okay so right now in the beginning of the program uh the current image value is zero sounds good what I'll do is I'll here I'll here get the ID of the current image okay I'll get the ID of our current image to get the ID of the current image what we will do we know the IDS are like Pi zero pick 1 pi two something like that right so I will create a variable where ID of the current image ID current image and this is obviously the string value like pick zero pick one this is not the integer address associated with that particular design component like we know that each and every component has ID their unique name like button pre B BTN preve BTN X right this is the string ID this is their unique name but this this is not integer address right so this is ID of the current image in a string format so it is pick and along with that the current image whatever the value is that will be there right so they are saying it you can shorten it as well you can put it in yes they are saying that you can shorten it you can put it in a stylish modern way as well you can use the dollar sign so if you click here convert a string concatenation to template basically they will put everything in uh double quotes and use a dollar sign okay so convert a string into this format basically they removed the extra code and this is uh what cotlin is about dollar sign is one of the stylish and modern syntaxes okay so this is the ID of the current image okay uh it can be pick zero pick one one more thing here which is very important is I have other uh image views as well right so I'll quickly make three or four more this will be pick one and here I will show pick one okay but what I will do is you would be thinking I mean why why there is so much of weirdness I mean you can see like all the image uh images are overlapping on each other right so for this what I'll do is I will first of all concentrate it in the right way okay make it look good and uh I'll put Alpha zero for all the other pics pick 1 2 3 4 all the p if I'll write Alpha as zero then you will see the image is gone right so Alpha is very significant attribute you must always remember this so in the same way I'll create more but before that let me see if we can do something about its orientation so for pick one let me make it look better okay because obviously I picked images I grabbed the images from the web from the inter internet and they were all from different websites so the dimensions everything is a bit distorted let's make it look good okay my focus right now is not on the design part but on the logic part but indeed I mean when you will work in startups for uh clients obviously everything will matter right so Alpha as Z Alpha zero and I'll again put pick three and this was pick one right so this should be pick two okay this is a bit better okay and Alpha for this one should also be zero right in the same way I'll do I'll repeat the same thing for all other images pick three and pick four as well this is your pick three and uh this also looks good all right and Alpha should be zero awesome and the last one that is the one with the ID pick four pick okay pick four and here as well pick four and Alpha should be Alpha should be zero now let's come back here when I click on next the very first thing I did is I grabbed I grabbed the uh id id in the string format like if the ID is pick zero pick one pick two like that so I grabbed all the IDS and after that what I want is I want to I have to get I have to get the integer address integer address associated assoc associated with each each design component with each view you can say okay with each view I want to get the integer address whatever is associated with them so I'll create where ID current image ID of current image but not in a string format I don't want pick zero pick one all those stuff I want integer value okay so that I can perform The Logical operations on top of them right so I will first of all get this I mean the context of this screen this activity after that this dot get resources get resources dot uh like if you see here instead of writing get resources completely if you see the first one it is saying resources but it will help us in getting all the resources right so get resources dot get identifier I can get the integer address with this as well with this as well but we have to do everything programmatically logically here why because I mean I I can't go on hardcoding things I can't be like find view by ID pick zero then pick one pick two no no we can't do it that way right based on the value of the current image we have to find the integer address Associated if it is pick zero then get me the address using the value of the current image I can't be like find view by ID and then I will pass the r. ID dot I can't hardcode it I have to do things programmatically right because next will be clicked I am not sure which will be the current image what will be next what will be previous right now I only have five uh five images but might be I I will have 100 images th images and so on right so I got the ID in this string format very easily pick 0 1 2 whatever and then I have to convert the same ID into integer format that's it you don't have to think too much you don't have to think too much you have got the string ID you have to get its corresponding integer address so for that this is the simple oneliner syntax you don't have to worry too much okay resources dot get identifier and here if you see you have to give three parameters you have to pass three parameters to it right what those parameters are so the very first thing you have to give the string ID okay which you are getting here okay this after that they are asking you for def type they are asking you for de type so you are playing with IDs right so the def type is ID here de type is ID and after ID what they are asking for is they are asking for the package name so you can get package name using the method get package okay get package so if you write uh package name so the second one the second one will help you get the package name okay so get package name like this perfect that's it I mean that's the that's all you have to do so easy and simple to convert the ID uh which you had in a string format into integer into integer now why I'm doing so much I mean there would be some reason right might be I want to use this integer address somewhere right I'll tell you where so now what I want to do is I want to get the actual image I want to get the actual image and make it invisible I want to get the current image and make it invisible set it Alpha to zero that's why I'm doing so much of a struggle right first I got the ID in a string format pick zero pick one whatever the value would be and then I'm converting the same ID into integer address into integer format so that I get its actual value where it is is after that I will so one more thing that I have to do is I have to create one um image uh image variable which will be of Type image button image button okay I'll tell you uh what's the use of that so while image uh of Type image button of Type image button and because I don't want to declare I want I don't want to initialize it right now so I will use late n whereare okay and now here I want to get the image I want to know what the image is so find view by ID and here I will pass the integer address this also gives me the integer address this also will give me the integer address obviously I don't know the ID I will not be knowing the ID like I can't write r. ID dop Z here right it will not work for it's not the best logic to write I mean this way I'm hardcoding things but here the value can be anything it can be pick zero pick one pick two so I'll get the integer associated with that respective ID and then I will pass the ID current uh ID of the current image and it's integer address so basically I've got the image now let's say uh for an example if if you go here okay if you go here if I am at this picture which is of aadam I got the very first thing I'm doing in the program is I'm getting its ID right which is p two P two and then I'm converting that into integer address associated with this image I got the integer address of that then I'm saying find this view by ID right and I'm passing the integer value which it wants so I'll exactly get this image and now what I want to do is I want to uh I want to make it I want to make it invisible right zero set it to zero it is expecting float value I guess yes so WR F that's it that's all you have to do and because I clicked on next image so I want to see pick three right which is of uh red f I guess so for that what you will do is it's so simple it's so simple you have to repeat things like current whatever the value of current image was you want the next image right so current image is equal to current image + one + one after that you have to repeat all these things you have to repeat all these things I mean the very first thing you will do is you will get the ID this is number right and this is right now only three if let's say I was in second image so current image value was two so I'll do current image is equal to current image plus one so three is the value right now I want to get pick three so where ID of uh this is image I want to show image to show uh and a string ID okay a string ID I want it to be like pick three pick three right so how will I do that I'll do it in the same way as I did here that's it yes I'll say pick plus the value of current image current image I incremented it right I incremented it perfect and all of the everything will be same I mean then I want to convert this string into integer right I want to convert this let's do it let's do it so ID current image ID of not the current image it is ID of image to show image to show and this is its integer address right and this is the ID of image to show a string then uh image is is equal to find view by ID and I want to get the ID of this image image which I want to show I want to set it to uh one because I want when I click on next so the current image should become invisible that's why I did zero zero Alpha and the next image for the next image I want it to be visible I want it to be visible so I set its Alpha to one that's it that's all youu have to do it's as simple as it looks go through the code once again you will understand it in even better manner uh we can make it private as well basically what I'm doing is uh when I click on next do set on click list when I click on the next button I want to see the next image so I am setting the current image Alpha to zero and I am making the next image Alpha to one for that I'm doing a lot of a struggle I am first of all getting the idid of the current image pick and whatever the value is after that I'm getting the iner address associated with that particular ID okay and then I'm passing that ID in find a view by ID method so that I can get that image and then I will set the image Alpha to zero perfect and I want to get the next image so I will say current image is equal to current image + one but if let's say I am at image number four current image value is 4 so 4 is equal to 4 + 1 that will be five and I don't have image five so what you have to do a very simple mathematic trick a very simple mathematic trick whatever is the total number of image right now it is five so you just have to add that 5+ oh sorry 5 + and you have to do modulus with same so if you set and do calculate you will find that after four if I do addition here I will again get zero only I will again get zero only that's a trick I mean to handle the corner case to handle the uh you know the significant the tricky case after that for previous as well I'll do the same thing and the code will be exactly same it's just that here instead of plus I will show minus right so let me copy and paste this much piece of code and and one more more thing I have to do is I will write here minus because if I am at uh I want previous image right so after current image if the current image is two I want one to be shown so current image 2 minus one so let's run it and see if it's working if this much piece of code is working fine or not so this will be a good opportunity for you to understand how do we check lock cat how do we check the errors okay so this is our lock cat and and the uh it is failing at this point at mean activity dok this one okay it is saying that uh app compar image view cannot be cast to image button okay this was not image button actually that's true because obviously these are image views right these are image views I casted it to image button that's that's my bad okay and if I rerun it it should work fine let's run it it failed at 24th line right I guess this one should work fine now H so when I'm clicking on next I'm getting the next next images see after so this is the magic after Lotus Temple basically uh this is the last one after Lotus Temple I want to see India Gate only so if I click on next I'm seeing India Gate right after R after this is K man right after kutub Minar I want to see this picture this picture which is of fure dam Temple so yes this is the one now everything is working fine everything is working perfectly do create your own travel photos app but but let me tell you one more thing quickly right now it is hardcoded it is not showing me the new text right new text so what should we do for that I mean pause the video think for a while then I'll tell you now that this much part is working fine we are dynamically able to change the images on clicking next we are seeing the next picture and clicking previous we are seeing the previous image right so the code of next button and previous button is working fine we are getting the current image we are making it invisible and we are then showing the next image we are making the alpha of the next uh image like if we are at pick zero then we are making the pick zero as Alpha 0 and pick one as alpha 1 we are making it visible right this is the logic we are using right now and I also want to change the name of the place in real time right so uh if you were able to think of some logic paste the code paste the logic in the comment section and yes it will be awesome to check all those replies all those Solutions if you were not able to think of a logic for changing the names real time in real time then let me tell you how can we go about it okay the very first thing I will do is I will create uh I'll create an array you already learned in my lecture two or three how to create arrays in cotland right so where uh names or I can say where places I'll create array of array of array of all the places so the places are pig zero is India Gate right so India Gate then pick one is pick one is k manard k Menard right and then pick pick uh two is aution D Temple so this is one of my favorites Temple I mean when I was in school as well I used to so much visit aadam as well as berla Mand Temple and these are so so good and then this is your red for temple not not Temple sorry red for only yeah uh red for only right one second let me zo it yes red f and then the last one is Lotus Temple okay so this one is your Lotus Temple perfect so I created an array I created an array that contains the name uh sequence wise I mean uh pick zero uh is of India Gate then kutub Minar pick one pick two it is matching with the IDS as well I mean picture name this is picture name this is not ID don't get confused this is name of the picture but if you go here and see so if you go here and see so pick four the ID is same as the uh name of the image okay if this is P 3. jpag or P 3.png then the ID is the same right so once again we are back here and what we have to do is as we are clicking on previous or next button the image is getting changed our logic is working perfectly fine but I want to change the name of the place as well so for that what I will do is it's very simple and easy to understand this much part is crisp and clear we got the details of the current image we got its ID we got its integer address we got the actual current image and then we set the alpha to zero right perfect and after that what we are doing is we are doing the same thing but we are let's say it's next do set on click list now so right now if let's say we were on pick zero so I increased its value to pick one I did current image + one + one this 5 plus and modulus 5 is just to take care of the corner case just to take care that if we are at the last image let's say 4 it shouldn't go to Five 4 + 1 it should come back to zero it should come back to zero and for that for handling that case I'm I'm just adding this 5 plus and modulus 5 basically you can you have to add and uh modulus do modulus 5 with the total images that you have that will handle your case okay all right so I incremented the value of the current image and then I'm doing the same thing again I'm finding the ID and you can write it in a smart way so you are finding the ID of the image to be shown and then you are finding the integer address associated with that image to be shown and then you are finding the actual image that you want to show and then you are setting it Alpha to one that is you are making it visible okay and now now what I have to do is I have to show the actual the Right image write name as well so for name as well I should first create the variable right text is equal to place name place name is equal to find view by ID and this is of type text view right text view so I will pass here r. ID do text text view I don't know what the ID name is so if you go here it is TV name it is TV name so TV name perfect I now I now have the uh actual text view the address right so I will do place name place name dot do set text so the very first one get text from get text set text so set text is equal to I have the array right places places and I will pass here the value the value which I want to show uh right so basically I will pass this because I have the exact value if let's say I was on pick one I made it invisible now uh I'm clicking on next so I want to show pick two right so I have the correct value here so I'll just say current image it will do the work for me just one line of code and it will show the name of every place in real time let's check let's check if it's working fine or not so I clicked on run button terminate so if I click on next kutub Minar you can see in real time picture is getting changed as well as the text is also getting changed next akaram Temple this is akaram Temple uh you can write here travel instead of travel photos app you can write top places to visit in Delhi next is this is red for this is Lotus Temple after this we'll go back to the first image because we had only five image in our database this is again India Gate this is again Kar if I click on previous button again India Gate after India Gate the last image because this is the first image right so last that is uh this Lotus Temple should be shown perfect that means our code is working completely fine right all right so I hope you find uh you found this fun and interesting make your own application as well just watching tutorials just watching me developing applications will not help you one more quick thing one more quick thing is I will put the code on GitHub and you can uh take that from there from GitHub but first try to create it on your own so that things are more clear in your mind and yes show it on the internet show everyone that you are developing you are learning these skills um in uh it open doors to Opportunities which you don't even know exist when you put things on the internet people will notice notice it if someone need app developer HRS hiring managers they'll see your work and if they like it they'll hire you as well so yes go ahead create the app right and tag scale or tag me tell us what difficulties you are facing and how fun it was for you to create this application also if you are interested in learning more about Android development M using cotl if you want to create more exciting projects on this channel only on a scaler Channel I have recorded I have created videos lectures in which I have taught how to create Android application development projects we will put the links of the previous tutorials as well if you are interested in creating more projects go ahead and watch them and let us know in the comment section if you want new projects new you know lectures around the same and we will bring them I will teach you how to develop a music application alongside developing the project you will have an better understanding of how to use API in your application how to pass queries parameters and much more these are very important concepts of application development hello everyone and welcome to scalers YouTube channel I am somia a software engineer and an educator in the part one that is this lecture I will try to find some good free music API and then I will teach you how we can fetch data like music album artist information Etc from that free API into our application so yes let's get into the system and start working on our project so first of all let's understand what an API is so for an example we all use so many applications in our day-to-day life like Amazon app is there Spotify I mean everywhere whatever application you are using the use of API is indeed there for example let's say if you use Amazon app right so if I search for maybe shoes and then I press on enter so I get a list of shoes right out there like from different brands like Adidas Nike Etc I get a big list right so you would have thought someday I mean from where that list is coming so that is where API comes into picture so as end user you will get all the required information on your app screen that is as what you want but all these things are done by us that is developers what we do we write code in a way that we bring apis and the end screen both into action like developers we design the app in a way that it could access the data is stored in the databases via apis and for this purpose we have multiple third party libraries like retrofit is there right volley is there OK http these are some of the third-party dependencies using which we work with apis in our applications so if these concepts are a bit you know tough for you on this uh page only on this scalers YouTube channel only I have created some basic tutorials as well for app development you can first check out that and then start with this one perfect so talking about API so what apis are API will connect the database to access the required information and send it to our application like right now it's all Theory but when I will implement it when I will write the code in the application then it will become quite easy for you to understand and assets or databases it's self-explanatory like databases that's a place where all the data is in is stored right awesome and this is a pictorial representation of what an API is so API which stands for application programming interface it allows to two programs to communicate on the web API between like an application and a server it basically facilitate the transfer of data these are the steps three steps are most important when we talk about API the number one request API call is initiated by the client like let's say if I ask for some clothes right so API will be triggered I mean a call will be made to the API via me via the nend user and then the worker that is like here they have given the example of B that act as an API it goes to the server and then collect the data the API goes to the server that collect the data and then we get the response in our end screen in our phone the API transfer the requested data back to the data back to the uh like requesting application let's say I'm using application Spotify I requested for some music so what the API will do it will go to the server it will fetch the data and show on the end screen that is my sporify application right it all is done in few second you don't even realize what's going on in the background but we developers we know that we write code in a way that everything is done fastly I mean we don't do these things on the same thread on the main thread you won't even realize that an API call is being made but in the background it is being made right so you can take a screenshot of this picture and try to understand yourself as well how everything is done it all starts from here once you make the HTTP request like here it is get nectar we can do get music get clothes anything right and then from the server API clict the data and finally it is shown to us the client awesome this is Json format so what happens is like I'm talking so much about API and now you have a basic idea as well what API is like if I'm requesting some data so API will fetch that data for me from the database and show it in my application right and the full form is application programming interface so the data that uh we are talking about that comes in Json format okay and this is an example of Json format that you see here so let me explain you right now I know that it might be a bit difficult to understand but I will make it all super simple for you don't worry so this curly braces these are called as objects okay and inside this we have a bands array you can see the starting point of bands array is this and it is closing here right it is closing here and inside the bands array we have two objects object one from here to here and object two this one then in object one that is object one and object two so in object one we have few parameters like name description image in the same way in object two as well we have name description image ear albums and so on right so this is a basic structure of adjacent data in Json data we have arrays right arrays which are represented by square brickets and we have objects as well we have objects as well which are represent presented using curly braces this is a basic overview of how Json data looks like moving ahead this is again the same explanation that I just did that Curly braces means object and square bracket means we have arrays perfect and like if we have square brackets like this that means that is array of data objects means we have information inside object perfect moving ahead now you have a basic idea of for what an API is right you know the full form you know what the role of API is and you also know what Json is like the basic structure of Json data I will use a free music API and then I will fetch all the information in that application okay once we'll do the Practical then you will get a better understanding of everything now that you have a basic understanding of what an API is and what is Jason format you got a basic structure like in what format Json data is designed so now what I will do is I will quickly get into the system I will tell you the steps what we will do what we will follow to create our application Perfect all right so let me write the steps here steps to create the application the very first thing is we have to add the dependencies we have to add the dependencies in our application right in our application we will add the useful dependencies like retrofit and Json converter which will convert the data for us into Json format we will use Picasso Etc some other third party libraries as well and second step is we will convert the data class we will basically create the data data class by converting the Json data okay we will exactly create the data class here create data class by converting the Json data like we have some extension I will teach you then you'll understand it all very well and after that we will create an API interface API interface right and the fourth step will be we will fetch all the data in our main activity fetch data in main activity and then we'll work on the UI ux part as well perfect so these are kind of summarized steps for you uh these are the same like add dependencies create data class API interface get data in Main and then populating the data that is uiux perfect so now let's uh try to search for some free good music API that we will use in our application free music API and U this is the first top blog which I'm getting top free music data apis and if we scroll down so this is a good list of uh apis the first one is dieser API so I'm going with that only so let me tell you like Spotify as it's very popular in India so dieser is a similar kind of music application that's heavily popular outside India people use it a lot to listen to music Etc so do one thing as you click on this link make sure you you are signed up to this portal rapid API so rapid API basically this is a portal where they have huge collection of apis right awesome so derer API is you can assume that it's very much like a Spotify only they have these end points as you can see infos radio search Etc uh and depending upon in which language you are writing the code you can choose the language here so we will be writing the code heavily in cotlin for our application so they have given the option here cotlin okay HTTP so this is the code base example also that they have given if you want to just copy paste their code you can do that as well but I will teach everything from scratch we will create the application from zero from scratch so that you understand everything very properly right and if I uh test and point here so we will get the result uh in this result tab okay so here you can see we will get three keys in our API okay uh that is object uh one object which is having three keys if I open it up data is the first array then total which is of type int and then we have next variable which is of type string right if I open up the data array then there I have 25 more objects right and inside each and every we we have multiple data like what is the ID of the music the title of the music then the artist information is here a lot many you know data is available here so this is I think a good API for us I mean I will fetch it in my application and then we will show some basic information like music title artist information Etc so first step is done I mean uh not exactly first step I I add the dependencies that was the first step that I told you but before that we have to find a free music API right so I have got a good music API and uh yes I'm mean these are some header parameters Etc that we will need to add in our application I'll teach you don't worry and then these are some required parameters as well perfect so let's do one thing let's open up Android studio and start the work so Android studio uh and if you don't know exactly how to you know create basic project in Android Studio I would highly recommend again that you go and check out the basic tutorials on this channel only which I have created so go ahead and choose an empty activity let's name it uh music app Music app and click on finish you can leave all their stuff as they are language shoose Scotland minimum SD K24 and let's click on finish once you click on finish because it's a bit heavy software I mean it is a software using which we create uh applic ations right so it will take few uh you know seconds minute depending upon your internet depending upon the storage of your uh system and for me it's almost done you can see here at the bottom gdle build is happening they are importing some of the grad projects Etc right so I won't like explain all the features in the application I'm assuming you have a bit of idea of what an Android Studio is how it works so let's go and yes work on on the step number one that is adding dependencies relevant dependencies for our Music application so I'm opening up gdle scripts I'll go in build. gridle and here in the dependencies section I have to add the relevant dependencies right so the very first one is retrofit retrofit dependency so let's go and search for the retrofit dependency uh so let me write retrofit dependency Android so this is the well explained blog that they have created so if you want to use retrofit in your application so they have given all these tips like you have to create the API interface this is the kind of code that you will be writing they have written it in Java and today we will be writing in the official language of Android that is Scotland right so if we scroll down so here we have the dependency so let's copy this and here we will put the retrofit dependency so they haven't given the uh latest version let me check from their GitHub repository if we go here and uh if we click on the tags so we will get the latest that that is 2.9.0 right 2.9.0 and after that I want Jon converter right Json converter so that is exactly the same that exactly has the same group ID as retrofit right the only difference will be here in the Jon converter in the Jon converter perfect and after that let's just click on sync now and you can confirm this I mean if let's say you are not sure of if the Jon converter dependency is correct or not so you can just write here something like this and you might get some good results from here so you can see I mean this is uh kind of existing dependency that is uh the converter G that actually exist perfect and the group ID is also exactly same as we have written and the version is also 2.9.0 and after that we just have to click on sync now so what sync now will do it will you know download all the relevant data classes dependencies for the given uh dependencies that we added like retrofit and Json converter so we have done this step number one let me show you uh by sharing this iPad screen as well so this is the step number one that we just completed we added the relevant dependencies in our application and after that we will focus on the step number two that is creating the data class perfect so I have the Json data ready here you can see I'm in if I go here this is the exact Json data Json information that I want right so I just copy it and to explain it in a better way to you I will open up Jason for matter okay Json form matter and uh let's click on this one and if I paste the Json data that I copied from the website derer API and if I click on process here so you can see I mean this is the process dejon data that we have got this is one object right this is one object if I expend it so I have three things here number one array of data number two total the variable of type integer and then I have next variable which is of type A String right so inside data array I have these many objects if I like you can go on you know minimizing it if you see here so we have three keys and then inside data we have 25 items we have 25 objects right in a single object if you want to see what data that contains so that contains ID title of the music title shot then duration of the music rank of the music like music also has some rank right what is the rank of the music popular music Etc and we have the preview of the music as well like they will play the music for a short time kind of trailer or something you can say and then we have image then here is the artist information the artist who has created that particular music like Eminem is the name of the artist for this music picture of the artist Etc all this is inside artist object and and then album object is there which contain the information about the album so inside the single data object also we have two more objects you can say album and artist apart from that these string or integer variables are there perfect so let me do one thing I already have the copy Json data right so what I will do I will right click here I will go on new just notice the cursor of my mouse okay and here if you see at number three cotland data class file from Json so if you want to convert Json data into Data class into Data class so that we can do using this extension right if you don't have this extension so listen to me very carefully you just have to go in the files option uh here you can go in the N Studio then preferences basically you have to go in the settings and after that just go in the plugins and search here for uh you know Json converter or something something like that so the Json to cotland class basically this is what I have to do I have the Json data I have to convert it into cotland class so I just I have installed this you have to install it and press okay perfect and after that once you will come here in the Java folder and in the package name right click right do the right click here and new after that cotland data class file from Json I will just paste it and then click on format and give name to the data class so I'm giving it the name my data okay my data will be the class name the main class name I will click on generate here so you can see I mean it has created four files for me right the very first is my data in which we have three main data because we know that in our dieser API we had three main data right what were they data total next so here as well we have data total and next right after that that in data that is an array of objects right so it has created a list of data if I go on data class now so you can see inside data we have plenty of information and as I told you ear earlier as well inside data class as well we have two more classes that is album and artist class right apart from that some string integer Etc variables are there perfect so uh my data is the main class and then I have data class inside which I have again album and then I have artist class as well let me close all these data classes now if I show you if I again do the screen cast so we have done the step number two as well that is uh that is creating the data class so this step is done adding dependencies let me Mark it with yellow so add dependencies this is done this was very easy right just adding the dependencies in the bill. gdel and after that we are also done with creating the data class right and after that step number three is something we are going to do right now that is creating the API interface API interface and if you want to get an overview of the uh data the Json data that we are using so this is the overview we have three keys in that data and after that we have two more objects like um like next as well as the other was I guess total the total music that the data is having perfect I mean you can use any API for that matter and I explained you the format as well very clearly how the you know Json data is most importantly you should know the difference between this and this this is object and this is your array Perfect all right so now is the time that we should U create the API interface that is a step number three all right so for that what you have to do just go here and create a new class go on new and then cotland class I will name it API interface API interface and instead of class file just click on interface so API interface is created here for you here you just have to create a simple function so I will create function get data okay and the return type of it so I'm not doing anything special I mean every information is explained here in the retrofit uh blog itself I mean if you read here so they have told you that okay you have to create a kind of interface and that should be of type call and that should return the list of the pojo class basically the my data class that we created now that is called pojo class as well all right so here I will use call of retrofit and then I will pass here list of list of my data awesome and inside this if you notice in our dieser API so we have to pass some query as well this is required parameter so what I will do is I have to give a query parameter that's very simple you just have to write at theate query right atate query and the name of that query like in our API we have q here you can see the required parameter is Q right so you just have to write q and after that you just have to write q and name for the query name for the query and just the type of the query so here we have to give the name of the artist right we are searching music by the name of the artist so I'm name is the artist name right so this is of type A String so I will just write a string here perfect that's all what you have to do this is the way you pass queries like uh this let me show you this is the code snippet right this much part is the base URL this is the base URL that we will pass in our main activity and after that we have search okay the end point and after that we have query in which we are passing the name of of the artist so for that we have to pass here query as well and after that you just have to write here atate get atate get because we are getting some data from the API right and just write the end point so you can see multiple endpoints are given here in the API like infos radio search playlist artist so we are using right now search endpoint so I will write here search that's it that I mean you have to write inside obviously double quotes all right and if you notice here we have one more extra thing in this API that is they have given us some header parameters right they have given us some header parameters for that what you have to do I mean you can just copy from here as well the header parameters so you just have to write at theate headers at theate headers and just give all the information of the headers here okay let me put the double quotee here and after that you can just take the information from here directly so this is the header one basically uh this is rapid API key and Rapid API host to access the API we have to add these headers okay whoops command okay I didn't copy I guess so let's copy it and then we will put in our application okay copy and here we go so let me put it in a better way uh all right and after this because we have two headers right not a single uh not single header right so for that I will add the other one as well which is the rapid API host right rapid API host here we copied it and we just have to put it here just remove these extra stuff and you will be good to go perfect all right uh I just want to remove this part all right make sure that when you copy these keys they should be correct let's say if I miss five from here or if I put something else then the API will not work and we will not be able to fetch the data from the API right awesome so instead of plus let me put a comma here and yes we are good to go perfect so we are done with the step number three as well that is creating API interface for that you just have to create a function get data and that should return call and whatever your pojo class is so list of my data and inside this we have to pass some query because in this API we are searching for music on the basis of name of the artile T that's why I have passed some query here and you have to write at theate get and name of the end point which endpoint we are using search so I have written here search and after that you have to write the headers as well awesome and now you are almost kind of done with the uh you know basic stuff now our main step is we have to get all these information in our main activity right so let's go and write the retrofit Builder which is most important right so well retrofit Builder retrofit Builder it's it's pretty simple and easy retrofit do Builder I mean uh obviously as a beginner no one expects that you know everything I mean how to write the code because I have been writing many softwares many applications so kind of these code bases are on tips but obviously as a beginner no one expects you to know or root learn all all the code I mean you can just follow these blogs I mean retrofit uh all the information is provided here that you have to create the retrofit Builder so I just created the retrofit Builder after that you have to pass the base URL right so the base URL for the API is here I will just like take this base URL from here don't take search the end point because end point we are passing here here right end point we are passing here so just take the base URL and after that you have to add converter here add converter Factory and inside this you have to you have to pass Jon converter Json converter Factory so it should auto complete I mean if you have uh if you have imported the you know right dependency so it should autoc complete everything thing let me see what's going wrong with this um so Json converter Json converter okay it's not autopicking it let me see if we have added the right dependency in our in our build. gdel so Json converter okay so maybe it hasn't picked it up not sure so add converter let's let's read the block once for retrofit so we added the base URL we will do build as well as create but before that we have to add the converter Factory because we are using Json here right all right so I think the Json converter the dependency I have used is instead of Json converter it's supposed to be converter Json and if you check that uh you if you search for it as well so it should be converter Json and that's why it's not autoc completing the converter Factory which I want to use right so converter Json and now if I go here so it should autocomplete it and if it's not happening that do invalidate the caching that will do the work for you right so and because Android Studio indeed is a heavy software right and sometimes it stops working or maybe it's stops autoc completing the code so in that cases you can just invalidate the cache so Jon converter Factory you can see the option here just go on do create and after that what I will do do build do build and finally I will do do create and I will also pass the API interface which I created here okay I will pass the API interface class. Java perfect so this much part is done basically you have created the retrofit Builder they have asked you to create the retrofit Builder here I mean they have done it all in the same way as I did the base URL build and and do create you have to pass the API which you have created in the step number three so we are right now on step number four that is we are writing all the code for our main activity perfect and um after that let's get the retrofit data in a variable retrofit data is equal to retrofit Builder one sec retrofit Builder dot get data why it's giving me the option of get data because in the API interface no I have created this function get data right which will get all the data from the endpoint search from the endpoint search awesome so here we will do get data and we have to pass a query of type A String so I will pass the same which is given here in the dieser API which is &m the name of the artist so I will just pass this one here okay and now listen to me very very carefully this is a bit tricky but veryy easy Once you understand it okay so what you have to do you got the retrofit data right you got the retrofit data now the only thing remaining is you have to use one method only one method that is NQ method so what happens is you have got the retrofit data from the API so you have to run NQ method and based on if the API call is a success or a failure you will do some operation okay so let's write do n Q do NQ and if you see here it is telling me that somia you have to pass call back parameter here so what I will do I mean it will be a long piece of code if I go on writing the call back everything so if you do control uh let me show you control shift space so it should show one second just do control P it will tell you what data you have to pass right and if you do here sec let me write object of type of type call back so like it should autoc complete it either you can write all the function everything on your own like the call back and everything or just use the shortcut control shift space and you can see here it is giving you an object of type call back right all right so just do control shift space and it will give you the first option that object variable of type call back list Etc just press enter and you can see it has written a bunch of code for you right so let me help you understand this don't worry uh let me erase the to-do part from here so what happens is once you got the retrofit data you run an NQ method you call NQ method so inside NQ method it's starting here and it's ending here inside this we have an object which is a call back which is of type call back right right so here you can see there are two overrided method on response and on failure let me explain you the purpose so if the API call if the API call is a success then this method that is on response is executed is executed right if the API call let's say if is if it's not happening maybe due to internet or maybe because the host is not working the API is not working any reasons anything right if the API call is a failure then this method then this method is executed so you would have seen sometimes I mean let's say if you make a request and maybe your internet is not there so you would be see you would be seeing some screen like no internet or maybe your offline or no data something like that right so we have to do all such stuff in the on failure method so failure and here will right spelling is a bit incorrect well it's a comment only all right so now what we have to do once the API call is Success we have to get all the data inside on response so let me try to get the data in the on response method right so I will do well and uh data list is equal to response dot now you can see I inan they are giving me bunch of options right so what I will do is this is the response response resp do body dot uh again I mean plenty of options are here so what I will do I'll first check with just response. body if I'm getting the right information or not right so I already have one text view available here the which is hello world so let's give ID to this let's give ID to this all right I change the design section yes split let's close it I'm just just minimizing it and here let's give a name to the text view ID let's name it just text view only okay text view or hello hello text so first of all I have to check if my API is working fine or not and then in part two we will learn how to you know beautify beautify our application using that data I mean how you can use that data in a meaningful manner so w Val text view is equal to find view by ID which is a text View and then r. ID do text hello text okay hello text Perfect all right so we have the data list here and I have got the text view as well so let me do one thing text view. set text do setex is equal to data list I want to see once if I'm getting some data or not do to a string and also let's do a log as well to confirm if everything is working properly or not so here I will write on failure tag n tag on response and inside on response I want to see the I want to see the response that we are getting plus response one second response Dot message or is successful anything you can write I'm just writing dot body all right and if the API call is a failure then in that case also I want a basic information right so tag on failure tag on failure and here I will get the message from the throwable whatever the failure reason is obviously I want that reason right and another thing is you have to add Internet permission in your application so just go in manifest and add user permission internet and just close it perfect and let's now run the application and see if it's working fine or not so I think we have completed all the steps that are needed to uh fetch the data from the API let's now see if it's working or not if not then we will debug it and see what's wrong at which point right mhm till then let me summarize stuff so first of all we just added these dependencies right we just added these dependencies and secondly so here you can see at the bottom the Gradle build is happening you can see the background task is happening which is they are trying to run the application obviously it's a heavy software it takes time and uh after that step number two we created the data classes right so I'm seeing the hello world text here so okay let me expand it so you can see we have got on failure on failure method is being called here they are saying that they expected begin array but was begin object at line one and column two okay so somewhere the data that you know the pojo class or the data we created uh somewhere you know the there is mismatch of information they expected array but we passed an object so let's see where that incorrect information is passed on and then we will improve right so let's start from the my data class only if we go here so this is the data class so if we debug the code here so in the step number three we created the API interface but we passed your list of my data I mean my data obviously is the you know the code data I mean we don't have a list of it so obviously we don't want to pass list of my data here so I'll just tell it that okay you just have to pass my data not list of my data and accordingly we will make the changes here as well everywhere instead of my data you just instead of list of my data you just have to give the actual class right so just pass it the actual class because we can pass list of the data class but not my data right I hope that makes sense to you as well and here we will just correct it everywhere and then we will run our application again okay perfect so I think it's done and if I do here response. body dot you can see the three variables that we had in our actual API that is uh next data and another one is total right so you can can get all these data here if I try to get here response. body dot total you can see all the three datas are available here let's try to see how the data thing is so it's asking me to put a nullable thing so that you know uh if the data is null then also it can manage the manage stuff I mean it will not crash basically your application will not crash awesome and now I will simply run my application okay so let's rerun it and see if it's working fine or not so when we are working with API so obviously there are high chances that we can make some you know mistakes here and there because it's a huge code base and you can see I mean the Json data is available here we are good to go I mean we now know how to fetch the data from the API you can see the data part I mean if you go here so the data part is here it has 25 object and all the Json format data is available here on our apps screen but obviously you can't show the data to the user in this way right you can't show it in this way so in the next part what we will do we will understand how to utilize this information in a better way how to design it in a proper way perfect so let me summarize all these steps quickly for you right okay so here is the screen casting so step number one we added the dependencies retrofit and Json converter what we did a mistake there we uh wrote the wrong dependency name right make sure you write the right dependency name then we created the data Class via that extension we just copied the Json data and with the help of the extension we created the data class it created four data classes for me my data data Class album and artist right and after that API interface and then we did the retrofit data. NQ all those things we created retrofit builder in our main activity and after that finally we populated the data in the view I mean we just uh checked right now I mean how to uh you know if the data is actually working or not in the next part we will exactly see how to populate the data in the views right awesome so if you have any queries about this much part about how to fetch the data how to use the uh Library Etc drop them in the comment section below I will be happy to answer them so now I hope all the steps are clear to you what we exactly did let me explain a step by step so this is a step one we added the dependencies in the bell. gridle that is retrofit dependency and converter Jon after that in Step number two we created the data class using the extension from Json to cotland class converter we have those extensions right and after that in a step number three we created the API interface and we just wrote put a simple function get data we pass the query here using the adate query the keyword and then that should be of type call and the name the pojo class name and then simply added the headers and we told that okay search is the end point that we want to access that we want to get and after that in Step number four what we did is we created the retrofit Builder Okay retrofit Builder do we pass the base URL added converter Factory build do create and then we fetch the retrofit data we called the NQ method then there will on response and on failure two methods in on response we write the code which uh we have to when the API call is Success if it is a failure then we will use this method right we ran the app yes that's all we have to do so I hope the part is clear to you this part the part one is completely clear to you if you are facing any doubt if you have any you know bug is coming up or anything then drop them in the comment section below and I am there to answer them this is part two of developing a music app Series so the very first thing that we need to understand is recycl view recyc view is considered as one of the most difficult and it's not so easy to understand because recycl view is in itself an advanced concept and when we talk about application developers their life somewhere revolve a lot around recycl view only so I will break down all the advanced concept into simpler parts so that you can understand everything very easily okay awesome so let me do the screencast and I will explain you each and everything very easily so now I will teach you about recycle view what a recycle view is using that we will make some list like uh let's say if this is your application right in day-to-day life we use so so many applications right and in most of them we see like list of data in any application where you scroll up or down like you use IG Instagram you use YouTube Etc so in YouTube if you remember there is a kind of card and a picture is shown here the title of the video right and a lot many information is there and we keep like scrolling it up and down so anywhere wherever we have to scroll things up or down so there is the concept of recycl view or List view behind it whenever we have a list of data let's say if that is if this is my mobile apps screen and I have to show a list of activities which I have to do today right kind of to-dos app let's say so here Activity one Activity 2 Activity 3 so either to show this list I need list view or recycl view so let me explain you what recycl view is recyc view is a powerful UI viset that allows you to display a list of data in a flexible manner when I was learning about recycl view indeed as a beginner that was very difficult for me and you know like there are a lot of resources on how to create a complex one but very few about how to create a simple project using recycle View and while the pieces that make up recycle view may seem confusing at first but the way I will explain today I hope that will make you understand this Advanced Concept in an easy manner so there are three to four parts which you have to remember like in the last lecture in the part one also API is in itself considered a very tough topic but I broke it down in five parts and I helped you understand everything right so in the same way in the same way in recycl view as well I will break down this topic into parts so you would have seen Gmail application right so in that as well these are kind of cards like right multiple cards and if you scroll down up you will see multiple males coming in right so here as well the concept of recycler view is used in this sample application as well you can see the name of the person is there and their image is associated right so either in all these Concepts you need list view or recycle view wherever there is a list of data which you want to show in your application the concept of list view or recycl view is used perfect so a recycl view is a container used to display a list or grid of data like text or photos when a list Scrolls only a handful of views are actually displayed on the screen and when a view Scrolls off screen recycle view reuses it and fills it with new data this makes your app more efficient both in time and space because it recycles existing structure instead of constantly creating new ones and this is the difference between recycler View and list view in case of list view what it does is it doesn't recycle the already present views it always create new one and that's where the space the uh you know time everything is hampered for your application and that's why recycl view is considered to be an upgraded version of list views you can do multiple things with the help of recycle view so here you can see they have written the pink cell represent the cells displayed on a screen and the yellow cells shows how the view that is a scrolled off a screen is recycled in a new view right so this is how efficiently recycl view do everything in your application and these are again some of the pointer why should you use recycl view especially as compared to list View and again like they have explained the important Concepts that are used when we make any project using recycl view adapters are most most important these are most important concept when we talk about recycl view I mean when you have to create a recycl view adapter is one of the most significant thing right apart from that obviously data is there recycle view is there view holder is there when we will develop the project you will understand these Concepts very very easily so so here as well I have divided the complete steps all the steps into two parts number one we have to create an adapter this is our step number one like in part one we did five steps right here we have to do two steps only number one we have to create adapter now creating adapter it involves a lot many stuff like lot many methods are there which class you have to extend you have to understand all those things and always remember don't try try to root learn these concept be it retrofit code or how to call Api anything don't try to root learn it because these are some important Concepts and it's important that you understand them right so in adapter as well I will teach you how to exactly create adapter that will be our step number one for today and step number two we have to link the recycler view that we will create in our main activity uh in the last lecture we had a text view we in that text view only we fed all the data right so here we will link the recycler view with our adapter perfect so let's go ahead in our laptop and before that here is a diagrammatical representation of recycler view adapter like this is adapter this is database and this is our uiu that is recycler view or List view so basically adapter plays the role of kind of middleman it kind of establishes the relation between databases and the uiux like recycler view or List view whatever you are using so that is the role of adapter they are very very important when we talk about recycl view awesome so let's get into the laptop and understand how we will exactly write the code okay so let's go into the project and see how we can Implement adapter in our project perfect so what you have to do uh here in the package name just right click and create a new class we'll go on new and cotland class name it my adapter or maybe data adapter something like that okay my adapter and press enter now this is your adapter class this is kind of very significant when we talk about recycler view in Android applications so just uh you have to pass some of the parameters here number one pass context to okay Val context which should be of type activity and after that you have to pass the data list okay you have to pass the data list it should be list of the my data class okay either it can be my data class or even like data class I mean based on which kind of information you want in your application you can use either of them right and then you simply have to based on our use case I mean we can later modify it as well let's say if I want the data of the uh other class the data class in which we have multiple parameters multiple information present we can use that as well right uh extends recycler view do adapter dot adapter and after that you have to write the name of the adapter my adapter and let me put it down so that everything is clear to you dot you have to create a view holder now okay you have to create a view holder I will explain everything I mean what is view holder why are we creating that every single thing view holder for now just note down these step by step things which I'm doing and in the first go obviously it might be a bit confusing for you like how to exactly you know write the code you might need to follow tutorials and watch others code basis but once everything will be clear in your mind I mean once you'll have the freedom to write on your own then it will be super duper simple for you okay so my view holder and after that after that if you see here if you go on my view holder it is asking me do you want to create a class so indeed I want to create a class and for that I'll click here create class and I want to create this class my view holder inside the adapter only right so I'll click here uh one second let me undo this and here we go I want to create class and inside my data okay it shouldn't be actually inside my data it should be here inside the my adapter only okay it shouldn't be my data here I have to write my adapter my bad cool and now if you go here create class then inside my adapter I have to give the instruction that okay create the my adap create the my view holder class inside the adapter only okay so press enter and that's it that's all after that you have to extend it recycler view Dot View holder and it is expecting a parameter of type view so here what I will do I will pass item View of type view and uh one second it is okay it imported this View and here I will simply pass the item view the parameter Perfect all right so while creating adapter while creating adapter what we did we followed simple steps only we first created the class my adapter we passed two parameters that is uh context of type activ it and data list of type list of either my data or data that's completely up to you I mean I think we better use list of data only I will tell you the reason shortly because in data class if you see we have plenty of information I mean I can show the album name artist name lot many stuff right in the my data class we just have these three information all right right so let's close these extra things for now and let's just focus on my adapter okay and before that let me tell you what my end goal is basically my end goal uh let me do a screencast I will explain I mean what kind of uh functionalities I will be adding in my application so let's say if this is the screen of my application right so I will make some cards here right I will make some cards basically these tutorials will help you understand everything about the logic part uiu like how to beautify the app how to add colors how to make it look awesome and all of those stuff you can do on your own as well right for now I want to use these 40 50 minutes whatsoever in just teaching you how you can populate the data from the API in a meaningful manner right so I will make cards and here I will show the music uh kind of of cover image and then title of the image maybe some play and pause button here and there to just teach you like how exactly to run music Etc and then you can make the UI as good as a Spotify Etc perfect so let's now come back here and uh if you see there is some kind of error or hint here at class my depor if I go here it is asking me that hey somia why don't you implement some members so let me tell you when we create a my adapter class and we extend it with recycler view. my adapter or adapter class right so there is always need of three significant methods those three methods are very very important in adapter so let me Implement them these are the three methods out of which the second one that is get item count is the simplest one let's say you have a list in which you have 10 music right so get item count what it will do it will return you 10 that is the size of the list so I will simply do return and where is the list here is the list right so data list dot size that's it I'm done with this method get item count I'm done with the code of get item count and after that I have to write code in my view holder and onbind onbind view holder so here I will write the code I will try to explain things and after that we will go in iPad and I will revise all the concepts for you I will summarize every single thing okay so in my view holder listen to me very carefully in my view holder what we have to do here we have to create the view create the view in case the layout manager in in case the layout layout manager fails to create view fails to create create View for the data for the data right all right and while on bind view holder what we do we have to populate the populate the data into the into the view perfect and uh with that being said we now have to create one very significant design file okay so if we go here in the resource directory in the layouts right now only one XML file is there activity main.xml so what I will do I just showed you that I want cards of uh music like there I will add some information like music image music title and so on like some buttons to play the music Etc so for that I have to create a basic layout as well so let's quickly do that I will do right click new and layout resource file and here let's name it uh each item I mean I want to design how each item will look like just imagine WhatsApp I mean on WhatsApp you have some specific you know uh columns or rows you can say in each you have one image of the person then message the re recent message and the time at which he or she has sent the message so each item in that way like I have to design each item so I will do kind of sim I will follow similar pattern like I will put one cover image for the music then music title and some buttons to play and pause the music okay I'll show you I mean what I'm exactly going to do so let's uh design each item how each item or you can say each row will look like okay press return and here it is so right now it is constraint right I'll just make it linear and once again I want to spend too much time on design part because my focus is to teach you the core coding part right how exactly we can populate data I mean you can beautify the design as much as you want let's bring it here and let's do it like this perfect and here I want the height to be wrap content okay because I don't want one item to take all the space right each item should take a particular space right awesome and then orientation vertical after that uh I will go in the design section and card view I will drag and drop a card view here and in one second it has not been dragged dropped so card view inside the linear layout and after that I want one image okay in which I will show the cover picture for particular music okay here is the card view let's for now put this random picture okay whoops H so I have dragged and drop an image in which I will add the cover picture for the music all right and after that I want a text view here but before that before that we want horizontal here because I actually want to put everything horizontally like music image then text View and then some buttons so what exactly I want to do is before this before this image view I want a linear layout once again right a linear layout which will give it the instruction that b it in horizontal direction right so we need one more linear layout inside the card view which should be of horizontal orientation right and here here we go like this is the linear layout inside this we want some more stuff like image view so let's first put image view image view here inside the linear layout let's put a random picture here for this one and after that inside this only I want one text view uh text view like this and also I want two buttons image buttons kind of on clicking that we will play the music which we will be getting from the API right so I'm not get giving much significance to uiux right now uh once again I'm telling this I mean you can make it look too beautiful maybe we can have a separate tutorial for the UI part right so all right image button and another image button I actually want the image buttons to be to be at the bottom and this is for pause the music one second let's now come in the split section and obviously it shouldn't be here the image button just copy it and put it here just above the pause button perfect all right so looks okayish to me I mean yes we our Focus again is to check the code part so let me give some meaningful name to these uh views okay so this is music image all right this is your uh let me give some fixed uh fixed uh height and width to this one and text view as well let's give it the name music title mic music title music and from we are not going to hardcode any information I mean everything will be feted from the API only right for the width I guess 100 APS more maybe 80 DP is fine for this right and uh again for this one as well I want to make the width 100 DP no it's it's more for it 50 DP is good cool and 50 DP for this one as well so that everything looks constant right awesome and this should be named BTN that is button play to play the music and this will be BTN BTN let's click again BTN and pause okay so a rough design part for each of the item is done here we will put the image of the music right and let's do a bit of good stuff give some radius to the card so let's give it five or maybe 4 DP and some margin between each and every uh view right okay for that maybe we can add margin of 1 DP and in the linear layout as well in the linear layout as well like this is the card view right inside each card view we have linear layout so let's give margin of 1 DP here as well cool we can maybe escape the margin for the card view here all right and we will see I mean based on how clean the data is looking we can make more changes here and there cool so let's now come back to the my adapter class okay my adapter class and now what I will do is I will write the code for my view holder class okay my view holder class so here is the my view holder class all right this explanation was for on create view holder like when layout manager fails to create the view then we ask the on create view holder to create the view right and this is for populating the data and right now we have to do a stuff in my view holder okay my view holder so the name is somewhere self-explanatory my view holder class it is there to hold the data right to hold the data so let me create the uh you know or everything that we have in our single row or each row design let me create variable for each and everything so music image music image this is of Type image view Right image image View and then I have val music music title this is of type text view text View uh I think we should give a different kind of like here as well we are giving the same name right to avoid confusion maybe we can write uh image only let's write image okay and uh here maybe just title okay title and then we have play and pause buttons Right image buttons so Val play off type play of Type image button and uh then we have pause of Type image button so You' be thinking I mean why it is throwing some errors because we haven't yet initialized all these values right so what I will do inside in it I will initialize all these values with the help of with the help of holder which is here in the class uh like which is inside this only okay one second one second so this is my view holder and I have now we have to initialize all these values right so image is equal to item view item view do find view by ID and R do ID dot we have music image somewhere right music image let's bring it up awesome and then I will initialize I will initialize title is equal to item view item view doind view by ID r. id. music title should come up here all right and after that we have play and pause buttons as well so play is equal to item view do find view by ID and here we have r. ID do play BTN play right and then finally pause is equal to item View do find view by ID find view by ID r. ID do BTN pause perfect so basically in the my view holder class what we are doing we are using it so that it can hold all the views for us like what all views are we have four views image for the music image IM music title and then two buttons for playing and pausing the music so so I have a habit since the beginning that I keep this my view holder class at the bottom of the my adapter class so let me do that I just copied it and I'll put it down here awesome awesome so the work of my view holder is done I told it that hey my view holder these are the views that I am having and these are the uh kind of initialization for them and here it is telling you that you can make it private as well it's up to you I mean you can make it private it is giving some hints and all to you and now is the time that I write code for on create view holder on create view holder right so here what I have to do I will write layout inflator basically I will create one item View and layout inflator do inflate layout inflator do fromom like from where you are inflating you have to tell that from it itself giving me a hint that you have to pass context here so I will pass context do inflate now you have to see command P it is giving you a list of parameters that you have to pass inside the inflate method right so here first of all I will give r. layout dot where I have created the design of each and every row that is in each item right each item do XML and after that you have to pass the root here it is parent parent you can see this is the root right and after that just pass false and return return so here you can see I'm in you have to return something of type my view hold up so I will return my view holder and pass this item view pass this item view perfect as you can see in the my view holder class as well I am passing item view right of type view all right so uh here in the adapter is Step number one we created the adapter we passed some parameters two parameters exactly we extended it recycl view. adapter and after that I created my view holder my my view holder basically I told it that okay these are the views I am having four things like music image title Etc and after that I obviously get item count is super duper simple I mean if you have let's say 10 music in your API so it will give you that give you number 10 okay this is the size of your array or whatever list you are having and then on create view holder it create view for me in case layout manager it fails to create a view right so here also I created the item View and I told it that okay this is the layout which I have created Etc I have given it all the information and now this is the most interesting part on bind view holder inside this what we have to do we basically have to populate the data into the views like music image music title everything via this method that is onbind view holder so let's do one thing let's uh get the value of current data is equal to is equal to what is the name of your list that is data list right so just get the data list and pass here the current position that is here position right so now you have the access to the current data in the API whatever the current data is you have the access to the current data so what I will do now I will uh uh like fill all the details into each and every view so first of all you know that I have the title right so holder dot holder dot this is the title where I have to write the name of the music right so I will just press title is equal to current data current data holder. title do set text right because I want to set a text there current data dot title link a lot many stuff are given here right so if you go on dieser API and uh check here that what exact information is present in the title so if you click here so title is basically the music title only right like this one is a stand the name of the music and if you look at the seventh object here so the title is love the way you like this is is also music right so these are kind of mostly in dieser API you will get to see English music I mean uh because Spotify if you use a Spotify API you will get to see a lot of Bollywood music Punjabi everything in dieser API you will mostly get to see English sort of music right perfect so current data do title so I'm assuming I mean at this point if I run this application it should show me at least title of the music which I will be getting from the API right but let me complete it I mean after title I have to uh fill data in the image view as well right perfect so I will get the image from where from album and then cover image is there right awesome so for image what you have to do you have to use one third party library that is Picasso let's go and find the dependency for Picasso Picasso Android dependency okay Android dependency the first link that you are getting this is their GitHub page the second one is their complete detailed blog so this is how you have to use picasso. getet everything and uh if you check their dependency so scroll down down and this is their dependency so let's add it in our build. gdel right in our build. gridle file here we go I'm putting here Picasso for Picasso for converting image link for converting image link given into API so basically you are given one image link and you have to show it in image form exactly in your application you can't show the string the the link that you are getting for the image right so for that I have to use Picasso which is a third party Library so what is the latest version of this let's go on GitHub and check so if you go here 2.8 is the latest version right so just copy it and uh here we go 2.8 you just have to click on sync now and it will do the work after that if you check the check the basic syntax of it this is is how you have to use it I mean it's a oneliner code which will help you do everything right so come back in my adapter and here Picasso just import it okay all right Picasso doget so you have to load this image into this image view right so image view I know holder dot holder dot holder Dot image right and what is the URL exactly so I will get the URL from the API like this is the exact URL which I want inside album I have the cover variable so from there I will get the image right awesome so if I do here current data current data Dot album do album dot then here is the cover right I think cover is having the link to the image yes right do image dot cover yes if I click on this link if I try to open this up to see if actually I'm getting some image of the music or not so yes I'm in some sort of music I'm me depending upon what music that is and as I told you I mean you won't get too much of Bollywood etc's music right so expect these kind of data only from this API all right so we have we are done with the Picasso part as well like image view as well now the very next thing that we have to do is we have to play the music as well right we have to play the music as well so for that you have to use media player somewhere right media player Val media player is equal to Media Player do create and then you have to pass inside your media player you have to pass the exact music which you want to like which you want to play and you can get that from your API itself right so context context and then you have to pass the music so you will get the music from your API only let me see from which variable so if you see here uh this is the data right 7eventh object and this is the title of the music link so preview is the variable which will give you the preview of the music kind of trailer right which I want so let's go here and I will do current current data current data dot do preview dot you have to convert it into URI okay to URI perfect so basically in media player now you have the right music which you want to play right awesome uh holder dot play button holder. play. set on click list now when I click on the play button I want the music to start so media player media player do start that's it that's it and then holder dot do pause do set on click list now when I click on pause button I either can pause the music or I can stop it as well right that's it I'm inan for all the four views for all these four views like the music image music title and the button what I did I have written the code I mean I have populated data into them in the title I am fetching the music title in the image I am fetching the album cover from the API only right and uh for play button and pause button as well I'm starting the music and stopping the music awesome so in adapter I will summarize it in the end now like we are done creating the adapter I know it's a bit lengthy understanding how adapter is designed but for now we are done with that and now my main task is in the activity main I mean you can see last time when I was uh writing code here so I dragged and dropped it somewhere at the bottom so now in the main activity. XML what I will do I will remove this text View and add one single recycler view okay so let's remove this text view from here and I will add linear layout so everything is sorted linear layout this one and orientation let's put vertical only and this is the design section right so let's quickly track and drop recycler view here awesome and now I will just add a single ID which is recycler view because it's important to give meaningful name to each and every view right and now we are almost done I mean we have to do the last step only that is we have to create the recycle view here and attach it with the adapter okay perfect so Laten itwar and recycler view let's name it my recycler view right my recycler view of type recycler View and late in it where my adap of type my adapter so late in it where basically what does it mean it means that hey I am putting you here I'm initializing you here but I will give you a value later I mean I'm declaring you here but I will initialize you means I will give you some value later in the project okay that's where we use late in it the variable and now what I will do is I will initialize recycler view as promised ever somewhere here r. ID do recycl view awesome and now in the on response I mean I have deleted the text view right so what I will do let's comment it and last time we checked I me we were able to fetch the data from the API in the text view we were able to see everything in Json format this time we have created some cards Etc right to see if music and everything works fine right and uh here what I have to do I have already initialized recycl view let's initialize the my adapter as we promised in the beginning here we gave it laate in it where right that means we'll initialize it later so now is the time my adapter is equal to my adapter and here I have to pass context that is this at the rate main activity and after that I have to give the data list right so I'm getting the data list here so let's quickly pass the data list as well awesome so it is giving me some error it is saying that they want they required this and we are giving them this perfect I mean not a big deal just put nullable stuff and you will be good to go and then recycler view do adapter this is most important step I mean you have created the adapter now is the time that you set link between the adapter and the recycler view okay all right set adapter and is equal to my adapter after that you have to uh set layout manager as well so recycler view my recycler view do layout manager is equal to linear layout manager linear layout manager oops oh God okay linear layout manager and inside this you have to pass these parameters which they are showing first of all context and that's all that's all so hopefully this should work fine right now it is saying that there is nothing like recycle view so what happens and studio is heavy software I mean I just created recycle view might be it is not able to fetch it but when Once we'll run the application it should work all good right so I think we are good to go let's see if it work fine or not else we'll debug the code right so yes SM ad adter I understand I mean the code might be a bit lengthy if you are first time writing recycl view code so you can see last time we were able to fetch everything using uh Json I mean uh the data that was there in the API we were able to fetch it now we are putting each and everything at its position like music image music title and so on right now the gradel build is happening the background tasks are going on we have created an application and yes I in Android Studio if you have been using it so obviously when we run any application it takes some time right so I think the build is done let's see if okay it is saying something and in on response you can see I inan I'm able to fetch the data I'm able to get all the data in on response one again yes you can see uh on response and it is giving me all the data my data data album is here I mean cover image Etc now if I put it down so the same information should come here as well so might be because my internet is a bit slow that why it's taking a lot of time in loading the information from the API right now you can see I mean it's all the information is loaded uh and it's a bit slow obviously because of the WiFi so make sure I mean whenever you are using API know few things are there number one internet permission should be there in your manifest so these are some of the few songs number one check your internet uh that permission is there number two the internet should be good then only the API data will fetch in a good way so these are the songs Superman the without me love the way you lie if I play something sto so the music is stopped right so right now I didn't Focus much on the you know UI ux part but yes I mean once you will once you have this knowledge like how to write the logic how to fet the data from the API you can obviously I inan beautify the app the way you want to I mean you can exactly clone the design of a Spotify as well but yes in this dieser API because this is uh this is not having Bollywood music Etc you can in the same same way use a Spotify API as well right all right so I think we are good to go it's working fine so I'm closing it for now and let me now summarize everything for you what all we did okay so let me again screencast my iPad so that I can explain everything to you all right screencast and here we go so basically the very first thing that you have to do I mean uh this was in part one as well how we use retrofit Etc this is the retrofit code the complete code is of retrofit for Recycler view we only added few parts like we in we created our recycler view adapter and this is the only part that we added apart from part one lecture in the part one these these are all the code bases of part one I mean how to deal with retrofit how to you know call NQ on response everything I explained very well in the part one you can watch that and after that if you talk about my adapter so let me quickly summarize it this is your class this is your class my adapter right so here you have to pass context right so this is the adapter class that we created we have to pass two parameters here one is context of type activity and the data list I mean whatever data you have to use in your application from the API just pass it and then extend the recycl view. adapter class and you have to create your own my view holder as well my view holder as I already explained the name is self-explanatory it is to hold the views that we create in our single row or each row design design file right perfect so this is our on create view holder method this is get item count and then onbind view holder so these three methods are the most important ones when we talk about adapter concept inside recycler view okay the simplest one is obviously get item count let's say if you if in your data list there are 20 items 25 item like we used music API right so if let's say there are 10 music it will return you the size 10 okay that in this data list there are 10 music present and after that there is on create view holder basically if your layout manager fails to create a view in case then we use on create view holder and then onbind view holder is there to populate the data into the views like we populated the data in each of the view we had text we added music title there in the image we added the cover image of the music you just saw in the application right right and then play button and pause button so once again I mean you can improve the uiu as much as you want my task was to explain you each and everything like how to fesh the data and how to use the information of the API in a meaningful manner in your application right so I mean that's the summary of what we did how we did my view holder class you already saw how we created it this is to just you know hold the view like we had four information and we we created it we declared it we initialized it and that's all about recycl View and adapter to summarize these were the steps for the part two like in part one we had five steps when we were fetching the data from the API in this case when we had to populate the data in a meaningful manner we use the concept of recycl view and for that the most important thing is adapter just practice creating recycler view adapter for very small small project projects once you'll be comfortable doing that you can easily create adapter for the big projects as well like when you are dealing with apis music API shopping API any such thing I would highly encourage like if you have let's say array of data list of data just try to put it in kind of some recycler view or to start with list view also works I'll try to put Links of some of the easy to follow tutorials which you can follow step by step to create some quick and easy projects around recycler View and then step number two we just linked the adapter with the recycler view linking of recycler view with the adapter which we did in the main activity inside the on response method so in this tutorial if you have any doubts any queries drop them in the comment section below I will be happy to answer them if you are facing any bugs around recycl view if you are facing difficulty how to create adapter or in any of the methods anything just tell in the comment section and I will be there to answer your doubts if you like the tutorial make sure you hit the like button and also subscribe to scala's YouTube channel for more such insightful content
Info
Channel: SCALER
Views: 22,202
Rating: undefined out of 5
Keywords: Kotlin, kotlin tutorial, android development, kotlin android development, android app development, android development course, android developer, android development tutorial, android development full course, android development for beginners, how to become android developer, android, java vs kotlin, kotlin tutorial for beginners, learn kotlin, kotlin course, programming, kotlin programming, Saumya Singh, Scaler, Scaler academy, kotlin programming language, kotlin android
Id: mOYN9HlfTgo
Channel Id: undefined
Length: 357min 47sec (21467 seconds)
Published: Tue Oct 31 2023
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.