Showing posts with label Interview. Show all posts
Showing posts with label Interview. Show all posts

Tuesday, 22 October 2013

How can we make a Empty interface ?

we can make an empty interface that to call it and make that configuration to the Compiler to take care about how to deal with the class that implement that interface.


Monday, 26 August 2013

Java Web Services #Interview Questions and Answers ?

Q. What are the different application integration styles?

A. There are a number of different integration styles like

1. Shared database
2. batch file transfer
3. Invoking remote procedures (RPC)
4. Exchanging asynchronous messages over a message oriented middle-ware (MOM).

Saturday, 13 July 2013

Difference between Enumeration and Iterator ? #java #interview

both Iterator and Enumeration provides way to traverse or navigate through entire collection in java

Enumeration is older and its there from JDK1.0 while iterator was introduced later. 
Iterator can be used with Java arraylist,  java hashmap keyset  and with any other collection classes.


As far Enumeration is older than Iterator so that  functionality of Enumeration interface is duplicated by the Iterator interface.

Only major difference is Iterator has a remove() method while Enumeration doesn't. Enumeration acts as Read-only interface, because it has the methods only to traverse and fetch the objects, where as by using Iterator we can manipulate the objects like adding and removing the objects from collection e.g. Arraylist.


Friday, 12 July 2013

Difference between Set, List and Map in #Java #interview

Set (Interface)

  • Set is an un-ordered collection which doesn’t allows duplicate (no-duplicate) elements
  • We can iterate the values by calling iterator() method

Set s = new HashSet();
Iterator iter = s.iterator();

List (Interface)

  • List is an ordered collection which allows duplicate elements
  • We can iterate the values by calling iterator() method

List li = new ArrayList();
Iterator iter = li.iterator();


Map (Interface)

  • In Map we used to store the data in key and value pairs, we may have duplicate values but no duplicate keys
  • In Map we don’t have iterator() method, but we can get the keys by calling the method keySet()

Map m; // insert values
Set s = m.keySet();
// Get Map keys into the Set and then iterate this Set object normally
// m.keySet() returns Set object with Map keys
Iterator iter = s.iterator();

 When to use List, Set and Map in Java


  1. If you need to access elements frequently by using index, than List is a way to go. Its implementation e.g. ArrayList provides faster access if you know index.
  2. If you want to store elements and want them to maintain an order on which they are inserted into collection then go for List again, as List is an ordered collection and maintain insertion order.
  3. If you want to create collection of unique elements and don't want any duplicate than choose any Set implementation e.g.HashSet, LinkedHashSet or TreeSet. All Set implementation follow there general contract e.g. uniqueness but also add addition feature e.g. TreeSet is a SortedSet and elements stored on TreeSet can be sorted by using Comparator or Comparable in Java. LinkedHashSet also maintains insertion order.
  4. If you store data in form of key and value than Map is the way to go. You can choose from Hashtable, HashMap, TreeMap based upon your subsequent need. In order to choose between first two see difference between HashSet and HashMap in Java.

References

  •  http://java67.blogspot.com/2013/01/difference-between-set-list-and-map-in-java.html
  •  http://www.java4s.com/core-java/difference-between-java-set-list-and-map-collections/