Fork me on GitHub

Java 9

Lightning Talk:

An overview over
the new features

? for help, space to navigate

2016-07-05
Benjamin Schmid
Technology Advisor
Tip: filename and JEP are direct links
Creative Commons Lizenzvertrag
Java 9: An short summary & overview over the new features by Benjamin Schmid
is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License.. Based in parts on the work of Reveal.JS.
## Datasheet
##### Datasheet - **82** JEP targeted - GA Release: ~~2016-09-22~~ **2017-03-23** - Brewing since: 2014-08-11
##### Highlights - Jigsaw - Tooling - HTTP API - Language details
# Tooling

HTML5 Javadoc example output

Example Java 9 Javadoc output with HTML5 enabled
## Language details
### Process Control ````java
// Get PIDs of own or started processes
                    out.println("Your pid is " + ProcessHandle.current().pid());

                    Process p = Runtime.getRuntime().exec("sleep 1h");
                    ProcessHandle h = ProcessHandle.of(p.pid())  // Optional
                            .orElseThrow(IllegalStateException::new);

                    // Do things on exiting process          // CompletableFuture
                    h.onExit().thenRun( ()-> out.println("Sleeper exited") );

                    // Get info on process
                    out.printf("[%d] %s - %s\n", h.pid(),
                               h.info().user().orElse("unknown"),
                               h.info().commandLine().orElse("none"));

                    // Kill a process
                    h.destroy();
````
### Immutable Collection Factories ````java
/* Comment sections would break ... */
                    List<Integer> listOfNumbers = List.of(1, 2, 3, 4, 5/*, null*/);

                    Set<Integer> setOfNumbers = Set.of(1, 2, 3, 4, 5/*, 1*/);

                    Map<String, String> mapOfString =
                        Map.of("key1", "value1", "key2", "value2");

                    Map<String, String> moreMapOfString =
                        Map.ofEntries(
                            Map.entry("key1", "value1"),
                            Map.entry("key2", "value2")/*,
                            Map.entry("key1", "value3")*/
                    );
                    ````
                
### StackWalker ````java
// return class/method only for our classes.
                    private static List<String> walkAndFilterStackframe() {
                      return StackWalker.getInstance().walk(s ->
                        s.map( frame-> frame.getClassName()+"/"+frame.getMethodName())
                               .filter(name -> name.startsWith("de.exxcellent"))
                               .limit(10)
                               .collect(Collectors.toList()) );
                    }
````
### New Input Stream Utilities ````java
// All bytes from an InputStream at once
                    byte[] result = new ByteArrayInputStream(buf)
                        .readAllBytes();

                    // Directly redirect an InputStream to an OutputStream
                    new ByteArrayInputStream(buf)
                        .transferTo(System.out);
````
### HTTP/2 Client ````java /** * The HTTP API functions asynchronously & synchronously. In * asynchronous mode, work is done in threads (ExecutorService). */ public static void main(String[] args) throws Exception { HttpClient.getDefault() .request(URI.create("https://www.exxcellent.de")) .GET() .responseAsync() // CompletableFuture :D .thenAccept(httpResponse -> out.println(httpResponse.body(HttpResponse.asString())) ); Thread.sleep(999); // Give worker thread some time. } ````
# Jigsaw
### Tools - List built-in modules: `java –listmods` - Find dependencies: `jdeps –jdkinternals app.jar`
### Resources - [JVM Module Summary](http://cr.openjdk.java.net/~mr/jigsaw/ea/module-summary.html) - [The State of the Module System](http://openjdk.java.net/projects/jigsaw/spec/sotms/)
## Many (obscure) Details