Showing posts with label Servlet. Show all posts
Showing posts with label Servlet. Show all posts

Monday, March 30, 2020

Top Ten Servlet Jsp Interview Questions For Coffee J2ee Programmer - Faq

Servlets together with JSP Interview Questions are pith of whatever J2EE Interview. Its expected from candidate to convey adept cognition of Servlet, JSP, EJB , Struts or Spring inwards whatever J2EE interview. Consequently Servlets together with JSP Interview Questions are real mutual inwards whatever J2EE Interviews along amongst to a greater extent than or less questions from pith Java, Some interview Questions from Spring together with Some EJB interview questions. Since J2EE is primary platform for edifice company together with spider web application using Java programming language, its of import to fix good for J2EE interview, peculiarly If you lot are inwards application evolution space. Servlet together with JSP forms spider web layer of J2EE framework where Java Server pages is primary persuasion technology together with Servlets are primary Controller constituent of criterion MVC architecture. In this article nosotros volition meet couplet of nearly mutual or oftentimes asked JSP together with Servlet Interview questions together with answers, which tin assistance you lot on your J2EE interview grooming together with agreement to a greater extent than or less key concept of Java spider web applications.


JSP Servlet Interview Questions Answers
 together with JSP Interview Questions are pith of whatever J Top 10 Servlet JSP Interview Questions for Java J2EE programmer - FAQHere is my listing of oftentimes asked JSP Servlet Interview questions to whatever Java programmer. Most of these Servlet JSP questions has appeared inwards diverse score of J2EE interviews including 2 to iii together with 2 to four years sense level. None of these questions require special inquiry together with neither of them are tricky questions, they all are focused on fundamentals which is key to clear whatever interview.



Question 1: What is JSESSIONID inwards Java? When does JSESSIONID gets created ?
One of my favourite Servlet JSP Interview inquiry for 2 to four years sense programmers on spider web development. JSESSION id is a cookie which is used to handle session inwards Java spider web application. JSESSIONID is created past times Web Container whenever a novel session is created. See What is JSESSIONID inwards Servlet JSP for to a greater extent than details.

Question 2: What is departure betwixt include activity together with include directive inwards JSP?
Another real pop JSP Interview questions, to a greater extent than often than non asked to 2 to iii years experienced J2EE programmer. There are couplet of differences, nearly of import of them is that include activity is request  time inclusion piece include directive is translation fourth dimension inclusion of to a greater extent than or less other resources e.g. JSP or html pages. This questions is likewise asked every bit departure betwixt file include together with page include. See Include activity vs Include directive for to a greater extent than differences.

Question 3: How create you lot define application broad mistake page inwards JSP?
Almost inwards every Servlet JSP interview you lot volition meet inquiry from mistake handling. You tin define 2 kinds of mistake pages inwards Java spider web application, i is using tag <error-page> inwards web.xml together with other is past times using mistake page JSP which uses isErrorpage to declare that this jsp page tin survive used every bit mistake page. Other JSP uses that page past times using attribute errorpage="error.jsp". Whenever you lot larn an unhandled exception inwards JSP, asking volition survive routed to mistake page. See How to utilisation mistake page inwards JSP for detailed reply of this question.

Question 4: Difference betwixt sendredirect together with forrad inwards Servlet ?
One of the classical Interview Question from Servlet together with JSP. This inquiry is every bit sometime every bit Vector vs ArrayList inwards pith Java. Anyway meet difference betwixt sendredirect together with forward to reply this Servlet Interview question.

Question 5: How create take variable using <c:set> tag from JSTL ?
This is i of the tricky Servlet JSP question. Many people assumes that <c:set> tin alone add together or laid variables inwards a particular range only you lot tin likewise take whatever variable from whatever range using JSTL <c:set> tag. See How to utilisation <c:set> JSTL tag inwards JSP for exact agency to take whatever variable from whatever range inwards JSP page.

Question 6: What is departure betwixt Web Server together with Application Server ?
This is rather unproblematic Servlet JSP inquiry to answer. If you lot convey used EJB together with then you lot should know that , Web Server doesn't comprise EJB container together with EJB tin non survive deployed on that. Application Server is used to deploy together with run EJB inwards J2EE environment. See 5 departure betwixt Application together with Web Server to meet to a greater extent than differences.

Question 7: What is departure betwixt URL Encoding together with URL rewriting ?
URL Encoding together with URL rewriting is full general spider web concept irrespective of Java programming language. URL Encoding refers to encoding URL e.g. replacing infinite amongst %20, you lot tin meet this when browser sends asking to Server. On the other mitt URL Rewriting is agency to handle Session inwards spider web application. See URL Encoding vs URL Rewriting for to a greater extent than differences.

Question 8: How create you lot larn ServletContext reference within Servlet ?
ServletContext is real of import object inwards Java Web application. ServletContext object is i per spider web application together with serves every bit application range together with utilisation to shop mutual config together with things which doesn't alter on per session. Its slowly to larn reference of ServletContext inwards jsp using application implicit variable only inwards Servlet is non available inwards HttpServletRequest until version 3.0. You demand HttpSession object to remember ServletContext inwards whatever Servlet. Influenza A virus subtype H5N1 adept follow-up questions is How create you lot larn ServletContext inwards Struts Action shape or Spring Controller classes. See How to remember ServletContext inwards Servlet, Spring together with Struts for to a greater extent than details.

Question 9: What is departure betwixt ServletContext together with ServletConfig inwards Java ?
One of those classical Servlet Interview Questions which you lot can't afford to miss. Again ServletContext is used to supply application broad configure piece ServletConfig is used to configure together with supply initialization parameter to i Servlet. See ServletContext vs ServletConfig for to a greater extent than differences.

Question 10: Which opened upwards origin tag library convey you lot used ?
This is an interesting Servlet JSP questions together with gives an chance to exhibit how many tag library you lot are familiar amongst together with which ones convey you lot used. Most J2EE programmer reply this inquiry amongst maxim JSTL pith tag library, Struts tag library , Spring tag library or display tag, which is quite pop tag library to display tabular information together with provides lot of characteristic out of box e.g. paging, sorting together with export functionality.

Question 11: What is departure betwixt GET together with POST method inwards HTTP protocol?
Another classical spider web interview question, non specific to Servlet or JSP only real of import inwards context of spider web evolution which is based on HTTP protocol. There several differences betwixt GET together with POST method including length of information required to Send to Server. GET is less secure together with tin alone post express information thus non useful to transfer sensitive information. See GET vs POST HTTP method for to a greater extent than differences.

Question 12: What does load-on-start-up chemical element inwards web.xml do?
One of the tough Servlet JSP Interview inquiry peculiarly to 2 years sense guy, who may non survive exposed to all tags of web.xml. load-on-startup is related to loading of Servlet. See What is load-on-startup tag inwards web.xml for to a greater extent than details.

These were to a greater extent than or less Servlet together with JSP Interview questions together with reply you lot tin human face for quick revision purpose. If you lot convey faced whatever interesting Servlet JSP inquiry or if you lot are looking reply for whatever Servlet JSP inquiry than delight share.

Further Learning
Top 10 Spring MVC Interview question

Sunday, March 29, 2020

