Tech 'n' Tech Books

J2EE Technical/Programming Interview Questions

EJB - Frequently Asked Questions

1.) What Is a Session Bean?

A session bean represents a single client inside the J2EE server. To access an application that is deployed on the server, the client invokes the session bean’s methods. The session bean performs work for its client, shielding the client from complexity by executing business tasks inside the server. As its name suggests, a session bean is similar to an interactive session. A session bean is not shared–it may have just one client, in the same way that an interactive session may have just one user. Like an interactive session, a session bean is not persistent. When the client terminates, its session bean appears to terminate and is no longer associated with the client.

2.) What is Stateful Session Beans?

Stateful session beans maintain state information that reflects the interaction between the bean and a particular client across methods and transactions.So, all field variables in the bean instance retain their values as long as the client application retains the bean stub.

3.) Explain EJB?

An EJB is essentially a software component on which method calls can be made, and which can itself make calls on other components. These calls may be made over a network. In this sense, EJB technology is similar to Java RMI and CORBA. However, there are some defining features of EJBs that make EJB development rather different from (and easier than) other techniques for developing distributed applications. In Version 2.0 of the EJB Specification, EJBs are allowed to interact using local calling semantics, as well as distributed, RMI-like techniques.

Hibernate - Frequently Asked Questions

1.) What is the difference between sorted and orderd collection in hibernate?

A sorted collection is sorted in-memory using java comparator, while order collection is ordered at the database level using order by clause.

2.) What is HQL?

Hibernate Query Language

3.) What are the elements in the mapping file?

The Elements are listed below:

1. Class Element

2. Id Element

3. Generator Element

4. Property Element

4.) What are all the components in Hibernate Architeture?

Hibernate architecture has three main components

a.Connection Management

b.Transcation Management

c.Object Relational Mapping

5.) What is the advantage of Hibernate over jdbc?

Hibernate is used to persist the objects in the database, but we have to use the jdbc to connect to database. JDBC is used to store the primitivies in the database

J2EE - Frequently Asked Questions

1.) Difference between forward and send Redirect?

In the case of forward when you invoke a forward request, the request of the user is sent to another resource on the server within the web container, without the client being informed about the process that a different resource is going to process the request. But when a sendRedirtect method is invoked, it causes the web container to return to the browser indicating that a new URL should be requested. For this extra round trip process a redirect is slower than the forward.

2.) What is the difference between ServletContext and ServletConfig?

ServletContext: Defines a set of methods that a servlet uses to communicate with its servlet container, for example, to get the MIME type of a file, dispatch requests, or write to a log file. The ServletContext object is contained within the ServletConfig object, which the Web server provides the servlet when the servlet is initialized

ServletConfig: The object created after a servlet is instantiated and its default constructor is read. It is created to pass initialization information to the servlet

3.) What’s the difference between Thread and Runnable?

A Java Thread controls the main path of execution in an application. When you invoke the Java Virtual Machine with the java command, it creates an implicit thread in which to execute the main method. The Thread class provides a mechanism for the first thread to start-up other threads to run in parallel with it.

The Runnable interface defines a type of class that can be run by a thread. The only method it requires is run, which makes the interface very easy to fulfil by extending existing classes. A Runnable class may have custom constructors and any number of other methods for configuration and manipulation.

4.) What’s the difference between notify () and notifyAll ()?

The notify () is used to unblock one waiting thread; notifyAll () is used to unblock all of them. Using notify () is preferable when only one blocked thread can benefit from the change.notifyAll() is necessary to multiple threads should resume .

5.) The Native API driver:

A) Translates JDBC calls into a database-independent network protocol that is sent to a middleware server.

B) Provides JDBC access to databases through ODBC drivers.

C) Converts JDBC commands into DBMS-specific native calls.

D) Communicates directly with the vendor’s database.

Ans: C)

6.) Which of the following can be the primary key in the entity bean?

A) The primary key can be a java primitive type.

B) The primary key can be Primitive wrapper classes.

C) None of the above.

D) Both.

Ans: B)

7.) What are transaction isolation levels in EJB?

A) Transaction_read_uncommitted
B) Transaction_read_committed
C) Transaction_repeatable_read.
D) Both A and B.
E) All the three.
Ans: E

8.) What are the contents of web module?

A web module contain:

a) JSP files

b) Java classes

c) gif and html files and

d) web component deployment descriptors

9.) What are the various types of Beans ?

The various types of beans are

1.Session Bean

2.Entity Bean

3.Message Driven Bean

10.) What are the services provided by a container?

The Various services provided by container are as follows:

a) Transaction management for the bean

b) Security for the bean

c) Persistence of the bean

d) Remote access to the bean

e) Lifecycle management of the bean

