Saturday, November 1, 2008

Printing from Java with CUPS 1.3+

I had a problem with printing from the Java application on my Fedora 9. The problem was quite strange and reproducible on both Java 1.5. and 1.6. It was even more strange because it appeared only after I've updated my Fedora to version 9.
It turned out that the problem was on the level where Java meets CUPS 1.3+. There is a corresponding Sun's bug. There is no such problem for CUPS version lover than 1.3. It looks like Java had made too many assumption how CUPS should work... and CUPS guys changed some things in 1.3.
As always Google came with help and the solution was found.

Friday, October 31, 2008

Java 1.4 on Fedora 9

Recently I needed to work on a legacy Swing project written on Java 1.4. So, I've installed 1.4 JDK on my Fedora 9 and... got a following error:
/usr/java/j2sdk1.4.2_16/jre/lib/i386/ cannot open shared object file: No such file or directory occurred
A little googling brought me to the Oracle forum post. The problem was that AWT requires the libXp package. After I've installed it the problem vanished :)

Friday, May 30, 2008

Java 1.6 on Mac... at last!

It is here. After 1.5 years. Java 1.6 on Mac. But... it is only for the Leopard and only for 64-bit Intel machines.
PPC, 32-bit Intel and Tiger folks are currently still out of the board.
There are two interesting facts regarding this Apple's release.
  1. It was not announced on Apple Developer Connection Java topics RSS. In fact that feed is useless. I'm still receiving here a bunches of 3 identical notifications about release notes for Java on Mac 10.5. The date when this document was published is 2007-10-31. Yeah, after 6 month Apple still reminds me (and the other subscribers of that feed) about such "news".
  2. Almost month passed since Java 1.6 on Mac release. And there is complete silence about this event on the Desktop community on This is rather strange - there was a lot of complains about long absence of this release (e.g. here and here).
Anyway, it's good it is here.

Wednesday, May 7, 2008

Running TestNG on NetBeans 6.0

TestNG is a great testing framework. And it's much more powerful than JUnit.
The problem for NetBeans 6.0 users is that there is no plugin for TestNG. I've spend a lot of time before I managed to run TestNG in a simple way. After some time I've figured out that the main obstacle is that NetBeans does not recognizes TestNG classes as test classes. And this was the key to success.
I've successfully run the tests using its command line and NetBeans Run feature. And it was done on the NetBeans Java SE bundle (the simplest one).
So, here are the simple steps to launch TaestNG on NetBeans:
  1. Project Properties -> Libraries. Compile-time libraries must contain testng-XXX.jar (where XXX is your TestNG version). Also Run-time libraries must contain the path to your compiled tests (if you put your test to default test directory, than the path to compiled tests should be build/test/classes).
  2. Create TestNG xml file(s). There are instructions how to build such file in the framework site. E.g. create testng.xml and put it in the project root.
  3. Project Properties -> Run. Create new configuration. You may name is testNG ;) Enter org.testng.TestNG as the Main Class. Put your TestNG xml file(s) as Arguments. Multiple xml files should be separated by space. Enter your project directory as Working Directory.
Congratulations! Now you can run your TestNG tests through NetBeans Run feature.

P.S. Even if there will be only one person on Earth who saves a few hours this post worth its writing.

Monday, March 3, 2008

Regular method call vice call through reflection

A few weeks ago I had a pleasure to discuss some Java topics with three Java guys. Each of them has much more experience than I do. One of those topics was a performance of method call through reflection vice regular method call. Those three guys were confident that the difference in performance is not significant. And I argued that it is. Our discussion ended, but I was curious what is that difference.
So, here is the little test I wrote, sound like the famous song of Bobby McFerrin ;) :

import java.lang.reflect.Method;

public class ReflectionSpeedTest {

public static void main(String[] args) {
int times = 100000;
long simpleCallTime = simpleCall(times);
long reflectionCallTime = reflectionCall(times);

System.out.println("number of calls: " + times);
System.out.println("simple call time: " + simpleCallTime);
System.out.println("reflection call time: " + reflectionCallTime);

private static long simpleCall(int times) {
ReflectionSpeedTest worker = new ReflectionSpeedTest();

long time = System.currentTimeMillis();

for (int i = 0; i < times; i++) {

return System.currentTimeMillis() - time;

private static long reflectionCall(int times) {
try {
Class workerClass = Class.forName("ReflectionSpeedTest");
Object workerInstance = workerClass.newInstance();
Method method = workerClass.getMethod("doWork", null);

long time = System.currentTimeMillis();

for (int i = 0; i < times; i++) {
method.invoke(workerInstance, null);

return System.currentTimeMillis() - time;
} catch (Exception e) {
throw new RuntimeException(e);

public void doWork() {
int i = 5 * 6;

You can download this test from if you want try it by yourself. Regularly the whole java poem is needed to call a single method through reflection (you need the class, the method and often also the instance). This test does not tests that case. Only method call is measured.
On my machine running openSUSE 10.3 the reflection call was more than 10 times slower. For sure, this difference may be not so significant for heavy methods, but for light ones it is.

Monday, January 21, 2008

openSUSE 10.3 and microphone

Recently I've bought a microphone. While this device works fine without configuring on MS Windows, you need to apply some efforts to make it work on Linux.
On my current system (openSUSE 10.3) the sound recorder application KRecord did not recorded anything :) I've played with KMix for some time but I did not managed to record anything. Fortunately, I have more luck with Skype.
As it is correctly emphasized on some forums, the key option for making the microphone work fine on Linux is KMix > Switches > Mic Boost. It was disabled on my openSUSE by default. And if this option is disabled, your voice is almost not heard.
The bad thing is that this option is not saved. So, you have to enable it every time you boot your system.