Question 01. Why can’t I use ResultSet object after the JDBC transaction completed?
- Because ResultSet is a lazy cache of data from the database and can have only a few rows from the database [Ref JDBC]
Question 02: What are advantages of ORM
- Productivity, because of automation
- Maintainability, raising the level of abstraction via use of mappings.
- Performance, by using complex optimization techniques.
- Vendor independence, a middle-ware to cater for various SQL dialects [Ref ORM Hibernate]
Question 03: What is normalization?
- It is a process of analysing the given relation schemas based on their Functional Dependencies (FDs) and primary key to achieve the properties
(1).Minimizing redundancy, (2). Minimizing insertion, deletion and update anomalies.
Question 04: What is 1 NF (Normal Form)?
- The domain of attribute must include only atomic (simple, indivisible) values.
Question 05: What is 2NF?
- A relation schema R is in 2NF if it is in 1NF and every non-prime attribute A in R is fully functionally dependent on primary key.
Question 06: What is 3NF?
- A relation schema R is in 3NF if it is in 2NF and for every FD X A either of the following is true
• X is a Super-key of R.
• A is a prime attribute of R.
In other words, if every non prime attribute is non-transitively dependent on primary key.
Question 07: What is BCNF (Boyce-Codd Normal Form)?
- A relation schema R is in BCNF if it is in 3NF and satisfies an additional constraint that for every FD X A, X must be a candidate key.
Question 08: What is indexing and what are the different kinds of indexing?
- Indexing is a technique for determining how quickly specific data can be found.
– Binary search style indexing
– B-Tree indexing
– Inverted list indexing
– Memory resident table
– Table indexing
Question 09: What is meant by query optimization?
- The phase that identifies an efficient execution plan for evaluating a query that has the least estimated cost is referred to as query optimization.
Question 10: Name and describe three types of binary relationships.
- 1:1 – a single entity instance of one type is related to a single-entity instance of another type.
- 1:N – a single entity instance of one type is related to many-entity instances of another type.
- M:N – many-entity instances of one type relate to many-entity instances of another type.
Question 11: What are stored procedures, and how do they differ from triggers?
- A stored procedure is a program that is stored within the database and is compiled when used. They can receive input parameters and they can return results. Unlike triggers, their scope is database-wide; they can be used by any process that has permission to use the database stored procedure.
Question 12: Explain the meaning of each of the transaction levels supported by SQL Server.
- The strictest isolation level is SERIALIZABLE. With it, SQL Server places a range lock on the rows that have been read. This level is the most expensive to use and should only be used when absolutely required. The next most restrictive level is REPEATABLE READ, which means SQL Server places and holds locks on all rows that are read. It is possible to make dirty reads by setting the isolation level to READ UNCOMMITTED, which is the least restrictive level. READ COMMITTED is the default isolation level.
Question 13: What is JPA?
- Java Persistence Architecture API (JPA) is a Java specification for accessing, persisting, and managing data between Java objects/classes and a relational database.
NOTE: JPA only defines interfaces. It does not provide an implementation.
Question 14: What is Hibernate?
- Hibernate is an implementation of JPA.
Hibernate is a pure Java object-relational mapping (ORM) and persistence framework that allows you to map plain old Java objects (POJOs) to relational database tables. Its purpose is to relieve the developer from a significant amount of relational data persistence-related programming tasks.
Question 15: What is ORM?
ORM stands for object/relational mapping. ORM is the automated persistence of objects in a Java application to the tables in a relational database.
Question 16: What does ORM consist of?
- An ORM solution consists of the following four pieces:
– API for performing basic CRUD operations
– API to express queries referring to classes
– Facilities to specify metadata
– Optimization facilities : dirty checking,lazy associations fetching
Question 17: Why do you need ORM tools like Hibernate?
- Improved productivity (Less Java code to write, No SQL to write).
- Improved performance (Sophisticated caching, Lazy loading, Eager loading).
- Improved maintainability.
- Improved portability (no DBMS specific code written).
Question 18: Difference between get and load in Hibernate?
- Get vs load is one of the most frequently asked Hibernate Interview questions since the correct understanding of both get() and load() is required to effectively use Hibernate. The main difference between get and load is that:
- Get(): always hits the database and fully initializes the retrieved object. If no row found , it return null.
- Load(): just initializes a proxy object which acts as the real object without real values. When the set-method of non-identifier properties are invoked, the database is queried for it. If no row found, it will throw an ObjectNotFoundException.
- Refer to [Lazing Loading p.29]; [Different between session.get() and session.load()]
Question 19: Difference between save, persist and saveOrUpdate methods in Hibernate?
- All three methods i.e. save(), saveOrUpdate() and persist() is used to save objects into database, but has subtle differences e.g. save() can only INSERT records but saveOrUpdate() can either INSERT or UPDATE records. Also, the return type of save() is a Serializable object, while the return type of persist() method is void.
- Refer to [Behzad Bordbar, Hibernate]]
Question 20: Can Entity class in JPA Java Persistence API, be an interface or can an interface be acted like an Entity?
- No, the Entity class must be class only, not an interface, the Entity class must not be declared final, and the Entity class must be the top-level class in a class hierarchy.
The entity class must have a no-argument public or protected constructor.
Question 21: What do you do to improve performance in hibernate? Or Performance Tunning?
- Lazy loading [Ref Lazy Loading p.28]
- Use Cache
- SQL Statement Tunning: good join, avoid duplication …
- Database Tuning: table structure, partition, index …
Question 22: What is IoC?
The basic concept of the Inversion of Control pattern (also known as dependency injection) is that you do not create your objects but describe how they should be created. You don’t directly connect your components and services together in code but describe which services are needed by which components. A container will be responsible for creating and wiring them together.
Question 23: What are the different types of IOC (dependency injection)?
- There are three types of dependency injection:
– Constructor Injection (e.g. Pico container, Spring etc): Dependencies are provided as constructor parameters.
– Setter Injection (e.g. Spring): Dependencies are assigned through JavaBeans properties (ex: setter methods).
– Interface Injection (e.g. Avalon): Injection is done through an interface.
Question 24: What are the benefits of IOC (Dependency Injection)?
- Loose coupling is promoted with minimal effort and the least intrusive mechanism.
- Minimizes the amount of code in your application.
- Make your application more testable by not requiring any singletons or JNDI lookup mechanisms in your unit test cases.
Question 25: What is Spring ?
- Spring is an open-source framework created to address the complexity of enterprise application development.
Question 26: What are features of Spring Framework (benefits)?
- Inversion of control (IOC): Loose coupling is achieved in spring using the technique Inversion of Control.
- Support AOP (Aspect Oriented Programming) [Ref AoP]
- Container: Spring contains and manages the life cycle and configuration of application objects.
- MVC Framework: Spring comes with MVC web application framework, built on core Spring functionality.
- Transaction Management.
Question 27: How many modules are there in Spring? What are they?
- The core container.
- Spring context: The Spring context is a configuration file that provides context information to the Spring framework. The Spring context includes enterprise services such as JNDI, EJB, e-mail, internalization, validation, and scheduling functionality.
- Spring AOP. [Ref AoP, Spring AOP]
- Spring DAO.
- Spring ORM.
- Spring Web module.
- Spring MVC framework.
Question 28: What is AOP?
- AOP is a programming technique that allows developer to modularize crosscutting concerns, that cuts across the typical divisions of responsibility, such as logging and transaction management. Spring AOP, aspects are implemented using regular classes or regular classes annotated with the @Aspect annotation
- Behzad Boradbar, Enterprise System. University of Birmingham. Slide for lecture