Search icon
Arrow left icon
All Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Newsletters
Free Learning
Arrow right icon
Learning Java Lambdas
Learning Java Lambdas

Learning Java Lambdas: An in-depth look at one of the most important features of modern Java

By Toby Weston
$23.99 $15.99
Book Mar 2017 114 pages 1st Edition
eBook
$23.99 $15.99
Print
$143.99
Subscription
$15.99 Monthly
eBook
$23.99 $15.99
Print
$143.99
Subscription
$15.99 Monthly

What do you get with eBook?

Product feature icon Instant access to your Digital eBook purchase
Product feature icon Download this book in EPUB and PDF formats
Product feature icon Access this title in our online reader with advanced features
Product feature icon DRM FREE - Read whenever, wherever and however you want
Buy Now

Product Details


Publication date : Mar 31, 2017
Length 114 pages
Edition : 1st Edition
Language : English
ISBN-13 : 9781787282087
Vendor :
Oracle
Category :
Table of content icon View table of contents Preview book icon Preview Book

Learning Java Lambdas

Chapter 1. Introduction

Welcome to Learning Java Lambdas.

Java underwent huge changes in it's version 8 release. A lot was driven by the perception that Java was becoming long in the tooth. To compete with modern, functional programming languages, Java 8 introduced functional programming constructs like lambdas to better support a more functional style.

This book offers a concise explanation of lambdas and various other features required to make them work in Java. As well as offering background, syntax and usage examples of lambdas, the book describes other related features, such as functional interfaces and type inference.

The road to modern Java


Java 8 was released on March 18, 2014, two years seven months after the previous release. It was plagued with delays and technical problems but when it finally came, it represented one of the biggest shifts in Java since Java 5.

The headliners were of course lambdas and a retrofit to support functional programming ideas. With languages such as Scala taking center stage and the modern trend towards functional programming, Java had to do something to keep up.

Although Java is not and never will be a pure functional programming language, the changes in Java 8 enabled developers to use functional idioms more easily than in previous versions. With discipline and experience, you can now get a lot of the benefits of functional programming without resorting to third-party libraries.

Modern Java features

To give you an idea of just how big a change Java 8 was, and why it ushered in a new, modern Java, here's a mostly complete list of the new features it introduced:

  • Lambda support.

  • The core APIs were updated to take advantage of lambdas, including the collection APIs and a new functional package to help build functional constructs.

  • Entirely new APIs were developed that use lambdas, things like the stream API which brought functional style processing of data. For example, functions like map and flatMap from the stream API enable a declarative way to process lists and move away from external iteration to internal iteration. This in turn allows the library vendors to worry about the details and optimize processing however they like. For example, Java now comes with a parallel way to process streams without bothering the developer with the details.

  • Minor changes to the core APIs; new helper methods were introduced for strings, collections, comparators, numbers and maths.

  • Some of the additions are changing the way that people code. For example, the Optional class will be familiar to some, and it enables a better way to deal with nulls.

  • There were various concurrency library improvements. Things like an improved concurrent hash map, completable futures, thread safe accumulators, an improved read write lock (called a StampedLock), an implementation of a work stealing thread pool and much more besides.

  • Support for adding static methods to interfaces.

  • Default methods (otherwise known as virtual extension or defender methods).

  • Type inference was improved and new constructs like functional interfaces and method references were introduced to better support lambdas.

  • An improved date and time API was introduced (similar to the popular Joda-time library).

  • The IO and NIO packages received welcome additions to enable working with IO streams using the new streams API.

  • Reflection and annotations were improved.

  • An entirely new JavaScript engine shipped with Java 8. Nashorn replaced Rhino, and was faster and had better support for ECMA-Script.

  • JVM improvements; the integration with JRocket was completed, creating a faster JVM.

  • The JVM dropped the idea of perm gen, instead using native OS memory for class metadata. This is a huge deal and provides better memory utilization.

  • The JRocket integration also brought Mission control (jmc) to the JDK as standard. It compliments JConsole and VisualVM with similar functionality but adds very inexpensive profiling.

  • Other miscellaneous improvements, like improvements to JavaFX, base64 encoding support and more.

Left arrow icon Right arrow icon

Key benefits

  • Take a deep dive into one of the single most important additions to modern Java
  • Master Java lambdas, and fully understand functions, classes, and scope.
  • Improve your programming skills, which will enable you to write cleaner and more dynamic code

Description

In this short book, we take an in-depth look at lambdas in Java, and their supporting features. The book covers essential topics, such as functional interfaces and type inference, and the key differences between lambdas and closures. You will learn about the background to functional programming and lambdas, before moving on to understanding the basic syntax of lambdas and what differentiates these anonymous functions from standard anonymous classes. Lastly, you'll learn how to invoke lambdas and look at the bytecode generated. After reading this book, you'll understand lambdas in depth, their background, syntax, implementation details, and how and when to use them. You'll also have a clear knowledge of the difference between functions and classes, and why that's relevant to lambdas. This knowledge will enable you to appreciate the improvements to type inference that drive a lot of the new features in modern Java, and will increase your understanding of method references and scoping.

