Joined-tables strategy for mapping inheritance with JPA

1. Joined-tables strategy Follow up the Single-table strategy for mapping inheritance with JPA, this strategy stores all financial products in a single table. In contrast, the joined table strategy creates separate tables for each entity in the domain model. This means that the financial product is the parent table and it holds common data for… Read More »

Single-table strategy for mapping inheritance with JPA

1. Stock Market Example Get started on our real market example with investors who want to buy or sell shares on the marketplace of which they are participants. Actually, stockbrokers (brokers) will do trading on behalf of their clients. But, there are different financial products: shares, loan, option, bond, hibrid, future, and so on. So… Read More »

Factory Pattern

Factory Pattern is to create object through a common interface/ abstract class. It belongs to Creational Pattern group. 1. Real-life example Suppose that we have two different types of instruments in capital market – one with an Equities and another with a Dept. A company want to use an instrument to raise capital, and represents… Read More »

Remove duplicated elements from a collection

1. Using LinkedHashSet from a given list Remove duplicated elements by using LinkedHashSet because it contains unique element and in the same order as the List Output in console: 2. Lambda Stream on arbitrary key Output in console:

Combinations in lexicographic order

Combinations of size k Prints out all C(n, k) = n! / (k! * (n-k)!) combinations of size k in increasing lexicographic order. For example: From a given String “abcde” when n = 5 and k = 3 you should get the following output: abc abd abe acd ace ade bcd bce bde cde Solution:… Read More »

Heap’s algorithm for Permutations

Problem: Find the biggest number from the array [3, 1, 2] (n = 3). For example: 321 is largest number in comparison with all possible numbers from the array. Solving: We need to resolve 2 things. Final all possible Permutations from the array. So possible permutation is n! = 3! = 6 cases. Find a maximum number from… Read More »

Quick Sort Algorithm

Quick sort discovered by C.A.R Hoare in 1962. It is a fast algorithm for internal or in-memory sorting except for sorting data in disk files. Figure 1: Time and Space complexity of quick sort. There are three basic steps: Partition the array or sub-array into left (smaller keys) and right (larger keys) groups. Call ourselves to sort… Read More »

Know Big-O complexities

This note covers the space and time Big-O complexities of common algorithms used in Computer Science: Figure 1: Data structure and Sorting Algorithms (Source:

What happens after you type a URL into a browser

In order to answer the question, we should go through Web, HTTP, and DSN concept in application layer. Webpage Web page includes objects which simply can be HTML file, an image, a Java applet, a video file,…- that is addressed by a single URL. Most Web pages consists of a base HTML file and several… Read More »

Exception Handling Tips

Please refer to Basic Exception Handling before reading some exception questions below. Question 1.  Consider the following program: Which one of the following options correctly describes the behavior of this program? a) The program prints the following: InvalidKeyException. b) The program prints the following: RuntimeException. c) The program prints the following: IllegalArgumentException. d) The program prints… Read More »