devxlogo

Java APIs

How to Use the Spring Example API

First, define a probe (an instance of the entity class): User user = new User();user.setName(“Ana”);user.setEmail(“[email protected]”); Next create a probe: Example userExample = Example.of(user); Next, define a repository that extends QueryByExampleExecutor

Trigger a GET Request via the JDK 11 HttpClient API

The JDK 11 HttpClient API is very flexible and intuitive. Here it is a sample of triggering a GET request and printing the response: HttpClient client = HttpClient.newHttpClient();HttpRequest request =

Get the Class-Level Annotation

Via Java Reflection API, we can obtain all the annotations of a class as follows: Class clazz = Foo.class;Annotation[] clazzAnnotations = clazz.getAnnotations();

How to Check Whether a Number Is Prime

Java has an API called BigInteger and it is easily able to identify if the number under consideration is a prime number or not. Code snippet: import java.math.BigInteger;public class ProbablePrime{

Does Your Timezone Support Daylight Saving Time?

You may want to know if your timezone supports Daylight Saving Time programmatically. This can be easily determined with the code below: Listing 1. Sample Code import java.util.TimeZone;public class DaylightSavingsTime{