Home » Java

Tag Archives: Java

Java 8 CompletableFuture thenRun Example

Hello. In this tutorial, we will explore the Java 8 CompletableFuture thenRun method. 1. Introduction Before diving deep into the practice stuff let us understand the thenRun(…) method we will be covering in this tutorial. CompletableFuture.thenRun() method does not depend on the previous execution CompletableFuture.thenRun() method does not return anything i.e. CompletableFuture<Void> 2. Practice Let us dive into some practice ...

Read More »

Java 8 CompletableFuture thenAccept Example

Hello. In this tutorial, we will explore the Java 8 CompletableFuture thenAccept method. 1. Introduction Before diving deep into the practice stuff let us understand the thenAccept(…) method we will be covering in this tutorial. CompletableFuture.thenAccept() takes a Consumer and returns CompletableFuture 2. Practice Let us dive into some practice stuff from here and I am assuming that you already ...

Read More »

Java 8 CompletableFuture supplyAsync Example

Hello. In this tutorial, we will explore the Java 8 CompletableFuture and explain the supplyAsync method. 1. Introduction Before diving deep into the practice stuff let us understand the supplyAsync(…) method we will be covering in this tutorial. Run a Supplier functional interface asynchronously. A Supplier functional interface does not accept anything but returns a valueThe completableFuture.get() blocks until the ...

Read More »

Java 8 CompletableFuture runAsync Example

Hello. In this tutorial, we will explore the Java 8 CompletableFuture and explain the runAsync method. 1. Introduction Before diving deep into the practice stuff let us understand the runAsync(…) method we will be covering in this tutorial. Used to run a method asynchronously. The method accepts a Runnable functional interface The method does not return any value Supports the ...

Read More »

Java 8 Stream API – limit() & skip() Example

Hello. In this tutorial, we will explore the Stream API: limit() and skip() methods introduced in Java 8. 1. Introduction Before diving deep into the practice stuff let us understand the methods we will be covering in this tutorial. The skip() method discards the first n elements of a stream. n cannot be a negative number and if it is ...

Read More »

Java 8 Stream API – distinct(), count() & sorted() Example

Hello. In this tutorial, we will explore the Stream API methods: sorted(), count(), and distinct() methods introduced in Java 8. 1. Introduction Before diving deep into the practice stuff let us understand the methods we will be covering in this tutorial. The distinct() method returns a stream of unique elements. It is a stateful intermediate operation and returns a new ...

Read More »

Java 8 Functional Interface – BiPredicate Example

Hello. In this tutorial, we will explain the BiPredicate functional interface in Java 8. 1. Introduction Java 8 BiPredicate functional interface represents a method that accepts two input arguments and returns a boolean output. Represented by the method syntax – boolean test(T t, U u). This interface also provides some default methods like – default BiPredicate or(BiPredicate other) – Composed ...

Read More »

Summing Numbers with Java 8 Stream.reduce() operation

Hello. In this tutorial, we will explain the Stream.reduce method in java 8. 1. Introduction Before diving deep into the practice stuff let us understand the reduce() method in java8 programming. Stream.reduce() – Combine the elements of a stream and produces a single result. The method accepts T identity and BinaryOperator<T> accumulator as the arguments. If the identity argument is ...

Read More »

Java 8 Functional Interface – BiConsumer Example

Hello. In this tutorial, we will explain the BiConsumer functional interface introduced in java 8. 1. Introduction Before diving deep into the practice stuff let us understand the BiConsumer functional interface in java8 programming. void accept(T t, U u) – It is an abstract method that accepts two input arguments, prints the operation based on the given input, and returns ...

Read More »

Java 8 Stream – count() Example

Hello. In this tutorial, we will explain the count() method introduced in java 8. 1. Introduction Before diving deep into the practice stuff let us understand the count() method introduced in java8 programming. Stream.count() – Returns the number of elements in the stream with or without filter condition being appliedThis is a terminal operation and once consumed the same stream ...

Read More »