Book review: Effective Java, 2nd edition

Date July 13, 2008

The first edition of Effective Java by Joshua Bloch has quickly become one of the best rated and most popular Java books of all time. Now, the 2nd edition is out and I immediately bought it after it came out. I expected a very good Java book and was (of course!) not disappointed.
The 2nd edition has been completely updated and expanded. It also covers the features that were introduced with Java 5 like Annotations, Generics, Enums or new libraries introduced for threading with Java 5 and 6.
The book contains 78 items covering good programming style and how to use Java correctly and most efficiently. It does not cover topics like EJBs, Swing or XML. But all you learn in this book can be applied to all your Java work.

The book assumes at least a basic knowledge of the Java language. If you are completely new to Java, you might want to start with books like Core Java I and II to get you started with Java.

Joshua Bloch is an excellent writer you knows how to explain difficult topics for a broad readership.

This book is a MUST HAVE book for every Java programmer. In fact, I consider it the only must read book out there on Java. No matter how long you have been programming in Java and what your skill level is, this book should be on your book shelf.

Groovy: methodMissing and propertyMissing

Date July 9, 2008

Groovy, like Ruby, has a way to intercept method calls. This is done with overloading methodMissing.
That method gets called when you call a method that does not exist. The default would be to throw an exception.
But you can use that to get “dynamic” methods. This very interesting feature is used by several Groovy projects, for example in Grails.
Very similar to methodMissing is propertyMissing.

I like examples. So, instead of more theory, just have a look at the following code:


class Dict {

    def words = ['eagle' : 'Adler', 'woodpecker' : 'Specht']

    def methodMissing(String name, args) {
        getTranslation(name)
    }

    def propertyMissing(String name) {
        getTranslation(name)
    }

    private def getTranslation(String key) {
        String result = "unknown - unbekannt" // default
        if(words.containsKey(key)) {
            result = words[key]
        }
        result
    }

}

d = new Dict()
println ("German word for 'eagle': " + d.eagle() )
println ("German word for 'owl': " + d.owl() )

println ("German word for 'woodpecker': " + d.woodpecker )

The output of the programm is:

German word for ‘eagle’: Adler
German word for ‘owl’: unknown - unbekannt
German word for ‘woodpecker’: Specht

The first parameter to methodMissing is the name of the method and the second are it’s arguments. The latter is not used in our example. You can see that we just take the method name and see if a key with the name exists in our small dictionary. If that’s the case, than we return the value (here the German translation of the key). If the key is not found, we just return a default value. The same is done for propertyMissing.

As you can see when we call the eagle() and owl() methods, the German translation for “eagle” is returned, while “owl” is not known in our dictionary. Accessing the woodpecker property gives use the German word “Specht”.

This is just an example to demonstrate those two useful methods, not a useful implementation of a English-German dictionary.
So if you fail your next German or English test, don’t blame me!

VisualVM now part of JDK

Date July 9, 2008

VisualVM is a wonderful tool and should be part of the toolkit of any Java programmer.
With the latest version of Java, JDK 6 Update 7, VisualVM is now also part of the JDK distribution. If you are using an older version of Java, get it from it’s homepage.

VisualVM is build with the Netbeans RPC platform and a great example that sophisticated Swing GUIs can be build with Netbeans RPC.

Netbeans 6.5 with new features for SQL and databases

Date June 28, 2008

The next Netbeans realease will offer some interesting new features for database interaction like SQL Editor code completion (for which many have been waiting) or a SQL History.

For a more detailed explanation of the new features, click here:

http://davidvancouvering.blogspot.com/2008/06/new-db-features-coming-in-netbeans-65.html

JBoss AS 5: getting closer to final release

Date June 27, 2008

People have been waiting for new next version of JBoss Application Server for almost three years now. The new Version 5 will be close to a first release candidate now.
The new version promises improved performance and a much more flexible platform.

Together with new software like JBoss Messaging and more, JBoss probably will stay a major player in the application server market, even though it has recently seen more competition with the Spring Application Platform or Sun’s Open Source Glassfish app server.

Do you use Generics?

Date June 10, 2008

Since Generics have been introduced to the Java language, there has been a lot of discussion about them. Many say they are too complicated.
Some say, Generics are the biggest problem in Java.
Many developers probably use Generics when using libraries like the Collections framework that comes with Java. But much less use them when designing their own libraries.
According to a recent poll done by JavaHispano, more than 50% don’t use generics in there code. Less than 20% use them regularly.
(Using Generics only with libraries like the Collection framework didn’t count as using them in the poll).

Does this mean that Generics are too complicated?
What do you think?

Groovy as a first programming language? Not yet!

Date April 22, 2008

Groovy is one of the best things that happened in the Java world in the last years. It’s powerful, quite easy to use and just plain fun.

A couple of days ago, I met a guy in the train who saw me reading a Java book. He told me that he wanted to get into programming and asked me which programming language he should start with. I first wanted to suggest Groovy but then I recommended Java.
Why?
One simple reason. I don’t know any book for the absolute beginner (in English or German) that not only teaches Groovy but also the basics of programming. All Groovy books I know are written for someone with Java or at least some other programming experience.

Until there is such a book I thought he should start with Java. But I already told him about Groovy and gave him the advice that he should give it a closer look after he has mastered the basics of Java.

Maybe there will be such a book in the future. Then people could start right away with Groovy, although I think every Groovy programmer should also know Java.

MySQL abandoning the Linux market?

Date April 21, 2008

Appearently there has been some rumor about Mysql abandoning the Linux market and concentrating more on Solaris after the acquisition by Sun.
I am sure that won’t happen. Why? Because Sun is not stupid!
MySQL would never have become so big without Linux. I would always use Linux as the operating system for MySQL.
Sun wants to make profit.
Putting off the Linux community would be a big economic mistake by Sun. And that’s the very reason why they would never do that. I am sure MySQL will stay a powerful database solution for Linux in the future.

My favorite programming websites

Date April 20, 2008

There are tons of websites about programming and software development out there. Here is a list of my favorites. I try to visit them regularly to keep me up to date.

infoq.com
Many interesting articles about Java, .NET, Ruby, Agile practices and more

theserverside.com
Enterprise Java

Javalobby
Many interesting articles and news about Java

rubyinside.com
On of the best Ruby websites

groovyblogs.org
Collection of Groovy Blog entries

jdesktop.org
An interesting resource for Swing developers

artima.com
Many interesting articles and blogs about many programming languages and about software development

planetjdk.org
Interesting stuff about J2SE

planetnetbeans.org
Staying up to date with Netbeans

planeteclipse.org
Staying up to date with Eclipse

dzone.com
Many useful links every day

If you know more interesting websites, please leave a comment.

The end of my Scala adventures

Date April 19, 2008

Recently I’ve played a little with Scala. I really like the language but for now I will not continue playing with Scala. That has nothing to do with the language but is just a matter of time. What I really liked about Scala:

  • clean syntax
  • easy to understand once you master the basics
  • great concurrency features
  • reasonably good performane

In the future I will focus more on Groovy. Groovy is not better or worse than Scala. But it’s easier to learn for a Java developer than Scala and there is the great Grails framework. Also, the IDE support is IMHO better for Groovy than for Scala.

I am sure Scala has a great future, especially when it comes to concurrent programming. It’s definitely worth looking at it.