What's New in Java 8: Lambdas
- 1.5 hours on-demand video
- 3 downloadable resources
- Full lifetime access
- Access on mobile and TV
- Certificate of Completion
Get your team access to 4,000+ top Udemy courses anytime, anywhere.Try Udemy for Business
- A FREE companion eBook to support your study
- Get an overview of (almost) all of the new features in Java 8
- Gain in-depth understanding of the major new features in Java 8 that you can apply straight away
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
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
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.
- Previous experience with Java (pre Java-8)
- An IDE to practice and experiment with the examples
- Java Software Development Kit (SDK) available FREE from Oracle
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
- Have an overview of new features in Java 8
- Understand lambdas in-depth, their background, syntax, implementation details and how and when to use them
- Understand the difference between functions to classes and why that's relevant to lambdas
- Understand the difference between lambdas and closures
- Appreciate the improvements to type inference that drive a lot of the new features
- Be able to use method references and understand scoping and "effectively final"
- Understand the differences in bytecode produced when using lambdas
- Be able to reason about exceptions and exception handling best practice when using lambdasvariables
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.
- Anyone interested in learning about Java 8
- Prior knowledge and experience of pre Java-8 is advantagous