While working with the database we often need to delete data, sometimes to create more space, sometimes just remove all data to make table ready for next day's transaction or sometimes just selectively remove stale data. SQL provides a couple of handy commands to remove data e.g. truncate, delete and drop. The last one is bit different because instead of removing data it just deletes table. What is the difference between truncate and delete command in SQL or when to use truncate vs delete is one of the most frequently asked SQL interview question? Knowledge of this critical command is not only useful for interviews, but also while working with a big database with a large number of records, especially while writing SQL scripts for purging transaction databases. An Incorrect choice of SQL command can result is either very slow processor can even blow up the log segment; if too much data needs to be removed and log segment is not enough. That's why it's critical to know when to use truncate and delete command in SQL.
Enum was introduced in Java 5 and since then it's been very popular among Java developers and widely used in different Java applications. Since Enum in Java is much more versatile than Enum in C or C++, it also presents lots of interesting use cases, couple of them, we have seen in my article 10 ways to use Enum in Java. But, despite being so popular, many Java programmer are still not aware of functionality provided by Enum and subtle details of using Enum in Java code. I realized this fact, when couple of my readers asked me some of the questions e.g. Can Enum implement an interface in Java or Why we can not create Enum instances outside of Enum, stating that these has been asked to them in there Java Interviews. This motivates me to put together a list of frequently asked question in Java Enum, which not only helps to do well in Interviews, but also open new path for learning. As I had said before, lot of time a question in Interviews, makes you to take a topic more seriously than otherwise, which is not a bad thing, and given the power and facilities offered by Java Enum, I think it's high time to get master of it.
Decorator Pattern is one of the famous Gang of Four (GOF) structural design pattern, which provides an alternative way of extending an object's functionality. It's different than the traditional way of adding new functionality into an object using Inheritance, since it's based on Composition and provides additional functionality at the run time, as opposite to Inheritance, which adds new functionality at compile time. Decorator design pattern is introduced by famous Gang of Four design pattern book, almost 2 decades ago. It's a time-tested way of adding new functionalities into an object. In this Java design pattern tutorial, we will learn Decorator design pattern by using it in a Java example. This is the best way of learning design pattern, followed you try it yourself to apply in similar scenarios. Decorator pattern is one of the popular design patterns along with Factory method pattern and Singleton Pattern, and you can see it's usage even in JDK itself. Couple of classes from java.io package e.g. BufferedInputStream, LineNumberInputStream are good example of Decorator design pattern in Java.