The document presents an overview of Java 8 features, including lambda expressions, functional interfaces, default methods, predicates, functions, the double colon operator, and the Stream API. It highlights the transition from Java 7 to Java 8, emphasizing the functional aspects introduced in 1.8, including the new date and time API. The document also briefly mentions the library management project associated with Java 8.
Introduction to the presentation focused on Java 8 updates and features.
The content includes Introduction, Lambda Expression, Functional Interfaces, Default Methods, Predicates, Functions, Double Colon Operator, Stream API, Date and Time API, and a Project.
Java 8 was released on March 18, 2014, marking a major shift in focusing on functional programming aspects.
Lambda Expressions are unnamed functions that simplify syntax for function implementation in Java.
Functional Interfaces contain a single abstract method; examples include Runnable, Comparable, and ActionListener.
Java 8 allows default methods inside interfaces, enhancing the flexibility of interface implementations.
Predicates are functions returning boolean values, implemented through Predicate interface in Java 8.
Functions in Java 8 can return any type of result, similar to predicates but with broader value types.
Java 8 introduces the double colon operator for method references linking functional interfaces to defined methods.
The Stream API processes collection objects with configuration and mapping phases to streamline data handling.
Java 8 introduced Joda-Time API via java.time package, improving date and time management over prior versions.
A project aligning with Java 8 concepts for practical implementation in managing library systems.
Closing remarks and appreciation for participation in the Java 8 presentation.
CONTENT
• Introduction
• LambdaExpression
• Functional Interfaces
• Default methods
• Predicates
• Functions
• Double colon operator
• Stream API
• Date and Time API
• Project
3.
Introduction
• java 7– July 28th 2011
• Java 8 - March 18th 2014
• Java 9 - September 22nd 2016
• Java 10 – 2018
• After Java 1.5version, Java 8 is the next major version. Before Java 8,
sun people gave importance only for objects but in 1.8version oracle
people gave the importance for functional aspects of programming to
bring its benefits to Java.ie it doesn’t mean Java is functional oriented
programming language
4.
Lambda Expression
• LambdaExpression is just an anonymous (nameless) function.
That means the function which doesn’t have the name, return
type and access modifiers.
public void m1()
{
sop(“hello”);
}
() ->{
sop(“hello”);
}
5.
Functional Interfaces
• Ifan interface contain only one abstract method, such type of interfaces are called functional
interfaces and the method is called functional method or single abstract method (SAM)
• Ex->
• 1) Runnable -> It contains only run() method
• 2) Comparable ->It contains only compareTo() method
• 3) ActionListener -> It contains only actionPerformed()
• 4) Callable -> It contains only call() method
interface Interf {
public abstract void m1();
default void m2() {
System.out.println (“hello”); } }
@Functional Interface
Interface Interf {
public void m1();
}
6.
Default methods
• Until1.7 version onwards inside interface we can take only public
abstract methods and public static final variables
• But from 1.8 version onwards in addition to these, we can declare
default concrete methods also inside interface, which are also
known as defender methods.
default void m1()
{
System.out.println (“Default Method”);
}
• Interface default methods are by-default available to all
implementation classes. Based on requirement implementation
class can use these default methods directly or can override
7.
Predicates
• A predicateis a function with a single argument and returns
boolean value.
• To implement predicate functions in Java, Oracle people
introduced Predicate interface in 1.8 version (i.e.,Predicate)
• Predicate interface present in Java.util.function package.
• public boolean test(Integer I) {
if (I >10) {
return true; }
else { return false;
} }
With predicate
predicate p = I ->(I >10);
System.out.println (p.test(100)); true
System.out.println (p.test(7)); false
8.
Functions
• Functions areexactly same as predicates except that functions can return
any type of result but function should (can) return only one value and
that value can be any type as per our requirement
• To implement functions oracle people introduced Function interface in
1.8version.
• interface function(T,R) {
• public R apply(T t);
• }
9.
Double colon operator
•Functional Interface method can be mapped to our
specified method by using :: (double colon) operator. This
is called method reference.
• Our specified method can be either static method or
instance method
Syntax:
if our specified method is static method
Classname::methodName
if the method is instance method
Objref::methodName
10.
Stream API
• Toprocess objects of the collection, in 1.8 version Streams concept introduced.
• java.util streams meant for processing objects from the collection. I and Java.io
streams meant for processing binary and character data with respect to file.
• We can create a stream object to the collection by using stream() method of
Collection interface. stream() method is a default method added to the Collection in
1.8 version.
• default Stream stream()
• Stream s = c.stream();
• Stream is an interface present in java.util.stream. Once we got the stream, by using
that we can process objects of that collection. We can process the objects in the
following 2 phases
• Configuration
• Mapping
11.
Date and TimeAPI
• Joda-Time API
• Until Java 1.7version the classes present in Java.util package to
handle Date and Time (like Date, Calendar, TimeZoneetc) are
not up to the mark with respect to convenience and
performance.
• To overcome this problem in the 1.8version oracle people
introduced Joda-Time API. This API developed by joda.org and
available in Java in the form of Java.time package.