Difference Betwixt Genericservlet Vs Httpservlet Inwards Servlet Jsp - J2ee Question

Difference betwixt GenericServlet together with HttpServlet is 1 of the classic Servlet Interview Question, asked on many Servlet together with JSP Interviews on ii to four years sense developers. Since both GenericServlet together with HttpServlet forms footing of Servlets its of import to know What are they together with What is principal divergence betwixt them. From mutual sense together with at that spot names, its obvious that GenericServlet is a generic together with protocol independent implementation of Servlet interface piece HttpServlet implements HTTP protocol specifics. If you lot are working inwards Java spider web application or J2EE projects, you lot are around probable to bargain amongst HttpServlet all fourth dimension every bit HTTP is principal communication protocol of web. In this Servlet JSP article nosotros volition outline around of import difference betwixt HttpServlet together with GenericServlet which is worth knowing together with remembering.

GenericServlet vs HttpServlet

Here is my listing of divergence betwixt HttpServlet together with GenericServlet inwards Java Servlet API :

1) GenericServlet provides abstract service(ServletRequest, ServletResponse) method to implement which gets called past times container whenever it receives asking for processing, On the other manus HttpServlet overrides service method together with provides callback on doGet(HttpServletRequest request, HttpServletResponse) together with doPost(HttpServletRequest request, HttpServletResponse response) whenever it receives HTTP asking from GET or POST method. It too provides several other method based upon diverse HTTP methods of sending asking e.g. doPut() or doDelete() to conduct maintain HTTP PUT together with HTTP DELETE request.



2) Another difference betwixt GenericServlet together with HttpServlet is that afterward is a subclass of GenericServlet together with inherit properties of GenericServlet.

3) Generic servlet provides a rather easier agency to extend Servlet, its plenty to override service method to implement GenericServlet. Apart from extending Servlet interface, it too implements ServletConfig interface together with provides agency to stimulate got initialization parameter passed to Servlet from web.xml e.g. past times using getInitParamter().

 forms footing of Servlets its of import to know What are they together with What is principal divergence b Difference betwixt GenericServlet vs HttpServlet inwards Servlet JSP - J2EE question
That's all on difference betwixt GenericServlet together with HttpServlet inwards Servlet API. Its real rare you lot are going to run GenericServlet simply its practiced to know basics every bit its generally asked inwards diverse Servlet interviews every bit well. HttpServlet is primary Servlet flat which is used inwards Java spider web application from treatment customer request.

Further Learning
Difference betwixt URL Encoding together with URL rewriting

Sunday, November 24, 2019

Can You Lot Declare Constructor Within Servlet Class?

Yes, Servlet tin conduct maintain Constructor, it's perfectly legal but it's not the correct agency to initialize your Servlet. You should purpose the init() method provided past times the Servlet interface to initialize the Servlet. If you lot remember, Servlet's are particular inward a feel that they are instantiated past times the container as well as managed past times the container. Influenza A virus subtype H5N1 servlet container similar Tomcat creates a puddle of multiple Servlets to serve multiple clients at the same time. They instantiate Servlet past times calling the default no-argument constructor as well as suppose you lot conduct maintain declared unopen to other constructor which takes a parameter e.g. HelloServlet(String name) than Java compiler volition non add together the default no-argument constructor as well as Servlet container volition non able to initialize the Servlet. That's why it's of import non to render a constructor inward Servlet, but if you lot do, brand certain you lot besides add together a default constructor in that place for Servlet container.


Even though Servlet is the backbone of Java Web Application, many Programmer doesn't know commutation of Servlet e.g. who creates Servlet instance, life-cycle of Servlet instance, thread-safety as well as concurrency, Session administration etc. If you lot are only learning Servlet as well as JSP inward hotch potch manner, perhaps this is the fourth dimension to alternative upwardly a practiced mass similar Head First Servlet as well as JSP as well as read it from start to end. This is an former mass which is non yet updated to comprehend Servlet 3.0 as well as Asynchronous Servlet but all the same a practiced mass to larn fundamentals. Once yo acquire through this book, you lot tin response questions similar this past times yourself.

s are particular inward a feel that they are instantiated past times the container as well as managed past times the co Can You Declare Constructor within Servlet Class?



java.lang.InstantiationException inward Servlet

Sometimes, when developer declares constructor on Servlet they add together a parameterized constructor i.e. a Servlet constructor which accepts a parameter. Since coffee alone adds the default constructor inward whatever shape if in that place is no constructor specified, it volition non add together default constructor if you're Servlet shape already conduct maintain one. In this case, if Servlet container e.g. Tomcat tries to instantiate a Servlet inward guild to serve the outset asking from client, it volition throw the next exception:



HTTP Status 500 - Error instantiating servlet shape HelloServlet

javax.servlet.ServletException: Error instantiating servlet shape HelloServlet
org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:103)
org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:293)
org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:861)
org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:606)
org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:489)
java.lang.Thread.run(Thread.java:662)


Root cause:

java.lang.InstantiationException: HelloServlet
at java.lang.Class.newInstance0(Class.java:340)
at java.lang.Class.newInstance(Class.java:308)
at org.apache.catalina.core.StandardWrapper.loadServlet(StandardWrapper.java:1149)
at org.apache.catalina.core.StandardWrapper.allocate(StandardWrapper.java:827)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:129)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:103)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:293)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:861)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:606)
at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:489)
at java.lang.Thread.run(Thread.java:662)

You tin endeavour this yourself, only do a Servlet without a default no-argument constructor. Though it's only a error if you lot are sure, you lot tin conduct maintain your constructor but retrieve Servlet container calls that. I suggest, you lot should purpose the init() method to initialize the Servlet because that's the measure way.

Further Learning
Java Web Fundamentals By Kevin Jones
Spring Framework 5: Beginner to Guru
JSP, Servlets as well as JDBC for Beginners: Build a Database App

>

Java.Lang.Illegalstateexception: Getwriter() Has Already Been Called For This Response

This mistake comes when a Servlet calls the getOutputStream() method on response object for writing something afterwards calling the include() method. Suppose a Servlet calls the include() method to charge the response of a JSP. Since JSP has already written the response on it thence ane time again opening OutputStream on response object is illegal, you lot acquire the java.lang.IllegalStateException: getWriter() has already been called for this response error. This mistake besides comes when you lot endeavour to include response of but about other Servlet together with than tries to write something on output stream again. In short, your Servlet should never write anything on response object afterwards calling the include() method. 

Here is the detailed stack draw of exception :
java.lang.IllegalStateException: getWriter() has already been called for this response
org.apache.catalina.connector.Response.getOutputStream(Response.java:580)
org.apache.catalina.connector.ResponseFacade.getOutputStream(ResponseFacade.java:183)
HelloServlet.doGet(HelloServlet.java:20)
javax.servlet.http.HttpServlet.service(HttpServlet.java:617)
javax.servlet.http.HttpServlet.service(HttpServlet.java:723)



This a perfect beginner mistake who tries to larn Servlet together with JSP past times case together with error. If you lot know the right agency to role the include() together with forward() method so you lot won't aspect upward this type of problem. That ane time again highlights the of import of learning novel technology from a expert mass similar Head First Servlet together with JSP. The mass volition no doubtfulness instruct you lot the basics, which is quite of import inwards the long journeying of learning novel characteristic every day.

 This mistake comes when a Servlet calls the  java.lang.IllegalStateException: getWriter() has already been called for this response



