May 15 2013
Why Java passes objects as references passed by value
I came across a question recently on stackoverflow that was very enlightening and proves how objects are actually passed in java. It was quite an interesting discovery!
I am quoting from here
Java is always pass-by-value. The difficult thing can be to understand that Java passes objects as references passed by value.
It goes like this:
public void foo(Dog d) { d.name.equals("Max"); // true d = new Dog("Fifi"); d.name.equals("Fifi"); // true } Dog aDog = new Dog("Max"); foo(aDog); aDog.name.equals("Max"); // trueIn this example aDog.name will still be “Max”. “d” is not overwritten in the function as the object reference is passed by value.
Likewise:
public void foo(Dog d) { d.name.equals("Max"); // true d.setname("Fifi"); } Dog aDog = new Dog("Max"); foo(aDog); aDog.name.equals("Fifi"); // true

Sep 23 2013
Optimized Character Escaper for Java
I wanted to write my own character escaper for requests going to Apache Lucent.
After writing my own, I also received feedback from programmers-stackexchange which resulted in the fastest implementation, also posted here. (Thanks to MrSmit42)
Below is my application that tests 6 different slightly different implementations over 30,000,000 executions each and outputs the time in MS.
The results in MS (on my computer) were the following:
Method 1 (Boolean Array)-> 7574
Method 0 (Switch Stmt)-> 9778
Method 4 (Switch Stmt Ugly – BreakPoints after evert case)-> 12451
Method 6 (HashSet)-> 17273
Method 5 (EnumMap)-> 39516
Method 3 (Pattern/Regex)-> 98229
This proves that for production systems that have many requests, jumping directly on the RegEx bandwagon for even trivial problems is not always the solution.
Even a 0,5 MS reduction per request leads to 50MS saved over 100 requests (per second) and 500MS over 1000 requests.
[polldaddy poll=7418939]
By Menelaos Bakopoulos • Java SE, Programming, Scripts 0 • Tags: Escape Characters, Java SE