Tuesday, July 31, 2007

RMI, JDBC, XML Interview questions with answers

RMI, JDBC, XML INTERVIW QUESTIONS WITH ANSEWRS

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

Question: How many types of JDBC Drivers are present and what are they?
Answer: There are 4 types of JDBC Drivers
Type 1: JDBC-ODBC Bridge Driver
Type 2: Native API Partly Java Driver
Type 3: Network protocol Driver
Type 4: JDBC Net pure Java Driver

Question: What is the fastest type of JDBC driver?
Answer: JDBC driver performance will depend on a number of issues:
(a) the quality of the driver code,
(b) the size of the driver code,
(c) the database server and its load,
(d) network topology,
(e) 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).

Question: Is the JDBC-ODBC Bridge multi-threaded?
Answer: No. The JDBC-ODBC Bridge does not support concurrent access from different threads. The JDBC-ODBC Bridge uses synchronized methods to serialize all of the calls that it makes to ODBC. Multi-threaded Java programs may use the Bridge, but they won't get the advantages of multi-threading.

Question: Does the JDBC-ODBC Bridge support multiple concurrent open statements per connection?
Answer: No. You can open only one Statement object per connection when you are using the JDBC-ODBC Bridge.

Question: What is cold backup, hot backup, warm backup recovery?
Answer: a. cold backup - All these files must be backed up at the same time, before the databaseis restarted.
b. hot backup - official name is 'online backup' ? is a backup taken of each tablespace while the database is running and is being accessed by the users.

Question: When we will Denormalize data?
Answer: Data denormalization is reverse procedure, carried out purely for reasons of improving performance.It maybe efficient for a high-throughput system to replicate data for certain data.

Question: What is the advantage of using PreparedStatement?
Answer: If we are using PreparedStatement the execution time will be less.The PreparedStatement object contains not just an SQL statement,but the SQL statement that has been precompiled.This means that when the PreparedStatement is executed,the RDBMS can just run the PreparedStatement's Sql statement without having to compile it first.

Question: What is a "dirty read"?
Answer: Quite often in database processing, we come across the situation wherein one transaction can change a value, and a second transaction can read this value before the original change has been committed or rolled back. This is known as a dirty read scenario because there is always the possibility that the first transaction may rollback the change, resulting in the second transaction having read an invalid value. While you can easily command a database to disallow dirty reads, this usually degrades the performance of your application due to the increased locking overhead. Disallowing dirty reads also leads to decreased system concurrency.

Question: What is Metadata and why should I use it?

Answer: Metadata ('data about data') is information about one of two things: Database information (java.sql.DatabaseMetaData), or Information about a specific ResultSet (java.sql.ResultSetMetaData).
Use DatabaseMetaData to find information about your database, such as its capabilities and structure. Use ResultSetMetaData to find information about the results of an SQL query, such as size and types of columns

Question: Different types of Transaction Isolation Levels?
Answer: The isolation level describes the degree to which the data being updated is visible to other transactions. This is important when two transactions are trying to read the same row of a table. Imagine two transactions A & B.
Three types of inconsistencies can occur:
· Dirty-read: A has changed a row, but has not committed the changes. B reads the uncommitted data but his view of the data may be wrong if A rolls back his changes and updates his own changes to the database.
· Non-repeatable read: B performs a read, but A modifies or deletes that data later. If B reads the same row again, he will get different data.
· Phantoms: A does a query on a set of rows to perform an operation. B modifies the table such that a query of A would have given a different result. The table may be inconsistent.
TRANSACTION_READ_UNCOMMITTED : DIRTY READS, NON-REPEATABLE READ AND PHANTOMS CAN OCCUR.
TRANSACTION_READ_COMMITTED : DIRTY READS ARE PREVENTED, NON-REPEATABLE READ AND PHANTOMS CAN OCCUR.
TRANSACTION_REPEATABLE_READ : DIRTY READS , NON-REPEATABLE READ ARE PREVENTED AND PHANTOMS CAN OCCUR.
TRANSACTION_SERIALIZABLE : DIRTY READS, NON-REPEATABLE READ AND PHANTOMS ARE PREVENTED.