f) Database-connection pooling

g) Instance pooling for the bean

Java - Frequently Asked Questions

1.) Difference between Enumeration and Iteration?

Both will help you to travel into collection bag, but Enumeration is a legacy classes, Iterator have introduced in Collection framework. In enumeration we can modify the collection objects but throw Iterator it is possible. Enumeration can be used for Collection objects as well as Iterator can be used for legacy classes. Enumeration acts as Read-only interface, where as using Iterator we can manipulate the objects also like adding and removing the objects. So Enumeration is used whenever we want to make Collection objects as Read-only.

2.) What’s the difference between Transient and Volatile?

Transient: The transient modifier applies to variables only and it is not stored as part of its object’s Persistent state. These variables are not serialized. Transient instance fields are neither saved nor restored by the standard serialization. You have to handle restoring them yourself.

Volatile: Volatile modifier tells the compiler that the variable modified by volatile can be changed unexpectedly by other parts of the program. For example a Variable might be read from Cache and not update the content if it has been changed by another thread. Specifying a variable as volatile tells the JVM that any threads using that variable are not allowed to cache that value at all. Making the Variable Volatile will ensure that the compiler will get the content of the variable every time it is used and not cache its content. If not used Carefully this modifier might introduce bugs.

3.) Is JVM platform dependent?

Although java is platform independent but still JVM IS platform dependent one of the feature called byte code makes JVM platform dependent. Byte code is an intermediate machine code of compiled source code. The byte code can run on all machines, however the JVM must be installed in each machine.

4.) What are wrapper classes? Why do we need wrapper classes?

Java provides specialized classes corresponding to each of the primitive data types. These are called wrapper classes. They are Boolean, Byte, Character, Double, Float, Integer, Long, and Short.

We can create instances of these classes hence we can store them in any of the collection classes and pass them around as a collection. Also we can pass them around as method parameters where a method expects an object.

5.) What are Checked and Unchecked Exception?

A checked exception is generally known as Compiletime Exception. Checked exception forces client programmers to deal with the possibility that the exception will be thrown hence the programmer has to handle these types of exceptions. e.g., IOException thrown by’s read( ) method.

Where as Unchecked exceptions are Runtime Exception. With an unchecked exception, however, the compiler doesn’t force client programmers either to catch the exception or declare it in a throws clause. In fact, client programmers may not even know that the exception could be thrown. e.g., StringIndexOutOfBounds Exception thrown by String’s charAt () method· Checked exceptions must be caught at compile time but Runtime exceptions do not need to be.

6.) What is deadlock and how it can be avoid?

Deadlock is a situation when two threads are waiting on each other to release a resource. Each thread waiting for a resource, which is held by the other waiting thread. In Java, this resource is usually the object lock obtained by the synchronized keyword.

7.) What is the difference between interface and abstract class?

Difference between interface and abstract:
All the methods declared inside interface should be abstract, and there is no need to use the key word “abstract” for those method, but in case of abstract class at least one method should be abstract, most importantly u have to use the “abstract” key word for that method, besides that it may contain concrete methods. Abstract class must be extended abstract () methods generally contain only declaration part without definition part.

8.) Why are there no global variables in Java?

Global variables are considered bad form for a variety of reasons:

9.) What are the steps in the JDBC connection?

For making a JDBC connection we need to go through the following steps:

Step 1: Register the database driver by using:
Class.forName (\” driver class for that specific database\”);

Step 2 : Create a database connection using:
Connection con = DriverManager.getConnection (url, username, password);

Step 3: Create a query using:
Statement stmt = Connection.Statement (\”select * from TABLE NAME\”);

Step 4: Exceute the query:
Stmt.exceuteUpdate ();

10.) What is an enumeration?

An enumeration is an interface which containing methods for accessing the underlying data structure. It is a construct which collection classes return when you request a collection of all the objects stored in the collection. It allows sequential access to all the elements stored in the collection.

11.) How Application is differ from Applet?



12.) What is CDC?

The Connected Device Configuration (CDC) is a specification for a J2ME configuration. Conceptually, CDC deals with devices with more memory and processing power than CLDC; it is for devices with an always-on network connection and a minimum of 2 MB of memory available for the Java system.

13.) What is the MIDP?

The MIDP defines a set of APIs for mobile devices, such as cell phones and low-end PDAs

14.) What is variable typing in javascript?

It is perfectly legal to assign a number to a variable and then assign a string to the same variable as follows

Example: i = 10;

i = “string”;

15.) What does a well-written java program look like?

A well-written java program exhibits recurring structures that promote abstraction, flexibility, modularity and elegance.

JMS - Frequently Asked Questions

1.) Which of the following are Roles of a JMS Provider?

