Java implementation with Priority Queue.