 So, welcome back after the break. So, let us start with more questions. I am already seeing quite a few questions on chat, but I would like to start with some live questions. We have Pyagraja College Madurai. Sir, I have doubt in the example you dealt when saying about BCN officer. Yeah. The table you used to ask instructor underscore department. It relates both the instructor and the department. Right. But I think that decompositional happen when the relation crosses second normal form itself. So, I think the question you are saying is if we wanted second normal form, would we have decompose that particular relation in the same way? Did we have to wait for 3NF or BCNF? In this particular case, second normal form like I said in our book we do not even care about it because we feel it is just of historical interest. Somebody defined it at one point. If you look at research papers, there are thousands and thousands of such concepts which people have defined at some point. And at some point you want to say please do not burden students with all these unnecessary concepts. It will just confuse them and won't lead to anything useful coming out of it. So, the first thing I would say is just forget about 2NF. If you want unnecessary things, by all means go read the literature to read not just thousands, but probably tens of thousands of papers have been written on databases, overall normalization, so forth. And there are many, many concepts out there which are not so important and should be best ignored. But since you have asked this specific question, I think in this particular case it is not a partial key dependency. I think it is a transitive dependency because we had ID to department and then department to something else. So, I think in this case, its second normal form would not have played any role. It could have already been in 2NF. Let us move to some other questions. Now, in order by class, if there are some 2 attributes in the order by class, then how will the result get sorted based on the second attribute or based on the first attribute? That actually fairly straightforward. Whenever you sort by multiple things, there is a standard lexicographic sort order which is very basic in computer science and in real life also. So, when you sort students by let us say a class and then within each class by role number, this is exactly what you are doing. You are sorting on 2 attributes class and then role number. And databases SQL in particular of course allows you to sort on 2 attributes. So, the first thing will the initially will be sorted on the first attribute. Now, there may be many tuples with exactly the same value for the first attribute. So, those are relatively sorted using the second attribute. And SQL gives a lot of control over this. You can say the first one should be ascending, the second one should be descending and so on and so forth. I hope that answers your question. At this point, I would like to request more questions on the current topic which is servlets and web apps. So, please try to restrict your questions to this area. The next question is what is the difference between the get and the post method? So, the basic difference is the get method passes its parameters by adding extra stuff to the URL itself. So, it is explicit in the URL. In the post method, the URL does not contain the parameters, but the HTTP protocol has some further back and forth communication through which the parameters are passed. In terms of writing the HTML file, the only difference is that you say method equal to get or method equal to post. There are couple of other methods to use for sending binary large amounts of data and so forth. So, that is the only difference from your viewpoint, but the protocol itself sends it differently. Now, from your point of writing servlets, you can write a get and you can write a do post method. You can write separate code for these two methods. Which one do you use? It depends. So, get is recommended only for things that do not do updates. The HTTP protocol specification strongly recommends against doing any updates based on a get method. Any update should only be done through the things that use the post method. Nothing prevents you from writing a get method that updates the database, but it is considered bad to do this because sometimes there are web crawlers and so on. Google can come crawling. It will use the get method. If you do an update through the get method, Google crawl can damage your database. So, it is highly recommended against doing updates using the get method. Updates should only be done using the post method and crawlers such as Google will not use the post method. They will only, if they find a form with the get method, they will use it with the post method. They won't. Another question is how to retrieve cookie information from the browser. So, if you are the web server, you use HTTP to retrieve it. That is part of the protocol. If you are a user, every browser has its own way to look at details through tools or preferences or so forth. Then you can dig in and go to security or so on. Somewhere in there, there is cookies and then you can view the cookies. Is it possible to have a constructor in a servlet? Can we use constructor instead of init? Now, let me mention the init method. So, we have focused on get and post method. We have only seen get. Post is similar. It is pretty much identical in terms of the interface. The init method is something which is used when the servlet code is first invoked. So, the very first invocation of a particular servlet will call the init method and that can be used to do some initial setup. For example, we have some thing at IIT Bombay which we use to do keyword search on data. So, the init method will basically load the data into memory and then the get method is used to query it. So, the very first time the get method is invoked or the post for that matter. The first time any method on this particular servlet is invoked. The web server will call the init method and that is used to load data, whatever data we need into memory. We also access a database, but for performance reasons certain things are loaded into memory first. So, that happens in the init. Now, the question was can you use a constructor instead? I am not sure about the answer to that question, but the recommended way to do initialization is to use init, not the constructor. One more question is, is HCTPS connection less or stateless? Connectionless is the answer here because the connection can be closed. It does not have to persist. Stateless means that you completely forget everything about the state. In fact, it does maintain state through cookies and other means. Adi, Sitar Pradesh, please go ahead. My question is related to ER diagram to relation conversion. In ER diagram session you have taken an example of Moodle in which you have taken a course as a strong entity and assignment as a weak entity. When we take a relationship between course and assignment, in that case when we convert it to the relation, course is converted to the relation directly by its primary key. But when we take the assignment, in that case we take the course primary key and discriminator attribute as a key for the weak entity. My question is here is that if both the entities are weak entities, in that case how we will convert it to the relation? Is it possible to convert if both the relations are weak entity? I think this question was asked earlier. In fact, we had an example of that. So, we made assignment a weak entity which is identified by course and then we had submission as a weak entity which was identified by assignment. So, that is exactly the kind of situation you are asking about. So, the idea is fairly simple. So, first of all we start with assignment which is identified by a strong entity. So, its primary key is the primary key of the identifying entity that is course ID followed by its discriminator. So, assignment ID. So, the assignment ID now is local within a course of assignment 1, 2, 3, 4 can exist in each course. So, now the assignment is uniquely identified by course ID comma assignment ID. Now, a submission is a weak entity identified by assignment which is itself a weak entity, but the rule says take the primary key of the identifying entity. In this case, the primary key of assignment is what course ID comma assignment ID. So, we take that and then the discriminator of submission to create the primary key for submission. So, supposing we had used may be student ID as discriminator for submission, then we will take course ID, assignment ID, student ID. Does that answer your question? Sir, another question related to cookies. Sir, when a user send a request to the server, server sends the response or cookies is stored to the browser. Also, you mentioned that the server also stores the cookies at server side. But, second time when existing user send the same request, how server knows that these requests came from the previous user? How the browser's cookie is compared with the server's cookie? Right. So, first of all, the web server has to tell the browser, please give me the cookie with the following name. So, as I said, a particular web server can only access cookies that it created earlier. So, the first time when you connected, a new session is created. If you use the servlet session API, you would say request.getSession true and a session is created. At that point, the server would create a cookie and send the cookie to the browser which stores the cookie. You don't see all this. It's happening underneath the part of the HDP protocol. So, now the cookie is stored on the browser. The next time you make a request, the server asks the browser, please send me the cookie with that particular name. It gave a name. I think the cookie has a name, user info or whatever else the name was. So, next time when the server says, do you have a cookie called user info, the browser will send that value back. And that value, like I said, is a string, randomly generated string. And the server will take the value which it got back from the browser and look it up in its local storage to see if that particular string is already available. If it is available, then it is part of an ongoing session. Another related question which you didn't ask, but let me answer it, what about session timeout? So, typically any web app has a timeout. So, if you don't use this thing for say 20 minutes or 5 minutes or 2 minutes or whatever else, the session expires. So, what exactly happens is that the web server throws out the information about that particular session cookie. So, what will happen is it will still ask the browser, do you have this cookie user info? The browser will send the cookie value which it has back. And the web server will look it up in its database. It is not a permanent database, just a in-memory transient thing. It will look it up. And what happened is because of the timeout, it threw that information away. And now when it looks it up, it will say, no, I can't find it. So, it will say, sorry, you don't have an active session and it will proceed to the login page. So, that's how session timeouts are done. You can also from your servlet, you can explicitly invalidate a session. So, that is an API call for invalidating the session also. If you want to log out the user, at that point you will immediately invalidate the session so that the next time request that comes from the user, the session will no longer be valid. I didn't show that, but that is part of the API. Does that answer your question? Thank you, sir. Thank you. Bidala Vishwakarma College, Gujarat, if you have a question, please go ahead. Yes, sir. Can you just a little bit explain the life cycle of Java servlet in brief? Yeah. So, the life cycle of a servlet, this is something which I skipped for brevity. But what happens is, sorry, let me explain it intuitively. I am not getting into all the details, but intuition. So, first of all, when you have created a servlet and compiled it, you have to tell the web server about this. So, what you do is, you deploy this thing by either copying the files into the web server, the application server along with some other configuration files, web.xml and so on, and start the server. Or you can actually deploy on an already running server. There is a way to package all of these things into a single file called a var file, and you can just deploy it. At this point, the application server has access to all your code, and it knows the mappings between the URL and the specific servlet code. But at this point, it does not actually do anything with it. It is just ready to be run when a request comes in. Now, when a request comes in, the first time particular servlet is requested, the application server is going to run an init method, and that init method is useful for you to do some setup. So, that is something which I explained a few minutes back. We can use it to load some stuff into memory, etcetera, etcetera. And now that setup is complete. After that the method which was called get or post, whatever method was called, that is actually executed, and that returns something to the user. So, now further request can come, get, post, whatever. But you may also want to close that servlet eventually. So, there is a way to tell the application server to close this servlet and turn it off. So, usually that is done if there is a long period of inactivity when this thing is not getting used anymore. So, you might as well close it and release resources from the app server. Remember the init method would have done some loading or could have done some loading of data into memory. What you want is if that servlet has not been used a long time, maybe you want to close it and release those resources. So, there is a way to tell the thing servlet container to close down this servlet. I would not get into the details, but there are API tools for this. So, I think now let us get back to some new slides. Now, let us move on. The next topic is scripting. So far we have been writing programs in Java servlets. There are some overheads to this. You have to compile it, deploy it and so forth. And people found that writing scripts which are interpreted on the fly can be a lot more convenient. So, there is two kinds of scripting. One is called server side scripting. The other is called client side scripting. Servet side scripting actually came first and the initial versions of it actually combined HTML documents with executable code inside it. And there are many alternatives. There is JSP, PHP and many other alternatives for server side scripting. I think I have an example slide here in JSP. So, what happens is you write a HTML page. So, the assumption is the bulk of your work in design is going to be HTML design. And this can be done by somebody who is not a programmer. They can use tools for designing HTML pages and create a HTML page. So, all this body here HTML head, body, all this can be created by somebody who does not know programming at all. In fact, they do not need to know all that much of HTML for that matter because there are tools to create HTML. Now, there are certain parts of this page which are going to be filled with dynamically generated data. Those parts you do the following. For JSP you simply say less than percent up to percent greater than everything in between here in the context of Java server pages. So, JSP is actually Java code. So, what we have here is actual Java code which earlier we would have written inside the servlet. So, let me show this and then contrast it with the earlier servlet. So, we have HTML as usual. Now, here this is a very simple thing. It says if request dot parameter name equal to null it says out dot print line hello world otherwise out dot print line name get parameter name. So, there are a few things happening here. First of all the parameter the variables request, out, response they are all defined in a standard way. The request must be would be referred to as request here that is guaranteed. The response where object will be called response. There is already a print writer out open on response. So, all that is guaranteed at this point. So, this Java code simply does whatever it needs with these objects. Now, what actually happens with this? There is a compiler which takes this and generates a servlet out of it compiles the servlet and then it can deploy it. So, here we basically had just HTML tags with Java code. But, JSP also has some other tags which act as some kind of library. To contrast if you see our servlet here the HTML code had to be inside of Java code. We had say out dot print line blah blah blah this is quite tedious sometimes. So, it is much easier for many apps to flip it and do it differently. So, let me wrap up with this slide on PHP then we will have our visitors coming. So, PHP is another very widely used scripting language and Moodle is written entirely in PHP and many other very large projects are done in PHP. So, this also scripting language. So, you will see that you have HTML coming up as is. But, inside the HTML you will have PHP code written like this less than question mark PHP up to question mark greater than everything in between here is actually code written in PHP. Now, this is a code which is interpreted and by a PHP interpreter and this code is there is a language PHP is a language. So, it has something which you see here it has if statement it has echo which prints the thing to the output it has variables global variables which are preset. For example, dollar underscore request is a variable that stores all the request parameters that you bought. So, if you say dollar underscore request square bracket and then single code name single code close square bracket. What is that? This is actually equivalent to request dot get parameter name that is equivalent in servlets. Similarly, echo goes to the output there is an is set which said checks if it is defined or not and so forth. So, with that we will take a break