SlideShare a Scribd company logo
1 of 14
Srimanta Sahu
Contents
• Brief introduction to Java
• Why Java 8
• Lambda expressions
• Streams
• Date and Time APIs
• Nashorn
• New APIs to join Strings
Brief introduction to Java
• Java is a high-level programming language
– A high-level language cannot run directly on a computer, it
needs to be translated into a machine language by a
program called Compiler
• Java source code is compiled to intermediate byte
code, which is interpreted and executed by a JVM
– A virtual machine is a software application that simulates a
computer but hides the underlying OS and hardware from
the programs that interact with it
• Java’s byte-codes are portable between platforms,
i.e., “Write Once, Run Anywhere”
• Java is a computing platform
– It consists of two essential software – JRE and JDK
Why Java 8 ?
• Java 8 is the latest version of Java, which contains
important enhancements to improve performance,
stability and security of Java applications
• The addition of Lambda expressions to the language
brings Java to the forefront of functional
programming
• New parallel processing capabilities are added to the
framework for efficiently carrying out heavy
operations such as sorting, filtering and mapping
• A new lightweight, high performance implementation
of JavaScript engine is integrated to JDK and is
available to Java applications via existing APIs
Lambda expressions
• Lambda expressions are anonymous functions
which are used to instantiate interfaces with single
abstract method
• Replaces more verbose class declarations and
eliminates unnecessary syntaxes
• Significantly reduces the amount of code and
makes it lot more readable
• Doesn't provide any performance benefit, as the
underlying functionality remains exactly the same
• Facilitates functional programming, and simplifies
the development a lot
Lambda expressions Syntax
• Syntax : ( parameters… ) -> { method body };
• Important characteristics of lambda expressions
– Optional type declaration − No need to declare the type of a
parameter, the compiler can inference the same from the
single abstract method in interface
– Optional parenthesis around parameter − No need to
declare a single parameter in parenthesis, for multiple
parameters, parentheses are required
– Optional curly braces − No need to use curly braces in
method body, if the body contains a single statement
– Optional return keyword − The compiler automatically
returns the value, if the expression has a single value to
return, curly braces are required in-case method body
explicitly returns a value
Functional Interfaces
• Where to use Lambda expression
– Lambda expressions can only appear in places where they
will be assigned to a variable whose type is a functional
interface
• Functional Interface
– A Functional Interface has a single abstract method (not
methods inherited from Object and declared as abstract)
– Instances of functional interfaces can be created with
lambda expressions, method references, or constructor
references
– Functional Interfaces included with Java runtime are –
Runnable, Callable, Comparator, Comparable, Iterable
– Java 8 added a number of new functional interfaces in
package java.util.function
Important FIs and Method
References
• forEach method
– In Java 8, we can use lambda expression to traverse
collection of items, mainly lists and sets
– New default implementation of forEach in Iterable interface
is - default void forEach(Consumer<? super T> action),
where Consumer is a FI with abstract method - accept(T t)
• Predicate FI
– Predicate FI has a single abstract method – test(T t), which
can be used to wrap up conditional processing and make
conditional code much cleaner
• Method References
– Method reference give us a way of naming a method that
we want to call instead of calling it directly, goal is to make
the code more concise and readable
Default and Static Methods in
Interface
• Prior to Java 8, interfaces can only contain abstract
methods and constant declarations, but Java 8 has
added support for default and static methods too
• Default Methods
– A default method is an instance method defined in an
interface whose method begins with the ‘default’ keyword
– Every class that implements the interface inherits the
interface's default methods and can override them
• Static Methods
– A static method defined inside an interface begins with the
‘static’ keyword
– Static method always remains as a part of the interface and
not part of the implementing classes
Java 8 Stream
• In Java 8, we have a new way of managing,
traversing, filtering and aggregating collections with
the Stream APIs
• A stream represents a sequence of elements and
supports different kind of operations to perform
computations upon those elements
• Java 8 supports two kinds of collection streams
known as Sequential stream and Parallel stream
• To avoid divide by zero problem in case of
averaging, we can use a type of Optional variable
• mapTo* - takes a complex object and extracts a
simple primitive value from it
Date and Time APIs
• Java 8 includes a complete set of new APIs for
managing date and time values
• The classes that actually hold the data in new Date
and Time APIs are all immutable and thread-safe, so
we don’t have to worry about passing the object
around multi-threading environment and while using
them with parallel stream
• LocalDate | LocalTime | LocalDateTime classes
simplify the development where timezones are not
required and ZonedDateTime class is used where
timezone needs to be considered
• All classes of these new APIs are members of the
java.time package
Nashorn
• Nashorn is a JavaScript engine developed in Java
programming language
• It allows to code in JavaScript instead of Java using
the dynamic coding capabilities that language
supports and we can write complete code blocks
using JavaScript and then execute them in the
context of Java class
• Its always a better practise to put all the JavaScript
code into a separate file
• The Nashorn JavaScript engine can either be used
programmatically from Java programs or by utilizing
the command line tool jjs, which is located in
$JAVA_HOME/bin
StringJoiner Class and
String.join Method
• StringJoiner class is used to construct a sequence
of characters separated by a delimiter and
optionally starting with a supplied prefix and ending
with a supplied suffix
• String.join method returns a String composed of
copies of the CharSequence elements joined
together with a copy of the specified delimiter
• String.join method is an abbreviated call in a sense
but under the hood it delegates to StringJoiner
class
References
• The Complete Java Tutorial with Java 8 |
Udemy
• Oracle Docs
• What's New in JDK 8

