Skip to main content
Advertisement

Networking Overview

Networking refers to the procedure of interconnecting two or more computers or distinct devices via physical cables or wireless communication mechanisms to construct a functional network capable of actively exchanging data. By utilizing Java's robust java.net package, developers can effortlessly construct complex network applications entirely without requiring profound hardware networking architectural knowledge.

1. IP Addresses

An IP Address is fundamentally a completely unique numerical identification formally assigned to every individual computer (Host) to distinctly identify it on a network.

  • IPv4: A standard 4-byte address typically formatted like 192.168.0.1 (Currently experiencing global depletion).
  • IPv6: The next-generation, massively expanded 16-byte address format.

Locally in Java, we utilize the InetAddress class exclusively to interact with IP addresses.

import java.net.InetAddress;
import java.net.UnknownHostException;

public class NetworkEx {
public static void main(String[] args) {
try {
// Ascertaining an IP Address reliably through a domain name
InetAddress ip = InetAddress.getByName("www.google.com");
System.out.println("Host Name: " + ip.getHostName());
System.out.println("IP Address: " + ip.getHostAddress());

// Handling situations where multiple dynamic IP Addresses exist (e.g., Local Load Balancing)
InetAddress[] ipArr = InetAddress.getAllByName("www.naver.com");
for(InetAddress i : ipArr) {
System.out.println("NAVER IP: " + i.getHostAddress());
}
} catch (UnknownHostException e) {
e.printStackTrace();
}
}
}

2. Port Numbers

If an IP address operates exactly like a physical building's street address, the Port acts identically to a specific 'room number' or 'designated entrance' inside that building. Within a single computer (IP), numerous independent programs—like a Web Server, Mail Server, or Game Server—can run completely concurrently. A Port Number (ranging continuously from 0 to 65535) is rigorously applied to accurately identify precisely which program the incoming network data must be routed to.

Well-known Ports

Ports ranging tightly from 0 up to 1023 are universally designated system service ports established by international protocol. Uniquely, when developing personal generic applications, developers avoid these and typically utilize ports higher than 1024 (For example, 8080).

  • 80: HTTP (Unencrypted Web Data Communication)
  • 443: HTTPS (Secured & Encrypted Web Communication)
  • 21: FTP (Dedicated File Transfer)
  • 22: SSH (Secure Remote Shell Access)

3. Categories of Network Communication

Network communication protocols are broadly structurally divided into two primary categories, aggressively dependent on the exact required reliability vs. speed paradigm of data exchange.

  • TCP (Transmission Control Protocol): Strictly connection-oriented, meticulously ensuring the successful delivery and precise ordering of all data. Conventionally used essentially for Web communication and crucial File transfers, prioritizing flawless reliability.
  • UDP (User Datagram Protocol): Inherently connectionless, relentlessly transmitting data without ever structurally verifying delivery success or sequential ordering. Noticeably utilized primarily for raw speed, extensively in live Video Streaming and hardcore Online Gaming where realtime performance completely outweighs perfect reliability.
Advertisement