5. www.luxoft.com
Java 9
• Modular system – Jigsaw Project
• A new HTTP Client
• Process API
• Small language modifications
• Jshell Command Line Tool
• JCMD Sub-Commands
• Multi-Resolution Image API
• Variable Handles
• Publish-Subscribe Framework
• Unified JVM Logging
• New APIs
6. www.luxoft.com
Java 9 :: Java Platform Module System (JPMS)
• Module—a uniquely named, reusable group of related packages, as well as resources (such as
images and XML files) and a module descriptor specifying
• the module’s name
• the module’s dependencies (that is, other modules this module depends on)
• the packages it explicitly makes available to other modules (all other packages in the module
are implicitly unavailable to other modules)
• the services it offers
• the services it consumes
• to what other modules it allows reflection
7. www.luxoft.com
Java 9 :: Modules Types
• System Modules – These are the modules listed when we run the list-modules command above.
They include the Java SE and JDK modules.
• Application Modules – These modules are what we usually want to build when we decide to use
Modules. They are named and defined in the compiled module-info.class file included in the
assembled JAR.
• Automatic Modules – We can include unofficial modules by adding existing JAR files to the module
path. The name of the module will be derived from the name of the JAR. Automatic modules will
have full read access to every other module loaded by the path.
• Unnamed Module – When a class or JAR is loaded onto the classpath, but not the module path, it's
automatically added to the unnamed module. It's a catch-all module to maintain backward
compatibility with previously-written Java code.
9. www.luxoft.com
Java 9 :: New HTTP Client
HttpURLConnection -> HttpClient
(jdk.incubator.http.HttpClient)
It supports both HTTP/2 protocol and WebSocket handshake, with performance that should be
comparable with the Apache HttpClient, Netty and Jetty.
HttpRequest request2 = HttpRequest.newBuilder()
.uri(new URI("https://postman-echo.com/get"))
.header("key1", "value1")
.header("key2", "value2")
.GET()
.build();
15. www.luxoft.com
Java 9 :: Publish-Subscribe Framework
These interfaces correspond to the reactive-streams specification. They apply in both concurrent and
distributed asynchronous settings: All (seven) methods are defined in void "one-way" message style.
• static interface Flow.Processor<T,R> - A component that acts as both a Subscriber and Publisher.
• static interface Flow.Publisher<T> - A producer of items (and related control messages) received by
Subscribers.
• static interface Flow.Subscriber<T> - A receiver of messages.
• static interface Flow.Subscription - Message control linking a Flow.Publisher and Flow.Subscriber.
16. www.luxoft.com
Java 9 :: Publish-Subscribe Framework
@FunctionalInterface
public static interface Flow.Publisher<T> {
public void subscribe(Flow.Subscriber<? super T> subscriber);
}
public static interface Flow.Subscriber<T> {
public void onSubscribe(Flow.Subscription subscription);
public void onNext(T item) ;
public void onError(Throwable throwable) ;
public void onComplete() ;
}
public static interface Flow.Subscription {
public void request(long n);
public void cancel() ;
}
public static interface Flow.Processor<T,R> extends Flow.Subscriber<T>, Flow.Publisher<R> {
}
20. www.luxoft.com
Java 10 :: Local-Variable Type Inference
• Java 9: String message = “Hi there!”;
• Java 10: var message = “Hi there!”;
• Compiller infers the type of message from the type of initializer present on the right-hand
side
• var dict = new HashMap<String, String>();
• Illegal to use in cases:
• var x;
• var emptyList = null;
• public var x = “test”;
• var p = (String x) -> s.length() < 5;
• var arr = {”x”, “y”, “z”};
22. www.luxoft.com
Java 10 :: Time-Based Release Versioning
• Each major release of the Java platform will occur every 6 months (March and September)
• Update releases will occur every quarter (January, April, July, October)
• Long Term Release (LTS) – updates for releases will be available for at least three years
• Version format: $FEATURE.$INTERIM.$UPDATE.$PATCH
27. www.luxoft.com
Java 11 :: Dynamic Class-File Constants
• *.class format extension described support CONSTANT_Dynamic (condy)
• Using bootstrap method to define values
• java.lang.invoke.ConstantBootstraps
30. www.luxoft.com
Java 12 :: Switch Case
T result = switch (arg) {
case L1 -> e1;
case L2 -> e2;
default -> e3;
};
int j = switch (day) {
case MONDAY -> 0;
case TUESDAY -> 1;
default -> {
int k = day.toString().length();
int result = f(k);
break result;
}
};
31. www.luxoft.com
Java 12 :: Streams API has new Collector
public static <T,R1,R2,R> Collector<T,?,R> teeing(Collector<? super T,?,R1> downstream1, Collector<?
super T,?,R2> downstream2, BiFunction<? super R1,? super R2,R> merger)
var result = Stream.of("Devoxx", "Voxxed Days", "Code One", "Basel One", "Angular Connect")
.collect(
Collectors.teeing(
Collectors.filtering(n -> n.contains("xx"),
Collectors.toList()),
Collectors.filtering(n -> n.endsWith("One"), Collectors.toList()),
(List<String> list1, List<String> list2) -> List.of(list1, list2)
)
); System.out.println(result);
// -> [[Devoxx, Voxxed Days], [Code One, Basel One]]