Tags / interview questions
Can I use try-finally block (without catch)?
Yes, you can use the try-finally construction. As a use case, we can try to connect to a database and finally we will close the connection: This code looks a bit redundant. But in Java 7 we can use a try-with-resources block to handle our resources closing in a more convinient way... In Java 7 we can use a try-with…
Describing the Java Deque collection interface
A Deque is a double-ended-queue. It is a collection of elements that supports the insertion and removal of elements at both end points. It implements both Stack and Queue at the same time. This interface defines following methods: void addFirst(E e) void addLast(E e) boolean offerFirst(E e) boolean offerLast(E e) E…
Describing the Java List collection interface
List is an ordered collection that can contain duplicates. In addition to the Collection interface methods, the List interface includes the following: Positional access: manipulating the elements by their index in the list. This includes methods such as: get, set, add, addAll, remove. Search: methods indexOf and…
Describing the Java Map collection. Difference between other collections.
Map is a collection that stores key-value pairs. A map cannot contain duplicate keys. What is the main difference between Map and other collections? The main difference between Map and other collections is that it contains key and value. It doesn’t inherit from Collection interface. The Map interface includes methods…
Describing the Java Set collection interface
A Set is a Collection that cannot contain duplicates. The Set interface extends Collection interface but has no specific methods. It adds the restriction that duplicates are prohibited. This interface also adds a stronger contract on the behavior of the equals and the hashcode methods, allowing Set instances to be…
Java Collections hierarchy
(Self-explanatory image above)
Java exceptions handling order
Consider there is a method which can throw IOException and FileNotFoundException. Is there a difference in which order we catch these exceptions in a single try-catch block? Will this code work correctly? The answer is NO. If you handle IOException first, you will never reach FileNotFoundException handling block…