Oct 1 2007

Migrating to Java 6

I work with a large code base consisting of over 4,000 classes, with a custom ORM persistence layer, layout managers, Rapid Application Development (RAD) User Interface (UI) builder. The code is written in Java 1.4.2 but we have been considering a move to Java 5 or even up to Java 6. We currently have been debating the need, real or imagined, to migrate to Java 5. As developers, we just want to play with something new and shinny but there are business consideration that come into play.

As an exercise I migrated our code to Java 5 and then up to Java 6 and ran into few compilation and runtime errors. Upgrading to Java 5 revealed compilation errors with XPathAPI. To fix the XPathAPI error I just needed to add xalan as a dependency or import com.sun.org.apache.xpath.internal.XPathAPI. I also had a compilation error because it seems that compareTo(Object) had been removed form BigDecimal and BigInteger. As you know, Java 5 introduced enum as a keyword and wouldn’t you know I got a ton of warnings about this but this can easily be refactored.

Our system had a few runtime problems when moving to Java 5. We have some objects serialized to disk and changing the version of Java throws an InvalidClassException when reading in these objects. I also encountered some runtime exceptions thrown because of FileLock/FileChannel where none was throw before in Java 1.4.2. The errors where thrown because we had a programming error, we tried to release a file lock after the FileOutputStream for that lock had been closed.

Moving up to Java 6 I encountered a ton of compilation errors because new abstract methods have been introduced into JDBC classes such as Connection, Wrapper, and ResultSet.

Technorati Tags: , , ,


Sep 30 2007

Top Technology Podcasts

In no particular order here is the list of of technology related podcasts that I frequently listen to.

  • Cranky Geeks – Not cranky enough, but John C. Dvorak and guest rant on latest technology news.
  • Diggnation – A weekly tech/web culture show based on the top stories on Digg.
  • Drunk and Retired – They are not as drunk as one would hope, but they do tend to go off on Rails, software development, and zombies.
  • Google Developer Podcast – Googlers talking about the latest Google APIs.
  • The Java Posse – The seminal Java podcast put out by Google, Sun, and Apple engineers, just hope they never have to pronounce your name.
  • .Net Rocks! – A weekly talk show for anyone interested in programming on the Microsoft .NET platform.
  • Railscasts – Free, and most importantly frequent, Ruby on Rails screencasts ranging from 5 to 10 minutes covering testing, migrations, controllers, and more.
  • WebDevRadio – This podcast covers web development news with the occasional interview with engineers working on projects with .NET, MySQL, PHP, etc.
  • Polymorphic Podcast – Insight into software development in the .NET platform along with interviews with industry luminaries.
  • Code Sermon – The podast somewhat preaches to the choir. This is a somewhat semi-weekly sermon on the virtues of software development best practices.
  • Killer Innovation – A podcast about creativity, innovation, and idea generation. This podcast will present ideas to think outside the box, or IDE.
  • Grails Podcast – Keeps you up to date about the latest Grails developments.
  • NetBeans Podcast – Hosted by Roman Strobl of Sun, this podcast has the occasional interview with NetBeans developers like Tor Norbye and Geertjan Wielenga.
  • Ask A Ninja – Every programmer needs a break between hacking sessions.
  • Rails Podcast – News and interviews about the Ruby language and the Rails framework.
  • Entrepreneurial Thought Leaders – This podcast is put out by the Stanford business school. It usually has business leader share their experience.
  • Floss Weekly – Free/Libre Open Source Software might be free, but it is not timely.
  • Late Night Cocoa Podcast – Usually has hacking cocoa and API discussions and Cocoa practitioners, currently on summer hiatus.
  • TWiT – Leo Laporte and gang talk technology, unless they are reminiscing about their TechTV days or how to monetize ‘netcasts’.
  • Scoble Show – Robert Scoble talks with geeks, technologists, and developers.
  • GigaOm Show – Om Malik and Joyce Kim talk with entrepreneurs in the valley and run down some of the latest tech news.

If you feel I missed any other developer noteworthy podcast please let me know in the comments.

Technorati Tags: , , , , , , , , , , , ,


Sep 27 2007

YourKit Java Profiler 7.0 Review

Like most developers, I like free software and open source software both for it’s freedom and it’s price. But once in a while there are some software you can’t avoid but to pay for. I was involved in a project recently where I had to profile some Java memory leak in a tight deadline. The code base for the project is compiled to Java 1.4 bytecode and the team uses Eclipse 3.1. I don’t know of any good profiler for Eclipse so without skipping a beat or thinking twice about it I downloaded a free 15-day trial version of YourKit Java Profiler.

It was just drop dead simple to manually enable YourKit to profile our JBoss 3.2.x based application even though we highly customized the start batch script. Once profiling is enabled, I was able to connect to our application from YourKit to have it start profiling, monitor, inspecting the leaky architecture in the application.

It took me just a few hours to get familiar with the YourKit screens and memory snapshots views. Within a day I was able to track down a ThreadLocal object that was keeping a HashMap instance that in turn collected a large hierarchy of objects in memory. Clearing the value of the ThreadLocal did the job.

YourKit Java Profiler 7.0

