Bridge pattern is useful for add a common property to a series of objects. Let's say we have a series of vehicles; like car and train. Different vehicles has different kind of wheels. It is easy to change wheels of vehicles after making wheel as a property of vehicles.
Lazy initialization pattern is similar to lazy initialization singleton. The key point of lazy initialization is "no need no create". The sample of code is like following.
Sometimes creating a new object is expensive, you need use "new" keyword and set properties. Prototype pattern is a good way to create the instance without "new" keyword. You can change the value of properties when needed after cloning object. Example code is like following.
Singleton make sure only one instance in your program. There are two kinds of singleton: initialization first, lazy initialization. The first one initializes class in the beginning. The second one initializes class when getInstance method is first invoked. The codes of them are like following.
There are two kinds of builder pattern on the internet. Both of them separate the construction of a complex object from its representation. In this page I will show you how to use them.
Factory method pattern is used to create different "product" when you overridden the create method in subclass. Your business logic code is handle the "product" which created by overridden method. The diagram of it is like following.
Abstract factory is one of the most popular design patterns. You can upgrade your program by adding concrete factory and without modifying the code. In this blog I will show you how it works. The diagram of it is like following.
There are two ways to sort multiple objects. Create a Comparator or make objects implement Comparable interface. In this blog I will show you how to sort multiple objects.
In last blog I have show you how to use thrift in java. You may found that you have to use command to generate class and move it into your package. Today I will show you how to use maven generate thrift class. It is easy and efficient.
Thrift is one of the most popular remote procedure call (RPC) frameworks. You can use it to build cross-platform system. In this page I will show you how to use it in Java.
Using StringBuilder or StringBuffer is more efficient then String when you need append some strings. There is a problem when use them in loop. We have to remove the last character when end the loop. Today I will show you how to remove last character when you use StringBuilder or StringBuffer.
In this page I will show you how to use BlockingQueue. Producer put products into BlockingQueue and consumer consumes the products one by one. The products in BlockingQueue will be consumed on a FIFO (first-in-first-out) basis. Sample code is like following.
In this blog I will show you how to use Future and Callable to get the result asynchronously. Write your logic code in call method of Callable then submit it and get Future. isDone method in Future class can help you to get the result of your task. get method of Future class will get the result of your task, this method will block the thread if the task doesn't finish. Sample code is like following.
It is easy to serialize object to byte array and deserialize byte array to object. Today I will show you how to serialize and deserialize object when it changed.
In this page I will show you how to use interceptor in Spring Boot. You can use interceptor handling common business logic. The structure of project is like following.