More Related Content

What's hot

What's hot (17)

Lambdas
LambdasLambdas
Lambdas
 
Programming Paradigm & Languages
Programming Paradigm & LanguagesProgramming Paradigm & Languages
Programming Paradigm & Languages
 
Syntax directed-translation
Syntax directed-translationSyntax directed-translation
Syntax directed-translation
 
Java
JavaJava
Java
 
Java script
Java scriptJava script
Java script
 
L06 Using Design Patterns
L06 Using Design PatternsL06 Using Design Patterns
L06 Using Design Patterns
 
JVM
JVMJVM
JVM
 
Java tokens
Java tokensJava tokens
Java tokens
 
Java virtual machine
Java virtual machineJava virtual machine
Java virtual machine
 
Atks (Arabic Toolkit services)
Atks (Arabic Toolkit services)Atks (Arabic Toolkit services)
Atks (Arabic Toolkit services)
 
Java architecture
Java architectureJava architecture
Java architecture
 
Practices and tools for building better API (JFall 2013)
Practices and tools for building better API (JFall 2013)Practices and tools for building better API (JFall 2013)
Practices and tools for building better API (JFall 2013)
 
Features of java
Features of javaFeatures of java
Features of java
 
Javanotes
JavanotesJavanotes
Javanotes
 
Compiler Design Lecture Notes
Compiler Design Lecture NotesCompiler Design Lecture Notes
Compiler Design Lecture Notes
 
Functional Programming In Jdk8
Functional Programming In Jdk8 Functional Programming In Jdk8
Functional Programming In Jdk8
 
MuleSoft Surat Virtual Meetup#30 - Flat File Schemas Transformation With Mule...
MuleSoft Surat Virtual Meetup#30 - Flat File Schemas Transformation With Mule...MuleSoft Surat Virtual Meetup#30 - Flat File Schemas Transformation With Mule...
MuleSoft Surat Virtual Meetup#30 - Flat File Schemas Transformation With Mule...
 

Viewers also liked

Viewers also liked (20)

Videokevin
VideokevinVideokevin
Videokevin
 
Silaboims
SilaboimsSilaboims
Silaboims
 
Redes ....
Redes ....Redes ....
Redes ....
 
retoque
retoque retoque
retoque
 
Aprender por proyectos[1]
Aprender por proyectos[1]Aprender por proyectos[1]
Aprender por proyectos[1]
 
