Explore topic-wise InterviewSolutions in Current Affairs.

This section includes 7 InterviewSolutions, each offering curated multiple-choice questions to sharpen your Current Affairs knowledge and support exam preparation. Choose a topic below to get started.

1.

Which Classes And Interfaces Does Applet Class Consists?

Answer»

Applet CLASS consists of a SINGLE class, the Applet class and three INTERFACES: AppletContext, AppletStub, and AudioClip.

Applet class consists of a single class, the Applet class and three interfaces: AppletContext, AppletStub, and AudioClip.

2.

Can Applets On Different Pages Communicate With Each Other?

Answer»

Use the getSize() method, which the Applet class inherits from the COMPONENT class in the Java.awt package. The getSize() method returns the size of the applet as a DIMENSION object, from which you EXTRACT separate width, height fields. The following code SNIPPET explains this:
Dimension dim = getSize();
INT appletwidth = dim.width();
int appletheight = dim.height();

Use the getSize() method, which the Applet class inherits from the Component class in the Java.awt package. The getSize() method returns the size of the applet as a Dimension object, from which you extract separate width, height fields. The following code snippet explains this:
Dimension dim = getSize();
int appletwidth = dim.width();
int appletheight = dim.height();

3.

How Do I Select A Url From My Applet And Send The Browser To That Page?

Answer»

Ask the applet for its applet context and invoke showDocument() on that context object.

URL targetURL;
STRING URLString
AppletContext context = getAppletContext();
TRY
{
targetURL = NEW URL(URLString);
}
catch (MalformedURLException e)
{
// Code for recover from the exception
}
context. showDocument (targetURL);

Ask the applet for its applet context and invoke showDocument() on that context object.

URL targetURL;
String URLString
AppletContext context = getAppletContext();
try
{
targetURL = new URL(URLString);
}
catch (MalformedURLException e)
{
// Code for recover from the exception
}
context. showDocument (targetURL);

4.

How Can I Arrange For Different Applets On A Web Page To Communicate With Each Other?

Answer»

Name your APPLETS INSIDE the Applet TAG and INVOKE AppletContexts getApplet() method in your applet code to obtain references to the other applets on the PAGE.

Name your applets inside the Applet tag and invoke AppletContexts getApplet() method in your applet code to obtain references to the other applets on the page.

5.

How Do We Read Number Information From My Applets Parameters, Given That Applets Getparameter() Method Returns A String?

Answer»

Use the parseInt() method in the Integer CLASS, the Float(STRING) CONSTRUCTOR or parseFloat() method in the Class Float, or the DOUBLE(String) constructor or parseDoulbl() method in the class Double.

Use the parseInt() method in the Integer Class, the Float(String) constructor or parseFloat() method in the Class Float, or the Double(String) constructor or parseDoulbl() method in the class Double.

6.

Can We Pass Parameters To An Applet From Html Page To An Applet? How?

Answer»

We can pass parameters to an applet USING <param> tag in the following way:

► <param name=param1″ value=value1″>
► <param name=param2″ valuevalue2″>

ACCESS those parameters inside the applet is done by calling getParameter() method inside the applet. Note that getParameter() method returns String value corresponding to the PARAMETER name.

We can pass parameters to an applet using <param> tag in the following way:

► <param name=param1″ value=value1″>
► <param name=param2″ valuevalue2″>

Access those parameters inside the applet is done by calling getParameter() method inside the applet. Note that getParameter() method returns String value corresponding to the parameter name.

7.

How Do Applets Differ From Applications?

Answer»

Following are the main differences:
Application: Stand Alone, doesnt need web-browser.
Applet: Needs no explicit installation on local MACHINE. Can be TRANSFERRED through Internet on to the local machine and may run as PART of web-browser.
Application: EXECUTION starts with main() method. Doesnt work if main is not there.
Applet: Execution starts with init() method.
Application: May or may not be a GUI.
Applet: Must run within a GUI (Using AWT). This is essential feature of APPLETS.

Following are the main differences:
Application: Stand Alone, doesnt need web-browser.
Applet: Needs no explicit installation on local machine. Can be transferred through Internet on to the local machine and may run as part of web-browser.
Application: Execution starts with main() method. Doesnt work if main is not there.
Applet: Execution starts with init() method.
Application: May or may not be a GUI.
Applet: Must run within a GUI (Using AWT). This is essential feature of applets.

8.

What Is The Sequence For Calling The Methods By Awt For Applets?

Answer»

When an applet begins, the AWT CALLS the following methods, in this SEQUENCE:
► init()
► start()
► paint()
When an applet is TERMINATED, the following sequence of method calls takes PLACE :
► stop()
DESTROY()

When an applet begins, the AWT calls the following methods, in this sequence:
► init()
► start()
► paint()
When an applet is terminated, the following sequence of method calls takes place :
► stop()
► destroy()

9.

What Are The Applets Life Cycle Methods? Explain Them?

Answer»

methods in the life cycle of an Applet:
► init() method - called when an applet is first LOADED. This method is called only once in the entire cycle of an applet. This method USUALLY intialize the variables to be USED in the applet.
► start( ) method - called each time an applet is started.
► paint() method - called when the applet is minimized or refreshed. This method is used for drawing DIFFERENT strings, figures, and images on the applet window.
► stop( ) method - called when the browser MOVES off the applets page.
► destroy( ) method - called when the browser is finished with the applet.

