Featured Article

Build Rest API sending SMS with Amazon SNS and Spring

1. Introduction. This note is to help us to build an API for pushing notifications and SMS to mobile devices using Amazon Simple Notification Service (SNS). Amazon provides the AWS SDK that enables simple and cost effective to send notifications/SMS message to 200+ countries. 2. AWS SNS and Maven configuration. 2.1 AWS SNS Access. –… Read More »

Featured Article

Common parallel stream pitfalls

One of the most powerful features of the Java 8 Streams provides an easier path to parallel programming. However, in some cases, parallel stream may make programs run slower in comparison with the serial stream, including for loop to iterate over a collection. I put some common mistakes when using the Java 8 parallel stream to warn… Read More »

Featured Article

Creating a URL Shortener with Spring RESTful Web Service, Liquibase, and Postgresql

In this note I will create a URL shortening service using Spring Restful, Spring Boot, Liquibase, and PostgreSQL database.  In a similar way of some shortening services, such as goo.gl, tinyurl.com, and bit.ly, purpose of the shortened URL may be more convenience for website and provide detailed information on clicks a link receives. 1. URL Shortener Service. The service will… Read More »

Featured Article

Paging and sorting with Spring Data JPA and Querydsl

1. Introduction. Retrieved data with paging and storing is a basic feature of any application. This can be handled by database side (page and sort in a stored procedure, or native SQL query), and Spring Data JPA via use QueryDSL or Specifications. The note will present how to implement QueryDSL with Optional in Java 8.… Read More »

Bits Manipulation in Java

1. Detect if two integers have opposite signs. 2. Determining if an integer is a power of 2. 3. Swap the values of a and b without using a temporary variable. 4. Check non-zero. References: Gayle Laakmann Mcdowell, “Bit Manipulation”, in Cracking the code interview, 6th Edition. Bit Twiddling Hacks, Accessed at https://graphics.stanford.edu/~seander/bithacks.html Bit Manipulation… Read More »

Maps in Java

Concrete maps in Java JDK 1.8 Below is the summary of differences between HashMap, LinkedHashMap, TreeMap, and Hashtable in Java: (Source: javarevisited.blogspot.com) If we need to get the key back in insertion order, then use LinkedHashMap. If we need to get the key back in their true/natural order, then use TreeMap. Otherwise, HashMap is best because it… Read More »

Merge two stored arrays with different sizes.

1. Question. You are given two sorted arrays, A and B, where A has a large enough buffer at the end to hold B. Write a method to merge B into A in sorted order. For example: int[] a = {2, 3, 4, 8, 10, 100, 0, 0, 0, 0}; int[] b = {1, 4,… Read More »

Binary search algorithm

1. Getting. In binary search algorithm, we find an element x in a sorted array by using the principle of divide and conquer. First, we compare x to the middle point of the array. If x is less than the middle point, then we search the left of array. Otherwise, we look for the right… Read More »

Singleton Pattern

1. Definition. Singleton Pattern makes sure that a class only have one instance and provide a global point of access to it. It also belongs to Creation Pattern Group. Singleton Pattern should be used where we only need one of: Thread pools, caches, dialog boxes, object that handle preferences and registry settings, objects used of… Read More »

Observer Pattern

Observer Pattern defines a one-to-many relationship between a set of objects. When the state of one object changes, all of its dependents are notified/updated automatically. It also belongs to Behavior pattern group. 1. A customized notification system. Several newspaper agencies like CNN, NYTime, BBC are subscribed to a feed of new tweets and may want… Read More »