SlideShare a Scribd company logo
1 of 34
Download to read offline
New Features
Haim Michael
June 4th
, 2019
All logos, trade marks and brand names used in this presentation belong
to the respective owners.
lifemichael
Java 11
1st Part https://youtu.be/zggphqAcUvw
2nd Part https://youtu.be/ViL0flSGrGY
© 1996-2018 All Rights Reserved.
Haim Michael Introduction
● Snowboarding. Learning. Coding. Teaching. More
than 20 years of Practical Experience.
lifemichael
© 1996-2018 All Rights Reserved.
Haim Michael Introduction
● Professional Certifications
Zend Certified Engineer in PHP
Certified Java Professional
Certified Java EE Web Component Developer
OMG Certified UML Professional
● MBA (cum laude) from Tel-Aviv University
Information Systems Management
lifemichael
© 2008 Haim Michael 20151026
Oracle JDK is not Free
 As of Java 11, the Oracle JDK would no longer be free
for commercial use.
 The Open JDK continues to be free. We can use it
instead. However, we won't get nor security updates
and nor any update at all.
© 2008 Haim Michael 20151026
Running Java File
 We can avoid the compilation phase. We can compile
and execute in one command. We use the java
command. It will implicitly compile without saving the
.class file.
© 2008 Haim Michael 20151026
Running Java File
© 2008 Haim Michael 20151026
Java String Methods
 The isBlank() method checks whether the string is
an empty string, meaning... whether the string solely
includes zero or more blanks. String with only white
characters is treated as a blank string.
public class Program {
public static void main(String args[]) {
var a = "";
var b = " ";
System.out.println(a.isBlank());
System.out.println(b.isBlank());
}
}
© 2008 Haim Michael 20151026
Java String Methods
 The lines() method returns a reference for a stream
of strings that are substrings we received after splitting
by lines.
public class Program {
public static void main(String args[]) {
var a = "wenlovenjavanandnkotlin";
var stream = a.lines();
stream.forEach(str->System.out.println(str));
}
}
© 2008 Haim Michael 20151026
Java String Methods
 The strip(), stripLeading()and the
stripTrailing methods remove white spaces from
the beginning, the ending and the remr of the string. It
is a 'Unicode-Aware' evolution of trim();
public class Program {
public static void main(String args[]) {
var a = " we love kotlin ";
var b = a.strip();
System.out.println("###"+b+"###");
}
}
© 2008 Haim Michael 20151026
Java String Methods
 The repeat() method repeats the string on which it is
invoked the number of times it receives.
public class Program {
public static void main(String args[]) {
var a = "love ";
var b = a.repeat(2);
System.out.println(b);
}
}
© 2008 Haim Michael 20151026
Using var in Lambda Expressions
 As of Java 11 we can use the var keyword within
lambda expressions.
interface Calculation {
public int calc(int a,int b);
}
public class Program {
public static void main(String args[]) {
Calculation f = (var a, var b)-> a+b;
System.out.println(f.calc(4,5));
}
}
© 2008 Haim Michael 20151026
Using var in Lambda Expressions
 When using var in a lambda expression we must use
it on all parameters and we cannot mix it with using
specific types.
© 2008 Haim Michael 20151026
Inner Classes Access Control
 Code written in methods defined inside inner class can
access members of the outer class, even if these
members are private.
class Outer
{
private void a() {}
class Inner {
void b() {
a();
}
}
}
© 2008 Haim Michael 20151026
Inner Classes Access Control
 As of Java 11, there are new methods in Class class
that assist us with getting information about the created
nest. These methods include the following:
getNestHost(), getNestMembers() and
isNestemateOf().
© 2008 Haim Michael 20151026
Epsilon
 As of Java 11, the JVM has an experimental feature
that allows us to run the JVM without any actual
memory reclamation.
 The goal is to provide a completely passive garbage
