Featured Article

Asymmetric encryption by Java Cryptography

1. Overview In cryptography, there are two general categories of key based algorithms: Symmetric encryption algorithms: Symmetric algorithms use the same key for encryption and decryption such as the Data Encryption Standard (DES) and the Advanced Encryption Standard (AES) Asymmetric (or public key) encryption algorithms: Asymmetric algorithms use two separate keys for these two operations.… 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 »

JPA OneToOne Relationship

In JPA, two types of the @OneToOne relationships are bidirectional and unidirectional. In each type, we can use different mapping approaches: One-to-one association that maps a foreign key column. One-to-one association where both source and target share the same primary key values. One-to-one association from an embeddable class to another entity. 1. Bidirectional OneToOne association… Read More »

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 »

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 »

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 »