SlideShare ist ein Scribd-Unternehmen logo
1 von 47
Downloaden Sie, um offline zu lesen
Java, what’s next?
by Stephan Janssen
• Founder of Devoxx

• Co-founder of Voxxed (Days)

• Co-founder Devoxx4Kids

• Java Champion

• Passionate Developer
Who am I ?
“The Future Is Complicated”
- John Rose , JVM Architect
“For Java to remain competitive it
must not just continue to move
forward — it must move forward
faster.”
- Mark Reinhold , Chief Architect of the Java Platform Group at Oracle
@Stephan007
More Java Releases
• Every 6 months feature releases (March, September)

• Long-term support releases every 3 years

• Next release for March 2018

• Details @ https://mreinhold.org/blog/forward-faster
@Stephan007
New Java Versioning
• Java SE 18.3
@Stephan007
• Project Amber

• Project Valhalla

• Project Panama - Interconnecting JVM and native code

• Project Loom - Make Concurrency simple(r) again!

• Project Metropolis - The holy Graal : a Java compiler & interpreter
How will this effect you?
@Stephan007
Project Amber
@Stephan007
Project Amber
• Local-Variable Type Inference
• Enhanced Enums
• Lambda Leftovers
• Pattern matching
• Switch expression
https://openjdk.java.net/projects/amber/
JEP 286 Local-Variable Type Inference (LVTI)
(Java 18.3 target release)
@Stephan007
Expanded Type Inference
List<String> empty = Collections.<String>emptyList();
List<String> empty = Collections.emptyList();
	 •	 Java 5: type inference for generic method type arguments
	 •	 Java 7: type inference for constructor type arguments
List<String> newList = new ArrayList<String>();
List<String> newList = new ArrayList<>();
	 •	 Java 8: type inference for lambda formals