methods in the life cycle of an Applet:
► init() method - called when an applet is first loaded. This method is called only once in the entire cycle of an applet. This method usually intialize the variables to be used in the applet.
► start( ) method - called each time an applet is started.
► paint() method - called when the applet is minimized or refreshed. This method is used for drawing different strings, figures, and images on the applet window.
► stop( ) method - called when the browser moves off the applets page.
► destroy( ) method - called when the browser is finished with the applet.

10.

What Is The Order Of Method Invocation In An Applet?

Answer»

► public void init() : Initialization method called once by browser.
► public void start() : Method called after init() and contains code to start PROCESSING. If the USER leaves the page and RETURNS without killing the current browser session, the start () method is called without being preceded by init ().
► public void stop() : Stops all processing started by start (). Done if user moves off page.
► public void destroy() : Called if current browser session is being terminated. Frees all resources used by APPLET.

► public void init() : Initialization method called once by browser.
► public void start() : Method called after init() and contains code to start processing. If the user leaves the page and returns without killing the current browser session, the start () method is called without being preceded by init ().
► public void stop() : Stops all processing started by start (). Done if user moves off page.
► public void destroy() : Called if current browser session is being terminated. Frees all resources used by applet.

11.

In Our Urls And In The Text Of The Buttons We Have Comma. Its Causing An Error. Is There A Way To Change The Delimiting Character For The Menu Arguments?

Answer»

SINCE 2.00 version our applets support an user-defined delimiter for the menu ARGUMENTS. To modify the default delimiter add the following parameter (you can use any character as a delimiter):

&LT;param name="delimiter" value="~"> and use it within "menuItems": <param name="menuItems" value=" {Home~http://www.wisdomjobs.com.com/index.php} {FEATURES,Setup~http://www.wisdomjobs.com/} ">

Since 2.00 version our applets support an user-defined delimiter for the menu arguments. To modify the default delimiter add the following parameter (you can use any character as a delimiter):

12.

How To Insert Your Applets Into Frontpage?

Answer»

1. PLACE the .class file in the DIRECTORY containing the HTML document into which you want to insert the applet.
2. Copy the <applet>...</applet> tag from your applet implementation or examples to the clipboard.
3. In FrontPage select the "HTML" tab from the lower left hand corner.
4. Paste the <applet>...</applet> tag in an appropriate place between the <body> and </body> tags. You'll FIND a GRAY box with the aqua letter "J" in the "NORMAL" view indicating the the applet tag has been inserted.
5. To see the applet appearance select the "Preview" tab.

1. Place the .class file in the directory containing the HTML document into which you want to insert the applet.
2. Copy the <applet>...</applet> tag from your applet implementation or examples to the clipboard.
3. In FrontPage select the "HTML" tab from the lower left hand corner.
4. Paste the <applet>...</applet> tag in an appropriate place between the <body> and </body> tags. You'll find a gray box with the aqua letter "J" in the "Normal" view indicating the the applet tag has been inserted.
5. To see the applet appearance select the "Preview" tab.

13.

How Will You Initialize An Applet?

Answer»

Write my INITIALIZATION code in the APPLETS INIT method or applet constructor.

Write my initialization code in the applets init method or applet constructor.

14.

What Is An Applet? Should Applets Have Constructors?

Answer»

Applets are small programs transferred through Internet, AUTOMATICALLY installed and run as part of web-browser. Applets IMPLEMENTS functionality of a client. APPLET is a DYNAMIC and interactive program that runs inside a Web page displayed by a Java-capable browser. We dont have the concept of Constructors in Applets. Applets can be invoked EITHER through browser or through Appletviewer utility provided by JDK.

Applets are small programs transferred through Internet, automatically installed and run as part of web-browser. Applets implements functionality of a client. Applet is a dynamic and interactive program that runs inside a Web page displayed by a Java-capable browser. We dont have the concept of Constructors in Applets. Applets can be invoked either through browser or through Appletviewer utility provided by JDK.

15.

How Do You Communicate In Between Applets And Servlets?

Answer»

We can USE the java.net.URLConnection and java.net.URL classes to open a standard HTTP connection and "tunnel" to the web SERVER. The server then passes this information to the servlet in the normal way. BASICALLY, the applet pretends to be a web browser, and the servlet doesn't know the difference. As FAR as the servlet is concerned, the applet is just another HTTP client.

We can use the java.net.URLConnection and java.net.URL classes to open a standard HTTP connection and "tunnel" to the web server. The server then passes this information to the servlet in the normal way. Basically, the applet pretends to be a web browser, and the servlet doesn't know the difference. As far as the servlet is concerned, the applet is just another HTTP client.

16.

How Will You Communicate Between Two Applets?

Answer»

The simplest method is to use the STATIC variables of a SHARED class since there's only one instance of the class and hence only one copy of its static variables. A slightly more RELIABLE method relies on the fact that all the APPLETS on a given page share the same AppletContext. We obtain this applet context as follows:

AppletContext ac = getAppletContext();

AppletContext provides applets with methods such as getApplet(name), getApplets(),getAudioClip, getImage, showDocument and showStatus().

