PriorityQueue Example in java

PriorityQueue(Since Java 1.5) : It is an unbounded priority queue based on priority heap. The elements of the priority queue are ordered according to the constructor which you use. PriorityQueue pq = new PriorityQueue() It creates empty priority queue with default initial capacity 11. Priority order is natural sorting order. PriorityQueue pq = new PriorityQueue(int […]

TreeSet in java

TreeSet(Since Java 1.2) Underlying data structure is balanced tree. Duplicates are not allowed. Insertion order is not preserved since objects will be inserted based on some sorting technique. Null insertion is not possible in a non-empty TreeSet. We will get NullPointerException if we add. Heterogeneous objects are not allowed.  We will get ClassCastException if we […]

HashSet and LinkedHashSet

HashSet (Since Java 1.2):  HashSet is achild interface of Set.  Underlying data structure is HashTable.(Internally it’s a HashMap. See HashTable code)  Insertion order is not preserved.  Duplicates are not allowed.  Allows null element ( only one 🙂 since set will not allow duplicates).  Default initial capacity is 16.  Default load factor is 0.75f.  Threshold = […]

ArrayList,LinkedList,Vector and Stack

ArrayList (Since Java 1.2): Grow able Array implementation of List interface. Insertion order is preserved. Duplicate elements are allowed. Multiple null elements of insertion are allowed. Default initial capacity of an ArrayList is 10. The capacity grows with the below formula, once ArrayList reaches its max capacity. newSize/newCapacity= (oldCapacity * 3)/2 + 1

Output: […]


Program to Marshall and Unmarshall list of object.





Prototype Design pattern

Prototype design pattern comes under creational design pattern. This pattern is very easy to understand. Prototype design pattern provides duplication of an existing object. This can be achieved with Object class clone method. Object creation with new operator is time consuming and costly in an Enterprise projects. So instead of creating object with new operator […]

Stored procedure Cursor example using JDBC CallableStatement API

Program to call database stored procedure using JDBC’s java.sql.CallableStatement API and get OUT Parameter as CURSOR. Stored Procedure in Oracle database:

Java class:


 In Database: