Thursday, December 07, 2006


The project that I am currently working on had the need for unique identifiers. This can easily be accomplished using a sequence from a database or by creating a centralized ID generation server. However, we had the need for many clients to create a globally unique identifier without requesting information over the network. We ending up utilizing the java.util.UUID which is a class that was added into Java 5.0. java.util.UUID creates version 4 UUIDs from the ISO/IEC 11578:1996 spec. It can also parse versions 1-3. There is a very informative mini-faq on java.util.UUID here.

Friday, October 20, 2006

New NetBeans 6.0 Editor

Looks like NetBeans 6.0 will be getting a new java editor. Check out some of the features here. NetBeans is a fast moving train, and I believe it will eventually replace my eclipse usage.

Wednesday, June 28, 2006

That Dang URLConnection Class Bit Me Again

Over the past couple days, I've been reinventing RPC mechanisms by making use of passing serialized java object to and from servlets. I ran into some complexities that I had forgotten existed when trying to use the URLConnection class. In short the trick is to not call URLConnection.getInputStream() until you are finished writing to the URLConnection's output stream. The JavaWorld article Dodge the traps hiding in the URLConnection class helped me again. Here is some example code for posting a serialized object to a servlet and retrieving an object response from the servlet: -------------------------------------------------------------------

public class Client {

    public static void main(String[] args) throws Exception {
        URL url = new URL("http://localhost:8080/myContext/myServlet");

        URLConnection servletConnection = url.openConnection();

        // inform the connection that we will send output and accept input

        // Don't use a cached version of URL connection.

        // Specify the content type that we will send binary data
        servletConnection.setRequestProperty("Content-Type", "application/x-java-serialized-object");

        // get input and output streams on servlet
        ObjectOutputStream os = new ObjectOutputStream(servletConnection.getOutputStream());

        // send your data to the servlet
        String s = "Some object I am sending to the server";

        ObjectInputStream is = new ObjectInputStream(servletConnection.getInputStream());

        Object o = is.readObject();

        String returnedValue = (String) o;


import javax.servlet.GenericServlet;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;

public class InsertFeature extends GenericServlet {

    public void service(ServletRequest request, ServletResponse response) throws ServletException, IOException {

        String contentType = "application/x-java-serialized-object";

        String value = "Thank You";

        try {

            // read an object
            ObjectInputStream is = new ObjectInputStream(request.getInputStream());

            String receivedString = (String) is.readObject();
        } catch (IOException ex) {
            value = "ERROR";
        } catch (ClassNotFoundException ex) {
            value = "ERROR";

        ObjectOutputStream oStream = new ObjectOutputStream(response.getOutputStream());


Tuesday, June 06, 2006

Java Concurrency Annotations

I'm in the process of reading Java Concurrency in Practice by Brian Goetz et al. So far this is a terrific book. It is extraordinarily well written and very informative. I'm intrigued by a set of annotations in the book (@ThreadSafe, @NotThreadSafe, @Immutable, and @GuardedBy). The book suggests these annotations are ideal for use by static analysis tools. I think this is a phenomenal idea and a highly effective use of annotations. I started looking to see if any of the tools I use have rules to utilize these annotations. I did find reference to the JCIP annotations on the FindBugs site, but nothing from PMD or CheckStyle yet. Anyhow downloads, documentation, and source of the JCIP annoations can be found here. Check them out if you need a way to document the intent of thread safety in your classes as well as be warned if the classes are modified in such a way that your original concurrency design is broken by maintenance.

Monday, June 05, 2006

Read What I Read

I currently use the google reader to aggregate rss/atom feeds from many of the sites and communities that I find interesting. I have just found a way to share the articles I find interesting. Old News: With Google Reader I can apply labels to articles. New News: I can make any of my labels public and share them with you. I have applied a javascript clip to my blog template allowing you to view the articles I mark as useful or interesting. You should be seeing a section titled "Interesting Articles" in the right area of this page.

Monday, May 22, 2006

Java 5.0 Performance Tuning

Here are some links I have been reading regarding java performance tuning. An application I am currently working on is about to hit stress testing, so I'd like to be prepared to help the QA and Operations groups pinpoint and mitigate some problems if they should occur. Some things have changed as of Java 5.0, so here are some links.

Java Specialists' Newsletter

I was discussing some java related things with a co-worker and realized that maybe not everyone is familiar with the "Java Specialists' Newsletter". Anyhow this is a newsletter created by Dr. Heinz Kabutz in South Africa. These newsletters are excellent reads on somewhat advanced java topics. Everyone in the java field should subscribe.

Effective Java -- Reloaded

Probably my favorite java book of all time is Effective Java by Joshua Bloch. As many people know this is a priceless book. I was excited to hear a second edition of this book is in the works. The second edition will be taking a bit longer to produce than I had originally hoped, but you can see a few peeks at some of the new stuff that will be contained in the book, from Mr. Bloch's JavaOne 2006 Presentation Slides.