 First of all, I would like to know how many of you have already taken the course Java. Pretty much people, right? So, can I expect an interactive session? If it can be interactive and if you can answer all these things, we will go into something which we will be doing it here. If you have a Java project, how you will be connecting it to the database? How will you be iterating the data, fetching the data, saving the data? So, can you be interactive? You can say yes or no? Ok, fine. So, we will go to the first thing about Java. Java is object oriented. What is an object? Can anyone try it out? What is an object? So, I can call like human being is an object. The entities are eyes, ears which will hear. Hearing is a functionality of the ears. So, you can say in simple terms. I do not want you to say definitions which were memorized. I want the level of understandability from you. That is it. So, platform independent. What do you mean by platform independent? Can run in any machine. If you can code in Mac, you can code in Linux machine, you can go to a Windows machine, but still the functionality, whatever. You can just create a wire file. You have Apache server. You can run it in any machine. That is what platform independent means. One more thing. It is simple. People call it simple. Why? You have many predefined functions available. Unlike C, you have string as a data type. So, string manipulations, operations are very easy. So, we call it as simple and secure. What do you mean by secure language? C not secure. What do you mean by secure? Like you can make it simple. It runs as a class file. So, class file is not readable. Can you read class files? No. So, it is secure. And also you can say a few examples. Like let us have something like this. So, everyone has seen URLs of different websites. So, for example, Facebook. So, you will have www.facebook.com slash your user name. This is the basic thing. It is a URL. And also you could see something like id is equal to or ref is equal to and. So, this is a URL. We will fetch it as variable. So, id and reference is equal to something. Reference is equal to guest. We will fetch these id and reference. We will fetch these id and reference as a HTTP session variable. So, if you pass it like this, id is equal to some user name I am giving. For example, in that id is equal to something. I am just fetching it out here. You can generate MySQL injections in it. You know what MySQL injection is. So, I can do this. Select star from person where id is equal to something. 1, 2, 3, 4, whatever. Say 1. This is a person table id and user name. You are having something email. So, you are passing this parameter id 1. You will have it as a string. String id is equal to 1. If you pass it like this, also you can append. Say for example, you can edit the URL. You can always edit the URL. Have you tried editing the URLs? So, you can edit the URL. You can put 1 drop table person. So, if you write this, it will execute. It will execute if you execute this query. If you write this statement, execute query of query. This will be executed along with the string drop table person and you are dead. You will be responsible, right? You are a programmer. So, how can you restrict it? If you are passing in a URL and you are getting it as a session variable and you are running this query, execute query, how can you restrict it? I am speaking about Java. Java itself has an input thing to do it. So, you can use prepared statements. You can set the string. You can use prepared statement. Prepared statement query is equal to write this. Instead of passing the variable here, you can put a question mark. You put a question mark and then write query dot set string of 1 comma id. So, what Java does is it pre-compiles it. It converts everything into literals. So, you cannot do SQL injections. For example, in many sites which is not secure, it will have this thing. User name and password. Just put the user name and password as or equal to. It will log you in. You don't require a password. You don't need to hack. You don't need to do anything. It's just minimum SQL injection. You just have to do it. You can try it out with different websites and you cannot press website which sends you password. It has to have some encryption, MD5, something like that. So, try it out. If you have any websites you think which is not secure, you can try it out. You put your user name and put password as or equal to, then it will let you in. So, you can do it on Facebook or equal to. It will not let you in because it will say enter a valid password because of this. They are converting things to literals before putting it as a string. So, MySQL is vulnerable if you don't know how to use it. So, this is one among the things which will increase the security. And you can say multi-threading. What multi-threading is? Give an example for me, please. What multi-threading is? It's valid. But I would like you to say something which we face it every day. IRCTC. Take IRCTC. You have multiple threads so that many people can log in and book the tickets at the same time. If you want to go from Mumbai to Delhi. Multiple people can book the tickets. But they will have this thing. Say if the ticket count is only 60, 60 seats are only available. Like 59 people can log in and book 59 seats. It will not be a problem. But for only one seat, if two people are fighting for. So, what happens is whoever pays the transaction is faster, they will get it. So, it will come under multi-threading. They will allow excess users, multiple users. But you can book seats only which is limited and which is available. So, it can run on multi-threading. And high performance. You can say it is fast. Like string is a predefined data type. You don't have to manipulate string as a character array. So, this is it. It can run in all the platforms. Platform independent. And objects are like take human beings, take car, car, the color of the car, the gear, the speed. It will be different objects, the states. And behavior is like changing the gear. Like hearing in human beings is a function. It's a behavior of the year. You cannot expect it to smell. So, that's it. So, these are the basic definitions. I don't want you to teach any definition. Is this fine? Can I skip this? Class methods and instance variables. Instance variables are something which you call inside the function. It will be available for that particular instance. One more thing I would like to suggest is use a single naming convention. Naming convention should be unique. And also everyone should be following the same naming convention. For example, the class names should be starting with caps, uppercase. And then the next word also should start with uppercase. There is no nothing called as this should be uppercase and this should be uppercase. You cannot do like first underscore class. These is the naming convention of a variable. Camel cases are variable convention for naming convention for the variables. Please don't do it. One more thing. If you are naming a variable, for example, for... So, can everyone see it? I am writing a for variable. Sorry, for loop. Instead of that, I am writing a variable i. What do you mean by the variable i? You cannot write variable names that way. Just write it as iterator variable. This is used for the iterator. So, write it as iterator variable which will make the code easily readable. Everybody knows i is a iterator variable. Can I not use it for anything else? So, for avoiding the confusion, right? Proper names. It's okay. Even if you have nicknames, that's okay. But you have a name for the school or college, right? So, use proper name for anything. It will be readable and also it will not be redundant. For example, in the same code, you will have it for int i. For int i, you can use multiple int i's which is not a good thing to do. So, these are the naming conventions. Case sensitivity is very important. And method names also should be the first. Starting should be in the lower case and then second word should be uppercase. Don't do multiple things. If you follow a naming convention, do follow it. This is a simple program to say hello world. What it does is hello world app. Hello is an object of this class and then it will be called. When you call the function, say hello. This is a very basic syntax of the Java. I think everybody knows it. Can you call the hello function without creating an object? You can make it static and also one more thing you can do, you can call inside the constructor. You can write the system.outdoor.printl and inside the constructor. You can do that. So, we go to important topic, access modifiers. Everybody knows access modifiers? Sure. What do you mean by public? Can anyone say please be louder? What is public? So, you can access it inside like any class, any package, any subclass. It is accessible to the world. It can be called anywhere. Protector, you can call inside the class, inside the same package, inside the subclass, but not for the entire world. If it is going outside the package, you cannot be able to access it. No modifier, it's default. No modifier would be the default thing. And it can be accessed inside the class, inside the package, not inside the subclass and not inside the, like you cannot access it outside the package. And private, you can access it only inside the class. So, you should be... So, everybody knows what is public, static, void, main, string arguments. Everybody writes the line, right? Public, static, void, main, string arguments. What is the meaning of it? What is public? It's access modifier. It can be accessed from any class. It can be called. For example, I am outside the package, but still I can call the package and I can call the main variable, main functions. Static, it runs on its own. You don't have to call it. Void, main, void is... There is no return type and main is the main function. This is an example of an access modifier class. So, it shows what values will be fetched when you call each and every modifiers. You can try it out. This will be available. You can try it out. The code will be... You can try it out later. So, what is this? There is something called as this.pub, this.private, this.protected. What is this? This, the reference to the object, which is actually there now. This instance, whichever is available, we call this. So, they are extending a subclass, which will extend the base class access modifier. You use extends keyword for extending the class. If you want to derive something from the previous class, you use extend and you use subclasses. We call this a subclass. So, these are the keywords, which cannot be changed. Few keywords are available. These are non-access modifiers. Final is final. You cannot change it. You cannot change the value of a variable. You set it as final. Nobody can change it. Even if you write it again, final pi is equal to something. If you write pi again, it will throw you an error. You cannot redefine a variable. Abstract classes... Can abstract class be instantiated? So, we can just say, an abstract class is like, you know, say, figures and its area. So, it will have a subfunction class, figures and also area. The figure can be anything. It can be a trapezoid. It can be a circle. It can be a rectangle. It can be a triangle. Anything. And its area will be different. Every figure's area is different. So, you can extend it. For example, class, triangle, extends, abstract class, something. You can extend it. That's why we use this. It cannot be instantiated. It can be just extended. You can use it as a mother. That's it. It cannot be directly called untaught. Strict FP is strictly floating point. It cannot be redefined. Even if you put 10, it will be taken as 10.00. Synchronized access only by one thread at a time. Say, for example, there is only one track and two trains has to travel in the same track. So, they use something called a synchronization. They have signals. One train goes and then the next train comes in. If it goes together, it will be a problem, right? So, this is called synchronization in layman's terms. And volatile changed unexpectedly by other parts of the code. Like, it can be changed. So, finally, we have come to variables. Variables can be classified as local variable, class variable, and instance variables. So, class variables will be declared. So, for example, if you write class, public class, public class person, if you say a variable string, this is called a class variable. If you have at the start, it is declared at the start. You write a class and you declare it. It is called a class variable. And local variables are inside the loops. For example, you use a iterator variable. It can be localized. It need not be declared in the class, because it will not be used again and again. And instance variables, instance variables are something which you call, like, inside a specific class. It cannot be called outside. For example, you write it as public. It can be taken from anywhere. And a variable can also be an object. Has anyone tried it out? A variable can also be an object. That is the main thing we are going to use here. For example, there is a table person. You are fetching a list, say ID, name, date of birth, an email ID. How do you save it? You are writing a query, select star from person where state is equal to 13. So, you have a list of rows available. How do you save it? Can anyone say, how do you save it? Please answer me. Can anyone say, how do you save the number of rows which you fetch? You can go to my SQL and write, like, select star from person where state is equal to 13. So, you get a list of five rows. How do you save it? Please, can anyone say me? Yeah, yeah, exactly. You can store it as an array list of something, objects. Person is an object. You can write it as a beam. You can define a person class. Say, for example, this person will have a name, will have a date of birth. He will have an email and he has a state. This you call as a beam class. You define the variables of that object. What you can do is, you can, like, when you are calling this my SQL statement, after fetching, it will fetch the number of rows. You can save it as a person, single entity. You can call one person. You can set its name. Person1.name, set name is equal to this. Person.setDob, person.setEmail, person.setState. You can do all these things. You can save it as an object and put it in an array list. When you can, you can iterate it, you can iterate the array list and you can get the number of rows for you. This is how you save it. Please go through this array list. Like, it is very important that you learn array list and iterating things and representing things. That's what you do it in a report, right? If you want to say how many people got A grade, how do you know? You have to fetch the data and put it. You have to represent it. That's why we need JSPs, we need HTML, we need frameworks to represent data. So how many of you has actually tried writing a project with database connections? So what is important in having a database connection? Drivers. Use drivers and what is inside the driver? We copy-paste from Google. class.forName is equal to da-da-da-da. That's it, right? A MySQL connection is very important. You just please go through how it connects to the database, how it actually returns the fetched array. How can you save it as objects? How can you represent the data? Try doing all these things. I think this is all minimal things which are in the slide. You need to work on something which is not there in the slide. That's why I kept mentioning your SQL injections. You have to write a secure code. You have to write certain naming conventions. I think everybody knows all these things. And yeah, this is what is void, what is public, what is static. Everything is last year. And the principles of object-oriented programming. I'm not here to, I'm not a Java teacher. I'm not here to teach each and everything about Java. I'm here to say something which is required to program here. Can I skip this if you all know? What is abstraction, encapsulation, inheritance, polymorphism? It's all saying, okay, I can give you examples. Polymorphism, function overloading, function overriding. We can say all these things. These are all very simple programs. I expect that everyone will know they have taken courses in Java. The thing here is you have to connect to a database. We have to fetch array, write logic and do this. I think we have already discussed this. The meaning of abstract class. Abstract class cannot be instantiated. You cannot call an object of abstract class, although it can be subclass. You can extend it and you can use the same functions and you can override it. That's where comes polymorphism. Abstract class, for example, I told you, like the shape of the figure and also area. It can be a vague thing. You're supposed to do all these things. I have given you a template. So you can extend it to any particular figure and a particular area you can put as you like it. This extends, this is used for inheritance. We say encapsulation, data hiding, data hiding. What is that? Has anyone tried it? What is data hiding? Can anyone answer me? That is called data hiding. And also, it will be in a class file. When it returns, it's an array list. Try writing, let our list be a person. Person.getI. We write I as a iterator variable. So if you put that, you will get at something, at something, at something. You will not be getting the proper array list. Like it cannot be, it will not represent name is equal to, this is equal to, age is equal to, state is equal to. Not sure. You have to iterate it and everything. It will show things only when you know what exists inside the array list. You know that's a person array list, but you don't know the exact variables in the array list. Only programmers will know. Say for example, date of birth is a date. You cannot expect it as a string. If you don't know, the external users may not know what you have defined as a person. I can put a name person and I can write something else. Trash. So nobody knows it. That is data hiding. Nobody knows unless the programmer lets you know, okay, this is a bean class. This is what I have defined. That's what we saw. Polymorphism, figures and area again you can take it. So function overloading is something you use different kinds of parameters. Different, the number of parameters you put, it is all function overloading. Function overriding is like you have a parent class and you inherit it and then you write a function inside that with the same name. It will overwrite the parent function. This is function overloading you can see. So some of two integers, a float and a integer, three different integers. It will all give you, it is all called function overloading. And function overriding is as I have explained. If you inherit a class, you can overwrite the class of the function of the thing which is available in the parent class. It will not be taking that. It will take only things which you write in the subclass. So yeah, we have come to a very important topic threads. When you write any code, you have to use threads. What is the use of thread? We have discussed several examples, right? IRCTC booking, use threads. So when you open the website like at 9.58, it says two minutes remaining, your session gets expired. That is also thread. You save everything on thread. You can make things sleep. Okay, don't do this. Well, sending an email. Okay, let's say you get mails from different subscribers, right? Okay, you can subscribe to pin interest. Pin interest will send you mails. Are you getting any subscribed emails in your mailing list? Sometimes things go to spam. Sometimes they go to spam because there is no proper interval in the mails sent. It is because of that. So if they send more than 1000 mails in a minute, they will actually identify it as spam, Google, Yahoo, everything. So it goes in the spam folder. So you put a sleep of a second or two after 50 emails, after 100 emails, 30 seconds, you will not be marked as spam. So you can also send if you have a list of email addresses, but the possibility is that you will be marked spam. If you don't put a sleep, that's where thread comes into picture. You can use threads for sleeping, making the work to sleep for some time. So thread can also be used when we use synchronized operators. For example, two dependent things are there, and you have to execute the second thing only after the first thing does. It takes the input of the first thing. So you can put the second thing at sleep until the first process. You don't have to waste the memory till then. So you just put things in sleep. So when you start, it goes into a runnable state and it is running. You can make it sleep, wait or yield until the next waiting state or something. And yeah, important thing is exception handling. You're going to help me out in this. We will write a program to compute factorial. Everybody knows factorial, right? People will recursively do it. So if I give a input of y, you will get 5 into 4 into 3 into 2 into 1. You get the result. You get this as a result. So what are the exceptions which can be there? I give like int, entire integer. We give a box. So what are the exceptions which can be available here? Can you say me, list out the exceptions? Please. Yeah, first one is entering a character. If you enter a character, it should throw an error, right? You have to validate it. It is an exception. You cannot put a character. You cannot put a string. You cannot put any different data type. And next one, you cannot put negative numbers, floating points. Then you cannot put float. It has to be strict. Say even if you put an integer, say I put 100, do you think factorial will compute? I am just saying for and what we will do is we will iterate it with I star something which is coming so that it is a recursive function, right? So even if you put this, if you return an integer again, it will throw an exception. For 100, it is not an integer. Like if you multiply 100 into 99 into 98, the return will not be an integer. So we should make sure that even if you enter an integer, if you have to get a proper answer, you have to define the data type. Else it will throw an exception. You have to handle the exception. That is why we want exception handling, okay? So in Java, like which can throwable, like exception can be throwable, can be errors, it can be exception and runtime exception. In runtime exception, you have null pointer exception, number format exception. This comes under number format exception. If you try to return the factorial of 100 as an integer, you will have number format exception. If you try to return a floating point value as an integer, it will become a number format exception. Make sure that you do not make all these mistakes. Even if you make the mistakes, you have to write an exception class in the catch and finally block so that it will print what actually the exception is and you can debug it. Index out of bound. Where do you get index out of bound exception? I raise. You always get. Okay. Everybody has got it. IO exception, SQL exception, malformed URL exception. When you cannot fetch the variables in the URL. So have you noticed they generally use Amazon simple to separate variables in the URL and they say ID is equal to this thing and password is equal to this thing. They use and as a delimiter in the URL. So you can pass things easily. That's why people use post methods instead of get in the HTML forms. So you don't have to see everything in the URL catching exceptions. It's very important that you catch all the exceptions and you debug the code. You will know things when you put in wrong test cases. That's called destructive testing. Like when you want, okay, your enemy has written a code. You want to distract it. Say that you have written a shit code. So what do you do? You inter malicious values. So for your own code, also you have to do that. To make sure things work. And what is the importance of finally block? Try catch. Finally block always executes irrespective of whatever is hanging there. Say the try is having some exception and you want to return something. At least you want to return a dummy value. So you can put it in finally and you can close the connections. You can close the prepared statements. You can close the result sets. So your memory will be free even though Java has an automatic garbage collection thing. You can also do it to increase the speed. We have already spoken about this, right? Constructor, you don't have to call a constructor. It will be automatically executed. Things under that also will be automatically executed. There's the same name as a function name. So these are the references you can go through. Do you have any doubts? We have completed well before time. What is the use of interface? Normally we are not using interfaces as such. Like here. But in IIT Bombay X and other sites, you will have a class. So in our code we are not going to write any interfaces. We are not going to describe anything generic to something else. The first thing, if you have to inherit certain characteristic. Say for example, what is your name? Vasudev. Vasudev has a good characteristic of asking questions. It can be inherited to someone else sitting on the first bench. What is your name? Abhishek. Abhishek can inherit certain qualities of Vasudev's. So that is why we use that. Like normally we don't use that in the code. When you have MIS systems, we don't use inheritance as such. We just try to collect data, manipulate it, fetch it. Like our work will be most like data analyst job. And you have to put in a certain logic to have a sorting of whatever you want. The collection of data, you have a collection of data and you manipulate it and you display it. That's what we want. Anything else? So the important concept is that you write my SQL query. You have to know how to manipulate it, how to save it in a hurry list, how to iterate it, how to display it. And also you can call certain functions in Ajax. Everybody should know Ajax and little bit of JavaScript. If you know document.getElement by ID, that is more than enough. And you could find all validations. I think everybody knows it, right? And to display it, you can put a name, you can put different variables. Say for example, you want to display something, person's name. As I mentioned you, it encrypts it. So it doesn't say a person's name until you call the person name, person.name. You can have it as a name in the HTML tag and you can display it. That is how you display it. Anything else? That's it. You can wind up the session. So if you have any doubts, you can mail me at abhinaya.itb on Java. I'm not a Java teacher, but still. Thank you.