Tecnologías y sistema de conmutación y enrutamiento
Tecnologías y sistema de conmutación y enrutamientoTecnologías y sistema de conmutación y enrutamiento
Tecnologías y sistema de conmutación y enrutamiento
 
My power point
My power pointMy power point
My power point
 
Conscius instructor disciplinado e incondicional
Conscius instructor disciplinado e incondicionalConscius instructor disciplinado e incondicional
Conscius instructor disciplinado e incondicional
 
Buscar información educativa
Buscar información educativaBuscar información educativa
Buscar información educativa
 
Ensayo numeros
Ensayo numerosEnsayo numeros
Ensayo numeros
 
Algebra matrices
Algebra matricesAlgebra matrices
Algebra matrices
 
Federico García Lorca-En el cine
Federico García Lorca-En el cineFederico García Lorca-En el cine
Federico García Lorca-En el cine
 
Federico García Lorca-En el cine
Federico García Lorca-En el cineFederico García Lorca-En el cine
Federico García Lorca-En el cine
 
Sistema nervioso
Sistema nerviosoSistema nervioso
Sistema nervioso
 
Informe a 6
Informe a 6Informe a 6
Informe a 6
 
Informe a 1
Informe a 1Informe a 1
Informe a 1
 
Automatizacion leslie
Automatizacion leslieAutomatizacion leslie
Automatizacion leslie
 
Dunia quintero f cris (1)
Dunia quintero f cris (1)Dunia quintero f cris (1)
Dunia quintero f cris (1)
 
Pauly222
Pauly222Pauly222
Pauly222
 
Presentacion
PresentacionPresentacion
Presentacion
 

Similar to A-Brief-Introduction-To-JAVA8_By_Srimanta_Sahu

Improved Developer Productivity In JDK8
Improved Developer Productivity In JDK8Improved Developer Productivity In JDK8
Improved Developer Productivity In JDK8Simon Ritter
 
Playing with Java Classes and Bytecode
Playing with Java Classes and BytecodePlaying with Java Classes and Bytecode
Playing with Java Classes and BytecodeYoav Avrahami
 
Complete PPT about the Java lokesh kept it
Complete PPT about the Java lokesh kept itComplete PPT about the Java lokesh kept it
Complete PPT about the Java lokesh kept itlokeshpappaka10
 
Skillwise Elementary Java Programming
Skillwise Elementary Java ProgrammingSkillwise Elementary Java Programming
Skillwise Elementary Java ProgrammingSkillwise Group
 
Unit 1 Core Java for Compter Science 3rd
Unit 1 Core Java for Compter Science 3rdUnit 1 Core Java for Compter Science 3rd
Unit 1 Core Java for Compter Science 3rdprat0ham
 
Compiler Construction
Compiler ConstructionCompiler Construction
Compiler ConstructionAhmed Raza
 
Learn Java with Dr. Rifat Shahriyar
Learn Java with Dr. Rifat ShahriyarLearn Java with Dr. Rifat Shahriyar
Learn Java with Dr. Rifat ShahriyarAbir Mohammad
 
Stream Api.pdf
Stream Api.pdfStream Api.pdf
Stream Api.pdfAkaks
 
java 8 new features
java 8 new features java 8 new features
java 8 new features Rohit Verma
 
1 java programming- introduction
1  java programming- introduction1  java programming- introduction
1 java programming- introductionjyoti_lakhani
 
Swift programming language
Swift programming languageSwift programming language
Swift programming languageNijo Job
 
Programming language paradigms
Programming language paradigmsProgramming language paradigms
Programming language paradigmsAshok Raj
 
JAVA object oriented programming (oop).ppt
JAVA object oriented programming (oop).pptJAVA object oriented programming (oop).ppt
JAVA object oriented programming (oop).pptAliyaJav
 

Similar to A-Brief-Introduction-To-JAVA8_By_Srimanta_Sahu (20)

Java
JavaJava
Java
 
Improved Developer Productivity In JDK8
Improved Developer Productivity In JDK8Improved Developer Productivity In JDK8
Improved Developer Productivity In JDK8
 
