Java 8 stream allMatch, noneMatch and anyMatch examples

In this post we will provide three examples on how to use the java 8 stream allMatch, noneMatch and anyMatch methods. Java 8 stream allMatch, noneMatch and anyMatch examples: Stream allMatch() Example: The allMatch() method is used on a stream to determine, if all the values satisfy a certain condition(predicate). The example below, checks to … Continue reading Java 8 stream allMatch, noneMatch and anyMatch examples

Basic HttpClient Configuration Example

In this post we will provide a basic HttpClient configuration example. The example will configure different timeout values along with connection pool management. HttpClient configuration example: The example below configures a HttpClient object. The configuration details is as follows: RequestConfig: This object is an immutable class which encapsulates request configuration items. RequestConfig.setConnectionRequestTimeout(): Timeout in milliseconds … Continue reading Basic HttpClient Configuration Example

What is a NullPointerException in Java

In this post we will explain what is a NullPointerException in Java, and how to fix these issues. What is a NullPointerException in Java An application will throw a null pointer exception when you are invoking a method on an object who's value is null. Lets have a look at the example below.

Running … Continue reading What is a NullPointerException in Java

Convert an Object to a Map in Java

In this post we will provide an example on how to convert an object to a map in Java. Setup: You will need to include the following dependency

Convert an Object to a Map in Java: The example below uses a User object which has the following properties Name Age Address (which is another … Continue reading Convert an Object to a Map in Java

Java ExecutorService examples

This post will provide a brief description of the different types of ExecutorService available in java. This post will also include some Java ExecutorService examples. What is the ExecutorService: The executor service is provided by the java JDK because it helps simplifies the execution of asynchronous tasks. It provides a pool of threads and an API allowing you … Continue reading Java ExecutorService examples

Handle an exception thrown by a callable

In this post an example is provided to demonstrate how to handle an exception thrown by a Callable object. Handle exception thrown by callable:

A few points to note from the above code. A callable object which throws a RuntimeException, is passed into the submit() method. The result of the callable object is retrieved … Continue reading Handle an exception thrown by a callable