Sat, 08, Dec 2001 11:44:00 PM

by Charles Miller on December 8, 2001

Ignore this if you're not a nerd. I'm raving about the Java IDE I've been playing around with.

I'm using a new Java IDE called IntelliJ IDEA. It's really smart.

I was writing a new class. Amongst other things, here was the code I'd just written.

public class Connection implements Runnable {
    private final String hostName;
    private final int port;
    private Socket socket;
    private BufferedReader in;
    private BufferedOutputStream out;
    private List listeners = new LinkedList();
    private boolean open = false;

    public Connection(String hostName, int port) {
        this.hostName = hostName;
        this.port = port;

    public void addConnectionListener(ConnectionListener listener) {
        if (!listeners.contains(listener))

    public void removeConnectionListener(IRCConnectionListener listener) {

    public void fireLineReceived(String line) {

At this point, I wanted to iterate over the listeners collection, and send the line received to each one. So I typed itco<tab> (short for "ITerate over COllection), and IDEA was smart enough to write the following, except for the word "HERE", which I've put in to show you where the cursor ended up.

        for (Iterator iterator = listeners.iterator(); iterator.hasNext();) {
            ConnectionListener listener = (ConnectionListener);

I didn't have to prompt it or anything. It worked out everything it needed to make the loop from the context. That's so cool. It found the most recent collection I'd been working with, wrote out the iterator loop for it, and it worked out what kind of objects I was putting inside the collection so it could write the annoying cast-stuff that Java forces on you. There's a whole bunch of these little shortcuts built in, and they really make a difference.

This is why I like a good IDE. This sort of thing can really file off the rough edges of a language and let you concentrate on writing the code that really does stuff. Gosling can take his "do everything in a text editor" and shove it sideways where it hurts. (yeah, I know you could program emacs to do the same thing, but it'd be way too much effort and I don't know lisp)

Previously: Fri, 07, Dec 2001 07:28:00 AM

Next: Three Kinds of Projects