Computing @ 40's

Trying to overcome the obsolescence

Leave a comment

Java float and double primitive types are evil. Don’t use them.

Hi people!

I’m right back here again from holidays and after some weeks without publishing anything I want to resume the work with a short post talking about java primitive types float and double.  Today is an easy post for begginers. No web, no application servers, no JavaServer Faces. A simple lesson about Java SE.

Today I was talking with a colleague at work. He was showing me a Java class, and I noticed that he was using a Double class variable to store some floating point values that were coming from a database. A long time ago I had a bad experience with float and double types when doing a database migration that gave me some hours of headache. I pointed him that he should use BigDecimal instead of that evil things. Fortunately he followed my advice.

I will explain here why I hate float and double primitive types in Java. Why I think they shouldn’t exist. Follow this link and you will learn the reason of my obsession against these “poor innocent” types.

As always I will be very proud to have any comment, any word encouragement, any gift, any million of euros. Every kind of feedback will be greatefully wellcomed.

Cardedeu, September 30th, 2013