P8tech logo      

P8tech home | Authors | Select eBooks and eLearning | Contact P8techch

 


Java 8 New Features Book and eBook

Colour Book and eBook
198 pages
$19.99 / £12.99

Amazon review

ISBN: 978-0992910570

Published: May 15, 2014


 



Errata
Code

Java 8 New Features: A Practical Heads-Up Guide [Book and eBook]

by Richard Reese

Are you are worried you are missing out on the latest version of Java? When you hear a term such as lambda expressions - do you wonder what you are neglecting? If so, Java 8 New Features will squash your concerns and deliver a quick and easy-to-understand guide to what’s new in Java 8.

The latest version of Java offers numerous improvements and new features to better utilize Java. Streams, for example, supports a fluent approach to problem solving and lets the developer take advantage of concurrency with minimal effort, whilst Lambda Expressions offer new ways of expressing a solution that brings efficiency and succinct programming.

Get up-to-speed here!

Java 8 New Features is a concise new book filled with code examples and best practice.

In this book, you will:

  • Learn how interface enhancements - such as default methods - affect new additions to Java 8 and their impact on multiple inheritance between interfaces
  • Use lambda expressions to simplify solutions to development problems
  • Discover how the new Stream interface supports query type problems
  • Explore the new support for concurrent processing including that supported by Streams
  • Find out why the new date and time enhancements make working with time so much easier than it used to be
  • Includes information on the Nashorn JavaScript Engine, File IO Enhancements, and Project Jigsaw

 Buy Now (UK) >>

Buy Now (USA) >>

 

Who is this Book for?
This book is intended for Java developers who are familiar with Java 7 (and earlier) and who want to get up-to-speed, quickly, on the new features found in Java 8.

Who is the Author?
Richard Reese is an acclaimed author who has written several Java and C books, bringing a focused and easy-to-follow approach to learning. He currently teaches at Tarleton State University.

Table of Contents

Chapter 1 - Java 8 and Interface Enhancements

1

 Introduction to Java 8

1

 Default Methods and Functional Interfaces

2

 Creating Default Methods

2

 Understanding the Importance of Default Methods

4

 Defining a Default Method

4

  Overriding Default Methods

5

 Using Inheritance with Default Methods

7

  Working with Single Inheritance

7

  Working with Multiple Inheritance

9

  Understanding how Diamond Inheritance Works

11

 Resolving Overridden Default Methods

14

 Using Default Methods

16

  Extending Existing Interfaces

16

  Using Default Methods to Supplement Adapter Classes

17

  Using Default Methods in Core Java Classes

18

  Using a Class to Support Default Methods

20

 Understanding the Difference between an Abstract Class and Interfaces

21

 Using Static Interface Methods

21

 Functional Interfaces

23

  Creating a Functional Interface

23

  Using  the @FunctionalInterface Annotation

24

  Overriding Object Class Methods in a Functional Interface

25

  Using Functional Interfaces in the Core Libraries

25

 Conclusion

26

Chapter 2 - Lambda Expressions

27

 Understanding Lambda Expressions

28

  Inferring the Type of the Target

30

 Creating Lambda Expressions

33

  Lambda Expression Syntax Rules

34

   Declaring Parameter Types

34

   Mixing Parameter Declarations

34

   Omitting Parentheses

35

   Eliminating the Block Statement

36

   Using Multiple Statements in a Lambda Expression Body

36

   Using a Return Value

36

  Writing Succinct Lambda Expressions

37

  Capturing Variables in a Lambda Expression

38

  Differentiating between a Lambda Expression and a Closure

40

  Method and Constructor References

41

   Using Static Method References

42

   Using Instance Method References

43

   Using Constructor References

44

 Working with Lambda Expressions

47

  Using Lambda Expressions with Variable Declarations

48

  Using Lambda Expressions as a Return Value

48

  Using Exceptions with a Lambda Expression

49

  Using Lambda Expressions with the Tertiary Operator

50

  Casting Lambda Expressions

50

  Using Lambda Expressions to Initialize an Array

51

  Writing Recursive Lambda Expressions

51

 Using the java.util.function Functional Interfaces

52

  Using the Predicate Interface

53

  Using the Function Interface

57

  Using the BiFunction Interface

59

  Using the Consumer Interface

60

  Using the Supplier Interface

62

  Using Operator Type Interfaces

64

  Using the UnaryOperator Interface

65

  Using the BinaryOperator Interface

66

 Conclusion

67

Chapter 3 - Streams

69

 Streams

69

  Stream Characteristics

70

   Streams Do Not Store Elements

71

   Streams Can Be Unbounded

71

   Streams Do Not Modify the Original Source

71

   A Stream May Be Ordered

72

   Automatic Parallelization

