Java

Explore More Methods in the java.lang.Math Package

The java.lang.Math¬†package is very powerful. Understand more methods in this package that are related to the Euler’s number named e. public class MathMethods{ public static void main(String args[]) { MathMethods

How to Trigger a Synchronous GET Request

For triggering a synchronous GET request we can rely on HTTP Client API as follows: HttpClient client = HttpClient.newHttpClient();HttpRequest request = HttpRequest.newBuilder() .uri(URI.create(“https://reqres.in/api/users/2”)) .build();HttpResponse response = client.send(request, BodyHandlers.ofString());

Simplifying Null Check in Java

To avoid null exceptions, we usually validate against null and emptiness as shown: if(object != null && !object.equals(“”)) {} We can simplify this as below: if(!””.equals(object)){}

Automation of Tasks

Automation of tasks is a good concept. Consider the example below in which you create a task and schedule it at your convenience to execute the needed actions. There are

Get the Abstract Methods of a Class

With the Java Reflection API, we can isolate the abstract methods from a class via the following snippet of code: List abstractMethods = new ArrayList();Class clazz = Foo.class;Method[] methods =

Finding the Current Flush Mode for the JPA EntityManager

Knowing the current flush mode can be done as follows: // via EntityManagerentityManager.getFlushMode();// in Hibernate JPA, via Session(entityManager.unwrap(Session.class)).getFlushMode();// starting with Hibernate 5.2(entityManager.unwrap(Session.class)).getHibernateFlushMode();