The simplest method is to use the static variables of a shared class since there's only one instance of the class and hence only one copy of its static variables. A slightly more reliable method relies on the fact that all the applets on a given page share the same AppletContext. We obtain this applet context as follows:

AppletContext ac = getAppletContext();

AppletContext provides applets with methods such as getApplet(name), getApplets(),getAudioClip, getImage, showDocument and showStatus().

17.

What Are The General Considerations Or Best Practices For Defining Your Hibernate Persistent Classes?

Answer»

1.You must have a default no-argument constructor for your persistent classes and there should be getXXX() (i.e accessor/getter) and setXXX( i.e. mutator/setter) methods for all your persistable instance variables.
2.You should implement the equals() and hashCode() methods based on your business key and it is important not to use the id field in your equals() and hashCode() definition if the id field is a surrogate key (i.e. Hibernate managed identifier). This is because the Hibernate only generates and sets the field when saving the object.
3. It is recommended to implement the Serializable interface. This is potentially USEFUL if you want to MIGRATE AROUND a multi-processor cluster.
4.The persistent class should not be final because if it is final then lazy loading cannot be used by creating PROXY objects.
5.Use XDoclet tags for generating your *.hbm.xml files or Annotations (JDK 1.5 onwards), which are less verbose than *.hbm.xml files.

1.You must have a default no-argument constructor for your persistent classes and there should be getXXX() (i.e accessor/getter) and setXXX( i.e. mutator/setter) methods for all your persistable instance variables.
2.You should implement the equals() and hashCode() methods based on your business key and it is important not to use the id field in your equals() and hashCode() definition if the id field is a surrogate key (i.e. Hibernate managed identifier). This is because the Hibernate only generates and sets the field when saving the object.
3. It is recommended to implement the Serializable interface. This is potentially useful if you want to migrate around a multi-processor cluster.
4.The persistent class should not be final because if it is final then lazy loading cannot be used by creating proxy objects.
5.Use XDoclet tags for generating your *.hbm.xml files or Annotations (JDK 1.5 onwards), which are less verbose than *.hbm.xml files.

18.

How Would You Reatach Detached Objects To A Session When The Same Object Has Already Been Loaded Into The Session?

Answer»

You can USE the session.merge() METHOD CALL.

You can use the session.merge() method call.

19.

What Is The Difference Between The Session.update() Method And The Session.lock() Method?

Answer»

Both of these methods and saveOrUpdate() method are intended for reattaching a detached object. The session.lock() method simply reattaches the object to the session without checking or updating the database on the assumption that the database in sync with the detached object. It is the BEST practice to use either session.update(..) or session.saveOrUpdate(). Use session.lock() only if you are absolutely sure that the detached object is in sync with your detached object or if it does not matter because you will be OVERWRITING all the columns that would have CHANGED later on within the same transaction. Note: When you reattach detached objects you need to MAKE sure that the dependent objects are reatched as well.

Both of these methods and saveOrUpdate() method are intended for reattaching a detached object. The session.lock() method simply reattaches the object to the session without checking or updating the database on the assumption that the database in sync with the detached object. It is the best practice to use either session.update(..) or session.saveOrUpdate(). Use session.lock() only if you are absolutely sure that the detached object is in sync with your detached object or if it does not matter because you will be overwriting all the columns that would have changed later on within the same transaction. Note: When you reattach detached objects you need to make sure that the dependent objects are reatched as well.

20.

What Is The Difference Between The Session.get() Method And The Session.load() Method?

Answer»

Both the session.get(..) and session.load() methods create a PERSISTENT OBJECT by LOADING the required object from the database. But if there was not such object in the database then the method session.load(..) throws an exception whereas session.get(&) returns NULL.

Both the session.get(..) and session.load() methods create a persistent object by loading the required object from the database. But if there was not such object in the database then the method session.load(..) throws an exception whereas session.get(&) returns null.

21.

How Does Hibernate Distinguish Between Transient (i.e. Newly Instantiated) And Detached Objects?

Answer»

Hibernate uses the version property, if there is one.

If not uses the identifier VALUE. No identifier value means a new object. This does WORK only for Hibernate managed surrogate KEYS. Does not work for NATURAL keys and assigned (i.e. not managed by Hibernate) surrogate keys.

Write your own STRATEGY with Interceptor.isUnsaved().

Hibernate uses the version property, if there is one.

If not uses the identifier value. No identifier value means a new object. This does work only for Hibernate managed surrogate keys. Does not work for natural keys and assigned (i.e. not managed by Hibernate) surrogate keys.

Write your own strategy with Interceptor.isUnsaved().

22.

What Are The Pros And Cons Of Detached Objects?

Answer»

Pros:
" When long transactions are required due to USER think-time, it is the best practice to break the long transaction up into two or more transactions. You can use detached objects from the first transaction to carry data all the way up to the presentation layer. These detached objects get modified outside a transaction and later on re-attached to a NEW transaction via another session.
Cons
" In general, working with detached objects is quite cumbersome, and better to not clutter up the session with them if possible. It is better to discard them and re-fetch them on subsequent requests. This approach is not only more portable but also more efficient because - the objects HANG AROUND in Hibernate's cache anyway.
" Also from PURE rich domain driven design perspective it is recommended to use DTOs (DataTransferObjects) and DOs (DomainObjects) to maintain the separation between Service and UI tiers.

