Transcript for:
Types of Programming Languages

hey everyone welcome back to the channel and in this video we are learning about types of languages this is important in order to understand you know when we will be doing like data structures algorithms and even though we'll be doing it in java you have to you know have a basic idea about what all these things are and what type of languages you are working with be that java python or c plus plus so without further ado let's just jump right into it you know computers like internally like you know at the very minute details it's just bunch of zeros and ones okay binary numbers and we'll look more into like how binary numbers are actually stored in memory and whatever you know how we convert normal decimals to binaries and all these other things the memory management all of these things will be covered in the future lectures speaking of programming languages what are programming languages programming languages allow us to you know we have some idea and we write that in form of a code and we get the output for that like whatever you want to do let's say you want to you know create a function or let's say not if i if you don't if you're not aware of functions let's say you want to create a program okay that takes input of all the students in your class okay or let's say you want to create a program that gives you the table of two or you want to create a program that just you know gives you a nice message like hi how are you and good morning and all these things so we can do that via like programming languages and um programming language is basically as i mentioned earlier like internally at the very minute details it's just a bunch of zeros and ones so when you are executing these instructions like you're instructing your computer hey computer please uh please you know um do this thing for me or tell me the time or hey computer please uh you know this is a program that i have for you like uh please print the you know date for today so these are basically just instructions that your cpu is giving like you know you're giving to your computers and computers contains all these things like there's a cpu there's a ram and how these how all these things work we'll look into uh later on so internally if it's just zeros and ones and uh instructions that you're giving to your computer it would be very difficult to write all these instructions in just zeros and ones okay there is a reason we have like programming languages that allows us to write all of these programs like okay computer do this take this output this perform this calculate this and do all these things that is the reason we have programming languages that we can write it in a human readable format in a human readable format internally computer is going to translate it in a bunch of zeros and ones a computer is problem not my problem okay cool let's look at the type of languages that we may have you might have heard about so many languages java c c plus plus python no and so many other languages the first one we are going to look into is called procedural language now procedural language like very initial you know years of programming as you can see on the screen it specifies a series of well-structured steps and procedures to compose a program now we can do this in you know it contains like uh an order of statements functions and commands to complete a task so for example it can be like hey first you have to input a number then you have to input the second number then you have to add the sum of that and then you have to print that you can also you know see you can see this flow of structure that is going is it at any point of time going to be input a number take the sum of the two numbers then input the second number it will not happen like that right you definitely need two numbers and then only you will do the sum so you can see the series of steps that are happening this can happen in many ways it can be loops if you don't know what loops are don't worry you can do this like in your statements cases functions so many other commands basically the idea is to complete a task like that now you might be wondering hey kunal so many languages do this i am personally let's say not let's say you might be like hey i don't let's say know that much about know all the languages but i'm pretty sure many languages do this and you are correct you are correct java does this python does this c plus plus does this so can we say like java c plus plus and python and all these other languages they follow the procedural language um the the properties of this most definitely they do all right now let's look at the next language next next type of language is the functional language functional language what is it so writing a pro program only in pure functions if you don't know what functions are do not worry we have a separate module for that later in the course functions are basically in simple language whenever i say this thing right whenever i say in simple language during the course that basically means understand what it's doing ignore how it's doing it because it will be covered later in the course if you want to google yourself you can do that for now just ignore how it's doing it because that is a separate module in the course functions is basically you bundle a code together in a particular you know let's say something and you can use that and reuse that many many times if someone asks you hey kunal uh you have 10 files 10 programming files or whatever and in every file you have to you know take two numbers in sum them and print the sum does it make sense that i write this program again and again for 10 files i can just write this program in one file and use that particular program in every other file saves me time also will help me in changing the particular function the particular program if there's an error in the program i can just change the main one automatically all the ones will be changed rather than changing every single file functions allow us in doing that so pure functions are basically never modify the variables again if you're not aware of variables do not worry variable is simply if i'm saying a is equal to 10 so a is a variable and the value of that is 10. name is equal to kunal name is a variable value is kunal we'll look into it later on in in this particular like shortly as shortly only in the next next videos so it it is never going to modify it but only create new ones as an output or in other cases like in simple terms if i want to share with you what functional programming languages are then it can be like used in situations where we have to perform lots of different operations on the same same set of data because it's not modifying the original data it's creating new one as an output if you're like hey i am doing machine learning here's the data set that i have for you i'm like okay cool this is my data set let's play with this data set and you know create some nice algorithms and machine learning models and whatever right so we are doing these things with this data set and i am like actually utilizing that data set you know uh for various operations and it might be the case that i'm not modifying the original file it might be the case that i'm taking a copy of that data manipulating it changing its type or whatever that i'm doing another example i can give you is they also follow first class functions now what are first class functions very simple do not worry this is very simple stuff first class function i'll explain to you right now functions are basically just you know block of code that i can reuse again and again many many simple things you can do in programming languages like a is equal to 10 name is equal to kunal a is equal to b that's a b let's say a is equal to let's say let's say number variable number i i'll just write it down over here let me just write it down so if i'm saying let's say in simple programming language term i'm saying a is equal to 10 then i say b is equal to 30 and then i say c is equal to b so can you see that i reassigned c to b if i print c now if i try to get the value of c it's going to be equal to what the value of b which is 30 so the value of c is also value of b 30 do not worry about this we'll cover this later on but the important thing to note over here is can you see how i'm reassigning variables like this c to b and things like that this is basically means that if you are able to do such things with functions as well reassigning function variable name to other function you know doing all these other things that basically means that is like first class functions example for this language that follows these sorts of you know properties can be python python follows such properties python has first class functions may not be purely functional but it does follow the functional programming theories now you might be asking hey kunal you're saying python is procedural also saying it follows functionals also which one is it wait a minute let's look at object oriented what is object-oriented programming so again do not worry if you did not like get the gist of it just a basic understanding is fine do not worry if you did not get the details because we have a function section separate as a module and variables what are variables we will cover that in the next next videos in this video object-oriented programming it basically revolves around objects now what is object the idea is that code the code file that the code that we have plus the data if you combine these two together it forms an object what do i mean by an object let's say you are like hey kunal um can you please collect us a data for me of 10 people that contains the role numbers of those people okay that's a problem statement what is the type of this data going to be forget programming what is the type of role number going to be in simple terms integer integer let's say hey kunal create a collection of data that contains names of all the students what is the type of this data going to be string alphabets letters you're like hey kunal create a collection of data that contains all the addresses of people what is the type of this is going to be maybe like a it's going to be like a string or a paragraph you know what is the type of all the collections of all the people the marks of all the people the cgpa going to be decimal numbers some cgpa 9.5 9.2 9.1 8.7 whatever now you might be asking another question hey create a collection of data of all the students where each student has let's say three properties name roll number and marks now you get confused okay what is the data type of this going to be now what is the data of each student going to be of which type is it going to be string because we are containing names is it going to be the integer because we are storing the integer like the roll number is it going to be decimal point because we are storing the marks we are storing all of these different types of data types so what is one single data type that can be of a student it can be a custom data type which we can specify using classes do not worry about what if you don't know what classes are classes in simple terms is this only named group of properties and functions someone is saying create a separate data type like a type of data for student you're like okay this is neither an integer nor a string or alphabets nor a decimal because it is collection of all this collection of all is called a class okay so and an instance of this class is called an object so for example i am of class human we all are of class human but i am an object of class human i'm a running i'm an instance of that class a class is like a template a property we all know humans have a few properties two eyes one nose one mouth two ears two hands two legs this is a property a template using this template god has created many objects we we are actually objects we are actually the the memory inside your ram you know when you say a is equal to 10 a is actually the variable 10 is actually the object that is the thing that is actually in the memory we'll talk more about that later do not worry but i hope you are able to understand the difference between classes and object we'll cover that later on classes objective programming is a separate section but in order to make you understand what object-oriented programming you know is in type of languages it's basically dividing our code into various chunks so that it makes it easy for us to develop debug reuse and maintain the software for example if you want to create a function or sorry not a function a program a program computer program that has information about your car it can have many information what is the color how what what is the type of the car supercar or what is the you know how many engine does it has or what is the type of the engine okay so many things let's say in your program now you want to change the type of the engine you're saying hey i want to change it from diesel to petrol or petrol to diesel or from fuel to electrical does it really make sense to change the entire car when you go to your car mechanic and you want to get that you know some parts changed do they change the entire car or just change that particular part they change that particular part if we divide the entire program also in these parts engine has an a separate code base steering wheel has a separate code base you know other properties have separate code bases if you want to make a change in that entire program just change that simple part of the program that is what i mean by like object-oriented simple terms so i'm trying to explain it as simple as you can as i can do not worry about how these things are working do not worry about it ignore it because it will be covered later on in detail ignore what is happening just understand what these things are ignore how it's happening okay now java supports object-oriented principles okay we can create objects and like classes and all these nice nice structures that i told you about like entire student structure or whatever python also supports this c plus also supports this i might be asking hey kunal you're saying java supports both procedural and object oriented python supports all the three c plus plus also supports object-oriented and procedural are these languages all the types of languages the correct answer is yes like a particular language if it's object oriented it does not mean that it will not follow procedural you know fundamentals procedural rules or functional rules java for example follows object oriented and procedural c we have that follows procedural c plus plus we have that follows like you know procedural we can also do like some functional programming that was as well it also follows objective programming python you know follows procedural functional object oriented so this idea that one particular language can only be of one type that is not correct okay that is not correct it's like hybrid sort of like structure follow many many other theories and that's basically about the types of languages we are learning java so we'll be doing heavily focused on object-oriented principles this is also very very important for your you know interviews and stuff object-oriented we will do in very detail and so many properties inheritance polymorphism abstraction encapsulation everything will be done in detail do not worry about it that was a basic understanding of this thing let's move forward another types that you might encounter are known as static versus dynamic languages let's look into what is static and dynamic language let me create a yeah okay let me just write this thing over here so you are able to see i think we all can see this now cool okay just looks good so speaking of static versus dynamic languages this is based on that was based on like the mem like the the previous three points that we had were like structure of the you know how we write code and how things are structured and everything what are static versus dynamic languages static languages before moving forward to that we gave the student example right so i can say i have something like name is equal to kunal something like this okay now here you can see when i write name is equal to kunal the name the type of this variable that we have over here is string like letters and alphabets right if i say something like roll number is equal to 56 this is of type integer okay if i write something like marks is equal to 93.6 this is of type decimal or float now there are two ways to approach this problem like the problem is that how do we know which type how does the programming language know what is the type of these variables okay how does the programming language know that so the basic idea over here is that there are two ways to do this one is the static and one is the dynamic what is static type checking is you know performing the type checking it does the type checking at compile time so what do i mean by compile time remember when i mentioned that we write the program in programming languages and computer will you know compile that and or interpret that in whatever sense and convert it into the machine readable format like zeros and ones or whatever assembly or whatever so that the computer can understand this this conversion is known as compilation your source code the code that you will be writing in java or c plus plus or whatever that gets convert to machine code that machine can read and then machine will read that code this is known as compilation of your program so when you're writing a is equal to 10 for example there are two ways to do this when the compilation is done and when the program is running that time if the programming language is like okay this is integer that is dynamic language entire program is run it is being converted to machine language and now programming language is like okay program is running the value of a is equal to 10 so a is an integer program is running the value of a is equal to kunal so so value of name is equal to kunal sorry name is equal to kunal so name has a type of let's say string or alphabets or letters or whatever okay this is known as dynamic language where you do not have to worry about specifying the type previously so you don't have to tell the programming language like hey i am giving you a variable a which is of type integer like int a is equal to 10. what is happening in this case this is statically typed here while the program is compiling while it's converting your source code the code you have written in machine code during that conversion time the programming language should know what is the type of a during that time so the type checking here it is done at compile time while the thing is compiling so you can see this left hand side thing what is happening is compile whatever happens here in the right hand side of the equal to is runtime this is the actual thing that is stored in the object and this is the actual object that is stored in the memory to understand more about this in detail watch the next lecture i'll cover it in detail what are the memories and how the reference variables and everything is working in the next detail for now just imagine that this is a variable a it has a type that is equal to whatever type it's equal to in simple case again do not worry how it's working because that is coming in the next lecture okay so in static type languages if i'm saying you have an integer a the value is equal to kunal is this possible is this kunal thing that i have on the right hand side is really an integer no it's a string it's letters and you know characters this will give me an error error while my program will be compiling it will be like hey you mentioned a is integer but you're giving string error so errors will show at compile time okay i hope the first point is clear type checking at runtime and then static type checking at compile time what is runtime when the program is running after the compilation period okay once the program has been converted into machine code and when that machine code is running that's basically when the runtime thing is happening okay very simple stuff okay when you write a is equal to 10 okay let's say this is dynamic language i'm not specifying a is equal to 10 i'm like when you run this program you figure it out yourself that is what i'm saying to the language so in this case it will be like okay when the program is running so when first it will compile and then in the runtime like if i look at the memories and everything 10 will actually be stored in some memory or ram a will be pointing to that all these things we'll look into it in the next lecture but here let's say if we do let's look at the second point now so error will show at compile time or i already showed you if i do something like you know something like string a is equal to 10 or not a something like i can do int a is equal to kunal error kunal is not an integer and you are specifying it as integer error at compile time let's see how we can get an error in the dynamic languages let's say you do a is equal to 10 this will work perfectly fine this will work perfectly fine you know and uh here you may say that um another possibility can be a is equal to in the next line i can say of the code kunal first a was integer now a is kunal is it going to give an error pause this video and think to yourself in dynamic languages where type is not specified beforehand type is only calculated after the you know the in the during the run time in python for example okay if you said yes then that's not correct actually it will not give an error okay why it will not give an error watch the next video it's basically an object and references thing and it's uh actually like first the value was 10 and then the value is going to point towards kunal string because at the compile time it does not really care about the type so it can definitely change things like that okay first a was pointing to 10 then a will be pointing to kunal then a will be pointing to 13.5 whatever now float or decimals you want but this will give an error in static languages here i have specified a is equal to 10 there is a rule associated to it in the next line if i do a is equal to kunal this will give an error in static languages okay so when it's compiling it will be like hey you said a is equal to 10 which is an integer but in the next line you are assigning it a string this is an error you can definitely do something like this okay so that's like error will show at compile time error might not show till the program is run so in this case it can be something like if you do you know if you're doing something like a plus 10 so you are adding a string and a number this will give an error okay we'll talk more about this later on now declaring the data type before you use it we already covered this in a is equal to 10 like a is type integer value is 10 declaring the data type before we actually use it no need to declare the data type now what are the advantages disadvantages more control okay you have to write a little bit more code but you have more control over the you know type data run time errors are reduced and in dynamic languages no need to specify the type or anything so just saves time in writing code but it might give error at runtime that was pretty much about it and we'll cover more about the memory management and all these things in the next video now let's answer a few questions that you might be having right you might not know what are variables you might not know how the objects are working internally what all this memory thing that i'm talking about so let's answer that let's take the very very simple stuff like the very simple stuff if you write in a programming language something like a is equal to 10 as simple as it gets i'm just writing a is equal to 10 over here let's dive deep into how this thing is working so when you're talking about memory management right there are two types of memories here in your computer you know programming languages one is the stack memory one is the heap memory okay so this is the stack memory and this is the heap memory and when you write in your programming language when you write something like this a is equal to 10 when you write something like this this a is known as what reference variable and this 10 is known as what object a is not the object many people say is the object no a is the reference variable 10 is the object how is this stored in memory then your variables and function calls and whatever like for now let's just say variables they are stored in the stack and the actual object that is in the memory like the actual value of that object that is stored in heap in this memory let's say in its ram or whatever and a is going to be pointing towards that object so when you're saying hey give me the value of a it's going to say it's 10 how it's going to see a is here what is a pointing towards a is pointing to 10 this a is going to point to the address of this particular thing you know every object and stuff has an address in the memory like some some address in some ram or whatever very nice computer science is very fascinating in simple terms this is how it works so you have a is equal to 10 a is a variable in stack memory pointing towards the object in heap memory the stack and heap and everything is just memory management how they are done in like computer like scientists and stuff they have computer scientists they have you know made these things like there's a stack memory heap memory this thing will be much more clear when we'll be doing like recursion and stuff for now this is as simple as it gets it's not like a separate hardware piece in your pc okay it's just how memory is managed it's how memory is managed so a is in the stack memory pointing towards the heap memory heap is let's say another section of your memory or ram or whatever hard disk and there's a heap memory allocation over there in your you know it sometimes there's also like some if you talk about cpus they also have some memories they have registers and stuff but we don't have to go in too much detail simple terms variables in stack memory pointing towards the object in heap memory that is simple but that is not what i am trying to make you understand here i am trying to make you understand how these things are working and how this is going to help us what is the actual meaning of object what is the actual meaning of reference variable let's look into that this is the best example and it will make things very very clear so now we are answering the very important question he the object and memory and reference variable all these things previously i mentioned that i am an object for by far you should know that the reference variable is just like the variable and the actual value of that variable is in the object i'll repeat it again variable does not a is not the actual value of 10 in a is equal to 10 10 is actually in the memory in the heap memory a is just pointing towards that for example i am kunal my object is my body this is a physical object in the memory of this of this world this is this is the object kunal object when i'm saying name is equal to kunal okay so this object kunal this is a object on an actual object you might i might ask you hey what is the type of this object kunal human we are all of class human so objects have a type and we can define those via classes we'll look more into that later on so this is the object in the memory in the heap memory okay this is in the heap memory the object if you want to call this object if you want to call my myself my my physical self how do you call me you call me via my name so you can say kunal this is the reference variable pointing to this object so if kunal is giving a party okay so we'll just say kunal pay the bill kunal will pay the pill and this objects bill account will be reduced like this objects money will be spent let's say my mom also calls me something she does not call me kunal she calls me son son is also the same person if you are calling me you will call me kunal if my call if my mom let's say only my mom if let's say my mom calls me kunal same person is being called if my mom calls me son same person is being called if my sister calls me brother same person is being called so if kunal is giving a party or son is giving a party or brother is giving a party let's say in a hypothetical world i might have a girlfriend might call me baby if baby is giving a party money is being spent of the original object only just one object it's not like there are four canals for these four people what am i trying to make you understand with this if you write something like a is equal to 10 b is equal to 37.5 or whatever you buy now you know these are objects these are reference variables these are in heap memory these are the actual objects and these are in the stack memory that are just pointing towards these objects what am i trying to make you understand with this example then the thing i'm trying to make you understand is one object or more than one this is what i'm trying to make you understand listen very carefully more than one reference variables can point to the same object point number one pointer number two if any one of these reference variables change the object original object is going to be changed and it is going to be changed for all if sun gets a haircut then if br if if if uh if son gets the haircut then baby also gets the haircut right okay if if my mom told me to get a haircut it's not like my sister will not see that haircut even though the change was made via this reference variable original object was changed and since all of these other variables are also pointing towards the original object the change is going to be visible to all these variables this is how it sort of like functions in like java and python as well so in the future we will be looking into like some concepts like pass by reference pass by value you know might have heard in c plus java does not have this thing it only has pass by objects value sorry not objects value pass by reference value okay it does not have like value or anything pass by reference value that it's there in java only we'll talk more about that later okay how these things are internally working but what it's doing are you able to understand if i'm saying there's a list something like this let's say let's say simple python example let's say i say a is equal to a list which is like 1 3 5 9 or whatever and then i say b is equal to a what is happening internally this is happening internally list is nothing but a collection of uh numbers or you know elements you can you might have also heard it like in areas or whatever okay let's say this is array forget about programming language let's say this is an array in you know java or python so actually internally all of you know this is in stack memory pointing towards this which is 1 3 5 9 b is pointing to a means whatever a is pointing to b will also point to that very simple stuff now if you make a change via a if you say the 0th element of whatever a is pointing to should be 99 this will be changed to 99 very simple stuff now when you display output b my question to you is is b also going to show this updated 99 or is it going to show the original one pause for a minute and think about it if you said that it will also update 99 that is true because the answer is in front of your eyes b is also pointing to the same object so if this simple terms are repeated again if the object was changed via one reference variable then this change will also be visible to all the other reference variables that are pointing to the same object okay there are more things we'll consider mutability immutability later on but this is just like a simple example that i'm giving you okay don't worry we'll we'll cover mutability like how we can modify and all these things objects and sometimes it may show sometimes we may not show but this is the theory i wanted to show you i noticed you were not able to see but i i just wrote output b only okay that's it output b was only thing written you did not miss out on anything one more thing i want to share with you it's another important thing which is what happens when there is no reference variable to the object say it's my name is kunal reference variable to something this is my body okay my object now someone calls me baby same object let's say a third person came let's say um i don't know um this is a hypothetical situation by the way trying to make you understand so you know i can either be called kunal or baby so if you call me by canal or she calls me by a baby same person is being called okay let's say there comes another person and let's say this person's name is another object so this name is adam levine or whatever adam levine is married let's take some other example who is a popular celebrity who is not married um or i can just take some random name uh random name okay alex or alex or alex zan alexander or something okay this new guy comes and now let's say baby now points towards alexander okay let's say kunal is not the baby anymore okay so if alexander is called the same person will be called now baby will be called all the changes made by a baby variable will be in this object now okay let's say kunal now gets upset like i'm not the baby anymore okay so what happens to kunal is that kunal goes into the forest and like leaves the material world and everything and gives up his name okay so now there is no more name kunal even there is no name of this person now this person is living alone in the forest okay so when this is an object what is happening this is an object with no reference variable there is no reference variable to this object meaning there is no variable that is pointing towards this object so this will be removed from the memory when garbage collection hits so in java there is something known as garbage collection in very simple terms what is garbage collection very simple terms garbage collection means that objects that do not have a reference variable pointing towards them like this example no one is pointing to this object when the garbage collection hits it it is it hits automatically okay when it feels like it needs to free the memory in that case all the all the objects that do not have a variable pointing to them they will be removed from the memory deleted that happens automatically we'll we'll look more into that later on how we can you know perform some functions when garbage collection is hit in object 20 programming we look into later on there's a finalize final finalize on whatever okay so if you're doing something like a is equal to 10 so this basically means uh a is pointing to an object 10 then you say a is equal to 37 now a will be pointing towards 37 okay what happens to this 10 no one is pointing to 10 garbage collection will come and remove it yam raj if you can get that reference okay one last thing i wanted to share was in like uh previous example i mentioned something regarding the dynamically type languages so why is this thing working so if i say something in dynamic type language that in python for example if i say a is equal to 10 then i say a is equal to kunal this will not give an error in dynamic languages where the type is decided compile at runtime hours this is working internally now you might be knowing a is pointing towards 10 a is equal to kunal now another object will be formed kunal a will be now pointing to this this will be removed when garbage collection hits that's how python works very simple stuff that's the entire idea of objects and you know things and we'll go more into details of this when we're learning about classes objective and programming but this is the general idea of memory management some simple simple data types we look into next lecture is like the integer and like character and like booleans very simple stuff like int a is equal to 10 just created an integer a value 10 this is the object this is a reference variable this is in stack this is in heap this is pointing to this that's it if you did if you say something like output the value of a it will actually see where it's pointing and get that value and print this for us if you say a plus b what is equal to c is equal to a plus b this will get the value from heap this will get the value from heap combine it and add a value in another another variable this also will be in heap all the objects are in heap nothing to think about here very simple stuff all right thanks a lot for watching and we will see you in the next video make sure you like share and subscribe and check out the links in the description as well [Music]