Comp102 lec 3
Comp102   lec 3Comp102   lec 3
Comp102 lec 3
 
Playing with Java Classes and Bytecode
Playing with Java Classes and BytecodePlaying with Java Classes and Bytecode
Playing with Java Classes and Bytecode
 
Complete PPT about the Java lokesh kept it
Complete PPT about the Java lokesh kept itComplete PPT about the Java lokesh kept it
Complete PPT about the Java lokesh kept it
 
Skillwise Elementary Java Programming
Skillwise Elementary Java ProgrammingSkillwise Elementary Java Programming
Skillwise Elementary Java Programming
 
Unit 1 Core Java for Compter Science 3rd
Unit 1 Core Java for Compter Science 3rdUnit 1 Core Java for Compter Science 3rd
Unit 1 Core Java for Compter Science 3rd
 
Compiler Construction
Compiler ConstructionCompiler Construction
Compiler Construction
 
Lambdas in Java 8
Lambdas in Java 8Lambdas in Java 8
Lambdas in Java 8
 
Learn Java with Dr. Rifat Shahriyar
Learn Java with Dr. Rifat ShahriyarLearn Java with Dr. Rifat Shahriyar
Learn Java with Dr. Rifat Shahriyar
 
Stream Api.pdf
Stream Api.pdfStream Api.pdf
Stream Api.pdf
 
java 8 new features
java 8 new features java 8 new features
java 8 new features
 
java.pptx
java.pptxjava.pptx
java.pptx
 
JVM
JVMJVM
JVM
 
1 java programming- introduction
1  java programming- introduction1  java programming- introduction
1 java programming- introduction
 
Swift programming language
Swift programming languageSwift programming language
Swift programming language
 
JAVA PROGRAM CONSTRUCTS OR LANGUAGE BASICS.pptx
JAVA PROGRAM CONSTRUCTS OR LANGUAGE BASICS.pptxJAVA PROGRAM CONSTRUCTS OR LANGUAGE BASICS.pptx
JAVA PROGRAM CONSTRUCTS OR LANGUAGE BASICS.pptx
 
Programming language paradigms
Programming language paradigmsProgramming language paradigms
Programming language paradigms
 
Introduction to Spring & Spring BootFramework
Introduction to Spring  & Spring BootFrameworkIntroduction to Spring  & Spring BootFramework
Introduction to Spring & Spring BootFramework
 
JAVA object oriented programming (oop).ppt
JAVA object oriented programming (oop).pptJAVA object oriented programming (oop).ppt
JAVA object oriented programming (oop).ppt
 

