Corrections to Chapter 4 of Java Network Programming, The InetAddress Class

p. 59: Array brackets were missing from the return type of getAllByName(). It should read

public static InetAddress InetAddress.getByName(String hostname)
public static InetAddress[] InetAddress.getAllByName(String hostname)
public static InetAddress InetAddress.getLocalHost()
p. 65: In Example 4-7 "helios" should be "spacecadet". In other words

import java.net.*;

class macfaq {

  public static void main (String args[]) {

    try {
      InetAddress macfaq = InetAddress.getByName("www.macfaq.com ");
      InetAddress spacecadet = InetAddress.getByName("spacecadet.cnet.com");
      if (macfaq.equals(spacecadet)) {
        System.out.println
          ("www.macfaq.com is the same as spacecadet.cnet.com");
      }
      else {
        System.out.println
          ("www.macfaq.com is not the same as spacecadet.cnet.com");
      }
    }
    catch (UnknownHostException e) {
      System.out.println("Host lookup failed.");
    }

  }

}
Furthermore, since the book was written, www.macfaq.com has moved off of spacecadet.cnet.com onto a new host. Thus if you run this you won't get the results shown in the book.

p. 68, first paragraph: Change "polymorphic newInetAddressFactory() methods." to "... overloaded newInetAddressFactory() methods."

p. 68, Example 4-8: Change

  // Use a byte array like {199, 1, 32, 90} to build
  // an InetAddressObject   
to
  // Use a byte array like {(byte) 199, (byte) 1, (byte) 32, (byte) 90} 
  // to build an InetAddressObject   
p. 74: In the last paragraph "11:53 PM" should be "10:53 PM"

p. 75: The last item in the date brackets is the difference between Coordinated Universal Time (CUT, essentially Greenwich Mean Time) and the local time zone. For instance in "[01/Jan/1996:22:53:58 -0500]" the "-0500" says the logal time zone is five hours earlier than CUT.

p. 76, Ex. 4-11 around line 26: Change java.net.InetAddress.getByName(thisIP); to InetAddress.getByName(thisIP); The java.net prefix is not explicitly necessary, though it is not incorrect.

p. 77: Change "Finally the hostname, a space, and everything else on the line (theRest) is printed on System.out." to "Finally the hostname and everything else on the line (theRest) is printed on System.out."


[ Java Network Programming Corrections | Java Network Programming Home Page | Table of Contents | Examples | Order from Amazon ] ]

Copyright 1998, 1999 Elliotte Rusty Harold
elharo@metalab.unc.edu
Last Modified March 6, 1999