SlideShare ist ein Scribd-Unternehmen logo
1 von 53
JAVA 8 
Create The Future
What's New in JDK 8 
• Lambda Expressions 
• Method references 
• Streams 
• Default methods 
• Date and Time API 
• Nashorn engine
What's New in JDK 8 
• Lambda Expressions 
• Method references 
• Streams 
• Default methods 
• Date and Time API 
• Nashorn engine
Lambda Expressions 
• Simply, It is a method to eliminate anonymous classes 
and nested calling functions like the action should be 
taken when someone clicks a button.
Lambda Expressions 
• Why Lambda Expressions? 
• Ex: 
for (int i = 0; i < names.size(); i++) 
{ 
System.out.println(names.get(i)); 
}
Lambda Expressions 
• Why Lambda Expressions? 
• It is Simple 
names.foreach 
(name->System.out.println(name))
Lambda Expressions 
• Why Lambda Expressions? 
• It eliminates nested calling functions & anonymous classes . 
btn.setOnAction(new EventHandler<ActionEvent>() { 
@Override 
public void handle(ActionEvent event) { 
System.out.println("Hello World!"); 
} 
});
Lambda Expressions 
• Why Lambda Expressions? 
• It eliminates nested calling functions & anonymous classes . 
btn.setOnAction(event -> System.out.println("Hello 
World!") );
What's New in JDK 8 
• Lambda Expressions 
• Method references 
• Streams 
• Default methods 
• Date and Time API 
• Nashorn engine
Method References 
• It is easy-to-read lambda expressions for methods that 
already have a name by referring to the existing method 
by name.
Method References 
• Why Method References? 
• If there is a function in person object compares ages. 
Arrays.sort(personsArray, (a, b) -> 
Person.compareByAge(a, b) ); 
When using Method References 
Arrays.sort(personsArray, Person::compareByAge);
Method References 
• Kinds of Method References 
Kind Example 
Reference to an instance method of a 
particular object 
persons.foreach 
(System.out.println(preson::getEmail)) 
Reference to a static method 
Arrays.sort(personsList, 
Person::compareByAge); 
Reference to an instance method of an 
arbitrary object of a particular type 
Arrays.sort(stringArray, 
String::compareToIgnoreCase); 
Reference to a constructor 
transferElements(personsList, 
HashSet<Person>::new);
What's New in JDK 8 
• Lambda Expressions 
• Method references 
• Streams 
• Default methods 
• Date and Time API 
• Nashorn engine
Streams 
• It is a sequence of elements. Unlike a collection, it is not 
a data structure that stores elements but it carries values 
from it.
Streams 
• Why Streams? 
• Parallelism is the main target today. 
big data multicore 
cloud 
computing
Streams 
• Why Streams? 
• Parallelism is the main target today. 
for (int i = 0; i < names.size(); i++) 
{ 
System.out.println(names.get(i)); 
} 
Ques: How to use Parallelism?
Streams 
• Why Streams? 
• Simply you can Choose between Serial or parallel. 
names.stream().foreach 
(name->System.out.println(name)) 
names.parallelStream().foreach. 
(name->System.out.println(name))
Streams 
• Why Streams? 
• It makes a pipeline (a sequence of aggregate operations) 
names.stream 
.filter(e -> e.equals(“java”)) 
.forEach(e -> System.out.println(e));
What's New in JDK 8 
• Lambda Expressions 
• Method references 
• Streams 
• Default methods 
• Date and Time API 
• Nashorn engine
Default methods 
• It enables you to add new functionality to the interfaces 
of your libraries and ensure compatibility with code 
written for older versions of those interfaces.
Default methods 
• Why Default methods? 
• Consider the following interface TimeClient. 
public interface TimeClient { 
void setTime(int hour, int minute, int second); 
void setDate(int day, int month, int year); 
}
Default methods 
• Why Default methods? 
• The following class SimpleTimeClient impelements it. 
public class SimpleTimeClient implements TimeClient { 
void setTime(int hour, int minute, int second){ 
//some code } 
void setDate(int day, int month, int year){ 
//some code } 
}
Default methods 
• Why Default methods? 
• How to add new functionality to the TimeClient interface?
Default methods 
• Why Default methods? 
• How to add new functionality to the TimeClient interface? 
public interface TimeClient { 
……… 
String getDateZone(String zoneString); 
}
Default methods 
• Why Default methods? 
• How to add new functionality to the TimeClient interface? 
public class SimpleTimeClient implements 
TimeClient{ 
……… 
String getDateZone(String zoneString){ 
// some code 
} 
}
Default methods 
• Default Methods 
• You can define default method in interfaces instead. 
public interface TimeClient { 
……… 
default getDateZone(String zoneString) { 
// some code 
} 
}
Default methods 
• Static Methods 
• Also, you can define static methods in interfaces. 
public interface TimeClient { 
……… 
static ZoneId getZoneId (String zoneString) { 
// some code 
} 
}
What's New in JDK 8 
• Lambda Expressions 
• Method references 
• Streams 
• Default methods 
• Date and Time API 
• Nashorn engine
Date and Time API 
• Why do we need a new date and time library? 
• (java.util.Date and SimpleDateFormatter) aren’t thread-safe. 
• Poor API design. For example, years in java.util.Date start at 
1900, months start at 1, and days start at 0—not very intuitive. 
• Inadequate support for the date and time use cases of ordinary 
developers.
Date and Time API 
• Why do we need a new date and time library? 
• (java.util.Date and SimpleDateFormatter) aren’t thread-safe. 
• Poor API design. For example, years in java.util.Date start at 
1900, months start at 1, and days start at 0—not very intuitive. 
• Inadequate support for the date and time use cases of ordinary 
developers. 
These issues, and several others, have led to “Time API”.
Date and Time API 
• Thread Safe 
• The classes are immutable “no setters”. 
LocalDateTime timePoint = LocalDateTime.now( ); 
// it is returning a new object instead of setting 
LocalDateTime thePast = timePoint.withDayOfMonth( 
10).withYear(2010); 
/* You can use direct manipulation methods, 
or pass a value and field pair */ 
LocalDateTime yetAnother = thePast.plusWeeks( 
3).plus(3, ChronoUnit.WEEKS);
Date and Time API 
• Periods 
• Represents values such as “3 years 2 months and 1 day” 
Period period = Period.of(3, 2, 1); 
// You can modify the values of dates using periods 
LocalDateTime newDate = timePoint.plus(period);
Date and Time API 
• Durations 
• Represents values such as “3 seconds and 5 nanoseconds” 
Duration duration = Duration.ofSeconds(3, 5); 
// You can modify the values of dates using durations 
LocalDateTime newDate = timePoint.plus(duration);
Date and Time API 
• Time Truncation 
• The truncatedTo method allows you to truncate a value to a field 
LocalTime truncatedTime = 
time.truncatedTo(ChronoUnit.SECONDS);
Date and Time API 
• Time Zones 
• You can specify the zone id when creating a zoned date time 
ZoneId id = ZoneId.of("Europe/Paris"); 
ZonedDateTime zoned = ZonedDateTime.of(timePoint, 
id); 
Hint: There is an existing time zone class in Java—java.util.TimeZone— 
but it isn’t used by Java SE 8 because Time API classes are immutable 
and time zone is mutable.
Date and Time API 
• Chronologies 
• Is the concept of representing a factory for calendaring system. 
Chronology: 
ChronoLocalDate 
ChronoLocalDateTime 
ChronoZonedDateTime
Date and Time API 
• Chronologies 
• Is the concept of representing a factory for calendaring system. 
Chronology: 
ChronoLocalDate 
ChronoLocalDateTime 
ChronoZonedDateTime 
These classes are there purely for developers who are working on 
highly internationalized applications
Date and Time API 
• HijrahChronology [Class Implements Chronology] 
• Follows Hijrah calendar system observation “new moon 
occurrence” 
Chronology ID Calendar Type Locale extension Description 
Hijrah-umalqura islamic-umalqura 
ca-islamic-umalqura 
Islamic - Umm 
Al-Qura calendar 
of Saudi Arabia
Date and Time API 
• HijrahDate 
• HijrahDate is created bound to a particular HijrahChronology 
HijrahChronology calendar = 
HijrahChronology.INSTANCE; 
HijrahDate date=calendar.dateNow(); 
// result is Hijrah-umalqura AH 1436-01-12 
//”rtl printing”
Date and Time API 
• HijrahDate 
• HijrahDate is created bound to a particular HijrahChronology 
HijrahChronology calendar = 
HijrahChronology.INSTANCE; 
HijrahDate date=calendar.dateNow(); 
date.minus(2, ChronoUnit.DAYS); 
date.plus(3, ChronoUnit.YEARS); 
HijrahDate secondDate=calendar.date(1435, 4, 1);//rtl 
date.isAfter(secondDate); 
date.isBefore(secondDate);
What's New in JDK 8 
• Lambda Expressions 
• Method references 
• Streams 
• Default methods 
• Date and Time API 
• Nashorn engine
Nashorn engine 
• Nashorn is an embedded scripting engine inside Java 
applications and how Java types can be implemented and 
extended from JavaScript, providing a seamless 
integration between the two languages.
Nashorn engine 
• What’s new in Nashorn 
• run JavaScript programs from the command line with tool jjs 
var hello = function() { 
print("Hello Nashorn!"); 
}; 
hello(); 
Evaluating it is as simple as this: 
$ jjs hello.js 
$ Hello Nashorn!
Nashorn engine 
• What’s new in Nashorn 
• Embedding Oracle Nashorn in java Apps 
public class Hello { 
public static void main(String... args) throws 
Throwable { 
ScriptEngineManager engineManager = new 
ScriptEngineManager(); 
ScriptEngine engine = 
engineManager.getEngineByName("nashorn"); 
engine.eval("function sum(a, b) { return a + b; }"); 
System.out.println(engine.eval("sum(1, 2);")); } }
Nashorn engine 
• What’s new in Nashorn 
• Java seen in javascript 
Java objects can be instantiated using the new 
operator: 
var file = new java.io.File("sample.js"); 
print(file.getAbsolutePath()); 
print(file.absolutePath);
Nashorn engine 
• What’s new in Nashorn 
• Java seen in javascript [ dealing with collections] 
var stack = new java.util.LinkedList(); 
[1, 2, 3, 4].forEach(function(item) { 
stack.push(item); }); 
tour through the new Java 8 stream APIs to sort the 
collection: 
var sorted = stack.stream().sorted().toArray();
Nashorn engine 
• What’s new in Nashorn 
• Java seen in javascript [ Imports] 
importClass(java.util.HashSet); 
var set = new HashSet(); 
importPackage(java.util); 
var list = new ArrayList();
Nashorn engine 
• What’s new in Nashorn 
• Java seen in javascript [JavaImporter] . 
var CollectionsAndFiles = new JavaImporter( 
java.util, java.i); 
It is not global as import classes: 
with (CollectionsAndFiles) { 
var files = new LinkedHashSet(); 
files.add(new File("Plop")); 
files.add(new File("Foo"));}
Nashorn engine 
• What’s new in Nashorn 
• The Java.type used to reference to precise Java types. 
var LinkedList = Java.type( "java.util.LinkedList"); 
var primitiveInt = Java.type( "int"); 
var arrayOfInts = Java.type( "int[]"); 
var list = new LinkedList; 
var a = new arrayOfInts(3);
Nashorn engine 
• What’s new in Nashorn 
• Extending java type 
var iterator = new java.util.Iterator({ 
i: 0, 
hasNext: function() { 
return this.i < 10; }, 
next: function() { 
return this.i++; } 
});
Nashorn engine 
• What’s new in Nashorn 
• Support Lambda Expression 
var odd = list.stream().filter( function(i) { return 
i % 2 == 0; }); 
Like this: 
var odd = list.stream().filter( function(i) i % 2 == 
0);
References 
• https://docs.oracle.com/javase/tutorial/java/javaOO/lambdaexpressions.html 
• https://docs.oracle.com/javase/tutorial/java/javaOO/methodreferences.html 
• https://docs.oracle.com/javase/tutorial/collections/streams/index.html#pipelines 
• https://docs.oracle.com/javase/tutorial/collections/streams/parallelism.html 
• https://docs.oracle.com/javase/tutorial/java/IandI/defaultmethods.html 
• http://www.oracle.com/technetwork/articles/java/jf14-date-time-2125367.html 
• https://docs.oracle.com/javase/8/docs/api/java/time/chrono/Chronology.html 
• http://docs.oracle.com/javase/8/docs/api/java/time/chrono/HijrahDate.html 
• http://www.oracle.com/technetwork/articles/java/jf14-nashorn-2126515.html 
• https://developer.mozilla.org/en-US/docs/Mozilla/Projects/Rhino 
• http://www.slideshare.net/zainalpour/whats-new-in-java-8?qid=07aab8b4-6251-45f3- 
af26-797bc21d8758&v=default&b=&from_search=1 
• Installing JDK8 and LUNA Eclipse 
• http://www.oracle.com/technetwork/java/javase/downloads/jdk8-downloads- 
2133151.html 
• http://www.eclipse.org/downloads/java8/
Any Questions?

Weitere ähnliche Inhalte

Was ist angesagt?

RxJava from the trenches
RxJava from the trenchesRxJava from the trenches
RxJava from the trenchesPeter Hendriks
 
Introduction to Scala
Introduction to ScalaIntroduction to Scala
Introduction to ScalaRahul Jain
 
The Dark Side Of Lambda Expressions in Java 8
The Dark Side Of Lambda Expressions in Java 8The Dark Side Of Lambda Expressions in Java 8
The Dark Side Of Lambda Expressions in Java 8Takipi
 
Advanced Production Debugging
Advanced Production DebuggingAdvanced Production Debugging
Advanced Production DebuggingTakipi
 
Martin Odersky - Evolution of Scala
Martin Odersky - Evolution of ScalaMartin Odersky - Evolution of Scala
Martin Odersky - Evolution of ScalaScala Italy
 
Functional Programming Past Present Future
Functional Programming Past Present FutureFunctional Programming Past Present Future
Functional Programming Past Present FutureIndicThreads
 
Harnessing the Power of Java 8 Streams
Harnessing the Power of Java 8 Streams Harnessing the Power of Java 8 Streams
Harnessing the Power of Java 8 Streams IndicThreads
 
Performance van Java 8 en verder - Jeroen Borgers
Performance van Java 8 en verder - Jeroen BorgersPerformance van Java 8 en verder - Jeroen Borgers
Performance van Java 8 en verder - Jeroen BorgersNLJUG
 
Java 8 - Project Lambda
Java 8 - Project LambdaJava 8 - Project Lambda
Java 8 - Project LambdaRahman USTA
 
Reactive Android: RxJava and beyond
Reactive Android: RxJava and beyondReactive Android: RxJava and beyond
Reactive Android: RxJava and beyondFabio Tiriticco
 
The Evolution of Scala / Scala進化論
The Evolution of Scala / Scala進化論The Evolution of Scala / Scala進化論
The Evolution of Scala / Scala進化論scalaconfjp
 
Java 101 Intro to Java Programming - Exercises
Java 101   Intro to Java Programming - ExercisesJava 101   Intro to Java Programming - Exercises
Java 101 Intro to Java Programming - Exercisesagorolabs
 
Scala Talk at FOSDEM 2009
Scala Talk at FOSDEM 2009Scala Talk at FOSDEM 2009
Scala Talk at FOSDEM 2009Martin Odersky
 
JDK8 Functional API
JDK8 Functional APIJDK8 Functional API
JDK8 Functional APIJustin Lin
 
CBStreams - Java Streams for ColdFusion (CFML)
CBStreams - Java Streams for ColdFusion (CFML)CBStreams - Java Streams for ColdFusion (CFML)
CBStreams - Java Streams for ColdFusion (CFML)Ortus Solutions, Corp
 

Was ist angesagt? (20)

RxJava from the trenches
RxJava from the trenchesRxJava from the trenches
RxJava from the trenches
 
Introduction to Scala
Introduction to ScalaIntroduction to Scala
Introduction to Scala
 
The Dark Side Of Lambda Expressions in Java 8
The Dark Side Of Lambda Expressions in Java 8The Dark Side Of Lambda Expressions in Java 8
The Dark Side Of Lambda Expressions in Java 8
 
Java 8 stream and c# 3.5
Java 8 stream and c# 3.5Java 8 stream and c# 3.5
Java 8 stream and c# 3.5
 
Scala in a nutshell by venkat
Scala in a nutshell by venkatScala in a nutshell by venkat
Scala in a nutshell by venkat
 
Advanced Production Debugging
Advanced Production DebuggingAdvanced Production Debugging
Advanced Production Debugging
 
Martin Odersky - Evolution of Scala
Martin Odersky - Evolution of ScalaMartin Odersky - Evolution of Scala
Martin Odersky - Evolution of Scala
 
JavaScript for real men
JavaScript for real menJavaScript for real men
JavaScript for real men
 
Functional Programming Past Present Future
Functional Programming Past Present FutureFunctional Programming Past Present Future
Functional Programming Past Present Future
 
Harnessing the Power of Java 8 Streams
Harnessing the Power of Java 8 Streams Harnessing the Power of Java 8 Streams
Harnessing the Power of Java 8 Streams
 
Performance van Java 8 en verder - Jeroen Borgers
Performance van Java 8 en verder - Jeroen BorgersPerformance van Java 8 en verder - Jeroen Borgers
Performance van Java 8 en verder - Jeroen Borgers
 
Java 8 - Project Lambda
Java 8 - Project LambdaJava 8 - Project Lambda
Java 8 - Project Lambda
 
Scala Intro
Scala IntroScala Intro
Scala Intro
 
Reactive Android: RxJava and beyond
Reactive Android: RxJava and beyondReactive Android: RxJava and beyond
Reactive Android: RxJava and beyond
 
The Evolution of Scala / Scala進化論
The Evolution of Scala / Scala進化論The Evolution of Scala / Scala進化論
The Evolution of Scala / Scala進化論
 
Java 101 Intro to Java Programming - Exercises
Java 101   Intro to Java Programming - ExercisesJava 101   Intro to Java Programming - Exercises
Java 101 Intro to Java Programming - Exercises
 
Scala Talk at FOSDEM 2009
Scala Talk at FOSDEM 2009Scala Talk at FOSDEM 2009
Scala Talk at FOSDEM 2009
 
Introduction to Scala
Introduction to ScalaIntroduction to Scala
Introduction to Scala
 
JDK8 Functional API
JDK8 Functional APIJDK8 Functional API
JDK8 Functional API
 
CBStreams - Java Streams for ColdFusion (CFML)
CBStreams - Java Streams for ColdFusion (CFML)CBStreams - Java Streams for ColdFusion (CFML)
CBStreams - Java Streams for ColdFusion (CFML)
 

Andere mochten auch

New Features in JDK 8
New Features in JDK 8New Features in JDK 8
New Features in JDK 8Martin Toshev
 
55 New Features in Java SE 8
55 New Features in Java SE 855 New Features in Java SE 8
55 New Features in Java SE 8Simon Ritter
 
Getting ready to java 8
Getting ready to java 8Getting ready to java 8
Getting ready to java 8DataArt
 

Andere mochten auch (6)

New Features in JDK 8
New Features in JDK 8New Features in JDK 8
New Features in JDK 8
 
Java 8 Features
Java 8 FeaturesJava 8 Features
Java 8 Features
 
Java 8 Features
Java 8 FeaturesJava 8 Features
Java 8 Features
 
Java SE 8 best practices
Java SE 8 best practicesJava SE 8 best practices
Java SE 8 best practices
 
55 New Features in Java SE 8
55 New Features in Java SE 855 New Features in Java SE 8
55 New Features in Java SE 8
 
Getting ready to java 8
Getting ready to java 8Getting ready to java 8
Getting ready to java 8
 

Ähnlich wie Java 8

Programming in java basics
Programming in java  basicsProgramming in java  basics
Programming in java basicsLovelitJose
 
Software Uni Conf October 2014
Software Uni Conf October 2014Software Uni Conf October 2014
Software Uni Conf October 2014Nayden Gochev
 
New features in jdk8 iti
New features in jdk8 itiNew features in jdk8 iti
New features in jdk8 itiAhmed mar3y
 
Java- Updates in java8-Mazenet solution
Java- Updates in java8-Mazenet solutionJava- Updates in java8-Mazenet solution
Java- Updates in java8-Mazenet solutionMazenetsolution
 
Hadoop cluster performance profiler
Hadoop cluster performance profilerHadoop cluster performance profiler
Hadoop cluster performance profilerIhor Bobak
 
A Quick peek @ New Date & Time API of Java 8
A Quick peek @ New Date & Time API of Java 8A Quick peek @ New Date & Time API of Java 8
A Quick peek @ New Date & Time API of Java 8Buddha Jyothiprasad
 
Spring Day | Spring and Scala | Eberhard Wolff
Spring Day | Spring and Scala | Eberhard WolffSpring Day | Spring and Scala | Eberhard Wolff
Spring Day | Spring and Scala | Eberhard WolffJAX London
 
LINQ Inside
LINQ InsideLINQ Inside
LINQ Insidejeffz
 
Alternate for scheduled apex using flow builder
Alternate for scheduled apex using flow builderAlternate for scheduled apex using flow builder
Alternate for scheduled apex using flow builderKadharBashaJ
 
Utilizing the open ntf domino api
Utilizing the open ntf domino apiUtilizing the open ntf domino api
Utilizing the open ntf domino apiOliver Busse
 
Big data week presentation
Big data week presentationBig data week presentation
Big data week presentationJoseph Adler
 
Java 102 intro to object-oriented programming in java
Java 102   intro to object-oriented programming in javaJava 102   intro to object-oriented programming in java
Java 102 intro to object-oriented programming in javaagorolabs
 
Parallel and Async Programming With C#
Parallel and Async Programming With C#Parallel and Async Programming With C#
Parallel and Async Programming With C#Rainer Stropek
 
How to crack java script certification
How to crack java script certificationHow to crack java script certification
How to crack java script certificationKadharBashaJ
 
Angular for Java Enterprise Developers: Oracle Code One 2018
Angular for Java Enterprise Developers: Oracle Code One 2018Angular for Java Enterprise Developers: Oracle Code One 2018
Angular for Java Enterprise Developers: Oracle Code One 2018Loiane Groner
 

Ähnlich wie Java 8 (20)

Programming in java basics
Programming in java  basicsProgramming in java  basics
Programming in java basics
 
React inter3
React inter3React inter3
React inter3
 
Software Uni Conf October 2014
Software Uni Conf October 2014Software Uni Conf October 2014
Software Uni Conf October 2014
 
New features in jdk8 iti
New features in jdk8 itiNew features in jdk8 iti
New features in jdk8 iti
 
Java- Updates in java8-Mazenet solution
Java- Updates in java8-Mazenet solutionJava- Updates in java8-Mazenet solution
Java- Updates in java8-Mazenet solution
 
Hadoop cluster performance profiler
Hadoop cluster performance profilerHadoop cluster performance profiler
Hadoop cluster performance profiler
 
A Quick peek @ New Date & Time API of Java 8
A Quick peek @ New Date & Time API of Java 8A Quick peek @ New Date & Time API of Java 8
A Quick peek @ New Date & Time API of Java 8
 
Spring Day | Spring and Scala | Eberhard Wolff
Spring Day | Spring and Scala | Eberhard WolffSpring Day | Spring and Scala | Eberhard Wolff
Spring Day | Spring and Scala | Eberhard Wolff
 
LINQ Inside
LINQ InsideLINQ Inside
LINQ Inside
 
Lambdas in Java 8
Lambdas in Java 8Lambdas in Java 8
Lambdas in Java 8
 
Alternate for scheduled apex using flow builder
Alternate for scheduled apex using flow builderAlternate for scheduled apex using flow builder
Alternate for scheduled apex using flow builder
 
Java8.part2
Java8.part2Java8.part2
Java8.part2
 
Utilizing the open ntf domino api
Utilizing the open ntf domino apiUtilizing the open ntf domino api
Utilizing the open ntf domino api
 
Big data week presentation
Big data week presentationBig data week presentation
Big data week presentation
 
Scala and Spring
Scala and SpringScala and Spring
Scala and Spring
 
Java 102 intro to object-oriented programming in java
Java 102   intro to object-oriented programming in javaJava 102   intro to object-oriented programming in java
Java 102 intro to object-oriented programming in java
 
Parallel and Async Programming With C#
Parallel and Async Programming With C#Parallel and Async Programming With C#
Parallel and Async Programming With C#
 
How to crack java script certification
How to crack java script certificationHow to crack java script certification
How to crack java script certification
 
Introduction to jQuery
Introduction to jQueryIntroduction to jQuery
Introduction to jQuery
 
Angular for Java Enterprise Developers: Oracle Code One 2018
Angular for Java Enterprise Developers: Oracle Code One 2018Angular for Java Enterprise Developers: Oracle Code One 2018
Angular for Java Enterprise Developers: Oracle Code One 2018
 

Kürzlich hochgeladen

signals in triangulation .. ...Surveying
signals in triangulation .. ...Surveyingsignals in triangulation .. ...Surveying
signals in triangulation .. ...Surveyingsapna80328
 
SOFTWARE ESTIMATION COCOMO AND FP CALCULATION
SOFTWARE ESTIMATION COCOMO AND FP CALCULATIONSOFTWARE ESTIMATION COCOMO AND FP CALCULATION
SOFTWARE ESTIMATION COCOMO AND FP CALCULATIONSneha Padhiar
 
Engineering Drawing section of solid
Engineering Drawing     section of solidEngineering Drawing     section of solid
Engineering Drawing section of solidnamansinghjarodiya
 
System Simulation and Modelling with types and Event Scheduling
System Simulation and Modelling with types and Event SchedulingSystem Simulation and Modelling with types and Event Scheduling
System Simulation and Modelling with types and Event SchedulingBootNeck1
 
"Exploring the Essential Functions and Design Considerations of Spillways in ...
"Exploring the Essential Functions and Design Considerations of Spillways in ..."Exploring the Essential Functions and Design Considerations of Spillways in ...
"Exploring the Essential Functions and Design Considerations of Spillways in ...Erbil Polytechnic University
 
Python Programming for basic beginners.pptx
Python Programming for basic beginners.pptxPython Programming for basic beginners.pptx
Python Programming for basic beginners.pptxmohitesoham12
 
Novel 3D-Printed Soft Linear and Bending Actuators
Novel 3D-Printed Soft Linear and Bending ActuatorsNovel 3D-Printed Soft Linear and Bending Actuators
Novel 3D-Printed Soft Linear and Bending ActuatorsResearcher Researcher
 
Module-1-(Building Acoustics) Noise Control (Unit-3). pdf
Module-1-(Building Acoustics) Noise Control (Unit-3). pdfModule-1-(Building Acoustics) Noise Control (Unit-3). pdf
Module-1-(Building Acoustics) Noise Control (Unit-3). pdfManish Kumar
 
US Department of Education FAFSA Week of Action
US Department of Education FAFSA Week of ActionUS Department of Education FAFSA Week of Action
US Department of Education FAFSA Week of ActionMebane Rash
 
Prach: A Feature-Rich Platform Empowering the Autism Community
Prach: A Feature-Rich Platform Empowering the Autism CommunityPrach: A Feature-Rich Platform Empowering the Autism Community
Prach: A Feature-Rich Platform Empowering the Autism Communityprachaibot
 
TechTAC® CFD Report Summary: A Comparison of Two Types of Tubing Anchor Catchers
TechTAC® CFD Report Summary: A Comparison of Two Types of Tubing Anchor CatchersTechTAC® CFD Report Summary: A Comparison of Two Types of Tubing Anchor Catchers
TechTAC® CFD Report Summary: A Comparison of Two Types of Tubing Anchor Catcherssdickerson1
 
Research Methodology for Engineering pdf
Research Methodology for Engineering pdfResearch Methodology for Engineering pdf
Research Methodology for Engineering pdfCaalaaAbdulkerim
 
KCD Costa Rica 2024 - Nephio para parvulitos
KCD Costa Rica 2024 - Nephio para parvulitosKCD Costa Rica 2024 - Nephio para parvulitos
KCD Costa Rica 2024 - Nephio para parvulitosVictor Morales
 
multiple access in wireless communication
multiple access in wireless communicationmultiple access in wireless communication
multiple access in wireless communicationpanditadesh123
 
Mine Environment II Lab_MI10448MI__________.pptx
Mine Environment II Lab_MI10448MI__________.pptxMine Environment II Lab_MI10448MI__________.pptx
Mine Environment II Lab_MI10448MI__________.pptxRomil Mishra
 
Input Output Management in Operating System
Input Output Management in Operating SystemInput Output Management in Operating System
Input Output Management in Operating SystemRashmi Bhat
 
11. Properties of Liquid Fuels in Energy Engineering.pdf
11. Properties of Liquid Fuels in Energy Engineering.pdf11. Properties of Liquid Fuels in Energy Engineering.pdf
11. Properties of Liquid Fuels in Energy Engineering.pdfHafizMudaserAhmad
 
List of Accredited Concrete Batching Plant.pdf
List of Accredited Concrete Batching Plant.pdfList of Accredited Concrete Batching Plant.pdf
List of Accredited Concrete Batching Plant.pdfisabel213075
 
Robotics-Asimov's Laws, Mechanical Subsystems, Robot Kinematics, Robot Dynami...
Robotics-Asimov's Laws, Mechanical Subsystems, Robot Kinematics, Robot Dynami...Robotics-Asimov's Laws, Mechanical Subsystems, Robot Kinematics, Robot Dynami...
Robotics-Asimov's Laws, Mechanical Subsystems, Robot Kinematics, Robot Dynami...Sumanth A
 

Kürzlich hochgeladen (20)

signals in triangulation .. ...Surveying
signals in triangulation .. ...Surveyingsignals in triangulation .. ...Surveying
signals in triangulation .. ...Surveying
 
SOFTWARE ESTIMATION COCOMO AND FP CALCULATION
SOFTWARE ESTIMATION COCOMO AND FP CALCULATIONSOFTWARE ESTIMATION COCOMO AND FP CALCULATION
SOFTWARE ESTIMATION COCOMO AND FP CALCULATION
 
Engineering Drawing section of solid
Engineering Drawing     section of solidEngineering Drawing     section of solid
Engineering Drawing section of solid
 
System Simulation and Modelling with types and Event Scheduling
System Simulation and Modelling with types and Event SchedulingSystem Simulation and Modelling with types and Event Scheduling
System Simulation and Modelling with types and Event Scheduling
 
"Exploring the Essential Functions and Design Considerations of Spillways in ...
"Exploring the Essential Functions and Design Considerations of Spillways in ..."Exploring the Essential Functions and Design Considerations of Spillways in ...
"Exploring the Essential Functions and Design Considerations of Spillways in ...
 
Python Programming for basic beginners.pptx
Python Programming for basic beginners.pptxPython Programming for basic beginners.pptx
Python Programming for basic beginners.pptx
 
Novel 3D-Printed Soft Linear and Bending Actuators
Novel 3D-Printed Soft Linear and Bending ActuatorsNovel 3D-Printed Soft Linear and Bending Actuators
Novel 3D-Printed Soft Linear and Bending Actuators
 
Module-1-(Building Acoustics) Noise Control (Unit-3). pdf
Module-1-(Building Acoustics) Noise Control (Unit-3). pdfModule-1-(Building Acoustics) Noise Control (Unit-3). pdf
Module-1-(Building Acoustics) Noise Control (Unit-3). pdf
 
US Department of Education FAFSA Week of Action
US Department of Education FAFSA Week of ActionUS Department of Education FAFSA Week of Action
US Department of Education FAFSA Week of Action
 
Prach: A Feature-Rich Platform Empowering the Autism Community
Prach: A Feature-Rich Platform Empowering the Autism CommunityPrach: A Feature-Rich Platform Empowering the Autism Community
Prach: A Feature-Rich Platform Empowering the Autism Community
 
TechTAC® CFD Report Summary: A Comparison of Two Types of Tubing Anchor Catchers
TechTAC® CFD Report Summary: A Comparison of Two Types of Tubing Anchor CatchersTechTAC® CFD Report Summary: A Comparison of Two Types of Tubing Anchor Catchers
TechTAC® CFD Report Summary: A Comparison of Two Types of Tubing Anchor Catchers
 
Research Methodology for Engineering pdf
Research Methodology for Engineering pdfResearch Methodology for Engineering pdf
Research Methodology for Engineering pdf
 
KCD Costa Rica 2024 - Nephio para parvulitos
KCD Costa Rica 2024 - Nephio para parvulitosKCD Costa Rica 2024 - Nephio para parvulitos
KCD Costa Rica 2024 - Nephio para parvulitos
 
multiple access in wireless communication
multiple access in wireless communicationmultiple access in wireless communication
multiple access in wireless communication
 
Mine Environment II Lab_MI10448MI__________.pptx
Mine Environment II Lab_MI10448MI__________.pptxMine Environment II Lab_MI10448MI__________.pptx
Mine Environment II Lab_MI10448MI__________.pptx
 
Input Output Management in Operating System
Input Output Management in Operating SystemInput Output Management in Operating System
Input Output Management in Operating System
 
11. Properties of Liquid Fuels in Energy Engineering.pdf
11. Properties of Liquid Fuels in Energy Engineering.pdf11. Properties of Liquid Fuels in Energy Engineering.pdf
11. Properties of Liquid Fuels in Energy Engineering.pdf
 
Designing pile caps according to ACI 318-19.pptx
Designing pile caps according to ACI 318-19.pptxDesigning pile caps according to ACI 318-19.pptx
Designing pile caps according to ACI 318-19.pptx
 
List of Accredited Concrete Batching Plant.pdf
List of Accredited Concrete Batching Plant.pdfList of Accredited Concrete Batching Plant.pdf
List of Accredited Concrete Batching Plant.pdf
 
Robotics-Asimov's Laws, Mechanical Subsystems, Robot Kinematics, Robot Dynami...
Robotics-Asimov's Laws, Mechanical Subsystems, Robot Kinematics, Robot Dynami...Robotics-Asimov's Laws, Mechanical Subsystems, Robot Kinematics, Robot Dynami...
Robotics-Asimov's Laws, Mechanical Subsystems, Robot Kinematics, Robot Dynami...
 

Java 8

  • 1. JAVA 8 Create The Future
  • 2. What's New in JDK 8 • Lambda Expressions • Method references • Streams • Default methods • Date and Time API • Nashorn engine
  • 3. What's New in JDK 8 • Lambda Expressions • Method references • Streams • Default methods • Date and Time API • Nashorn engine
  • 4. Lambda Expressions • Simply, It is a method to eliminate anonymous classes and nested calling functions like the action should be taken when someone clicks a button.
  • 5. Lambda Expressions • Why Lambda Expressions? • Ex: for (int i = 0; i < names.size(); i++) { System.out.println(names.get(i)); }
  • 6. Lambda Expressions • Why Lambda Expressions? • It is Simple names.foreach (name->System.out.println(name))
  • 7. Lambda Expressions • Why Lambda Expressions? • It eliminates nested calling functions & anonymous classes . btn.setOnAction(new EventHandler<ActionEvent>() { @Override public void handle(ActionEvent event) { System.out.println("Hello World!"); } });
  • 8. Lambda Expressions • Why Lambda Expressions? • It eliminates nested calling functions & anonymous classes . btn.setOnAction(event -> System.out.println("Hello World!") );
  • 9. What's New in JDK 8 • Lambda Expressions • Method references • Streams • Default methods • Date and Time API • Nashorn engine
  • 10. Method References • It is easy-to-read lambda expressions for methods that already have a name by referring to the existing method by name.
  • 11. Method References • Why Method References? • If there is a function in person object compares ages. Arrays.sort(personsArray, (a, b) -> Person.compareByAge(a, b) ); When using Method References Arrays.sort(personsArray, Person::compareByAge);
  • 12. Method References • Kinds of Method References Kind Example Reference to an instance method of a particular object persons.foreach (System.out.println(preson::getEmail)) Reference to a static method Arrays.sort(personsList, Person::compareByAge); Reference to an instance method of an arbitrary object of a particular type Arrays.sort(stringArray, String::compareToIgnoreCase); Reference to a constructor transferElements(personsList, HashSet<Person>::new);
  • 13. What's New in JDK 8 • Lambda Expressions • Method references • Streams • Default methods • Date and Time API • Nashorn engine
  • 14. Streams • It is a sequence of elements. Unlike a collection, it is not a data structure that stores elements but it carries values from it.
  • 15. Streams • Why Streams? • Parallelism is the main target today. big data multicore cloud computing
  • 16. Streams • Why Streams? • Parallelism is the main target today. for (int i = 0; i < names.size(); i++) { System.out.println(names.get(i)); } Ques: How to use Parallelism?
  • 17. Streams • Why Streams? • Simply you can Choose between Serial or parallel. names.stream().foreach (name->System.out.println(name)) names.parallelStream().foreach. (name->System.out.println(name))
  • 18. Streams • Why Streams? • It makes a pipeline (a sequence of aggregate operations) names.stream .filter(e -> e.equals(“java”)) .forEach(e -> System.out.println(e));
  • 19. What's New in JDK 8 • Lambda Expressions • Method references • Streams • Default methods • Date and Time API • Nashorn engine
  • 20. Default methods • It enables you to add new functionality to the interfaces of your libraries and ensure compatibility with code written for older versions of those interfaces.
  • 21. Default methods • Why Default methods? • Consider the following interface TimeClient. public interface TimeClient { void setTime(int hour, int minute, int second); void setDate(int day, int month, int year); }
  • 22. Default methods • Why Default methods? • The following class SimpleTimeClient impelements it. public class SimpleTimeClient implements TimeClient { void setTime(int hour, int minute, int second){ //some code } void setDate(int day, int month, int year){ //some code } }
  • 23. Default methods • Why Default methods? • How to add new functionality to the TimeClient interface?
  • 24. Default methods • Why Default methods? • How to add new functionality to the TimeClient interface? public interface TimeClient { ……… String getDateZone(String zoneString); }
  • 25. Default methods • Why Default methods? • How to add new functionality to the TimeClient interface? public class SimpleTimeClient implements TimeClient{ ……… String getDateZone(String zoneString){ // some code } }
  • 26. Default methods • Default Methods • You can define default method in interfaces instead. public interface TimeClient { ……… default getDateZone(String zoneString) { // some code } }
  • 27. Default methods • Static Methods • Also, you can define static methods in interfaces. public interface TimeClient { ……… static ZoneId getZoneId (String zoneString) { // some code } }
  • 28. What's New in JDK 8 • Lambda Expressions • Method references • Streams • Default methods • Date and Time API • Nashorn engine
  • 29. Date and Time API • Why do we need a new date and time library? • (java.util.Date and SimpleDateFormatter) aren’t thread-safe. • Poor API design. For example, years in java.util.Date start at 1900, months start at 1, and days start at 0—not very intuitive. • Inadequate support for the date and time use cases of ordinary developers.
  • 30. Date and Time API • Why do we need a new date and time library? • (java.util.Date and SimpleDateFormatter) aren’t thread-safe. • Poor API design. For example, years in java.util.Date start at 1900, months start at 1, and days start at 0—not very intuitive. • Inadequate support for the date and time use cases of ordinary developers. These issues, and several others, have led to “Time API”.
  • 31. Date and Time API • Thread Safe • The classes are immutable “no setters”. LocalDateTime timePoint = LocalDateTime.now( ); // it is returning a new object instead of setting LocalDateTime thePast = timePoint.withDayOfMonth( 10).withYear(2010); /* You can use direct manipulation methods, or pass a value and field pair */ LocalDateTime yetAnother = thePast.plusWeeks( 3).plus(3, ChronoUnit.WEEKS);
  • 32. Date and Time API • Periods • Represents values such as “3 years 2 months and 1 day” Period period = Period.of(3, 2, 1); // You can modify the values of dates using periods LocalDateTime newDate = timePoint.plus(period);
  • 33. Date and Time API • Durations • Represents values such as “3 seconds and 5 nanoseconds” Duration duration = Duration.ofSeconds(3, 5); // You can modify the values of dates using durations LocalDateTime newDate = timePoint.plus(duration);
  • 34. Date and Time API • Time Truncation • The truncatedTo method allows you to truncate a value to a field LocalTime truncatedTime = time.truncatedTo(ChronoUnit.SECONDS);
  • 35. Date and Time API • Time Zones • You can specify the zone id when creating a zoned date time ZoneId id = ZoneId.of("Europe/Paris"); ZonedDateTime zoned = ZonedDateTime.of(timePoint, id); Hint: There is an existing time zone class in Java—java.util.TimeZone— but it isn’t used by Java SE 8 because Time API classes are immutable and time zone is mutable.
  • 36. Date and Time API • Chronologies • Is the concept of representing a factory for calendaring system. Chronology: ChronoLocalDate ChronoLocalDateTime ChronoZonedDateTime
  • 37. Date and Time API • Chronologies • Is the concept of representing a factory for calendaring system. Chronology: ChronoLocalDate ChronoLocalDateTime ChronoZonedDateTime These classes are there purely for developers who are working on highly internationalized applications
  • 38. Date and Time API • HijrahChronology [Class Implements Chronology] • Follows Hijrah calendar system observation “new moon occurrence” Chronology ID Calendar Type Locale extension Description Hijrah-umalqura islamic-umalqura ca-islamic-umalqura Islamic - Umm Al-Qura calendar of Saudi Arabia
  • 39. Date and Time API • HijrahDate • HijrahDate is created bound to a particular HijrahChronology HijrahChronology calendar = HijrahChronology.INSTANCE; HijrahDate date=calendar.dateNow(); // result is Hijrah-umalqura AH 1436-01-12 //”rtl printing”
  • 40. Date and Time API • HijrahDate • HijrahDate is created bound to a particular HijrahChronology HijrahChronology calendar = HijrahChronology.INSTANCE; HijrahDate date=calendar.dateNow(); date.minus(2, ChronoUnit.DAYS); date.plus(3, ChronoUnit.YEARS); HijrahDate secondDate=calendar.date(1435, 4, 1);//rtl date.isAfter(secondDate); date.isBefore(secondDate);
  • 41. What's New in JDK 8 • Lambda Expressions • Method references • Streams • Default methods • Date and Time API • Nashorn engine
  • 42. Nashorn engine • Nashorn is an embedded scripting engine inside Java applications and how Java types can be implemented and extended from JavaScript, providing a seamless integration between the two languages.
  • 43. Nashorn engine • What’s new in Nashorn • run JavaScript programs from the command line with tool jjs var hello = function() { print("Hello Nashorn!"); }; hello(); Evaluating it is as simple as this: $ jjs hello.js $ Hello Nashorn!
  • 44. Nashorn engine • What’s new in Nashorn • Embedding Oracle Nashorn in java Apps public class Hello { public static void main(String... args) throws Throwable { ScriptEngineManager engineManager = new ScriptEngineManager(); ScriptEngine engine = engineManager.getEngineByName("nashorn"); engine.eval("function sum(a, b) { return a + b; }"); System.out.println(engine.eval("sum(1, 2);")); } }
  • 45. Nashorn engine • What’s new in Nashorn • Java seen in javascript Java objects can be instantiated using the new operator: var file = new java.io.File("sample.js"); print(file.getAbsolutePath()); print(file.absolutePath);
  • 46. Nashorn engine • What’s new in Nashorn • Java seen in javascript [ dealing with collections] var stack = new java.util.LinkedList(); [1, 2, 3, 4].forEach(function(item) { stack.push(item); }); tour through the new Java 8 stream APIs to sort the collection: var sorted = stack.stream().sorted().toArray();
  • 47. Nashorn engine • What’s new in Nashorn • Java seen in javascript [ Imports] importClass(java.util.HashSet); var set = new HashSet(); importPackage(java.util); var list = new ArrayList();
  • 48. Nashorn engine • What’s new in Nashorn • Java seen in javascript [JavaImporter] . var CollectionsAndFiles = new JavaImporter( java.util, java.i); It is not global as import classes: with (CollectionsAndFiles) { var files = new LinkedHashSet(); files.add(new File("Plop")); files.add(new File("Foo"));}
  • 49. Nashorn engine • What’s new in Nashorn • The Java.type used to reference to precise Java types. var LinkedList = Java.type( "java.util.LinkedList"); var primitiveInt = Java.type( "int"); var arrayOfInts = Java.type( "int[]"); var list = new LinkedList; var a = new arrayOfInts(3);
  • 50. Nashorn engine • What’s new in Nashorn • Extending java type var iterator = new java.util.Iterator({ i: 0, hasNext: function() { return this.i < 10; }, next: function() { return this.i++; } });
  • 51. Nashorn engine • What’s new in Nashorn • Support Lambda Expression var odd = list.stream().filter( function(i) { return i % 2 == 0; }); Like this: var odd = list.stream().filter( function(i) i % 2 == 0);
  • 52. References • https://docs.oracle.com/javase/tutorial/java/javaOO/lambdaexpressions.html • https://docs.oracle.com/javase/tutorial/java/javaOO/methodreferences.html • https://docs.oracle.com/javase/tutorial/collections/streams/index.html#pipelines • https://docs.oracle.com/javase/tutorial/collections/streams/parallelism.html • https://docs.oracle.com/javase/tutorial/java/IandI/defaultmethods.html • http://www.oracle.com/technetwork/articles/java/jf14-date-time-2125367.html • https://docs.oracle.com/javase/8/docs/api/java/time/chrono/Chronology.html • http://docs.oracle.com/javase/8/docs/api/java/time/chrono/HijrahDate.html • http://www.oracle.com/technetwork/articles/java/jf14-nashorn-2126515.html • https://developer.mozilla.org/en-US/docs/Mozilla/Projects/Rhino • http://www.slideshare.net/zainalpour/whats-new-in-java-8?qid=07aab8b4-6251-45f3- af26-797bc21d8758&v=default&b=&from_search=1 • Installing JDK8 and LUNA Eclipse • http://www.oracle.com/technetwork/java/javase/downloads/jdk8-downloads- 2133151.html • http://www.eclipse.org/downloads/java8/

Hinweis der Redaktion

  1. Oracle’s JDK include a command-line tool called jjs. It can be found in the bin/ folder of a JDK installation along with the well-known java, javac, or jar tools.
  2. Mozilla Rhino is an open-source implementation of JavaScript written entirely in Java. It is typically embedded into Java applications to provide scripting to end users. It is embedded in J2SE 6 as the default Java scripting engine.
  3. print(iterator instanceof Java.type("java.util.Iterator")); while (iterator.hasNext()) { print("-> " + iterator.next()); }  Result: true -> 0 -> 1 -> 2 -> 3 -> 4 -> 5 -> 6 -> 7 -> 8 -> 9