Complete Java Programming from Java Basics to Advanced Java. Learn Java Programming from Scratch. | Muhammad Hamza AbdulRehman | Skillshare

Playback Speed


  • 0.5x
  • 1x (Normal)
  • 1.25x
  • 1.5x
  • 2x

Complete Java Programming from Java Basics to Advanced Java. Learn Java Programming from Scratch.

teacher avatar Muhammad Hamza AbdulRehman

Watch this class and thousands more

Get unlimited access to every class
Taught by industry leaders & working professionals
Topics include illustration, design, photography, and more

Watch this class and thousands more

Get unlimited access to every class
Taught by industry leaders & working professionals
Topics include illustration, design, photography, and more

Lessons in This Class

32 Lessons (1h 53m)
    • 1. CE JAVA

      1:21
    • 2. Code editor download

      0:47
    • 3. Important interview questions

      0:23
    • 4. Is Java platform independent

      3:01
    • 5. JDK JRE and JVM

      2:14
    • 6. JIT Just in time

      0:40
    • 7. Introduction To Data Types

      3:48
    • 8. Printing Data Types

      2:17
    • 9. Getting user input

      7:11
    • 10. Array Explanation

      1:38
    • 11. Array Code

      4:10
    • 12. For Loop

      6:03
    • 13. While Loop

      2:30
    • 14. Infinite while loop

      1:31
    • 15. Try Catch Exception

      5:53
    • 16. Exception types

      0:43
    • 17. Finally

      1:54
    • 18. What are functions

      1:54
    • 19. Scope Of a Variable

      2:43
    • 20. Class and Object

      3:51
    • 21. What is Class

      5:51
    • 22. Constructor

      7:47
    • 23. Difference between Heap and Stack Memory

      1:54
    • 24. Inheritance Explanation

      3:18
    • 25. Inheritance Code

      11:56
    • 26. Polymorphism Explanation

      3:34
    • 27. Polymorphism Code

      8:44
    • 28. Overloading vs Overriding

      4:09
    • 29. Abstraction And Interfaces

      1:54
    • 30. Types of abstraction in java

      1:01
    • 31. Abstract Class Code

      4:56
    • 32. General idea of Abstraction

      3:15
  • --
  • Beginner level
  • Intermediate level
  • Advanced level
  • All levels
  • Beg/Int level
  • Int/Adv level

Community Generated

The level is determined by a majority opinion of students who have reviewed this class. The teacher's recommendation is shown until at least 5 student responses are collected.

--

Students

--

Projects

About This Class

This course covers Java programming all the way from Basics to Advanced topics like Object Oriented Programming.
In this course we will cover:

Datatypes in java

Function

Loops

Arrays

And much more

 In Advanced section we will cover:

Object Oriented Programming

Inheritance

Polymorphism

Abstraction

Class Ratings

Expectations Met?
  • Exceeded!
    0%
  • Yes
    0%
  • Somewhat
    0%
  • Not really
    0%
Reviews Archive

In October 2018, we updated our review system to improve the way we collect feedback. Below are the reviews written before that update.

Why Join Skillshare?

Take award-winning Skillshare Original Classes

Each class has short lessons, hands-on projects

Your membership supports Skillshare teachers

Learn From Anywhere

Take classes on the go with the Skillshare app. Stream or download to watch on the plane, the subway, or wherever you learn best.

Transcripts