java.lang.IllegalStateException: getWriter() has already been called for this response Solution

If you lot expect at the mistake carefully, you lot tin encounter it pointing to HelloServlet.doGet() method at work 20, let's encounter the HelloServlet degree to respect out what's happening at work 20.

import java.io.IOException;  import javax.servlet.ServletException; import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse;  public class HelloServlet extends HttpServlet {     private static in conclusion long serialVersionUID = 1L;      public void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {         String userAgent = req.getHeader("user-agent");         String clientBrowser = "Not known!";         if (userAgent != null)             clientBrowser = userAgent;         req.setAttribute("client.browser", clientBrowser);         req.getRequestDispatcher("/hello.jsp").include(req, resp);         resp.getOutputStream().println("This is written from Servlet");     }  }

You tin encounter that at work twenty nosotros are calling the getOutputStream() afterwards calling the include() method of RequestDispather, this is causing the problem. Remove this work together with your programme volition run fine. The bottom work is you lot should endeavour to write anything on output stream of Servlet afterwards calling the include() together with forward() method because the response is already committed.


Further Learning
Java Web Fundamentals By Kevin Jones
Spring Framework 5: Beginner to Guru
JSP, Servlets together with JDBC for Beginners: Build a Database App

Saturday, November 23, 2019

6 Divergence Betwixt Forward() Together With Sendredirect() Inwards Servlet - Java

Servlet inwards JEE platform provides 2 methods forward() as well as sendRedirect() to road an HTTP asking to about other Servlet for processing. Though, both are used for forwarding HTTP requests for farther processing at that spot are many differences betwixt forward() as well as sendRedirect() method e.g. frontward is performed internally past times Servlet, but a redirection is a two-step process, where Servlet instruct the spider web browser (client) to become as well as fetch about other URL, which is unlike from the original. That's why forward() is every bit good known every bit a server-side redirect as well as sendRedirect() is known every bit the client-side redirect. Becuase of their usefulness, the departure betwixt forward() as well as sendRedirect is every bit good a oft asked Servlet interview question. Let's run into a twain of to a greater extent than differences to answer this query better.

While working betwixt Servlet as well as JSP, yous volition often utilisation these asking re-direction methods similar include(), forward(), or sendRedirect(). Sometimes, yous volition include the response from other Servlet as well as sometimes it volition merely frontward the asking for processing to about other Servlet.

Btw, if yous are preparing for Java JEE interviews as well as learning this every bit utilisation of your interview preparation, yous should every bit good banking concern jibe the Java Programming Interview Exposed, 1 of the rare majority which covers all of import topics for Java JEE interviews. It covers kernel Java, Spring, Hibernate, JDBC as well as other advanced topics expected from both beginner as well as experienced Java programmers.

 Servlet inwards JEE platform provides 2 methods  vi Difference betwixt forward() as well as sendRedirect() inwards Servlet - Java



Forward vs SendRedirect inwards Servlet

Now, let's run into about of import differences betwixt sendRedirect() as well as forward() method of Servlet API:



1) First as well as most of import departure betwixt the forward() as well as sendRedirect() method is that inwards instance of former, redirect happens at server destination as well as non visible to client, but inwards instance of later, redirection happens at customer destination as well as it's visible to client.

2) Another key departure betwixt forward() as well as sendRedirect() is that frontward is marginally faster than the redirect. The sendRedirect() is marginally slower than a forward, since it requires 2 browser requests, non one. See Head First Servlet as well as JSP for to a greater extent than details.

3) Third departure betwixt forward() as well as sendRedirect() method is that inwards instance of forward() master URL remains intact, piece inwards instance of sendRedirect() browser knows that it's making a novel request, as well as then master URL changes.

context (Some containers brand provisions for cross-context communication but this tends non to last real portable). But the sendRedirect() method tin give the sack last used to redirect users to resources that are non utilisation of the electrical flow context, or fifty-fifty inwards the same domain. See Head First Servlet as well as JSP for to a greater extent than details.

6) In the instance of forward, Since both resources are utilisation of the same context, the master asking context is retained. On the other hand, since post redirect involves a novel request, the previous asking orbit objects, amongst all of its parameters as well as attributes are no longer available after a redirect. (Variables volition demand to last passed past times via the session object).


That's all virtually  the difference betwixt forward() as well as sendRedirect() inwards Servlet. It's 1 of the of import concepts to larn for Java spider web developers. It's non merely of import from the interview signal of thought but every bit good from writing real-world Java spider web application using Servlet, JSP, jQuery as well as other JEE technologies. Practically, yous volition convey several choices for  redirecting HTTP asking e.g. yous tin give the sack produce as well as then past times using jQuery every bit well, but yous demand to utilisation sendRedirect() as well as forward() if yous desire to produce as well as then from Servlet.

Further Learning
Java Web Fundamentals By Kevin Jones
Spring Framework 5: Beginner to Guru
JSP, Servlets as well as JDBC for Beginners: Build a Database App

Java.Lang.Illegalstateexception: Getoutputstream() Has Already Been Called For This Response

This fault comes when y'all telephone vociferation upwards include() or forward() method afterward calling  the getOutputStream() from ServletResponse object as well as writing into it.  This fault is like to java.lang.IllegalStateException: getWriter() has already been called for this answer error, which nosotros accept seen inwards the earlier article.

This is the exception:
org.apache.jasper.JasperException: java.lang.IllegalStateException: getOutputStream() has already been called for this response
org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:502)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:424)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:313)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:260)
javax.servlet.http.HttpServlet.service(HttpServlet.java:723)
HelloServlet.doGet(HelloServlet.java:25)
javax.servlet.http.HttpServlet.service(HttpServlet.java:617)
javax.servlet.http.HttpServlet.service(HttpServlet.java:723)

as well as hither is the root cause :




java.lang.IllegalStateException: getOutputStream() has already been called for this response
org.apache.catalina.connector.Response.getWriter(Response.java:611)
org.apache.catalina.connector.ResponseFacade.getWriter(ResponseFacade.java:198)
javax.servlet.ServletResponseWrapper.getWriter(ServletResponseWrapper.java:112)
org.apache.jasper.runtime.JspWriterImpl.initOut(JspWriterImpl.java:125)
org.apache.jasper.runtime.JspWriterImpl.flushBuffer(JspWriterImpl.java:118)
org.apache.jasper.runtime.PageContextImpl.release(PageContextImpl.java:180)
org.apache.jasper.runtime.JspFactoryImpl.internalReleasePageContext(JspFactoryImpl.java:118)
org.apache.jasper.runtime.JspFactoryImpl.releasePageContext(JspFactoryImpl.java:77)
org.apache.jsp.hello_jsp._jspService(hello_jsp.java:80)
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
javax.servlet.http.HttpServlet.service(HttpServlet.java:723)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:388)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:313)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:260)
javax.servlet.http.HttpServlet.service(HttpServlet.java:723)
HelloServlet.doGet(HelloServlet.java:25)
javax.servlet.http.HttpServlet.service(HttpServlet.java:617)
javax.servlet.http.HttpServlet.service(HttpServlet.java:723)