Pros:
" When long transactions are required due to user think-time, it is the best practice to break the long transaction up into two or more transactions. You can use detached objects from the first transaction to carry data all the way up to the presentation layer. These detached objects get modified outside a transaction and later on re-attached to a new transaction via another session.
Cons
" In general, working with detached objects is quite cumbersome, and better to not clutter up the session with them if possible. It is better to discard them and re-fetch them on subsequent requests. This approach is not only more portable but also more efficient because - the objects hang around in Hibernate's cache anyway.
" Also from pure rich domain driven design perspective it is recommended to use DTOs (DataTransferObjects) and DOs (DomainObjects) to maintain the separation between Service and UI tiers.

23.

What Are The Benefits Of Detached Objects?

Answer»

Detached objects can be passed ACROSS layers all the WAY up to the PRESENTATION layer WITHOUT having to use any DTOs (Data Transfer Objects). You can later on re-attach the detached objects to another session.

Detached objects can be passed across layers all the way up to the presentation layer without having to use any DTOs (Data Transfer Objects). You can later on re-attach the detached objects to another session.

24.

What Is A Session? Can You Share A Session Object Between Different Theads?

Answer»

Session is a light weight and a non-threadsafe object (No, you cannot share it between threads) that represents a single unit-of-work with the database. Sessions are opened by a SessionFactory and then are closed when all work is complete. Session is the primary interface for the persistence service. A session obtains a database connection lazily (i.e. only when required). To avoid creating too many sessions ThreadLocal class can be used as shown below to get the CURRENT session no matter how many times you make CALL to the currentSession() method.
&
public class HibernateUtil {
&
public static final ThreadLocal local = new ThreadLocal();
public static Session currentSession() throws HibernateException {
Session session = (Session) local.get();
//open a new session if this THREAD has no session
if(session == null) {
session = sessionFactory.openSession();
local.set(session);
}
RETURN session;
}
}
It is also vital that you close your session after your unit of work completes.

Session is a light weight and a non-threadsafe object (No, you cannot share it between threads) that represents a single unit-of-work with the database. Sessions are opened by a SessionFactory and then are closed when all work is complete. Session is the primary interface for the persistence service. A session obtains a database connection lazily (i.e. only when required). To avoid creating too many sessions ThreadLocal class can be used as shown below to get the current session no matter how many times you make call to the currentSession() method.
&
public class HibernateUtil {
&
public static final ThreadLocal local = new ThreadLocal();
public static Session currentSession() throws HibernateException {
Session session = (Session) local.get();
//open a new session if this thread has no session
if(session == null) {
session = sessionFactory.openSession();
local.set(session);
}
return session;
}
}
It is also vital that you close your session after your unit of work completes.

25.

What Is A Sessionfactory? Is It A Thread-safe Object?

Answer»

SESSIONFACTORY is Hibernates concept of a single DATASTORE and is threadsafe so that many threads can ACCESS it concurrently and request for sessions and immutable cache of compiled mappings for a single database. A SessionFactory is usually only built once at STARTUP. SessionFactory should be wrapped in some kind of singleton so that it can be easily accessed in an application CODE.
SessionFactory sessionFactory = new Configuration().configure().buildSessionfactory();

SessionFactory is Hibernates concept of a single datastore and is threadsafe so that many threads can access it concurrently and request for sessions and immutable cache of compiled mappings for a single database. A SessionFactory is usually only built once at startup. SessionFactory should be wrapped in some kind of singleton so that it can be easily accessed in an application code.
SessionFactory sessionFactory = new Configuration().configure().buildSessionfactory();

26.

How Will You Configure Hibernate?

Answer»

The configuration files hibernate.cfg.xml (or hibernate.properties) and mapping files *.hbm.xml are used by the Configuration class to create (i.e. configure and bootstrap hibernate) the SessionFactory, which in turn creates the Session instances. Session instances are the primary interface for the persistence service.

" hibernate.cfg.xml (alternatively can use hibernate.properties): These two files are used to configure the hibernate sevice (connection DRIVER class, connection URL, connection username, connection password, dialect etc). If both files are present in the classpath then hibernate.cfg.xml file overrides the settings found in the hibernate.properties file.

" Mapping files (*.hbm.xml): These files are used to map persistent objects to a relational database. It is the best practice to store each object in an individual mapping file (i.e mapping file per class) because storing LARGE number of persistent classes into one mapping file can be DIFFICULT to manage and maintain. The naming convention is to use the same name as the persistent (POJO) class name. For EXAMPLE Account.class will have a mapping file named Account.hbm.xml. Alternatively hibernate annotations can be used as part of your persistent class code instead of the *.hbm.xml files.

The configuration files hibernate.cfg.xml (or hibernate.properties) and mapping files *.hbm.xml are used by the Configuration class to create (i.e. configure and bootstrap hibernate) the SessionFactory, which in turn creates the Session instances. Session instances are the primary interface for the persistence service.