Predicate<String> isEmpty = (String s) -> s.isEmpty();
Predicate<String> isEmpty = s -> s.isEmpty();
Brian Goetz @ http://bit.ly/2x3Wop9
@Stephan007
Local-Variable
Type Inference (JEP 286)
URL url = new URL(“https://devoxx.com");
URLConnection conn = url.openConnection();
Scanner scanner = new Scanner(conn.getInputStream(), “UTF-8”);
var url = new URL(“https://devoxx.com");
var conn = url.openConnection();
var scanner = new Scanner(conn.getInputStream(), “UTF-8”);
Brian Goetz @ http://bit.ly/2x3Wop9
@Stephan007
LVTI warnings
var x = { 1, 2, 3 }; // array initializer needs an explicit target-type
http://cr.openjdk.java.net/~mcimadamore/8177466/lvti-diags.html
var x = null; // variable initializer is 'null'
var x; // cannot use 'var' on variable without initializer
var x = m(x); // cannot use 'var' on self-referencing variable
class var { } // as of release 9, 'var' is a restricted local variable type
@Stephan007
LVTI warnings
var[] x = s; // ‘var' is not allowed as an element type of an array
http://cr.openjdk.java.net/~mcimadamore/8177466/lvti-diags.html
var x = 1, y = 2; // 'var' is not allowed in a compound declaration
var<String> list() { return null; } // illegal ref to restricted type 'var'
var x = () -> { }; // lambda expression needs an explicit target-type
@Stephan007
Hidden compiler option
-XDfind=local
Detect local variables whose declared type can be replaced by 'var'
http://mail.openjdk.java.net/pipermail/compiler-dev/2017-September/011060.html
class TestLVTI {

void test() {

String s2 = "";

for (String s = s2 ; s != "" ; ) { }

Object o = "";

}

}
TestLVTI.java:3: warning: Redundant type for local variable (replace
explicit type with 'var').
String s2 = "";
^
TestLVTI.java:4: warning: Redundant type for local variable (replace
explicit type with 'var').
for (String s = s2 ; s != "" ; ) { }
^
2 warnings
The type of o is not redundant!
@Stephan007
Other JVM Languages
Groovy Kotlin
def robot = new Robot() // mutable property
var name = “Hello”
// Read-only
// there's no 'new' keyword
val result = Address()
Scala & Lombok
// Mutable
var name = ”Hello”
// Read-only
val result = new Address()
BTW None of these JVM languages demand a semi-colon! 🤓
@Stephan007
Immutability?
http://mail.openjdk.java.net/pipermail/platform-jep-discuss/2016-December/000066.html
“Local variables are in reality the least
important place where we need more
help making things immutable. 

Local variables are immune to data races;
most locals are effectively final anyway.”

- Brian Goetz
@Stephan007
Project Amber
• JEP 286 Local-Variable Type Inference
• JEP 301 Enhanced Enums
• JEP 302 Lambda Leftovers
JEP 301 Enhanced Enums
http://openjdk.java.net/jeps/301
@Stephan007
Generic Enums
“Enhance the expressiveness of the enum construct in the
Java Language by allowing type-variables in enums, and
performing sharper type-checking for enum constants.”
- Maurizio Cimadamore
http://openjdk.java.net/jeps/301
@Stephan007
Enum enhancements
enum Argument<X> { // declares generic enum
STRING<String>(String.class),
INTEGER<Integer>(Integer.class), ... ;
Class<X> clazz;
Argument(Class<X> clazz) { this.clazz = clazz; }
Class<X> getClazz() { return clazz; }
}
Class<String> cs = Argument.STRING.getClazz(); //uses sharper typing of enum constant
http://openjdk.java.net/jeps/301
• Enum constants to carry constant-specific type information

• Constant-specific state and behavior. 
JEP 302 Lambda Leftovers
http://openjdk.java.net/jeps/302
@Stephan007
Treatment of underscores
• Use an uncerscore for unnamed lambda parameters
BiFunction<Integer, String, String> biss = (i, _) -> String.valueOf(i);
http://openjdk.java.net/jeps/302
@Stephan007
Shadowing a lambda parameter
• Allow lambda parameters to shadow variables in enclosing scopes.

• And locals declared with a lambda.
Map<String, Integer> msi = …
…
String key = computeSomeKey();
msi.comuteIfAbstent(key, key -> key.length()); // error!
http://openjdk.java.net/jeps/302
Pattern Matching
@Stephan007
String formatted = “unknown”;
if (constant instanceof Integer) {
int i = (Integer)constant;
formatted = String.format(“int %d”, i);
} else if (constant instanceof Byte) {
byte b = (Byte)constant;
formatted = String.format(“byte %d”, b);
} // …
https://www.voxxed.com/2017/08/pattern-matching-java/
@Stephan007
Pattern Matching
String formatted = “unknown”;
switch(constant) {
case Integer i :
formatted = String.format(“int %d”, i); break;
case Byte b :
formatted = String.format(“byte %d”, b); break;
// …
default: formatted = String.format(“Unknown: %s”, constant);
}
https://www.voxxed.com/2017/08/pattern-matching-java/
@Stephan007
Switch Expression
String formatted =
switch(constant) {
case Integer i -> String.format(“int %d”, i);
case Byte b -> String.format(“byte %d”, b);
case Long l -> String.format(“long %d”, l);
case Double d -> String.format(“double %f”, d);
case String s -> String.format(“string %s”, s);
default -> “Unknown”;
}
https://www.voxxed.com/2017/08/pattern-matching-java/
@Stephan007
Enhanced Switch Expression
Shape s = …
double area = switch (shape) {
case Circle(var center, var radius)
-> PI * radius * radius;
case Square(var lowerLeft, var edge)
-> edge * edge;
case Rect(var lowerLeft, var upperRight)
-> (upperRight.x - lowerLeft.x)
* (upperRight.y - lowerLeft.y);
// …
}
interface Shape { }
class Circle implements Shape {
Point center;
double radius;
}
class Square implements Shape {
Point lowerLeft;
double edge;
}
class Rect implements Shape {
Point lowerLeft;
Point upperRight;
}
JavaOne 2017 keynote : https://www.youtube.com/watch?v=Tf5rlIS6tkg
@Stephan007
val x = Random.nextInt(10)
val value = x match {
case 0 => “zero”
case 1 => "one"
case 2 => "two"
case _ => "many"
}
val value = when(x) {
0 -> “zero”
1 -> "one"
2 -> "two"
else -> "many"
}
@Stephan007
Valhalla
JEP 169 Value Types
“Codes like a class, works like an int!”
@Stephan007
public class Point {
final int x;
final int y;
}
http://cr.openjdk.java.net/~jrose/values/values-0.html
@Stephan007
public class Point {
final int x;
final int y;
public Point(int x, int y) {
this.x = x;
this.y = y;
}
public boolean equals(Object o) {
return o instanceof Point && x == ((Point)o).x && y == ((Point)o).y;
}
public int hashCode() {
return x + 31 * y;
}
public String toString() {
return String.format(“Point[%d,%d]”, x, y);
}
}
http://cr.openjdk.java.net/~jrose/values/values-0.html
Data Classes
“Just data, no identiy”
@Stephan007
public class Point(int x, int y) { }
http://cr.openjdk.java.net/~jrose/values/values-0.html
@Stephan007
Value Types Requirements
• Final, not extensible

• Only interface parents

• Immutable fields

• No identity

• Equality based on state
• No recursive definitions

• Non-nullable values

• Value semantics

• No (representational) polymorphism

• Multiple fields supported
JEP 218 Generics over Primitive Types
ArrayList<int>
@Stephan007
Generic type arguments are
constrained to extend Object
• Supporting generic primitive and value types arguments!
class Box<T> {
private final T t;
public Box(T t) { this.t = t; }
public T get() { return t; }
}
http://openjdk.java.net/jeps/218
• Suppose we want to specialize the following class with T=int
@Stephan007
• Project Amber

• Project Valhalla

• Project Panama - Interconnecting JVM and native code

• Project Loom - Make Concurrency simple(r) again!

• Project Metropolis - The holy Graal
Personal Wishlist
IF expressions
Even better, change all statements into expressions 🤓
@Stephan007
Resources :
Brian Goetz - Java Language Architect, Oracle John Rose, JVM Architect, Oracle
November 22nd, 2017

Weitere ähnliche Inhalte

Was ist angesagt?

Was ist angesagt? (19)

An Introduction to Scala for Java Developers
An Introduction to Scala for Java DevelopersAn Introduction to Scala for Java Developers
An Introduction to Scala for Java Developers
 
Scala coated JVM
Scala coated JVMScala coated JVM
Scala coated JVM
 
10 Things I Hate About Scala
10 Things I Hate About Scala10 Things I Hate About Scala
10 Things I Hate About Scala
 
Scala Intro
Scala IntroScala Intro
Scala Intro
 
Lambda: A Peek Under The Hood - Brian Goetz
Lambda: A Peek Under The Hood - Brian GoetzLambda: A Peek Under The Hood - Brian Goetz
Lambda: A Peek Under The Hood - Brian Goetz
 
Scala fundamentals
Scala fundamentalsScala fundamentals
Scala fundamentals
 
Fundamental JavaScript [UTC, March 2014]
Fundamental JavaScript [UTC, March 2014]Fundamental JavaScript [UTC, March 2014]
Fundamental JavaScript [UTC, March 2014]
 
Scala presentationjune112011
Scala presentationjune112011Scala presentationjune112011
Scala presentationjune112011
 
Google Dart
Google DartGoogle Dart
Google Dart
 
All You Need to Know About Type Script
All You Need to Know About Type ScriptAll You Need to Know About Type Script
All You Need to Know About Type Script
 
Javascript
JavascriptJavascript
Javascript
 
Scala : language of the future
Scala : language of the futureScala : language of the future
Scala : language of the future
 
JavaScript Tutorial For Beginners | JavaScript Training | JavaScript Programm...
JavaScript Tutorial For Beginners | JavaScript Training | JavaScript Programm...JavaScript Tutorial For Beginners | JavaScript Training | JavaScript Programm...
JavaScript Tutorial For Beginners | JavaScript Training | JavaScript Programm...
 
JavaScript - An Introduction
JavaScript - An IntroductionJavaScript - An Introduction
JavaScript - An Introduction
 
camel-scala.pdf
camel-scala.pdfcamel-scala.pdf
camel-scala.pdf
 
The JavaScript Programming Language
The JavaScript Programming LanguageThe JavaScript Programming Language
The JavaScript Programming Language
 
Javascript Basics
Javascript BasicsJavascript Basics
Javascript Basics
 
Lecture 5 javascript
Lecture 5 javascriptLecture 5 javascript
Lecture 5 javascript
 
Introduction to Scala
Introduction to ScalaIntroduction to Scala
Introduction to Scala
 

Ähnlich wie Java, what's next?

BCS SPA 2010 - An Introduction to Scala for Java Developers
BCS SPA 2010 - An Introduction to Scala for Java DevelopersBCS SPA 2010 - An Introduction to Scala for Java Developers
BCS SPA 2010 - An Introduction to Scala for Java Developers
Miles Sabin
 
Intro to scala
Intro to scalaIntro to scala
Intro to scala
Joe Zulli
 
Building Concurrent WebObjects applications with Scala
Building Concurrent WebObjects applications with ScalaBuilding Concurrent WebObjects applications with Scala
Building Concurrent WebObjects applications with Scala
WO Community
 

Ähnlich wie Java, what's next? (20)

Scala uma poderosa linguagem para a jvm
Scala   uma poderosa linguagem para a jvmScala   uma poderosa linguagem para a jvm
Scala uma poderosa linguagem para a jvm
 
Scala Programming for Semantic Web Developers ESWC Semdev2015
Scala Programming for Semantic Web Developers ESWC Semdev2015Scala Programming for Semantic Web Developers ESWC Semdev2015
Scala Programming for Semantic Web Developers ESWC Semdev2015
 
Introduction to Scala for JCConf Taiwan
Introduction to Scala for JCConf TaiwanIntroduction to Scala for JCConf Taiwan
Introduction to Scala for JCConf Taiwan
 
Short intro to scala and the play framework
Short intro to scala and the play frameworkShort intro to scala and the play framework
Short intro to scala and the play framework
 
JavaScript.pptx
JavaScript.pptxJavaScript.pptx
JavaScript.pptx
 
BCS SPA 2010 - An Introduction to Scala for Java Developers
BCS SPA 2010 - An Introduction to Scala for Java DevelopersBCS SPA 2010 - An Introduction to Scala for Java Developers
BCS SPA 2010 - An Introduction to Scala for Java Developers
 
Introduction To Scala
Introduction To ScalaIntroduction To Scala
Introduction To Scala
 
Introduction to programming in scala
Introduction to programming in scalaIntroduction to programming in scala
Introduction to programming in scala
 
Inside the JVM - Follow the white rabbit! / Breizh JUG
Inside the JVM - Follow the white rabbit! / Breizh JUGInside the JVM - Follow the white rabbit! / Breizh JUG
Inside the JVM - Follow the white rabbit! / Breizh JUG
 
Intro to scala
Intro to scalaIntro to scala
Intro to scala
 
Scala and jvm_languages_praveen_technologist
Scala and jvm_languages_praveen_technologistScala and jvm_languages_praveen_technologist
Scala and jvm_languages_praveen_technologist
 
Scala for Java Programmers
Scala for Java ProgrammersScala for Java Programmers
Scala for Java Programmers
 
Knowledge of Javascript
Knowledge of JavascriptKnowledge of Javascript
Knowledge of Javascript
 
Scala Introduction
Scala IntroductionScala Introduction
Scala Introduction
 
Introduction to Scala
Introduction to ScalaIntroduction to Scala
Introduction to Scala
 
JavaFX In Practice
JavaFX In PracticeJavaFX In Practice
JavaFX In Practice
 
js.pptx
js.pptxjs.pptx
js.pptx
 
Scala.js
Scala.jsScala.js
Scala.js
 
Building Concurrent WebObjects applications with Scala
Building Concurrent WebObjects applications with ScalaBuilding Concurrent WebObjects applications with Scala
Building Concurrent WebObjects applications with Scala
 
Scala Talk at FOSDEM 2009
Scala Talk at FOSDEM 2009Scala Talk at FOSDEM 2009
Scala Talk at FOSDEM 2009
 

Mehr von Stephan Janssen

Devoxx speaker training (June 27th, 2018)
Devoxx speaker training (June 27th, 2018)Devoxx speaker training (June 27th, 2018)
Devoxx speaker training (June 27th, 2018)
Stephan Janssen
 
Devoxx2011 timesheet day3-4-5
Devoxx2011 timesheet day3-4-5Devoxx2011 timesheet day3-4-5
Devoxx2011 timesheet day3-4-5
Stephan Janssen
 
Devoxx2011 timesheet day1-2
Devoxx2011 timesheet day1-2Devoxx2011 timesheet day1-2
Devoxx2011 timesheet day1-2
Stephan Janssen
 
EJB 3.1 by Bert Ertman
EJB 3.1 by Bert ErtmanEJB 3.1 by Bert Ertman
EJB 3.1 by Bert Ertman
Stephan Janssen
 

Mehr von Stephan Janssen (17)

Devoxx speaker training (June 27th, 2018)
Devoxx speaker training (June 27th, 2018)Devoxx speaker training (June 27th, 2018)
Devoxx speaker training (June 27th, 2018)
 
The new DeVoxxEd websites with JHipster, Angular & Kubernetes
The new DeVoxxEd websites with JHipster, Angular & KubernetesThe new DeVoxxEd websites with JHipster, Angular & Kubernetes
The new DeVoxxEd websites with JHipster, Angular & Kubernetes
 
The new Voxxed websites with JHipster, Angular and GitLab
The new Voxxed websites  with JHipster, Angular and GitLabThe new Voxxed websites  with JHipster, Angular and GitLab
The new Voxxed websites with JHipster, Angular and GitLab
 
Programming 4 kids
Programming 4 kidsProgramming 4 kids
Programming 4 kids
 
Devoxx2011 timesheet day3-4-5
Devoxx2011 timesheet day3-4-5Devoxx2011 timesheet day3-4-5
Devoxx2011 timesheet day3-4-5
 
Devoxx2011 timesheet day1-2
Devoxx2011 timesheet day1-2Devoxx2011 timesheet day1-2
Devoxx2011 timesheet day1-2
 
EJB 3.1 by Bert Ertman
EJB 3.1 by Bert ErtmanEJB 3.1 by Bert Ertman
EJB 3.1 by Bert Ertman
 
BeJUG JAX-RS Event
BeJUG JAX-RS EventBeJUG JAX-RS Event
BeJUG JAX-RS Event
 
Whats New In Java Ee 6
Whats New In Java Ee 6Whats New In Java Ee 6
Whats New In Java Ee 6
 
Glass Fishv3 March2010
Glass Fishv3 March2010Glass Fishv3 March2010
Glass Fishv3 March2010
 
Advanced Scrum
Advanced ScrumAdvanced Scrum
Advanced Scrum
 
Scala by Luc Duponcheel
Scala by Luc DuponcheelScala by Luc Duponcheel
Scala by Luc Duponcheel
 
Intro To OSGi
Intro To OSGiIntro To OSGi
Intro To OSGi
 
Kick Start Jpa
Kick Start JpaKick Start Jpa
Kick Start Jpa
 
BeJUG - Di With Spring
BeJUG - Di With SpringBeJUG - Di With Spring
BeJUG - Di With Spring
 
BeJUG - Spring 3 talk
BeJUG - Spring 3 talkBeJUG - Spring 3 talk
BeJUG - Spring 3 talk
 
BeJug.Org Java Generics
BeJug.Org   Java GenericsBeJug.Org   Java Generics
BeJug.Org Java Generics
 

Kürzlich hochgeladen

The title is not connected to what is inside
The title is not connected to what is insideThe title is not connected to what is inside
The title is not connected to what is inside
shinachiaurasa2
 
+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
 
%+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
 
introduction-to-automotive Andoid os-csimmonds-ndctechtown-2021.pdf
introduction-to-automotive Andoid os-csimmonds-ndctechtown-2021.pdfintroduction-to-automotive Andoid os-csimmonds-ndctechtown-2021.pdf
introduction-to-automotive Andoid os-csimmonds-ndctechtown-2021.pdf
VishalKumarJha10
 
AI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
AI Mastery 201: Elevating Your Workflow with Advanced LLM TechniquesAI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
AI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
VictorSzoltysek
 

Kürzlich hochgeladen (20)

Announcing Codolex 2.0 from GDK Software
Announcing Codolex 2.0 from GDK SoftwareAnnouncing Codolex 2.0 from GDK Software
Announcing Codolex 2.0 from GDK Software
 
The title is not connected to what is inside
The title is not connected to what is insideThe title is not connected to what is inside
The title is not connected to what is inside
 
%in Hazyview+277-882-255-28 abortion pills for sale in Hazyview
%in Hazyview+277-882-255-28 abortion pills for sale in Hazyview%in Hazyview+277-882-255-28 abortion pills for sale in Hazyview
%in Hazyview+277-882-255-28 abortion pills for sale in Hazyview
 
Payment Gateway Testing Simplified_ A Step-by-Step Guide for Beginners.pdf
Payment Gateway Testing Simplified_ A Step-by-Step Guide for Beginners.pdfPayment Gateway Testing Simplified_ A Step-by-Step Guide for Beginners.pdf
Payment Gateway Testing Simplified_ A Step-by-Step Guide for Beginners.pdf
 
%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein
%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein
%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein
 
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
 
SHRMPro HRMS Software Solutions Presentation
SHRMPro HRMS Software Solutions PresentationSHRMPro HRMS Software Solutions Presentation
SHRMPro HRMS Software Solutions Presentation
 
AI & Machine Learning Presentation Template
AI & Machine Learning Presentation TemplateAI & Machine Learning Presentation Template
AI & Machine Learning Presentation Template
 
+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...
 
%in tembisa+277-882-255-28 abortion pills for sale in tembisa
%in tembisa+277-882-255-28 abortion pills for sale in tembisa%in tembisa+277-882-255-28 abortion pills for sale in tembisa
%in tembisa+277-882-255-28 abortion pills for sale in tembisa
 
%+27788225528 love spells in Vancouver Psychic Readings, Attraction spells,Br...
%+27788225528 love spells in Vancouver Psychic Readings, Attraction spells,Br...%+27788225528 love spells in Vancouver Psychic Readings, Attraction spells,Br...
%+27788225528 love spells in Vancouver Psychic Readings, Attraction spells,Br...
 
%+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...
 
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
 
introduction-to-automotive Andoid os-csimmonds-ndctechtown-2021.pdf
introduction-to-automotive Andoid os-csimmonds-ndctechtown-2021.pdfintroduction-to-automotive Andoid os-csimmonds-ndctechtown-2021.pdf
introduction-to-automotive Andoid os-csimmonds-ndctechtown-2021.pdf
 
The Top App Development Trends Shaping the Industry in 2024-25 .pdf
The Top App Development Trends Shaping the Industry in 2024-25 .pdfThe Top App Development Trends Shaping the Industry in 2024-25 .pdf
The Top App Development Trends Shaping the Industry in 2024-25 .pdf
 
%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein
%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein
%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein
 
Software Quality Assurance Interview Questions
Software Quality Assurance Interview QuestionsSoftware Quality Assurance Interview Questions
Software Quality Assurance Interview Questions
 
AI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
AI Mastery 201: Elevating Your Workflow with Advanced LLM TechniquesAI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
AI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
 
Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...
Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...
Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...
 
8257 interfacing 2 in microprocessor for btech students
8257 interfacing 2 in microprocessor for btech students8257 interfacing 2 in microprocessor for btech students
8257 interfacing 2 in microprocessor for btech students
 

Java, what's next?

  • 1. Java, what’s next? by Stephan Janssen
  • 2. • Founder of Devoxx • Co-founder of Voxxed (Days) • Co-founder Devoxx4Kids • Java Champion • Passionate Developer Who am I ?
  • 3. “The Future Is Complicated” - John Rose , JVM Architect
  • 4. “For Java to remain competitive it must not just continue to move forward — it must move forward faster.” - Mark Reinhold , Chief Architect of the Java Platform Group at Oracle
  • 5. @Stephan007 More Java Releases • Every 6 months feature releases (March, September) • Long-term support releases every 3 years • Next release for March 2018 • Details @ https://mreinhold.org/blog/forward-faster
  • 7. @Stephan007 • Project Amber • Project Valhalla • Project Panama - Interconnecting JVM and native code • Project Loom - Make Concurrency simple(r) again! • Project Metropolis - The holy Graal : a Java compiler & interpreter
  • 8. How will this effect you?
  • 10. @Stephan007 Project Amber • Local-Variable Type Inference • Enhanced Enums • Lambda Leftovers • Pattern matching • Switch expression https://openjdk.java.net/projects/amber/
  • 11. JEP 286 Local-Variable Type Inference (LVTI) (Java 18.3 target release)
  • 12. @Stephan007 Expanded Type Inference List<String> empty = Collections.<String>emptyList(); List<String> empty = Collections.emptyList(); • Java 5: type inference for generic method type arguments • Java 7: type inference for constructor type arguments List<String> newList = new ArrayList<String>(); List<String> newList = new ArrayList<>(); • Java 8: type inference for lambda formals Predicate<String> isEmpty = (String s) -> s.isEmpty(); Predicate<String> isEmpty = s -> s.isEmpty(); Brian Goetz @ http://bit.ly/2x3Wop9
  • 13. @Stephan007 Local-Variable Type Inference (JEP 286) URL url = new URL(“https://devoxx.com"); URLConnection conn = url.openConnection(); Scanner scanner = new Scanner(conn.getInputStream(), “UTF-8”); var url = new URL(“https://devoxx.com"); var conn = url.openConnection(); var scanner = new Scanner(conn.getInputStream(), “UTF-8”); Brian Goetz @ http://bit.ly/2x3Wop9
  • 14. @Stephan007 LVTI warnings var x = { 1, 2, 3 }; // array initializer needs an explicit target-type http://cr.openjdk.java.net/~mcimadamore/8177466/lvti-diags.html var x = null; // variable initializer is 'null' var x; // cannot use 'var' on variable without initializer var x = m(x); // cannot use 'var' on self-referencing variable class var { } // as of release 9, 'var' is a restricted local variable type
  • 15. @Stephan007 LVTI warnings var[] x = s; // ‘var' is not allowed as an element type of an array http://cr.openjdk.java.net/~mcimadamore/8177466/lvti-diags.html var x = 1, y = 2; // 'var' is not allowed in a compound declaration var<String> list() { return null; } // illegal ref to restricted type 'var' var x = () -> { }; // lambda expression needs an explicit target-type
  • 16. @Stephan007 Hidden compiler option -XDfind=local Detect local variables whose declared type can be replaced by 'var' http://mail.openjdk.java.net/pipermail/compiler-dev/2017-September/011060.html class TestLVTI { void test() { String s2 = ""; for (String s = s2 ; s != "" ; ) { } Object o = ""; } } TestLVTI.java:3: warning: Redundant type for local variable (replace explicit type with 'var'). String s2 = ""; ^ TestLVTI.java:4: warning: Redundant type for local variable (replace explicit type with 'var'). for (String s = s2 ; s != "" ; ) { } ^ 2 warnings The type of o is not redundant!
  • 17. @Stephan007 Other JVM Languages Groovy Kotlin def robot = new Robot() // mutable property var name = “Hello” // Read-only // there's no 'new' keyword val result = Address() Scala & Lombok // Mutable var name = ”Hello” // Read-only val result = new Address() BTW None of these JVM languages demand a semi-colon! 🤓
  • 18. @Stephan007 Immutability? http://mail.openjdk.java.net/pipermail/platform-jep-discuss/2016-December/000066.html “Local variables are in reality the least important place where we need more help making things immutable. Local variables are immune to data races; most locals are effectively final anyway.” - Brian Goetz
  • 19. @Stephan007 Project Amber • JEP 286 Local-Variable Type Inference • JEP 301 Enhanced Enums • JEP 302 Lambda Leftovers
  • 21. @Stephan007 Generic Enums “Enhance the expressiveness of the enum construct in the Java Language by allowing type-variables in enums, and performing sharper type-checking for enum constants.” - Maurizio Cimadamore http://openjdk.java.net/jeps/301
  • 22. @Stephan007 Enum enhancements enum Argument<X> { // declares generic enum STRING<String>(String.class), INTEGER<Integer>(Integer.class), ... ; Class<X> clazz; Argument(Class<X> clazz) { this.clazz = clazz; } Class<X> getClazz() { return clazz; } } Class<String> cs = Argument.STRING.getClazz(); //uses sharper typing of enum constant http://openjdk.java.net/jeps/301 • Enum constants to carry constant-specific type information • Constant-specific state and behavior. 
  • 24. @Stephan007 Treatment of underscores • Use an uncerscore for unnamed lambda parameters BiFunction<Integer, String, String> biss = (i, _) -> String.valueOf(i); http://openjdk.java.net/jeps/302
  • 25. @Stephan007 Shadowing a lambda parameter • Allow lambda parameters to shadow variables in enclosing scopes. • And locals declared with a lambda. Map<String, Integer> msi = … … String key = computeSomeKey(); msi.comuteIfAbstent(key, key -> key.length()); // error! http://openjdk.java.net/jeps/302
  • 27. @Stephan007 String formatted = “unknown”; if (constant instanceof Integer) { int i = (Integer)constant; formatted = String.format(“int %d”, i); } else if (constant instanceof Byte) { byte b = (Byte)constant; formatted = String.format(“byte %d”, b); } // … https://www.voxxed.com/2017/08/pattern-matching-java/
  • 28. @Stephan007 Pattern Matching String formatted = “unknown”; switch(constant) { case Integer i : formatted = String.format(“int %d”, i); break; case Byte b : formatted = String.format(“byte %d”, b); break; // … default: formatted = String.format(“Unknown: %s”, constant); } https://www.voxxed.com/2017/08/pattern-matching-java/
  • 29. @Stephan007 Switch Expression String formatted = switch(constant) { case Integer i -> String.format(“int %d”, i); case Byte b -> String.format(“byte %d”, b); case Long l -> String.format(“long %d”, l); case Double d -> String.format(“double %f”, d); case String s -> String.format(“string %s”, s); default -> “Unknown”; } https://www.voxxed.com/2017/08/pattern-matching-java/
  • 30. @Stephan007 Enhanced Switch Expression Shape s = … double area = switch (shape) { case Circle(var center, var radius) -> PI * radius * radius; case Square(var lowerLeft, var edge) -> edge * edge; case Rect(var lowerLeft, var upperRight) -> (upperRight.x - lowerLeft.x) * (upperRight.y - lowerLeft.y); // … } interface Shape { } class Circle implements Shape { Point center; double radius; } class Square implements Shape { Point lowerLeft; double edge; } class Rect implements Shape { Point lowerLeft; Point upperRight; } JavaOne 2017 keynote : https://www.youtube.com/watch?v=Tf5rlIS6tkg
  • 31. @Stephan007 val x = Random.nextInt(10) val value = x match { case 0 => “zero” case 1 => "one" case 2 => "two" case _ => "many" } val value = when(x) { 0 -> “zero” 1 -> "one" 2 -> "two" else -> "many" }
  • 33. JEP 169 Value Types “Codes like a class, works like an int!”
  • 34. @Stephan007 public class Point { final int x; final int y; } http://cr.openjdk.java.net/~jrose/values/values-0.html
  • 35. @Stephan007 public class Point { final int x; final int y; public Point(int x, int y) { this.x = x; this.y = y; } public boolean equals(Object o) { return o instanceof Point && x == ((Point)o).x && y == ((Point)o).y; } public int hashCode() { return x + 31 * y; } public String toString() { return String.format(“Point[%d,%d]”, x, y); } } http://cr.openjdk.java.net/~jrose/values/values-0.html
  • 36. Data Classes “Just data, no identiy”
  • 37. @Stephan007 public class Point(int x, int y) { } http://cr.openjdk.java.net/~jrose/values/values-0.html
  • 38. @Stephan007 Value Types Requirements • Final, not extensible • Only interface parents • Immutable fields • No identity • Equality based on state • No recursive definitions • Non-nullable values • Value semantics • No (representational) polymorphism • Multiple fields supported
  • 39. JEP 218 Generics over Primitive Types
  • 41. @Stephan007 Generic type arguments are constrained to extend Object • Supporting generic primitive and value types arguments! class Box<T> { private final T t; public Box(T t) { this.t = t; } public T get() { return t; } } http://openjdk.java.net/jeps/218 • Suppose we want to specialize the following class with T=int
  • 42. @Stephan007 • Project Amber • Project Valhalla • Project Panama - Interconnecting JVM and native code • Project Loom - Make Concurrency simple(r) again! • Project Metropolis - The holy Graal
  • 44. IF expressions Even better, change all statements into expressions 🤓
  • 45.
  • 46. @Stephan007 Resources : Brian Goetz - Java Language Architect, Oracle John Rose, JVM Architect, Oracle