Java Web development interview questions

  1. Can we use the constructor, instead of init(), to initialize servlet? - Yes , of course you can use the constructor instead of init(). There’s nothing to stop you. But you shouldn’t. The original reason for init() was that ancient versions of Java couldn’t dynamically invoke constructors with arguments, so there was no way to give the constructur a ServletConfig. That no longer applies, but servlet containers still will only call your no-arg constructor. So you won’t have access to a ServletConfig or ServletContext.
  2. How can a servlet refresh automatically if some new data has entered the database? - You can use a client-side Refresh or Server Push.
  3. The code in a finally clause will never fail to execute, right? - Using System.exit(1); in try block will not allow finally code to execute.
  4. How many messaging models do JMS provide for and what are they? - JMS provide for two messaging models, publish-and-subscribe and point-to-point queuing.
  5. What information is needed to create a TCP Socket? - The Local System?s IP Address and Port Number. And the Remote System’s IPAddress and Port Number.
  6. What Class.forName will do while loading drivers? - It is used to create an instance of a driver and register it with the DriverManager. When you have loaded a driver, it is available for making a connection with a DBMS.
  7. How to Retrieve Warnings? - SQLWarning objects are a subclass of SQLException that deal with database access warnings. Warnings do not stop the execution of an application, as exceptions do; they simply alert the user that something did not happen as planned. A warning can be reported on a Connection object, a Statement object (including PreparedStatement and CallableStatement objects), or a ResultSet object. Each of these classes has a getWarnings method, which you must invoke in order to see the first warning reported on the calling object
    	SQLWarning warning = stmt.getWarnings();
    	if (warning != null)
    	{
    		while (warning != null)
    		{
    			System.out.println("Message: " + warning.getMessage());
    			System.out.println("SQLState: " + warning.getSQLState());
    			System.out.print("Vendor error code: ");
    			System.out.println(warning.getErrorCode());
    			warning = warning.getNextWarning();
    		}
    	}
    
  8. How many JSP scripting elements are there and what are they? - There are three scripting language elements: declarations, scriptlets, expressions.
  9. In the Servlet 2.4 specification SingleThreadModel has been deprecated, why? - Because it is not practical to have such model. Whether you set isThreadSafe to true or false, you should take care of concurrent client requests to the JSP page by synchronizing access to any shared objects defined at the page level.
  10. What are stored procedures? How is it useful? - A stored procedure is a set of statements/commands which reside in the database. The stored procedure is pre-compiled and saves the database the effort of parsing and compiling sql statements everytime a query is run. Each database has its own stored procedure language, usually a variant of C with a SQL preproceesor. Newer versions of db’s support writing stored procedures in Java and Perl too. Before the advent of 3-tier/n-tier architecture it was pretty common for stored procs to implement the business logic( A lot of systems still do it). The biggest advantage is of course speed. Also certain kind of data manipulations are not achieved in SQL. Stored procs provide a mechanism to do these manipulations. Stored procs are also useful when you want to do Batch updates/exports/houseKeeping kind of stuff on the db. The overhead of a JDBC Connection may be significant in these cases.
  11. How do I include static files within a JSP page? - Static resources should always be included using the JSP include directive. This way, the inclusion is performed just once during the translation phase. Do note that you should always supply a relative URL for the file attribute. Although you can also include static resources using the action, this is not advisable as the inclusion is then performed for each and every request.
  12. Why does JComponent have add() and remove() methods but Component does not? - because JComponent is a subclass of Container, and can contain other components and jcomponents.
  13. How can I implement a thread-safe JSP page? - You can make your JSPs thread-safe by having them implement the SingleThreadModel interface. This is done by adding the directive <%@ page isThreadSafe="false" % > within your JSP page.
This entry was posted in Database, Java, Networking. Bookmark the permalink. Post a comment or leave a trackback: Trackback URL.

16 Comments on Java Web development interview questions

  1. Vinod
    Posted 10/28/2004 at 11:49 pm | Permalink

    Q9 should use word deprecated and not deprecates
    Answer to Q11 talks of showing an example, but example does not exist.
    please do these modifications.

  2. Prasanna
    Posted 10/31/2004 at 11:29 pm | Permalink

    This is realy good work, I will help to freshers,
    “Keep trying no matter how hard it seems, it will get easier”

  3. Ken Hutchinson
    Posted 11/30/2004 at 2:16 am | Permalink

    I’m glad threading with JSP/Servlets is mentioned here, but I’d like to see some specifics. Like why would you manually address threading over letting the container manage this. When should you manipulate threads yourself v. letting the container manager this for you?

    Thanks!

  4. Deepak
    Posted 3/17/2005 at 2:02 am | Permalink

    Well , it is really good to know about this site.It had helped me a lot.
    its really nice site to prepare for interviews.

  5. Chanakyan Chenniah
    Posted 3/20/2005 at 9:39 am | Permalink

    Well I wud appreciate this combined effort..Like i came to know lot of new things after reading the questionnares in this site..I also felt one more good thing on reading all these “Known is a drop and unknown is a ocean”
    Keep the spirit up.All the best

  6. Kalyani
    Posted 3/28/2005 at 5:11 am | Permalink

    Explanation of Q11 is so good.

  7. kalairajan
    Posted 3/31/2005 at 9:09 am | Permalink

    This is realy good !

  8. Posted 4/10/2005 at 9:20 pm | Permalink

    Its real good for person who peparing for interview and witten exam.

  9. Narendhar Reddy
    Posted 4/21/2005 at 2:51 pm | Permalink

    Yep good one, but need to add some more questions to get(test) knowledge one servlets&JSPs

  10. Venkat Reddy
    Posted 4/28/2005 at 10:44 pm | Permalink

    Hi,
    I learned lot of things here and excited to learn more. are you not planning to provide some FAQs on webservices?. Thanks - Venkat

  11. Posted 4/30/2005 at 1:55 am | Permalink

    This is Really a good work and you are helping freshers alot , which
    i can’t express in words. plz keep it up.

  12. rohit
    Posted 5/4/2005 at 10:21 pm | Permalink

    Hai,
    This site is realy too good for any interview question and answer.

    Thanks a lot

  13. Ahamed Thariq
    Posted 5/25/2005 at 2:30 am | Permalink

    Nice collection of Java Questions.But more descriptively needed

  14. b.l.krishna prasad
    Posted 5/26/2005 at 9:43 am | Permalink

    hi this very good who r going to attend for interviews.i got job by seing this site.

  15. Posted 6/3/2005 at 11:29 pm | Permalink

    Its nice to get the questions.
    Q:-How can we use thrads in servlets.

  16. satish jadhao
    Posted 4/16/2006 at 12:15 am | Permalink

    1.can i start same thread multiple times e.g t.start(),t.start().

Post a Comment

Your email is never published nor shared. Required fields are marked *

*
*