" hibernate.cfg.xml (alternatively can use hibernate.properties): These two files are used to configure the hibernate sevice (connection driver class, connection URL, connection username, connection password, dialect etc). If both files are present in the classpath then hibernate.cfg.xml file overrides the settings found in the hibernate.properties file.

" Mapping files (*.hbm.xml): These files are used to map persistent objects to a relational database. It is the best practice to store each object in an individual mapping file (i.e mapping file per class) because storing large number of persistent classes into one mapping file can be difficult to manage and maintain. The naming convention is to use the same name as the persistent (POJO) class name. For example Account.class will have a mapping file named Account.hbm.xml. Alternatively hibernate annotations can be used as part of your persistent class code instead of the *.hbm.xml files.

27.

Explain The Difference Between Hibernate And Spring.

Answer»

Hibernate is an ORM tool for data persistency. Spring is a framework for ENTERPRISE applications. Spring supports hibernate and provides the different CLASSES which are templates that CONTAINS the common CODE.

Hibernate is an ORM tool for data persistency. Spring is a framework for enterprise applications. Spring supports hibernate and provides the different classes which are templates that contains the common code.

28.

Explain The Main Difference Between Entity Beans And Hibernate.

Answer»

Entity beans are to be implemented by CONTAINERS, CLASSES, descriptors. Hibernate is just a tool that quickly persist the object tree to a class hierarchy in a database and without using a single SQL STATEMENT. The inheritance and polymorphism is quite simply implemented in hibernate which is out of the box of EJB and a big DRAWBACK.

Entity beans are to be implemented by containers, classes, descriptors. Hibernate is just a tool that quickly persist the object tree to a class hierarchy in a database and without using a single SQL statement. The inheritance and polymorphism is quite simply implemented in hibernate which is out of the box of EJB and a big drawback.

29.

Why Hibernate Is Advantageous Over Entity Beans &amp; Jdbc?

Answer»

An ENTITY bean always WORKS under the EJB container, which allows reusing of the object external to the container. An object can not be detached in entity beans and in hibernate detached objects are supported.

Hibernate is not database DEPENDENT where as JDBC is database dependent. QUERY tuning is not needed for hibernate as JDBC is needed. Data can be placed in multiple cache which is supported by hibernate, whereas in JDBC the cache is to be implemented.

An entity bean always works under the EJB container, which allows reusing of the object external to the container. An object can not be detached in entity beans and in hibernate detached objects are supported.

Hibernate is not database dependent where as JDBC is database dependent. Query tuning is not needed for hibernate as JDBC is needed. Data can be placed in multiple cache which is supported by hibernate, whereas in JDBC the cache is to be implemented.

30.

What Is The Advantage Of Hibernate Over Jdbc?

Answer»

The advantages of Hibernate over JDBC are:
• Hibernate code will WORK well for all databases, for ex: Oracle,MySQL, etc. where as JDBC is database specific.
• No KNOWLEDGE of SQL is needed because Hibernate is a set of objects and a table is treated as an OBJECT, where as to work with JDBC, one need to know SQL.
• Query tuning is not required in Hibernate. The query tuning is automatic in hibernate by using criteria queries, and the RESULT of performance is at its best. Where as in JDBC the query tuning is to be DONE by the database authors.
• With the support of cache of hibernate, the data can be placed in the cache for better performance. Where as in JDBC the java cache is to be implemented.

The advantages of Hibernate over JDBC are:
• Hibernate code will work well for all databases, for ex: Oracle,MySQL, etc. where as JDBC is database specific.
• No knowledge of SQL is needed because Hibernate is a set of objects and a table is treated as an object, where as to work with JDBC, one need to know SQL.
• Query tuning is not required in Hibernate. The query tuning is automatic in hibernate by using criteria queries, and the result of performance is at its best. Where as in JDBC the query tuning is to be done by the database authors.
• With the support of cache of hibernate, the data can be placed in the cache for better performance. Where as in JDBC the java cache is to be implemented.

31.

What Is The Difference Between Merge And Update?

Answer»

update () : When the session does not contain an persistent INSTANCE with the same identifier, and if it is sure use update for the DATA PERSISTENCE in hibernate.

merge (): Irrespective of the state of a session, if there is a need to save the MODIFICATIONS at any given time, use merge().

update () : When the session does not contain an persistent instance with the same identifier, and if it is sure use update for the data persistence in hibernate.

merge (): Irrespective of the state of a session, if there is a need to save the modifications at any given time, use merge().

32.

State The Role Of Sessionfactory Interface Plays In Hibernate.

Answer»

• An application obtains Session instances from a SessionFactory which is typically single for the whole application created during its INITIALIZATION.
• The SessionFactory caches generate SQL statements and other mapping METADATA that Hibernate uses at runtime.
• It also holds cached data that has been read in one unit of work and MAY be reused in a future unit of work
SessionFactory sessionFactory = configuration.buildSessionFactory();

• An application obtains Session instances from a SessionFactory which is typically single for the whole application created during its initialization.
• The SessionFactory caches generate SQL statements and other mapping metadata that Hibernate uses at runtime.
• It also holds cached data that has been read in one unit of work and may be reused in a future unit of work
SessionFactory sessionFactory = configuration.buildSessionFactory();

33.

Explain The Role Of Session Interface In Hibernate.

Answer»