If y'all expect at the stack describe it points to HelloServlet class, which is our Servlet, the business 25 of HelloServlet seems to live on causing the problem.

You tin dismiss run into that nosotros are calling the include() method afterward calling the getOutputStream() on Servlet object. Just comment out the telephone vociferation upwards to getOutputStream() and everything volition live on Ok.  To acquire to a greater extent than close Servlet as well as JSP,  read Head First Servlet as well as JSP, ane of the best books from concluding 10 years for learning JSP as well as Servlet.



Here is the consummate Java Servlet for your testing, y'all tin dismiss run this Servlet into Tomcat correct from your Eclipse IDE.
import java.io.IOException;  import javax.servlet.ServletException; import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse;  public class HelloServlet extends HttpServlet {      public void doGet(HttpServletRequest req, HttpServletResponse resp)             throws ServletException, IOException {         String userAgent = req.getHeader("user-agent");         String clientBrowser = "Not known!";         if (userAgent != null) {             clientBrowser = userAgent;         }         req.setAttribute("client.browser", clientBrowser);         //req.getRequestDispatcher("/hello.jsp").forward(req, resp);          resp.getOutputStream().println("This is written from Servlet");         req.getRequestDispatcher("/hello.jsp").include(req, resp);     }  }

That's all about java.lang.IllegalStateException: getOutputStream() has already been called for this response fault inwards Servlet. You accept learned what crusade this fault as well as how to laid upwards this. In short, this fault comes when y'all telephone vociferation upwards the include() or forward() method afterward committing the answer or past times calling the getOutputStream() on the answer object. 

Further Learning
Java Web Fundamentals By Kevin Jones
Spring Framework 5: Beginner to Guru
JSP, Servlets as well as JDBC for Beginners: Build a Database App

4 Ways Of Session Administration Inwards Servlet Java

Session tracking or Session management is an of import characteristic of modern spider web applications which allows the server to think it's clients. By keeping a session for each user, Server tin serve the customer better. It likewise helps inwards safety, security in addition to personalization in addition to must for sure enough sort of spider web applications e.g. e-commerce sites similar Amazon or e-bay which stores item selected past times the user for buy inwards a shopping cart, fifty-fifty after the user is logged out. Since HTTP is a stateless protocol, in that place are no ways to know that 2 HTTP requests are related to each other i.e. they are coming from the same customer or they are business office of the same process. Session tracking is a machinery that Servlets in addition to Java Web application purpose to maintain soil nearly a serial of asking from the same user across closed to menstruation of time. By keeping a session, an e-commerce site tin maintain add together to bill of fare facility in addition to likewise overstep on tracks of how y'all interact amongst the application. Since HTTP doesn't render a default agency to rails Session, in that place are closed to non-standard ways to create create Sessions inwards Servlet JSP based application. Let's convey a closed await on them.



Types of Session Tracking inwards Servlet

Since Session management needs to go amongst all spider web browsers in addition to likewise considers user's security preference, oft an identifier i.e. a SessionId is used to overstep on rails of asking coming from the same customer during a fourth dimension duration. There are 4 master copy ways to create create Session inwards Java Web application written using Servlet in addition to JSP.

1) URL rewriting
2) Cookies
3) Hidden Form fields
4) HTTPS in addition to SSL


let's meet them inwards picayune flake to a greater extent than detail:



URL rewriting
URL rewriting is a method of session tracking inwards which closed to extra information (session ID) is appended at the halt of each URL. This extra information identifies the session. The server tin associate this session identifier amongst the information it has stored nearly that session. This method is used amongst browsers that create non back upwards cookies or where the user has disabled the cookies. If y'all involve to rails Session from JSP pages, in addition to thence y'all tin use <c:out> tag for URL-rewriting. It automatically encodes session identifier inwards URL.


Hidden Form Fields
This is i of the oldest ways to create session tracking inwards Servlet application. Similar to URL rewriting. The server embeds novel hidden fields inwards every dynamically generated shape page for the client. When the customer submits the shape to the server the hidden fields position the client. See Head First Servlet in addition to JSP for to a greater extent than details on how to purpose hidden shape plain to create create session inwards Servlet JSP.

 Session tracking or Session management is an of import characteristic of modern spider web applications 4 ways of Session management inwards Servlet Java



Cookies
H5N1 cookie is a pocket-sized amount of information sent past times a servlet to a Web browser. H5N1 cookie is saved past times the browser in addition to subsequently sent dorsum to the server inwards subsequent requests. H5N1 cookie has a name, a unmarried value, expiration appointment in addition to optional attributes. H5N1 cookie's value tin uniquely position a client. Since a customer tin disable cookies, this is non the most secure in addition to fool-proof agency to create create the session. If Cookies are disabled in addition to thence y'all tin fallback to URL rewriting to encode Session id e.g. JSESSIOINID into the URL itself.

 Session tracking or Session management is an of import characteristic of modern spider web applications 4 ways of Session management inwards Servlet Java


Secure Socket Layer (SSL) Sessions
Web browsers that back upwards Secure Socket Layer communication tin purpose SSL's back upwards via HTTPS for generating a unique session key every bit business office of the encrypted conversation. Modern days online meshing banking website, ticket booking websites, e-commerce retailers similar Amazon in addition to e-bay all purpose HTTPS to security transfer information in addition to create create the session. You tin likewise see Murach's Java Servlets in addition to JSP to larn to a greater extent than nearly how HTTPS tin endure used amongst Java spider web application.


That's all nearly different ways to rails Session inwards Java Web application. Cookie was the most pop agency to create create Session amongst a fallback to URL rewriting when Cookies are non enabled at the customer side. While to a greater extent than security sensitive applications e.g. online e-commerce portals similar Amazon, FlipCart, EBay, online banking websites, go booking websites, or whatever other websites which bargain amongst sensitive information e.g. personal, fiscal or professional person they purpose SSL in addition to HTTPS to secures transfer in addition to maintain them.

Further Learning
Java Web Fundamentals By Kevin Jones
Spring Framework 5: Beginner to Guru
JSP, Servlets in addition to JDBC for Beginners: Build a Database App

3 Departure Betwixt Spider Web Server Vs Application Vs Servlet Containers Inward Coffee Jee

In the Java EE, or J2EE or JEE world, in that place is a lot of confusion betwixt terminology, which is quite evident that straightaway nosotros accept 3 words (J2EE, Java EE, as well as JEE) to clit the same technology platform. You volition encounter Java developers using the damage similar Web Server, Application Server, as well as Web containers interchangeably but they are non precisely same. The original departure betwixt a Web server as well as an application server is that spider web server is meant to serve static pages e.g. HTML as well as CSS, spell Application Server is responsible for generating dynamic content past times executing server-side code e.g. JSP, Servlet or EJB. One of the most pop spider web servers is Apache HTTPD which is oft used inwards conjunction amongst Tomcat to host many Java spider web application. Now, tomcat is non precisely an application server, it's to a greater extent than of a servlet engine or spider web container or too known equally servlet containers because it provides the runtime environs for Servlet as well as JSP but doesn't render the services similar EJB as well as distributed transaction which are a key characteristic of the application server inwards Java JEE world.



