SlideShare a Scribd company logo
1 of 22
Java 8 Features
Elias Hasnat
http://github.com/claymodel
Java 8 Features
1. Default and Static methods in Interface
2. Lambda Expressions
3. Optional
4. Streams
5. Method References
6. Data Time API
7. Nashorn Javascript Engine
8. Parallel Arrays
1. Interface Method (Default & Static)
=> Java 8 introduces new features to interfaces.
=> Before java 8 interface having only abstract methods but
now java 8 added two more type of methods to interface.
a. First one is default method. A method which is having a default keyword
with method body. Actually interfaces wont have any implemented
methods but now with java 8 default method we can add a method with
default implementation by using "default " keyword. The classes which are
implementing this interface can use these default method and same time it
can override the existing method. But its not mandatory to override.
1. Interface Method (Default & Static)
interface DefaultInterface{
abstract void add();
default void display(){
System.out.println("Interface
Default Method");
}
}
1. Interface Method (Default & Static)
b.The second new method introduced in java 8 is static method. Yes like in
classes now we can define a static methods inside interface by using "static".
Basically static methods which are defined in interface are interface level only.
if we want to call these static methods which are defined in interfaces we need
to use interface name so that we can access these methods.
1. Interface Method (Default & Static)
interface StaticInterface{
abstract void add();
default void display(){
System.out.println("Default Method");
}
public static void show(){
System.out.println("Static Method");
}
}
2. Lambda Expressions
=> One of the most awaited and biggest
release in java 8 is lamda expressions.
=> Ability to pass functionality/ behavior to
methods as arguments.
=> Allows us to write a method in the same
place we are going to use it.
2. Lambda Expressions
interface LambdaExpression{
public static void main(String[] args){
Arrays.asList( "j", "a", "v" ,"a","8").
forEach( e -> System.out.print( e ) );
}
}
3. Optional java.util.Optional
=> One of the best and cool feature of java 8 is Optional
class. Which is a final calls from java.util package.
=> The major repeating statement in every project is
checking "NullPointerException". Before using any object
we need to check whether it is null or not if its not null then
only we need to proceed.
=> Optional is just like a container which holds a value of
type <T> or "null". By using isPresent() method of Optional
class we can check particular object is null not not.
3. Optional java.util.Optional
class OptionalSample{
public static void main(String[] args ){
Optional< String > str = Optional.ofNullable(
null );
System.out.println( "str having value ? " +
str.isPresent() ); // output : str having value ? false
}
}
4. Streams
=> One of the excellent feature from java 8 as java.util.stream.
=> Stream API introduces real-world functional-style
programming into the Java.
=> Provides functional operations on stream of elements such
as list , set and map
=> Supports filtering, mapping and removal of duplicates of
elements in collections, are implemented lazily.
=> Now we can get Streams from collections, arrays and
bufferedReaders etc.
4. Streams
class StreamSample{
public static void main(String[] args ){
Arrays.stream(new int[] {1, 2, 3,4,5})
.map(n -> 2 * n + 1)
.average()
.ifPresent(System.out::println); // output: 7.0
}
}
5. Method Reference
=> We can use lambda expressions to create
anonymous methods.
=> Sometimes, however, a lambda expression does
nothing but call an existing method. In those cases, it's
often clearer to refer to the existing method by name.
=> Using Method references refer to the existing method
by name, they are compact, easy-to-read lambda
expressions for methods that already have a name
5. Method Reference
class MethodRefSample{
public void show(String str){
System.out.println(str);
}
public static void main(String[] args ){
Arrays.asList("a", "b", "c").forEach(new A()::
show); // a b c
}
}
6. Data Time API
=> The next cool feature from java 8 is new
date time API(jsr 310) added within java.time
package.
=> Before java 8 if we want to format dates we
use SimpleDateFormatter class in java 8 while
declaring date itself it has constructor to pass
format of date.
6. Data Time API
=> Some of the new classes introduced in java 8 date time
are as follows.
1. LocalTime
2. LocalDate
3. LocalDateTime
4. OffsetDate
6. OffsetTime
7. OffsetDateTime
6. Data Time API
class DateTimeAPISample{
public static void main(String[] args ){
LocalDate currentDate = LocalDate.now();
System.out.println(currentDate);
LocalDate twentyMarch2015 = LocalDate.of(2015, Month.
MARCH, 06);
System.out.println(twentyMarch2015); //2015-03-06
LocalDate firstApril2015 = LocalDate.of(2015, 4, 1);
System.out.println(firstApril2015);//2015-04-01
}
7. Nashorn Javascript Engine
=> Java 8 come with new Nashorn Javascript
Engine which is allowing us to develop and run
JavaScript applications.
7. Nashorn Javascript Engine
class JavaScriptSample{
public static void main(String[] args ){
ScriptEngineManager manager = new ScriptEngineManager();
ScriptEngine engine = manager.getEngineByName( "JavaScript"
);
System.out.println( engine.getClass().getName() );
System.out.println( "output:" + engine.eval( "function show() {
return 10; }; show();" ) );
}
}
jdk.nashorn.api.scripting.NashornScriptEngine
output:10
8. Parallel Array Sorting
=> As of now java 7 we already having Arrays.sort()
method to sort objects now java 8 introduced parallel
sorting which has more speed than arrays.sort() and
follows Fork/Join framework introduced in Java 7 to assign
the sorting tasks to multiple threads that are available in the
thread pool.
=> Java 8 added parallel sorting functionalities to java.util.
Arrays to take advantage of multithread machines
8. Parallel Array Sorting
class ParallelArray{
public static void main(String[] args ){
int arr[]={1,4,2,8,5};
Arrays.parallelSort(arr);
for(int i:arr){
System.out.println(i);
}
}
}
Thank You

More Related Content

What's hot (20)

Java 8 Lambda and Streams
Java 8 Lambda and StreamsJava 8 Lambda and Streams
Java 8 Lambda and Streams
 
Introduction to java 8 stream api
Introduction to java 8 stream apiIntroduction to java 8 stream api
Introduction to java 8 stream api
 
Java 8 lambda
Java 8 lambdaJava 8 lambda
Java 8 lambda
 
Java 8 streams
Java 8 streamsJava 8 streams
Java 8 streams
 
Java 8 Lambda Expressions
Java 8 Lambda ExpressionsJava 8 Lambda Expressions
Java 8 Lambda Expressions
 
Java collections
Java collectionsJava collections
Java collections
 
Java Collections Framework
Java Collections FrameworkJava Collections Framework
Java Collections Framework
 
Optional in Java 8
Optional in Java 8Optional in Java 8
Optional in Java 8
 
Spring Boot
Spring BootSpring Boot
Spring Boot
 
Java Collections
Java  Collections Java  Collections
Java Collections
 
Generics
GenericsGenerics
Generics
 
ASP.NET Web API
ASP.NET Web APIASP.NET Web API
ASP.NET Web API
 
Java abstract class & abstract methods
Java abstract class & abstract methodsJava abstract class & abstract methods
Java abstract class & abstract methods
 
Mocking in Java with Mockito
Mocking in Java with MockitoMocking in Java with Mockito
Mocking in Java with Mockito
 
Spring MVC
Spring MVCSpring MVC
Spring MVC
 
Multithreading in java
Multithreading in javaMultithreading in java
Multithreading in java
 
07 java collection
07 java collection07 java collection
07 java collection
 
An Introduction to JUnit 5 and how to use it with Spring boot tests and Mockito
An Introduction to JUnit 5 and how to use it with Spring boot tests and MockitoAn Introduction to JUnit 5 and how to use it with Spring boot tests and Mockito
An Introduction to JUnit 5 and how to use it with Spring boot tests and Mockito
 
Collections - Lists, Sets
Collections - Lists, Sets Collections - Lists, Sets
Collections - Lists, Sets
 
Hibernate ppt
Hibernate pptHibernate ppt
Hibernate ppt
 

Similar to Java8 features

Chap-2 Classes & Methods.pptx
Chap-2 Classes & Methods.pptxChap-2 Classes & Methods.pptx
Chap-2 Classes & Methods.pptxchetanpatilcp783
 
Stream Api.pdf
Stream Api.pdfStream Api.pdf
Stream Api.pdfAkaks
 
Java8: what's new and what's hot
Java8: what's new and what's hotJava8: what's new and what's hot
Java8: what's new and what's hotSergii Maliarov
 
Autoboxing and unboxing
Autoboxing and unboxingAutoboxing and unboxing
Autoboxing and unboxingGeetha Manohar
 
Java findamentals1
Java findamentals1Java findamentals1
Java findamentals1Todor Kolev
 
Java findamentals1
Java findamentals1Java findamentals1
Java findamentals1Todor Kolev
 
Java findamentals1
Java findamentals1Java findamentals1
Java findamentals1Todor Kolev
 
Introduction of Java 8 with emphasis on Lambda Expressions and Streams
Introduction of Java 8 with emphasis on Lambda Expressions and StreamsIntroduction of Java 8 with emphasis on Lambda Expressions and Streams
Introduction of Java 8 with emphasis on Lambda Expressions and StreamsEmiel Paasschens
 
Introduction of Object Oriented Programming Language using Java. .pptx
Introduction of Object Oriented Programming Language using Java. .pptxIntroduction of Object Oriented Programming Language using Java. .pptx
Introduction of Object Oriented Programming Language using Java. .pptxPoonam60376
 
Lec 5 13_aug [compatibility mode]
Lec 5 13_aug [compatibility mode]Lec 5 13_aug [compatibility mode]
Lec 5 13_aug [compatibility mode]Palak Sanghani
 
21UCAC31 Java Programming.pdf(MTNC)(BCA)
21UCAC31 Java Programming.pdf(MTNC)(BCA)21UCAC31 Java Programming.pdf(MTNC)(BCA)
21UCAC31 Java Programming.pdf(MTNC)(BCA)ssuser7f90ae
 
Automatic Migration of Legacy Java Method Implementations to Interfaces
Automatic Migration of Legacy Java Method Implementations to InterfacesAutomatic Migration of Legacy Java Method Implementations to Interfaces
Automatic Migration of Legacy Java Method Implementations to InterfacesRaffi Khatchadourian
 
Xebicon2013 scala vsjava_final
Xebicon2013 scala vsjava_finalXebicon2013 scala vsjava_final
Xebicon2013 scala vsjava_finalUrs Peter
 

Similar to Java8 features (20)

Chap-2 Classes & Methods.pptx
Chap-2 Classes & Methods.pptxChap-2 Classes & Methods.pptx
Chap-2 Classes & Methods.pptx
 
Colloquium Report
Colloquium ReportColloquium Report
Colloquium Report
 
Java 8 Intro - Core Features
Java 8 Intro - Core FeaturesJava 8 Intro - Core Features
Java 8 Intro - Core Features
 
Java Collections Tutorials
Java Collections TutorialsJava Collections Tutorials
Java Collections Tutorials
 
Stream Api.pdf
Stream Api.pdfStream Api.pdf
Stream Api.pdf
 
Java8: what's new and what's hot
Java8: what's new and what's hotJava8: what's new and what's hot
Java8: what's new and what's hot
 
Autoboxing and unboxing
Autoboxing and unboxingAutoboxing and unboxing
Autoboxing and unboxing
 
Java findamentals1
Java findamentals1Java findamentals1
Java findamentals1
 
Java findamentals1
Java findamentals1Java findamentals1
Java findamentals1
 
Java findamentals1
Java findamentals1Java findamentals1
Java findamentals1
 
Introduction of Java 8 with emphasis on Lambda Expressions and Streams
Introduction of Java 8 with emphasis on Lambda Expressions and StreamsIntroduction of Java 8 with emphasis on Lambda Expressions and Streams
Introduction of Java 8 with emphasis on Lambda Expressions and Streams
 
Introduction of Object Oriented Programming Language using Java. .pptx
Introduction of Object Oriented Programming Language using Java. .pptxIntroduction of Object Oriented Programming Language using Java. .pptx
Introduction of Object Oriented Programming Language using Java. .pptx
 
Java 8 Lambda Expressions
Java 8 Lambda ExpressionsJava 8 Lambda Expressions
Java 8 Lambda Expressions
 
Lec 5 13_aug [compatibility mode]
Lec 5 13_aug [compatibility mode]Lec 5 13_aug [compatibility mode]
Lec 5 13_aug [compatibility mode]
 
21UCAC31 Java Programming.pdf(MTNC)(BCA)
21UCAC31 Java Programming.pdf(MTNC)(BCA)21UCAC31 Java Programming.pdf(MTNC)(BCA)
21UCAC31 Java Programming.pdf(MTNC)(BCA)
 
Automatic Migration of Legacy Java Method Implementations to Interfaces
Automatic Migration of Legacy Java Method Implementations to InterfacesAutomatic Migration of Legacy Java Method Implementations to Interfaces
Automatic Migration of Legacy Java Method Implementations to Interfaces
 
Xebicon2013 scala vsjava_final
Xebicon2013 scala vsjava_finalXebicon2013 scala vsjava_final
Xebicon2013 scala vsjava_final
 
FunctionalInterfaces
FunctionalInterfacesFunctionalInterfaces
FunctionalInterfaces
 
FunctionalInterfaces
FunctionalInterfacesFunctionalInterfaces
FunctionalInterfaces
 
1_JavIntro
1_JavIntro1_JavIntro
1_JavIntro
 

More from Elias Hasnat

FacialRecognition-May-8-2020.pdf
FacialRecognition-May-8-2020.pdfFacialRecognition-May-8-2020.pdf
FacialRecognition-May-8-2020.pdfElias Hasnat
 
Smart City IoT Solution Improved
Smart City IoT Solution ImprovedSmart City IoT Solution Improved
Smart City IoT Solution ImprovedElias Hasnat
 
Connected vehicle mobility as a service (maas)
Connected vehicle mobility as a service (maas)Connected vehicle mobility as a service (maas)
Connected vehicle mobility as a service (maas)Elias Hasnat
 
Lorawan for agriculture, haccp hazard analysis and critical control point
Lorawan for agriculture, haccp hazard analysis and critical control pointLorawan for agriculture, haccp hazard analysis and critical control point
Lorawan for agriculture, haccp hazard analysis and critical control pointElias Hasnat
 
IoT Security with Azure
IoT Security with AzureIoT Security with Azure
IoT Security with AzureElias Hasnat
 
産業向け AWS IoT ソリューション
産業向け AWS IoT ソリューション産業向け AWS IoT ソリューション
産業向け AWS IoT ソリューションElias Hasnat
 
AIIoT組み込みシステム向けIEEE1888通信スタック
AIIoT組み込みシステム向けIEEE1888通信スタックAIIoT組み込みシステム向けIEEE1888通信スタック
AIIoT組み込みシステム向けIEEE1888通信スタックElias Hasnat
 
IoT security reference architecture
IoT security  reference architectureIoT security  reference architecture
IoT security reference architectureElias Hasnat
 
Intelligent video stream detection platform
Intelligent video stream detection platformIntelligent video stream detection platform
Intelligent video stream detection platformElias Hasnat
 
Machine Learning Algorithms
Machine Learning AlgorithmsMachine Learning Algorithms
Machine Learning AlgorithmsElias Hasnat
 
Reinforcement learning
Reinforcement learningReinforcement learning
Reinforcement learningElias Hasnat
 
China Mobile Market
China Mobile MarketChina Mobile Market
China Mobile MarketElias Hasnat
 

More from Elias Hasnat (20)

BLE.pdf
BLE.pdfBLE.pdf
BLE.pdf
 
FacialRecognition-May-8-2020.pdf
FacialRecognition-May-8-2020.pdfFacialRecognition-May-8-2020.pdf
FacialRecognition-May-8-2020.pdf
 
Smart City IoT Solution Improved
Smart City IoT Solution ImprovedSmart City IoT Solution Improved
Smart City IoT Solution Improved
 
Connected vehicle mobility as a service (maas)
Connected vehicle mobility as a service (maas)Connected vehicle mobility as a service (maas)
Connected vehicle mobility as a service (maas)
 
Lorawan for agriculture, haccp hazard analysis and critical control point
Lorawan for agriculture, haccp hazard analysis and critical control pointLorawan for agriculture, haccp hazard analysis and critical control point
Lorawan for agriculture, haccp hazard analysis and critical control point
 
IoT Security with Azure
IoT Security with AzureIoT Security with Azure
IoT Security with Azure
 
産業向け AWS IoT ソリューション
産業向け AWS IoT ソリューション産業向け AWS IoT ソリューション
産業向け AWS IoT ソリューション
 
Soap vs REST-API
Soap vs REST-APISoap vs REST-API
Soap vs REST-API
 
AIIoT組み込みシステム向けIEEE1888通信スタック
AIIoT組み込みシステム向けIEEE1888通信スタックAIIoT組み込みシステム向けIEEE1888通信スタック
AIIoT組み込みシステム向けIEEE1888通信スタック
 
IoT security reference architecture
IoT security  reference architectureIoT security  reference architecture
IoT security reference architecture
 
Intelligent video stream detection platform
Intelligent video stream detection platformIntelligent video stream detection platform
Intelligent video stream detection platform
 
Machine Learning Algorithms
Machine Learning AlgorithmsMachine Learning Algorithms
Machine Learning Algorithms
 
REST API
REST APIREST API
REST API
 
Mqtt
MqttMqtt
Mqtt
 
Reinforcement learning
Reinforcement learningReinforcement learning
Reinforcement learning
 
Dalvikよりart
DalvikよりartDalvikよりart
Dalvikよりart
 
K means
K meansK means
K means
 
Unity sdk-plugin
Unity sdk-pluginUnity sdk-plugin
Unity sdk-plugin
 
Cocos2dx
Cocos2dxCocos2dx
Cocos2dx
 
China Mobile Market
China Mobile MarketChina Mobile Market
China Mobile Market
 

Recently uploaded

『澳洲文凭』买拉筹伯大学毕业证书成绩单办理澳洲LTU文凭学位证书
『澳洲文凭』买拉筹伯大学毕业证书成绩单办理澳洲LTU文凭学位证书『澳洲文凭』买拉筹伯大学毕业证书成绩单办理澳洲LTU文凭学位证书
『澳洲文凭』买拉筹伯大学毕业证书成绩单办理澳洲LTU文凭学位证书rnrncn29
 
A Good Girl's Guide to Murder (A Good Girl's Guide to Murder, #1)
A Good Girl's Guide to Murder (A Good Girl's Guide to Murder, #1)A Good Girl's Guide to Murder (A Good Girl's Guide to Murder, #1)
A Good Girl's Guide to Murder (A Good Girl's Guide to Murder, #1)Christopher H Felton
 
Call Girls South Delhi Delhi reach out to us at ☎ 9711199012
Call Girls South Delhi Delhi reach out to us at ☎ 9711199012Call Girls South Delhi Delhi reach out to us at ☎ 9711199012
Call Girls South Delhi Delhi reach out to us at ☎ 9711199012rehmti665
 
Film cover research (1).pptxsdasdasdasdasdasa
Film cover research (1).pptxsdasdasdasdasdasaFilm cover research (1).pptxsdasdasdasdasdasa
Film cover research (1).pptxsdasdasdasdasdasa494f574xmv
 
『澳洲文凭』买詹姆士库克大学毕业证书成绩单办理澳洲JCU文凭学位证书
『澳洲文凭』买詹姆士库克大学毕业证书成绩单办理澳洲JCU文凭学位证书『澳洲文凭』买詹姆士库克大学毕业证书成绩单办理澳洲JCU文凭学位证书
『澳洲文凭』买詹姆士库克大学毕业证书成绩单办理澳洲JCU文凭学位证书rnrncn29
 
Packaging the Monolith - PHP Tek 2024 (Breaking it down one bite at a time)
Packaging the Monolith - PHP Tek 2024 (Breaking it down one bite at a time)Packaging the Monolith - PHP Tek 2024 (Breaking it down one bite at a time)
Packaging the Monolith - PHP Tek 2024 (Breaking it down one bite at a time)Dana Luther
 
Potsdam FH学位证,波茨坦应用技术大学毕业证书1:1制作
Potsdam FH学位证,波茨坦应用技术大学毕业证书1:1制作Potsdam FH学位证,波茨坦应用技术大学毕业证书1:1制作
Potsdam FH学位证,波茨坦应用技术大学毕业证书1:1制作ys8omjxb
 
Intellectual property rightsand its types.pptx
Intellectual property rightsand its types.pptxIntellectual property rightsand its types.pptx
Intellectual property rightsand its types.pptxBipin Adhikari
 
Git and Github workshop GDSC MLRITM
Git and Github  workshop GDSC MLRITMGit and Github  workshop GDSC MLRITM
Git and Github workshop GDSC MLRITMgdsc13
 
SCM Symposium PPT Format Customer loyalty is predi
SCM Symposium PPT Format Customer loyalty is prediSCM Symposium PPT Format Customer loyalty is predi
SCM Symposium PPT Format Customer loyalty is predieusebiomeyer
 
Elevate Your Business with Our IT Expertise in New Orleans
Elevate Your Business with Our IT Expertise in New OrleansElevate Your Business with Our IT Expertise in New Orleans
Elevate Your Business with Our IT Expertise in New Orleanscorenetworkseo
 
Call Girls Near The Suryaa Hotel New Delhi 9873777170
Call Girls Near The Suryaa Hotel New Delhi 9873777170Call Girls Near The Suryaa Hotel New Delhi 9873777170
Call Girls Near The Suryaa Hotel New Delhi 9873777170Sonam Pathan
 
办理(UofR毕业证书)罗切斯特大学毕业证成绩单原版一比一
办理(UofR毕业证书)罗切斯特大学毕业证成绩单原版一比一办理(UofR毕业证书)罗切斯特大学毕业证成绩单原版一比一
办理(UofR毕业证书)罗切斯特大学毕业证成绩单原版一比一z xss
 
PHP-based rendering of TYPO3 Documentation
PHP-based rendering of TYPO3 DocumentationPHP-based rendering of TYPO3 Documentation
PHP-based rendering of TYPO3 DocumentationLinaWolf1
 
Contact Rya Baby for Call Girls New Delhi
Contact Rya Baby for Call Girls New DelhiContact Rya Baby for Call Girls New Delhi
Contact Rya Baby for Call Girls New Delhimiss dipika
 
Magic exist by Marta Loveguard - presentation.pptx
Magic exist by Marta Loveguard - presentation.pptxMagic exist by Marta Loveguard - presentation.pptx
Magic exist by Marta Loveguard - presentation.pptxMartaLoveguard
 
定制(Lincoln毕业证书)新西兰林肯大学毕业证成绩单原版一比一
定制(Lincoln毕业证书)新西兰林肯大学毕业证成绩单原版一比一定制(Lincoln毕业证书)新西兰林肯大学毕业证成绩单原版一比一
定制(Lincoln毕业证书)新西兰林肯大学毕业证成绩单原版一比一Fs
 

Recently uploaded (20)

『澳洲文凭』买拉筹伯大学毕业证书成绩单办理澳洲LTU文凭学位证书
『澳洲文凭』买拉筹伯大学毕业证书成绩单办理澳洲LTU文凭学位证书『澳洲文凭』买拉筹伯大学毕业证书成绩单办理澳洲LTU文凭学位证书
『澳洲文凭』买拉筹伯大学毕业证书成绩单办理澳洲LTU文凭学位证书
 
A Good Girl's Guide to Murder (A Good Girl's Guide to Murder, #1)
A Good Girl's Guide to Murder (A Good Girl's Guide to Murder, #1)A Good Girl's Guide to Murder (A Good Girl's Guide to Murder, #1)
A Good Girl's Guide to Murder (A Good Girl's Guide to Murder, #1)
 
Call Girls South Delhi Delhi reach out to us at ☎ 9711199012
Call Girls South Delhi Delhi reach out to us at ☎ 9711199012Call Girls South Delhi Delhi reach out to us at ☎ 9711199012
Call Girls South Delhi Delhi reach out to us at ☎ 9711199012
 
Film cover research (1).pptxsdasdasdasdasdasa
Film cover research (1).pptxsdasdasdasdasdasaFilm cover research (1).pptxsdasdasdasdasdasa
Film cover research (1).pptxsdasdasdasdasdasa
 
『澳洲文凭』买詹姆士库克大学毕业证书成绩单办理澳洲JCU文凭学位证书
『澳洲文凭』买詹姆士库克大学毕业证书成绩单办理澳洲JCU文凭学位证书『澳洲文凭』买詹姆士库克大学毕业证书成绩单办理澳洲JCU文凭学位证书
『澳洲文凭』买詹姆士库克大学毕业证书成绩单办理澳洲JCU文凭学位证书
 
Model Call Girl in Jamuna Vihar Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in  Jamuna Vihar Delhi reach out to us at 🔝9953056974🔝Model Call Girl in  Jamuna Vihar Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Jamuna Vihar Delhi reach out to us at 🔝9953056974🔝
 
Packaging the Monolith - PHP Tek 2024 (Breaking it down one bite at a time)
Packaging the Monolith - PHP Tek 2024 (Breaking it down one bite at a time)Packaging the Monolith - PHP Tek 2024 (Breaking it down one bite at a time)
Packaging the Monolith - PHP Tek 2024 (Breaking it down one bite at a time)
 
Potsdam FH学位证,波茨坦应用技术大学毕业证书1:1制作
Potsdam FH学位证,波茨坦应用技术大学毕业证书1:1制作Potsdam FH学位证,波茨坦应用技术大学毕业证书1:1制作
Potsdam FH学位证,波茨坦应用技术大学毕业证书1:1制作
 
Intellectual property rightsand its types.pptx
Intellectual property rightsand its types.pptxIntellectual property rightsand its types.pptx
Intellectual property rightsand its types.pptx
 
Git and Github workshop GDSC MLRITM
Git and Github  workshop GDSC MLRITMGit and Github  workshop GDSC MLRITM
Git and Github workshop GDSC MLRITM
 
SCM Symposium PPT Format Customer loyalty is predi
SCM Symposium PPT Format Customer loyalty is prediSCM Symposium PPT Format Customer loyalty is predi
SCM Symposium PPT Format Customer loyalty is predi
 
Elevate Your Business with Our IT Expertise in New Orleans
Elevate Your Business with Our IT Expertise in New OrleansElevate Your Business with Our IT Expertise in New Orleans
Elevate Your Business with Our IT Expertise in New Orleans
 
Hot Sexy call girls in Rk Puram 🔝 9953056974 🔝 Delhi escort Service
Hot Sexy call girls in  Rk Puram 🔝 9953056974 🔝 Delhi escort ServiceHot Sexy call girls in  Rk Puram 🔝 9953056974 🔝 Delhi escort Service
Hot Sexy call girls in Rk Puram 🔝 9953056974 🔝 Delhi escort Service
 
Call Girls Near The Suryaa Hotel New Delhi 9873777170
Call Girls Near The Suryaa Hotel New Delhi 9873777170Call Girls Near The Suryaa Hotel New Delhi 9873777170
Call Girls Near The Suryaa Hotel New Delhi 9873777170
 
young call girls in Uttam Nagar🔝 9953056974 🔝 Delhi escort Service
young call girls in Uttam Nagar🔝 9953056974 🔝 Delhi escort Serviceyoung call girls in Uttam Nagar🔝 9953056974 🔝 Delhi escort Service
young call girls in Uttam Nagar🔝 9953056974 🔝 Delhi escort Service
 
办理(UofR毕业证书)罗切斯特大学毕业证成绩单原版一比一
办理(UofR毕业证书)罗切斯特大学毕业证成绩单原版一比一办理(UofR毕业证书)罗切斯特大学毕业证成绩单原版一比一
办理(UofR毕业证书)罗切斯特大学毕业证成绩单原版一比一
 
PHP-based rendering of TYPO3 Documentation
PHP-based rendering of TYPO3 DocumentationPHP-based rendering of TYPO3 Documentation
PHP-based rendering of TYPO3 Documentation
 
Contact Rya Baby for Call Girls New Delhi
Contact Rya Baby for Call Girls New DelhiContact Rya Baby for Call Girls New Delhi
Contact Rya Baby for Call Girls New Delhi
 
Magic exist by Marta Loveguard - presentation.pptx
Magic exist by Marta Loveguard - presentation.pptxMagic exist by Marta Loveguard - presentation.pptx
Magic exist by Marta Loveguard - presentation.pptx
 
定制(Lincoln毕业证书)新西兰林肯大学毕业证成绩单原版一比一
定制(Lincoln毕业证书)新西兰林肯大学毕业证成绩单原版一比一定制(Lincoln毕业证书)新西兰林肯大学毕业证成绩单原版一比一
定制(Lincoln毕业证书)新西兰林肯大学毕业证成绩单原版一比一
 

Java8 features

