Posts

Showing posts from July, 2015

Tutorial - Hibernate criteria query example

In our previous post we have seen an example of second level cache. Second level cache in hibernate is very popular and you should know about How to configured second level cache in hibernate , here is a complete step by step example of second level cache. In this post, I am going to show you few examples of Criteria query in hibernate. We all know that Query is one of the core interface in hibernate and here I will show you how to use Criteria query. The org.hibernate.Criteria is an interface and used to fetch the records from the database based on some conditions. Session is a factory for Criteria and can be obtained from the session, To use Criteria you need criterion instances and criterion instances can be obtained from the org.hibernate.criterion.Restrictions, Restrictions is a class having built in static factory method. OK, Lets see few examples of Criteria Query, In this post we are using the same project which we were created in our one-to-many association example ...

Java program to find second largest number in an array

Image
Java programing interview question to check your logic like how to print repeated numbers in an array here and how to balanced your parentheses . In my previous post, I have shared small list of java 7 features with practical example here and in this post going to show you simple program to find the second largest number in an array using two different approach one is traditional way and another one is using one of the collection api. ArrayUtils .java package com.javamakeuse.poc; import java.util.Set; import java.util.TreeSet; public class ArrayUtils { // without using collection framework public static int getSecondLargestNum(int[] numbers) { int largestNum = numbers[0]; int secondLargest = numbers[0]; for (int i = 0; i < numbers.length; i++) { if (numbers[i] > largestNum) { secondLargest = largestNum; largestNum = numbers[i]; } else if (numbers[i] > secondLargest) { secondLargest = numbers[i]; } } return secondLargest; } // usin...