Web Server vs Application Server vs Web Containers

From the outset business office it is clear that Web server serves static content, but, both spider web containers as well as application servers dynamic content. Let's encounter a span of to a greater extent than points to empathize the departure betwixt Web as well as Application Server equally good Servlet engines similar Tomcat as well as Jetty.



1) Examples
In corporation to meliorate empathize the difference, you lot must know roughly pop examples of the spider web server, application server, as well as spider web containers. Apache as well as IIS are 2 pop spider web servers. Apache is used everywhere including Java basis but IIS is to a greater extent than pop inwards Microsoft ASP .NET world. From Java EE perspective span of pop application servers are IBM WebSphere, Oracle WebLogic, Glassfish as well as Redhat's JBoss. Coming dorsum to spider web containers or servlet engines, Apache Tomcat as well as Jetty are 2 of the most pop Servlet engine inwards Java spider web world.



2) Features as well as Responsibility
The meaning departure betwixt spider web server as well as application server comes from a responsibleness perspective. Web servers are responsible for serving static content e.g. HTML over HTTP protocol spell application server is responsible for serving dynamic content, managing EJB pool, facilitating distributed transaction, facilitating application lookup over JNDI, application safety as well as others. While spider web containers are alone responsible for generating HTML past times executing JSP as well as Servlet on Server side.

This is too 1 of the pop questions on Java JEE interviews, but for meliorate preparation, you lot tin too refer Java Programming Interview Exposed book, 1 of the best to produce for Java spider web evolution interviews.




3) Service
One to a greater extent than departure betwixt an application server as well as spider web server comes from the service perspective. It's expected from a Web server to render HTTP protocol degree service spell application server is supposed to render to a greater extent than powerful as well as dynamic Web service as well as concern degree service via EJB (Enterprise Java Beans). Essential services similar Database connector pooling is non alone provided past times application server but too past times Web containers similar Tomcat. You tin read to a greater extent than nearly how to setup connector puddle inwards tomcat here.


4) Usage
Once you lot know the departure betwixt spider web as well as application server as well as spider web containers, it's slow to figure out when to job them. You take away a spider web server similar Apache HTTPD if you lot are serving static spider web pages. If you lot accept a Java application amongst only JSP as well as Servlet to generate dynamic content thus you lot take away spider web containers similar Tomcat or Jetty. While, if you lot accept Java EE application using EJB, distributed transaction, messaging as well as other fancy features than you lot take away a total fledged application server similar JBoss, WebSphere or Oracle's WebLogic.

You tin too job spider web server as well as application server together inwards the same setup equally shown inwards the next example:

 in that place is a lot of confusion betwixt terminology 3 Difference betwixt Web Server vs Application vs Servlet Containers inwards Java JEE



That's all nearly the difference betwixt Web Server, Application Server as well as Servlet Container in Java as well as JEE world. Remember, each 1 of the accept dissimilar live on as well as many times used together inwards Java Web world. For example, 1 of the pop setups is apache fronting Tomcat. You tin job this setup if your Web application is alone using JSP as well as Servlet as well as doesn't take away EJB or distributed transaction feature. More basic services similar Database connector pooling is too provided past times Tomcat. On the other hand, if you lot accept total fledged Java EE application including EJB thus you lot take away a proper application server similar WebSphere, WebLogic or JBoss to host your application.

Further Learning
Java Web Fundamentals By Kevin Jones
Java EE amongst Vaadin, Spring Boot as well as Maven
Spring Framework Master Class - Beginner to Expert

Difference Betwixt Include() In Addition To Forward() Methods Of Requestdispatcher Inwards Servlert

What is the departure betwixt include together with forrard methods of RequestDispatcher interface is 1 of the frequently asked Servlet questions from Java EE interviews together with we'll run into how yous tin reply this inquiry on your interview. You larn the RequestDispatcher reference either from ServletContext or ServletRequest interface together with fifty-fifty though both include() together with forward() method allow a Servlet to interact amongst closed to other servlet, primary departure betwixt include() together with forward is that include() method is used to charge the contents of the specified resources (could locomote a Servlet, JSP, or static resources e.g. HTML files) straight into the Servlet's response, equally if it is purpose of the calling Servlet. On the other hand, forward() method is used for server side redirection, where an HTTP asking for 1 servlet is routed to closed to other resources (Servlet, JSP file or HTML file) for processing.

This inquiry is often asked equally a follow-up of to a greater extent than pop Servlet Question, the difference betwixt forward() together with sendRedirect() inwards Servlet. Now, nosotros know the key departure betwixt these 2 methods, let's run into a twain of to a greater extent than differences to reply this inquiry a fiddling chip better.

Just recollect that, fifty-fifty though yous tin larn the RequestDispatcher reference from ServletContext.getRequestDispatcher() method or ServletRequest.getRequestDispatcher() method only at that topographic point is a slight difference, the pathname of Servlet must get amongst a / and is interpreted equally relative to the electrical flow context root, piece inwards illustration of ServletRequest, path tin locomote relative.

Btw, if yous are preparing for Java spider web or Java EE developer interview, yous tin likewise run into the Java Programming Interview exposed for to a greater extent than questions on Servlet, JSP, Spring, together with Hibernate, key skills for Java spider web developers.




include() vs forrard inwards Servlet

Before looking at the differences betwixt include() together with forward() method inwards Servlet, let's run into closed to similarities betwixt them.

1) Both include() together with forward() methods are purpose of RequestDispatcher interface of Servlet API

2) Both methods stimulate got objects of ServletRequest together with ServletResponse interface.

3) Both include() together with forward() tin interact amongst static together with dynamic resources e.g. closed to other Servlet, JSP or HTML files.


Now, let's run into twain of differences betwixt include together with forward() method from Servlet API:

1) First together with inaugural departure is that include() method includes the content of a resources inwards the response, the resources could locomote closed to other Servlet, JSP or HTML file. While forward() method is used to forrard the asking to closed to other resource.

2) The minute departure betwixt include() together with forward() from Servlet API is that If yous include a servlet or JSP document, the included resources must non endeavor to alter the response condition code or HTTP headers, whatever such asking volition locomote ignored. On the other hand, If yous include a Servlet or JSP document, the included resources must non endeavor to alter the response condition code or HTTP headers, whatever such asking volition locomote ignored.

3) Third together with a useful departure betwixt forward() together with include() method is that quondam is often used to include mutual boilerplate text of template markup which mightiness locomote included yesteryear many Servlets e.g. header or footer. While, forward() method is often used where a servlet is taking a controller role; processing closed to input together with deciding the number yesteryear returning a item response page.

Here are 2 diagrams which volition help yous sympathize how both include together with forrard methods of RequestDispatcher works inwards Servlet application:

How include method of RequestDispatcher works
You tin run into that the asking is for DispatcherServlet which calls include() method to include the response of Hello.jsp page, afterwards the response of DispatcherServlet together with Hello.jsp is combined together with sent to the client.

 What is the departure betwixt include together with forrard methods of  Difference betwixt include() together with forward() methods of RequestDispatcher inwards Servlert