1. CE JAVA: Salam Ali, go hide their peace and blessings be upon UDL students. I welcome you to this complete Java programming course. This course is for students want to learn Java programming all the way from basic to advanced level. So in this course we will start from the very basics and we will go to the advanced level topics that we will cover. So starting from basics, all the basics like for loops and conditionals and other. So in the advanced section, we will learn about classes and objects, which is a very important concept and its core importance in other languages as well. We will also learn about inheritance and encapsulation that is very important in object oriented programming. So we will also cover the basics like loops, functions, areas, and many more. Data will help you build your starting point of Java programming. And you're going to apply these concepts on other languages as well. So the thing, the skills you acquire and discourse are not only restricted to Java program and you can apply them in other languages as well. So I'm looking forward to see you in this course. Let's start this journey. My name is Jose and I will be your instructor of this course. Thank you so much. 2. Code editor download: Welcome. In this course I will be using Eclipse IDE for writing Java code. You can use any ID of your choice, but in this course are to be using Eclipse ID. So you can simply get this ID from writing eclipse, Java and Google and then going to this link that is Eclipse dot o RG. And here you can find the download links if you will go in Eclipse packages. Here you can download Eclipse IDE for Java Developers, Windows, Mac, and Linux as per your requirement, and then you can follow the steps. It will also ask you to download JDK dead. You can simply download and install. And I will also be telling you more about JDK in upcoming lectures. So you can get Eclipse from here and write code in it. That's all from this session. 3. Important interview questions: Welcome. These are the three very important to interview questions and sometimes they become very confusing if we do not have a good understanding of each of them. So is Java platform independent? What our JDK, JRE and JVM, what is GID? So in the coming lectures, I will be explaining these in a bit detail so that you can have good understanding of these topics. 4. Is Java platform independent: Welcome. In this session we will learn about an important interview question which is, is Java platform independent? The answer to that is yes, Java is platform independent. Let's see how the code which rewrite is human understandable. We can easily understand our code. It is in human understandable form, but computer can not understand that core because machine on the understand zeros and ones. So there is a process that converts our human understandable code to machine understandable code. And dad can have a few steps that converts this code. So we have different operating systems, which is Windows, Mac, and Linux, and they all are different from each other. But when we write a Java code, it is platform independent and we can run it on all major platforms. But there is some process involved which makes this possible. So how we can run our Java code on multiple platforms. First of all, we have to write a Java code. On the left you can see we have a Java course, so this is our code which we write. Then it has to go through a process called compilation. So what compiler does is it has a set of rules by which it converts our code into machine understandable form. But in case of Java, compiler converts it into bytecode. Bytecode is an intermediate form of gold, which is not directly understandable by Windows, Mac, or Linux operating system, but it is an intermediate form and it is an a dot class file. So we have to give this bytecode to JVM of specific operating system. So if we have to convert it into a Windows program, we will give it to the JVM of windows. Jvm java virtual machine is responsible for converting bytecode into operating system understandable or machine understandable native code. So JVM is platform dependent. As we have different JVMs for Windows, Mac, and Linux, one JVM cannot work for all the platforms. So the bytecode which we have is given to JVM, and then it runs our program in our desired platform, which makes Java platform independent. No matter what platform is, we just need to give this bytecode which compiler makes to the JVM and we can run. So that's it. Good benefit of Java that it's portable. So on the left side you can, now I will tell you how Java is different from C and C plus, plus, because C and C plus plus is platform dependent. So when we combine Java, it is converted into bytecode. And then each JVM of different platform can run this bytecode. But when you run a C, C plus plus code, when you compile it, it is directly converted into dot EXE file for Windows. So if we are working on Windows, EXE file will be made and it will only be executable on Windows. And this will happen for different platforms. We have to make their own files for the different platforms, which makes C, C Plus Plus platform dependent. So dad is a great benefit of Java that it is a platform independent language. So that's all from this session. 5. JDK JRE and JVM: Welcome. In this session we will discuss an important interview question that is, what does JDK JRE and JVM, JDK Java Development Kit is it don't get that provide us with all the necessary components that are required for the job up a ramp to be built. That is compiler linker, debugger, class libraries, and all of those components that are responsible for converting our human understandable code into machine understandable code. So this is a process of converting human understandable code into machine understandable cord. So JDK has a compiler that compiles our code and make a bytecode out of it. So bytecode is an intermediate file that we have which makes Java platform independent. So when compiler compiles and gives us a bytecode, it hands it over to JRE, which stands for Java Runtime Environment. And Java Runtime Environment uses JVM java virtual machine for processing this bytecode. So what basically is GRE? Gre is an implementation of JVM. So it provides the necessary components that are required for Java Virtual Machine can fork. So basically the main thing that does this process of converting bytecode into machine code is JVM, and it is a very important component. So JRE provides us with this component. And GDK on the whole is if top-level get debt has all these things, we can also separately don't know GRE and provided with any bytecode so it can convert it into machine code. But JDK has all these things by default. And JDK Java Development Kit is platform dependent, which means that we need to install separate GOD gives for Mac, Windows and Linux operating systems. So we have to have a separate GDP for all of these. So the idea here is JDK Java Development Kit, the toolkit that provides us with all the components that are necessary for the program to build. And the compiler in JDK converts our code into bytecode. And JVM is responsible for converting debt byte code into machine good. And who were white US with the JVM, that is JRE Java runtime environment for whites as JVM. So it has to implementation of JVM. So that's all from decision. 6. JIT Just in time: So now we are aware of the process of a Java program. So here comes the JID. Jit stands for just-in-time compiler. And it has the responsibility of improving the process of converting a bytecode into machine code. So when JVM is processed in the bytecode and converting it into machine board. It is done in the Java Runtime Environment. So GID comes in and optimizes its performance. There are multiple ways by which GID does that. So, but the main task of GID is to optimize the process and convert Bytecode into machine code. That's all from this session. 7. Introduction To Data Types: Welcome to this first coding session of learning Java programming. So I'm in code editor and this is Eclipse code editor. You can use any code editor of your choice that depends on you. Our focus in this course will be to learn programming. So you can write that code anywhere in any editor or online. So this is Eclipse code editor and I have a project launched air learn Java. You can first of all make a project here. And now I will add a file in this project so that I can write gold there. So in New, I will add a class here. I have to provide a name of this class. I will write me in class. And after I press Finish, it shows me a main class here. So what is this class? We will get into the details of this when we go to object oriented programming in our future sessions. So for now I will just show you the space in which we will be writing code for a few sessions here. So this is a function mean I have here. Every Java program starts from a main function. You can think of a mean function as a starting point as when you enter into your house, there is a main gate or a main door, or a main entrance from here you enter into the house. So everything needs to have a starting place in Java programming, and in most of the programming languages we have the starting point named mean. So we need to have this here. Main is a function and I will get into the details of functions when we go to the session where we will be discussing about functions. So for now, all the code we will be writing this in this function main and other details like this string, arguments and this public and static we will get into the details later. So for now in this first session, we will learn about numbers and variables. For every Java program we are, we have a need for numbers and strings. So what are numbers? For example, if I have a number 60, how I can use this, I have to store this in some variable. Let's say I make a variable int as it is an integer. So we have a few data types like integer, string and a lot of more. So we will be discussing them. Int keyword is used for integer values. After specifying this datatype, I have to provide the name of this value which are heavier debt can be offered twice. So let's say I name it 60. I can name it anything, but I named it 60 for better understanding. Every Java statement. After it completes, we add the semicolon sign. So this indicates that this line is finished now. So now we have the 60 value inside this variable named 60 that we can use in our code. To add a decimal point value in a variable we used a datatype name double. So integer is for values that are without decimal point and double is for values that we have a decimal point. So let's say I have a value, I can name it anything number, and I can add a value, let's say 55 year. So this datatype double will be used for the values like whichever decimal point here. And without decimal point we have datatype name integer. So these are reserved words like integer and double. We cannot use them as a variable name. The 60 and number here. This one is a variable in which, which is holding these values. Now whenever I want to use this particular value, 60 or 5.5, I have to use this variable name. So for a string, for any text that we want to store, we have a datatype name string. So string is a datatype name. After that I have to specify the variable name. So let's say I am saying this is a name of some person. So what will be the value? Any depth that goes inside of these courts will be stored in this variable named name. So let's say I have comes out here. So now this name variable is a string datatype that has a value Hamza. So these values now can be used in our code, any of your reward. So in this session we have learned about data types and variables and how to store values in these. So that's all from this session. 8. Printing Data Types: Welcome. In this session, I will show you how to run a Java program and show something in console window. Oval window is the output window where our program reserves will be shown. So to show something, to print something in the console window, what we use here is a command named System.out.print. So I will show you system dot out dot print. So what we have to do here is we have to write the thing which we want in the output window to be placed between these quotes. So I will write my first java programs. So I have written this string here between these course that my first Java program, and it will be printed in the console window as it is to, this is the command system.out.print that we are using that will tell this program that the thing which we are having next should be printed as it is. So I will run this program. To run this, there is a green arrow button on the top, as you can see here, which says run main class. So when I will press this, it will run this code and it will get into this main function and we'll start reading life. First of all, it will read this 63, the number, name, and then finally it will reach this and it would print it out. So as you can see, the console window pops up and it says my first Java program. So our result is shown if I will change this string cleansing else, it will print that. Now what I can do here is by using this string which I have written. I can also use the strings which we have there already. As you can see, this string name is already there. So what I have to do, if I want to use this variable, then I don't have to write courts, I will directly write the name of this variable that is name. And it will print whatever this name has currently it has humps OS or it will print Hamza. As you can see, I run it again and it prints homes on the screen at it. If I change this string content, it will bring that. So if I write anything else here or like ABC I added. So you will see that in the output it bring sums are ABC. So if I want to print an integer or a double value, then the procedure is same. I simply have to use the variable name. So if I use number here, it will bring 5.5. As you can see it bring to 5.5 because we printed the number here. 9. Getting user input: Welcome. In this session, I will guide you how to take user input. A lot of time there is a requirement of getting some input from user. For example, if you want to get the name of a person. Or there are a lot of things that we want our interactive software to get data from or user. So our user of our software many times has to enter that data. So how we can get that data is by using, there are a lot of ways that we can get data from our user. I will show you one of the way here, and I'm in code editor, so let's start. So I will give you an example of if you want to get the name of a person, if you want to get any string from the user. So what we will do, first of all, we will ask the user to enter that string. So data is same of system.out.print. And here we will ask the user enter your name. So when the user enters his name, we have to get that into some variable. I will create that variable here, like string name. Now this variable name will be having dad name which the user enters. But how we get that name here in this name variable, we use a class scanner. I will name it. I will get into the detail after writing this line is equals to num System.in. Okay, I have written a lot of code here and it shows me error as well. So when I go into this error, it says import scanner dot Java.util. So I would say yes, import this. So it has imported, as you can see, a Scanner class here. So what is this? What is class? So class is a topic that we will be discussing in our advanced section of this course. So when we move ahead, we will be learning about classes and objects. For now. To make it simpler, we will just know that how we can get the input irrespective of what we're writing here. So this is a must case that we have to make an object of the Scanner class all the time when we want to take the input. But what is the Scanner class and what is this library? We will be discussing it in detail in our upcoming sections of advanced bar. So there we will be discussing about classes and objects in detail. That is a very important part of object-oriented programming. For now, what we're doing here is we're getting the Scanner class from this library here. So what is library? Library? You can think of a library is having a lot of ready-made code. That is, we can use for, if, let's take a scenario that we are, we have to get the input from user for data, you have to write a lot of code to make that thing happen. How we can connect the console window with that. So we had these ready-made glosses that we can choose by the Java here. So java dot util dot scanner is a library that we are using to get our task done. And in future we will be using a lot of more as well. So this is very important. So now we have the scanner and this is the syntax of how we write. This is the object scanner that we will be using for taking the input. Now next thing is that we get that value in this name variable. So I have to write the name variable here name is equals to after data. We write this scanner object, scanner and dot operator. As you can see, intellisense, this is intellisense, which is showing us that what functions we can perform on this. So there are a lot of functions that we can perform, but the function of our requirement is next. So as you can see when I written next, it shows me multiple options here. So we will be using the first one, which is for the string. So what is for the integer? I will get into the details now. So now by using this Next we are storing the name here in this name variable. So first of all, it gets to this line. It asks the user to enter his name, then it makes the object of Scanner class. And here it will stop. It will stop for the user to input his name. So when the user will input is name, it will put that name here in this name variable. So this thing makes the quote to stop and takes the user input. Next, what we will do, we will display all the thing that is required for taking input is done, but we will show that on screen as well so that you know that it is correctly done in the name variable. So I will use system command here again. So what we will do here is v will say your name is simply and we will concatenate with the name variable here. So name variable here is concatenated with the string by using a plus sign. So this is the string which we have here. And when we want to concatenate it with the name variable, we use this plus sign. Now, I will run this. As you can see, it asks me to enter your name. I will enter, let's say Hamza. Now what it says, your name is Hamza. Now it actually got our input and displayed it here. Now whatever name I will enter here, it will display that for example, John. It says your name is John. So it is successfully done this by using the scanner class. These two lines, we have just made it get the user input. Now what if we want the age as well, so that will be integer. Now next we're going to do that. I will just repeat distinct. For after that we will say enter your age. Now the user will enter his age. Now this time we need not this class written. Again. We can use this object as we have previously defined it. Now what we have to do, we have to write this one here, but dot next is for string. So let's see what's for integer. I will make a variable here, integer age. And I will write age here. It equals to scanner dot. Next int. So next int is used for the integer values and for the double and float values we have next float double and so on for other data types as well. For now we are getting integer and that will be here in this gauge. And we will copy this statement here and we will print the age as well. Now your edges, instead of name variable, we will add AGE, year. So simply what we are doing here is we're asking the user to enter your age, and then we are getting that age by using scanner dot next int. This is the object, and after that we are just displaying that thing. So okay, I will run it now. And as you can see, it says enter your name. Let's say John. It says your name is John. After that, it asks me to enter age, let's say 20. It says your ages 20. Simply it has displayed both the values. Now what we can do here is we can just modify this by, we can ask the name then age, and after. In the end, we can place, read and print those values. So what we will do here is I will this command from here and I will print it here. And finally, we will be printing both the age and name. So what I'm doing here is these two, this command will get the name, and then I will ask the user to enter age, and we will get the age year by using this command. And finally, we will bring both the values just for the flow of this code. So enter named John. Enter your age 20. So it says your name is John urea, just 20. So we get all these values by using this and we can change the flow of our code depending upon our requirement. So in this session, we've learned how to take a user input. So that's all from this session. 10. Array Explanation: Welcome. In this session we will learn about areas. Area is a type of linear data structure where data is stored in the form of a sequence. Suppose we want to make six integer values in our code. So do store those six integer values. We need to have six integer variables to store them. Instead of those six integer variables, we can store all of them in a single array. Like if we have six values, 10, 578, 24, we can store them in a single array. Array is in the form of a sequence, so every value is at particular index. The starting index of array is 0, then the second index is 1, third is due, and so on. Area is of fixed size. So while initializing an array, we have to define the size of that array. If we initialize an array with size three, it will allocate three memory blocks for that particular array. And if you initialize an array with a size five, then it will allocate five memory blocks. For data array, we can have short and long areas depending upon our requirement. And if you initialize an array with 10, it will allocate 10 memory blocks for that particular array. We have to make arrays very intelligently because if you make an array of size 10 and we only use two blocks of it, that is, we only add two values in that particular array, then rest of the blocks will go wasted because array memory blocks or only dedicated to that particular array and cannot be used by any other variable inside of our code. So if we allocate an array with size 500 and only use few blocks of it. That is, we add only a few values in that array, then rest of them will get wasted. So we have to make an array of size that is required by that particular array. Let's learn array in details in our upcoming sessions. 11. Array Code: In this session, I will guide you how to make arrays in Java. To make an array of first of all, you have to define the data type of the array. For example, if I want the array of integers, I will specify int, and if I want the array of strings, I will write string. So first of all, we will make an array of integers. So I would write int to specify this is an array of ints and then the name of the array. So I will write array here. So I am giving a name array, then two square brackets. Then we have to initialize this array. So we will write the keyword new, and then again the datatype, and then two square brackets. And in these two square brackets, we have to define the size of the array. As we know that a ray is a static data structure, which means that it has a fixed length. So let's say I give ten here. So now I have made an array which, whose size is 10 and indexes will be from 0 to nine. So now I can add values in this area. So to add a value in an array, I will write the name of the array. And then these two records in this I will define the index number on which I, which I want the value to be. For example, the first value will be on index 0. So I will write the index 0 here, and I will make it equal to some value, let's say 50. So now at index 0 of this array, there is a value 50. So if I copy this and on index one, that is the second index of this array, I add a value 16. Similarly, on third, I will add value 70. So now in this array I have three elements, 50, 60, and 70 on indexes 01, and let it be two over 012. So now I can bring this on screen to see the value. So I can bring the value at index 0, system dot out dot print LN. So here I will specify the name of the array and then the index number. So what I'm saying here is bring the value of array at index 0. So let's run this. And as you can see, it printed 50 in the output. If I change this index from 0 to one, it will print 63. So let's run it and as you can see, it brings your 60. Similarly, if I change it to any other index, it will bring the value at that particular index. As I have made the integer array, I can also make an array of strings and other data types like double float. Now to make a string array, I will write the datatype first, that is string. I will name the array as array strings to skill records than new keyword and then again string. And then here we have to get the size, so I will give five here. So we have made an array of strings with a size of five. You can give the size of any of your choice here. So now we will add value into this area. So name of the array. Then index number is equals to, let's say I add my name here. And we can copy this to add other values. On index one, I will add some other value, let's say Alex. So now I will, in this print statement instead of Brinton, the values from Andy jury, I will try printing from the strings array. So I will change it to array strings. So I'm printing the value at index one less than the score. As you can see, on index 0, we had Hamza and our Ellipse 1. We had Alex certain printed Alex, if I change this index from one to 0, it will print comes up. So let's run it comes up. So that's all from this session, from areas. So before moving to the next session, you can try practicing this area here by using multiple datatypes like I've used in den, strings, you can use double and float as well and practice it so you will get a better understanding of areas. Thank you. 12. For Loop: Welcome. In this session we will learn about FOR loop. Loops are used when we want to repeatedly run a task over and over again. So if we want to print from one to ten on screen, what is the other way beside loop that we can use? We have to write 10 print commands there so we can minimize it too few lines by using loop. So in this session we will be learning about for loop that is one of the type of loop to write a for loop. First of all, we use a keyword for. Now, I will complete, I will write this complete statement and then I will explain that what each statement means. So I will make an integer I and put it equal to 0, then I is less than 10, I plus plus. So what I'm saying here, I will also add a print statement here, dot print and I will print I. So this is the loop that will print from 0 to nine on screen. I will run this and you can see, as you can see it printed from 0 to nine. So now I will explain Judah at how it's done. First, I have to define three things in between these two round brackets, which I have here. And dad is the backbone of this loop where we define that what this loop is going to do. So the first and these three things are separated by these semicolon signs as you can see. So everything is in between. The first statement is, as you know, we use the semicolon to end a statement. So there are these three statements, the first statement, and they are separated by semi-colon. The first statement is the starting point of our loop. We are telling our loop from where it needs to start. So if it is 0, then it will start from 0. And if it is one, it will start from one algorithms in the output, it started from 0. If I will change it to one, it will start from one. Let's see. As you can see, you started from one. So this is the starting point, the first thing here, and the second thing here is the stopping point and what will be the condition on which it will stop? So as long as this condition is true, it will keep on iterating this loop, the body of this loop, and the point where this will become false, it will stop. So what is the condition here? I is less than 10. So initially I is one and then we are seeing, it will check for the condition that I is less than 10. It was true. So it went into the body. It will go into the body of this loop. In the first iteration, it will ignore this part. So what it will do in first iteration, it will go through these two statements and then it will go into the body of this loop if this condition is true. So the first time I was equals to one and a check for the condition I was less than 10. So it went into the body of our loop and it printed this eye on screen that was one. And then it went into this part, which is the increment. So if we keep I equal to one, it will always be less than 10. So we have to increase the value somewhere so that it reaches this point as well. So we are seeing I plus plus, which is equivalent to adding one value in i. So if it was one, I plus plus will make it two. So again, plus plus will make it three. So now in the second iteration, I plus, plus the value of I22, and then it check for this condition, whether I was less than 10. So 2 was less than 10. So it again went into the body of this loop. It will not go into this first statement anymore. This first statement is read only one time in the initial run because we have to initialize the value only once. After that, we have to check for the condition and we have to do the increment. So these two parts of the statement will be executed over and over again. So when the value was Do it again, printed this on the screen that was two, and then went again into this part where it incrementing I by one and made it three. So and again, it check for the condition here that was true and it again went into the body. So it will keep on doing that until I will be incremented in an iteration and it will become ten. So when it will compare here, it will say ten is less than 10, so it was not true. It will stop the execution. So that is how this loop works. And anything we have in this body of this loop will be executed over and over again as this loop runs. So this statement system.out.print Ellen I is in a loop and this integer i, which I have made is of your choice. You can name it anything. It's a very able. Now I will just change a few values of this loop to show you. Similarly, I started, as I started from one, I will start from five. And as you can see, it says 56789. And if I make it if I want to include the 10 as well, I will make it, I is less than or equal to 10. So now 10 will also be included. As you can see, 10 is included. Now this loop is incrementing value. I can increment a greater value as well. For data I have to write I is equals to I plus 2 if I want to increment of two. So what I'm saying, put I is equals to I plus 2. Now the increment will be of two values. I will run this and as you can see, five and then increment of 27 and the nine. Let's start it with the one. So when I start with one, it gives an increment of two and it prints the values. Now as I'm doing the positive increment, I can also do a negative increment here. Let's say I'm starting from a 100 and then this condition will change. I will say it will be greater than or equal to 0. So now it's in the reverse order that I'm seeing. I is equal to initially is equals to a 100. And then it will check for this condition and I have to decrease the value by one here. So I will say I minus minus, that will decrease the value by one. So as you can see, it printed from a hundred and ninety nine, ninety eight, ninety seven, and it went to 0. So if i will decrease it by two value, I is equals to, let's say I minus 3. I'm giving, I'm decreasing the value by three. So let's see, As you can see, a hundred, ninety seven, ninety four, and ninety one and so on. And this lower and upper limit can be anything. I can start from 1000 as well. So it will be printing all those values are as you can see in the output. So we can change these conditions and play with these conditions. We can have any condition here that we want our loop to be working on. And inside the body of this loop, we can have any number of statements that we want. So if it's a big functionality, we can put it here and it will work on debt. So in future, when we will write some difficult codes as well, you will see the benefit of using these loops. So that's all for this session. 13. While Loop: Welcome. In this session we will learn about while loop. While loop is an another type of loop we are, we have a condition, they are in a loop that as long as that condition is true, it will execute that loop. And when that condition will become false, it will stop executing that loop. So let's see how is how it's done. So to write a while loop, first of all, I have to write the keyword while, that will indicate that it's a while loop after the ad, we will have these two wrong brackets and then the body of this loop. So this will be the body of loop, but we have to define the condition here in these two round brackets. So let's make a condition. I will make an integer variable count and put it equal to five. So I have this count five and I will add a condition here that as long as this count is greater than 0, so I will write count is greater than 0. So this will execute, it will keep on executing this while loop as long as this count is greater than 0. So I can perform anything in the body of this loop. Let's say I will just print system.out.print, and I will print the value of count there. So simply what I'm doing here is I'm printing the value of count. And now it will, you know, that this will go in an infinite loop because we're not changing the value of count anywhere. So we have to stop this loop as well. I will show you that it will go into an infinite loop. As you can see, it's keep on printing five, so we have to stop it here. How to stop this loop? We have to make this condition falls somewhere at point of our code. So what I will do here is I will decrease count by one here. So writing count minus minus will decrease the value by one. So now first-time count will be five and it will check this condition, dad, whether it is greater than 0. So it will be greater than 0 and it will move into the body and it will print the value of count. After that, it will decrease the value. And again check this condition before going into the body of this loop. So it will be four and it will be true. So again, it will print this valley and decreases the count, and it will keep on doing it until the value is equals to 0. So as you can see, it says 54321. And when the value becomes 0, then the count was not greater than 0 here in this condition, and it didn't went into the body of this loop. So this is how a while loop works. This is just an another type of low VQ and use any type of loop depending upon our requirement. So it's a different format. Now, whatever we will write in the body of this loop will be executed as many times as we want it to be until this condition will be true. So we can change this condition as well. I can change it from 52, let's say 30. And as you can see, it printed the value from 30 to 1. So this is how this loop works. That's all from this session. 14. Infinite while loop: Welcome. In this session I will tell you about one interview question. So I will write some code here and I will ask you for the output. So if I write like a while loop and then I write true very light condition and then I write something in the body like System.out.print. Let's say represent something like apple. So what it will do, what this loop will do, whether it will run or it will give an error, or what it will do. So this is important interview question. So the answer to this question is that it will go in an infinite loop. When we will run this condition, it will be always Drew. Drew means like it goes in an infinite loop. I will run this thing here and you can see the output. As you can see it is keep on printing Apple that I have an output command here that print apple. And when I, when I will press this cross here, it will again open it because the program is still running. So if you get a question that what will happen when we have true in a condition of while loop? It will go in an infinite loop and we have to explicitly stop this. And from here, like you can see here is a terminate button. When I press this, this loop will terminate and I have to manually do it. And as you can see, the output, it's filled with Apple. And as I scroll up, there are more and more values. So this will happen whatever we will have in the body of this while loop now, we'll be running infinite dying. So that's the answer to this question. That's all from this session. 15. Try Catch Exception: Welcome. In this session, we will learn about exception handling and even learn it with the help of an example. Exception handling is a very important part of any program that we need to handle exceptions, errors that can come in our program. So in this session, I will guide you how to handle exceptions. We will understand it with the help of an example. So as you can see, we have this little quote here that dx number one here and put it in the variable num 1. So it will ask the user to enter a number and we will save it in number one. And then again, it will ask the user to enter a second number and we will store it in variable num 2. Now, I will make it function here you can see this function is divide. What it will do is it will take two arguments and returns the result of their division. So integer a and integer b are two arguments. It will divide those a and B, and it will return us the value of it. So what I am, what I am going to do here is I will divide these two numbers, num1 and num2, and we will see what kind of exception can appear while we take input from user. So I will call it here divide and what I will send an argument is num1 and num2. So any value that user gives in num one and num two will be passed onto this divide function and it will divide them. And what we're going to do further here is we will print the result of this. So I will just simply copy this. And okay, we will simply print what we have here in the result. Now I will run this program and we will see the output. Okay, Let's say I give Dan as number one and it asks me for the number, do I give it two? Now the result should be five. As you can see in the output, it has printed phi. So this was the normal case that the normal user will input values. But there can be a case where we can have some exception there. I will run it again. Okay, Now I will give ten as the number 10 as a number two. Now we cannot divide an integer of 0, that is exception in arithmetic that causes an error. You cannot divide any number with zeros. So as you can see, it gives me an error. It says exception in thread main. So here you can read about the exception divide by 0. So divide-by-zero is an exception. Now this gives a very bad impression to user who is using a program that a big error appears in front of him, we need to handle such exceptions. There can be a lot of more exceptions that can be there. So how we can handle this, let's see. To handle this exception, I will use a block named dry, so I will write dry here. And at two curly braces inside of these two curly braces, I will add this code where I'm calling this divide function. So what it will do is I will first of all complete this dry blog has to be followed with the catch block. So this will be our catch block. And here I have to define my exception. So I will write exception and I can give any variable name that can be EX. Okay, we are good to go here. Now what did we do here is it will dry this part of the code. And if this works fine, it will move here without going into catch. And if there will be any problem while calling this divide function, exception appears here. It was simply a gash that exception in this catch block. And as you can see, I've written an exception here. This will be the exception that we will be getting. So we can simply handle that exception here in a proper way. So I will just tell the user that divide by 0 is not allowed. So simply I would write a statement there. Divide by 0 is not allowed. Or you can give any custom message that you want, or you can simply do anything with that exception that occurs. So this part of the code will be executed and if there is an exception, it will gadget in this part of the code. And if everything goes fine here in this part of the code, it will never go into this catch block. So I will run it again. Now, enter number one. I will give Dan, and again I will divide it by 0. Now previously there was a very big error message there, and now we are handling that exception. So as you can see, it shows us a line of code that divided by 0 is not allowed. So simply it has handled exception in a proper way. Now I will run it again without an exception. It will never go into the sketch blocked. So enter number 1, 10 divided by 2 is simplified. So it never went into this catch block while everything was okay. So if there is an exception, it will go into this catch block. Now the exception that is there in E X variable, we can auto brain that. So I can replace this with EX, which will actually print the value of EX, which will be telling us about that exception. So I will run it again. And value one will be damned. And I will divide it by 0. And you can see it tells us that Java Lang arithmetic exception, so divide by the Earth-Sun specific type of exception, we can handle different types of exception. That's meant that I will be discussing in our future lecture. So now we have this exception, e x dot v got printed there. If this try-catch block was not there, what it will do is it will stop the code. But if it is there, like dry and catch, it will handle the exception and it will move further in the code as well. So if I have these two repeated here, like this and I commanded, so now, after the exception occurs, it will move in this pot of gold as well. I have to change the variable names here. It will be three and it will be four, so it will not stop the execution of programs. The idea here is to continue the program even if the exception occurs. So let's run this now, value on a stem and a 0 now exception should occur, okay, it says Java Lang exception divide by 0 and again it continues the execution of program. It is asking us for the other numbers and the number 120 and to number 2 and 3. So what it does is it does not stop the program. And if the try-catch is not there, it will simply stop the program and it will not move any further in that goal. So that gives a very bad but you're off your program that it stops in the way without handling any type of exception. So that's all from this session. Thank you. 16. Exception types: Welcome. There are different types of exceptions that can occur. So in this catch block, we have written exception that is generic for all. So any kind of exception we'll be dealing with this will gadget in this exception. But here we know that only the exception dividing by 0 can't gone. So what we can do here is we can add automatic, automatic exception here instead of exception. So it will just give us a more detailed the reader point of view and the value of it will be more near to what we want here. So automatic exception would be a good thing to write here because we know the specific type of exception that can come here. So depending upon our different scenarios, we can add different types of exceptions here. So that's all from this session. 17. Finally: Welcome. In this session we will look on an another block of dry cache that is named finally. So it can also be asked in an interview question that what is finally in dry and catch? So here we have our example. We were real getting two numbers and then we are trying to divide them. And if there is an exception, we are getting debt in this catch block. So now we can add another block here which is named finally. So what it does is, no matter what if there is an exception or not in this strike at law, it will always go into this finally block. So finally is for the things that we definitely want to do no matter what. So in our case here, we will bring the message that program ended By. So this message, we want it to be there no matter what, whether the exception gums or not, this is beneficial in a lot of other scenarios as well. For example, in your application, you are showing the loading view that some functionality is being performed and you're showing the loading, you know, no matter what, if that functionality is completed or not. At some time you want to remove that loading view from screen. So it cannot be always there. So all those things which we definitely want to do or in finally block. So this block will run no matter what. So now I will run this program and we will go with the normal flow. Let's say 10 divided by 2, Arthur will be five, but it says program and did buy. So we're not printing the result here. So naturally I didn't bring into the reserve, but it went into the finally block, that is program. And by now I will run this again and we will make the exception to happen. So ten divided by 0 is an exception. We cannot divide it by 0. So it goes into the exception block, that is catch block. It says cannot divide by 0, but it still goes into the finally block that is program ended by. So in both the scenarios it went into this finally block. So this is the benefit of this finally block and we use it with try and catch block. So that's all from this session. 18. What are functions: Welcome. In this session, we will learn about functions. You can think of function as a processing unit that day if something has an input process on it and gives us some output. Suppose we have a function sum, so it will take two values as an input, add them in its processing unit and give us solution as an output. Suppose we have an another function named factorial. So it will take some value as an input, calculate x factorial, and give us some output to define a function. First of all, we have to define the name of function. So that can be anything offered drugs depending upon what functionality that function is going to perform. And then into round brackets, we have to give arguments. These arguments are input of that function. We can give one argument, two arguments, three arguments, or any number of arguments of our choice. A function can also perform without any arguments. So if there are no arguments, we will keep these do wrong brackets empty. Then we have a return type. So return type of a function is the datatype dysfunction is going to return that can be integer, double, float, array or anything. So the body of function is enclosed in two curly braces. All the functionality that this function is going to perform is going to be there in these two curly braces. Suppose we have a function sum, then the name of the function will be some. And as an argument, it will be taking two values of which it needs to calculate sum. So it will be integer a and integer b. We have to define the data type of this function is going to have an argument. So return type of this function is integer because after calculating sum of these two variables, it will return us a integer value. And in the body of this function is simply add those two values which we get in the argument of this function and return those. So input of this function is argument a and b. And output of this function is some value a and B that is returned by a command return. So we use a command named return to return from any function. 19. Scope Of a Variable: Welcome. In this session we will learn about scope of a variable. So this can be asked in an interview Dad, what is scope of a variable? So I will be guiding you in this session about this. Let's understand it with the help of an example. So I'm in code editor and this is our main function. I will make a variable here. Let, let's say it's a and its value is 20. It's an integer variable. Now if I want to print this on the value of this variable on screens and for the Eigen, do this in a brain function. So I will write a here, and when I run this code, it will print the value of a, as you can see, it printed 20 here in console window. So now this scope of this variable is only inside these two curly braces. Dat is the body of this main function. So this is only accessible in the body of this main function and anywhere outside it is not assessable. So I will make a function here. I will name this function print value of a. So what this function will do is it will try to print the value of this integer a. And let's see if it can do that. Okay, as you can see, a red dotted line appears under a, which means that let's read the error first. It says a cannot be resolved to a variable. So it does not know about this variable a, because it is defined in this main function and its scope is only in these two results. Now, I will remove this from here and put it here in main class and add a keyword static. So now this integer variable a is inside this mean gloss and its scope has increased. So everything, every function can access this variable that is inside this main class. So do know about the scope of any variable we have to look in which class or function it is, and it will be accessible inside that. So as you can see, these curly braces of main class start here and end here. So now it will be accessible in every function of this class. Now as you can see, the error is also gone. I will call this function print value of a to demonstrate that it can print the value of a as well. So I will simply call this function here and we will see the output. I will run this here. And as you can see, 20 is printed two times. The first one is here in main, and the second one is from this function print value of a. So a is accessible in the body of this main class. And this applies to all other classes and all of the things that we make in our code. So that's all from this session. 20. Class and Object: Welcome. In this session, we will learn about class and object in object oriented programming. And this concept is very important in object oriented programming. So let's start and we will understand it with the help of an example. Suppose a construction company needs to build a building. So what they need to do for us, they cannot go directly at someplace and start making the building by joining breaks. So that is not the case. They cannot do that. So what they need to have first, they need to hire an engineer that will make a blueprint of that building. So first of all, they need to have the structure of that building built on paper or something before they can go ahead and make that original building out there. So Dan blueprint, which an engineer will make for that building, is called a class in object oriented programming. That blueprint has no real value. It's not something real out there. It's just a structure of that real thing on paper that we call Hebrew blueprint. And now, by using this blueprint, we can go ahead and make an original building out there. Because in Blueprint structure will be defined and everything. So now we can have some people there that can build their building. And that original building is called an object in object oriented programming. And now by using this blueprint, we can have another building out there as well. So now there are two buildings of same blueprint. And we can have a third one as well. And we can have any number of buildings out there by using this blueprint. So this concept is called class and object. Class is basically something referred to as a blueprint that defines the structure that how that real thing is going to be. So we need to have glass there. And by using debt clause, we can make as many real objects in object oriented programming. So object you can think of as something real that has a real value clause is not real. Glasses something on paper and object is something real. So this concept is called class and object. So by using this class building, we can have Building a, B, and C out there. And these building a, b, and c will be real, but they will be derived from which class building that will define its structure there. Similarly, a car manufacturing company needs to have a model of car before they can start manufacturing that God. So any company needs to have debt engineering model there. So they will hire a person that will make that guard model there. And after this, we have that model of cards here. We can have any number of cars from that model. We can make those cars and factory by using that model, but we need to have that modeled here. So this model is called class and the real cars, which we, which we will make out of it, are called objects. So everything in real life is a class. For example, if you have a house, houses the class, and if you have a car, a car is a glass. You laptop is a class, your computer is glass. And anything you can think of in real-world is a class. Before we can have objects on that, we need to have something defined for that class. So what class is composed of? It is composed of two things, properties and functions. So what are these? If we have a car class, what will be the properties of God? It's colored top speed, number of wheels, doors. These all will be properties of this car. And you can get refers to how this looks and what discard have will be in properties. And the second thing of glass has is a function. So what functions guard can perform, it can accelerate, it, can start, it can read and apply break on this and we can stop discard. So any mechanism that any process that this discard have, any functionality that the scar is have IS, goes in this function part. So class has two things, only two things, properties and functions. You can refer to anything. If you have a building, then it will be have properties like color. How many rooms, how many floors functions will be live? You can open the door, you can close the door, and things like that in that building. So everything, every class has properties and functions. Here we have looked at an example of a car, but when we go to an example of book, we can open book that will be function, the color of book will be its property. Number of pages of that book will be its property. So we can, we can define these things in any of our class. So first of all, we have to define a class with the properties and functions. Then we can make any number of objects from that class. Now, let's move into code editor and write some real examples there of glass and object. 21. What is Class: I welcome you to this first coding session of learning object-oriented programming using Java. So I'm in code editor and this is Eclipse code editor. You can use any code editor of your choice because our main focus will be learning programming here. So the code is same and you can use any code editor. So in this eclipse code editor, I have this learn Java project already made. I will add my first-class in this project. So I right-click here and then I add select clause from new. After selecting class, I have to provide a name for this particular class. So what I will do here, I would write percent. So we will understand class with the help of a person class example because we can simply make a person class and it can be used in a lot of situations. Like for every working component that we made, there is always a person required if we are making a shop or something, Library Management System or something, everywhere there is customer and there are students, there are teachers, so we can make the person class there. And it will be in our source folder, name of our project and SRC source folder. So I will finish this and as you can see, our classes successfully made and it resides in our default package here. So let's understand this. To make a class, we need to have this class keyword, they're falling this class keyword, we will write the name of our class, so our classes person. So we have written a named person here and this public access modifier, we will get into the details of access modifiers in our upcoming sessions. But for now, just keep an ID of this as it is. It makes our class publicly available everywhere. So our class is assessable every year in our package, in our main function and in other places. So this will make more sense when we move to our next sessions and learn about access modifiers. So this is our class name person, and everything that goes inside our class will be in these two curly braces. So what actually a class contains. Let's look at the figure. As you can see in the figure on the right, a class can be mainly divided into two sections. The first section has the variables and properties. So these are like what a person looks like and what properties it can have. So every class will be divided in majorly divided into these two sections. The first section will have these variables and properties. So what properties we can think of person that is color, age, gender, and a lot of more. And in this section, in this section where we will have functions, we can add like what a person can perform, that he can eat, he can sleep, you can walk. So these are the functions that a person can perform. So all the functionality goes into this section. So I will go ahead and add a few variables in my person class. Let's say the first one will be the name, so it will be string and I will add it name. Every person will have a name as you, you, you should keep in mind that we are now adding a blueprint that how our person class will look like, this is a blueprint. So we have to write all those things that this class can have. What else our person class can have. It can have age or person can have age. And similarly a person can have a gender to, so it will be string. And a person can also have a height, so it will be. So we can have different data types of properties that we can add in our class. So string name, name is a string, age is an integer, gender is string again, and height is integer. Now, these all goes in this variables property section. As you can see in the image, that name, age, gender, and height goes into variables and properties section. Now we will add a few functions in our person class, and I will go ahead and make some. So public wide. The name of the function, let's say a person can eat. So we will add a function named eat. And in the body of this function, I will just write a single line of code for now before going into that, this public access modifier, again that we are defining before our function is saying that this function is publicly available on all the places. And that will make more sense when we move further into our code and in our upcoming sessions. So for now, just think of this idea. Void means that this function will return us nothing. So it will just perform this functionality which is inside these curly braces and it will end. So in this body of this function, I will write system dot out, dot print. And I will say eating. So it will refer to that the person is eating. Now similarly, as we have this Eat function, we can have other functions as well. Like for Blake wide walk, a person can also walk through. So this is the functionality that a person can perform. So I will write system dot out dot print, and we will save off. So now we have these two functions, eat and voc data person can perform. Similarly. We can have functions like getName, getAge, jet will return as these strings and the properties which we have in this person class. So I will go ahead and make a function here, public. Now the return type will not be wide, it will be string in case we are getting the name, this name variable value here. So string, I will write this, the name of the function getName. And in the body of this function I will return name. So name refers to this property which we have here in our class. So this function getName will always return us the name of the person. There might be a condition where we want to know about the name of person. So we will use this function getName to get the name. Similarly, as we have this getName function, we can also have they'll get age function, Gender function, getHeight function as well. So let's add one more function. This function will return an integer and it will be get age, and it will return us age of our person. So now in our person class we have for functions and they can be put in the function section of our image. So as you can see in the figure that eat, walk, getName and get it goes in this function section. So we can divide these all things in our class in two major sections, variables and properties and functions and methods. In the next session we will learn about constructor. So that's all from this session. 22. Constructor: Welcome. In this session we will make object or if our person class. So we have this class named person and we have defined different functions and properties in Scientists class. Now we need to make an object if we want to use this Person class, as we know, that class is only a definition of what it would be. So Person class is just a blueprint of what properties AND function a person class can have. So to give it something real, to make it real and part of our program, we need to make objects out of it. Now we have definition of this person class, and now we can make any number of objects that we want, but we need to make at least one object so that we can use that in our program. So this is our person class, and here we can make objects. To make an object we need a main function because main function is the entry point of any program. So we need to have one, at least one mean function in our program where we can make object of our person class. Currently we do not have any main function here. We can define main function here at the end of these functions in this class as well. But I will make it in a separate file because that is a good practice so that we can just assess that foil and we can make other objects there as well. So we can have all our classes here listed in our default package, and we can also have a class for our main function. So I will go ahead and add that in my project. I will add a new class. I will name it main class. So this class will be holding our main function in this class, as you can see me in classes made here, and I will add this main function here. Now in this function I can make object of my class person. So to make it object, first of all, we have to write the name of our class, so the name of our classes person. After that, we have to provide the name of object. So what will be the name of object that we are making? So I will name it person one as we can make other persons out of it as well. So the first object is named person one. After this I have to put it equal to and then a new keyword. New keyword is used to initialize an object as we have to initialize the object in memory. So what we will do, we will use this new operator here. After that, we have to write the name of our class again. And then these two wrong brackets. So that is all we need to do to make an object. So person one object is made and it will call its default constructor, as we haven't provided nothing in these two round brackets. So which constructor will be called? Let me show you in class this constructor which has no arguments. As you can see, Person constructor has no arguments here. If we need to call this constructor, we need to provide all these four arguments which we have there. So again, in our main class or person one object is ready. Now I can call all the properties and functions on this object. So let's see. I will write the name of this object person. And when I will write dot operator, intelligence will show me that what this class has, this clause has a gender, height, and name, and these functions as well, eat and get age. So all these functions that I have in my class will be shown here by the IntelliSense. So as you can see you walk, I will call some function here. Let's say I will call walk. As you can see, you chose that walk is there in your class, so I will call this function. Now everything is okay. I will run this and we will see the output. As you can see in the console window. It shows VOC written on the screen because what a raw function was doing, Let's see in our class, as you can see, VOC function prints walk on the screen. So it has successfully called the swap function there. Again in our main class, I can call all these function like eat, getName, getAge. So all these function can be called an, all these properties can be called as well. If I want to print the name, let's see, by printing the name because our default constructor will second name to Hamza and age to 25. I will call, and I will, I will remove this walk function call here and I will print okay, into print statement, I will to call any property again, I have to write the name of object for first. So person 1 is the name of object and dot operator, then I will call name. So what I'm doing here is I'm printing person one dot name and it should be thumbs up if my default constructor is called here. So let's see, I will run this. And as you can see in the output it says homes up. Because hmmm xy is set in our default constructor and we have never gone that constructor explicitly, that constructor what was called implicitly by when we, we're initializing this person one object. So what I can do here is I can call the other multiple argument constructor by providing values here. So if I provide for values like name, Let's say John, I will add, let's say 20. Then we have gender. I will write the middle and height, let's say six feet. So now I have provided these four arguments here. Now it will call the multiple argument constructor instead of calling this default constructor with no arguments. So let's see if it will set these property values name, age, gender, and height. And let's see whether they have set correctly or not. So as you can see in the output, it says John. So John is printed there that we have sent here in multiple argument constructor. So it was successfully called and it said two values. So that's how we call this multiple argument constructor there. Now, there might be a question in your mind that we are calling this name property on name of object, but we also have a function here, as you can see, to get name, debt return as the name. So why there is need of making a separate function when we can directly call properties, I can directly call this name property on object. But we have a function here as well. So why, why we make a function there? There is a great importance of making these functions. This will make more sense when we move to access modifiers, functions where we will learn about these public and private and protected access modifiers that will make more sense they are. So I will explain these things there. And this is of great importance. We will make it private and it will not be accessible. So now we are assessing this Person.new and this will no more be accessible when we make it private. So we will learn about how we can do that because we need to make some things private data that we do not want other people to join directly. So that is of great importance and we will learn about them. So for now, I will make an another person object here. Let's see. To make it other object, I just need to change the name like same pattern. We'll go name of class and the name of object, that is version two. Now, I can provide new values. Let say Peter, age 30, male and height. We can say five feet. So now we have other objects as well. So we have person one and person two. Let's print the name of person to. Okay, I can run this. And as you can see it says Peter two. So now we have two objects from that class. And that is like from one class we have defined, we can make any number of objects. So person 1, person to person three, and they will have their separate values in memory. So every object has its, all the things that are in our person class. These all things are separately made for all our objects in memory. So we can make any number of objects there. And as you can see, we have made two objects here, person 1 and person 2, and the name is John and Peter, we can give any name to our object. I have given person one. You can also give it John, as it is, a name of the person will be gone. So we can do this. We can also change these property values of any object after it has made. So if I want the person to values object values to be changed simply I have to write them of that object. So person to then dot operator and the property which I want to change, for example, height. If I want to change the height value, I can simply person to dot height and I can change it to anything like, let's say 77 feet. So now person to hide initially was set to five, but now it's seven. So I can just simply print out the height of person too. And you can see the changed value. As you can see now it prints seven similarity as I have changed hide, I can also change like name and age and anything. So that's all from this session, we learned about objects in this session. 23. Difference between Heap and Stack Memory: Welcome. In this session we will learn about difference in heap and stack memory. So when we are writing the program, what goes in heap and what goes in stack. So let's say we declare a variable a and assign a value to it. So what will happen is this will go into stack memory with a reference. So 1007 that you can see in this image is that reference and then is the value of a, so it is pushed into a stack. Now we make an another variable b with the value four. Again, it is pushed into stack with a value four and the reference 1, 0, 0, 8. Now, when we make an object of any class, let's say Apple here we have initiated an object. What will happen is the reference to Apple will go instead, but the value of that object we'll go in heap. So all the objects that we make in the lifecycle of our program, they go into heat and only their reference is pushed into stack. So stat woman will maintain the references of all the objects and other types like a and B that are integers. We can also have strings and doubles and floats, and all of those things goes into stack with their values, but the objects goes into heap with their values. So anything we changed in the apple object will be reflected in heap memory, but the reference to data object and stack will remain the same. Now, when we terminate this program, all the values from stack will be popped as they have been pushed. The concept of Boston lost out. So stack will start popping up the value. So the reference of Apple will be popped up first and then the value of b and a. And finally, he will be also clear when we remove the reference from the stack. So everything in the memory will be cleared when we terminate our program. So this is the sequence of how things go in heap and stack memory. So that's all from this session. 24. Inheritance Explanation: Welcome. In this session, we will learn about inheritance in object oriented programming, and we will learn it with the help of an example. Suppose we have a class named car and it has few properties like color, number of doors. And if you functions like start and stop. And we have another class named Ford as forward is a car, so it will also have all of these properties and functions. So the relation between Ford and God is, is a relation that Ford is a car, so forth will have all those properties and functions that are inside car. One way of achieving is achieving this is that we rewrite all the properties and functions that are in car class in art fold glass as well. And the second way of doing it is inheritance. So here inheritance come in play. That by using inheritance, we can simply use all the properties that are in car and all the functions that are in car simply inferred by just using inheritance. Similarly, we have another class name, Honda. It will also have all the properties and functions that are incurred because they have is a relation that Honda is a car. So we can simply achieve this by using inheritance. So by this class car, when we use inheritance and inherit these two classes, Ford and harder, all the properties and functions in our car class will automatically be added in are for glass and Honda class. So that is benefit of inheritance that we need not to rewrite all of these things there in these glasses are simply present in these both glasses. So when we inherit other classes from a parent class, that is the car class we have inherited Three, Ford, Honda, and Toyota. We can also inherit other classes from this class car. So the top loss from here we inherit other classes is gone parent class, and all the inherited classes are called giant classes. They have another name as well. Parent class can also be called as base class and child classes can also be called as Dr. classes. So all the properties and functions that are in car class will be separately edit to all inherited classes. That is, the fourth glass will be having car class functionality, and in addition to dead, it will have other functionality that is specific to fold. Similarly, Honda class will have God loves functionality. And in addition to that other functionality specific to Honda. Similarly data's case for Toyota that it will have core functionality, all the things of God glass, and in addition to that, it will have other functionality specific to Toyota. So that has benefit of inheritance that we get all the properties and functions from parent class in GI classes. And then we can have other functionality related to those giant clusters as well. Because Ford, Honda, and Toyota are different companies, so they will be having some specific properties to their brand as well. So that will be added to these glasses. So this is the benefit of object oriented programming, that data reusability. Suppose we have a base class that has 20 properties and a 100 functions. Now if you want to add all these properties and function to some other clause, we need not to rewrite them. We can simply inherit that glass from this base class and it will become a derived class and it will have all those properties and functions inside that class. And in addition to that, it can have other properties and functions that are specific to that Dr class. So this is a great benefit of inheritance, that is data reusability. We can reuse data from our base class into our derived class without writing and repeating that code again and again. So that's all from this session. 25. Inheritance Code: Welcome. In this session we will learn about inheritance. Currently we have this person class here, recently made. It has a few properties and a few functions. Now, I will go ahead and make an another class name student. So in this project learned Java, I will add a new class. Now name of this class will be student. Okay, we have this class here, student. Now, we know that student is a person. So students will have all those properties and functions which we already have in our person class. Student has a name, student has a gender and height. And all these functions like Eat, walk, getName. These can be there in a Student class. So what is the way that we can add all of these things in our student class. The first possible way would be to copy all of these things in my student class. But that will be a lot of repeating code. There will be lot of repeated code in my student class. We don't want to do that. If our person class having thousands of lines, then we have to copy all of those lines in our student class. So dad is not a good way. The other way is using inheritance. So here inheritance comes into play. By using inheritance, we can add all of the properties and functions in person class into our student class. So how we can do that, Let's see. To inherit. First of all, we use a keyword name extents. Know students will be inherited from person class. I write this keyword extent, and after that, I have to write the name of the class from which this class will inherit. So it will be Person class. So now all the properties and functions are available in the student class. So dad was so easy. This is called inheritance that we inherit some clouds from other clause. Now the student class has all the properties and functions which are in-person class. The only thing that is not copied in our new glass is these constructor, the person constructor which we have in this class. Constructor is never copied in the new class. But what it will do is whenever we will make an object of the student class, it will call this no argument constructor from parent class. So that is a very important concept we need to know. I will get into the details of this concept in a vial. But before that I will make an object of my student class which is currently empty, but it is inherited from our person class. So we will see that all these properties and functions are available on this gloss or not. So in our main function, I previously had this person class object named John. I have commented that and now I will make student class object. I will emit student. Okay, we have it here. Now what it will do is it will allow me to call all those properties and functions on this object. Let's see, I will write the name of the object and dot operator. And as you can see, it says age, gender, height, and name. It is giving me all those options which are in our person class. And if I remove this extent keyword here, extend person, it will not show me those properties there. Let's see. Now again, I will write this dot operator, and as you can see, it does not show me any of those properties which are in-person class. So when I add this line here, extends person it will, it gives me all those properties and functions in this class except constructor. Know when I have made an object of the student class like this. First of all, it will go into this parent class Person and it will call the default constructor. Data is this one, and it will call it from our parent class. I will give you an example of that as well in a while. Okay, before that I will call some function, for example, walk from our student class. And let's see. As you can see, it says Walk, which is in our person class, disfunction VOC, which is supposed to print four on screen. So dad is also in our student class now. So this proves that all of those things are here in the student class. Now as we have all those properties AND function inside this glass on top of that, we can have some specific properties to student as well. For example, let's say integers student ID. Now student ID is specific to student class and it has nothing to do with personal glass. So on top of that, we can have these properties and functions as well. I will add a function as well here. Let's say attend class. So this function student is supposed to Atlantic loss, not a person. So we have added this here. And I will print on the screen that attending class. Now this function at n clause will be available on student class object and it will not be available on Person class because student is inherited from person class, I will go in main function and I will call this student dot. Now as you can see, it will show me that function here. I will just write attend class, as you can see, it gives me option here now I will run it. And as you can see, it says attending glass, but this function attend class will not be on this person object john, which I have here. So this is our new student class. Now let's look at a sequence of constructor. When I make an object of student class like this and edited class, it will first of all call the default constructor from our person class, that is the root class. So I will add a line here to see that whether this function, this constructor is called or not. So it will be, we'll say default. Default constructor, person class. So this is the default constructor or Person class and it will print whenever it is called. So in our main function back, and now I will run it again. And as you can see, it says default constructor percent loss. So this constructor was called, and this constructor will always be called no matter what it calls the parent class constructor. Now I will give you an another example. As we have this multiple argument constructor inside our person class. And I have said that these are not copied in our new class student. So I will try to call that function multiple argument in our, on our student class and it will not allow me to do that. So I will copy these values from our person class. Okay, What edited gives us? It says the constructor student is undefined. So this constructor is not present in our new class student, because I said that constructors are not copied in the new class. So it doesn't find this constructor there in our new class, as it called the default constructor from parent class, but this constructor was not there. So I will just define that function in my student class. I will copy it from person class. Okay, Now in my student class, I will add this multiple argument constructor, and I will name it Student. Ok, now we have this here in our student class. Now it should not give an error in Maine glass. So as you can see, the editor is gone. Now it finds that constructor in our Student class, which had previously didn't. So that is how constructor sequence and I will explain you some more things about this as well. Now, what will be the sequence? Now when we call this multiple argument constructor, as I have told you that this default constructor of root class, that is person, will always be called. So first of all, always it will call this default constructor there, which we have default constructor. After that it will go into the student class and it will go on multiple argument constructor. If we are making the object like this, which we have passed four values here, multiple argument constructor, first of our default constructor, and then this constructor which wasn't student class. So I will add a comment line here so that we can see that it is called. Now I will say multiple argument constructor student class. Okay? So now I'm seeing multiple argument constructor student class in our main class. I will run this. And as you can see, first of all, it calls the default constructor or Person class. And then after dad, multiple argument constructor of student class. So it's calling this multiple argument constructor. And it has never call this multiple argument constructor in person class because only this default constructor, of course, some classes called That is rude. So to make that more clear, I will add this print line in this person Class argument as well to see that it is not called. So this one here in this as well. So now this is multiple argument constructor of Person class. Okay? If it would have called this, it would have printed this statement here which we have, but it will not print this because it will not be called, so I would not need to be in. And as you can see, default constructor of Person class and then multiple argument constructor of Student class is called Person class constructors never call. So is there a way that this person class constructor is also called disown? Yes, there is a way that we can call this constructor as well for debt in our student class, to call the multiple argument constructor, we need to use the keyword super. Now the super will refer to the parent class which we have deer and datas person and I will. And the arguments here, let's say name because there are four arguments, name, age, gender, and height. So I'm sending these arguments which are, I'm getting in this multiple argument constructor or student class. I'm just sending them to superclass multiple argument constructor. So now that will be called and it will ignore this default constructor or person class. Now what will be the sequence in this case would be that it will ignore this default constructor here. And as we have called the super constructor of multiple arguments of this, it will call this function instead the upper one. And from student class it will keep on to the next functionality which we have air. So it will go into this one and then it will read the functionality that we haven't student class. So I will run it again. And as you can see, it says multiple argument constructor person class. So it simply ignored the above constructor which we have this one default and it calls this one. Now, as you can see, multiple argument constructor Person class, and then after that, it continue, continue the execution of the student class that is multiple argument constructor student class. So it printed this line. So dance hall, we call this super function multiple arguments. So as you can see in our main class, the way we call this as we provided the arguments there. So this is very important sequence of constructor that we need to know while dealing with inheritance. Because we may want to perform certain things in our inherited class and some things from our parent class. So if this student class here, I also want to, if I want to initialize the student ID, or I can do that in my functions, in my constructor there. Now to set the value of the student ID, I can just simply get an argument here. If I want to get the value from user, I will say in teacher student ID. Now what it will do here is all the other values will be set like name, age, gender, and height by the constructor, which is in our parent class, and the student IDs left because it is in our inherited class. So what I will do, I will set it here. So this dot student ID is equals to student ID, which I have from the user. So this will successfully said this value student ID to student ID. Now I also have to provide this value here while volume. So I will set a value, let's say a 100. So this will successfully set the value of student ID. This is one way of doing it. Other ways that I make a no argument constructor here like this. So this will set the default value student. And here I can set the value of student ID like this, which I have done here, this dot student ID. And I can set it to some default value, let's say 0 initially. So this will be the case. Now when we have this constructor student here in this class as well, now it depends upon are calling, so if we are calling this multiple argument constructor, it will call this one, which we have here, this one. And if we call it like this, let me show you here. If I remove all those arguments here, the sequence will be dead. Now it has to call no argument constructor. So first of all, it will call this person class and no argument constructor. And then finally it will call student class constructor. So to show that I will just call this here again. And print statement that would be here is default constructor. Default constructor of student class. So now first of all, default constructor or a person and then student, I will run this again. And as you can see it says default constructor or Person class and then default constructor or student class. So this is the sequence when we have default constructor there. So now it totally depends upon the user data is making the object that which type of constructor he needs to call there. So that's all from this session. 26. Polymorphism Explanation: Welcome. In this session we will learn about polymorphism. Polymorphism is a very important concept in object oriented programming. Polymorphism can be divided into two parts, Bali and morphism. Boldly refers to many, and morphism refers to forms. So polymorphism completely refers to many farms. So let's learn it with the help of an example. Suppose we have a class name shape. It can have a few properties like sides of that shape, area of their shapes and angles between the sides of debt shape. And this shape can be of different type like triangle rectangle, scale and so on. So shape is our base class and all the rest of these classes are Dr. classes. So triangle has three sides and rectangle has four. So all of these have these properties with different values. But when it comes to calculating the area of all of these shapes, the formula for calculating area is different for every shape. That is, triangle cannot have same function for calculating area. And they have different formulas. So if we have a base class name shape and it has a function named calculate area, it might have some functionality, but when it comes to triangle, that is giant class, Dr class, it has different formula for calculating area. And so scare has retained will as well. They all have different formula for calculating their area. Now what we have concept of base and derived class, if we have it calculate area function in our base class. So the drive class automatically has that function. That is our concept of inheritance. So if we have a shape class has a base and it has calculate area function, then the rectangle class that is derived class will automatically be having dysfunction there. But when we go ahead and redefine that function, so what we are doing here, we are redefining their function in r dr class because rectangle has a different formula for calculating area. So we cannot use that same function of base class. So this concept is called overriding the function that we are redefining, calculate area function in our derived class with a different functionality. Now, it will ignore that function in base class and it will use the function of Dr. Glass. So base class function will never be called and it will only call derived class function calculate area. So that makes a lot of sense for rectangle, it will call rectangle area function and for triangle, the different function in triangle. So this concept refers to polymorphism. That is many forms. We can have many forms of same function calculate area is a function that is redefined in Dr class. So it has different forms, like for rectangle, it has different calculate area for a triangle, different for hangs up on different, for circle different. It has many forms. So this concept refers to polymorphism. This can also apply in other classes. Suppose we have a class named car, then different cars can have a lot of different functions there like starting mechanism. For example, different cars have different starting mechanism. Some cars are started by the P, some width button, and some different options there. So we can not have a starting mechanism function for every car. Same, we need to have different functions there. And similarly with the acceleration function, if we have the acceleration function, different cars might have different time and different processes and different mechanism of acceleration. And same is the case for breaks. Different cars have different mechanism of braking system. So we have polymorphism concept here in object oriented programming. So now let's understand it in code. 27. Polymorphism Code: Welcome. In this session, you will learn about polymorphism and we will understand it with the help of an example. So I'm in code editor and in this project learn Java. I will add a new class and I will name it shape. So our shape class is here inside this shape loss. I will make two variables. The first one will be worth and the second one will be height. These two variables will be used to calculate area of shape. So I will go ahead and make a function named area. Now we have this area function. Just to keep it simple, I will just bring that this is area of shape class. So I will print area of shape gloss. So this is area of shape glass and shaped clouds is our parent class. So I will add this parent here like like this. This will be apparent class because we will inherit a few classes from this class. So now our shape loss is ready. I will go ahead and make an another class in this project and dad will be named rectangle. So this rectangle class will inherit from our shape gloss. So let's see. Okay, we have a rectangle class here that extends from our shape loss. And now I have a main method. I will make another class that will be main class. So I will go ahead and make that. Just to run this project. I will name it main class. This class will be having our main function. We need to have everything organized so that our project looks good and works well. So in this main class, I will have our main function, and in this function I will make rectangle class object rectangle. I will name it rectangular, new rectangle. So now our object is ready and as we know this shape loss has this very tight and area. When I call the area function on Rectangle class, which is, which seems to be empty, but it inherits from shape. So it has all those properties and functions that are in shaped loss. So I can call these on this rectangle object. So let see rectangle dot area. So this area function automatically gets into order ten of glass. Now I can run this and we can see what's awkward. As you can see, it says area or shared data sphere and glass. But rectangle class will have a different functionality for calculating area. Similarly, if we have another classes like triangle, hexagon, and circle, they will have their different formulas for calculating area. We cannot use the parent class. Your function that isn't shaped gloss. So what we need to do, we know that this area function is already in this rectangle class due to inheritance. But when we redefine that function, I will go ahead and redefine that function. Now what I'm doing in this area function was already there, but I'm redefining this concept and this is called overriding a function. What I'm doing here is I'm overriding this area function in my rectangle class. Now it will ignore the shape glossy area function and it will execute this rectangle class area function. I will run this project again. And as you can see, there is nothing in output because this time it went into this area of functioning rectangle class, instead of going into the area function of our shape class. In this rectangle class, I will print that this is rectangle gloss area function. So what I have here, rectangle loss area. So now when I run this again, as you can see in the output it says Rectangle gloss area. So it ignored shaped glass area function that was supposed to be there in this class, but it has been overridden in our rectangle class. Now what I will do here, I will make the constructor of this retentive glass to calculate area for this rectangle. So rectangle, and this will be having two arguments. The first one will be W that we'll refer to wait, and the second one will be after that we'll refer to hide. And in the body of this constructor, what I will do, I will set the values of width and height of this class. So we have these vert and high that are in shaped loss already in this rectangle class. So I can send those with is equals to W and height is equals to h. So now I'm setting the values of width and height here in this constructor. Now in our main glass, in our main method when I'm making an object of this class, as you can see, it's chose error because now we have to send these to ornaments to our constructor. So let's say I send a value that is 20 and 5. So the width will be 20 and hi, it will be five. Now in a rectangle class, while we are calculating area here, I can add this thing to this plus icon concatenated with multiplying width and height. So weird in tube. All right, so this is the formula to calculate width and height of it, to calculate area of a rectangle by multiplying weight and height. So now I will say area of rectangle is and it would bring the area after, after it prints this. So I will go ahead and run this again when we have these two values there as well. Now let's see what's the output. As you can see, it says area of rectangle is a 100 because it multiplied 20. With five, which gives us a 100. So area of rectangle is calculated well, now I will go ahead and make an another class, let's say triangular. Okay, now I have a triangle gloss deer as well, and I will inherited from shape. So we have two classes, rectangle and triangle debt inherits from our shape class. So what I will do next is I will again make a constructor of this class triangle. And I can get the values for width and height and dry angle, let's say do your w and then do your edge, set the values. So constructor is ready that will set the values inside our triangle class. Now this triangle class will again overwrite the parent class area function that we haven't shaped glass. I will say public void area. So now this area function is again overridden in drying the class similarly as we did it in rectangular glass. So this area function now we'll be calculating area of triangle. So now in the body of this function, I will calculate area of triangle and print that to screen. So system dot out dot print for branding. And then I will say area of triangle is, and I will concatenate it with the formula of triangles. The formula for calculating area of triangle is base into height divided by two. So we will consider rid of that base and height as height. And I will add the formula here, width into height. This will multiply weight and height, and then I will divide it by, divide it by two. So first of all, weight and height will be multiplied and then it will divide it by two. So now I will go ahead in my main class and I will make a triangle object as well. So we have this triangle object and I have to pass it. Values are repulsed. The same values like 20 and 50, base will be 20 and height will be five as we have for rectangle. So now I will write object name and call the area function here. Okay, So now we are calling this on rectangle as well, area function and triangle as well. So I will run this and we will see the output. As you can see, it says area of rectangle is a 100 and area of triangle is 15. How it calculated 15, 20, and 25, that was a 100 and then divided it by two. So that gave us the area of triangle. So this concept here, which we have learned is called polymorphism dad, this area function that exist in our shape class has different forms in its giant glasses. So every child class rectangle and triangle has its own definition of area method. So debt refers to many forms. So this function, which we have area inside our shape class has many forms there in our triangle and a rectangle gloss. So if you have other shapes, they are, we can have this area function overridden in that as well. So this overriding a function in different classes that refers to different forms. This concept overall is referred to as polymorphism. So this area function, which is in our shape class, has different forms in rectangle and triangle. So when we look into our main method, the same area function that is overridden in both the classes is called and has different reserves. It has many forms now. So this refers to as polymorphism. That's all from this session. 28. Overloading vs Overriding: Welcome. In this session we will be learning about a very important interview question, and that is what is difference between overloading and overriding? This is a very important into recursion. So let's understand it with the help of an example. On the left, you can see an example of overriding. And on the right, you can see an example of overloading. So let's look at overriding first, we have a class named Matt, and it has a function named sum. It takes two parameters and returns the sum of a and B. And on the bottom we have another gloss. Some dat is child of matte gloss. So math is a parent class on dark and some is a child class on bottom. We know that the function some data is in matte gloss is already there in some class. We need not to write it again because this is our concept of inheritance, that the giant class has all the functions of a parent class. But let's understand overriding. Now, we have written that some function, again with some different functionality. As you can see, the function in child class also prints that sum is a plus b. So it will also print on console that the sum of the two parameters. So this is the difference between these two some functions. Now what it will do is it will only call the function of a child class. So some function in child class that we have overridden will be called and the sum function in parent gloss matte will be ignored. So only the giant loss function will be called. This is called overriding that we have overridden the functionality of a function that wasn't parent class. So it becomes a new function with the same name and it performs some different functionality. So the function in math class that is barren glass on the returns, the sum of a and B Berg. The child class also brings the value on console. So these are two different functions that perform some different functionality. So this is the concept overriding that we have overridden the functionality of bailment glass function. And now this becomes a new function that does its own functionality. This is a very important concept. Now let's look at overloading. So we have a gloss matte and it has three functions named sum. Now the important thing here is these three functions are not same, irrespective that their name is same. These functions are different because they are parameters are different. The function on the top that takes two parameters, a and b returns the sum of a and B. And the middle function, it takes three parameters, a, b, and c, and it returns the sum of a, B, and C. And the third function, as you can see, the four parameters. So these three are different functions and this concept is called overloading, that the name of the function is same but the number of parameters is different. Have overloaded with multiple parameters. So when you have a function with the same name and different parameters, it becomes a different function. So this is called overloading that we have overloaded with multiple parameters. So this is very important interview question and you need to answer this very quickly. So this should come into your mind very quickly that what is overloading and overriding. So the simple way of remembering it is this like overloading that you are, you can simply remember it like this. That overloading means you are loading it with multiple parameters. As you lower things, we load things on different. Like if you are loading some luggage and your car, you are adding luggage in your car. So something is being added. So overloading means you are adding something. So what does meet at it? The parameters are being added. So these remains in the same cost and different parameters. This is called overloading and overriding. You can simply remember it by like we override things on top of wanting we override the other. So the previous thing is gone and the overridden thing is available. So this is the same concept, like you can remember this that we override the functionality of parent gloss function with our new functionality that we want in our child's clause. So this is the difference between overloading and overriding. That's all from this session. 29. Abstraction And Interfaces: Welcome. In this session, I will explain you the concept of abstraction and interfaces. So we will do it with the help of an example. Let's take an example of a car. In the car that we use, there is a complicated functionality. Data's being performed, which we are unaware all. For example, when we apply break, there comes into play functionality that makes the car to stop. But the only thing we have here is the brake pedal. So we press that brake pedal and we are unaware of the complicated functionality that is hidden that makes the car stop. And dad, it's for some other parts as well. For example, if we start a car, if we have only a button to start a car, but we don't know about the functionality which is happening behind. Similarly, when we breast the acceleration pedal, that functionality comes into play for that part. So all these interfaces, like Start button, acceleration, pedal, brake pedal, are the interfaces provided us by this guard that we can use, which hides the complicated functionality. So what interface does is we get the interfaces for a particular type and it highlights the functionality that we should not be knowing who or which is not very important for us to know. So we only know that we have to press the brake pedal. For different bars. The functionality for Brave will be different. Similarly is for the start but and an acceleration pedal. Different cars have different acceleration methods may be. So the only thing if a person knows about an acceleration pedal or he knows how to use the interfaces of car. You can drive it any car irrespective of what the functionality is behind. So what interfaces does is it hides the complicated functionality and it only provides us with the things that we require for data into work. So it's very beneficial. This is the concept of abstraction and interfaces. 30. Types of abstraction in java: Welcome abstraction in Java. So how we achieve abstraction in Java is by abstract classes and interfaces. Abstract classes are similar to any other gloss which we have in Java. But there are a few constraints on abstract classes. That is, we cannot make an object of abstract class. So if you cannot make an object of abstract class, how we can use it, we can choose it by inheritance. Any class can inherit extract blas. And interfaces. Interfaces are set of interfaces for any functionality that we want, but they do not have any implementation in them. So interfaces are only as we lived into the example of car, there were a few interfaces. So interfaces defined some methods that any other class can implement. So any class that implements an interface needs to provide the functionality of that interface. Abstract classes and interfaces are very similar to each other, but they have a few differences as well. So v will be discussing them in our upcoming sessions. 31. Abstract Class Code: Welcome. In this session we will learn about abstract classes and interfaces. And abstract classes are almost the same with a few differences. So I will take this previous example of our interface where we have a GAR interface. Now I will change this interface into an abstract class and we will do the required modifications in our code. So to change this interface into an abstract class, we have to do, first of all, we have to add an abstract keyword, abstract. And then like a normal class, we are making this class car. So now it, it is an abstract class which we have made and it has three functions, but they're, as you can see, there is some error. So what is the error here? In an abstract class, we can not leave the body, the implementation MD as an interface, we do not have to provide implementation here, but in an abstract class we have to do. So. I will provide an implementation for all three. No matter it doesn't matter if it is empty, but we have to provide the implementation here. So this will be the default implementation that will be deal. So this is the first difference between interface and an abstract class. Like interfaces, we can also have abstract methods, an abstract class. So abstract method is similar to interface method. We need not to provide the implementation. So if I say abstract, I have made the start function abstract. So now I will remove the body here, and I will simply add a semicolon here. Now, these two functions, accelerate and break are not abstract, but the start function is abstract. So when we add a keyword abstract 0, it makes it similar to interface method that it is abstract. We need not to provide the body here. We will provide the body in the class that will extend this class. So these two are normal methods. Now there is an another difference. We can provide public, private and protected access modifiers and abstract class, but we cannot do that in interface because interface there everything is public and we cannot change it. So I will make it public. This one as well. And the break as well. For the sake of this video, I have made all of these public. So now I have this one abstract method start and do normal matters. When I extend this abstract class to any other class, I will forcefully have to provide the body of the start function as it wasn't interfaces. But if we do not provide the body of this accelerated and break, it will be fine because the default implementation is already there. But this abstract method needs to be implemented in the class which we will extend. So this BMW gloss, it implemented the GAR in interface, but now it is not there. So even say extent GAR. So extend means that is the simple keyword for inheritance that we have been using. So BMW extends car. Now, we have provided the functionality of all these three methods which we have there. So I will try removing the start function from here. And let's see what it does here. As you can see, it says error. It says the Thai BMW must implement the inherited abstract method, guard dot start. So it is saying it should implement that. So I added it. But if I remove this accelerated from accelerate function, nothing will happen because this function is not abstract. So there is a default. As you can see, there is no error. When I go into scar abstract class, the default functionality will be here. So I can add any default functionality that will go here. So now I will undo this and I will run this. And you can see everything works fine. First of all, start function is called and break and axillary data is in our main clause which we previously wrote. So as you can see, abstract class and interface on very similar to each other with little differences and they both provide abstraction. So the idea of abstraction is to hide things. So same in this abstract class, we are hiding the functionality of these three and implementing in BMW gloss. So this is an abstract class. We can not make an object of abstract class. So if I will try to make an object of this car class which is abstract, it will give me errors. So I will try that in Maine glass. I will, instead of BMW here, I will keep that and I will also make it a car object. So what it says here, it says cannot initiate the type car. Why? Because it is abstract. You can only inherited as BMW God is doing it is, you can only do it like this, extend this car. So when I run this program, it will show me errors as you can see. So no output. I will remove this and run this again, there will be output. So this is how this abstraction books in Java. That's all from this session. 32. General idea of Abstraction: Welcome, In this session we will learn about abstraction. So I'm in code editor and this we have, what we have here is a rectangle class and triangle data is from our previous sessions. So to learn about abstraction, we will take this example. Now on this rectangle class object rectangle, we're calling this area function. And on triangle object we are calling this area function. So suppose we give this class to other persons to use. Now what we'll do here is they will make the object of these glasses and they will call the respective area function to calculate area. Now the person who is making the object and calling this area function does not know about the internal details of this area function. That how we are calculating area for both the classes are 10 billion triangle. He, what he's doing is he is calling this area function buyer's name. And as long as the results are correct, he's not concerned about the implementation. So what we are doing here is we are hiding implementation of this area function from the outside world. So in our rectangle class, when we see that how we are calculating area is this formula here, width into height. And in triangle class, what we have for MLA width into height divided by two. So what we are doing here is we are hiding this internal detail in this area function. Currently it is a one-line code, but it can be a separate line code as well. So what we are doing there is we are hiding that. And only thing we are showing two outside world is in our main clause is this area function name. So this has a lot of benefits. First of all, the third person is not the person who is using this is not concerned about Internet functionality. And other benefit is that later on, if this change the implementation changes the user, it has no effect on dead person, on deterred person that is using it. So because he is only using the name of this function area, and as long as the name remains the same, he is not concerned about the Internet functionality. If it changes, it will have the same results. So as long as the results are same, he is okay with that. So what he's using is only the name of this function that is area. So now if we go ahead and future and we change the functionality inside this function area for rectangle. That is, we shift this to another line in another variable. The user of this clause that is making object is not concerned. We have hired this details from him to understand it better. Suppose we have a very difficult algorithm going on there in some function. For example, there is a algorithm for searching, and we have implemented that. So the person who will make the object will only call their search function when he is making the object. And later on after few years, if we think that there is a better algorithm for that search and function, we can simply go there and replace that functionality in our search function. So that will make no changes on the person who is making object because he was calling the function search. And again, he is calling the search function and he needs not to change anything in this code. The only thing we changed is we've changed our implementation there. The name of the function was searched. So the name was saying it didn't make any difference, but the algorithm inside that function changed and now it's a foster and good algorithm that we have made. So this is benefit of abstraction on user side and on our side, Every as long as we do not change the name, we can change the implementation of any function without notifying the person because he's not concerned about the implementation there. So we hired this implementation details of our function from outside world, and this is called abstraction. So that's all from this session.