Socket communication in Java enables communication between two endpoints over a network. There are two main types of sockets: TCP sockets and UDP sockets. Let's explain both types with examples: TCP Socket Communication: 1. **Server Side**: - The server creates a `ServerSocket` object to listen for incoming connections on a specific port. - When a client connects, the server accepts the connection and creates a `Socket` object to communicate with the client. - The server reads from and writes to the socket's input and output streams to communicate with the client. import java.io.*; import java.net.*; public class TCPServer { public static void main(String[] args) throws IOException { ServerSocket serverSocket = new ServerSocket(12345); System.out.println("Server started. Waiting for client..."); Socket clientSocket = serverSocket.accept(); System.out.println("Client connected."); BufferedReader in = new Bu
File I/O Classes Reading 1. File Class: - Represents a file or directory path in the file system. - Provides methods for file manipulation and querying file attributes. File file = new File("example.txt"); if (file.exists()) { System.out.println("File exists!"); } else { System.out.println("File does not exist!"); } 2. FileInputStream: - Reads raw bytes from a file input stream. - Suitable for reading binary data from files. try (FileInputStream fis = new FileInputStream("example.txt")) { int byteRead; while ((byteRead = fis.read()) != -1) { System.out.print((char) byteRead); } } catch (IOException e) { e.printStackTrace(); } 3. BufferedReader: - Reads text from a character-input stream efficiently by buffering characters. try (BufferedReader br = new BufferedReader(new FileReader("example.txt"))) { String line; while (