J2EE Interview Questions

Interview Questions Categories
Core Java | J2EE | Database | Struts | XML | HTTP | Web Services

I have prepared this list for those of you seeking to appear in Java / J2EE interview at various companies globally. This post contains a list of core java questions. These are prepared from most frequently asked questions from various software industries. I myself have interviewed over 100 candidates. I have intentionally not provided the solution here. But if you are desperate for one, send me an email via Contact Us link. For other interview questions such as those for J2EE, XML, Database etc and for some sample programming implementations intended to help you to prepare for the interview of tech giants like Google  / Microsoft / Amazon, go to my page here.

The questions below are alphabetically sorted.

  1. Are JavaBeans J2EE components?
  2. How do we package J2EE components?
  3. How is the MVC design pattern used in Struts framework?
  4. How to access web.xml parameters from jsp pages?
  5. Is HTML page a web component?
  6. Is J2EE application only a web-based?
  7. Is Servlet a pure java object?
  8. What are container services?
  9. What are JSP Directives?
  10. What are JSP Tags?
  11. What are servlets?
  12. What are the advantages of hibernate?
  13. What are the benefits of ORM?
  14. What are the four components of J2EE applications?
  15. What are the limitations of hibernate?
  16. What are types of J2EE clients?
  17. What can be considered as a web component?
  18. What do Enterprise JavaBeans components contain?
  19. What is a thin client?
  20. What is Applet container?
  21. What is deployment descriptor?
  22. What is Enterprise JavaBeans (EJB) container?
  23. What is Hibernate
  24. What is J2EE Connector?
  25. What is J2EE?
  26. What is JAAP?
  27. What is Java Naming and Directory Service?
  28. What is JAXP?
  29. What is JDNI?
  30. What is JSF?
  31. What is JTA and JTS?
  32. What is ORM?
  33. What is Struts?
  34. What is the container?
  35. What is the difference between war, jar and ear files?
  36. What is the EAR file?
  37. What is the web container?
  38. What is web.xml?
  39. What makes J2EE suitable for distributed multitiered Applications?
  40. What are types of J2EE Clients?

The Servlet Basic Structure

/**
 * @author Kushal Paudyal
 * www.sanjaal.com/java
 * Created on 19th July 2008
 */
package com.kushal.servlets;
/*
 * This is a basic servlet class that shows how
 * servlet can be structured.
 */
import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;

public class MyFirstServlet extends HttpServlet {

/**
 * This is GET method. Request has parameters, 
 * and we write back using response.
 */	
public void doGet(HttpServletRequest request,
                    HttpServletResponse response)
      throws ServletException, IOException {
      
    PrintWriter out = response.getWriter();
    
    out.write("Hello, this is my first servlet");    
  }

/**
 * This is another kind of request with POST
 * kind of submission. We can simply reroute
 * the request to doGetmethod as below.
 */
public void doPost(HttpServletRequest request,
                    HttpServletResponse response)
      throws ServletException, IOException {
	  doGet(request, response);	  
  }
}

/**
 * In order to be able to run this servlet, you have
 * to setup a proper application server and deploy
 * the servlet. Discussing those steps is out of
 * scope in this post.
 */

How to print HttpServletRequest’s All Available Request Parameters and Request Attributes

If you ever debugged your J2EE application, you know the pain of finding out where you request parameters are on the HttpServletRequest object. I always get lost when I am inspecting the request object because it holds so much onto it. This example here shows you how to print all available request parameters and request attributes so you can easily look at what values those attribtues and parameters are holding.

If you run this servlet, you should be able to print these parameters and attributes on to you browser itself.

package com.kushal.tools;
/**
 * @author Kushal Paudyal
 * www.sanjaal.com/java
 * www.icodejava.com
 * 
 */
import java.io.IOException;
import java.io.PrintWriter;
import java.util.Enumeration;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.ibm.ws.http.HttpConnection;
import com.ibm.ws.http.HttpRequest;

public class HttpRequestParamsAndAttributesPrintServlet extends HttpRequest{

    public HttpRequestParamsAndAttributesPrintServlet(HttpConnection connection) {

        super(connection);

    }

    public void doGet(HttpServletRequest req, HttpServletResponse res) 
        throws ServletException, IOException {

        res.setContentType("text/html");
        PrintWriter out = res.getWriter();

        printRequestAttributes(req, out);

        printRequestParameters(req, out);

    }
    
    public void doPost(HttpServletRequest req, HttpServletResponse res) 
        throws ServletException, IOException {
        
        doGet(req, res);
    }

    /**
     * This method prints all the request parameters that are 
     * available on the HttpServletRequest.
     * 
     * The result will be printed back to the browser
     *
     */
    private void printRequestParameters(HttpServletRequest req, PrintWriter out) {

        out.println("Printing All Request Parameters From HttpSerlvetRequest:");

        Enumeration<String> requestParameters = req.getParameterNames();
        while (requestParameters.hasMoreElements()) {
            String paramName = (String) requestParameters.nextElement();
            out.println("Request Paramter Name: " + paramName 
                            + ", Value - " + req.getParameter(paramName));
        }
    }

    /**
     * This method prints all the request attributes that are 
     * available on the HttpServletRequest.
     * 
     * The result will be printed back to the browser.
     *
     */
    private void printRequestAttributes(HttpServletRequest req, PrintWriter out) {

        out.println("Printing All Request Parameters From HttpSerlvetRequest:");

        Enumeration<String> requestAttributes = req.getAttributeNames();
        while (requestAttributes.hasMoreElements()) {
            String attributeName = (String) requestAttributes.nextElement();
            out.println("Request Attribute Name: " + attributeName 
                            + ", Value - " + (req.getAttribute(attributeName)).toString());
        }
    }
}