• In hibernate, the Session interface wraps a JDBC CONNECTION, holds a mandatory (first-level) cache of persistent objects, used when NAVIGATING the object graph or LOOKING up objects by IDENTIFIER and is a factory for Transaction.
• Session session = sessionFactory.openSession();
• The Session interface is the primary interface used by Hibernate applications.
• It is a single-threaded, short-lived object representing a conversation between the application and the persistent store.
• It allows you to create QUERY objects to retrieve persistent objects.

• In hibernate, the Session interface wraps a JDBC connection, holds a mandatory (first-level) cache of persistent objects, used when navigating the object graph or looking up objects by identifier and is a factory for Transaction.
• Session session = sessionFactory.openSession();
• The Session interface is the primary interface used by Hibernate applications.
• It is a single-threaded, short-lived object representing a conversation between the application and the persistent store.
• It allows you to create query objects to retrieve persistent objects.

34.

Explain The General Flow Of Hibernate Communication With Rdbms.

Answer»

The general flow of HIBERNATE communication with RDBMS is :
• The Hibernate configuration is to be loaded and creation of configuration object is done. The mapping of all hbm files will be performed automatically.
• Creation of SESSION FACTORY from the configuration object.
• Obtain a session from the session factory.
• Creation of HQL Query .
• Execution of the query in order to get the list of containing java objects.

The general flow of Hibernate communication with RDBMS is :
• The Hibernate configuration is to be loaded and creation of configuration object is done. The mapping of all hbm files will be performed automatically.
• Creation of session factory from the configuration object.
• Obtain a session from the session factory.
• Creation of HQL Query .
• Execution of the query in order to get the list of containing java objects.

35.

What Is Hibernate Query Language (hql)?

Answer»

Hibernate Query Language is designed for data management using Hibernate TECHNOLOGY. It is completely object ORIENTED and hence has NOTIONS like inheritance, polymorphism and abstraction. The queries are case-sensitive. This has an EXCEPTION for Java classes and properties. The query operations are through objects. HQL acts as a BRIDGE between Objects and RDBMS.

Hibernate Query Language is designed for data management using Hibernate technology. It is completely object oriented and hence has notions like inheritance, polymorphism and abstraction. The queries are case-sensitive. This has an exception for Java classes and properties. The query operations are through objects. HQL acts as a bridge between Objects and RDBMS.

36.

Explain The Advantages And Disadvantages Of Detached Objects.

Answer»

Advantages:
• Detached objects passing can be done ACROSS layers upto the presentation layer without using Data Transfer Objects.
• At the TIME of using long TRANSACTIONS by the user which needs long think-time, it is suggested to split these transactions into some transactions. The detached objects get modified APART from the TRANSACTION scope which then can be re-attached to a new transaction.

Disadvantages:
• The usage of detached objects are cumbersome and cryptic. It is suggested not to be cluttered with the session, if possible.
• It is recommended to use DataTransferObjects and DomainObjects that is used to maintain separation between the user interfaces and the Service.

Advantages:
• Detached objects passing can be done across layers upto the presentation layer without using Data Transfer Objects.
• At the time of using long transactions by the user which needs long think-time, it is suggested to split these transactions into some transactions. The detached objects get modified apart from the transaction scope which then can be re-attached to a new transaction.

Disadvantages:
• The usage of detached objects are cumbersome and cryptic. It is suggested not to be cluttered with the session, if possible.
• It is recommended to use DataTransferObjects and DomainObjects that is used to maintain separation between the user interfaces and the Service.

37.

What Is The Difference Between Sorted And Ordered Collection In Hibernate?

Answer»

Sorted Collection:
The sorted collection is a collection that is sorted using the Java collections framework. The sorting is done in the memory of JVM that is RUNNING hibernate, SOON after reading the data from the database using Java Comparator.

The less the collection the more the efficient of sorting.

Ordered Collection:
The order collections will also sorts a collection by using the order by clause for the results fetched.

The more the collection, the more efficient of sorting.

Sorted Collection:
The sorted collection is a collection that is sorted using the Java collections framework. The sorting is done in the memory of JVM that is running hibernate, soon after reading the data from the database using Java Comparator.

The less the collection the more the efficient of sorting.

Ordered Collection:
The order collections will also sorts a collection by using the order by clause for the results fetched.

The more the collection, the more efficient of sorting.

38.

What Is Lazy Fetching In Hibernate?

Answer»

• Lazy SETTING decides whether to load child objects while loading the Parent OBJECT.
• This can be DONE by a setting in hibernate mapping file of the parent class.Lazy = TRUE.
• By default the lazy loading of the child objects is true.

• Lazy setting decides whether to load child objects while loading the Parent Object.
• This can be done by a setting in hibernate mapping file of the parent class.Lazy = true.
• By default the lazy loading of the child objects is true.

39.

What Is Lazy Initialization In Hibernate?

Answer»

The delaying the object creation or calculating a value or some PROCESS until the first time it is needed. The retrieval of particular information only at the time when the object is accessed, is lazy initialization in HIBERNATE. A scenario for lazy initialization is:

When the field creation is EXPENSIVE, a field may or may not be invoked.

In this scenario the creation of a field can be deferred until the actual moment is arise to use it. The performance is increased using this technique, by avoiding unnecessary creation of objects which is expensive and consumes the MEMORY space.

