HTTPCLIENT / NOTES</>↗HttpClient16 May 2025
In Java 11, you can use the HttpRequest class (from the java.net.http package) to build HTTP requests, including adding query parameters to a URI. Here’s how you can build an HttpRequest with query parameters: Example package org.kodejava.net.http; import java.net.URI; import java.net.URISyntaxException; import java.net.http.HttpClient; import java.net.http.HttpRequest; import java.net.http.HttpResponse; import java.net.http.HttpHeaders; import java.net.URLEncoder; import jav...
HTTPCLIENT / NOTES</>↗HttpClient15 May 2025
Java 11 introduced a new HttpClient API (java.net.HttpClient) that simplifies making HTTP requests and handling responses. It provides a clean and concise way to perform synchronous and asynchronous HTTP operations, and it fully supports RESTful APIs. Here’s a step-by-step guide with examples for how to use the Java 11 HttpClient to call REST APIs. 1. […]
HTTPCLIENT / NOTES</>↗HttpClient15 May 2025
Java 11 introduced the HttpClient API to simplify and modernize HTTP communications. This API supports sending requests using different HTTP methods (GET, POST, PUT, DELETE, etc.). Below is an explanation and example of how to perform these operations. 1. Setup You will use the HttpClient and related classes from java.net.http package: HttpClient – To execute […]
CONCURRENCY / NOTES</>↗Concurrency14 May 2025
Writing custom synchronizers with AbstractQueuedSynchronizer (AQS) in Java involves creating classes that encapsulate synchronization logic, such as locks, semaphores, or barriers. AQS simplifies the development of concurrency tools by handling queueing and thread state management. Below are the key steps and guidelines to write custom synchronizers using AbstractQueuedSynchronizer: 1. Understand AQS Concepts state: AQS maintains […]
CONCURRENCY / NOTES</>↗Concurrency14 May 2025
Asynchronous pipelines can be implemented efficiently in Java using CompletableFuture. The ability of CompletableFuture to chain multiple steps through its functional programming model (e.g., thenApply, thenCompose, thenAccept, etc.) makes it a powerful tool for building non-blocking pipelines. Here’s a step-by-step guide to implement async pipelines using CompletableFuture chaining: 1. Basics of CompletableFuture CompletableFuture is a […]
CONCURRENCY / NOTES</>↗Concurrency13 May 2025
Using CompletableFuture in Java can be a powerful way to implement reactive-style concurrency. It provides a clean and functional way to perform asynchronous tasks, compose their results, and handle exceptions without blocking threads. Here’s an explanation with examples to guide you through its reactive-style usage: Key Features of CompletableFuture Asynchronous execution – Run tasks on […]