Wednesday, 7 November 2012

JAVA interview questions ...

Difference Between get( ) and load( ) 


 Get Load
The get( ) methods always hit the database. A call to load( ), on the other hand, does not immediately incur a call to the database.
as soon as the call to get( ) occurs, Hibernate issues an SQL statement to the database in an attempt to fetch the associated data (usually a row in the database) to rebuild the requested persistent object. The load( ) method causes a proxy object to be constructed as a stand-in for the persistent object.  It is only after some state is requested from the proxy that Hibernate issues the appropriate SQL to the database and builds the real persistent object.
When using get( ), the method will return null if no data exists for the requested identifier. The load( ) method does not immediately retrieve the object, if no data exists for the identifier used to retrieve the object, an ObjectNotFoundException is thrown once data is requested of the proxy.

  Difference between forward and sendRedirect


NO Forward SendRedirect
1 forward runs on the server side SendRedirect runs on the client as well as on the server side thats why the response generated by sendRedirect() is slow as compared to rd.forward()
2 Incase of forward() the request has to be forwarded to the same web application By using sendRedirect() you can forward the request to any web application either in the same server or to the another one
3 One more difference is that forward() method holds the previous request and response objects sendRedirect(),it will create fresh request and response objects



There are 6 interfaces, based on he message payload.

1 Message

2 BytesMessage

3 TextMessage

4 StreamMessage

5 MapMessage

6 ObjectMessage

What is a SessionFactory?

The SessionFactory is the concept that is a single data store and thread safe. Because of this feature, many threads can access this concurrently and the sessions are requested, and also the cache that is immutable of compiled mappings for a specific database. A SessionFactory will be built only at the time of its startup. In order to access it in the application code, it should be wrapped in singleton. This wrapping makes the easy accessibility to it in an application code.

What is JMX?

To make it short, JMX is a technology that lets you implement management interfaces for Java applications.
A management interface, as defined by JMX, is composed of named objects - called MBeans (Management Beans). MBeans are registered with a name (an ObjectName) in an MBeanServer. To manage (a) resource(s) in your application, you will write an MBean that defines its management interface, and then register that MBean in your MBeanServer.