FindBugs helps you fix your code

July 19, 2006

There is a good article at IBM Developer Works about using the FindBugs static code analysis tool. Test cases are important, but when you inherit code, a good static analysis code tool can really help you out. The article is a couple years old, but still quite relevant. I thought this comment summed it up nicely. From the article:

Much of the knowledge of how a class works (or is supposed to work) evaporates shortly after it is written, in the form of implicit assumptions, invariants, and expected use cases that are clear in the developer's head but never get written down in the form of design notes, comments, or documentation. Existing code is always harder to work with than new code.1

Even with strong test cases, you can still miss more complex bug patterns. FindBugs can help you out.




  1. [1] Java theory and practice: Kill bugs dead, http://www-128.ibm.com/developerworks/java/library/j-jtp06294.html, posted June 29, 2004, viewed July 20, 2006

Web services in Java 6

July 18, 2006

Eyal Lupu has a nice (short) primer on Web service support in Java 6. It's an easy read, and it really gets you excited about the possibilities of Web services. Since the concept of Web services was first mentioned, it seemed like an ideal way to foster code reuse and componentization (in the Web domain)—ideas that are core to Java development.

However, in the Java space, there has always been a fairly steep learning curve and/or a significant amount of code and configuration that went along with using Web services. But now, thanks to the power of annotations and Sun listening to the Java community, it is now quite simple.

Here is a before and after snippet. See if you can spot the difference:
Before

package ws;
public class CalcWS {
   public int add(int a, int b) {
     return a+b;
   }
   public float div (int a, int b) {
     return a/b;
   }
}
After (from the article)
package ws;
import javax.jws.WebService;
import javax.jws.soap.SOAPBinding;
@WebService
@SOAPBinding(style=SOAPBinding.Style.RPC)
public class CalcWS {
   public int add(int a, int b) {
     return a+b;
   }
   public float div (int a, int b) {
     return a/b;
   }
}

See the difference? Just 4 lines of code two imports and two annotations. Pretty cool! Now if we can just get Tor Norbye to abandon Creator and Project Semplice and focus on enabling the following annotation:
@TurnThisObjectIntoACoolWebAppLikeRailsDoes
That's not too much to ask, is it?

A crash course in Software Engineering

June 28, 2006

During one episode of the Java Posse, the gang mentioned a new podcast called Software Engineering Radio. I had subscribed to the feed (via iTunes), but had not really had chance to listen until a recent trip.

After listening to 10 episodes, I must say it's a wonderful show. It is very informative, with a pace that is not at all slow, but instead moves you along quite quickly. The basic gist of the show is that they cover high level software engineering topics, providing enough information to give you a conversational knowledge of the subject—and perhaps help you decide if it's a topic you want to delve into further. They provide a good balance between high level information and more concrete examples. And they also provide resources for further information.

As an example, in a recent episode about Remoting they give a guideline for when to use messaging vs. RPC style calls. Here is a short excerpt:

...use a messaging system in case you have an event drive application, when you have state machines driving the application logic, and use an RPC style communication when you have to integrate the result into your regular control flow. 1
It seems obvious. But for me it was a question that I had wondered about for some time—and they answered it quite concisely.

The show tries very hard to be language neutral and platform agnostic. It's a great show and I really recommend it to anyone who wants to dive deeper into software engineering.




  1. [1] Episode 9: Remoting Pt.1 and Listener Feedback, http://media.libsyn.com/media/seradio/seradio-episode9-remoting_pt1.mp3, posted March 20, 2006, comment ~ at 12 minutes, 35 seconds

New features coming to Java SE

May 19, 2006

Ed Burnette has a concise and tantalizing summary of Graham Hamilton's presentation during the Sun general Technical session at JavaOne (2006). You can see a Web cast of the presentation via Sun's site. Two really interesting things popped out for me.

First, it looks as if Java 7 will have some important language changes. For instance, there will (perhaps) be direct support for XML. If you have ever accessed an XML file using Java, you know that there are many lines of code required just to open the file—let alone pull out a value.

Second, Project Semplice. Project Semplice is an attempt to allow Visual Basic programmers to use their VB skill in Java. From the article:

The goal is to enable VB developers to use Java platform. It's not for porting existing applications, it just lets you use your VB skills. Compile from VB source into Java classfiles, make VB source code calls into Java platform APIs, etc. It's a new language for the Java latform. It will support standard VB.net concepts.
This is exciting because it removes a barrier to entry for many programmers. In my opinion, there have been two major barriers for VB programmers to get into Java. The first has been a lack of solid IDE. There are a lot of IDE's for Java and have been from some time, but if you were interested in trying Java the price of the IDE's was somewhat prohibitive. Eclipse and Netbeans solved this problem. Both are excellent IDE's and both are free. The second problem was the complexity of the Java APIs. Java itself is quite a simple language, but compared to using an ActiveX control in VB or calling a DLL, the Java API's can seem quite complex and confusing to a newbie. Once you get past the learning curve you have quite a bit of power at your finger tips, but the curve is steep. Allowing someone to dip there toes by using code they are used to will help to at least entice them to the platform.

In our shop, I watched my team make the transition from ASP to .Net. It was interesting because instead of sticking with Visual Basic (the core ASP language), our developers quickly switched to C#. A familiarity with the development environment and the Framework helped them get over the hurdle of learning a new language, and once they did, they never looked back.

I can't wait to try it out. It will be fun to dust off my old VB knowledge.

Using Oracle's IDE and JSF...

April 26, 2006
The folks at WEBLOG IT-eye have created an interesting screencast to demonstrate what it's like to create a Web service and use JSF in Oracle's IDE JDeveloper. If you are interested in how different IDEs work, or if you want to know what the draw is to Oracle, you will enjoy this screencast. Here it is.

Sun Java Studio Creator 2.0 released

January 31, 2006

The latest release of Creator, which is Sun's answer to rapid application development for the Web, has just been released. If you don't know, Creator's primary focus is creating apps using JSF—Java Server Faces1. Creator contains a neat data-binding model that allows you to bind JSF components to just about any data source. Based on NetBeans, Creator contains many easy to use and quality team tools, inspectors, and editors. You can find from information about the release here: (Web site)

I tried out the first release (I believe it was a pre-release) and wasn't enticed enough to devote time into figuring out how it worked. Actually, I tried to import some existing JSP projects, which it turns out wasn't the best approach. Firstly, the designer wasn't too kind to my CSS and secondly even though JSF is based on JSP, it's a completely different way of programming an app. I was thoroughly lost.

This time around, I started with a blank project, added an existing data source, and within a couple minutes I had created a Web page that contained an table bound to a table in the data source. All of this without writing one line of code! Of course, the page didn't respond to any user events or do anything particularly interesting, but it was much quicker than if I had set up a JSP page that did the same thing.

My goal is to spend some time this coming weekend exploring the tool in more depth and writing about my experience. I have not used JSF at all, and I think my background with JSP and Microsoft Visual Basic should provide an interesting reference point. For all it's short comings, Visual Basic was a fantastic tool for creating GUIs and I am anxious to see if Creator can provide that same GUI building experience with the power of Java and J2EE under the hood. I am going to try to stumble through without trying any of the tutorials or without reading the documentation.

I should mention that The Java Posse (Web site) is a fantastic podcast for anyone interested in Java. They have some great interviews, lots of good news, tons of practical experience, and they really get you psyched about using Java.

And check back next week if you are interested in learning about my experience!