Category: java

  • How to implement Bridge pattern in Java?

    Let’s say you are a technical manager. You have several projects under you. You have designed them already to use different client and server technologies. Client technologies include Angular , VueJS and React. Server technologies include Java, DotNet and NodeJS. You are combining these two categories in different combinations and using each combination for a…

  • How to implement Adapter pattern in Java?

    Let’s say you love nuts. You buy them every now and then from a vendor named Raghav. You buy it online through a java program which calls Raghav’s shop API. Let’s say you have created a Shop interface to represent Raghav’s shop and created a class RaghavShop implementing it. And you have declared a method…

  • How to implement Singleton pattern in Java?

    In most interviews when candidates are asked about design patterns , the first answer that pops up is Singleton pattern! This pattern has been beaten to pulp ever since design patterns became mainstream. Still people can go wrong in effectively implementing it. This post looks into this pattern in detail. Singleton , as the name…

  • How to implement Prototype pattern in Java?

    Lets say you run a modelling agency. You are creating an application to manage your models. They are of different types – actors, male and female , can do anchoring , can play the role of video jockey , can act in cinema etc. To design classes for the above use case , you could…

  • How to implement Factory Method pattern in Java?

    Lets say you want to sell headphones. You create an application to handle your sales. You create a generic HeadPhoneShop class which can handle creating(buying from the manufacturer) the head phones and sell them. But you don’t want it to do the actual creation. You want to delegate it a shop which deals with creating…

  • How to implement Builder pattern in Java

    Let’s prepare Vanjaram Fish Curry , a complex object in Java. Let’s use Builder Pattern right out of the books of the Gang of Four. In fact I bought this book recently and used the recipe given by them. Let’s start with the client code . This I believe gives a better perspective to decode…

  • What are the new features in Java 14 that a day to day Java developer should know?

    There are about 16 changes introduced in Java 14. Not all of them need to be known for a day to day java programmer to improve his programming. Here are the 5 features which every Java developer should know which will save his time and improve code quality: Text Blocks If you want to define…