This is a 3 part series on Java8 Features. Drop me an email for a discussion - singh.marut@gmail.com
Code is available at https://github.com/singhmarut/java8training
Videos available at my youtube channel https://www.youtube.com/channel/UCBM4yHwfjQ_syW6Lz8kYpmA
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
Â
Java8 training - class 2
1. Java 8 Training â Class 2
-Marut Singh
Email: singh.marut@gmail.com
http://www.marutsingh.com/
http://marutsingh.com/
2. Built-in Functional Interfaces
Predicate Interface
@FunctionalInterface
public interface Predicate<T> {
* Evaluates this predicate on the given argument.
boolean test(T t);
default Predicate<T> and(Predicate<? super T> other) {
default Predicate<T> negate()
default Predicate<T> or(Predicate<? super T> other)
static <T> Predicate<T> isEqual(Object targetRef)
}
http://marutsingh.com/
3. Built-in Functional Interfaces - Quiz
ï” If functional interfaces can have only one abstract method then how does
Predicate qualify for functional interface?
http://marutsingh.com/
4. Built-in Functional Interfaces
Consumer Interface
accepts a single argument by calling its accept (args) method and does not return any
value making it a void method
Unlike most other functional interfaces, Consumer is expected to operate via side-
effects.
@FunctionalInterface
public interface Consumer<T> {
* Performs this operation on the given argument.
void accept(T t);
default Consumer<T> andThen(Consumer<? super T> after) {
Objects.requireNonNull(after);
return (T t) -> { accept(t); after.accept(t); };
}
}
http://marutsingh.com/
5. Built-in Functional Interfaces
Supplier Interface
A supplier of objects. The result objects are either created during the invocation
of get() or by some prior action.
The supplier does the opposite of the consumer, so it takes no arguments but it
returns some value by calling its get() method.
@FunctionalInterface
public interface Supplier<T> {
/**
* Gets a result.
*
* @return a result
*/
T get();
}
Example:
Supplier<String> i = ()-> "springpeople.com";
System.out.println(i.get());
http://marutsingh.com/
7. Pipelining
ï” Stream operations return stream itself so that their result can be pipelined.
These operations are called intermediate operations and their function is to
take input, process them, and return output to the target. collect() method is
a terminal operation which is normally present at the end of the pipelining
operation to mark the end of the stream
http://marutsingh.com/
10. Lambda Operations
ï” Extracting data from an object using map
ï” Stream Operations
ï” Optional Class
ï” Lazy Processing
ï” Sorting
ï” Collect Method
ï” Grouping and Partition
http://marutsingh.com/