Interfaces in Java
Runtime Polymorphism in Java
Abstract Classes in Java : Runtime polymorphism
The interfaces have played a key role in making the architecture of Java robust and uniform. The interfaces are used in many places in Java. They are extensively used in JDBC architecture, Collections framework, Multi-threading etc., We will see in detail how interfaces have become crucial for Java to become robust and maintain the uniformity.
Interfaces used in JDBC:
Interfaces are so well used in architecture of JDBC by Java. I should say Java has got most of the flexibility mainly from interfaces and abstract classes. In fact, what Java has done is defined all the method-names in the interfaces. It did not give any implementation for any of the methods. So, what the DBMS has to do is just use these method-names and build implementation according to the DBMS implementation. In case of migration from one DBMS to other DBMS literally, only the database driver URL, username, password for connection have to be changed.
Now consider a situation without interfaces in Java. In such cases, each DBMS will have its own set of method-implementations and method-names for specific functionalities in Java. Eventually, the method-names for database processing such as executing SQL stored procedures will differ from one DBMS to other DBMS. Now if we want to just change the DBMS we need to change the entire database processing code instead of just changing the driver URL, username and password.
Interfaces used in Multi-Threading:
Similarly interfaces are critical in view of the multi-threading. We know that a thread can be created by two methods.
1. Extending Thread class.
2. Implementing Runnable interface.
Now the first method can impair you in one way. If you extend Thread class, there is no way that you can extend another class since multiple inheritance is not allowed in Java. Now the second option is always good since we can create a class that implements any number of interfaces.
Interfaces used in Collections framework:
Another place where Java has made use of the interfaces is the Collections framework. The Collection framework is the most basic interface. It contains methods to add, remove, search and iterate over list. These are most general functionalities provided. The List, Set and Queue interfaces extend the Collections interface. These interfaces have their specific functionalities in addition to those provided by the Collection interface.
Related Posts:
Interfaces in Java
Runtime Polymorphism in Java
Abstract Classes in Java : Runtime polymorphism
Java Database Connectivity with MS Access -- Part 1
Java Database Connectivity with MS Access -- Part 2
Java Database Connectivity with MS Access -- Part 3