What you will learn

• What a lambda is and how it differs from other Java features • How to use lambdas effectively in your own projects • The use of method references and advanced scoping • The difference between lambdas and closures • The differences in bytecode produced when using lambdas

What do you get with eBook?

Product feature icon Instant access to your Digital eBook purchase
Product feature icon Download this book in EPUB and PDF formats
Product feature icon Access this title in our online reader with advanced features
Product feature icon DRM FREE - Read whenever, wherever and however you want
Buy Now

Product Details


Publication date : Mar 31, 2017
Length 114 pages
Edition : 1st Edition
Language : English
ISBN-13 : 9781787282087
Vendor :
Oracle
Category :

Table of Contents

10 Chapters
Learning Java Lambdas Chevron down icon Chevron up icon
Credits Chevron down icon Chevron up icon
About the Author Chevron down icon Chevron up icon
www.PacktPub.com Chevron down icon Chevron up icon
Customer Feedback Chevron down icon Chevron up icon
Preface Chevron down icon Chevron up icon
Introduction Chevron down icon Chevron up icon
Lambdas Introduction Chevron down icon Chevron up icon
Lambdas in Depth Chevron down icon Chevron up icon
Bytecode Chevron down icon Chevron up icon

Customer reviews

Filter icon Filter
Top Reviews
Rating distribution
Empty star icon Empty star icon Empty star icon Empty star icon Empty star icon 0
(0 Ratings)
5 star 0%
4 star 0%
3 star 0%
2 star 0%
1 star 0%

Filter reviews by


No reviews found
Get free access to Packt library with over 7500+ books and video courses for 7 days!
Start Free Trial

FAQs

How do I buy and download an eBook? Chevron down icon Chevron up icon

Where there is an eBook version of a title available, you can buy it from the book details for that title. Add either the standalone eBook or the eBook and print book bundle to your shopping cart. Your eBook will show in your cart as a product on its own. After completing checkout and payment in the normal way, you will receive your receipt on the screen containing a link to a personalised PDF download file. This link will remain active for 30 days. You can download backup copies of the file by logging in to your account at any time.

If you already have Adobe reader installed, then clicking on the link will download and open the PDF file directly. If you don't, then save the PDF file on your machine and download the Reader to view it.

Please Note: Packt eBooks are non-returnable and non-refundable.

Packt eBook and Licensing When you buy an eBook from Packt Publishing, completing your purchase means you accept the terms of our licence agreement. Please read the full text of the agreement. In it we have tried to balance the need for the ebook to be usable for you the reader with our needs to protect the rights of us as Publishers and of our authors. In summary, the agreement says:

  • You may make copies of your eBook for your own use onto any machine
  • You may not pass copies of the eBook on to anyone else
How can I make a purchase on your website? Chevron down icon Chevron up icon

If you want to purchase a video course, eBook or Bundle (Print+eBook) please follow below steps:

  1. Register on our website using your email address and the password.
  2. Search for the title by name or ISBN using the search option.
  3. Select the title you want to purchase.
  4. Choose the format you wish to purchase the title in; if you order the Print Book, you get a free eBook copy of the same title. 
  5. Proceed with the checkout process (payment to be made using Credit Card, Debit Cart, or PayPal)
Where can I access support around an eBook? Chevron down icon Chevron up icon
  • If you experience a problem with using or installing Adobe Reader, the contact Adobe directly.
  • To view the errata for the book, see www.packtpub.com/support and view the pages for the title you have.
  • To view your account details or to download a new copy of the book go to www.packtpub.com/account
  • To contact us directly if a problem is not resolved, use www.packtpub.com/contact-us
What eBook formats do Packt support? Chevron down icon Chevron up icon

Our eBooks are currently available in a variety of formats such as PDF and ePubs. In the future, this may well change with trends and development in technology, but please note that our PDFs are not Adobe eBook Reader format, which has greater restrictions on security.

You will need to use Adobe Reader v9 or later in order to read Packt's PDF eBooks.

What are the benefits of eBooks? Chevron down icon Chevron up icon
  • You can get the information you need immediately
  • You can easily take them with you on a laptop
  • You can download them an unlimited number of times
  • You can print them out
  • They are copy-paste enabled
  • They are searchable
  • There is no password protection
  • They are lower price than print
  • They save resources and space
What is an eBook? Chevron down icon Chevron up icon

Packt eBooks are a complete electronic version of the print edition, available in PDF and ePub formats. Every piece of content down to the page numbering is the same. Because we save the costs of printing and shipping the book to you, we are able to offer eBooks at a lower cost than print editions.

When you have purchased an eBook, simply login to your account and click on the link in Your Download Area. We recommend you saving the file to your hard drive before opening it.

For optimal viewing of our eBooks, we recommend you download and install the free Adobe Reader version 9.