There are several ways to select top N objects from A list in the order of multiple data members of an object. For example, you may select top 10 players (top scores) from a list ordered by the players' score_1, score_2 and then score_3. The Simplest Way But Ineffective The simplest way to pick the top N elements is to sort the whole list and get the top N elements. … [Read more...]
Database: CHAR and VARCHAR – What are the differences?
Most programmers may already know the main different between CHAR and VARCHAR - The first one supports fixed-length data and the second one supports variable-lengths of data. Some people may think, since VARCHAR can do what CHAR does, then why we still need CHAR in our database design. I even have heard one of the very experienced Oracle database administrator say "Nowadays … [Read more...]
Java: Format Integer Into Fixed Width String
Sometime, you may want to format an integer or a long value into a fixed width String. You need to display the value in fixed width especially in reports where you want to keep the numbers in aligned (e.g. 3456 as 0003456 and 1234 as 0001234). Other than that, you may also want to format the integer value for a better visibility. For example, to display integer value as a do … [Read more...]
Java: Loading Large Data into JTable or JList
In software programming (especially Graphical User Interface or GUI programming), many times, we need to load data from file or database into a table or list to be displayed to user on computer screen. Most of the time, the size of the data can be determined only during runtime. The data could be very small to a few rows of record and could be very large to a few millions rows … [Read more...]
Java: Least Recently Used (LRU) Cache
Least Recently Used or in short LRU is an performance optimizing algorithm. LRU algorithm is widely used in software programming as well as in hardware instructions (e.g. CPU). In many case, in programming, we may want to cache some data from physical disk, for example database and files, but we cannot load all the data into memory due to the memory limitation on the server o … [Read more...]