A) Handles security of messages.

B) Data Conversion.

C) Client Triggering.

D) All the above.

E) None of the above.

Ans: D)

2.) What are the three components of a Message ?

A JMS message has three components
1.A header
3.A body

3.) What are the different types of messages available in the JMS API?

The types of messages are

Message, TextMessage, BytesMessage, StreamMessage, ObjectMessage, MapMessage are the different messages available in the JMS API

4.) What is JMS?

JMS is an acronym used for Java Messaging Service. It is used to creating software using asynchronous messaging.

JSP - Frequently Asked Questions

1.) What is wrong with using JSP scriptlet tags ?

Java code embedded within scriptlet tags is ugly and obtrusive.
A non-Java developer cannot modify the embedded Java code, nullifying a major benefit of JSP: empowerment of designers and business people to update page content.
Other JSP pages cannot reuse Java code within JSP scriptlet, so common logic snippets end up being re-implemented in multiple pages.
Retrieving objects out of the HTTP request and session is cumbersome. Casting to the object’s class is required. This then requires that the object’s class be known to the JSP by importing or fully qualifying the class name.

2.) Which one is thread safe?

A) Arraylist

B) Vector

C) Map

D) Table

Ans: B) Vector.

3.) The set Secure (Boolean) method of the Cookie class is used to:

A) Encrypt a cookie so that the user can not read the stored cookies.

B) Specify whether the cookie is sent over a secure protocol such as SSL.

C) Specify whether the cookie is not violating any security rules.

D) Gather security related information about a user.

Ans: B)

4.) Which element enables JSP to integrate with JavaBeans?

A) Scriptlets.

B) Directives.

C) Declarations.

D) Actions.

Ans: D)

5.) Can a interface be implemented in a jsp file?

A) Yes.

B) No.

C) Only when static pages are included.

D) Only when dynamic pages are included.

Ans: B)

6.) What is a Scriplet?

Scriptlet can contain any number of language statements, variable or method declarations, or expressions that are valid in the page scripting language.

7.) What is the purpose of Jsp forward method?

This method will forward the control to another resource available in the same web application on the same container.

8.)What are the implicit objects used in JSP?

The various implicit objects are









Struts - Frequently Asked Questions

1.) How you will handle exceptions in Struts?

In Struts you can handle the exceptions in two ways:

a) Declarative Exception Handling: You can either define global exception handling tags in your struts-config.xml or define the exception handling tags within .. tag.





b) Programmatic Exception Handling: Here you can use try{}catch{} block to handle the exception.

2.) What are the core classes of the Struts Framework?

Core classes of Struts Framework are ActionForm, Action, ActionMapping, ActionForward, ActionServlet etc.

3.) What are the components of Struts?

Struts is based on the MVC design pattern. Struts components can be categories into Model, View and Controller.
  • Model: Components like business logic / business processes and data are the part of Model.
  • View: JSP, HTML etc. are part of View
  • Controller: Action Servlet of Struts is part of Controller components which works as front controller to handle all the requests.

4.) How Struts relates to J2EE?

Struts framework is built on J2EE technologies (JSP, Servlet, Taglibs), but it is itself not part of the J2EE standard.

5.) What are the various Struts tag libraries?

Struts is very rich framework and it provides very good and user friendly way to develop web application forms. Struts provide many tag libraries to ease the development of web applications. These tag libraries are:

6.) Is struts threadsafe?

Struts is not only thread-safe but thread-dependant.

7.) How to communicate from struts to ejb?

In Struts architecture Action class contain execute() method, within execute() method it access database through jdbc or EJB. Then can call the reference of entity bean class by jndi call and easily fetch data from database.

8.) Give the Details of XML files used in Validator Framework?

The Validator Framework uses two XML configuration files validator-rules.xml and validation.xml. The validator-rules.xml defines the standard validation routines, these are reusable and used in validation.xml. to define the form specific validations. The validation.xml defines the validations applied to a form bean.

9.) What is ActionForm?

An ActionForm is a JavaBean that extends org.apache.struts.action.ActionForm. ActionForm maintains the session state for web application and the ActionForm object is automatically populated on the server side with data entered from a form on the client side.

10.) What is ActionServlet?

The class org.apache.struts.action.ActionServlet is the called the ActionServlet. In the the Jakarta Struts Framework this class plays the role of controller. All the requests to the server goes through the controller. Controller is responsible for handling all the requests.

11.) What is Jakarta Struts Framework?

Jakarta Struts is open source implementation of MVC (Model-View-Controller) pattern for the development of web based applications. Jakarta Struts is robust architecture and can be used for the development of application of any size. Struts framework makes it much easier to design scalable, reliable Web applications with Java.