Skip to main content

JSP and JDBC Interview Questions & Answers

What is the query used to display all tables names in SQL Server (Query analyzer)?
select * from information_schema.tables


How many types of JDBC Drivers are present and what are they?
- There are 4 types of JDBC Drivers

  • JDBC-ODBC Bridge Driver
  • Native API Partly Java Driver
  • Network protocol Driver
  • JDBC Net pure Java Driver



  • Can we implement an interface in a JSP?
    - No



    What is the difference between ServletContext and PageContext?
    - ServletContext: Gives the information about the container. PageContext: Gives the information about the Request.




    What is the difference in using request.getRequestDispatcher() and context.getRequestDispatcher()?
    - request.getRequestDispatcher(path): In order to create it we need to give the relative path of the resource, context.getRequestDispatcher(path): In order to create it we need to give the absolute path of the resource.



    How to pass information from JSP to included JSP?
    - Using <%jsp:param> tag.



    What is the difference between directive include and jsp include?
    - <%@ include>: Used to include static resources during translation time. JSP include: Used to include dynamic content or static content during runtime.



    What is the difference between RequestDispatcher and sendRedirect?
    - RequestDispatcher: server-side redirect with request and response objects. sendRedirect : Client-side redirect with new request and response objects.



    How does JSP handle runtime exceptions?
    - Using errorPage attribute of page directive and also we need to specify isErrorPage=true if the current page is intended to URL redirecting of a JSP.



    How do you delete a Cookie within a JSP?
     Cookie mycook = new Cookie("name","value");  response.addCookie(mycook);  Cookie killmycook = new Cookie("mycook","value");  killmycook.setMaxAge(0);  killmycook.setPath("/");  killmycook.addCookie(killmycook); 



    How do I mix JSP and SSI #include?
    - If you're just including raw HTML, use the #include directive as usual inside your .jsp file.
     <!--#include file="data.inc"--> 
    But it's a little trickier if you want the server to evaluate any JSP code that's inside the included file. If your data.inc file contains jsp code you will have to use
     <%@ vinclude="data.inc" %> 
    The <!–#include file="data.inc"–> is used for including non-JSP files.



    I made my class Cloneable but I still get Can't access protected method clone. Why?
    - Some of the Java books imply that all you have to do in order to have your class support clone() is implement the Cloneable interface. Not so. Perhaps that was the intent at some point, but that's not the way it works currently. As it stands, you have to implement your own public clone() method, even if it doesn't do anything special and just calls super.clone().



    Why is XML such an important development?
    - It removes two constraints which were holding back Web developments: dependence on a single, inflexible document type (HTML) which was being much abused for tasks it was never designed for; the complexity of full SGML, whose syntax allows many powerful but hard-to-program options. XML allows the flexible development of user-defined document types. It provides a robust, non-proprietary, persistent, and verifiable file format for the storage and transmission of text and data both on and off the Web; and it removes the more complex options of SGML, making it easier to program for.



    What is the fastest type of JDBC driver?
    - JDBC driver performance will depend on a number of issues:
    the quality of the driver code,

    • the size of the driver code,
    • the database server and its load,
    • network topology,
    • the number of times your request is translated to a different API.
    In general, all things being equal, you can assume that the more your request and response change hands, the slower it will be. This means that Type 1 and Type 3 drivers will be slower than Type 2 drivers (the database calls are make at least three translations versus two), and Type 4 drivers are the fastest (only one translation).



    How do I find whether a parameter exists in the request object?
    boolean hasFoo = !(request.getParameter("foo") == null   request.getParameter("foo").equals("")); 
    or
    boolean hasParameter =  request.getParameterMap().contains(theParameter); //(which works in Servlet 2.3+) 



    How can I send user authentication information while makingURLConnection?
    - You'll want to use HttpURLConnection.setRequestProperty and set all the appropriate headers to HTTP authorization.

    Comments

    Popular posts from this blog

    Java Health Center - Overview and Features

    This video highlights the features available in Health Center. Health Center is a low-processor and memory usage diagnostic tool for monitoring the status of a running IBM Java Virtual Machine (JVM). Health Center provides live information and recommendations in each of the following areas: - Classes: information about classes being loaded - Environment: details of the configuration and system of the monitored application - Garbage Collection: information about the Java heap and pause times - Locking: information about contention on inflated locks - Profiling: sampling profile of Java methods including call paths

    WebSphere MQ Interview Questions

    What is MQ and what does it do? Ans. MQ stands for MESSAGE QUEUEING. WebSphere MQ allows application programs to use message queuing to participate in message-driven processing. Application programs can communicate across different platforms by using the appropriate message queuing software products. What is Message driven process? Ans . When messages arrive on a queue, they can automatically start an application using triggering. If necessary, the applications can be stopped when the message (or messages) have been processed. What are advantages of the MQ? Ans. 1. Integration. 2. Asynchrony 3. Assured Delivery 4. Scalability. How does it support the Integration? Ans. Because the MQ is independent of the Operating System you use i.e. it may be Windows, Solaris,AIX.It is independent of the protocol (i.e. TCP/IP, LU6.2, SNA, NetBIOS, UDP).It is not required that both the sender and receiver should be running on the same platform What is Asynchrony? Ans. With messag...

    Java Garbage Collection

    Explain Garbage collection mechanism in Java? Garbage collection is one of the most important features of Java. The purpose of garbage collection is to identify and discard objects that are no longer needed by a program so that their resources can be reclaimed and reused. A Java object is subject to garbage collection when it becomes unreachable to the program in which it is used. Garbage collection is also called automatic memory management as JVM automatically removes the unused variables/objects (value is null) from the memory. Every class inherits finalize() method from java.lang.Object, the finalize() method is called by garbage collector when it determines no more references to the object exists. In Java, it is good idea to explicitly assign null into a variable when no more in use. In Java on calling System.gc() and Runtime.gc(), JVM tries to recycle the unused objects, but there is no guarantee when all the objects will garbage collected. Garbage collection is an automatic pro...