bigdecimal precision and scale

we might see two way of setting round in BigDecimail: // 1. BigDecimal r1 = new BigDecimal(“35.3456”).round(new MathContext(4, RoundingMode.HALF_UP)); // 2. BigDecimal r2 = new BigDecimal(“35.3456”).setScale(4, RoundingMode.HALF_UP); r1 is 35.35 r2 is 35.3456 Well, at first glance it seems that r1 differs from r2 in only one thing: the r1 is using RoundingMode through MathContext object,…

MY unix commands

tail a file tail -100f FileName -f to allow file monitoring less command Another way is to watch file using less +F FileName to wait for new data. use ctrl+c to exit to the normal less mode to do search/page uptown etc. once down, we can hit F again to the watch mode. less only opens chunk of file so…

yoeman, bower and grunt

This article aims at introducing you to some of the currently most popular tools when developing modern web applications with JavaScript. These are totally not new at all and have been around for a couple of years now. Still, I found many devs still don’t use or know about them (as you might), wherefore this…

Difference between java.util.Date and java.sql.Date and java.sql.Timestamp in Java

Difference between java.util.Date and java.sql.Date in Java or why does Java has java.sql.Date if there is already a Date class in java util package is a common java interview question. There is always confusion among many Java developer familiar with both java.util.Date and java.sql.Date. Though many of them already using java.sql.Date to interface with DATE…

spring data jpa

you extend repository/jpaRepository/CrudRepository/PagingRepository…etc. it generates sql based on method name so you do not need to write sql/jpql. it provides paging, query criteria…etc. reference, here and here

jpa performance over jdbc for large table

I have a table with about 80 million records. While I was doing a simple query using JPA with 2-3 predicates. It takes about 120s to get the result, comparing the 1s using JDBC. Notice, i am using exactly the same query that the jpa generates. This is somehow frustrating. To be honest, I have…

500 error when migrating the joomla site between servers

Steps: 1. download the all the files from the original server. 2. export the db using to a sql file. 3. upload the files to the new server. 4. create mysql db and new db user in the new server.import the exported sql to the newly created db. 5. edit the configuration.php. modify the user/dbname/password to…

javascript callback with browser dom

prototype is the function template when new is called so that it could be assign to the object’s __proto__. very good video explaining event loop/callback and browswer. Some summary: Typical type of event: User event, XHR event, Timer event. the whole picture is callstack+eventloop+web api. call stack is where the code runs eventloop is where…

understanding and using jsonp

JSONP is really a simple trick to overcome the XMLHttpRequest same domain policy. (As you know one cannot send AJAX (XMLHttpRequest) request to a different domain.) So – instead of using XMLHttpRequest we have to use script HTML tags, the ones you usually use to load js files, in order for js to get data…

add InterpretedFunction to the java scriptEngine using eval

RhinoScriptEngine This is the typical engine we use for js evaluation. http://grepcode.com/file/repository.grepcode.com/java/root/jdk/openjdk/6-b14/com/sun/script/javascript/RhinoScriptEngine.java without ScriptContext When you get back the reference to a function, you need to ask the engine to execute that function for you. And although not pretty, asking js to eval() it for you with a specific set of bindings will actually do the…