Java 8

Java 8, released on March 2014 introduces a number of new features to the Java programming language. Lambda expressions, a functor (function pointer) like feature was well expected and is finally here to make code more convenient and concise. Streams (not IO streams) are wrappers around existing data structures that provide a convenient API to iterate, filter, map/reduce and query a data structure and have nice properties that collections lack. JDK 8 also introduces a new enhanced well-defined and convenient API for dealing with date and time. This training program introduces these new features to Java programmers who are not yet familiar with the new JDK.

Module 1 – Overview: Pre-Lambda Java 

  • Installing Java 8
  • Installing an Eclipse IDE that supports Java 8
  • Review: Classic Pre-Lambda Java handlers and anonymous classes
  • Separate class
  • Main class that implements the interfaces
  • Named Inner classes
  • Anonymous inner classes
  • Review of making Generic classes and methods (since JDK 5)
  • Exercise:
  • Program a simple Swing  application using each of the traditional ways

Module 2 – Lambda Expressions 1: Basics

  • Motivation and the big idea
  • The new lambda options
  • Interpretation
  • The basic form
  • Type inferencing
  • Expression as lambda body
  • Omitting the parenthesis
  • Comparing lambda approaches to the alternatives
  • Using effectively final variables
  • The @FunctionalInterface Annotation
  • Method reference
  • The java.util.function package
  • Exercise
  • Sorting an array of Strings – by length, reverse length, first character, String with 'e'
  • Improve the sorting with lambdas
  • Using Predicates to sort the strings
  • Using Generics to sort an array of any element type

Module 3 –  Lambda Expressions 2: The building blocks

  • Lambda building blocks in java.util.function
  • XunaryOperation
  • XbinaryOperator
  • Xpredicate
  • XConsumer
  •  Generic Versions
  • Predicate
  • Function
  • BinaryOperator
  • Consumer
  • Supplier
  • variable scoping rules for lambda
  • Exercise
  • Create a static method that accepts a List of Strings and a Predicate and return a new List containing values that pass a lambda expression test
  • Generify the previous method so it takes a list of any element type
  • The same as with the Predicate, only this time the method is called transformedList and it takes a list of strings and a Function
  • Generify the transformedList method

Module 4 – Lambda Expressions 3: Wrap up

  • Variable Scoping
  •  local variables
  • instance variables
  • "this"
  • Method References – Details
  • Class::staticMethod
  • variable::instanceMethod
  • Class::instanceMethod
  • Class::new
  • New features in Java 8 Interfaces
  • Default methods
  • Static methods
  • Lambda returning methods
  • From Predicate: and, or, negate, isEqual
  • From Function: andThen, compose, identify
  • From Consumer: chain
  • custom methods

Module 5 – Streams in Java 8: Part 1 

  • Overview of Streams
  • Building Streams
  • Outputting streams into arrays or Lists
  • Core Stream Methods
  • Overview
  • forEach
  • map
  • filter
  • findList
  • Lazy evaluation and short-circuit operations
  • Exercise
  • Looping a List of String using forEach
  • Looping with forEach and System.out::println method references
  • Looping with map and collect
  • Looping with filter and collect
  • Looping with chained filters
  • Looping with lazy evaluation
  • Converting a list to an array using the String[]::new method reference

Module 6 – Streams in Java 8: Part 2 

  • Additional Stream methods
  • reduce, sum
  • limit, skip
  • sorted, min, max, distinct
  • noneMatch, allMatch, anyMatch, count
  •  Parallel Streams
  •  Infinite Streams
  • bounded streams with on-the-fly calculated values
  • Grouping Stream Elements
  • fancy uses of collect
  • Exercise
  • Using a single stream.reduce (no map) to uppercase and concatenate a list of strings
  • Using map and reduce to do the same 
  • Produce a CSV string using reduce and orElse
  • Creating a static method for producing a list of a given size of random numbers

using Stream.generate(Supplier<?>) and collect

  • Creating a static method that produces a list of numbers that go in order by a step size using Stream.iterate(Integer, UnaryOperator) and collect
  • Compute the sums of some ints – in serial using stream().reduce Vs. in parallel 
  • using stream().parallel().reduce (all-ways the same result)
  • Compute the product of some doubles in serial using stream().reduce(Double, BynariOperator<Double>) and in parallel using stream().parallel().reduce(Double, BynariOperator<Double>) (not always the same result)

Module 7 – The new Java 8 Date & Time Approach

  • Date-Time Overview
  • Why a new API?
  • Advantages of the new API
  • Design Principles
  • Concepts
  • New packages and commonly used classes
  • Method Naming Convensions
  • Formatting and Parsing
  • Temporal Adjusters and Temporal Queries
  • Legacy Date-Time Code Interoperability
  • Summary
  • Java programming language skills with JDK 5 and later 
  • Familiarity with Generics – Programmers must be able to define generic instance and static methods. 
  • Familiarity with the Java Collections Framework. Programmers must know how to work with lists, maps and sets 

3 Days (24 hours)

השתתפות ב80% מהקורס

לשיחה / תאום פגישה עם יועץ לימודים: