HTTPCLIENT / CATATAN</>↗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 / CATATAN</>↗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 […]
IO / CATATAN</>↗IO05 Jan 2026
Using FileChannel.map() allows you to map a region of a file directly into memory. This creates a MappedByteBuffer, which acts like a bridge between your application’s memory and the file on disk. The operating system handles the actual reading and writing in the background, making it extremely efficient for large files. Here is how you […]
IO / CATATAN</>↗IO05 Jan 2026
To use ObjectOutputStream with a Java record, you need to make the record implement the java.io.Serializable interface. One of the great things about records is that they are designed to be “data carriers,” and Java’s serialization mechanism handles them more robustly and securely than regular classes. Specifically, records are serialized using only their components (the […]
IO / CATATAN</>↗IO04 Jan 2026
In a modern Java environment, “safely” means avoiding the pitfalls of standard Java Serialization, which is often vulnerable to gadget attacks and remote code execution. Here are the best practices for safe serialization and deserialization: 1. Prefer Data-Only Formats (JSON/XML) Instead of standard Java serialization, use JSON with a library like Jackson (already common in […]
IO / CATATAN</>↗IO04 Jan 2026
Using ByteBuffer to process binary files is a core part of Java NIO (New I/O). It provides a more efficient way to handle raw bytes compared to traditional stream-based I/O by allowing direct interaction with memory and OS-level optimizations. Here is a guide on how to effectively use ByteBuffer for binary file processing. 1. The […]