This is PART 1 of a two part course looking at the new features of Java 8.
In this part, we take an in-depth look at lambdas and their supporting features; things like functional interfaces and type inference. In the follow up course (PART 2), we look at the remaining features.
After watching this course, you'll
So whether you're migrating existing Java programs to Java 8 or building applications from scratch, this course will help you start to leverage the power of functional programming on the Java platform.
A whistle-stop tour of the new features.
00:42 Run down of the new features
The course comes with a free companion eBook.
Please register your course at http://bit.ly/whatsnewjava8 for updates to the book and to be notified of special offers on related courses.
00:00 Download your FREE companion eBook
00:15 Register for updates
This lecture talks about some background to functional programming and lambdas in general.
00:15 Alonzo Church and the lambda calculus
01:00 John McCarthy and LISP
01:30 Lambda calculus and LISP expressions side by side
01:55 What is a lambda?
Anonymous functions (aka lambdas) are not the same thing as anonymous classes in Java.
Although we might start to use them in a similar way, there are several technical differences. Find out about these before we look at Java 8's syntax.
00:00 Lambdas aren't the same as anonymous classes
01:15 Lambdas aren't just syntactic sugar
Discover the basic syntax of lambdas in Java. We look at variations on the new syntax and how to put together a lambda.
Get up and running quickly and see how to convert legacy code to using the new syntax.
00:00 Introduction and Comparator example
01:15 Converting anonymous classes to lambdas
02:40 Syntax summary
Test your knowledge on Lambdas.
In this lecture, we talk about functional interfaces.
Functional interfaces are just regular Java interfaces but with just one method. Because Java understands the options for using these are limited (they only have one method), it can do all kinds of neat things. The most significant of which is using lambdas in-lieu of anonymous implementations of the interface.
00:00 What is a functional interface? SAM?
00:50 Examples of using the functional interface annotation
Recap the basics of type inference and learn about Java 8's improvements. We cover "target" typing as well as looking at the Java Enhancement Proposal (JEP) 101 covering generalised target typing.
00:00 Introducing the changes due to type inference with Java 8
00:22 Recapping the basics of type inference
01:45 Type erasure
02:52 The three areas of improvement
03:10 Target typing for lambdas
04:45 Parameter type inference in method calls
06:00 Parameter type inference for chained methods
Find out how to pass around references to exsitings methods using method references.
We take a look at the variations on syntax and show how you might use each.
00:00 What is a method reference?
01:08 What can you do with them?
03:35 The four types of method reference
04:03 Constructor method references (includes constructor arguments)
09:25 Static method references
10:00 Instance method references (of a particular object)
10:50 Instance method references (of an arbitrary object)
11:47 Summary of syntax
Lambdas are lexically scoped in Java 8. In this lecture, find out more about scoping and the new effectively final concept.
00:00 Scoping introduction
00:34 Lexical scoping demo
02:34 Effectively final introduction
03:15 Effectively final demo
07:35 Warning! Be more functional. Use fold/reduce instead!
Let's take a look at the options with dealing with exception from lambdas. We'll look at it from the perspective of the developer writing lambdas and from the perspective of the library developer, calling lambdas passed in.
00:00 Introducing the issues
02:12 Exception handling from the author's perspective
08:09 Exception handling from the client's perspective
11:35 Side by side comparison
The term closures and lambdas are often used interchangeably but just as often incorrectly. There are key differences between the two and in this lecture we'll take a look at what they are.
00:00 Introduction and Java timeline
01:25 What's the difference?
05:09 Side by side comparison
Take a look at the differences in bytecode between anonymous classes and the new lambdas.
00:30 Recap on bytecode basics
01:55 Java as a stack based computation model
03:50 JVM "descriptors" ie, Ljava/lang/String;
05:57 Introducing the examples
06:20 Anonymous class
07:50 Anonymous class closing over variables (closure)
08:29 Lambda with no arguments
10:46 Lambda with arguments
12:20 Lambda closing over variables (closure)
The source and corresponding bytecode for the examples from the previous lecture.
Now really test your understanding of lambdas in Java.
I specialise in modern software development; functional and object-oriented programming, agile and lean best practice. I wrote the book Essential Acceptance Testing and have written for magazines as well as regularly blogging.
I've been part of the software industry for more than fifteen years and love what I do. I love talking and writing about it and sharing my experiences online with Udemy.