Equals and HashCode and Hibernate

In one of my current consulting projects the topic of implementing equals and hashCode in Hibernate domain model classes was discussed again so I decided to write down how I deal with that in my projects.

First I encourage every Java developer to read chapter 3 of Effective Java from Joshua Bloch - which is available online here (the whole book is great but chapter 3 deals with methods common to all objects). Basically chapter 3 says you have to obey the contracts when overriding equals (item 7) and to always override hashCode when overriding equals (item 8). These contracts are also documented in the Java API doc.

Read more →

Problems connecting with jconsole to linux jvm

Lately I had problems configuring the JMX remote management for tomcat servers running on Ubuntu linux servers. After configuring everything necessary like the com.sun.management.jmxremote JVM parameters and the password files I still got connection errors when trying to connect from my Windows system to the server via jconsole.

I found this bug entry for the Sun Java VM with some interesting suggestions. In my case the problem was a wrong configuration of the /etc/hosts file. The command hostname -i always resolved to the loopback device 127.0.0.1 - after adapting the /etc/hosts file so that hostname -i resolved the real IP address I was able to connect my jconsole.

Read more →

Error code 1920 when installing VMware converter

I am just preparing our Windows 2003 Small Business Server to be upgraded to Small Business Server 2008. Therefor I tried to install the VMware converter tools to convert the old server to a virtual machine before upgrading it.

My problem was that the installer always complained about not being able to start the converter service with the following message:

VMware vCenter Converter Standalone — Error 1920
Service VMware vCenter Converter Server (vmware-converter-server) failed to start. Verify that you have sufficient privileges to start system services.`

After doing some web research with finding a lot of useless tips I found this blog post showing up a very easy solution: I had to add a group called “Domain Admins” because it did not exist on the German version of our Small Business Server. This is why I always try to install the original English version of operating systems when available and our new Small Business Server 2008 will be in English.

Read more →

Default Rounding Mode in Java

Lately I was a bit surprised when I found out that the default rounding mode in Java is something called “half even”. This API docs page provides good information about rounding in Java. For HAVE_EVEN it says:

Rounding mode to round towards the “nearest neighbor” unless both neighbors are equidistant, in which case, round towards the even neighbor. Behaves as for RoundingMode.HALF_UP if the digit to the left of the discarded fraction is odd; behaves as for RoundingMode.HALF_DOWN if it’s even. Note that this is the rounding mode that statistically minimizes cumulative error when applied repeatedly over a sequence of calculations. It is sometimes known as “Banker’s rounding,” and is chiefly used in the USA. This rounding mode is analogous to the rounding policy used for float and double arithmetic in Java.

Read more →

Eclipse building workspace hangs

Today I encountered the problem that every time I started one of my Eclipse workspaces it always started to build the workplace and could not finish it. The progress monitor showed additional tasks waiting but I could not stop them. After killing the Java VM process several times and starting up again I searched for a solution and found this page.

I already heard about the clean command line argument and after adding it to the command line it resolved my problem. I will not add this permanently to my Eclipse links because it takes significantly longer to start up but I did a good job to fix the workspace.

Read more →

The size of java.util.Calendar

A friend of mine asked me why his Java batch job reading a 23MB text file took over 300MB Memory. He read some text and date values and stored them in String an Calendar objects. A short web search brought up this blog post of Jason Rennie writing about the size of java.util.Calendar. He points out that a single instance of java.util.Calendar takes 432 bytes of memory. This was the explanation – 500000 calendar objects need 206MB memory! This was new to me …

Read more →

Internationalization and JavaScript

Lately the amount of JavaScript in web applications has grown a lot. JavaScript has always been there but with the need of AJAX and more and more dynamical features modern web developers can not avoid it.

Luckily there are a lot of good concepts arising and libraries available (e.g. prototype, yui, …) that show how to control the JavaScript monster. Something that always bothered me was that I was not able to find a good editor for JavaScript. Since about six months I am using JSEclipse from Adobe which is a free Eclipse plugin that provides a lot support for writing JavaScript (code-completion, syntac check, …).

Read more →

There Ain’t No Such Thing as Plain Text

Jeff Atwood posted a link to a site that sells T-shirts and stickers with the following image:

unicode

I am thinking of ordering some of them. Handling encodings is a very important part of programming and from my experience a lot of developers do not care enough about it. I encourage every developer to read “The Absolute Minimum Every Software Developer Absolutely, Positively Must Know About Unicode and Character Sets (No Excuses!)” from Joel Spolsky. It describes the evolution of encodings in a very easy way.

Read more →

Fixing memory leaks of Internet Explorer 6

Lately we experienced a lot of performance problems in our AJAX applications. Since we went online a year ago we always had problems with users of Internet Explorer 6 but within the last three months they got more and more.

We already knew that this had something to do with the huge memory amount the Internet Explorer 6 uses after some hours of working with our application. I used the Process Explorer to analyze which page causes the problem. After identifying the page I did some reloads of it and generated the following image:

Read more →

@Override specification changes in Java 6

Between Java 5 and Java 6 changes to the specification of @Override have been made. In Java 6 it is possible to add the @Override annotation to methods that implement methods of an interface which is not allowed in Java 5.

I noticed the difference when a friend told me that he had to remove all the @Override annotations to make his Java 6 project compile with Java 5.

The interesting thing is that there is no documentation about this change. The API specification of @Override is exactly the same in both Java versions. I found out that this was forgotten by Sun developers. Peter, a former developer at Sun, calls it the @Override Snafu.

Read more →