Network Programming in Java
By Bruce Eckel
Historically, network programming has been error-prone, difficult, and complex because the programmer had to know many details about the network and sometimes even the hardware. However, the concept of networking is not so very difficult: You want to move information from one machine to another. It's quite similar to reading and writing files, except that the file exists on a remote machine that determines what to do about the information you're requesting or sending.
One of Java's great strengths is painless networking. As much as possible, the underlying details of networking have been abstracted away and taken care of within the Java Virtual Machine (JVM) and local-machine installation of Java. The programming model is the file; in fact, you wrap the network connection ("socket") with InputStream and OutputStream objects, so you end up using exactly the same method calls you would with files. In addition, Java's built-in multithreading is exceptionally handy when dealing with multiple simultaneous connections.
Identifying a Machine
To differentiate between machines and ensure you are connected with the proper one, there must be a way of uniquely identifying machines on a network. Early networks provided unique names for machines within the local network, but because Java works within the Internet, a machine must be uniquely identified from all others in the world. This is accomplished with the Internet Protocol (IP) address, which is a 32-bit number that is unique across the Internet.