collector implementation with a bounded allocation limit
and the lowest latency overhead possible.
https://openjdk.java.net/jeps/318
© 2008 Haim Michael 20151026
Deprecated Modules Removal
 As of Java 11, Java EE and CORBA modules that
were already marked as deprecated in Java 9 are now
completely removed.
java.xml.ws
java.xml.bind
java.activation
java.xml.ws.annotation
java.corba
java.transaction
java.se.ee
jdk.xml.ws
jdk.xml.bind
© 2008 Haim Michael 20151026
Flight Recorder
 The Flight Recorder is a profiling tool with a negligible
overhead below 1%. This extra ordinary overhead
allows us to use it even in production.
 The Flight Recorder, also known as JFR, used to be a
commercial add-on in Oracle JDK. It was recently open
sourced.
© 2008 Haim Michael 20151026
Flight Recorder
 Using the jps command we can get the process id of
our Java program.
© 2008 Haim Michael 20151026
Flight Recorder
 Using the jcmd command we can perform various
commands, such as jcmd 43659 JFR.start
© 2008 Haim Michael 20151026
Flight Recorder
 Using the jcmd command together with JFR.dump we
can dump all data to a textual file we choose its name
and it location on our computer.
© 2008 Haim Michael 20151026
Flight Recorder
 There are various possibilities to process the new
created data file.
https://github.com/lhotari/jfr-report-tool
© 2008 Haim Michael 20151026
The HTTP Client
 As of Java 11, the HTTP Client API is more
standardized.
 The new API supports both HTTP/1.1 and HTTP/2.
 The new API also supports HTML5 WebSockets.
© 2008 Haim Michael 20151026
The HTTP Client
 As of Java 11, the HTTP Client API is more
