Tuesday, 13 February 2018

What is query cache in Hibernate?

QueryCache actually stores the result sets of SQL query for future calls. Query cache can be used along with second level cache for improved performance.
Hibernate support various open source caching solution to implement Query cache e.g. EhCache.
Every time the query is fired the cache manager checks for the combination of parameters and query. If the results are found in the cache they are returned otherwise a database transaction is initiated.

<property name="hibernate.cache.use_query_cache">true</property>

What is Second-level Cache in Hibernate?

Second level cache is an optional cache and first-level cache will always be consulted before any attempt is made to locate an object in the second-level cache. 
The second-level cache can be configured on a per-class and per-collection basis and mainly responsible for caching objects across sessions.
Any third-party cache can be used with Hibernate. An org.hibernate.cache.CacheProvider interface is provided, which must be implemented to provide Hibernate with a handle to the cache implementation.

What is Caching And the type of Hibernate caching?

Caching is all about application performance optimisation and it sits between your application and the database to avoid the number of database hits as many as possible to give a better performance.

Hibernate provides the out-of-box caching solution but there are many caches e.g. first level cache, second level cache and query cache. First level cache is maintained at Session level and cannot be disabled but the second level cache is required to be configured with external cache provider like EhCache.


What is Hibernate Query Language (HQL) ?

Hibernate Query Language (HQL) is an object-oriented query language, similar to SQL, but instead of operating on tables and columns, HQL works with persistent objects and their properties.
 HQL queries are translated by Hibernate into conventional SQL queries which in turns perform action on database.
Keywords like SELECT, FROM and WHERE etc. are not case sensitive but properties like table and column names are case sensitive in HQL

String hql = "SELECT E.firstName FROM Employee E";
Query query = session.createQuery(hql);

List results = query.list();

What is Hibernate ConfigurationFile?

Hibernate configuration file contains database specific configurations and used to initialise SessionFactory. We provide database credentials or JNDI resource information in the hibernate configuration xml file. Some other important parts of hibernate configuration file is Dialect information, so that hibernate knows the database type and mapping file or class details.

What is ORM?

ORM (Object Relational Mapping) is the fundamental concept of Hibernate framework which maps database tables with Java Objects and then provides various API’s to perform different types of operations on the data tables.

What the benefits are of hibernate over JDBC?

. Hibernate can be used seamlessly with any type of database as its database independent while in case of JDBC, developer has to write database specific queries.
. Using hibernate, developer doesn’t need to be an expert of writing complex queries as HQL simplifies query writing process while in case of JDBC, its job of developer to write and tune queries.
. In case of hibernate, there is no need to create connection pools as hibernate does all connection handling automatically while in case of JDBC, connection pools need to be created.

What is Hibernate and its advantages?

Hibernate is an Object-Relational Mapping (ORM) solution for JAVA and it is open source persistent framework. Hibernate maps Java classes to db tables and Java data types to SQL data types.
The framework helps to map plain java object to relational database table using xml configuration file.
Advantages
·Provides simple APIs for storing and retrieving Java objects directly to and from the database.
·If there is change in Database or in any table then the only need to change XML file properties.
·Hibernate does not require an application server to operate.
·Provides simple querying of data.
.Perform basic CURD operations.
.Dirty checking, lazy association fetching.

Monday, 12 February 2018

How many ways to create a New File in java?

There are three ways to create New File.
1. using java.io.File class
2. using java.io.FileOutputStream class
3. using java.nio.file.Files class

Sunday, 11 February 2018

What is difference between Executor.submit() and Executer.execute() method ?

There is a difference when looking at exception handling. If your tasks throws an exception and if it was submitted with execute this exception will go to the uncaught exception handler (when you don't have provided one explicitly, the default one will just print the stack trace to System.err). If you submitted the task with submit any thrown exception, checked exception or not, is then part of the task's return status. For a task that was submitted with submit and that terminates with an exception, the Future.get will re-throw this exception, wrapped in an ExecutionException.

Wednesday, 31 January 2018

What is method overloading and method overriding?


Method Overloading : -In Method Overloading, Methods of the same class shares the same name but each method must have different number of parameters or parameters having different types and order.
-Method Overloading is to “add” or “extend” more to method’s behavior.
-It is a compile time polymorphism.
-The methods must have different signature.
-It may or may not need inheritance in Method Overloading
Method Overriding: -In Method Overriding, sub class have the same method with same name and exactly the same number and type of parameters and same return type as a super class.
-Method Overriding is to “Change” existing behavior of method.
-It is a run time polymorphism.
-The methods must have same signature.
-It always requires inheritance in Method Overriding.

What is the difference between ‘ == ’ and ‘equals()?

“==” or equality operator in Java is a binary operator provided by Java programming language and used to compare primitives and objects. public boolean equals(Object o) is the method provided by the Object class. The default implementation uses == operator to compare two objects. For example: method can be overridden like String class. equals() method is used to compare the values of two objects.

Equals() method is defined in Object class in Java and used for checking equality of two objects defined by business logic.

What is the difference between java.util.Date and java.sql.Date in Java?

Both are known as Date class, but there is some difference between java.util.Date and jaca.sql.Date, for example, Former is used whenever a Date is required in Java application while later is used to read and store DATE SQL type from the database.

Another significant difference is java.util.Date stores both date and time values, while java.sql.date only stores date information, without any time apart. According to the Javadoc specification, java.sql.date is a thin wrapper around a millisecond value that lets JDBC distinguish as an SQL DATE value.

 The meaning of SQL DATE, the millisecond values bound by a java.sql.Date instance must be ‘normalised’. However, setting the hours, minutes, seconds, and milliseconds to zero in the specific time zone with which the case is connected.