Wednesday, 31 October 2012

What are different types of inner classes? Nested -level classes, Member classes, Local classes, Anonymous classes. Explain them




There are 4 types of inner classes - Member inner class, Local inner class, Static inner class and Anonymous inner class
1. Member inner class – A member of a class(enclosing class).
2. Local inner class – An inner class that is defined within a block.
3. Static inner class – Like static members, this class itself is static.
4. Anonymous inner class – A class without a name and implements exactly only one interface or exactly extends one abstract class.

The enclosing class can not have the accessibility to the inner class. To do so, the outer class must create an object of its nested class except for static inner class. The member classes can access all of its enclosing class’s members, because inner class is like a member of a class.
Anonymous inner class is used when an object creation, one time single method invocation to be done and releasing the object at once. This is particular in event driven programming.
The nested classes are implemented in handling AWT, Swing and Applet programming. An anonymous inner class is invoked when an action event is to be performed.

What is a “dirty read”?


In typical database transactions, one transaction reads changes the value while the other reads the value before committing or rolling back by the first transaction. This reading process is called as ‘dirty read’. Because there is always a chance that the first transaction might rollback the change which causes the second transaction reads an invalid value. 

What are the main advantages of ORM like hibernate?


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

Explain the role of Session interface in Hibernate.


  • 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.

What are Collection types in Hibernate?


  • 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)

What is the difference between merge and update?


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..........

What is Hibernate proxy ?

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.

What is Map Collection?

A map collection refers to a set of maps that are compiled and organized for a specific purpose, such as research, education, or preservatio...