This document provides information about a Java 8 Bootcamp training conducted by Mohamed Ben Hassine. It outlines the key topics that will be covered in the training including an introduction to lambda expressions, Java 8 Stream API, new date and time API, Nashorn JavaScript engine, and other Java 8 features. It also provides a brief history of Java releases and versions. The training will use an example project of building an employee management application to demonstrate and apply the Java 8 concepts over the course.
Java 8 Streams And Common Operations By Harmeet Singh(Taara)Harmeet Singh(Taara)
In this, we are discuss about Java 8 Streams. Common Operations . Java 8 Streams are huge topic, so i am not cover all the things, but try to cover the basics operations of Streams. Before this, please refer my previous presentation "Functional programming in java 8", because of clear some basic concept for functional programming. For the reference use Java 8 API docs.
Java 8 Streams And Common Operations By Harmeet Singh(Taara)Harmeet Singh(Taara)
In this, we are discuss about Java 8 Streams. Common Operations . Java 8 Streams are huge topic, so i am not cover all the things, but try to cover the basics operations of Streams. Before this, please refer my previous presentation "Functional programming in java 8", because of clear some basic concept for functional programming. For the reference use Java 8 API docs.
My presentation slides in KMS TechCon 2014, an internal technology event at KMS Technology Vietnam company.
"Java 8 is one of the most highly anticipated programming language updates in many years. Let me give you an introduction about its new features: Lambda expressions, Method references, Default Methods, Stream API, new JS Engine, new Date/Time API and more..."
Modern Programming in Java 8 - Lambdas, Streams and Date Time APIGanesh Samarthyam
This presentation provides a comprehensive overview of modern programming in Java. It focuses only on Java 8 features: Lambdas, Streams and Date Time API. It also briefly covers refactoring legacy Java code to Java 8.
These are Java ways of functional style; pragmatic ways of understanding and introducing Lambda/Functional API.
你可以在以下找到中文說明:
http://www.codedata.com.tw/java/jdk8-functional-api/
Refactoring to Scala DSLs and LiftOff 2009 RecapDave Orme
An introductory presentation given to the Chicago Area Scala Enthusiasts (a) beginning with a recap of the Scala LiftOff unconference in Reston, VA, 2009, and (b) describing how to gradually migrate Scala code translated directly from Java into a DSL that facilitates readability and maintainability of client code. We then observe that this technique makes it possible to use Scala DSLs as a way to introduce Scala in a Java shop.
Async library is an asynchronous programming facility for Scala that offers a direct API for working with Futures.
It was added in Scala version 2.10 and is implemented using macros. Its main constructs, async and await, are inspired by similar constructs introduced in C# 5.0.
Cover Basic concept for Functional Programming in Java. Define new functional interfaces, lambda expressions, how to translate lambda expression, JVM deal with new byte code etc. This is not the perfect slides for functional programming, but trying cover simple basic functional programming.
My presentation slides in KMS TechCon 2014, an internal technology event at KMS Technology Vietnam company.
"Java 8 is one of the most highly anticipated programming language updates in many years. Let me give you an introduction about its new features: Lambda expressions, Method references, Default Methods, Stream API, new JS Engine, new Date/Time API and more..."
Modern Programming in Java 8 - Lambdas, Streams and Date Time APIGanesh Samarthyam
This presentation provides a comprehensive overview of modern programming in Java. It focuses only on Java 8 features: Lambdas, Streams and Date Time API. It also briefly covers refactoring legacy Java code to Java 8.
These are Java ways of functional style; pragmatic ways of understanding and introducing Lambda/Functional API.
你可以在以下找到中文說明:
http://www.codedata.com.tw/java/jdk8-functional-api/
Refactoring to Scala DSLs and LiftOff 2009 RecapDave Orme
An introductory presentation given to the Chicago Area Scala Enthusiasts (a) beginning with a recap of the Scala LiftOff unconference in Reston, VA, 2009, and (b) describing how to gradually migrate Scala code translated directly from Java into a DSL that facilitates readability and maintainability of client code. We then observe that this technique makes it possible to use Scala DSLs as a way to introduce Scala in a Java shop.
Async library is an asynchronous programming facility for Scala that offers a direct API for working with Futures.
It was added in Scala version 2.10 and is implemented using macros. Its main constructs, async and await, are inspired by similar constructs introduced in C# 5.0.
Cover Basic concept for Functional Programming in Java. Define new functional interfaces, lambda expressions, how to translate lambda expression, JVM deal with new byte code etc. This is not the perfect slides for functional programming, but trying cover simple basic functional programming.
The slides of my JavaOne 2017 talk. It describes how you can create API using functional interfaces, default and static methods starting with Java 8. You can watch the video here: https://www.youtube.com/watch?v=64UO1YjVcZ0
Presentation on the new features introduced in JDK 8, presented on the 26.02.2013 in Sofia University in front of students and members of the Bulgarian java user group.
Java is Object Oriented Programming. Java 8 is the latest version of the Java which is used by many companies for the development in many areas. Mobile, Web, Standalone applications.
Since its first public release over two decades ago, the Java platform has become ubiquitous in virtually all areas of computing; from embedded systems to enterprise applications. As the demands of modern software development have evolved, so too have programming languages. There are many languages on the Java platform designed to be a “better Java”; though none are as widespread as Java itself. Despite the somewhat conservative nature of Java as a language, there have been a number of notable additions designed to address the challenges developers face without breaking compatibility. This presentation aims to provide an overview of the newer language features and APIs in recent releases of Java in the hope of increasing developer productivity.
This presentaion provides and overview of the new features of Java 8, namely default methods, functional interfaces, lambdas, method references, streams and Optional vs NullPointerException.
This presentation by Arkadii Tetelman (Lead Software Engineer, GlobalLogic) was delivered at Java.io 3.0 conference in Kharkiv on March 22, 2016.
1. Mohamed Ben Hassine
Java / JEE Technical Lead
Trainer
med.ingenieur@gmail.com
(+216) 52 633 220
www.linkedin.com/in/mohamedbnhassine
Java 8 Bootcamp
2. Java 8 Bootcamp
What you will Learn
• Get Started
• Lambda Expressions
• Java 8 Stream API
• New Date and Time API
• Nashorn: New JavaScript Engine
• Miscellaneous
4. History of Java releases
4
1995
JDKIntroduction
January1996
JDK1.0
“OAK”JDK1.0
December1998
J2SE1.2
FoundationofJCJ
Swing,Collections
February2002
J2SE1.4
Assert,JAXP,IPv6
RegularExpressions
February 1997
JDK 1.1
Java Beans, RMI , JDBC,
JIT
May 2000
J2SE 1.3
HotSpot JVM , JNDI,
Java Debugger
September 2004
J2SE 5.0
Generics, Metadata,
Concurrency, Static
Import
September 2006
Java SE 6
Java Compiler API
,Support JDBC 4.0 , JVM
improvements
July 2011
Java SE 7
Try-with-Resources
Strings in switch
New IO API , Dynamic
languages
March 2015
Java SE 8
Project Lambda Streams
API , Functional Interfaces
,Nashorn Engine ,New
Date Time API ,
Annotations on Type
2017
Java SE 9
Jshell Java REPL ,
Support HTTP 2.0 , G1
default Garbage
Collector
Get Started
5. Why Java 8 Now ?
5
Get Started
Revolution in Processing power
Parallel multicores architectures
Big Data Applications
Code behavior
Code as data
Functional programming Support
Enhance core librairies
Interface unlocking (concrete methods )
Backward compatibility
Java / Javascript
JavaScript made great in Java 8
7. Project Based Course
7
Get Started
Employee management
Throughout the whole course , we will develop a java
console app which offers suck key features :
Add manage employee
Manage employees personal details , salaries and bonus
Search employee by predefined criteria
8. Lambda Expressions
First Lambda Expression
Comparator<Employee> compLambda = ( emp1, emp2) -> {
int i = Integer.compare(emp1.getAge(), emp2.getAge());
if (i != 0) {
return i;
} else {
i = Double.compare(emp1.getSalary(), emp2.getSalary());
if (i != 0)
return i;
}
return i;
};
Collections.sort(persons, compLambda);
Much Easier !
persons.sort(Comparator.comparing(Employee::getAge).thenComparing(Employee::getSalary));
Don’t worry about this code for now. This
Course will explain what it does and how you can develop
similar code!
9. Lambda Expressions
Why Lambda Expression
Using anonymous classes for code behavior parameterization is verbose
Programmers struggle with anonymous classes.
(confusion “this”, no access to non-final local variables)
Convenient for new streams library
persons.forEach(emp -> emp.setSalary(3000));
Solution :
Lambda let you represent a behavior or pass code in a concise way.
Another way to write anonymous classes
Comparator<Employee> compLambda = ( emp1, emp2) -> { return emp1.getJobTitle().compareTo(emp2.getJobTitle()); }
Lambda
Parameters
Arrow
Lambda Body
10. Lambda Expressions
How to Write Lambda Expression
The simple way
More than One line of code
Runnable r = () -> {
for (int i = 0; i < 2016; i++) {
System.out.println("Hello to your Java SE 8 Bootcamp 2016 !");
}
};
More than One Argument
Comparator<Employee> compLambda = (Employee emp1, Employee emp2) -> {
return emp1.getJobTitle().compareTo(emp2.getJobTitle());
}
;
FileFilter filter = (File file) -> file.getName().endsWith("class");
11. Lambda Expressions
So what is exactly Lambda Expression ?
Everything in Java has a type so what for Lambda ? :
Lambda Expression is Functional Interface ( new Java 8 concept , Interface with one
abstract Method..example Runnable , Comparator interfaces known prior to Java
SE8 as Single Abstract Method Interface).
Where to use A Lambda Expression ?
In each case it could be assigned to a variable of Type Functional Interface
Runnable r = () -> System.out.println("Hello to your Java SE 8 Bootcamp 2016 !");
;
Lambda Expression
12. Lambda Expressions
Functional Interface
An Interface with only one abstract method
Example :
public interface Runnable {
public abstract void run();
}
@FunctionalInterface
public interface SimpleInterface {
public void doSomeJob() ;
}
Define Java SE8 Functional Interface
13. Lambda Expressions
Predefined Functional Interface in JAVA SE8
New Java Package : java.util.function
Divided into 4 categories :
Supplier Consumer Predicate
/** @since 1.8
*/
@FunctionalInterface
public interface
Supplier<T> {
/**
* Gets a result.
*
* @return a result
*/
T get();
}
Function
/** @since 1.8
*/
@FunctionalInterface
public interface Consumer<T>
{
/**
* @param t the input
argument
*/
void accept(T t);
}
/** @since 1.8
*/
@FunctionalInterface
public interface
Predicate<T> {
/**
* Evaluates this
predicate on the given
argument.
*/
boolean test(T t);
}
/** @since 1.8
*/
@FunctionalInterface
public interface Function<T,
R> {
/**
* Applies this function
to the given argument.
*/
R apply(T t);
}
14. Lambda Expressions
Method Reference
Simply : An other way to write Lambda Expression
Comparator<Employee> compLambda = (Employee emp1, Employee emp2) -> {
return Double.compare(emp1.getSalary(), emp2.getSalary()) ;
}
;
Comparator<Employee> compLambdaRef = Comparator.comparing(Employee::getSalary);
– Replace
(args) -> ClassName.staticMethodName(args)
– with
ClassName::staticMethodName
15. Lambda Expressions
So how to process Data with this Lambda ?
List<Employee> persons = new ArrayList<>();
persons.add(new Employee("Mohamed", 30, 2500, new Date(), true, "Java / JEE TL"));
persons.add(new Employee("Ferdaous", 24, 1900, new Date(), false, "IT Consultant"));
// Prior to Java SE 8
for (Employee employee : persons) { System.out.println(employee) ;}
Using Lambda Expression
// Traverse collection with Lambda Expression
persons.forEach(emp -> System.out.println(emp));
// More concise syntax with Method Reference
persons.forEach(System.out::println);
Where does this method come from ? All interface
implementations of Iterable should be refactored !..
Response Next episode ..
16. Lambda Expressions
Default Method
In Java 8 a method can be implemented in an interface.
New Java 8 Concept for backward compatibility
Allow to add methods to an existing interface long after it has been released
without breaking the interface
Interface
void newMethod()
Class
implements
Compilation Error must
implement newMethod
Solution to not modify sub class
Interface
default void
newMethod() {
Code here….
}
Does not break any sub
class implementing this
Interface
Default Method could be overridden in interface implementation
17. Lambda Expressions
Interface Static Method
Similar to default methods except that it is not possible to override them in
the implementation classes
providing security.
Interface static methods are good for providing utility methods.
Interface
void newMethod()
Class
implements
Compilation Error must
implement newMethod
Solution to not modify sub class
Interface
Static void
newMethod() {
Code here….
}
Does not break any sub
class implementing this
Interface