How forrard method of RequestDispatcher works
You tin run into the asking is for Servlet1 which forwards it to Servlet2, whose response is together with hence sent to the client. The response of Servlet1 is non used or non sent to the client.

 What is the departure betwixt include together with forrard methods of  Difference betwixt include() together with forward() methods of RequestDispatcher inwards Servlert


That's all virtually the difference betwixt include() together with forward() inwards Servlet API. You should usage include() method to charge a resources which could locomote a JSP page or closed to other Servlet, together with usage forward() to redirect the asking to closed to other resources for farther processing, 1 time to a greater extent than yous tin forrard the asking to closed to other Servlet or JSP page.


Related Servlet together with JSP interview questions for Java programmers
  • Difference betwixt ServletContext together with ServletConfig inwards Servlet? (answer)
  • Can yous declare Constructor within Servlet class? (answer)
  • Difference betwixt GenericServlet together with HttpServlet inwards Servlet API? (answer)
  • Difference betwixt the spider web server, application server together with Servlet container? (answer)
  • How to grapple customer session inwards Servlet application? (answer)
  • Difference betwixt include directive together with include activity inwards JSP? (answer)
  • Difference betwixt jsp:include together with jsp:forward activity inwards JSP? (answer)


Further Learning
Java Web Fundamentals By Kevin Jones
Spring Framework 5: Beginner to Guru
JSP, Servlets together with JDBC for Beginners: Build a Database App

Saturday, November 9, 2019

Top Xl Advanced Java/J2ee Interview Questions Answers For Experienced - Iii To V Years

I have got shared many posts most Java interview query inward the past times but nothing, especially for back upwardly engineer perspective. Since at that spot are a lot of L1 as well as L2 back upwardly task exists inward BFSI (Banking, Finance, as well as Insurance Industry) as well as they are also for the longer term, I decided to write this post. When you lot move for a back upwardly engineer role, especially for Java application live on it to heart as well as person Java or Java EE application, Interviewer expects you lot know basics of Java as well as tin start/stop the application, come across log files, warning developers, as well as other aspects of the back upwardly e.g. opening conference pair to solve production issues, communicating to stakeholders, as well as involving correct peoples. In this article, I volition percentage questions to assist with technical aspects e.g. the essential skills you lot demand to clear a back upwardly engineer interview.

Even though you lot volition live on interviewed to back upwardly Java application, it's expected from you lot to know SQL, UNIX, XML as well as other key technologies which you lot volition exercise inward your day-to-day job. In this post, you lot volition notice questions which are asked to banking concern represent whether a candidate has required skills to back upwardly Java application or not.


39 Interview Questions for Java JEE Support Engineers

Here is my collection of some of the best interview questions for Java as well as JEE back upwardly professionals. If you lot are working inward production services or supporting Java application, these interview query volition assist you lot to create good on your interview. If you lot moving from evolution to back upwardly role so also these questions volition give you lot a proficient thought most what is expected from a Java JEE back upwardly engineers.

1) How create you lot banking concern represent your Java procedure is running on Linux? (example)
You tin banking concern represent past times using "ps" ascendancy as well as "grep" ascendancy e.g. ps -ef | grep "myprocess". The keyword which you lot exercise with grep for search tin live on anything unique to your process, something which appears inward its ascendancy draw e.g. get upwardly of the shape which implements the primary method. You tin also create "ps -ef | grep java" to listing all Java process.



2) How create you lot banking concern represent how much retention as well as CPU your Java procedure is consuming?
First, you lot demand to notice the PID of your process, which you lot tin notice past times using the "ps" ascendancy equally shown inward the previous question. Once you lot notice the PID you lot tin exercise the "top" ascendancy to notice the CPU as well as retention usage. Alternatively, you lot tin also exercise the prstat ascendancy equally shown here.


3) What does -Xmx as well as -Xms parameters mean?
These are parameters to specify heap size inward Java. The -Xms defines the size of the heap when JVM starts upwardly as well as -Xmx is used to specify the maximum heap size for Java application i.e. your heap cannot grow beyond that as well as JVM volition croak past times throwing OutOfMemoryError if your heap doesn't have got plenty infinite to create novel objects. See here to acquire to a greater extent than most heap retention inward Java.


4) What is the departure betwixt JVM as well as JRE?
The JRE stands for Java Runtime Environment as well as JVM stands for Java Virtual Machine. You install JRE to run Java application e.g. Applet or Core Java application or Web server similar Tomcat. The JVM is business office of JRE. See here to acquire to a greater extent than differences betwixt JVM as well as JRE.


5) What is the departure betwixt JVM as well as JIT? (answer)
The JVM stands for Java Virtual machine spell JIT stands for Just inward fourth dimension Compiler. The JIT is business office of JVM as well as used to convert the Java bytecode into native machine code which runs faster. There is some threshold gear upwardly if a code runs to a greater extent than than the threshold it becomes the candidate of only inward fourth dimension compilation past times JIT.



6) How create you lot accept the heap dump of a Java process? 
There are many ways to accept the heap dump of a Java procedure e.g. Tomcat, but most mutual is past times using tools available inward JDK e.g. jVisualVM, jCmd, as well as jmap. Here is the ascendancy you lot tin exercise to accept the heap dump of Java process:

$ jmap -dump:live, file=/location/of/heap_dump.hprof  PID

The heap dump volition comprise all alive objects as well as they are stored inward heap_dump.hprof file. Remember, you lot also demand PID of Java procedure which you lot tin notice past times using "ps" as well as "grep" ascendancy equally discussed inward the source question. You tin come across Java Performance Companion past times Charlie Hunt to acquire to a greater extent than most taking as well as analyzing heap dump inward Java to notice retention leak as well as other retention related errors. 



7) How create you lot accept a thread dump of a Java process?
Taking thread dump is easier than taking heap dump because you lot don't demand to call back tool. In Linux, you lot tin only exercise the kill ascendancy to accept the thread dump e.g.

$ kill -3 PID 

volition impress the thread dump inward the log file or where System.out is redirected. Similarly, inward Windows, you lot tin exercise Ctrl + Break from the ascendancy prompt. Alternatively, you lot tin also exercise jConsole as well as VisualVM to accept the thread dump of Java application inward both Windows as well as Linux. You tin also read Java Performance The Definitive Guide By Scott Oaks to acquire to a greater extent than most thread dump as well as heap dump.



8) What is OutOfMemoryError inward Java? How create you lot bargain with that?
The Java virtual machine throws java.lang.OutOfMemoryError when at that spot is non plenty retention to run the application e.g. no to a greater extent than retention to create novel objects, no to a greater extent than retention to create novel threads etc. The most mutual OutOfMemoryError is the java.lang.OutOfMemoryError: coffee heap space, which comes when at that spot is no to a greater extent than retention left to create a novel object.


9) What is the departure betwixt 32-bit as well as 64-bit JVM? (answer)
The primary differences betwixt 32-bit as well as 64-bit JVM are that afterward is designed for 64-bit operating arrangement e.g. Windows 8 or afterward versions of Linux. From Java developer's perspective, the primary departure betwixt them comes from heap size. Influenza A virus subtype H5N1 64-bit JVM virtually has unlimited heap memory equally compared to 4GB of the theoretical bound of 32-bit JVM. If your plan needs to a greater extent than memory, meliorate run it on 64-bit JVM with large heap space. See hither to acquire to a greater extent than most 32-bit as well as 64-bit JVM.



