Java 9 Revealed (eBook)
XXIV, 521 Seiten
Apress (Verlag)
978-1-4842-2592-9 (ISBN)
- Discover what is new in the Process API
- Inspect a thread's stack with the Stack-Walking API
- Use the jlink tool to create a custom runtime image
- Work with HTML5 Javadoc and use the new search feature in Javadoc
- Learn how to use new methods and collectors in the Streams API
- Learn how to create a custom logger to log messages from platform classes and how to use JVM logs
- Learn about new methods in the Optional class and how to use them
- Learn how to compare arrays and slices of arrays
- Learn how to use the enhanced try-with-resources blocks
- Make your object deserialization more secure by using object deserialization filters
Explore the new Java 9 modules, SDK, JDK, JVM, JShell and more in this comprehensive book that covers what's new in Java 9 and how to use these new features. Java 9 Revealed is for experienced Java programmers looking to migrate to Java 9. Author Kishori Sharan begins by covering how to develop Java applications using the new module system introduced in Java 9 and how to use the JShell tool in Java 9 for prototyping, compiling and testing. The book provides extensive coverage of new Java 9 features, such as the new layout of the modular JDK/JRE runtime image, new convenience factory methods for creating collections, the new spin-wait hints introduced to improve performance of spin loops in your code, and the new Desktop API for implementing platform-specific desktop features. Along the way you will also learn how to use the Reactive Streams API in Java 9 and, most importantly, this book will show you the breaking changes in Java 9.What You'll LearnHow JShell facilitates rapid development, code evaluation, and testingDiscover what is new in the Process APIInspect a thread's stack with the Stack-Walking APIUse the jlink tool to create a custom runtime imageWork with HTML5 Javadoc and use the new search feature in JavadocLearn how to use new methods and collectors in the Streams APILearn how to create a custom logger to log messages from platform classes and how to use JVM logsLearn about new methods in the Optional class and how to use themLearn how to compare arrays and slices of arraysLearn how to use the enhanced try-with-resources blocksMake your object deserialization more secure by using object deserialization filtersWho This Book Is ForExperienced Java programmers and developers.
Kishori Sharan has earned a Master of Science in Computer Information Systems degree from Troy State University, Alabama. He is a Sun Certified Java 2 programmer. He has vast experience in providing training to professional developers in Java, JSP, EJB, and Web technology. He possesses over ten years of experience in implementing enterprise level Java application.
Contents 5
About the Author 16
About the Technical Reviewer 17
Acknowledgments 18
Introduction 19
Chapter 1: Introduction 21
Introduction to JDK 9 21
How to Read This Book 22
System Requirements 23
Installing the NetBeans IDE 24
Downloading the Source Code 25
Chapter 2: The Module System 26
Life Before Java 9 26
The New Module System 28
What Is a Module? 29
Module Dependencies 30
Module Graph 32
Aggregator Modules 36
Declaring Modules 36
Module Names 38
Controlling Access to Modules 38
Declaring Dependency 40
Configuring Services 40
Module Descriptors 41
Compiling Module Declarations 41
Module Version 41
Module Source Files Structure 42
Packaging Modules 43
A Module in a Directory 43
A Module in a Modular JAR 43
A Module in a JMOD File 44
Module Path 44
Observable Modules 46
Summary 48
Chapter 3: Creating Your First Module 49
Using the Command Prompt 49
Setting Up the Directories 49
Writing the Source Code 50
Compiling the Source Code 51
Packaging the Module Code 53
Running the Program 54
Using the NetBeans IDE 57
Configuring the IDE 57
Creating the Java Project 61
Setting the Project Properties 63
Adding the Module Declaration 65
Viewing Module Graph 68
Writing the Source Code 68
Compiling the Source Code 70
Packaging the Module Code 70
Running the Program 71
Summary 73
Chapter 4: Module Dependency 75
Declaring Module Dependency 75
Troubleshooting the Example 83
Empty Package Error 83
Module Not Found Error 84
Package Does Not Exist Error 84
Module Resolution Exception 84
Implicit Readability 85
Qualified Exports 89
Optional Dependency 90
Accessing Modules Using Reflection 91
Open Modules 92
Opening Packages 92
Using Deep Reflection 93
Type Accessibility 102
Splitting Packages Across Modules 102
Restrictions in Module Declarations 103
Types of Modules 103
Normal Modules 105
Open Modules 105
Automatic Modules 105
Unnamed Modules 109
Normal Modules to Unnamed Modules 110
Unnamed Modules to Normal Modules 112
Migration Path to JDK 9 115
Disassembling Module Definitions 116
Summary 120
Chapter 5: Implementing Services 122
What Is a Service? 122
Discovering Services 124
Providing Service Implementations 125
Defining the Service Interface 127
Defining Service Providers 130
Defining a Generic Prime Service Provider 130
Defining a Faster Prime Service Provider 132
Defining a Fastest Prime Service Provider 134
Testing the Prime Service 135
Selecting and Filtering Providers 138
Testing Prime Service in Legacy Mode 140
Summary 142
Chapter 6: Packaging Modules 143
The JAR Format 143
What Is a Multi-Release JAR? 144
Creating Multi-Release JARs 145
Rules for Multi-Release JARs 152
Modular Multi-Release JARs 152
Modular Multi-Release JARs and Encapsulation 152
Multi-Release JARs and Boot Loader 153
Same Versioned Files 153
Multi-Release JARs and JAR URL 153
Multi-Release Manifest Attribute 154
The JMOD Format 154
Using the jmod Tool 154
Creating JMOD Files 156
Extracting JMOD File Contents 157
Listing JMOD File Contents 157
Describing a JMOD File 158
Recording Modules Hashes 158
Summary 161
Chapter 7: Creating Custom Runtime Images 162
What Is a Custom Runtime Image? 162
Creating Custom Runtime Images 163
Binding Services 166
Using Plugins with the jlink Tool 168
The jimage Tool 171
Summary 173
Chapter 8: Breaking Changes in JDK 9 174
The New JDK Versioning Scheme 174
Version Number 175
Prerelease Information 176
Build Information 176
Additional Information 176
Parsing Old and New Version Strings 177
Version Changes to System Properties 177
Using the Runtime.Version Class 177
Changes to the JDK and JRE 180
Layout Changes in JDK and JRE 181
Behavioral Changes 183
Endorsed Standards Override Mechanism 183
Extension Mechanism 184
Changes in Class Loaders 184
Accessing Resources 188
Accessing Resources Before JDK 9 188
Accessing Resources in JDK 9 192
Resource Naming Syntax 193
Rules to Find Resources 193
An Example of Accessing Resources in Named Modules 196
Accessing Resources in the Runtime Image 201
Using JDK Internal APIs 206
Patching Module Contents 208
Summary 210
Chapter 9: Breaking Module Encapsulation 212
What Is Breaking Module Encapsulation? 212
Command-Line Options 213
The --add-exports Option 213
The --add-opens Option 214
The --add-reads Option 215
The --illegal-access Option 215
An Example 216
Using Manifest Attributes of a JAR 224
Summary 227
Chapter 10: The Module API 229
What Is the Module API? 229
Representing Modules 231
Describing Modules 231
Representing Module Statements 232
Representing the exports Statement 232
Representing the opens Statement 233
Representing the provides Statement 233
Representing the requires Statement 233
Representing a Module Version 234
Other Properties of Modules 235
Knowing Module Basic Info 236
Querying Modules 239
Updating Modules 241
Accessing Module Resources 244
Annotation on Modules 244
Loading Classes 246
Working with Module Layers 249
Finding Modules 251
Reading Module Contents 253
Creating Configurations 255
Creating Module Layers 256
Summary 264
Chapter 11: The Java Shell 266
What Is the Java Shell? 266
The JShell Architecture 268
Starting the JShell Tool 269
Exiting the JShell Tool 271
What Are Snippets and Commands? 271
Evaluating Expressions 273
Listing Snippets 275
Editing Snippets 279
Rerunning Previous Snippets 281
Declaring Variables 281
Import Statements 284
Method Declarations 288
Type Declarations 289
Setting Execution Environment 292
No Checked Exceptions 294
Auto-Completion 295
Snippets and Commands History 298
Reading JShell Stack Trace 299
Reusing JShell Sessions 300
Resetting the JShell State 302
Reloading the JShell State 303
Configuring JShell 305
Setting the Snippet Editor 305
Setting Feedback Mode 307
Creating Custom feedback Modes 309
Setting Up Startup Snippets 313
Using JShell Documentation 316
The JShell API 318
Creating a JShell 319
Working with Snippets 320
Handling Snippet Events 322
An Example 322
Summary 326
Chapter 12: Process API Updates 327
What Is the Process API? 327
The Current Process 328
Querying Process State 329
Comparing Processes 332
Creating a Process 333
Obtaining a Process Handle 341
Terminating Processes 343
Managing Process Permissions 343
Summary 346
Chapter 13: Collection API Updates 347
The Background 347
Unmodifiable Lists 350
Unmodifiable Sets 353
Unmodifiable Maps 356
Summary 360
Chapter 14: The HTTP/2 Client API 361
What Is the HTTP/2 Client API? 362
Setting Up Examples 363
Creating HTTP Clients 364
Processing HTTP Requests 366
Obtaining an HTTP Request Builder 366
Setting HTTP Request Parameters 367
Setting Request Headers 368
Setting the Request Body 368
Creating HTTP Requests 370
Processing HTTP Responses 370
Processing Response Status and Headers 371
Processing the Response Body 372
Processing Response Trailers 376
Setting the Request Redirection Policy 376
Using the WebSocket Protocol 377
Creating a Server Endpoint 377
Creating a Client Endpoint 380
Creating a Listener 380
Building an Endpoint 382
Sending Messages to a Peer 383
Running the WebSocket Program 383
Troubleshooting the WebSocket Application 387
Summary 388
Chapter 15: Enhanced Deprecation 389
What Is Deprecation? 389
How to Deprecate an API 389
Updates to @Deprecated in JDK 9 391
Suppressing Deprecation Warnings 393
A Deprecated API Example 394
Static Analysis of Deprecated APIs 398
Dynamic Analysis of Deprecated APIs 401
No Deprecation Warnings on Imports 401
Summary 402
Chapter 16: Stack Walking 403
What Is a Stack? 403
What Is Stack Walking? 404
Stack Walking in JDK 8 404
Drawbacks to Stack Walking 407
Stack Walking in JDK 9 408
Specifying Stack-Walking Options 408
Representing a Stack Frame 408
Obtaining a StackWalker 410
Walking the Stack 411
Knowing the Caller’s Class 416
Stack-Walking Permissions 419
Summary 420
Chapter 17: Reactive Streams 422
What Is a Stream? 422
What Is Reactive Streams? 423
The Reactive Streams API in JDK 9 425
Publisher-Subscriber Interactions 425
Creating Publishers 426
Publishing Items 427
A Quick Example 428
Creating Subscribers 430
Using Processors 435
Summary 438
Chapter 18: Streams API Updates 439
New Stream Operations 439
New Collectors 443
Summary 449
Chapter 19: Platform and JVM Logging 450
Platform Logging API 450
Setting up Log4j Libraries 451
Setting Up a NetBeans Project 451
Defining a Module 452
Adding a Log4j Configuration File 453
Creating a System Logger 454
Creating a Logger Finder 456
Testing the Platform Logger 457
Further Work 460
Unified JVM Logging 461
Message Tags 462
Message Levels 463
Message Decorations 463
Message Output Destination 464
The -Xlog Syntax 464
Summary 468
Chapter 20: Other Changes in JDK 9 469
The Underscore Is a Keyword 470
Improved try-with-resources Blocks 471
Diamond Operator in Anonymous Classes 476
Private Methods in Interfaces 478
@SafeVarargs on Private Methods 480
Discarding Process Outputs 482
New Methods in the StrictMath Class 483
Changes to the ClassLoader Class 486
New Methods in the Optional< T>
Additions to the CompletableFuture< T>
Spin-Wait Hints 490
Enhancements to the Time API 491
The Clock Class 491
The Duration Class 492
Dividing a Duration by Another Duration 492
Converting and Retrieving Duration Parts 493
Truncating Duration 494
The ofInstant() Factory Method 494
Obtaining Epoch Seconds 495
Stream of LocalDate 496
New Formatting Options 498
Modified Julian Day Formatter 498
Generic Time Zone Names 498
Stream Operations with Scanner 499
Enhancement to the Matcher Class 500
Enhancement to the Objects Class 502
Comparing Arrays 503
The Applet API Is Deprecated 505
Javadoc Enhancements 506
Native Desktop Features 508
Object Deserialization Filters 512
Additions to Java I/O API 520
Summary 521
Erratum 523
Index 524
Erscheint lt. Verlag | 19.4.2017 |
---|---|
Zusatzinfo | XXIV, 521 p. 75 illus. |
Verlagsort | Berkeley |
Sprache | englisch |
Themenwelt | Informatik ► Programmiersprachen / -werkzeuge ► Java |
Informatik ► Software Entwicklung ► Objektorientierung | |
Schlagworte | API • java 9 • Java 9 interpreter • JDK • JShell • JSON • JVM • Modular • modules • object • OO • programming • REPL |
ISBN-10 | 1-4842-2592-9 / 1484225929 |
ISBN-13 | 978-1-4842-2592-9 / 9781484225929 |
Haben Sie eine Frage zum Produkt? |
Größe: 7,4 MB
DRM: Digitales Wasserzeichen
Dieses eBook enthält ein digitales Wasserzeichen und ist damit für Sie personalisiert. Bei einer missbräuchlichen Weitergabe des eBooks an Dritte ist eine Rückverfolgung an die Quelle möglich.
Dateiformat: PDF (Portable Document Format)
Mit einem festen Seitenlayout eignet sich die PDF besonders für Fachbücher mit Spalten, Tabellen und Abbildungen. Eine PDF kann auf fast allen Geräten angezeigt werden, ist aber für kleine Displays (Smartphone, eReader) nur eingeschränkt geeignet.
Systemvoraussetzungen:
PC/Mac: Mit einem PC oder Mac können Sie dieses eBook lesen. Sie benötigen dafür einen PDF-Viewer - z.B. den Adobe Reader oder Adobe Digital Editions.
eReader: Dieses eBook kann mit (fast) allen eBook-Readern gelesen werden. Mit dem amazon-Kindle ist es aber nicht kompatibel.
Smartphone/Tablet: Egal ob Apple oder Android, dieses eBook können Sie lesen. Sie benötigen dafür einen PDF-Viewer - z.B. die kostenlose Adobe Digital Editions-App.
Zusätzliches Feature: Online Lesen
Dieses eBook können Sie zusätzlich zum Download auch online im Webbrowser lesen.
Buying eBooks from abroad
For tax law reasons we can sell eBooks just within Germany and Switzerland. Regrettably we cannot fulfill eBook-orders from other countries.
aus dem Bereich