A-Brief-Introduction-To-JAVA8_By_Srimanta_Sahu

  • 2. Contents • Brief introduction to Java • Why Java 8 • Lambda expressions • Streams • Date and Time APIs • Nashorn • New APIs to join Strings
  • 3. Brief introduction to Java • Java is a high-level programming language – A high-level language cannot run directly on a computer, it needs to be translated into a machine language by a program called Compiler • Java source code is compiled to intermediate byte code, which is interpreted and executed by a JVM – A virtual machine is a software application that simulates a computer but hides the underlying OS and hardware from the programs that interact with it • Java’s byte-codes are portable between platforms, i.e., “Write Once, Run Anywhere” • Java is a computing platform – It consists of two essential software – JRE and JDK
  • 4. Why Java 8 ? • Java 8 is the latest version of Java, which contains important enhancements to improve performance, stability and security of Java applications • The addition of Lambda expressions to the language brings Java to the forefront of functional programming • New parallel processing capabilities are added to the framework for efficiently carrying out heavy operations such as sorting, filtering and mapping • A new lightweight, high performance implementation of JavaScript engine is integrated to JDK and is available to Java applications via existing APIs
  • 5. Lambda expressions • Lambda expressions are anonymous functions which are used to instantiate interfaces with single abstract method • Replaces more verbose class declarations and eliminates unnecessary syntaxes • Significantly reduces the amount of code and makes it lot more readable • Doesn't provide any performance benefit, as the underlying functionality remains exactly the same • Facilitates functional programming, and simplifies the development a lot
  • 6. Lambda expressions Syntax • Syntax : ( parameters… ) -> { method body }; • Important characteristics of lambda expressions – Optional type declaration − No need to declare the type of a parameter, the compiler can inference the same from the single abstract method in interface – Optional parenthesis around parameter − No need to declare a single parameter in parenthesis, for multiple parameters, parentheses are required – Optional curly braces − No need to use curly braces in method body, if the body contains a single statement – Optional return keyword − The compiler automatically returns the value, if the expression has a single value to return, curly braces are required in-case method body explicitly returns a value
  • 7. Functional Interfaces • Where to use Lambda expression – Lambda expressions can only appear in places where they will be assigned to a variable whose type is a functional interface • Functional Interface – A Functional Interface has a single abstract method (not methods inherited from Object and declared as abstract) – Instances of functional interfaces can be created with lambda expressions, method references, or constructor references – Functional Interfaces included with Java runtime are – Runnable, Callable, Comparator, Comparable, Iterable – Java 8 added a number of new functional interfaces in package java.util.function
  • 8. Important FIs and Method References • forEach method – In Java 8, we can use lambda expression to traverse collection of items, mainly lists and sets – New default implementation of forEach in Iterable interface is - default void forEach(Consumer<? super T> action), where Consumer is a FI with abstract method - accept(T t) • Predicate FI – Predicate FI has a single abstract method – test(T t), which can be used to wrap up conditional processing and make conditional code much cleaner • Method References – Method reference give us a way of naming a method that we want to call instead of calling it directly, goal is to make the code more concise and readable
  • 9. Default and Static Methods in Interface • Prior to Java 8, interfaces can only contain abstract methods and constant declarations, but Java 8 has added support for default and static methods too • Default Methods – A default method is an instance method defined in an interface whose method begins with the ‘default’ keyword – Every class that implements the interface inherits the interface's default methods and can override them • Static Methods – A static method defined inside an interface begins with the ‘static’ keyword – Static method always remains as a part of the interface and not part of the implementing classes
  • 10. Java 8 Stream • In Java 8, we have a new way of managing, traversing, filtering and aggregating collections with the Stream APIs • A stream represents a sequence of elements and supports different kind of operations to perform computations upon those elements • Java 8 supports two kinds of collection streams known as Sequential stream and Parallel stream • To avoid divide by zero problem in case of averaging, we can use a type of Optional variable • mapTo* - takes a complex object and extracts a simple primitive value from it
  • 11. Date and Time APIs • Java 8 includes a complete set of new APIs for managing date and time values • The classes that actually hold the data in new Date and Time APIs are all immutable and thread-safe, so we don’t have to worry about passing the object around multi-threading environment and while using them with parallel stream • LocalDate | LocalTime | LocalDateTime classes simplify the development where timezones are not required and ZonedDateTime class is used where timezone needs to be considered • All classes of these new APIs are members of the java.time package
  • 12. Nashorn • Nashorn is a JavaScript engine developed in Java programming language • It allows to code in JavaScript instead of Java using the dynamic coding capabilities that language supports and we can write complete code blocks using JavaScript and then execute them in the context of Java class • Its always a better practise to put all the JavaScript code into a separate file • The Nashorn JavaScript engine can either be used programmatically from Java programs or by utilizing the command line tool jjs, which is located in $JAVA_HOME/bin
  • 13. StringJoiner Class and String.join Method • StringJoiner class is used to construct a sequence of characters separated by a delimiter and optionally starting with a supplied prefix and ending with a supplied suffix • String.join method returns a String composed of copies of the CharSequence elements joined together with a copy of the specified delimiter • String.join method is an abbreviated call in a sense but under the hood it delegates to StringJoiner class
  • 14. References • The Complete Java Tutorial with Java 8 | Udemy • Oracle Docs • What's New in JDK 8