Course Notes‎ > ‎

Chapter 7 - Java Network Applications

Historically, network programming has been thought of as complex and difficult. It was necessary to understand the various network layers involved, along with the data packaging, network connection, data shipping and the handshaking involved. However, the concept of networking is not that difficult to understand - in fact, it is quite similar to the concept of file I/O, except that the file is some black box on another computer/device. The Java programming language has significant network supports and it is structured to hide the lower-level communication from the programmer.

Unless it is behind a firewall/router, each computer connected to the Internet has a unique address called an IP address. Each IP address is a 32-bit number, of the form xx.xx.xx.xx, where xx is an 8-bit number that represents a number between 0 and 255. An IP address can also be represented by a domain name form, such as "". Computers also have a loop-back IP address (, so that provided you have a TCP/IP stack installed on your computer you can develop network aware applications. The new IP address format is also available under Windows 2000+ (IP-6) that provides addresses of the form xxxx.xxxx.xxxx.xxxx i.e. 128-bit addressing. IPv4 supports 4.2 billion addresses, which is inadequate to even provide one address to each living person (although routed internal network sharing and reuse is possible). IPv6 supports 3.4x10^38 addresses, enough to provide every atom of every person alive on the earth 7 unique IP addresses (assuming 6.5 billion humans, each having 7x1027 atoms [12]).

A computer connected to the Internet, will often provide several services. For example, it could act as both a web server and an e-mail server. To allow multiple services, a port number is used, that provides a software abstraction, rather than a hardware address. Some common port for services are 80 (http), 20/21 (ftp data/control), 7 (echo), 22(SSH inc. sFTP), 23 (telnet), 25 (SMTP), etc...

There are several mechanisms that provide network services. There is UDP (User-Datagram Protocol) and TCP (Transfer-Control Protocol). We will use TCP for the majority of our applications, as we are guaranteed that the messages will arrive at their destination. UDP is less reliable and can often lose packets in transit, but is still useful for applications like broadcasting audio/video. Most protocols (such as HTTP, SMTP, SSH and FTP) are based on TCP.

[12] Source:

These notes are copyright Dr. Derek Molloy, School of Electronic Engineering, Dublin City University, Ireland 2013-present. Please contact him directly before reproducing any of the content in any way.