Lecessi | Functional Interfaces in Java | E-Book | www.sack.de
E-Book

E-Book, Englisch, 415 Seiten

Lecessi Functional Interfaces in Java

Fundamentals and Examples
1. ed
ISBN: 978-1-4842-4278-0
Verlag: Apress
Format: PDF
Kopierschutz: 1 - PDF Watermark

Fundamentals and Examples

E-Book, Englisch, 415 Seiten

ISBN: 978-1-4842-4278-0
Verlag: Apress
Format: PDF
Kopierschutz: 1 - PDF Watermark



Reduce development time by organizing your programs as chains of functional interfaces and see that the advantages of using functional interfaces include the flexibility and power of inlined functional chains and reuse of functional methods utilized throughout the Java API. You'll see how complex logical expressions can be reduced to chains of predicates and how chains of comparators can be used to sort data by several criteria in order. Other examples include streams that utilize functional interfaces to filter, sort, transform, and perform calculations on data; CompletableFutures that use functional interfaces to create cascading and parallel execution threads; and JavaFX programs that use functional interfaces to monitor the data backed by their graphical components.
Each chapter contains a complete programming project: the Discount Dave project shows you how to qualify car customers by organizing questions as a list of predicates; the Real Estate Broker project shows you how to use chains of comparators to filter and sort homes according to customer priorities; the Dave's Part Inventory project shows you how to query and write reports from an inventory database using stream operations; and the Sentence Builder project shows you how to correct a sentence by implementing each grammar rule as a separate link in a future chain.
Functional Interfaces in Java will help you quickly develop powerful and reliable programs that utilize functional interfaces to implement logic and calculations.

What You Will LearnUse the functional interfaces in the java.util.function package to perform conditional logic, transform and generate data, and perform calculations
Filter and sort data by several criteria  using comparators 
Process collections and filter, sort, transform, and reduce stream elements with functional interfaces 
Write cascading and parallel execution threads

Who This Book Is For
Computer science student or a professional Java programmer. This work is a rigorous discussion of the application of functional interfaces, so prerequisites for this text include basic Java programming and object-oriented Java programming.


Ralph Lecessi, PhD, is a software engineer with over thirty years professional programming experience in the aerospace, telecommunications, and payment industries at companies including Lockheed Martin, Alcatel-Lucent, AT&T, and Northrop Grumman.  He is also an adjunct professor of computer science and Java programming.

Lecessi Functional Interfaces in Java jetzt bestellen!

Autoren/Hrsg.


Weitere Infos & Material