standardized. The new API supports both HTTP/1.1
and HTTP/2. The new API also supports HTML5
WebSockets.
© 2008 Haim Michael 20151026
The HTTP Client
package com.lifemichael.samples;
import java.io.IOException;
import java.net.http.*;
import java.net.*;
import java.net.http.HttpResponse.*;
public class HTTPClientDemo {
public static void main(String args[]) {
HttpClient httpClient = HttpClient.newBuilder().build();
© 2008 Haim Michael 20151026
The HTTP Client
HttpRequest request = HttpRequest.newBuilder().uri(URI.create(
"http://www.abelski.com/courses/dom/lib_doc.xml"))
.GET()
.build();
try {
HttpResponse<String> response = httpClient.send(
request, BodyHandlers.ofString());
System.out.println(response.body());
System.out.println(response.statusCode());
} catch (IOException e) {
e.printStackTrace();
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}
© 2008 Haim Michael 20151026
The HTTP Client
 The new HTTP Client allows us to initiate an
asynchronous HTTP request.
HttpClient
.sendAsync(request,BodyHandlers.ofString())
.thenAccept(response -> {
System.out.println(response.body());
//..
});
© 2008 Haim Michael 20151026
The HTTP Client
 The new HTTP Client supports the WebSocket
protocol.
HttpClient httpClient = HttpClient.newBuilder()
.executor(executor).build();
Builder webSocketBuilder = httpClient.newWebSocketBuilder();
WebSocket webSocket = webSocketBuilder
.buildAsync(
URI.create("wss://echo.websocket.org"), 
 ).join();
© 2008 Haim Michael 20151026
Nashorn is Deprecated
 As of Java 11, the Nashorn JavaScript engine and
APIs are deprecated. Most likely, in future versions of
the JDK.
© 2008 Haim Michael 20151026
The ZGC Scalable Low Latency GC
 As of Java 11, we can use the ZGC. This new GC is
available as an experimental feature.
 ZGC is a scalable low latency garbage collector. It
performs the expensive work concurrently without
stopping the execution of application threads for more
than 10ms.
© 2008 Haim Michael 20151026
The ZGC Scalable Low Latency GC
 ZGC is suitable especially for applications that require
low latency and/or use a very large heap (multi-
terabytes).
© 2008 Haim Michael 20151026
Files Reading and Writing
 Java 11 introduces two new methods that significantly
assist with reading and writing strings from and to files.
readString()
writeString()
© 2008 Haim Michael 20151026
Files Reading and Writing
public class FilesReadingDemo {
public static void main(String args[]) {
try {
Path path = FileSystems.getDefault()
.getPath(".", "welove.txt");
String str = Files.readString(path);
System.out.println(str);
} catch (IOException e) {
e.printStackTrace();
}
}
© 2008 Haim Michael 20151026
Files Reading and Writing
public class FilesWritingDemo {
public static void main(String args[]) {
Path path = FileSystems.getDefault()
.getPath(".", "welove.txt");
try {
Files.writeString(path,
"we love php", StandardOpenOption.APPEND);
} catch (IOException e) {
e.printStackTrace();
}
}
}
© 2008 Haim Michael 20151026
Q&A
Thanks for attending our meetup! I hope you enjoyed! I
will be more than happy to get feedback.
Haim Michael
haim.michael@lifemichael.com
0546655837

More Related Content

What's hot

Java Persistence API (JPA) Step By Step
Java Persistence API (JPA) Step By StepJava Persistence API (JPA) Step By Step
Java Persistence API (JPA) Step By Step
Guo Albert
 
Optional in Java 8
Optional in Java 8Optional in Java 8
Optional in Java 8
Richard Walker
 

What's hot (20)

Intro to React
Intro to ReactIntro to React
Intro to React
 
Spring data jpa
Spring data jpaSpring data jpa
Spring data jpa
 
Spring Boot Tutorial
Spring Boot TutorialSpring Boot Tutorial
Spring Boot Tutorial
 
JUnit & Mockito, first steps
JUnit & Mockito, first stepsJUnit & Mockito, first steps
JUnit & Mockito, first steps
 
ES6 presentation
ES6 presentationES6 presentation
ES6 presentation
 
java 8 new features
java 8 new features java 8 new features
java 8 new features
 
Java 8-streams-collectors-patterns
Java 8-streams-collectors-patternsJava 8-streams-collectors-patterns
Java 8-streams-collectors-patterns
 
Java Persistence API (JPA) Step By Step
Java Persistence API (JPA) Step By StepJava Persistence API (JPA) Step By Step
Java Persistence API (JPA) Step By Step
 
Spring boot Introduction
Spring boot IntroductionSpring boot Introduction
Spring boot Introduction
 
Java 8 - Features Overview
Java 8 - Features OverviewJava 8 - Features Overview
Java 8 - Features Overview
 
Java 8 lambda
Java 8 lambdaJava 8 lambda
Java 8 lambda
 
Understanding react hooks
Understanding react hooksUnderstanding react hooks
Understanding react hooks
 
Core java
Core javaCore java
Core java
 
Java Basics
Java BasicsJava Basics
Java Basics
 
Optional in Java 8
Optional in Java 8Optional in Java 8
Optional in Java 8
 
Spring boot
Spring bootSpring boot
Spring boot
 
Junit
JunitJunit
Junit
 
Spring boot
Spring bootSpring boot
Spring boot
 
Spring boot introduction
Spring boot introductionSpring boot introduction
Spring boot introduction
 
Introduction to java 8 stream api
Introduction to java 8 stream apiIntroduction to java 8 stream api
Introduction to java 8 stream api
 

Similar to Java11 New Features

Introduction to JavaFX on Raspberry Pi
Introduction to JavaFX on Raspberry PiIntroduction to JavaFX on Raspberry Pi
Introduction to JavaFX on Raspberry Pi
Bruno Borges
 
Java rmi example program with code
Java rmi example program with codeJava rmi example program with code
Java rmi example program with code
kamal kotecha
 
Networking and Data Access with Eqela
Networking and Data Access with EqelaNetworking and Data Access with Eqela
Networking and Data Access with Eqela
jobandesther
 

Similar to Java11 New Features (20)

Asynchronous JavaScript Programming
Asynchronous JavaScript ProgrammingAsynchronous JavaScript Programming
Asynchronous JavaScript Programming
 
Introduction to JavaFX on Raspberry Pi
Introduction to JavaFX on Raspberry PiIntroduction to JavaFX on Raspberry Pi
Introduction to JavaFX on Raspberry Pi
 
Mastering the Sling Rewriter by Justin Edelson
Mastering the Sling Rewriter by Justin EdelsonMastering the Sling Rewriter by Justin Edelson
Mastering the Sling Rewriter by Justin Edelson
 
Mastering the Sling Rewriter
Mastering the Sling RewriterMastering the Sling Rewriter
Mastering the Sling Rewriter
 
Node.js primer for ITE students
Node.js primer for ITE studentsNode.js primer for ITE students
Node.js primer for ITE students
 
Traffic Management In The Cloud
Traffic Management In The CloudTraffic Management In The Cloud
Traffic Management In The Cloud
 
Java and Serverless - A Match Made In Heaven, Part 2
Java and Serverless - A Match Made In Heaven, Part 2Java and Serverless - A Match Made In Heaven, Part 2
Java and Serverless - A Match Made In Heaven, Part 2
 
JavaFX8 TestFX - CDI
JavaFX8   TestFX - CDIJavaFX8   TestFX - CDI
JavaFX8 TestFX - CDI
 
Node JS Crash Course
Node JS Crash CourseNode JS Crash Course
Node JS Crash Course
 
Bring the fun back to java
Bring the fun back to javaBring the fun back to java
Bring the fun back to java
 
Node.js Crash Course (Jump Start)
Node.js Crash Course (Jump Start) Node.js Crash Course (Jump Start)
Node.js Crash Course (Jump Start)
 
Java rmi example program with code
Java rmi example program with codeJava rmi example program with code
Java rmi example program with code
 
Open Source XMPP for Cloud Services
Open Source XMPP for Cloud ServicesOpen Source XMPP for Cloud Services
Open Source XMPP for Cloud Services
 
Maximize the power of OSGi in AEM
Maximize the power of OSGi in AEM Maximize the power of OSGi in AEM
Maximize the power of OSGi in AEM
 
Node.js primer
Node.js primerNode.js primer
Node.js primer
 
Java 9 features
Java 9 featuresJava 9 features
Java 9 features
 
Networking and Data Access with Eqela
Networking and Data Access with EqelaNetworking and Data Access with Eqela
Networking and Data Access with Eqela
 
Node.js Workshop
Node.js WorkshopNode.js Workshop
Node.js Workshop
 
InterConnect2016: WebApp Architectures with Java and Node.js
InterConnect2016: WebApp Architectures with Java and Node.jsInterConnect2016: WebApp Architectures with Java and Node.js
InterConnect2016: WebApp Architectures with Java and Node.js
 
Java vs. Java Script for enterprise web applications - Chris Bailey
Java vs. Java Script for enterprise web applications - Chris BaileyJava vs. Java Script for enterprise web applications - Chris Bailey
Java vs. Java Script for enterprise web applications - Chris Bailey
 

More from Haim Michael

More from Haim Michael (20)

Anti Patterns
Anti PatternsAnti Patterns
Anti Patterns
 
Virtual Threads in Java
Virtual Threads in JavaVirtual Threads in Java
Virtual Threads in Java
 
MongoDB Design Patterns
MongoDB Design PatternsMongoDB Design Patterns
MongoDB Design Patterns
 
Introduction to SQL Injections
Introduction to SQL InjectionsIntroduction to SQL Injections
Introduction to SQL Injections
 
Record Classes in Java
Record Classes in JavaRecord Classes in Java
Record Classes in Java
 
Microservices Design Patterns
Microservices Design PatternsMicroservices Design Patterns
Microservices Design Patterns
 
Structural Pattern Matching in Python
Structural Pattern Matching in PythonStructural Pattern Matching in Python
Structural Pattern Matching in Python
 
Unit Testing in Python
Unit Testing in PythonUnit Testing in Python
Unit Testing in Python
 
OOP Best Practices in JavaScript
OOP Best Practices in JavaScriptOOP Best Practices in JavaScript
OOP Best Practices in JavaScript
 
Java Jump Start
Java Jump StartJava Jump Start
Java Jump Start
 
JavaScript Jump Start 20220214
JavaScript Jump Start 20220214JavaScript Jump Start 20220214
JavaScript Jump Start 20220214
 
Bootstrap Jump Start
Bootstrap Jump StartBootstrap Jump Start
Bootstrap Jump Start
 
What is new in PHP
What is new in PHPWhat is new in PHP
What is new in PHP
 
What is new in Python 3.9
What is new in Python 3.9What is new in Python 3.9
What is new in Python 3.9
 
Programming in Python on Steroid
Programming in Python on SteroidProgramming in Python on Steroid
Programming in Python on Steroid
 
The matplotlib Library
The matplotlib LibraryThe matplotlib Library
The matplotlib Library
 
Pandas meetup 20200908
Pandas meetup 20200908Pandas meetup 20200908
Pandas meetup 20200908
 
The num py_library_20200818
The num py_library_20200818The num py_library_20200818
The num py_library_20200818
 
Jupyter notebook 20200728
Jupyter notebook 20200728Jupyter notebook 20200728
Jupyter notebook 20200728
 
The Power of Decorators in Python [Meetup]
The Power of Decorators in Python [Meetup]The Power of Decorators in Python [Meetup]
The Power of Decorators in Python [Meetup]
 

Recently uploaded

Abortion Pill Prices Tembisa [(+27832195400*)] đŸ„ Women's Abortion Clinic in T...
Abortion Pill Prices Tembisa [(+27832195400*)] đŸ„ Women's Abortion Clinic in T...Abortion Pill Prices Tembisa [(+27832195400*)] đŸ„ Women's Abortion Clinic in T...
Abortion Pill Prices Tembisa [(+27832195400*)] đŸ„ Women's Abortion Clinic in T...
Medical / Health Care (+971588192166) Mifepristone and Misoprostol tablets 200mg
 
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
masabamasaba
 
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...
masabamasaba
 
%+27788225528 love spells in Huntington Beach Psychic Readings, Attraction sp...
%+27788225528 love spells in Huntington Beach Psychic Readings, Attraction sp...%+27788225528 love spells in Huntington Beach Psychic Readings, Attraction sp...
%+27788225528 love spells in Huntington Beach Psychic Readings, Attraction sp...
masabamasaba
 
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
Health
 
Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024
Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024
Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024
VictoriaMetrics
 

Recently uploaded (20)

WSO2Con2024 - Enabling Transactional System's Exponential Growth With Simplicity
WSO2Con2024 - Enabling Transactional System's Exponential Growth With SimplicityWSO2Con2024 - Enabling Transactional System's Exponential Growth With Simplicity
WSO2Con2024 - Enabling Transactional System's Exponential Growth With Simplicity
 
WSO2CON 2024 - How to Run a Security Program
WSO2CON 2024 - How to Run a Security ProgramWSO2CON 2024 - How to Run a Security Program
WSO2CON 2024 - How to Run a Security Program
 
VTU technical seminar 8Th Sem on Scikit-learn
VTU technical seminar 8Th Sem on Scikit-learnVTU technical seminar 8Th Sem on Scikit-learn
VTU technical seminar 8Th Sem on Scikit-learn
 
Abortion Pill Prices Tembisa [(+27832195400*)] đŸ„ Women's Abortion Clinic in T...
Abortion Pill Prices Tembisa [(+27832195400*)] đŸ„ Women's Abortion Clinic in T...Abortion Pill Prices Tembisa [(+27832195400*)] đŸ„ Women's Abortion Clinic in T...
Abortion Pill Prices Tembisa [(+27832195400*)] đŸ„ Women's Abortion Clinic in T...
 
OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...
OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...
OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...
 
Direct Style Effect Systems - The Print[A] Example - A Comprehension Aid
Direct Style Effect Systems -The Print[A] Example- A Comprehension AidDirect Style Effect Systems -The Print[A] Example- A Comprehension Aid
Direct Style Effect Systems - The Print[A] Example - A Comprehension Aid
 
WSO2CON 2024 - Cloud Native Middleware: Domain-Driven Design, Cell-Based Arch...
WSO2CON 2024 - Cloud Native Middleware: Domain-Driven Design, Cell-Based Arch...WSO2CON 2024 - Cloud Native Middleware: Domain-Driven Design, Cell-Based Arch...
WSO2CON 2024 - Cloud Native Middleware: Domain-Driven Design, Cell-Based Arch...
 
WSO2CON 2024 Slides - Open Source to SaaS
WSO2CON 2024 Slides - Open Source to SaaSWSO2CON 2024 Slides - Open Source to SaaS
WSO2CON 2024 Slides - Open Source to SaaS
 
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
 
WSO2CON 2024 - API Management Usage at La Poste and Its Impact on Business an...
WSO2CON 2024 - API Management Usage at La Poste and Its Impact on Business an...WSO2CON 2024 - API Management Usage at La Poste and Its Impact on Business an...
WSO2CON 2024 - API Management Usage at La Poste and Its Impact on Business an...
 
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...
 
tonesoftg
tonesoftgtonesoftg
tonesoftg
 
%+27788225528 love spells in Huntington Beach Psychic Readings, Attraction sp...
%+27788225528 love spells in Huntington Beach Psychic Readings, Attraction sp...%+27788225528 love spells in Huntington Beach Psychic Readings, Attraction sp...
%+27788225528 love spells in Huntington Beach Psychic Readings, Attraction sp...
 
%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain
%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain
%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain
 
What Goes Wrong with Language Definitions and How to Improve the Situation
What Goes Wrong with Language Definitions and How to Improve the SituationWhat Goes Wrong with Language Definitions and How to Improve the Situation
What Goes Wrong with Language Definitions and How to Improve the Situation
 
%in ivory park+277-882-255-28 abortion pills for sale in ivory park
%in ivory park+277-882-255-28 abortion pills for sale in ivory park %in ivory park+277-882-255-28 abortion pills for sale in ivory park
%in ivory park+277-882-255-28 abortion pills for sale in ivory park
 
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
 
Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024
Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024
Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024
 
MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...
MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...
MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...
 
WSO2CON 2024 - Does Open Source Still Matter?
WSO2CON 2024 - Does Open Source Still Matter?WSO2CON 2024 - Does Open Source Still Matter?
WSO2CON 2024 - Does Open Source Still Matter?
 

Java11 New Features

  • 1. New Features Haim Michael June 4th , 2019 All logos, trade marks and brand names used in this presentation belong to the respective owners. lifemichael Java 11 1st Part https://youtu.be/zggphqAcUvw 2nd Part https://youtu.be/ViL0flSGrGY
  • 2. © 1996-2018 All Rights Reserved. Haim Michael Introduction ● Snowboarding. Learning. Coding. Teaching. More than 20 years of Practical Experience. lifemichael
  • 3. © 1996-2018 All Rights Reserved. Haim Michael Introduction ● Professional Certifications Zend Certified Engineer in PHP Certified Java Professional Certified Java EE Web Component Developer OMG Certified UML Professional ● MBA (cum laude) from Tel-Aviv University Information Systems Management lifemichael
  • 4. © 2008 Haim Michael 20151026 Oracle JDK is not Free  As of Java 11, the Oracle JDK would no longer be free for commercial use.  The Open JDK continues to be free. We can use it instead. However, we won't get nor security updates and nor any update at all.
  • 5. © 2008 Haim Michael 20151026 Running Java File  We can avoid the compilation phase. We can compile and execute in one command. We use the java command. It will implicitly compile without saving the .class file.
  • 6. © 2008 Haim Michael 20151026 Running Java File
  • 7. © 2008 Haim Michael 20151026 Java String Methods  The isBlank() method checks whether the string is an empty string, meaning... whether the string solely includes zero or more blanks. String with only white characters is treated as a blank string. public class Program { public static void main(String args[]) { var a = ""; var b = " "; System.out.println(a.isBlank()); System.out.println(b.isBlank()); } }
  • 8. © 2008 Haim Michael 20151026 Java String Methods  The lines() method returns a reference for a stream of strings that are substrings we received after splitting by lines. public class Program { public static void main(String args[]) { var a = "wenlovenjavanandnkotlin"; var stream = a.lines(); stream.forEach(str->System.out.println(str)); } }
  • 9. © 2008 Haim Michael 20151026 Java String Methods  The strip(), stripLeading()and the stripTrailing methods remove white spaces from the beginning, the ending and the remr of the string. It is a 'Unicode-Aware' evolution of trim(); public class Program { public static void main(String args[]) { var a = " we love kotlin "; var b = a.strip(); System.out.println("###"+b+"###"); } }
  • 10. © 2008 Haim Michael 20151026 Java String Methods  The repeat() method repeats the string on which it is invoked the number of times it receives. public class Program { public static void main(String args[]) { var a = "love "; var b = a.repeat(2); System.out.println(b); } }
  • 11. © 2008 Haim Michael 20151026 Using var in Lambda Expressions  As of Java 11 we can use the var keyword within lambda expressions. interface Calculation { public int calc(int a,int b); } public class Program { public static void main(String args[]) { Calculation f = (var a, var b)-> a+b; System.out.println(f.calc(4,5)); } }
  • 12. © 2008 Haim Michael 20151026 Using var in Lambda Expressions  When using var in a lambda expression we must use it on all parameters and we cannot mix it with using specific types.
  • 13. © 2008 Haim Michael 20151026 Inner Classes Access Control  Code written in methods defined inside inner class can access members of the outer class, even if these members are private. class Outer { private void a() {} class Inner { void b() { a(); } } }
  • 14. © 2008 Haim Michael 20151026 Inner Classes Access Control  As of Java 11, there are new methods in Class class that assist us with getting information about the created nest. These methods include the following: getNestHost(), getNestMembers() and isNestemateOf().
  • 15. © 2008 Haim Michael 20151026 Epsilon  As of Java 11, the JVM has an experimental feature that allows us to run the JVM without any actual memory reclamation.  The goal is to provide a completely passive garbage collector implementation with a bounded allocation limit and the lowest latency overhead possible. https://openjdk.java.net/jeps/318
  • 16. © 2008 Haim Michael 20151026 Deprecated Modules Removal  As of Java 11, Java EE and CORBA modules that were already marked as deprecated in Java 9 are now completely removed. java.xml.ws java.xml.bind java.activation java.xml.ws.annotation java.corba java.transaction java.se.ee jdk.xml.ws jdk.xml.bind
  • 17. © 2008 Haim Michael 20151026 Flight Recorder  The Flight Recorder is a profiling tool with a negligible overhead below 1%. This extra ordinary overhead allows us to use it even in production.  The Flight Recorder, also known as JFR, used to be a commercial add-on in Oracle JDK. It was recently open sourced.
  • 18. © 2008 Haim Michael 20151026 Flight Recorder  Using the jps command we can get the process id of our Java program.
  • 19. © 2008 Haim Michael 20151026 Flight Recorder  Using the jcmd command we can perform various commands, such as jcmd 43659 JFR.start
  • 20. © 2008 Haim Michael 20151026 Flight Recorder  Using the jcmd command together with JFR.dump we can dump all data to a textual file we choose its name and it location on our computer.
  • 21. © 2008 Haim Michael 20151026 Flight Recorder  There are various possibilities to process the new created data file. https://github.com/lhotari/jfr-report-tool
  • 22. © 2008 Haim Michael 20151026 The HTTP Client  As of Java 11, the HTTP Client API is more standardized.  The new API supports both HTTP/1.1 and HTTP/2.  The new API also supports HTML5 WebSockets.
  • 23. © 2008 Haim Michael 20151026 The HTTP Client  As of Java 11, the HTTP Client API is more standardized. The new API supports both HTTP/1.1 and HTTP/2. The new API also supports HTML5 WebSockets.
  • 24. © 2008 Haim Michael 20151026 The HTTP Client package com.lifemichael.samples; import java.io.IOException; import java.net.http.*; import java.net.*; import java.net.http.HttpResponse.*; public class HTTPClientDemo { public static void main(String args[]) { HttpClient httpClient = HttpClient.newBuilder().build();
  • 25. © 2008 Haim Michael 20151026 The HTTP Client HttpRequest request = HttpRequest.newBuilder().uri(URI.create( "http://www.abelski.com/courses/dom/lib_doc.xml")) .GET() .build(); try { HttpResponse<String> response = httpClient.send( request, BodyHandlers.ofString()); System.out.println(response.body()); System.out.println(response.statusCode()); } catch (IOException e) { e.printStackTrace(); } catch (InterruptedException e) { e.printStackTrace(); } } }
  • 26. © 2008 Haim Michael 20151026 The HTTP Client  The new HTTP Client allows us to initiate an asynchronous HTTP request. HttpClient .sendAsync(request,BodyHandlers.ofString()) .thenAccept(response -> { System.out.println(response.body()); //.. });
  • 27. © 2008 Haim Michael 20151026 The HTTP Client  The new HTTP Client supports the WebSocket protocol. HttpClient httpClient = HttpClient.newBuilder() .executor(executor).build(); Builder webSocketBuilder = httpClient.newWebSocketBuilder(); WebSocket webSocket = webSocketBuilder .buildAsync( URI.create("wss://echo.websocket.org"), 
 ).join();
  • 28. © 2008 Haim Michael 20151026 Nashorn is Deprecated  As of Java 11, the Nashorn JavaScript engine and APIs are deprecated. Most likely, in future versions of the JDK.
  • 29. © 2008 Haim Michael 20151026 The ZGC Scalable Low Latency GC  As of Java 11, we can use the ZGC. This new GC is available as an experimental feature.  ZGC is a scalable low latency garbage collector. It performs the expensive work concurrently without stopping the execution of application threads for more than 10ms.
  • 30. © 2008 Haim Michael 20151026 The ZGC Scalable Low Latency GC  ZGC is suitable especially for applications that require low latency and/or use a very large heap (multi- terabytes).
  • 31. © 2008 Haim Michael 20151026 Files Reading and Writing  Java 11 introduces two new methods that significantly assist with reading and writing strings from and to files. readString() writeString()
  • 32. © 2008 Haim Michael 20151026 Files Reading and Writing public class FilesReadingDemo { public static void main(String args[]) { try { Path path = FileSystems.getDefault() .getPath(".", "welove.txt"); String str = Files.readString(path); System.out.println(str); } catch (IOException e) { e.printStackTrace(); } }
  • 33. © 2008 Haim Michael 20151026 Files Reading and Writing public class FilesWritingDemo { public static void main(String args[]) { Path path = FileSystems.getDefault() .getPath(".", "welove.txt"); try { Files.writeString(path, "we love php", StandardOpenOption.APPEND); } catch (IOException e) { e.printStackTrace(); } } }
  • 34. © 2008 Haim Michael 20151026 Q&A Thanks for attending our meetup! I hope you enjoyed! I will be more than happy to get feedback. Haim Michael haim.michael@lifemichael.com 0546655837