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...]
JSP: How to Declare Methods and Inner Class in JSP
JSP itself is just a plaint text and will be translated into Java source file (actually a servlet), compiled into class file and only interpreted at the end during runtime. All these happen at the backend. When the whole JSP is translated into Java source file, all the HTML codes will be translated and source lines in <% %> tag will be included in a function of the t … [Read more...]
Java: Static Variables, Static Methods and Static Constructor
Java's static variables are variables or fields that are common to all object of a class. Unlike instance variables, objects of the same class have their own distinct copies of the variables and values. In other words, a static variable is shared among objects of the same class. You can declare static variables (or static fields or class variables) by adding static modifier to … [Read more...]
Java: Randomly sort values in a array (the generic way) in single pass
Few years back (yes, about 4 years back), I wrote an article about randomly sort query results in MySQL. The main problem in randomly sort query results is that when you have a very large data in your database and the statement to sort the result may change the data execution plan causing DMBS does not choose the right plan. Therefore, sometime it is more wise to sort it in … [Read more...]
Java: Format integer into number of decimal places and performance
For certain reasons (e.g. precision issue), some programmer may store a float value (e.g. money) in integer variable. For example -12345678.90 is stored as -1234567890. To convert the integer value to number with number of decimal places is a problem. There are several way to do it. You can simply use the Java's String.format(), DecimalFormat or Float.toString(). Most of … [Read more...]