Question: What is 2 phase commit?
Answer: A 2-phase commit is an algorithm used to ensure the integrity of a committing transactionIn Phase 1, the transaction coordinator contacts potential participants in the transaction. The participants all agree to make the results of the transaction permanent but do not do so immediately. The participants log information to disk to ensure they can complete Phase 2. If all the participants agree to commit, the coordinator logs that agreement and the outcome is decided. The recording of this agreement in the log ends Phase
In Phase 2, the coordinator informs each participant of the decision, and they permanently update their resources.

Question: How do you handle your own transaction ?
Answer: Connection Object has a method called setAutocommit ( Boolean istrue)
- Default is true
Set the Parameter to false , and begin your transaction

Question: What is the normal procedure followed by a java client to access the db.?
Answer: The database connection is created in 3 steps:
1.Find a proper database URL (see FAQ on JDBC URL)
2.Load the database driver
3.Ask the Java DriverManager class to open a connection to your database
In java code, the steps are realized in code as follows:
1.Create a properly formatted JDBR URL for your database. (See FAQ on JDBC URL for more information). A JDBC URL has the form
jdbc:someSubProtocol://myDatabaseServer/theDatabaseName 2. Class.forName("my.database.driver");
3 . Connection conn = DriverManager.getConnection("a.JDBC.URL", "databaseLogin","databasePassword");

Question: What is a data source?
Answer: A DataSource class brings another level of abstraction than directly using a connection object. Data source can be referenced by JNDI. Data Source may point to RDBMS, file System , any DBMS etc.

Question: What are collection pools? What are the advantages?
Answer: A connection pool is a cache of database connections that is maintained in memory, so that the connections may be reused

Question: How to call a Stored Procedure from JDBC?
Answer: The first step is to create a CallableStatement object. As with Statement an and PreparedStatement objects, this is done with an open Connection object. A CallableStatement object contains a call to a stored procedure.
E.g.
CallableStatement cs = con.prepareCall("{call SHOW_SUPPLIERS}");
ResultSet rs = cs.executeQuery();

Question: Why is XML such an important development?

Answer: It removes two constraints which were holding back Web developments:
1. § dependence on a single, inflexible document type (HTML) which was being much abused for tasks it was never designed for;
2. 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.

Question: What is the difference between URL instance and URLConnection instance? (Networking)
Answer: A URL instance represents the location of a resource, and a URLConnection instance represents a link for accessing or communicating with the resource at the location.

Question: What are the two important TCP Socket classes? (Networking)
Answer: Socket and ServerSocket. ServerSocket is used for normal two-way socket communication. Socket class allows us to read and write through the sockets. getInputStream() and getOutputStream() are the two methods available in Socket class.

Question: Can RMI and Corba based applications interact ?
Answer: Yes they can. RMI is available with IIOP as the transport protocol instead of JRMP.

Question: How many types of protocol implementations does RMI have?
Answer: RMI has at least three protocol implementations: Java Remote Method Protocol(JRMP), Internet Inter ORB Protocol(IIOP), and Jini Extensible Remote Invocation(JERI). These are alternatives, not part of the same thing, All three are indeed layer 6 protocols for those who are still speaking OSI reference model.

Question: Does RMI-IIOP support dynamic downloading of classes?
Answer: No, RMI-IIOP doesn't support dynamic downloading of the classes as it is done with CORBA in DII (Dynamic Interface Invocation).Actually RMI-IIOP combines the usability of Java Remote Method Invocation with the interoperability of the Internet Inter-ORB Protocol (IIOP).So in order to attain this interoperability between RMI and CORBA,some of the features that are supported by RMI but not CORBA and vice versa are eliminated from the RMI-IIOP specification.

JAVA JNDI JMS Interview questions

JNDI, JMS INTERVIEW QUESTIONS

