I always have the question: How the interface find its implementation ? In the calling code we always declare object with the interface name, Never need to declare the implementation class. We never explicitly tell the compiler which implementation to use.

The answer is , compiler don't know which implementation to use. When you declare a interface , there is no instance created, you have to new something and assign that instance to the interface. And the instance can be anything that implement the interface.

NodeList nodeList = new DeepNodeListImpl();
// do something with nodeList
return nodeList;

So, you have to explicitly choose an implementation. If you are using sort of Framework, you may never choose the implementation because the Framework will do this for you. All the things you need to know is the interface specification, and can know nothing about the implementation at all.

This may cause confusion in some cases, because you don't know implement details of the instance you are using. If something goes wrong you can not get any clue from the interface specification.