Download Issue
Total Page:16
File Type:pdf, Size:1020Kb
Issue October 2019 | presented by www.jaxenter.com #70 The digital magazine for enterprise developers JavaThe JDK’s hidden 13 treasures i Jakarta EE 8 Let the games begin JDK 13 Why text blocks are worth the wait OpenJFX 13 JavaFX gets its own identity © Teguh Mujiono/Shutterstock.com, Pushkin/Shutterstock.com Illustrationen: Sun Microsystems Inc., S&S Media Editorial Let’s celebrate Java – three times! It’s that time again: A new Java version is here! Java 13 Last but not least: Jakarta EE, the follow-up project of was launched as planned, six months after the release Java EE, has announced its first release under the umbrella of of Java 12, and again it has some interesting features on the Eclipse Foundation. We got hold of the executive director board. In this issue of Jax Magazine, we’ve covered them of the Eclipse Foundation, Mike Milinkovich, and asked him for you in detail. about the current status of Jakarta EE. The good news doesn’t end there, as JavaFX 13 has also been released. The UI toolkit is no longer included in the JDK Happy reading, but has adjusted its new version releases to the new Java re- lease cadence. Find out what’s new here! Hartmut Schlosser Java 13 – a deep dive into the JDK’s 3 Kubernetes as a multi-cloud 17 new features operating system Falk Sippach Patrick Arnold Index Java 13 – why text blocks are worth the wait 6 Multi-tier deployment with Ansible 21 Tim Zöller Daniel Stender Jakarta EE 8 is sprinting towards an 9 Do we need a service mesh? 28 exciting future for enterprise Java Anton Weiss Thilo Frotscher Neural networks with PyTorch 31 Jakarta EE 8 release – the future is now! 11 Chi Nhan Nguyen Interview with Mike Milinkovich Machine learning with the Apache Kafka 37 OpenJFX 13 – “JavaFX gets its own identity” 13 ecosystem Interview with Dirk Lemmermann Kai Wähner JavaFX 13 release 14 Python: “We see a trend towards adding 43 Interview with Johan Vos more and more typing support“ The state of DevOps 16 Interview with Oz Tiram Jeff Sussna www.JAXenter.com | October 2019 2 Java 13 © Teguh Mujiono/Shutterstock.com, Pushkin/Shutterstock.com Illustrationen: Sun Microsystems Inc., S&S Media Every half a year, new Java is here! Java 13 – a deep dive into the JDK’s new features Java expert Falk Sippach celebrates the release of Java 13 in this article talking about what’s new, why it matters and what it means for the future of the programming language. by Falk Sippach • JEP 353: Reimplement the Legacy Socket API • JEP 354: Switch Expressions (Preview) You can tell this year sped by in a flash because Java’s version • JEP 355: Text Blocks (Preview) number has already increased by two! Meanwhile, we Java developers should have got used to the short release cycles. At first glance, it doesn’t look like much. In fact, due to the After all, we can now regularly try out new functions and are short time since the release of Java 12, we can’t really expect not killed every few years by a huge range of new features. In too many changes. Instead, the releases between the Long- this article we take a look at Java 13, which is released today, Term Support (LTS) versions are mostly there to offer certain September 17th, 2019. features as previews in order to get early feedback from the users. The functions are implemented in the JEPs and – as Java 13 at a glance soon as they have reached a certain maturity – delivered with The following Java Enhancement Proposals have made it into the next release of the defined half-yearly cycle. JDK 13: This makes it impossible to predict exactly how many new functions relevant to the typical Java programmer will be • JEP 350: Dynamic CDS Archives included in the next release. The goal is to finalize the pre- • JEP 351: ZGC: Uncommit Unused Memory view features by the next LTS version so that they are stable www.JAXenter.com | October 2019 3 Java 13 enough and will look good for the next three years. In Septem- The preview feature must also be activated at startup. Of ber 2021, Java 17 will take over the legacy of Java 8 and 11. course, build tools (Maven, etc.) also have configuration switches: Enhancements for Switch Expressions If you look at the feature list above from a developer’s point java --enable-preview Examples of view, it’s the last two points that are mainly interesting. For example, the Switch Expressions introduced as a preview Text Blocks instead of Raw String Literals in Java 12 have been extended due to user feedback. The Text blocks are actually only a small part of the Raw String Switch Expression is an alternative to the cumbersome and Literals (JEP 326) originally planned for Java 12. The first error-prone Switch Statement. A detailed overview of its use implementation of Raw String Literals was not yet thought can be found in various articles on Java 12 [1]. through down to the last detail, users’ feedback raised many The biggest change in Java 13 is the replacement of the questions. The exact details can be found in the mailing keyword break in the switch expression by yield. The back- list [2]. Java 13 “only” has multi-line text blocks for now. ground is the better differentiation between switch statement But that’s better than nothing. After all, many Java appli- (with possible break) and expressions (with yield). The yield cations process code snippets from other languages such as statement exits the switch and returns the result of the current HTML or SQL, which usually consist of several lines for the branch, similar to a return. sake of clarity. Until now, such strings could only be defined A code example follows in Listing 1. Above, we see a state- in a very cumbersome way, which makes them difficult to ment with break and fall through. In the direct comparison read. For example, extra control commands (escaping with follows a switch expression with the new keyword yield and \n) must be used for line breaks. Other languages such as multiple labels. In contrast to the first variant, no variable is Groovy, Scala or Kotlin have long offered the possibility of changed, but the result of the case branch is returned directly. defining multi-line texts. The Arrow syntax introduced in Java 12 still works (List- The new text blocks use triple quotation marks as delim- ing 2). iters and can be used wherever normal strings are allowed. Switch Expressions remain in preview for the time being, Listing 3 shows the differences between traditional and new so there could be further adjustments in future Java versions. syntax. The opening and closing triple quotes must be in a When compiling with JDK 13, the corresponding flags must separate line. Nevertheless, the actual content starts with the therefore be specified: second line. This increases the readability of the source code, as the indentation of the first line is displayed correctly in the javac --release 13 --enable-preview Examples.java source text. Further examples can be found in Tim Zöller’s article in this Listing 1 Listing 2 JaxMag, which deals specifically with JEP 355. Text blocks are re- // Switch Statement with break private static String expressionWithArrow(int i) { placed by normal strings at com- private static String statementBreak(int switchArg){ return switch (i) { pile time; in the byte code, you String str = "not set"; case 1, 2 -> "one or two"; can no longer see how the string switch (switchArg){ case 3 -> "three"; was originally defined. case 1: default -> "smaller than one or more than three"; case 2: }; Dynamic CDS Archives str = "one or two"; } Besides the new features that are break; obvious to developers, a lot has case 3: happened under the hood of the str = "three"; Listing 3 JVM and in the class library. Class break; // Without Text Blocks Data Sharing (CDS) was intro- }; String html = "<html>\n" + duced back in Java 5. The goal of return str; " <body>\n" + CDS is to shorten the start times of } " <p>Hello, Escapes</p>\n" + Java applications by storing cer- " </body>\n" + tain information about classes in // Switch Expression with yield "</html>\n"; Class Data Sharing archives. This private static String expressionBreakWithValue(int switchArg){ data can then be loaded at runt- return switch (switchArg){ // With Text Blocks ime and used by several JVMs. case 1, 2: yield "one or two"; String html = """ Until Java 10, however, the case 3: yield "three"; <html> shared archives were only accessi- default: yield "smaller than one or bigger than three"; <body> ble for the Bootstrap Class Load- }; <p>Hello, Text Blocks</p> er. Starting with Java 10, CDS } </body> </html>"""; was extended by Application Class Data Sharing (AppCDS). www.JAXenter.com | October 2019 4 Java 13 AppCDS enables the built-in system and platform class loader Since Java 10 we can look forward to new Java releases as well as user-defined class loaders to access the CDS archives. twice a year (March and September). Since of course not so Class lists are required to create the CDS archives in order to much can happen in development in half a year, the respective identify the classes to be loaded. feature lists are fortunately manageable. However, the short Previously, these class lists had to be determined by trial update cycles allow us to regularly try out the new features at runs of the application to determine which classes were actu- short intervals.