The delaying the object creation or calculating a value or some process until the first time it is needed. The retrieval of particular information only at the time when the object is accessed, is lazy initialization in hibernate. A scenario for lazy initialization is:

When the field creation is expensive, a field may or may not be invoked.

In this scenario the creation of a field can be deferred until the actual moment is arise to use it. The performance is increased using this technique, by avoiding unnecessary creation of objects which is expensive and consumes the memory space.

40.

What Are Collection Types In Hibernate?

Answer»

• ArrayType,
Constructor: ArrayType(STRING role, String propertyRef, Class elementClass, boolean isEmbeddedInXML)
• BagType,
Constructor: BagType(String role, String propertyRef, boolean isEmbeddedInXML)
• CustomCollectionType, A custom type for mapping user-written CLASSES that implement PersistentCollection Constructor: CustomCollectionType(Class userTypeClass, String role, String foreignKeyPropertyName, boolean isEmbeddedInXML)
• IdentifierBagType,
Constructor: IdentifierBagType(String role, String propertyRef, boolean isEmbeddedInXML)
LISTTYPE,
Constructor: ListType(String role, String propertyRef, boolean isEmbeddedInXML)
MAPTYPE,
Constructor: MapType(String role, String propertyRef, boolean isEmbeddedInXML)
• SetType
Constructor: SetType(String role, String propertyRef, boolean isEmbeddedInXML)

• ArrayType,
Constructor: ArrayType(String role, String propertyRef, Class elementClass, boolean isEmbeddedInXML)
• BagType,
Constructor: BagType(String role, String propertyRef, boolean isEmbeddedInXML)
• CustomCollectionType, A custom type for mapping user-written classes that implement PersistentCollection Constructor: CustomCollectionType(Class userTypeClass, String role, String foreignKeyPropertyName, boolean isEmbeddedInXML)
• IdentifierBagType,
Constructor: IdentifierBagType(String role, String propertyRef, boolean isEmbeddedInXML)
• ListType,
Constructor: ListType(String role, String propertyRef, boolean isEmbeddedInXML)
• MapType,
Constructor: MapType(String role, String propertyRef, boolean isEmbeddedInXML)
• SetType
Constructor: SetType(String role, String propertyRef, boolean isEmbeddedInXML)

41.

Explain The Types Of Hibernate Instance States.

Answer»

The PERSISTENT class’s instance can be in any one of the three different states. These states are defined with a persistence context. The Hibernate has the FOLLOWING instance states:
• Transient: This instance is never been associated with any one of the persistence process. This does not have persistent IDENTITY like primary key value.
• Persistent: A persistent context is made to associate with the current instance. It has persistent identity like primary key value and a corresponding row of a table in the data base. Hibernate guarantees the persistent identity is equivalent to the java Identity [object], for a PARTICULAR persistence context.
• Detatched: This instance association with a persistence context is only once and the context was CLOSED or serialized to another process. The persistent identity is retained and it can be a corresponding row in a database.

The persistent class’s instance can be in any one of the three different states. These states are defined with a persistence context. The Hibernate has the following instance states:
• Transient: This instance is never been associated with any one of the persistence process. This does not have persistent identity like primary key value.
• Persistent: A persistent context is made to associate with the current instance. It has persistent identity like primary key value and a corresponding row of a table in the data base. Hibernate guarantees the persistent identity is equivalent to the java Identity [object], for a particular persistence context.
• Detatched: This instance association with a persistence context is only once and the context was closed or serialized to another process. The persistent identity is retained and it can be a corresponding row in a database.

42.

What Is Hibernate Proxy?

Answer»

Mapping of classes can be made into a PROXY instead of a table. A proxy is returned when actually a LOAD is called on a session. The proxy contains actual method to load the data. The proxy is created by default by Hibernate, for mapping a class to a FILE. The code to invoke Jdbc is contained in this class.

Mapping of classes can be made into a proxy instead of a table. A proxy is returned when actually a load is called on a session. The proxy contains actual method to load the data. The proxy is created by default by Hibernate, for mapping a class to a file. The code to invoke Jdbc is contained in this class.

43.

What Are The Benefits Of Hibernatetemplate?

Answer»

The BENEFITS of HibernateTemplate are:
• HibernateTemplate, which is a SPRING Template class, can simplify the INTERACTIONS with Hibernate Sessions.
• Various common functions are simplified into SINGLE method invocations.
• The sessions of hibernate are CLOSED automatically.
• The exceptions will be caught automatically, and converts them into runtime exceptions.

The benefits of HibernateTemplate are:
• HibernateTemplate, which is a Spring Template class, can simplify the interactions with Hibernate Sessions.
• Various common functions are simplified into single method invocations.
• The sessions of hibernate are closed automatically.
• The exceptions will be caught automatically, and converts them into runtime exceptions.

44.

What Is A Hibernatetemplate?

Answer»

HibernateTemplate is a HELPER class that is used to simplify the data access code. This class supports automatically converts HibernateExceptions which is a checked EXCEPTION into DataAccessExceptions which is an unchecked exception. HibernateTemplate is typically used to implement data access or BUSINESS logic services. The central method is EXECUTE(), that supports the Hibernate code that implements HibernateCallback interface.

