You are on page 1of 9


Array object can be converted to :

• Object **
• Clone*
• Array.Array


An Object Array reference can be converted to:

• An Object reference.

• A Cloneable interface reference.

• A super-class Array reference, including an Object Array reference.

• Any sub-class Array reference with casting, with runtime check

An Object reference can be converted to: (java.lang.Object)

• an Object reference

• a Cloneable interface reference, with casting, with runtime check

• any class reference, with casting, with runtime check

• any array referenece, with casting, with runtime check

• any interface reference, with casting, with runtime check

A Class type reference can be converted to:

• any super-class type reference, (including Object)

• any sub-class type reference, with casting, with runtime check

• an interface reference, if the class implements that interface

• any interface reference, with casting, with runtime check (except if the class is final
and doesn't implement the interface)
An Interface reference can be converted to:

• an Object reference

• a super-interface reference

• any interface/class reference with casting, with runtime check (except if the class is
final and doesn't implement the interface)

A Primitive Array reference can be converted to:

• an Object reference

• a Cloneable interface reference

• a primitive array reference of the same type

2. .war file contains:

• Image, HTML, Sound File **
• GIF *

Explaination :

In addition to Web components, a Web application archive usually contains other files,
including the following:

• Server-side utility classes (database beans, shopping carts, and so on). Often these classes
conform to the JavaBeans component architecture.
• Static Web content (HTML, image, and sound files, and so on).
• Client-side classes (applets and utility classes).

3. How to move the next record in the ResultSet?

• **

Table 2-2: JDBC 2.0 Record Scrolling Functions

Method Function
first( ) Move to the first record.
last( ) Move to the last record.
next( ) Move to the next record.
previous( ) Move to the previous record.
beforeFirst( ) Move to immediately before the first record.
afterLast( ) Move to immediately after the last record.
absolute(int) Move to an absolute row number. Takes a positive or negative argument.
Move backward or forward a specified number of rows. Takes a positive or negative

4. J2EE client tier provide support to which of the following client type :
• Web Browser**
• Stand Alone*
• XML Applicable
• Visual Basic


The types of clients in the Client tier of J2EE application programming module are:
• Web Clients – They access HTML or XML content on the Web Tier using HTTP
• EJB Clients – They access Enterprise Beans in EJB Server in the EJB tier using
RMI over either IIOP or JRMP.
• EIS Clients – They access database, packaged functionality such as ERP or
Scheduling System and legacy Information System. EIS Clients are use JDBC for
database and either Java Connector or VPP for other EIS-tier resources.
• Web Service Peers – They access data and functionality on the web tier.

5. JNDI can be implemented in :

• LDAP **

JNDI can be implemented over Lightweight Directory Access Protocol (LDAP) and is
useful when locating components (eg, EJBs) in a distributed system.
Java Naming and Directory Services (JNDI) provides a way of connecting to
various kinds of services that are indexed in a registry. JNDI is modeled on LDAP
(Lightweight Directory Access Protocol and usually associated with LDAP. But
importantly, JNDI also forms the backbone of other important APIs, including RMI,

Connection Pooling
Connection pooling is a mechanism whereby when an application closes a connection, that connection is
recycled rather than being destroyed. Because establishing a connection is an expensive operation,
reusing connections can improve performance dramatically by cutting down on the number of new
connections that need to be created.

Assuming that an application wants to connect to a data source represented by the DataSource object
whose logical name is EmployeeDB , the code for getting a connection that uses connection pooling looks
like this:

Context ctx = new InitialContext();

DataSource ds = (DataSource)ctx.lookup("jdbc/EmployeeDB");
Connection con = ds.getConnection("myUserName", "myPassword");
Note that the code is identical to that in the previous example except for the logical name, which is
different because the application wants to connect to a different data source. Whether or not the
connection returned by a call to the DataSource.getConnection method will be a pooled connection
depends entirely on how the DataSource class being used has been implemented. If it has been
implemented to work with a middle tier server that supports connection pooling, a DataSource object will
automatically return Connection objects that will be pooled and reused.

Just as there is no change in code to get a pooled connection, there is virtually no difference in the code
for using a pooled connection. The only change is that the connection should be closed in a finally block,
which is not a bad idea for closing any type of connection. That way, even if a method throws an
exception, the connection will be closed and put back into the connection pool. The code for the finally
block, which comes after the appropriate try and catch blocks, should look like this:

} finally {
if (con != null) con.close():
This finally block ensures that a valid connection will be recycled.

6. One of the Messaging type by JMS :

• Point To Point Messaging Model **
• Publish/Subscribe Messaging Model **
• Request/Reply Messaging Model **


Types of messaging
JMS supports two fundamental messaging mechanisms. The first is point-to-point messaging, in which a
message is sent by one publisher (sender) and received by one subscriber (receiver). The second is publish-
subscribe messaging, in which a message is sent by one or more publishers and received by one or more
subscribers. While these two mechanisms are the actual foundation of JMS, many view the technology in
terms of its three messaging models:
• One-to-one messaging is a point-to-point model. A message is sent from one JMS client
(publisher) to a destination on the server known as a queue. Another JMS client (subscriber) can
access the queue and retrieve the message from the server. Multiple messages may reside on the
queue, but each message is removed upon retrieval.

• One-to-many messaging is a publish-subscribe model. A JMS client still publishes a message to a

destination on the server, but the destination is now referred to as a topic. The key difference here
is that messages placed in a topic include a parameter that defines the message durability (how
long it should remain on the server awaiting subscribers). The message will remain on the topic
until all subscribers to the topic have retrieved a copy of the message or until its durability has
expired, whichever comes first.

• Many-to-many messaging, also a publish-subscribe model, extends one-to-many messaging. In

addition to supporting multiple subscribers, this model also supports multiple publishers on the
same topic. A good example of many-to-many messaging would be an e-mail listserve: multiple
publishers can post messages on a topic, and all subscribers will receive each message.

The structure of a JMS message is fairly intuitive. There is a section for routing, addressing, and message
identification; an optional section where application-specific parameters can be passed; and a third section
where the message payload (text, bytes, value map, object, etc.) is stored. These three sections are known
as the header, property, and body, as illustrated in Figure 1.

Figure 1. JMS message structure

The type of messaging model you employ depends upon the needs of your enterprise. It is not uncommon to
employ more than one messaging strategy within a single enterprise. In the sections that follow, we will
explore three JMS solutions for the Java platform: the simple JMS client, session beans combined with JMS,
and message-driven beans. We'll review each type, its pros and cons, and its applicability to different
enterprise scenarios.

7. How selectively serialize instance variables?

How to selectively serialize an instance variable:
• Use Transient **
• Use Volatile
• Use Static


Transient is used when u have any sensitive data. Like credit card number, a/c number, etc.
u can also use static variable if u don’t want to serialize the variable.
8. How to compare empty String :
• S.length ==0 *
• S.equals(“”) **
• S = = “”.trim()
• s = " ".trim().intern();
• s==”” *
* All above are correct answers.


String is an Object type in Java.

You would always use if (users.equals("")) in Java to compare the content.
You would only use (rarely the case) if(users == "") to check whether they referring to same Object instance.
if (users.equals{"regional")) {
out.print ("I am inside code");

I am not sure what kind of Exception you have got. You should post it.
But I would guess it would be NullPointerException.
This exception throws when it found that users is NULL.
You should have
String users = request.getParameter("regional");

9. Suppose DB Server does not support pure JDBC driver but it

does support ODBC driver. How can access the DB Server using
• Java RMI


JDBC drivers basically communicate via TCP/IP to the DBMS server and pass
SQL statements to it and receive results back from it.

JDBC Driver Architecture

The four types of JDBC drivers are as follows:

• Type 1 - ODBC Bridge

Used with databases that are unable to directly support JDBC. ODBC is a Microsoft
Windows interface to SQL. This solution works best on a Windows-based system, but
may not work on other operating systems that do not support ODBC.
• Type 2 - Native API, Native Code
The fastest JDBC driver, written partly in Java and partly in native code, for example,
Microsoft C++ . Although it speaks the native protocol of the SQL database, it is
limited to operating systems on which native code is preinstalled on client machines.
• Type 3 - Net Protocol, Pure Java
Written entirely in Java. This type of driver can run on any platform or browser that
supports Java. The driver converts requests into a database that uses vendor-neutral
protocol. A server process receives the requests and carries out the specified action
on the database. With this type of driver, you can access SQL databases on different
client machines without loading additional JDBC drivers. This JDBC driver is small
and loads quickly.
• Type 4 - Native Protocol, Pure Java
The fastest way to use the Web from a single server. This type of JDBC driver is
written entirely in Java, which means it can be safely loaded into any Java-powered
Web browser. The driver speaks DBMS-vendor-specific protocol directly to the SQL
server. It is efficient, but if you need to attach to various types of SQL databases,
several JDBC drivers must be loaded onto the client machines.

10-15. Programming Type Questions:




import java.text.NumberFormat;

import java.util.Locale;

public class MyClass {

public static void main(String[] args)

//1st Questions...........

StringReader sr = new StringReader("text");

LineNumberReader lnr = new LineNumberReader(sr);

PrintWriter out = new PrintWriter(System.out);

out.println(lnr.readLine()); // Compile Time Error


//Output ---- java.lang.Error: Unresolved compilation problem: Unhandled exception type

//Solution : Use try...catch bolck for IOException or use throws clause as throws

//2nd Questions...........................

Locale loc = new Locale("de","DE");

NumberFormat nf = NumberFormat.getCurrencyInstance(loc);

double dl = 5676.0;


//Output ---- 5.676,00 €

// 3rd Questions..............................

int i,j,n,m;





//--Compile Time Error---method println(int) is not applicable for



//Output ---- 8644

//5th Questions...........

int num1=1;

//float num2=num1/f2; // Compile time error ---- f2 can not be resolved.

float num2=num1/2f;

System.out.println("Output :"+ num2);

//Output : 0.5