13) What is Garbage Collector? (answer)
The garbage collector is a element of Java virtual machine which is responsible for reclaiming retention from dead objects. It's i of the key components as well as allows an application developer to focus on application evolution rather than doing retention management. Some of the pop garbage collectors are a Concurrent Mark-Sweep garbage collector as well as G1 garbage collector inward recent times.


14) How create you lot analyze a heap dump?
There are many tools to analyze heap dump inward Java e.g. you lot tin exercise the jhat tool which comes along with JDK. You tin also exercise Eclipse Memory Analyzer to analyze heap dump to notice out whatever retention leak inward Java spell dealing with OutOfMemoryError inward Java. See Java Performance The Definitive Guide By Scott Oaks to acquire to a greater extent than about analyzing Java Heap dump.

 I have got shared many posts most Java interview query inward the past times but zero Top xl Advanced Java/J2EE Interview Questions Answers for Experienced - iii to five Years



15) What is the departure betwixt Web Server as well as Application Server? (answer)
The primary departure betwixt Web as well as Application Server comes from the fact that you lot cannot run EJB on the Web server similar Tomcat or Jetty. The application server similar WebLogic as well as WebSphere provides the runtime surroundings for EJB as well as other advanced services required past times Java EE or J2EE specification.


16) What is the departure betwixt Apache httpd as well as Tomcat?
Though both httpd as well as Tomcat are products of Apache software foundation, the httpd is to a greater extent than pop as well as used across the spider web as well as non only inward Java world. The httpd is a spider web server which tin serve static HTML files as well as dynamic content using PHP, Perl or Python, spell Tomcat is a Servlet container which provides the runtime surroundings for Servlet as well as JSP. You tin also exercise both Apache httpd as well as Tomcat together inward Java world.


17) Can you lot exercise Apache as well as Tomcat together?
Yes, you lot tin exercise Apache as well as Tomcat together. There are many Java spider web application which is fronted past times Apache spider web server to deliver static resources e.g. HTML files, images, configuration files etc. You tin so configure Apache to forwards the asking to Tomcat.


18) How create you lot start as well as halt Tomcat inward Linux?
When you lot install Tomcat inward Linux past times unzipping the downloaded package, you lot tin come across that at that spot is a startup.sh as well as shutdown.sh file inward the tomcat/bin directory. These scripts are used to start as well as halt Tomcat inward Linux. These scripts internally telephone phone Catalina.sh, the primary script to start Tomcat engine.



19) How create you lot start as well as halt Apache inward Linux?
The Apache server runs equally httpd daemon inward Linux as well as you lot tin either exercise kill command after finding the PID of httpd procedure equally shown hither or you lot tin exercise the apachectl script equally shown below to start as well as halt Apache spider web server inward Linux

Starting Apache spider web server inward Linux

$ apachectl start

Stopping Apache web server inward Linux

$ apachectl stop

Restarting Apache spider web server inward Linux

$ apachectl restart
or:
/sbin/service httpd restart

You mightiness demand root access to create if Apache spider web server is non running on your application account.


20) What is JDBC?
The JDBC stands for Java Database connectivity as well as it provides API to connect a database from Java programs. Different Java vendors e.g. MySQL, Oracle, Microsoft SQL Server, PostgreSQL they implement the API as well as provides their driver implementation to allow Java to connect to their database. Since almost every venture application has a database, JDBC is real of import for whatever existent globe projects.


21) What is the departure betwixt JDBC as well as JNDI?
As I said inward the previous answer, the JDBC stands for Java Database Connectivity as well as provides APIs as well as guidelines to connect a database from Java, spell JNDI stands for Java Naming as well as Directory Interface as well as provides a logical construction for retrieving resources e.g. database, messaging queues, venture Java beans without knowing their physical house e.g. host or port. You tin register a resources with JNDI as well as so residuum of your application element tin access them using JNDI name. The database connexion puddle is the most mutual resources accessed via JNDI inward web servers similar Tomcat or WebLogic.


22) What is database connexion pool? (answer)
As it get upwardly suggests, it only a puddle of database connections. Since creating a novel database connexion inward real-time is an expensive procedure as well as tin potentially deadening downwards the response time, many application maintains a puddle of active database connection. When a request comes inward they retrieve a connexion from the pool, acquire the information from the database as well as so render the connexion dorsum to puddle so that it tin live on reused. This way, response fourth dimension is improved inward most of the Java spider web application. See here to setup a database connexion puddle inward Tomcat using Spring framework.


23) Your Java application is connected to a Database via a connexion pool. Suddenly your database goes down? Is that an number with your Java application? Do you lot demand to restart your Java application?

hint: Since your Java application is using a connexion pool, it has active connections to database which volition acquire disconnected i time DB goes down. If you lot attempt to execute a query, you lot volition have Socket errors.



24) How create you lot shipping spider web service asking from Linux? (answer)
There are some commands available inward Linux e.g. curl as well as wget which allows you lot to shipping HTTP commands, which you lot tin exercise to telephone phone as well as essay your spider web services from Linux. Particular, Curl is used extensively to essay RESTful Web Services because it tin shipping POST request, GET request, asking with headers as well as also authenticate using both basic as well as digest authentication.

If you lot are working with REST API, I advise learning curl, it's real convenient to banking concern represent if your API is working properly using curl from the ascendancy line. You tin fifty-fifty write a script to automate those stuff.


25) What is the departure betwixt HTTP as well as HTTPS? (answer)
This is i of the mutual as well as like shooting fish in a barrel questions. Of course, you lot know the departure betwixt HTTP as well as HTTPS right? well, HTTP is insecure but HTTPS is secure, the extra "s" is for security, which agency it non exclusively encode as well as encrypt the message earlier sending but also verify the identity of the server past times using  SSL certificates provided past times global certificate government e.g. GoDaddy, Thawte, VeriSign, Digicert, GeoTrust, as well as Comodo.  See here to acquire to a greater extent than how SSL as well as Certifications run inward Java spider web application.


26) What is the departure betwixt the GET as well as POST method? (answer)
Another uncomplicated but ofttimes asked query on Java back upwardly interviews. The primary departure betwixt the GET as well as POST is that GET is both idempotent and rubber but POST is not. You tin burn GET asking multiple fourth dimension as well as it volition give the same number but multiple POST submission should ever live on avoided. GET is also used to read information from server as well as POST is used to shipping information to the server.


27) What is the departure betwixt Servlet as well as JSP? (answer)
This is some other interesting Java JEE back upwardly Interview Question. Even though both Servlet as well as JSP is used to create dynamic HTML the key departure betwixt them is their purpose. Servlet is meant for Java developers as well as you lot write to a greater extent than Java than HTML as well as that's why it serves equally Controller inward many pop MVC framework e.g. DispatcherServlet inward Spring MVC.

On the other hand, JSP is designed for HTML developers as well as it's to a greater extent than HTML than Java as well as that's why it is used equally "view" inward MVC frameworks similar Spring as well as Struts. See the link inward the reply for to a greater extent than detailed comparison.



