NET PACKAGE / NOTES</>↗Net Package08 Jan 2026
To implement a simple TCP client and server in Java, you use the ServerSocket class for the server and the Socket class for the client. Here is a straightforward example of both, where they exchange simple text messages. 1. The TCP Server The server listens on a specific port and waits for a client to […]
NET PACKAGE / NOTES</>↗Net Package08 Jan 2026
Actually, the standard java.net.URI class in the JDK does not have a built-in Builder API. It only provides constructors and the URI.create(String) factory method. To build URIs using a builder pattern in Java, you have three common options: 1. Using URI Constructors (Standard JDK) While not a “builder,” the multi-argument constructor is the safest way […]
HTTPCLIENT / NOTES</>↗HttpClient07 Jan 2026
To fetch JSON using the Java HTTP Client (java.net.http), you typically send a GET request and process the response body as a String. Since the standard library doesn’t include a JSON parser, you’ll receive the raw JSON string, which you can then parse using a library like Jackson or Gson. Here is a clean example […]
HTTPCLIENT / NOTES</>↗HttpClient07 Jan 2026
To use WebSockets with the Java native HttpClient (introduced in Java 11 and fully supported in Java 25), you use the WebSocket.Builder. The process involves three main steps: 1. Create an HttpClient (or use an existing one). 2. Implement a WebSocket.Listener to handle incoming messages and events. 3. Build and open the connection using HttpClient.newWebSocketBuilder(). […]
HTTPCLIENT / NOTES</>↗HttpClient06 Jan 2026
To use HttpClient with JSON parsing in Java, the most common approach is to combine the standard java.net.http.HttpClient with a JSON library like Jackson or Gson. While HttpClient doesn’t have a built-in JSON parser, you can map the response body string to a Java object. Using Jackson (Recommended) Jackson is a powerful and widely-used library […]
HTTPCLIENT / NOTES</>↗HttpClient06 Jan 2026
To send asynchronous HTTP requests in Java using the java.net.http.HttpClient, you use the sendAsync() method. This method returns a CompletableFuture<HttpResponse<T>>, allowing you to handle the response without blocking the main thread. Here is a step-by-step example of how to implement this: 1. Basic Asynchronous GET Request This example demonstrates how to fire a request and […]