What tech stack was I working with in May 2003?

Clearing out some stuff in the home office I came across this CD-ROM of tech tools, products and libraries that I was using at work at this time:

  • JBoss – the open source Java EE app server of choice at this time
  • Xerces – Java XML Parsing library (DOM)
  • Amazon WS Kit – not sure what this was, maybe an SDK for AWS?
  • Apache – HTTP web server
  • Caucho Resin – no longer around – if I remember right this was an optimized Servlet runtime
  • EJ Tech Profiler – I think this was a competitor to JProfiler?
  • Homesite – HTML editor
  • IBM WS Kit – SDK for Java XML webservices
  • IntelliJ – still around today. At the time I don’t think it was as popular as Eclipse or Netbeans, but is probably the best. Java IDE around today

Interesting look back at Java versions in use at the time:

  • Java JDK 1.4 (at the time, also called Java 2 after JDK version 1.2, abbreviated as J2SE)
  • Java EE 1.2 and 1.3 – abbreviated to J2EE – the days when J2EE was actually called J2EE before dropping the 2 and just becoming Java EE after Java EE 5 was released in 2006)

Don’t use floats and doubles in Java to represent Money values (or anything where you need exact values)

Float and double types in Java are approximations – they don’t represent exact values. This is by design to allow faster calculations of approximate values at the cost of exact accuracy.

If you are new to Java, at some point you will run into this, or you’ll come across someone else you work with who may tell you to never use floats and doubles to represent Money, but maybe you’re not sure why. The reason is because of how floats and doubles represent approximate values.

If you’ve never come across this before, try this experiment:

float result = 0.01f + 0.01f + 0.01f;

You would expect this calculation to represent 0.03, but if you compare the value of result with 0.03f you’ll find this snippet of code unexpectedly prints false:

if(result == 0.03f){
    System.out.println("true");
}
else{
    System.out.println("false");
}

To represent accurate floating point values use BigDecimal. Alternatively, money values can be represented as an integer value in cents or pennies (for example) to avoid the approximation issues.

tldr; Don’t use floats and doubles to represent money values in Java.

Java local variable vs class field initialization and default values

This is a common error when starting out with Java:

DefaultValues.java:5: error: variable example might not have been initialized
        System.out.println(example);

In Java, Class instance properties are initialized to default values if not explicitly defined with an initial value. For local variables however (e.g. variables local within method or a block scope), default values are not automatically assigned, meaning that you must explicitly initialize them otherwise you’ll see the compile error above.

This is described in the Java tutorial here.

Maven vs Gradle equivalent commands

I’ve seen Gradle becoming more popular in recent years, but it wasn’t too long ago that Maven was the tool for managing dependencies and building/packaging apps.

From my own experience with both, here’s the commonly used equivalent commands:

MavenGradle
mvn compileNo equivalent as gradle build compiles and packages?
mvn packagegradle build
mvn install (see note below)gradle build
mvn testgradle test

There is no direct equivalent to ‘mvn install’ in gradle, but if you depend on a local Maven repo, there is a Gradle plugin to publish packaged artifacts to a Maven repo – see here.