foreign students as students are bonding I am starting preparing the Java practical videos along with the aw the first practical is creating a simple calculator application using servlet for developing the application I am using netbins as suggested by University so my first practical Concepts creating a simple calculator that means two numbers need to be accepted and from the list of choices like addition subtraction multiplication division user will be selecting any of the one and when the user clicks on a submit depending on which Choice has been done by the user the appropriate operation has to be done and operation output need to be displayed to the user so let's start working with this practical first I am going to netbeans selecting the new project here I am coming with the Java web selecting web application given the click on next given the name of this application a practical 1A then give a click on next select the server which you would like to use either a glass fish or maybe the Tomcat I am right now selecting Tomcat you can select glass space also not a issue then given a click on next no need of selecting any of the framework just give a click on finish so a new project gets created and we need to develop two different pages one I need to develop HTML page where the data will be accepted and second the servlet where data has been processed that means the calculation has been done so inside a body I am planning to the by default page has been created for the index.html and here I am interested in creating the form by saying form method equal to post action equal to the name of the server maybe I am given the name of the server it adds calculate so the servlet name when I'm creating the servlet it will be calculated see capital mean foreign first number then providing input type equals number name equal to T1 this is the object name and BR tag for a line break further I am specifying second number input type equal to number name equal to T2 again the BR attack or a line break I need to have a submit button but before the submit button the choices has to be given to the user the choices can be given in drop down list or the choices can be given in radio button now I am interested in giving the choices in terms of what I should use drop down list or a radio patterns radio button the students are saying radio better so here I am preparing the review button by providing input type equal to radio name equal to R1 value is something important so I'm providing value equal to maybe I am providing the value for addition I am providing the value as that a capital and here I am using addition then the second radio button I just copy paste the radio button second third fourth so four Rowdy buttons are there R1 same name has to be given for all the video buttons so that any one can be selected for a second radio button I am providing the subtraction and here also I am providing the value at SUV this is what is getting displayed and this is what is getting passed here I am interested in going for multiplication so I may be providing multiplication and this I need to go for division so I am saying division and I give a name as the IV fine then I need those submit buttons so I'm providing input type equal to submit while you don't want to provide let it be so when a user clicks on the submit button the data has been passed through the post to the servlet named as calculate and now the work need to be done by the calculate servlet let's see how the process need to be done so first I need to create a calculate server so I give a right click on the project selected the option new and given option called as servlet here the name of the servlet is calculate and the name of the package that given as com.test my favorite package I don't mind then give a click on next there is no need to specify a deployment descriptor so I give a click on finish a ready-made servlet has been developed for you if you don't want to use ready-made servlet no issue just copy paste this particular code and keep it somewhere else so you can use it afterwards and delete the entire circuit you can develop the entire servlet by your own you know your package name is com.test so the first statement is going to be packets from the test next is importing all the required packages so I am providing input Java IU package as well as import Java x dot servlet.http.astric so two packages had taken then I'm creating the public class by saying public class the name of this Outlet extend HTTP server will be having a service method or a do get method or a do Post method uh or you can create your own method in which you write a code and then call the created method under rookette also and then they do post also so I'm interested in creating the third option where I will be creating my own method and that method will be called in do get also and do Post stores so I'm specifying here public return type is going to be void maybe I just say My Method name as process request in the bracket two parameters one is HTTP servlet request object what is the name of the object I had given the name of the object at the request and HTTP servlet response object and name of the object had given as response and this method must be throwing two exception one is servlet exception so through this bullet exception or this real exception it is those servlet exception and one is called the io exception so I am throwing server exception as well as what here are you exception yeah okay fine I'm just changing it as not a request over here I need a response so two two parameters are there one is actually reserved request second HTTP servlet respond the same method I just copied for twice and I just changed the name of the method I had kept the name of the method over here as do get and here I'd given the name of the method as do pose fine so you know that when your forms method is post the servlets do post is called and if your forms method is get then the servlet do get is being called and I don't know whether my form method is getter post so I am keeping both the method and I am calling my process request the Creator method over here under do get and same way process request and reduces so you may come through a post or you may come through the gig you will be always going to My Method named as process request now here what I'm interested I am interested in sending the response towards what your client when I'm sending the response to the client I need to utilize HTTP servlet response object and my response object over here named as response and my request object is named as what request so here I am writing first of all an object of print writer so I am creating print writer object out equal to response dot get right and further I would like to um if you want you can write a try cash for handling the exception but I'm okay with not handling the exception but I am just interested in setting my content type also so I'm writing response dot set contain type and providing content type as text public HTML right so output text as well as HTML and I am writing the basic format saying out Dot println starting with HTML again I'm providing out Dot println closing with the HTML now this entire code has been developed by the netbeans and given it to you is starting with the head tag and closing with the head tag as I do not write anything inside ahead and again we're emitting out dot println body type and closing with the body now inside the body tag I would like to do my operations of addition or a subtraction or a multiplication or a division an output I would like to show to the end user correct so first thing take the input which is received from the user so I am providing in text equal to integer dot percent in the bracket request dot method is get parameter so I am providing request dot get parameter foreign the text box name is T1 so the value of T1 the retread converted in integer stored inside X then writing into y equal to integer dot percent request dot get parameter the second text box name T2 now I would like to take operator so I'm writing string op ER equal to now the operator need to be accepted simple request Dot get parameter and my radio button's name is R1 so I'm keeping it at Urban so the opr will be having a value either as add or at subtract or as multiply or at divide whatever the value which is being given by U over here so now operator value is been there with us I am saying n t n s equal to 0 and then providing out dot println it's one candle reserved is plus N S Plus H1 is closed now here I need to first of all calculate result by saying if opr dot equals or if I want you can write equals ignore string and the equal ignore case add so if suppose opr value is at a double d X Plus y I'll say again I am providing over here op ER dot equals ignore case SUV subtract and writing answer equal to x minus y l c f o p e r dot equals ignore case and providing over here multiplication so I am providing mul TI please remember that this is equals ignore case multiplied by Y and then providing last answer equal to x divided by y now this is the integer division so 10 divided by 3 will be only 3 not 3.3333 if you want 3.33333 then you have to be using the float the float dot password so variables floater okay and my task has been completed and I would like to run and check okay foreign [Music] what it is it is the URL which you need to specify for Tomcat server okay so you need to provide your web servlet name equal to calculate URL pattern equal to slash calculate and here I just completed my import of java x dot servlet.annotation.web server when this task been completed save your program and just run the HTML page it will take some more time for the first time because Apache comcat server is started now right now applications and then we are passing the values in the two text Boxes by default Edition is what being checked so my first number I had given as 10 and my second number I had given at 2 uh and further I'd give it a click on submit query the result is 12 if I say subtract my result is 8 if I say multiply my result will be 20 and if I say divide my result will be fine but please fraction is not considered because it using the data type as in fractions your data type has to be what float so you have to use cloud dot password for the same so this is our first practical practical one a uh students Please Subscribe the channel and if any requirements from your end please comment it out so I will try to create a videos for you for the same thanks a lot class [Music]