72

  An Overview of Stream Methods

72

 Creating a Stream

73

  Using the Stream Interface’s of Method

74

  Using the Collection Class’ stream Method

75

  Using a Stream.Builder Interface

76

   Using the builder method

77

  Generating Infinite Streams

77

   Using the iterate Method

78

  Concatenating Streams

78

  Generating an Empty Stream

78

 Using Stream Methods

79

  The Part Example Class

79

  Using the forEach Method

81

   Using the forEachOrdered Method

82

  Using the map Method

82

   Using Other Map Methods

83

  Using the flatmap Method

84

  Using the filter Method

86

  Using the Match Type Methods

87

  Using the findFirst Method

88

   Using the findAny Method

88

   Using the Optional Class

88

  Using the reduce Method

90

  Using the Collector Interface and the collect Method

91

   Using the Collects Class

93

  Using the iterator Method

93

  Using the sorted Method

94

  Using the distinct Method

95

  Using the limit Method

95

  Using the skip Method

96

  Using the max, min, and count Methods

96

 Streams for Primitive Types

97

  Using the IntStream Interface

98

 Understanding Lazy and Eager Evaluation

98

  Using Short-Circuit Methods

99

 Using Parallel Stream Operations

99

 Conclusion

102

Chapter 4 - Date and Time

103

 Introduction

103

  Why a New API?

104

  A Simple Example

104

  The ISO-8601 String Format

106

  Design Considerations

107

  Understanding the Standard Method Names

107

   Understanding the of Type Methods

108

   Understanding the from Method

108

   Understanding the parse Method

109

   Understanding the format Method

109

   Understanding the get Type Method

109

   Understanding the is Type Methods

110

   Understanding the with Type Methods

110

   Understanding the plus Type Methods

110

   Understanding minus Type Methods

111

   Understanding the to Type Methods

111

   Understanding the at Type Methods

111

  Overview of the Date and Time Packages

112

 Getting the Current Time

113

  Working with the Instant Class

115

   Creating an Instant

115

   Creating an Instant Based on the Epoch

116

   Creating an Instant Based on Parsing a UTC String

116

   Creating an Instant by Adding or Subtracting a Time from an Instant

117

   Using the Instant Class’ get Type Methods

117

  Working with Time Intervals

118

   Creating Offsets Using the of Type Methods

118

   Creating Offsets Using the with Type Methods

119

   Creating a Duration Using the parse Method

119

   Creating a Duration by Adding or Subtracting a Unit

120

   Using the Duration Class

121

  Using the Period Class

122

 Using Date and Time Classes

123

  Creating Date and Time Classes

124

   Date and Time get Type Methods

125

   Adjusting a Date or Time

126

  Using the YearMonth, MonthDay, and Year Classes

126

   Comparing MonthDay Instances

128

  Using the Enumerations DayOfWeek and Month

128

   Using the DayOfWeek Enumeration

128

   Using the Month Enumeration

129

 Working with the Time Zone and Offset Classes

130

  Obtaining Available Zone Ids

131

  Working with ZoneOffsets

132

  Working with Zone Rules

134

 Formatting, Queries, and Value-Based Classes

135

  Formatting Dates and Times

135

  Using Temporal Queries

137

  Understanding Value-Based Classes

139

 Conclusion

140

Chapter 5 - Odds and Ends

141

 Introduction

141

 Using the Nashorn JavaScript Engine

141

  Accessing the Nashorn Engine

141

  Executing JavaScript Code

142

  Executing Java Code from JavaScript

143

  Implementing a Java Interface

144

 File IO Enhancements

145

  Using the FileFilter Interface

146

  Using the PathMatcher Interface

147

  Using the Files Class’ list Method

147

  Using the Files Class’ walk Method

148

  Using the Path Class’ lines Method

148

 Concurrency Enhancements

149

  Using the Arrays Class’ parallelSort Method

149

  Using the Arrays Class’ parallelSetAll Method

150

  Using the Arrays Class’ parallelPrefix Method

151

 Collections Enhancements

152

  Using the forEachRemaining Method

153

  Using the replace Type Methods

153

  Using the compute Type Methods

155

 Project Jigsaw and Compact Profiles

155

  The Compact Profiles

156

  Using Compact Profiles

158

 Other Enhancements

159

  Javadoc Enhancements

159

  Security Enhancements

160

  VM Related Enhancements

160

  Core Java Enhancements

161

 Conclusion

161

Appendix A - Date and Time Classes

163

 Of Type Methods

163

 The from Method

165

 The parse Method

166

 Get Type Methods

167

 Is Type Methods

170

 With Type Methods

172

 Plus Type Methods

175

 Minus Type Methods

177

 To Type Methods

180

 At Type Methods

181

Index

183