HTTPCLIENT / CATATAN</>↗HttpClient09 Jan 2026
In modern Java, using JSON libraries like Jackson or Gson is the standard way to handle data exchange, as the Java Standard Library does not include a built-in JSON parser. With Java 25, you can take advantage of Records for clean data models and Text Blocks for readable JSON strings in your code. 1. Using […]
NET PACKAGE / CATATAN</>↗Net Package09 Jan 2026
To resolve a hostname to an IP address (or vice versa) in Java, you use the java.net.InetAddress class. This class provides static factory methods to perform DNS lookups. Here are the most common ways to use it: 1. Resolve a Hostname to an IP Address Use InetAddress.getByName(String host) to get the primary IP address associated […]
NET PACKAGE / CATATAN</>↗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 / CATATAN</>↗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 / CATATAN</>↗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 / CATATAN</>↗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(). […]