Again, I choose YourKit mostly because of the environment and JVM I was using. I do understand that NetBeans 5.5 has a nice profiler for Java, which I have not tried myself. I would have opted for that if I was already using NetBeans or if it was the first result when I googled ‘java profiler.’ Unfortunately I was not able to find what seemed like a good or reliable profiler for Eclipse. For this reason alone I recommended YouKit Java Profiler to my boss. Although to be completely honest, since YourKit worked so well for me I thought of just getting another trial version next time I am ever in a bind and need to profile a Java application.

Technorati Tags: , , , , , , , ,


Sep 21 2007

Windows Print Screen Key

Earlier this year I wrote about discovering the purpose of the F11 key on OS X. Today I rediscovered how to get a screen shot for a particular application window using the Print Screen key. If you hit the Print Screen you get a screen shot of the whole desktop. If you you hit Alt + Print Screen you get a nicely cropped screen shot of the current application window. Here are other favorite Windows key shortcuts. Hit Alt + Tab to see all icons for all opened applications. To change focus to a different application hit Tab again until the application of interest is highlighted while still holding down the Alt key. Hit Start + D to toggle between the cluttered/clean desktop. Hit Start + E to open a new Windows Explorer. Hit Alt + F4 to exit the current application. Ctrl + F4 usually closes the current application window (I have seen some applications that don’t observe this key combination). Knowing key shortcuts will make you a more productive developer.

Technorati Tags: , , , ,


Sep 21 2007

Java, Ruby, and even Python Sucks

There is a bit of a flame war unfolding between Javanistas and Rubyists. I could trace this most recent scuffle to an article posted on JavaLobby by Daniel Spiewak about a little Java library called ActiveObjects. The aritcle is promoting this Java-based but Rails inspired Object Relational Mapping library. ActiveObjects is a Java implementation of the Active Record pattern made famous by Ruby on Rails and it’s use of convention over configuration. In touting the benefits of ActiveObjects, Daniel complains and grossly exaggerates that in Hibernate “you have to write more XML than code!”

Gavin King, the founder of Hibernate, responded that XML was soo 1999 and now they overuse annotations. Gavin wrote, “Hibernate Annotations has been around since early 2005 and there is no longer any good reason for people to define mappings in XML.”

Out of the blue and into the blogosphere, Obie Fernandez responded to Gavin’s ‘FUDdly’ remarks with his top 10 rant why Java sucks ass! Basically Obie resorts to fighting FUD with FUD. Obie goes ballistic on compilers, IDEs, frameworks, libraries, High School Musical 2, and Java developers themselves. Obie rants that most Java Programmers are morons. From his writing, it is clear that Obie idol worships DHH as the fucking second coming of the fifth generation computer language era. Obie’s top ten reasons why Java sucks include that the language makes money for vendors. From his Ruby rage you think he hopes to make Java vendor money by writing Ruby books.
Continue reading


Jul 25 2007

Daylight Standard Time Fiasco with Java

One of the hardest things to get right in Java is to figure out which class to use when working with time and dates. You have a recipe for disaster when you mix Java dates with timezone information with energy policy and a tight schedule. The U.S. Energy Policy Act of 2005 changed the start and end dates used for the Daylight Saving Time (DST). This policy had the potential negative effect of breaking millions of desktop computers, similar to the Y2K bug.

Software updates and patches where provided by software vendors such as Microsoft and Sun with plenty of time to spare before the new DST went into effect. The Microsoft patch was available as one of the thousands of security updates that you need to run on a Windows computer every so often. The Microsoft DST update was simply an exe installer. All you had to do to install the Microsoft DST update was to run it and restart your computer. Sun provided a Timezone Updater tool to patch Java with the new timezone data. The Java Timezone Updater is a jar file that you need to run from the command prompt with a series of command options. You need to run the Java Timezone Updater for each and every JRE available on the client machine! A typical client machine will have four to five different versions of the JRE.

Earlier this year when I was writing documentation and instructions for our field engineers for the new timezone change, I knew that the Java Timezone Updater was difficult for end users, even IT professionals, to run correctly. As mentioned you needed to run the updater manually from the command prompt, for every machine, for every JRE on a given machine, and there is no validation or test to notify you of success.

Well, just last week, three months after the DST change took effect one of our clients site started reporting a bug where they select April 2007 but our date widget rolls back to March 2007. After some time of head scratching, code reviews, and debugging we still were not able to reproduce the problem. After some time, it dawned on me that this might be a DST problem and sure enough we were to reproduce the bug on an updated JRE. For some reason, not yet completely explained but most likely related to human error, a whole set of computers where not patched correctly with the Java Timezone Updater. This DST bug locked out our users at this site from key UI screens at a critical time in their work flow.

We had people at the client’s site try to update our client machines with the Timezone Updater, but the bug still keep popping up. We then thought of fixing this in code with some sort of conditional chunk of code but that is just trying to fix a bad bug caused by a bad policy decision with a bad software hack because of a bad JRE update. Since our desktop client runs on Java Web Start, we thought that the best solution was to have our Web Start client run only on a newer version of the JRE that already has the correct and current timezone data. This is not entirely the most accommodating solution for the end user because each client machine now needs to have the correct JRE installed or else our application will not start.

In the end, we went with that hack, to have our JNLP restrict the version of the JRE used on our application. But this is not the best solution, since you have to update every client machines, just the scenario that Web Start promised you would not have to do! The takeaway message from this experience is that dates in Java are hard.

Technorati Tags: , , , , , ,