Java SDK 1.5 Beta 1

February 13th, 2004

Well, time to comment on my own pet peeves that have been fixed in the new JDK, I guess. They seem to be bundled in this page.

The InetAddress class now provides an API to allow testing for the reachability of a host. This features provides a ping-like capability in Java. Great. I (unlike most Java developers, so it seems) find myself always behind a firewall, which makes me connect through a proxy. I had written a tiny class (for own use) that set the proxy for me. Only one thing I had to remember: every time I switched locations, I had to switch the selected proxy. No more.

public static void setDefaultLocation() throws UnknownHostException, IOException, ProxyException {
    List locations = new ArrayList();
    locations.add(ALOCATION);
    locations.add(ANOTHERLOCATION);
    boolean set = false;

    for(Location location:locations) {
        InetAddress host = InetAddress.getByName(location.getHost());
        if (host.isReachable(3000)) {
            setProxy(location);
            set = true;
        }
    }
    if (!set) {
        throw new ProxyException("Could not find a reachable proxy.");
    }
}
(Some details left out). Also notice the use of the generics and the "foreach" loop. They came quite naturally when I was writing this code. Nice job.

BTW, it seems that I could do an even better job using ProxySelector, but I didn't figure out how to use this yet.

On to the next one. Did I ever tell you the reason I fell in love with Java? It was because you could connect with the web from within code so easily! Write a program that does stuff humans do (surfing the web, that is) -- who wouldn't want to do this? Well, now we will be able to do this using FTP too, or so it seems from the sentence The specification of the URL class now mandates a minimum set of URL protocol handlers that are guaranteed to be present in J2SE. They are http, https, file, jar and ftp. I still have to figure out the ins and outs, but it looks promising.

Something I also didn't know yet: Doug Lea's concurrency package has made it into the core.

There are also some new packages popping up: java.lang.annotation, java.lang.instrument, java.lang.management , and javax.management.* are intriguing to me. Yet to be investigated, though.

On a side note, if you're an Eclipse user and want to play around with these new toys, check out the SDK 1.5 plugin.

Update: I forgot to mention this one: The networking API now provides a way of setting timeouts on connect and read operations for protocol handlers. This will benefit any HTTP client application that must behave robustly in the event of server failure. I know at least one guy who has been crawling the internet, just to find a library that could overcome this shortcoming in the previous JDKs.

Update: The link to the plugin is referring to the installation manual. However, that has the wrong link for the actual plugin (an old version). So you're better of downloading it here.

3 Responses to “Java SDK 1.5 Beta 1”

  1. F.Baube Says:
    The ping() functionality sounds way handy for one thing in particular: don't we all have stale bookmarks up the wazoo? How 'bout a utility to load your bookmarks and then try to ping all the hosts and then try to load the particular URLs. And let it save its work and retry all the bogosities after a day or two, because hosts can be down for a short while. Then it goes back to your Moz/Firecritter bookmark file and marks those URL's that just ain't there no more... ready for a manual retry and then deletion.
  2. KissaBoo Says:
    Quick Hits As a stop gap until we move to a better technique, here are some Quick Hits: Links that need to be put somewhere, but won't get a full entry at this time. Upcoming.org Could be a very useful site or the basis for a hacker, stalker movie. Neighborhood R...
  3. KissaBoo Says:
    Quick Hits As a stop gap until we move to a better technique, here are some Quick Hits: Links that need to be put somewhere, but won't get a full entry at this time. Upcoming.org Could be a very useful site or the basis for a hacker, stalker movie. Neighborhood R...

Leave a Reply