Keeping up with Java - GOTO Conference · 2019-06-19 · lib1 lib2 jdk ~300mb application ~2mb JVM...
Transcript of Keeping up with Java - GOTO Conference · 2019-06-19 · lib1 lib2 jdk ~300mb application ~2mb JVM...
By Sander Mak
Keeping up
@Sander_Makwith Java
About SanderFellow, Software Architect
@ Luminis
Experience in modular development stacks
Conference Speaker & Author
@Sander_Mak
Java
9(Sept. 2017)
@Sander_Mak
Quick Java Module Overview
@Sander_Mak
Modules
Packages
Classes
Methods
What's a Module?
10 PRINT "REALLY?!"; 20 GOTO 10;
@Sander_Mak
module main { }
module-info.java
Module Declarations
main.web main.persistence main.integration
main
@Sander_Mak
module main { requires helper; }
module-info.java
module helper {
}
module-info.java
helper
Explicit Dependencies
main.web main.persistence main.integration
main
@Sander_Mak
module main { requires helper; }
module helper { exports helper.api;
}
module-info.java module-info.java
helper.api
helper
Well-defined Interfaces
main.web main.persistence main.integration
main
@Sander_Mak
module main { requires helper; }
module helper { exports helper.api;
}
module-info.java module-info.java
helper.api
helper.impl
helper
Strong Encapsulation
main.web main.persistence main.integration
main
@Sander_Mak
module main { requires helper; }
module helper { exports helper.api; opens helper.impl; }
module-info.java module-info.java
helper.api
helper.impl
helper
Open for Run-time Reflection
main.web main.persistence main.integration
main
@Sander_Mak
Demo: EasyText
easytext.cli
easytext.analysis
@Sander_Mak
Why?Modular JDKMaintainability
Reliable compositionFlexibility
@Sander_Mak
quick refresher why/advantages
(JDK: modularized, your app: architecture from whiteboard to code, explicit dependencies in language, strong encapsulation, jlink
Why?
Decrease the model-code gap
@Sander_Mak
IoT Device
jlink
+main
lib1 lib2
jdk ~300mb
application ~2mb
JVM
main
lib1 lib2
java.base
java.logging
java.xml
Custom Run-time Image
~25mb
@Sander_Mak
Impact on Java 8 codebasesUse of encapsulated JDK types:
Run-time warningsCompile-time errors
Use of enterprise APIs in JDK:Won't resolve by defaultGone in Java 11!
java.corba java.xml.bind java.xml.ws.* java.activation java.transaction
@Sander_Mak
R
jshell
EPL
eadvalrintoop
Input codeRun codeSee resultsIteratively refine
@Sander_Mak
jshell
DEMO
@Sander_Mak
List<String> books = new ArrayList<>(); books.add("Java 9 Modularity"); books.add("Designing Data-Intensive Applications"); books.add("Java 8 Lambdas");
Collection Factory Methods
@Sander_Mak
Collection Factory Methods
List<String> books = List.of("Java 9 Modularity", "Designing Data-Intensive Applications", "Java 8 Lambdas");
Set.of Map.of
@Sander_Mak
Java
10(March 2018)
@Sander_Mak
var
String name = "Sander"; public void aMethod() { String name = "Sander"; }
public void aMethod() { var name = "Sander"; }
@Sander_Mak
var
URL url = new URL("https://javamodularity.com"); URLConnection connection = url.openConnection(); BufferedInputStream inputStream = new BufferedInputStream(connection.getInputStream());
var bookurl = new URL("https://javamodularity.com"); var connection = bookurl.openConnection(); var bookStream = new BufferedInputStream(connection.getInputStream());
DEMO
@Sander_Mak
Java
11(Sept. 2018)
@Sander_Mak
HttpClient
HttpURLConnectionHTTP/2 & WebSocketReactive Streams Support
@Sander_Mak
HttpClient
send sendAsync ...
HttpClient.Builder
HttpRequest
uri headers method ...
HttpRequest.Builder
HttpResponse
uri statusCode body ...newBuilder
newBuilder
HttpClient
@Sander_Mak
HttpClient
HttpClient httpClient = HttpClient.newHttpClient();
HttpRequest req = HttpRequest.newBuilder(URI.create("https://google.com")) .GET() .build();
HttpResponse<String> response = httpClient.send(req, BodyHandlers.ofString())
@Sander_Mak
Java
12(March 2019)
@Sander_Mak
Switch Statements
int numletters; switch (day) { case MONDAY: FRIDAY: SUNDAY: numletters = 6; break; case TUESDAY: numletters = 7; break; case THURSDAY: SATURDAY: numletters = 8; break; case WEDNESDAY: numletters = 9; break; }
@Sander_Mak
Preview Feature: Switch Expression
int numLetters = switch (day) { case MONDAY, FRIDAY, SUNDAY -> 6; case TUESDAY -> 7; case THURSDAY, SATURDAY -> 8; case WEDNESDAY -> 9; };
@Sander_Mak
Let's Talk About Adoption
@Sander_Mak
https://jaxenter.com/java-8-still-strong-java-10-142642.html
https://www.baeldung.com/java-in-2018https://www.jetbrains.com/research/devecosystem-2018/java/
Java Magazine & Snyk
@Sander_Mak
Java 11
Long Term Support
Java 9
Java 10
Java 12
Java 13
6 months
Java 11 Java 11 LTS
minimum 3 years
@Sander_Mak
Which JDK?
JDK 11 changes the game
@Sander_Mak
Oracle JDK 8Binary Code License
Oracle JDK 11Java SE Subscription
$
OpenJDK 11GPL v2
Amazon CorrettoAdoptOpenJDKRed Hat OpenJDK
=