Question: What is messaging?
Answer: Messaging is a mechanism by which data can be passed from one application to another application.
Question: What is point-to-point messaging?
Answer: With point-to-point message passing t

Question: What is point-to-point messaging?
Answer: With point-to-point message passing the sending application/client establishes a named message queue in the JMS broker/server and sends messages to this queue. The receiving client registers with the broker to receive messages posted to this queue. There is a one-to-one relationship between the sending and receiving clients.

Question: Can two different JMS services talk to each other? For instance, if A and B are two different JMS providers, can Provider A send messages directly to Provider B? If not, then can a subscriber to Provider A act as a publisher to Provider B?

Answer: The answers are no to the first question and yes to the second. The JMS specification does not require that one JMS provider be able to send messages directly to another provider. However, the specification does require that a JMS client must be able to accept a message created by a different JMS provider, so a message received by a subscriber to Provider A can then be published to Provider B. One caveat is that the publisher to Provider B is not required to handle a JMSReplyTo header that refers to a destination that is specific to Provider A.

Question: What is the advantage of persistent message delivery compared to nonpersistent delivery?
Answer: If the JMS server experiences a failure, for example, a power outage, any message that it is holding in primary storage potentially could be lost. With persistent storage, the JMS server logs every message to secondary storage. (The logging occurs on the front end, that is, as part of handling the send operation from the message producing client.) The logged message is removed from secondary storage only after it has been successfully delivered to all consuming clients

Question: How is a java object message delivered to a non-java Client?

Answer: It is according to the specification that the message sent should be received in the same format. A non-java client cannot receive a message in the form of java object. The provider in between handles the conversion of the data type and the message is transferred to the other end.


Question: What is MDB and What is the special feature of that?

Answer: MDB is Message driven bean, which very much resembles the Stateless session bean. The incoming and out going messages can be handled by the Message driven bean. The ability to communicate asynchronously is the special feature about the Message driven bean.

Question: Give an example of using the publish/subscribe model.

Answer: JMS can be used to broadcast shutdown messages to clients connected to the Weblogic server on a module wise basis. If an application has six modules, each module behaves like a subscriber to a named topic on the server.

Question: What is the difference between the Mailing and Messaging?

Answer: Java Mailing is the set of APIs that primarily concerns with the sending of Mail messages through the standard mail protocols. Messaging is the way of communicating to the remote machines using Message Oriented Middlewares. Message Oriented Middlewares do not use mailing internally for communication. They create their own channels for communication.

Java Design Pattern Questions with answers

JAVA DESIGN PATTERN QUESTIONS WITH ANSWERS

Question: Describe the visitor design pattern
Answer: Represents an operation to be performed on the elements of an object
structure. Visitor lets you define a new operation without changing the classes of the elements on which it operates. The root of a class hierarchy defines an abstract method to accept a visitor. Subclasses implement this method with visitor.visit(this). The Visitor interface has visit methods for all subclasses of the baseclass in the hierarchy.

Question: What is a design pattern?
Answer: A design pattern systematically names, motivates, and explains a general design that addresses a recurring design problem.

Question: Describe the visitor design pattern
Answer: Represents an operation to be performed on the elements of an object structure. Visitor lets you define a new operation without changing the classes of the elements on which it operates.
The root of a class hierarchy defines an abstract method to accept a visitor. Subclasses implement this method with visitor.visit(this). The Visitor interface has visit methods for all subclasses of the baseclass in the hierarchy.

Java Utils Questions with answers

JAVA UTILS QUESTIONS WITH ANSWERS

Question: What is the Collections API?
Answer: The Collections API is a set of classes and interfaces that support operations on collections of objects

Question: What is the List interface?
Answer: The List interface provides support for ordered collections of objects.

Question: What is the Vector class?
Answer: The Vector class provides the capability to implement a growable array of objects

Question: What is an Iterator interface?
Answer: The Iterator interface is used to step through the elements of a Collection