HibernateTemplate is a helper class that is used to simplify the data access code. This class supports automatically converts HibernateExceptions which is a checked exception into DataAccessExceptions which is an unchecked exception. HibernateTemplate is typically used to implement data access or business logic services. The central method is execute(), that supports the Hibernate code that implements HibernateCallback interface.

45.

What Are The Core Interfaces Of Hibernate Framework?

Answer»

1. Session Interface: The basic interface for all hibernate applications. The instances are light weighted and can be created and destroyed without expensive process.
2. SESSIONFACTORY interface: The delivery of session OBJECTS to hibernate applications is done by this interface. For the whole application, there will be generally one SessionFactory and can be shared by all the application threads.
3. Configuration Interface: Hibernate bootstrap action is configured by this interface. The location specification is specified by specific MAPPING documents, is done by the instance of this interface.
4. Transaction Interface: This is an optional interface. This interface is used to abstract the code from a transaction that is IMPLEMENTED such as a JDBC / JTA transaction.
5. Query and Criteria interface: The queries from the USER are allowed by this interface apart from controlling the flow of the query execution.

1. Session Interface: The basic interface for all hibernate applications. The instances are light weighted and can be created and destroyed without expensive process.
2. SessionFactory interface: The delivery of session objects to hibernate applications is done by this interface. For the whole application, there will be generally one SessionFactory and can be shared by all the application threads.
3. Configuration Interface: Hibernate bootstrap action is configured by this interface. The location specification is specified by specific mapping documents, is done by the instance of this interface.
4. Transaction Interface: This is an optional interface. This interface is used to abstract the code from a transaction that is implemented such as a JDBC / JTA transaction.
5. Query and Criteria interface: The queries from the user are allowed by this interface apart from controlling the flow of the query execution.

46.

What Are The Main Advantages Of Orm Like Hibernate?

Answer»

Hibernate IMPLEMENTS extremely high-concurrency architecture with no resource-contention issues. This architecture scales extremely well as concurrency increases in a cluster or on a single machine.

Other performance related optimizations that hibernate performs are:
• Caching OBJECTS
• Executing SQL statements later, when needed
• Never updating unmodified objects
• Efficient Collection Handling
• Rolling two updates into one
• Updating only the MODIFIED columns
• Outer JOIN fetching
• Lazy collection INITIALIZATION
• Lazy object initialization.

Hibernate implements extremely high-concurrency architecture with no resource-contention issues. This architecture scales extremely well as concurrency increases in a cluster or on a single machine.

Other performance related optimizations that hibernate performs are:
• Caching objects
• Executing SQL statements later, when needed
• Never updating unmodified objects
• Efficient Collection Handling
• Rolling two updates into one
• Updating only the modified columns
• Outer join fetching
• Lazy collection initialization
• Lazy object initialization.

47.

Why Do You Need Orm Tool Like Hibernate?

Answer»

ORM TOOLS like hibernate provide FOLLOWING BENEFITS:
• Improved performance: Lazy loading, SOPHISTICATED caching, Eager loading.
• Improved productivity: High-level object-oriented API, Less Java code to write, No SQL to write.
• Improved maintainability: A lot less code to write.
• Improved portability: ORM framework generates database-specific SQL for you.

ORM tools like hibernate provide following benefits:
• Improved performance: Lazy loading, Sophisticated caching, Eager loading.
• Improved productivity: High-level object-oriented API, Less Java code to write, No SQL to write.
• Improved maintainability: A lot less code to write.
• Improved portability: ORM framework generates database-specific SQL for you.

48.

What Are Managed Associations And Hibernate Associations?

Answer»

ASSOCIATIONS that are related to container MANAGEMENT persistence are CALLED managed associations. These are bi-directional associations. Coming to hibernate associations, these are UNIDIRECTIONAL.

Associations that are related to container management persistence are called managed associations. These are bi-directional associations. Coming to hibernate associations, these are unidirectional.

49.

What Are The Different Approaches To Represent An Inheritance Hierarchy?

Answer»

i. Table PER concrete CLASS.
ii. Table per class HIERARCHY.
iii. Table per SUBCLASS.

i. Table per concrete class.
ii. Table per class hierarchy.
iii. Table per subclass.

50.

What Are The Different Methods Of Identifying An Object?

Answer»

There are three methods by which an object can be identified.
i. Object IDENTITY –Objects are identical if they reside in the same memory location in the JVM. This can be checked by using the = = operator.
ii. Object EQUALITY – Objects are equal if they have the same value, as DEFINED by the equals( ) method. Classes that don’t EXPLICITLY override this method inherit the implementation defined by java.lang.Object, which compares object identity.
iii. Database identity – Objects STORED in a relational database are identical if they represent the same row or, equivalently, share the same table and primary key value. 

There are three methods by which an object can be identified.
i. Object identity –Objects are identical if they reside in the same memory location in the JVM. This can be checked by using the = = operator.
ii. Object equality – Objects are equal if they have the same value, as defined by the equals( ) method. Classes that don’t explicitly override this method inherit the implementation defined by java.lang.Object, which compares object identity.
iii. Database identity – Objects stored in a relational database are identical if they represent the same row or, equivalently, share the same table and primary key value.