Top 20 Hibernate Interview Questions for Java J2EE Programmers

Hibernate is one of the most popular persistent frameworks in Java world. Hibernate offers object to relational (ORM) solution which frees Java developers from writing tedious, hard to read and cluttered JDBC code converting SQL columns into Object properties. Apart from freeing Java developer from writing JDBC and database interaction code, Hibernate also offers the out-of-box solution on caching, proxying and lazy loading which drastically improves the performance of your Java Web application. Given it's important in Java Web application development field Hibernate has become of one of the  most sought after skill and goes hand in hand with Spring framework. That's why Hibernate interview questions are also very popular in Java interviews. Earlier I have shared some Spring MVC interview questions and due to popular demand, I am now sharing 20 odd Hibernate questions from various Java interviews.

How to implement singly linked list in Java using Generics

Linked list is a popular data structure for writing programs and lots of questions from linked list is asked in various data structures and algorithmic interviews. Though Java provides a sound implementation of Doubly linked list as java.util.LinkedList, all these interview questions require you to code linked list in Java. If you are not comfortable to make a linked list, it would be really difficult to solve questions like reversing a linked list or finding middle element of linked list. Java 5 brought another twist of this kind of questions, now interview expects you to write a type-safe implementation of linked list using Generics. This raise difficulty level as writing parameterized class is not easy in Java, and it requires a good understanding of Generics fundamental.

Difference between Thread.start() and Thread.run() method in Java?

If you remember, a Thread is started in Java by calling the start() method of java.lang.Thread class, but if you learn more you will find out that start() method internally calls the run() method of Runnable interface to execute the code specified in the run() method in the separate thread. Now the question comes, why can't you just call the run() method instead of calling the start() method because anyway start() is calling the run()? This is one of the tricky multi-threading question you will find on Java interviews. The trick here is that, when you directly call the run() method than the code inside run() method will not be executed on a new thread, instead it will be executed on the same thread. On the other hand, when you call the Thread.start() method, then the code inside run() method will be executed on a new thread, which is actually created by the start() method. This is one of the fundamental of threading in Java, which is often get overlooked by Java developers unless you have read book like Java Threads By Scott Oaks, which explains every key multi-threading concept and thread basics in good detail.