-
Small programming tips
A quickpost inspired by issues I encountered recently. How to concatenate (aggregate) strings with PostgreSQL? In MySQL you can write: SELECT concat(name) FROM test_table Because concat also works as an aggregate function (like MIN, MAX, SUM, COUNT, etc). To get the equivalent result in PostgreSQL, you can use the following query (based on ideas from…
-
Repetitive testcases with jUnit
Update: after listening to a recent episode of Java Posse, I found out about parameterized tests for JUnit which seems to be a better option than the method described below. Live and learn. Let’s say you have a lot of similar cases in a jUnit test. You might be tempted to write a loop to…
-
Random Java blogging
From the JUnit FAQ: Each test runs in its own test fixture to isolate tests from the changes made by other tests. That is, tests don’t share the state of objects in the test fixture. Because the tests are isolated, they can be run in any order. Very important to keep in mind if you…
-
Watch out for long running tasks with Java Timer
The problem? Write a code which will execute every N seconds. The solution? Using a Timer with scheduleAtFixedRate. Now you got two problems :-), unless you’ve carefully read the documentation which states (emphasis added): If an execution is delayed for any reason (such as garbage collection or other background activity), two or more executions will…
-
Java numerical calculation benchmark
Update: it seems that the JITting process has improved quite a bit these last years (which is to be expected), and the differences are much smaller (and in some cases in favor of Java). Also, the discussion below is to be understood in the context of trigonometric functions rather than floating point operations in general.…
-
Privacy risks of signed Java applets
Probably it is an occupational hazard, but when I’ve listened to episode #222 of the Java Posse (1/3 of the devil :-D) and they talked about a java applet do do screencasts, my first reaction was: is it possible to do this from an applet? isn’t this a privacy risk? The answer is: it depends…
-
Negative zero – what is it?
Computers have two ways of representing numbers: One is called sign and magnitude – usually you have one bit specifying the sign (again, most of time you have 0 for positive and 1 for negative) and the rest of the bits specify the absolute value (“magnitude”) of the number. The other is ordering the numbers…
-
If you have problems using SVN with Eclipse…
make sure that you’ve installed the JavaHL Adapter. Otherwise you will get messages saying: Unable to load default SVN Client JavaHL seems to be the actual bingding to the Subversion, so it is really a mystery to me why it isn’t marked as a dependency for subeclipse… Related blogposts which pointed me in the right…
-
Curious Eclipse (Java?) bug…
It seems that watchpoints are not triggered if the field is changed using reflection. A simple test program to demonstrate this: import java.lang.reflect.*; public class ReflectMe { public static int foo = 1; //*1 public void test() throws Exception { foo = 2; //*2 Class c = Class.forName(“ReflectMe”); Field f = c.getField(“foo”); f.setInt(this, 10); //*3…
-
The big java regex shoutout
I discovered recently that the built-in java regex library has problems with some expressions, so I set out to find alternatives. Searching for regex benchmarks, I found the following page: Java Regular expression library benchmarks (it also has an older version). The original IBM article also contains a benchmark. However both of these resources are…