1;Table of Contents;4
2;About the Author;13
3;About the Technical Reviewer;14
4;Foreword;15
5;Chapter 1: Functional Interfaces;16
5.1;Section 1.1: Interfaces in Java;16
5.2;Section 1.2: Enhancements to Interfaces in Java 8 and Java 9;17
5.3;Section 1.3: Functional Interfaces Defined;20
5.4;Section 1.4: Implementing Functional Interfaces with Pre-Java 8 Constructs;21
5.5;Section 1.5: Providing Default Methods in  Functional Interfaces;23
5.6;Section 1.6: Providing Static Methods in Functional Interfaces;26
5.7;Section 1.7: Generic Functional Interfaces;28
5.7.1;Section 1.7.1: Generic Functional Interfaces with Type Restrictions;29
5.8;Section 1.8: Specializing a Generic Functional Interface;32
5.9;PROJECT 1: Playful Pets;35
5.9.1;Problem Statement;35
5.9.2;Solution;35
5.10;Short Problems;40
5.11;Long Problems;41
6;Chapter 2: Lambda Expressions;43
6.1;Section 2.1: Lambda Expressions Defined;43
6.2;Section 2.2: Using Lambda Expressions to  Represent Functional Interfaces;43
6.3;Section 2.3: The Scope of a Lambda Expression;45
6.4;Section 2.4: Lambda Argument List Variations;46
6.5;Section 2.5: Lambda Bodies in Block Form;48
6.6;Section 2.6: Limitations of Lambda Expressions;51
6.7;PROJECT 2: Compute Square;54
6.7.1;Problem Statement;54
6.7.2;Solution;54
6.8;Short Problems;57
6.9;Long Problems;57
7;Chapter 3: Predicates;58
7.1;Section 3.1: The java.util.function Package;58
7.2;Section 3.2: The Predicate Interface;58
7.3;Section 3.3: Passing a Predicate to a Method;60
7.4;Section 3.4: Chains of Functional Interfaces;63
7.5;Section 3.5: Predicate Chaining Creates Complex Logical Expressions;63
7.5.1;Section 3.5.1: Chains Involving the OR Operation;63
7.5.2;Section 3.5.2: Chains Involving the AND Operation;65
7.5.3;Section 3.5.3: Chains Involving the ! Operation;66
7.5.4;Section 3.5.4: Using Predicate.isEqual;67
7.5.5;Section 3.5.5: Using Predicate.not [JAVA 11];68
7.6;Section 3.6: Overriding Predicate Default Methods;69
7.7;Section 3.7: Specializations of Predicates;70
7.8;Section 3.8: Binary Predicates;72
7.9;PROJECT 3: Discount Dave;72
7.9.1;Problem Statement;72
7.9.2;Solution;73
7.10;Short Problems;80
7.11;Long Problems;80
8;Chapter 4: Functions;82
8.1;Section 4.1: The Function Interface;82
8.2;Section 4.2: Passing a Generic Function to a Method;83
8.2.1;Section 4.2.1: Passing a Function with Restricted or Known Type Parameters;84
8.3;Section 4.3: Function Chaining;86
8.3.1;Section 4.3.1: Chains Involving the andThen Method;86
8.3.2;Section 4.3.2: Chains Involving the compose Method;86
8.4;Section 4.4: The Function.identity Method;87
8.5;Section 4.5: Specializations of Functions Which Convert from Primitive Types;88
8.6;Section 4.6: Specializations of Functions Which Convert to Primitive Types;89
8.7;Section 4.7: Non-generic Specializations of Functions;90
8.8;Section 4.8: Binary Functions;90
8.9;Section 4.9: Creating Chains Using BiFunctions;91
8.10;Section 4.10: Specializations of BiFunctions Which Convert to Primitive Types;92
8.11;PROJECT 4: Sales Promotions;93
8.11.1;Problem Statement;93
8.11.2;Solution;93
8.12;Short Problems;105
8.13;Long Problems;106
9;Chapter 5: Operators;107
9.1;Section 5.1: The UnaryOperator Interface;107
9.2;Section 5.2: Specializations of UnaryOperator;108
9.2.1;Section 5.2.1: Chains Involving UnaryOperator Specializations;109
9.3;Section 5.3: The BinaryOperator Interface;110
9.4;Section 5.4: Non-generic Specializations of  BinaryOperator;111
9.5;PROJECT 5: Calculator;112
9.5.1;Problem Statement;112
9.5.2;Solution;112
9.6;Short Problems;118
9.7;Long Problems;119
10;Chapter 6: Consumers;120
10.1;Section 6.1: The Consumer Interface;120
10.2;Section 6.2: Using Chains of Consumers to Compute Equations;121
10.3;Section 6.3: Using Consumers with println as the Terminal Operation;123
10.4;Section 6.4: Non-generic Specializations of Consumers;123
10.5;Section 6.5: The BiConsumer Interface;125
10.6;Section 6.6: Specializations of BiConsumer;126
10.7;PROJECT 6: Bank Transactions;127
10.7.1;Problem Statement;127
10.7.2;Solution;128
10.8;Short Problems;139
10.9;Long Problems;140
11;Chapter 7: Suppliers;141
11.1;Section 7.1: The Supplier Interface;141
11.2;Section 7.2: Wrapping User Prompts in a Supplier;143
11.3;Section 7.3: Non-generic Specializations of Suppliers;145
11.4;PROJECT 7: Ticketing System;146
11.4.1;Problem Statement;146
11.4.2;Solution;147
11.5;Short Problems;158
11.6;Long Problems;159
12;Chapter 8: Use in Traversing Objects;161
12.1;Section 8.1: Traversing Objects Using Iterators;161
12.2;Section 8.2: Traversing Java Arrays of Primitive Types;162
12.2.1;Section 8.2.1: Using Specializations of PrimitiveIterator;166
12.3;Section 8.3: Traversing Objects Using Spliterators;170
12.4;Section 8.4: Traversing Iterable Objects;174
12.5;Section 8.5: Traversing Iterable Objects That Contain Java Arrays of Primitives;175
12.5.1;Section 8.5.1: Using Specializations of PrimitiveIterator;179
12.6;Section 8.6: Traversing Maps;181
12.7;Section 8.7: Traversing Sets;182
12.8;PROJECT 8: Payroll;182
12.8.1;Problem Statement;182
12.8.2;Solution;183
12.9;Short Problems;189
12.10;Long Problems;190
13;Chapter 9: Use in Collections;191
13.1;Section 9.1: Removing Elements from a Collection;191
13.2;Section 9.2: Populating an Array;192
13.3;Section 9.3: Replacing the Elements of a List or a Map;194
13.4;Section 9.4: Parallel Computations on Arrays;195
13.5;Section 9.5: Map Computations;196
13.6;Section 9.6: Map Merging;199
13.7;Section 9.7: Functional Interfaces and Sets;201
13.8;PROJECT 9: Department of Motor Vehicles;201
13.8.1;Problem Statement;201
13.8.2;Solution;202
13.9;Short Problems;214
13.10;Long Problems;216
14;Chapter 10: Use in Comparing Objects;218
14.1;Section 10.1: The Comparator Interface;218
14.2;Section 10.2: Some Useful Comparator Methods;220
14.3;Section 10.3: The Comparator comparing Methods;221
14.4;Section 10.4: Specializations of the Comparator comparing Method;226
14.5;Section 10.5: Building Chains of Comparators;227
14.6;Section 10.6: Specializing Comparator Chain Components;230
14.7;Section 10.7: Using Comparators to Sort Lists;231
14.8;Section 10.8: Using Comparators to Sort Java Arrays;233
14.9;Section 10.9: Using Comparators to Organize Maps;236
14.10;Section 10.10: Using Comparators in BinaryOperator Methods;237
14.11;PROJECT 10: Real Estate Broker;238
14.11.1;Problem Statement;238
14.11.2;Solution;239
14.12;Short Problems;248
14.13;Long Problems;249
15;Chapter 11: Use in Optionals;252
15.1;Section 11.1: Creating an Optional;252
15.2;Section 11.2: Determining If an Optional Is Present;253
15.3;Section 11.3: Retrieving the Contents of an Optional;254
15.4;Section 11.4: Creating Chains of Optionals;255
15.5;Section 11.5: Printing the Contents of an Optional;257
15.6;Section 11.6: Filtering Optionals;258
15.7;Section 11.7: Optional Chains Involving map and flatmap;259
15.8;PROJECT 11: Guess a Number;262
15.8.1;Problem Statement;262
15.8.2;Solution;262
15.9;Short Problems;265
15.10;Long Problems;266
16;Chapter 12: Use in Streams;267
16.1;Section 12.1: Generating Stream Elements;267
16.2;Section 12.2: Traversing Streams;268
16.3;Section 12.3: Filtering Stream Elements;269
16.4;Section 12.4: Converting an Object to a Stream;270
16.5;Section 12.5: Sorting Stream Elements;270
16.6;Section 12.6: Selecting the Smallest or Largest Element in a Stream;271
16.7;Section 12.7: flatMap vs. map;272
16.8;Section 12.8: Reducing Stream Elements;274
16.9;Section 12.9: Collecting Stream Elements into a Mutable Reduction;275
16.9.1;Section 12.9.1: Using Prewritten Collectors;279
16.10;Section 12.10: Building Streams Interactively;284
16.11;Section 12.11: Displaying Intermediate Results;285
16.12;Section 12.12: Stream Specializations;286
16.13;PROJECT 12: Dave’s Part Inventory;287
16.13.1;Problem Statement;287
16.13.2;Solution;287
16.14;Short Problems;298
16.15;Long Problems;298
17;Chapter 13: Use in Multithreaded Programs;300
17.1;Section 13.1: Performing Computations Using Runnable and Callable;300
17.1.1;Section 13.1.1: Using Runnable in Optionals;304
17.2;Section 13.2: Futures and FutureTasks;304
17.3;Section 13.3: CompletionStages and  CompletableFutures;305
17.4;Section 13.4: Creating CompletableFutures and Retrieving Their Results;306
17.5;Section 13.5: Using the thenApply and thenAccept Methods;308
17.6;Section 13.6: Processing the First Asynchronous Future to Complete;309
17.7;Section 13.7: Making a Future Dependent on Another Future;310
17.8;Section 13.8: Cancelling a Future;311
17.9;Section 13.9: When Futures Throw Unchecked Exceptions;313
17.10;Section 13.10: Running Futures in Parallel;314
17.11;PROJECT 13: Sentence Builder;320
17.11.1;Problem Statement;320
17.11.2;Solution;320
17.12;Short Problems;333
17.13;Long Problems;334
18;Chapter 14: Use in Atomic Calculations;335
18.1;Section 14.1: Atomic Integers;336
18.1.1;Section 14.1.1: Accumulating an Atomic Value;338
18.1.2;Section 14.1.2: Updating an Atomic Value;339
18.1.3;Section 14.1.3: Comparing an Atomic Value;340
18.2;Section 14.2: Atomic Longs;343
18.3;Section 14.3: Atomic Booleans;344
18.4;Section 14.4: Atomic Arrays;344
18.5;Section 14.5: Atomic References;345
18.6;PROJECT 14: Bank Account;347
18.6.1;Problem Statement;347
18.6.2;Solution;347
18.7;Short Problems;351
18.8;Long Problems;352
19;Chapter 15: Use in JavaFX Applications;353
19.1;Section 15.1: Handling JavaFX Events;353
19.2;Section 15.2: Building JavaFX UI Components;355
19.3;Section 15.3: JavaFX Builder Factories;358
19.4;Section 15.4: Monitoring Changes in Collections;362
19.4.1;Section 15.4.1: Monitoring List Changes;362
19.4.2;Section 15.4.2: Monitoring Set Changes;368
19.4.3;Section 15.4.3: Monitoring Map Changes;372
19.5;Section 15.5: Invalidating an Observable Object;376
19.6;PROJECT 15: DMV GUI;380
19.6.1;Problem Statement;380
19.6.2;Solution;380
19.7;Short Problems;394
19.8;Long Problems;395
20;Appendix: Method References;397
20.1;Section A.1: Using References to Static Methods to Represent Functional Interfaces;397
20.2;Section A.2: References to Instance Methods;399
20.3;Section A.3: References to Constructors;400
20.4;Section A.4: Passing Method References as Arguments;401
20.5;Section A.5: Representing Functions with Method References;403
20.6;Section A.6: Using Method References with Comparators;405
20.7;Section A.7: Using Method References with Streams;406
21;Index;410



Ihre Fragen, Wünsche oder Anmerkungen
Vorname*
Nachname*
Ihre E-Mail-Adresse*
Kundennr.
Ihre Nachricht*
Lediglich mit * gekennzeichnete Felder sind Pflichtfelder.
Wenn Sie die im Kontaktformular eingegebenen Daten durch Klick auf den nachfolgenden Button übersenden, erklären Sie sich damit einverstanden, dass wir Ihr Angaben für die Beantwortung Ihrer Anfrage verwenden. Selbstverständlich werden Ihre Daten vertraulich behandelt und nicht an Dritte weitergegeben. Sie können der Verwendung Ihrer Daten jederzeit widersprechen. Das Datenhandling bei Sack Fachmedien erklären wir Ihnen in unserer Datenschutzerklärung.