TreeSet Vs HashSet

Treeset and hashset both belong to set and obey the rule of maintaining uinique elements . But treeset comes with some more added advantage. TreeSet gives ability to sort elements with the help of the compareTo(). More examples on http://www.shivapreals.tech/allpost/java-tutorial/java-collection-tutorial/ HashSet allows null elements. Treeset never allows null.   Hashset is faster as it is not dealing with sorting of elements. Treeset has sorting capability so it is somewhat slow.   To compare equality hashSet uses equals() while on…

Read More Read More

Java Mutithreading

Why we need multithreading in java I am going to explain in most simple easy way. Imagine google is giving you data in seconds literally 1000’s of links are fetched in less than a second.How this damn thing is possible.Let us take one example if you and your cousin is at home you are told to make the lunch at…

Read More Read More

Java8 forEach loop

Java8 forEach loop example

forEach Signature forEach(Consumer<? super T> action) Working :Performs the provided action for each element of the Iterable until all elements have been processed or the action throws an exception.Your code gives hint about what should be iterated.The internal implementation of forEach determines how to iterate it.This is delegation we don’t write the implementation we used…

Read More Read More

Persistence Life Cycle

There are in all four stages of Object in hibernate 1.Transient 2.Persistent 3.Removed 4.Detached 1.Transient Objects When an object is instantiated it’s not persistent immediately let’s suppose we are creating simple object if I am having in Employee class. We will create instance in this way, Employee emp= new employee(); When we create object it is in  transient state. Once…

Read More Read More