Posts

Popular Post

Learn - Abstract Class vs Interface in Java

Abstract Class vs Interface, Differences, when to use? Why not create an object? Interface Interface is used when you want to define a contract and you don't know anything about implementation. (here it is total abstraction as you don't know anything). Interface is used in a situation, 1. When you know the contract methods but don't know anything about the implementation. 2. Your contract implementation can change in future. 3. You want to achieve dynamic polymorphism and loose coupling that is by just changing one line of code, you should be able to switch between contract implementer. 4. Since multiple inheritance is not supported in Java, you cannot inherit your class from two abstract classes. An interface is your only option in such situations. 5. If there is no default or common behavior among all the classes that are inheriting from abstract class then interface may be a better choice. Example Analogy for point 1: Redbus interface lists out ...

Learn - Collection - List, Set & Map in Java

Image
                        Collection is an Interface in Java 1.        Single dimensional – List & Set Interfaces 2.        Multi-dimensional – Map Interface A Java collection framework provides an architecture to store and manipulate a group of objects. A Java collection framework includes the following: ·        Interfaces ·        Classes ·        Algorithm Interfaces: Interface in Java refers to the abstract data types. They allow Java collections to be manipulated independently from the details of their representation. Also, they form a hierarchy in object-oriented programming languages. Classes: Classes in Java are the implementation of the collection interface. It basically refers to the data structures that are used again and again. Algorit...