28) What is the departure betwixt Struts as well as Spring MVC?
This is i time again a pop as well as ofttimes asked query on Java JEE Interviews. Even though both are pop spider web MVC framework for Java applications, the key departure is that Spring brings dependency injection source as well as Struts brings it afterward using Struts 2.0.

Spring is also a suite of libraries e.g. you lot acquire Spring Security to implement safety inward your application, so at that spot is Spring Boot, Spring Data, Spring Cloud as well as many to a greater extent than useful libraries nether Spring umbrella.

answer)
There are many differences betwixt JDBC as well as Hibernate but the most of import i is that JDBC provides an API to connect to the database as well as execute the query but Hibernate is an ORM (Object Relational modeling) framework, which agency it allows you lot to run with objects spell it takes aid of saving as well as retrieving object from database.

In short, inward JDBC you lot demand to write SQL queries to acquire as well as shop information from database but inward Hibernate you lot only bargain with objects, Hibernate takes aid of issuing SQL queries to the database.


30) What is the departure betwixt Stack retention as well as heap? Which i is faster? (answer)
These are only 2 dissimilar retention areas used to shop dissimilar kinds of variables. The stack is local to every thread spell heap retention is shared alongside all threads. Since Stack is closer to thread as well as unremarkably implemented using CPU registers they are faster than heap memory. The stack is used to shop local variables equally good method telephone phone frames spell heap is used to shop objects as well as shape metadata. See the detailed reply for to a greater extent than points.


31) What is the departure betwixt TCP/IP as well as UDP protocol? (answer)
There are several differences betwixt TCP as well as UDP protocol but the most of import of them is that TCP provides a guarantee of message delivery spell UDP doesn't give whatever guarantee. Because of this guarantee TCP sends to a greater extent than messages than UDP as well as thus eat to a greater extent than bandwidth as well as slower than UDP. TCP is also connexion oriented protocol spell UDP is connectionless. See the detailed reply for to a greater extent than points.

 I have got shared many posts most Java interview query inward the past times but zero Top xl Advanced Java/J2EE Interview Questions Answers for Experienced - iii to five Years



32) Your Java application is connecting to some other Java application (server) running on the remote host as well as listening on port 17865. Now, you lot don't have got access to that remote host to move as well as come across if the procedure is running. How create notice if the server is upwardly as well as running?
hint: you tin exercise the telnet command



33) You are supporting a Java spider web application which connects to many heart as well as person Java procedure as well as gets information from them to the distribution to clients? One customer complains that the asking for information is taking also long as well as it's almost similar hung? How create you lot troubleshoot this problem?

hint: banking concern represent the log, banking concern represent database, banking concern represent the file system


34) The Java application you lot back upwardly connects to a database via a DNS, which automatically switches to the secondary database server when the primary goes down. You notice that inward the trial of a failover, your Java application is non connecting to secondary DB server? How create you lot troubleshoot this problem?

hint: banking concern represent which version your Java application is running. Some JRE caches the DNS e.g. JRE 1.6

answer)
The deadlock is a status which tin occur betwixt 2 or multiple threads. In this case, each of the thread waits for each other as well as cannot progress. In Java, this unremarkably happens when thread 1 holds the lock required past times thread 2 as well as thread 2 holds the lock required past times thread 1. If your Java plan is hung so it could live on a deadlock. You tin accept a thread dump as well as notice out if whatever thread is waiting for the lock concord past times other as well as vice-versa. You tin also exercise jConsole tool to notice deadlock.


36) What is the race condition? (answer)
The race status is some other multithreading as well as concurrency põrnikas which happens due to racing betwixt 2 threads, for example, if i thread is updating a variable as well as minute thread tries to read the value earlier it finished. You tin avoid race weather condition past times properly synchronizing your code.


37) What is the departure betwixt PATH as well as CLASSPATH? (answer)
Both are key surroundings variable used past times Java platform, but the key departure betwixt them is that PATH points to the JDK binaries or native libraries e.g. java.exe, spell CLASSPATH points to Java binaries e.g. JAR files, which contains bytecode. PATH is also arrangement marker concept independent of Java but CLASSPATH is purely Java concept as well as used past times JVM to charge classes required past times Java application you lot are running.


38) How create you lot notice the Java version used past times your application? (answer)
You tin run the coffee -version ascendancy inward the ascendancy prompt to notice out the version of Java used past times your application. If you lot have got multiple JDK or JRE installed so brand certain you lot exercise the i which is used past times your application.


39) What is JAVA_HOME surroundings variable? (answer)
The JAVA_HOME is zero but a user defined surroundings variable which points to the installation directory of JDK. For example, if you lot have got installed JDK inward /opt/jdk_1.6_20 inward Linux so the JAVA_HOME variable volition betoken to this directory. Same goes for Windows or whatever other operating system.


That's all most 39 essential questions fro Java JEE Support Engineer. It's only a pocket-size gear upwardly of questions you lot tin hold off inward whatever service based companionship or investment banks but does call back to create key skills required for back upwardly engineers e.g. UNIX, SQL, Java, as well as others. In the adjacent business office of this article, I volition percentage some of the ofttimes asked questions from Java Support Engineer on SQL, UNIX, as well as other supporting technologies.


Other topic based Java Interview questions for to a greater extent than practice
  • 21 Java Inheritance Interview Questions as well as Answers (list)
  • 15 Data Structure as well as Algorithm Questions from Java Interviews (read here)
  • Top 10 Spring Framework Interview Questions with Answers (see here)
  • Top twenty Hibernate Interview Questions as well as Answers (list)
  • 10 JDBC Interview Questions for Java Programmers (questions)
  • 15 Java NIO as well as Networking Interview Questions with Answers (see here)
  • 20 Java Design Pattern Questions asked on Interviews (see here)
  • 10 Struts Interview Questions for Java developers (list)
  • 30 OOP Interview Questions with Answer (see)
  • 19 Method overloading as well as overriding interview questions (see here)
  • 10 ofttimes asked Servlet Interview Questions with Answers (see here)
  • 15 Java Enum based interview questions with answers (read)
  • 10 Oracle Interview Questions for Java developers (see here)
  • Top 10 JSP Questions  from J2EE Interviews (read here)
  • 12 Good RESTful Web Services Questions from Interviews (read here)
  • Top 10 EJB Interview Questions as well as Answers (see here)
  • Top 10 JMS as well as MQ Series Interview Questions as well as Answers (list)
  • 10 Hibernate Interview Questions for Java EE developers (see here)
  • 21 Final modifier interview questions with reply (read)
  • 10 XML Interview Questions for Java Programmers (read here)
  • Top 10 XSLT Interview Questions with Answers (read more)
  • Top 10 Trick Java Interview Questions as well as Answers (see here)
  • Top xl Core Java Phone Interview Questions with answers (list)

This list of Java interview questions for Java, JEE, as well as J2EE back upwardly engineers should live on plenty to create for whatever Java interview. You tin crevice both fresher as well as sense marker interview past times preparing these Java interview questions, at to the lowest degree source few rounds. If you lot human face upwardly whatever other interesting query which is non inward this list, so delight permit me know via comments as well as I'll add together it.

Further Learning
Java Web Fundamentals By Kevin Jones
Spring Framework 5: Beginner to Guru
JSP, Servlets as well as JDBC for Beginners: Build a Database App