Question: Which java.util classes and interfaces support event handling?
Answer: The EventObject class and the EventListener interface support event processing

Question: What is the GregorianCalendar class?
Answer: The GregorianCalendar provides support for traditional Western calendars

Question: What is the Locale class?
Answer: The Locale class is used to tailor program output to the conventions of a particular geographic, political, or cultural region

Question: What is the SimpleTimeZone class?
Answer: The SimpleTimeZone class provides support for a Gregorian calendar

Question: What is the Map interface?
Answer: The Map interface replaces the JDK 1.1 Dictionary class and is used associate keys with values

Question: What is the highest-level event class of the event-delegation model?
Answer: The java.util.EventObject class is the highest-level class in the event-delegation class hierarchy

Question: What is the Collection interface?
Answer: The Collection interface provides support for the implementation of a mathematical bag - an unordered collection of objects that may contain duplicates

Question: What is the Set interface?
Answer: The Set interface provides methods for accessing the elements of a finite mathematical set. Sets do not allow duplicate elements

Question: What is the purpose of the enableEvents() method?
Answer: The enableEvents() method is used to enable an event for a particular object. Normally, an event is enabled when a listener is added to an object for a particular event. The enableEvents() method is used by objects that handle events by overriding their event-dispatch methods.

Question: What is the ResourceBundle class?
Answer: The ResourceBundle class is used to store locale-specific resources that can be loaded by a program to tailor the program's appearance to the particular locale in which it is being run.

Java Threads Interview questions with answers

JAVA THREADS QUESTIONS WITH ANSWERS


Question: What is the difference between yielding and sleeping?
Answer: When a task invokes its yield() method, it returns to the ready state. When a task invokes its sleep() method, it returns to the waiting state.

Question: When a thread blocks on I/O, what state does it enter?
Answer: A thread enters the waiting state when it blocks on I/O.

Question: When a thread is created and started, what is its initial state?
Answer: A thread is in the ready state after it has been created and started.
Question: What invokes a thread's run() method?


Answer: After a thread is started, via its start() method or that of the Thread class, the JVM invokes the thread's run() method when the thread is initially executed.

Question: What method is invoked to cause an object to begin executing as a separate thread?
Answer: The start() method of the Thread class is invoked to cause an object to begin executing as a separate thread.

Question: What is the purpose of the wait(), notify(), and notifyAll() methods?
Answer: The wait(),notify(), and notifyAll() methods are used to provide an efficient way for threads to wait for a shared resource. When a thread executes an object's wait() method, it enters the waiting state. It only enters the ready state after another thread invokes the object's notify() or notifyAll() methods.

Question: What are the high-level thread states?
Answer: The high-level thread states are ready, running, waiting, and dead

Question: What happens when a thread cannot acquire a lock on an object?
Answer: If a thread attempts to execute a synchronized method or synchronized statement and is unable to acquire an object's lock, it enters the waiting state until the lock becomes available.

Question: How does multithreading take place on a computer with a single CPU?
Answer: The operating system's task scheduler allocates execution time to multiple tasks. By quickly switching between executing tasks, it creates the impression that tasks execute sequentially.

Question: What happens when you invoke a thread's interrupt method while it is sleeping or waiting?
Answer: When a task's interrupt() method is executed, the task enters the ready state. The next time the task enters the running state, an InterruptedException is thrown.

Question: What state is a thread in when it is executing?
Answer: An executing thread is in the running state

Question: What are three ways in which a thread can enter the waiting state?
Answer: A thread can enter the waiting state by invoking its sleep() method, by blocking on I/O, by unsuccessfully attempting to acquire an object's lock, or by invoking an object's wait() method. It can also enter the waiting state by invoking its (deprecated) suspend() method.

Question: What method must be implemented by all threads?
Answer: All tasks must implement the run() method, whether they are a subclass of Thread or implement the Runnable interface.

Question: What are the two basic ways in which classes that can be run as threads may be defined?
Answer: A thread class may be declared as a subclass of Thread, or it may implement the Runnable interface.