ebook img

Mastering Java 9 PDF

441 Pages·2017·13.076 MB·english
Save to my drive
Quick download
Download
Most books are stored in the elastic cloud where traffic is expensive. For this reason, we have a limit on daily download.

Preview Mastering Java 9

Mastering Java 9 Write reactive, modular, concurrent and secure code Dr. Edward Lavieri Peter Verhas BIRMINGHAM - MUMBAI Mastering Java 9 Copyright © 2017 Packt Publishing First published: October 2017 Production reference: 1031017 Published by Packt Publishing Ltd. Livery Place 35 Livery Street Birmingham B3 2PB, UK. ISBN 978-1-78646-873-4 www.packtpub.com Contents Preface 1 Chapter 1: The Java 9 Landscape 7 Java 9 at 20,000 feet 7 Breaking the monolith 9 Playing around with the Java Shell 10 Taking control of external processes 11 Boosting performance with G1 11 Measuring performance with JMH 11 Getting started with HTTP 2.0 12 Encompassing reactive programming 12 Expanding the wish list 12 Summary 13 Chapter 2: Discovering Java 9 14 Improved Contended Locking [JEP 143] 15 Improvement goals 16 Segmented code cache [JEP 197] 16 Memory allocation 17 Smart Java compilation, phase two [JEP 199] 18 Resolving Lint and Doclint warnings [JEP 212] 18 Tiered attribution for javac [JEP 215] 19 Annotations pipeline 2.0 [JEP 217] 20 New version-string scheme [JEP 223] 22 Generating run-time compiler tests automatically [JEP 233] 22 Testing class-file attributes generated by Javac [JEP 235] 23 Storing interned strings in CDS archives [JEP 250] 25 The problem 25 The solution 26 Preparing JavaFX UI controls and CSS APIs for modularization [JEP 253] 26 JavaFX overview 26 Implications for Java 9 28 Compact strings [JEP 254] 29 Pre-Java 9 status 30 New with Java 9 30 Merging selected Xerces 2.11.0 updates into JAXP [JEP 255] 30 Updating JavaFX/Media to newer version of GStreamer [JEP 257] 31 HarfBuzz Font-Layout Engine [JEP 258] 32 HiDPI graphics on Windows and Linux [JEP 263] 33 Marlin graphics renderer [JEP 265] 34 Unicode 8.0.0 [JEP 267] 34 New in Unicode 8.0.0 34 Updated Classes in Java 9 35 Reserved stack areas for critical sections [JEP 270] 35 The pre-Java 9 situation 35 New in Java 9 36 Dynamic linking of language-defined object models [JEP 276] 37 Proof of concept 38 Additional tests for humongous objects in G1 [JEP 278] 38 Improving test-failure troubleshooting [JEP 279] 40 Environmental information 40 Java process information 41 Optimizing string concatenation [JEP 280] 41 HotSpot C++ unit-test framework [JEP 281] 42 Enabling GTK 3 on Linux [JEP 283] 42 New HotSpot build system [JEP 284] 44 Summary 44 Chapter 3: Java 9 Language Enhancements 45 Working with variable handlers [JEP 193] 46 Working with the AtoMiC Toolkit 47 Using the sun.misc.Unsafe class 49 Eliding depreciation warnings on import statements [JEP 211] 50 Milling Project Coin [JEP 213] 51 Using the @SafeVarargs annotation 51 The try-with-resource statement 52 Using the diamond operator 54 Discontinuing use of the underscore 55 Making use of private interface methods 56 Processing import statements correctly [JEP 216] 58 Summary 60 Chapter 4: Building Modular Applications with Java 9 61 A modular primer 62 Reviewing Java's platform module system [JEP-200] 64 Modularizing JDK source code [JEP-201] 68 Pre-Java 9 JDK source code organization 69 Development tools 70 Deployment 70 Internationalization 70 Monitoring 71 RMI 71 Security 71 Troubleshooting 71 Web services 72 JavaFX tools 72 Java runtime environment 72 Source code 72 Libraries 73 C header files 74 Database 75 JDK source code reorganized 75 Understanding modular run-time images [JEP-220] 75 Runtime format adoption 76 Runtime image restructure 76 Supporting common operations 78 De-privileging JDK classes 78 Preserving existing behaviors 78 Getting to know the module system [JEP-261] 78 Module paths 79 Access-control boundary violations 80 Runtime 80 Modular Java application packaging [JEP-275] 82 Advanced look at the Java Linker 83 Java Packager options 83 JLink - The Java Linker [JEP-282] 87 Encapsulating most internal APIs [JEP-260] 89 Summary 90 Chapter 5: Migrating Applications to Java 9 91 Quick review of Project Jigsaw 92 Classpath 92 The monolithic nature of the JDK 93 How modules fit into the Java landscape 94 Base module 95 Reliable configuration 96 Strong encapsulation 97 Migration planning 98 Testing a simple Java application 98 Potential migration issues 101 The JRE 102 Access to internal APIs 102 Accessing internal JARs 103 JAR URL depreciation 103 Extension mechanism 105 The JDK's modularization 106 Advice from Oracle 107 Preparatory steps 108 Getting the JDK 9 early access build 108 Running your program before recompiling 108 Updating third-party libraries and tools 108 Compiling your application 109 Pre-Java 9 -source and -target options 111 Java 9 -source and -target options 112 Running jdeps on your code 112 Breaking encapsulation 115 The --add-opens option 116 The --add-exports option 116 The --permit-illegal-access option 117 Runtime image changes 117 Java version schema 117 JDK and JRE layout 118 What has been removed 120 Updated garbage collection 121 Deployment 122 JRE version selection 122 Serialized applets 122 JNLP update 123 Nested resources 123 FX XML extension 123 JNLP file syntax 125 Numeric version comparison 125 Useful tools 126 Java environment - jEnv 127 Maven 128 Obtaining the M2Eclipse IDE 129 Summary 132 Chapter 6: Experimenting with the Java Shell 133 What is JShell? 134 Getting Started with JShell 134 Practical uses of JShell 140 Feedback modes 141 Creating a custom feedback mode 146 Listing your assets 148 Editing in the JShell 149 Modifying text 149 Basic navigation 150 Historical navigation 150 Advanced editing commands 151 Working with scripts 151 Start up scripts 151 Loading scripts 152 Saving scripts 152 Advanced scripting with JShell 153 Summary 154 Chapter 7: Leveraging the New Default G1 Garbage Collector 155 Overview of garbage collection 156 Object life cycle 156 Object creation 156 Object mid-life 157 Object destruction 157 Garbage collection algorithms 158 Mark and sweep 158 Concurrent mark sweep (CMS) garbage collection 158 Serial garbage collection 159 Parallel garbage collection 159 G1 garbage collection 159 Garbage collection options 160 Java methods relevant to garbage collection 165 The System.gc() method 166 The finalize() method 168 Pre-Java 9 garbage collection 169 Visualizing garbage collection 170 Garbage collection upgrades in Java 8 171 Case study - Games written with Java 172 Collecting garbage with the new Java platform 173 Default garbage collection 173 Depreciated garbage collection combinations 175 Unified garbage collection logging 176 Unified JVM logging (JEP-158) 177 Tags 177 Levels 178 Decorations 178 Output 179 Command-line options 179 Unified GC logging (JEP-271) 179 Garbage collection logging options 180 The gc tag 182 Macros 182 Additional considerations 183 Persistent issues 184 Making objects eligible for garbage collection 184 Summary 187 Chapter 8: Microbenchmarking Applications with JMH 188 Microbenchmarking overview 189 Approach to using JMH 190 Installing Java 9 and Eclipse with Java 9 support 190 Hands-on experiment 193 Microbenchmarking with Maven 195 Benchmarking options 202 Modes 203 Time units 203 Techniques for avoiding microbenchmarking pitfalls 204 Power management 204 OS schedulers 204 Time sharing 205 Eliminating dead-code and constant folding 205 Run-to-run variance 206 Cache capacity 207 Summary 207 Chapter 9: Making Use of the ProcessHandle API 208 What are processes? 209 The new ProcessHandle interface 210 Getting the PID of the current process 210 Getting information about a process 211 Listing processes 213 Listing children 213 Listing descendants 214 Listing all processes 215 Waiting for processes 216 Terminating processes 217 A small process controller application 219 Main class 220 Parameters class 221 The ParamsAndHandle class 222 The ControlDaemon class 223 Summary 226 Chapter 10: Fine-Grained Stack Tracing 227 Overview of the Java Stack 227 The importance of stack information 228 Example - Restricting callers 230 Example - Getting logger for caller 233 Working with StackWalker 234 Getting an instance of StackWalker 234 RETAIN_CLASS_REFERENCE 234 SHOW_REFLECT_FRAMES 235 SHOW_HIDDEN_FRAMES 235 Final thoughts on enum constants 238 Accessing classes 238 Walking methods 239 StackFrame 241 Performance 242 Summary 242 Chapter 11: New Tools and Tool Enhancements 243 The new HTTP client [JEP-110] 244 The HTTP client before Java 9 244 Java 9's new HTTP client 247 New API limitations 248 Simplified Doclet API [JEP-221] 250 The pre-Java 9 Doclet API 250 API enums 252 API classes 252 API interfaces 253 Problems with the pre-existing Doclet API 254 Java 9's Doclet API 254 Compiler tree API 254 Language model API 258 The AnnotatedConstruct interface 259 The SourceVersion enum 259 The UnknownEntityException exception 261 HTML5 Javadoc [JEP-224] 262 Javadoc search [JEP-225] 267 Introducing camel case search 268 Remove launch-time JRE version selection [JEP-231] 268 Parser API for Nashorn [JEP-236] 269 Nashorn 269 Using Nashorn as a command-line tool 270 Using Nashorn as an embedded interpreter 273 EMCAScript 274 Parser API 275 Multi-release JAR files [JEP-238] 277 Identifying multi-release JAR files 277 Related JDK changes 279 Java-level JVM compiler interface [JEP-243] 280 BeanInfo annotations [JEP-256] 281 JavaBean 281 BeanProperty 282 SwingContainer 283 BeanInfo classes 283 TIFF image input/output [JEP-262] 284 Platform logging API and service [JEP-264] 286 The java.util.logging package 287 Logging in Java 9 289 XML Catalogs [JEP-268] 290 The OASIS XML Catalog standard 290 JAXP processors 291 XML Catalogs prior to Java 9 291 Java 9 platform changes 291 Convenience factory methods for collections [JEP-269] 291 Using collections before Java 9 292 Using new collection literals 295 Platform-specific desktop features [JEP-272] 295 Enhanced method handles [JEP-274] 296 Reason for the enhancement 297 Lookup functions 297 Argument handling 298 Additional combinations 298 Enhanced deprecation [JEP-277] 299 What the @Deprecated annotation really means 300 Summary 300 Chapter 12: Concurrency and Reactive Programming 301 Reactive Programming 302

See more

The list of books you might like

Most books are stored in the elastic cloud where traffic is expensive. For this reason, we have a limit on daily download.