  • 1. Java 8 Features Elias Hasnat http://github.com/claymodel
  • 2. Java 8 Features 1. Default and Static methods in Interface 2. Lambda Expressions 3. Optional 4. Streams 5. Method References 6. Data Time API 7. Nashorn Javascript Engine 8. Parallel Arrays
  • 3. 1. Interface Method (Default & Static) => Java 8 introduces new features to interfaces. => Before java 8 interface having only abstract methods but now java 8 added two more type of methods to interface. a. First one is default method. A method which is having a default keyword with method body. Actually interfaces wont have any implemented methods but now with java 8 default method we can add a method with default implementation by using "default " keyword. The classes which are implementing this interface can use these default method and same time it can override the existing method. But its not mandatory to override.
  • 4. 1. Interface Method (Default & Static) interface DefaultInterface{ abstract void add(); default void display(){ System.out.println("Interface Default Method"); } }
  • 5. 1. Interface Method (Default & Static) b.The second new method introduced in java 8 is static method. Yes like in classes now we can define a static methods inside interface by using "static". Basically static methods which are defined in interface are interface level only. if we want to call these static methods which are defined in interfaces we need to use interface name so that we can access these methods.
  • 6. 1. Interface Method (Default & Static) interface StaticInterface{ abstract void add(); default void display(){ System.out.println("Default Method"); } public static void show(){ System.out.println("Static Method"); } }
  • 7. 2. Lambda Expressions => One of the most awaited and biggest release in java 8 is lamda expressions. => Ability to pass functionality/ behavior to methods as arguments. => Allows us to write a method in the same place we are going to use it.
  • 8. 2. Lambda Expressions interface LambdaExpression{ public static void main(String[] args){ Arrays.asList( "j", "a", "v" ,"a","8"). forEach( e -> System.out.print( e ) ); } }
  • 9. 3. Optional java.util.Optional => One of the best and cool feature of java 8 is Optional class. Which is a final calls from java.util package. => The major repeating statement in every project is checking "NullPointerException". Before using any object we need to check whether it is null or not if its not null then only we need to proceed. => Optional is just like a container which holds a value of type <T> or "null". By using isPresent() method of Optional class we can check particular object is null not not.
  • 10. 3. Optional java.util.Optional class OptionalSample{ public static void main(String[] args ){ Optional< String > str = Optional.ofNullable( null ); System.out.println( "str having value ? " + str.isPresent() ); // output : str having value ? false } }
  • 11. 4. Streams => One of the excellent feature from java 8 as java.util.stream. => Stream API introduces real-world functional-style programming into the Java. => Provides functional operations on stream of elements such as list , set and map => Supports filtering, mapping and removal of duplicates of elements in collections, are implemented lazily. => Now we can get Streams from collections, arrays and bufferedReaders etc.
  • 12. 4. Streams class StreamSample{ public static void main(String[] args ){ Arrays.stream(new int[] {1, 2, 3,4,5}) .map(n -> 2 * n + 1) .average() .ifPresent(System.out::println); // output: 7.0 } }
  • 13. 5. Method Reference => We can use lambda expressions to create anonymous methods. => Sometimes, however, a lambda expression does nothing but call an existing method. In those cases, it's often clearer to refer to the existing method by name. => Using Method references refer to the existing method by name, they are compact, easy-to-read lambda expressions for methods that already have a name
  • 14. 5. Method Reference class MethodRefSample{ public void show(String str){ System.out.println(str); } public static void main(String[] args ){ Arrays.asList("a", "b", "c").forEach(new A():: show); // a b c } }
  • 15. 6. Data Time API => The next cool feature from java 8 is new date time API(jsr 310) added within java.time package. => Before java 8 if we want to format dates we use SimpleDateFormatter class in java 8 while declaring date itself it has constructor to pass format of date.
  • 16. 6. Data Time API => Some of the new classes introduced in java 8 date time are as follows. 1. LocalTime 2. LocalDate 3. LocalDateTime 4. OffsetDate 6. OffsetTime 7. OffsetDateTime
  • 17. 6. Data Time API class DateTimeAPISample{ public static void main(String[] args ){ LocalDate currentDate = LocalDate.now(); System.out.println(currentDate); LocalDate twentyMarch2015 = LocalDate.of(2015, Month. MARCH, 06); System.out.println(twentyMarch2015); //2015-03-06 LocalDate firstApril2015 = LocalDate.of(2015, 4, 1); System.out.println(firstApril2015);//2015-04-01 }
  • 18. 7. Nashorn Javascript Engine => Java 8 come with new Nashorn Javascript Engine which is allowing us to develop and run JavaScript applications.
  • 19. 7. Nashorn Javascript Engine class JavaScriptSample{ public static void main(String[] args ){ ScriptEngineManager manager = new ScriptEngineManager(); ScriptEngine engine = manager.getEngineByName( "JavaScript" ); System.out.println( engine.getClass().getName() ); System.out.println( "output:" + engine.eval( "function show() { return 10; }; show();" ) ); } } jdk.nashorn.api.scripting.NashornScriptEngine output:10
  • 20. 8. Parallel Array Sorting => As of now java 7 we already having Arrays.sort() method to sort objects now java 8 introduced parallel sorting which has more speed than arrays.sort() and follows Fork/Join framework introduced in Java 7 to assign the sorting tasks to multiple threads that are available in the thread pool. => Java 8 added parallel sorting functionalities to java.util. Arrays to take advantage of multithread machines
  • 21. 8. Parallel Array Sorting class ParallelArray{ public static void main(String[] args ){ int arr[]={1,4,2,8,5}; Arrays.parallelSort(arr); for(int i:arr){ System.out.println(i); } } }