Free your Lambdas Java SE 8

Size: px
Start display at page:

Download "Free your Lambdas Java SE 8"

Transcription

1 Free your Lambdas Java SE 8

2 Agenda Tutorial session: we will start at the very beginning! and explore how to build functional interfaces to design new APIs This is about lambdas and functional interfaces So not much about Streams & Collectors

3

4 start

5

6 Questions?

7 A first example What is this code doing? Comparator<Person> cmp = new Comparator<Person>() { public int compare(person p1, Person p2) { return p1.getlastname().compareto(p2.getlastname()); }

8 A first example What is this code doing? Comparator<Person> cmp = new Comparator<Person>() { public int compare(person p1, Person p2) { int cmp = p1.getlastname().compareto(p2.getlastname()); if (cmp == 0) { return p1.getfirstname().compareto(p2.getfirstname()); } else { return cmp; } }

9 A first example What is this code doing? Comparator<Person> cmp = new Comparator<Person>() public int compare(person p1, Person p2) { int cmp = p1.getlastname().compareto(p2.getlastname()); if (cmp == 0) { cmp = p1.getlastname().compareto(p2.getfirstname()); if (cmp == 0) { return p1.getage() - p2.getage(); } else { return cmp; } } else { return cmp; } } };

10 A first example What is this code doing? Comparator<Person> cmp = new Comparator<Person>() public int compare(person p1, Person p2) { int cmp = p1.getlastname().compareto(p2.getlastname()); if (cmp == 0) { cmp = p1.getfirstname().compareto(p2.getfirstname()); if (cmp == 0) { return p1.getage() - p2.getage(); } else { return cmp; } } else { return cmp; } } };

11 A first example What is this code doing? Comparator<Person> cmp = Comparator.comparing(Person::getLastName).thenComparing(Person::getFirstName).thenComparing(Person::getAge);

12 A closer look at the Comparator Suppose we want to sort strings of characters 1) We create a comparator: Comparator<String> comparator = new Comparator<String>() { public int compare(string s1, String s2) { return Integer.compare(s1.length(), s2.length()); } };

13 A closer look at the Comparator Suppose we want to sort strings of characters 1) We create a comparator: Comparator<String> comparator = new Comparator<String>() { public int compare(string s1, String s2) { return Integer.compare(s1.length(), s2.length()); } }; 2) We pass it to the right method: Arrays.sort(strings, comparator); Collections.sort(list, comparator) ;

14 A closer look at the Comparator What did we do?

15 A closer look at the Comparator What did we do? We passed a piece of code as a parameter to a method And this method will use this code later

16 A closer look at the Comparator Why did we use an instance of an anoymous class?

17 A closer look at the Comparator Why did we use an instance of an anoymous class? Because there is no other way in Java 7!

18 Another way of writing it Our comparator: Comparator<String> comparator = new Comparator<String>() { } public int compareto(string s1, String s2) { return Integer.compare(s1.length(), s2.length()) ; }

19 Another way of writing it Our comparator: Comparator<String> comparator = new Comparator<String>() { } public int compareto(string s1, String s2) { return Integer.compare(s1.length(), s2.length()) ; } Becomes: Comparator<String> comparator = (String s1, String s2) -> Integer.compare(s1.length(), s2.length()) ;

20 Back to the Comparator interface The Comparator interface public interface Comparator<T> { } public int compare(t t1, T t2) ;

21 Back to the Comparator interface The Comparator interface becomes a functional interface in Java 8 public interface Comparator<T> { } public int compare(t t1, T t2) ;

22 Back to the Comparator interface The Comparator interface becomes a functional interface in Java 8 because it has a single abstract method public interface Comparator<T> { } public int compare(t t1, T t2) ;

23 Back to the Comparator interface A functional interface can be annotated But it is public interface Comparator<T> { } public int compare(t t1, T t2) ;

24

25 So Writing a lambda is a matter of finding what interface to implement The type of a lambda is always known at compile time The method to write a lambda is always the same: - copy / paste the block of parameters - little ASCII art arrow - implement the method

26 A weird thing We wrote this code: List<String> strings =...; strings.foreach( System.out::println // method reference (bound instance) ) ; The foreach() method is defined on the Iterable interface

27 A weird thing We wrote this code: List<String> strings =...; strings.foreach( System.out::println // method reference (bound instance) ) ; The foreach() method is defined on the Iterable interface Do we really want to refactor all the Collection API?

28 Default methods Breaking the backward compatibility is not possible in Java The way interfaces work has been modified: public interface Iterable<E> { // usual methods } default void foreach(consumer<? super T> action) { Objects.requireNonNull(action); for (T t : this) { action.accept(t); } }

29 Default methods We can now add methods in interfaces with their implementation Those are «normal» methods It is a new concept of interface, not a new concept of method

30 Default & static methods We can now add methods in interfaces with their implementation Those are «normal» methods It is a new concept of interface, not a new concept of method And static methods are allowed too!

31 Back to the functional interface A functional interface is an interface with only one abstract method So default & static methods do not count

32

33 So Interfaces in Java 8: - Functional interfaces to write lambda expressions - Default methods, can be used to compose them - Static methods, can be used as factory We have better readability, better robustness and better performances! (Youtube: Lambda a peek under the hood by B. Goetz)

34 Package java.util.function 4 categories of functional interfaces: Consumer Supplier Function Predicate

35 Package java.util.function 4 categories of functional interfaces: Consumer t -> {}; Supplier () -> t; Function t -> u; Predicate t -> true;

36 Package java.util.function 4 categories of functional interfaces: Consumer t -> {}; s -> System.out.println(s); Supplier () -> t; () -> new Balloon(); Function t -> u; person -> person.getage(); Predicate t -> true; age -> age > 20;

37 Package java.util.function 4 categories of functional interfaces: Runnable () -> {}; Consumer t -> {}; s -> System.out.println(s); Supplier () -> t; () -> new Balloon(); Function t -> u; person -> person.getage(); Predicate t -> true; age -> age > 20;

38 Package java.util.function 4 categories of functional interfaces: Runnable () -> {}; () -> logger.log(message); Consumer t -> {}; s -> System.out.println(s); Supplier () -> t; () -> new Ballon(); Function t -> u; person -> person.getage(); Predicate t -> true; age -> age > 20;

39 Back to the Comparator Let us write a comparator of people - Using an anonymous class - Then a lambda

40

41 Method reference There are 4 types of method references Nom Static Bound instance Unbound instance Constructor Syntaxe RefType::staticMethod expr::instmethod RefType::instMethod ClassName::new

42 Method reference There are 4 types of method references Lambda d -> Math.sin(d) Method Reference Math::sin s -> System.out.println(s) System.out::println (s, t) -> s.compareto(t) name -> new Person(name) String::compareTo Person::new

43 What about patterns? Let us talk about the GoF

44 What about patterns? Let us talk about the GoF The factory pattern

45

46 What about patterns? Let us talk about the GoF The factory pattern The registry & builder patterns

47

48 Conclusion Lambdas are not just a nice way of writing instances of anonymous classes Functional interfaces + default methods + factory methods provide new ways of implementing well-known patterns for our applications & APIs

49 Thank you!

50

New Features in Java 8

New Features in Java 8 New Features in Java 8 Lambda expressions Functional interfaces Streaming support for Collections Lambda expressions Are a block of java code with parameters Can be assigned to variables Can be executed

More information

Copyright 2014, Oracle and/or its affiliates. All rights reserved.

Copyright 2014, Oracle and/or its affiliates. All rights reserved. 1 Introduction to Lambda Stuart W. Marks Principal Member of Technical Staff Oracle JDK Core Libraries Team Twitter: @stuartmarks What is a Lambda? A lambda is a function. A function is a computation that

More information

Java Technologies. Lecture IV. Valdas Rapševičius

Java Technologies. Lecture IV. Valdas Rapševičius Preparation of the material was supported by the project Increasing Internationality in Study Programs of the Department of Computer Science II, project number VP1 2.2 ŠMM-07-K-02-070, funded by The European

More information

EECS2030 Week 7 worksheet Tue Feb 28, 2017

EECS2030 Week 7 worksheet Tue Feb 28, 2017 1. Interfaces The Comparator interface provides a way to control how a sort method (such as Collections.sort) sorts elements of a collection. For example, the following main method sorts a list of strings

More information

LAMBDA EXPRESSIONS AND STREAMS API

LAMBDA EXPRESSIONS AND STREAMS API Java 8 LAMBDA EXPRESSIONS AND STREAMS API An Introduction Methods As Data 2 @FunctionalInterface public interface Runnable { public abstract void run(); public interface ActionListener extends EventListener

More information

Copyright 2012, Oracle and/or its affiliates. All rights reserved.

Copyright 2012, Oracle and/or its affiliates. All rights reserved. 1 Jump-Starting Lambda Stuart Marks @stuartmarks Mike Duigou @mjduigou Oracle JDK Core Libraries Team 2 What is Lambda? Essentially an anonymous function allows one to treat code as data provides parameterization

More information

Quick start. Robert Bachmann & Dominik Dorn. JSUG Meeting #63

Quick start. Robert Bachmann & Dominik Dorn. JSUG Meeting #63 1.. Java 8 Quick start Robert Bachmann & Dominik Dorn JSUG Meeting #63 Outline: What s new in Java 8 2 Interface additions and lambda syntax (r) Library additions (r) Nashorn (d) Type annotations (d) VM

More information

Lambdas & Streams In JDK 8: Beyond The Basics

Lambdas & Streams In JDK 8: Beyond The Basics Lambdas & Streams In JDK 8: Beyond The Basics Simon Ritter Deputy CTO, Azul Systems @speakjava azul.com Copyright Azul Systems 2015 1 A clever man learns from his mistakes......a wise man learns from other

More information

Lambda Expressions and Java 8 Streams. Jan Trienes, adapted by Th. Dorssers, Pieter van den Hombergh. Contents of this talk.

Lambda Expressions and Java 8 Streams. Jan Trienes, adapted by Th. Dorssers, Pieter van den Hombergh. Contents of this talk. Java 8 s and Java 8 van den Hombergh Fontys Hogeschool voor Techniek en Logistiek February 23, 2017 and /FHTenL s and Java 8 February 23, 2017 1/28 talk Expression and Internal/External Iteration Java

More information

Notable Enhancements in Java 8. Functional Programming with Java. Lambda Expressions in Java. How to Define a Lambda Expression? Lambda expressions

Notable Enhancements in Java 8. Functional Programming with Java. Lambda Expressions in Java. How to Define a Lambda Expression? Lambda expressions Notable Enhancements in Java 8 Lambda expressions Allow you to do functional programming in Java Functional Programming with Java Static and default methods in interfaces 1 2 Lambda Expressions in Java

More information

Fontys Hogeschool voor Techniek en Logistiek. March 13, 2018

Fontys Hogeschool voor Techniek en Logistiek. March 13, 2018 Java 8 s and Java 8 Fontys Hogeschool voor Techniek en Logistiek March 13, 2018 and? /FHTenL s and Java 8 March 13, 2018 1/34 talk The other anonymous and? Java 8 and? /FHTenL s and Java 8 March 13, 2018

More information

Introduction to Object-Oriented Programming

Introduction to Object-Oriented Programming Introduction to Object-Oriented Programming Lambda Expressions Christopher Simpkins chris.simpkins@gatech.edu CS 1331 (Georgia Tech) Lambda Expressions 1 / 14 Inner Classes Recall from SortTroopers.java

More information

Java SE 8 Programming

Java SE 8 Programming Oracle University Contact Us: +52 1 55 8525 3225 Java SE 8 Programming Duration: 5 Days What you will learn This Java SE 8 Programming training covers the core language features and Application Programming

More information

LAMBDA EXPRESSIONS. Summer 2018

LAMBDA EXPRESSIONS. Summer 2018 LAMBDA EXPRESSIONS Summer 2018 LAMBDA EXPRESSIONS USES Introduced in Java SE 8, lambda expressions are a way to create single-method classes in your code in a much less cumbersome manner than anonymous

More information

Functional Constructs in Java 8: Lambdas and Streams

Functional Constructs in Java 8: Lambdas and Streams Functional Constructs in Java 8: Lambdas and Streams Josh Bloch Charlie Garrod School of Computer Science 1 Administrivia Homework 6 due Thursday 11:59 pm Final exam Tuesday, May 3, 5:30-8:30 pm, PH 100

More information

Java SE 8 Programming

Java SE 8 Programming Java SE 8 Programming Training Calendar Date Training Time Location 16 September 2019 5 Days Bilginç IT Academy 28 October 2019 5 Days Bilginç IT Academy Training Details Training Time : 5 Days Capacity

More information

Overview of Java 8 Functional Interfaces

Overview of Java 8 Functional Interfaces Overview of Java 8 Functional Interfaces Douglas C. Schmidt d.schmidt@vanderbilt.edu www.dre.vanderbilt.edu/~schmidt Professor of Computer Science Institute for Software Integrated Systems Vanderbilt University

More information

Java SE 8: Lambda Expressions And The Stream API

Java SE 8: Lambda Expressions And The Stream API Java SE 8: Lambda Expressions And The Stream API Simon Ritter Head of Java Technology Evangelism Java Product Management Java Day Tokyo 2015 April 8, 2015 Safe Harbor Statement The following is intended

More information

Java SE 8 Programming

Java SE 8 Programming Oracle University Contact Us: Local: 1800 103 4775 Intl: +91 80 67863102 Java SE 8 Programming Duration: 5 Days What you will learn This Java SE 8 Programming training covers the core language features

More information

Advanced Programming Methods. Lecture 4 - Functional Programming in Java

Advanced Programming Methods. Lecture 4 - Functional Programming in Java Advanced Programming Methods Lecture 4 - Functional Programming in Java Important Announcement: At Seminar 6 (7-13 November 2017) you will have a closed-book test (based on your laboratory work). Overview

More information

PIC 20A Anonymous classes, Lambda Expressions, and Functional Programming

PIC 20A Anonymous classes, Lambda Expressions, and Functional Programming PIC 20A Anonymous classes, Lambda Expressions, and Functional Programming Ernest Ryu UCLA Mathematics Last edited: December 8, 2017 Introductory example When you write an ActionListener for a GUI, you

More information

Java gets a closure. Tomasz Kowalczewski

Java gets a closure. Tomasz Kowalczewski Java gets a closure Tomasz Kowalczewski Agenda Lambdas and closures Java syntax Language interaction Implementation Interface evolution Library changes Lambda expression First class function that closes

More information

Anonymous Classes. A short-cut for defining classes when you want to create only one object of the class.

Anonymous Classes. A short-cut for defining classes when you want to create only one object of the class. Anonymous Classes A short-cut for defining classes when you want to create only one object of the class. Why Anonymous Class? Sometime we must define a class just to create only one instance of the class.

More information

Lambdas, Default Methods and Bulk Data Operations by Anton Arhipov. All rights reserved ZeroTurnaround OÜ

Lambdas, Default Methods and Bulk Data Operations by Anton Arhipov. All rights reserved ZeroTurnaround OÜ Java 8 Revealed Lambdas, Default Methods and Bulk Data Operations by Anton Arhipov 1 Table of contents Introduction to Java 8 1-2 Part I Lambdas in Java 8 3-10 Part Ii Default Methods 12-15 Part iii Bulk

More information

Advanced Java Programming

Advanced Java Programming Advanced Java Programming Programming Technologies 2015/2016 spring Kollár, Lajos Kocsis, Gergely (English version) Advanced Java Programming Java 5 Generics (Enums) Java 7 Strings in switch try-with-resources

More information

Introduktion Die Klarstellung

Introduktion Die Klarstellung Introduktion Die Klarstellung 3 Lambdas in aller Kürze 4 class C { public int method(int x); public static int function(int x); Lambdas in aller Kürze 5 class C { public int method(c this, int x); public

More information

Java Workshop Lambda Expressions

Java Workshop Lambda Expressions Java Workshop Lambda Expressions AP Java Workshop 2015 Hanno Hüther and Martin Stein Agenda 1. Origin and syntax 2. History and motivation 3. Exercise 1: Refactoring to lambdas 4. Method references 5.

More information

Ausblick auf Java 8. Martin Plümicke. 25. Mai Baden-Wuerttemberg Cooperative State University Stuttgart/Horb

Ausblick auf Java 8. Martin Plümicke. 25. Mai Baden-Wuerttemberg Cooperative State University Stuttgart/Horb Ausblick auf Java 8 Martin Plümicke Baden-Wuerttemberg Cooperative State University Stuttgart/Horb 25. Mai 2012 Overview Introduction Introduction Closures Java s motivation λ expressions Functional interfaces

More information

Lambdas in Java 8. Start programming in a more functional style

Lambdas in Java 8. Start programming in a more functional style Lambdas in Java 8 Start programming in a more functional style Background Who am I? Tobias Coetzee I m a Technical Lead at BBD I present the Java Expert Level Certifications at BBD (EJB, JPA, etc.) I m

More information

Roland Mast Sybit GmbH Agiler Software-Architekt Scrum Master

Roland Mast Sybit GmbH Agiler Software-Architekt Scrum Master SOLID mit Java 8 Roland Mast Sybit GmbH Agiler Software-Architekt Scrum Master roland.mast@sybit.de Roland Mast Sybit GmbH Agiler Software-Architekt roland.mast@sybit.de SOLID und Uncle Bob Single responsibility

More information

Copyright 2012, Oracle and/or its affiliates. All rights reserved.

Copyright 2012, Oracle and/or its affiliates. All rights reserved. 1 Lambda Expressions in Java Simon Ritter Java Technology Evangelist Twitter: @speakjava With thanks to Brian Goetz 2 The following is intended to outline our general product direction. It is intended

More information

Binghamton University. CS-140 Fall Functional Java

Binghamton University. CS-140 Fall Functional Java Functional Java 1 First Class Data We have learned how to manipulate data with programs We can pass data to methods via arguments We can return data from methods via return types We can encapsulate data

More information

Principles of Programming Languages

Principles of Programming Languages Principles of Programming Languages h"p://www.di.unipi.it/~andrea/dida2ca/plp- 15/ Prof. Andrea Corradini Department of Computer Science, Pisa Lesson 30 Java 8! Lambdas and streams in Java 8 1 Java 8:

More information

Whether to Include Java 8 Features in Introductory CS Courses

Whether to Include Java 8 Features in Introductory CS Courses CCSC Eastern Conference 2015 Tutorial Whether to Include Java 8 Features in Introductory CS Courses James Heliotis Computer Science Rochester Inst. of Technology jeh@cs.rit.edu 1 Our History in Java Education

More information

COURSE 5 PROGRAMMING III OOP. JAVA LANGUAGE

COURSE 5 PROGRAMMING III OOP. JAVA LANGUAGE COURSE 5 PROGRAMMING III OOP. JAVA LANGUAGE PREVIOUS COURSE CONTENT Generics Defining a generic Run-time behavior Collections List Set Map COUSE CONTENT Collections Utilities classes Aggregate Operations

More information

Java SE 8 New Features

Java SE 8 New Features Java SE 8 New Features Duration 2 Days What you will learn This Java SE 8 New Features training delves into the major changes and enhancements in Oracle Java SE 8. You'll focus on developing an understanding

More information

Streams in Java 8. Start programming in a more functional style

Streams in Java 8. Start programming in a more functional style Streams in Java 8 Start programming in a more functional style Background Who am I? Tobias Coetzee I m a Technical Lead at BBD I present the Java Expert Level Certifications at BBD (EJB, JPA, etc.) I m

More information

JSR 335: Project Lambda. François Sarradin -- Xebia

JSR 335: Project Lambda. François Sarradin -- Xebia λ JSR 335: Project Lambda François Sarradin -- Xebia Java Roadmap Java 7 jul. 2011 37 3 JSR Java 8 aug. 2013 Java 9? Modularity Performance Productivity FP / Parallel comp. Date API improv. Type annotation

More information

Sets and Maps. Sets Maps The Comparator Interface Sets and Maps in Java Collections API. Review for Exam Reading:

Sets and Maps. Sets Maps The Comparator Interface Sets and Maps in Java Collections API. Review for Exam Reading: Sets and Maps Sets Maps The Comparator Interface Sets and Maps in Java Collections API TreeSet TreeMap Review for Exam Reading: 13.1-13.6 Sets A set is a collection of elements with no duplicates We had

More information

1 Copyright 2012, Oracle and/or its affiliates. All rights reserved. Insert Information Protection Policy Classification from Slide 8

1 Copyright 2012, Oracle and/or its affiliates. All rights reserved. Insert Information Protection Policy Classification from Slide 8 1 Copyright 2012, Oracle and/or its affiliates. All rights Insert Information Protection Policy Classification from Slide 8 Project Lambda: To Multicore and Beyond David Holmes 2 Copyright 2012, Oracle

More information

301AA - Advanced Programming [AP-2017]

301AA - Advanced Programming [AP-2017] 301AA - Advanced Programming [AP-2017] Lecturer: Andrea Corradini andrea@di.unipi.it Tutor: Lillo GalleBa galleba@di.unipi.it Department of Computer Science, Pisa Academic Year 2017/18 AP-2017-15: Recursion,

More information

Java 8 new features Juan Hernández

Java 8 new features Juan Hernández Java 8 new features Juan Hernández Dec 1st 2015 1 / 73 Introduction In this session we will do an introduction to the new features introduced by Java 8 for functional programming: λ-expressions and the

More information

Today. Reading. Homework. Lecture Notes CPSC 224 (Spring 2012) hashcode() method. Collections class. Ch 9: hw 7 out (due in a week)

Today. Reading. Homework. Lecture Notes CPSC 224 (Spring 2012) hashcode() method. Collections class. Ch 9: hw 7 out (due in a week) Today hashcode() method Collections class Reading Ch 9: 406-424 Homework hw 7 out (due in a week) S. Bowers 1 of 9 The Object hashcode() function The signature: public int hashcode() What it does: returns

More information

<Insert Picture Here> Project Lambda: To Multicore and Beyond

<Insert Picture Here> Project Lambda: To Multicore and Beyond Project Lambda: To Multicore and Beyond Brian Goetz Java Language Architect, Oracle Corporation The following is intended to outline our general product direction. It is intended

More information

Introducing Scala-like function types into Java-TX

Introducing Scala-like function types into Java-TX Introducing Scala-like function types into Java-TX ManLang 2017 Martin Plümicke Andreas Stadelmeier www.dhbw-stuttgart.de/horb Overview 1 Type of lambda expressions in Java-8 2 Introducing real function

More information

Introduction to Functional Programming in Java 8

Introduction to Functional Programming in Java 8 1 Introduction to Functional Programming in Java 8 Java 8 is the current version of Java that was released in March, 2014. While there are many new features in Java 8, the core addition is functional programming

More information

Java 8 Functional Programming with Lambdas Angelika Langer

Java 8 Functional Programming with Lambdas Angelika Langer Java 8 Functional Programming with Lambdas Angelika Langer Training/Consulting objective learn about lambda expressions in Java know the syntax elements understand typical uses Lambda Expressions in Java

More information

Evolving Java. Brian Goetz Java Language Architect, Oracle. Copyright 2013, Oracle and/or its affiliates. All rights reserved.

Evolving Java. Brian Goetz Java Language Architect, Oracle. Copyright 2013, Oracle and/or its affiliates. All rights reserved. Evolving Java Brian Goetz Java Language Architect, Oracle 1 The following is intended to outline our general product direction. It is intended for information purposes only, and may not be incorporated

More information

Lambda Expressions In JDK8: Going Beyond The Basics

Lambda Expressions In JDK8: Going Beyond The Basics Lambda Expressions In JDK8: Going Beyond The Basics Simon Ri?er Head of Java Technology Evangelism Oracle Corp Twi?er: @speakjava Copyright 2014, Oracle and/or its affiliates. All rights reserved. Safe Harbor

More information

Lambda expressions in Java: a compiler writer's perspective. Maurizio Cimadamore Type-system engineer, Oracle Corporation

Lambda expressions in Java: a compiler writer's perspective. Maurizio Cimadamore Type-system engineer, Oracle Corporation Lambda expressions in Java: a compiler writer's perspective Maurizio Cimadamore Type-system engineer, Oracle Corporation The following is intended to outline our general product direction. It is intended

More information

Java Technologies. Lecture V. Valdas Rapševičius

Java Technologies. Lecture V. Valdas Rapševičius Preparation of the material was supported by the project Increasing Internationality in Study Programs of the Department of Computer Science II, project number VP1 2.2 ŠMM-07-K-02-070, funded by The European

More information

Java 8 Stream Performance Angelika Langer & Klaus Kreft

Java 8 Stream Performance Angelika Langer & Klaus Kreft Java 8 Stream Performance Angelika Langer & Klaus Kreft objective how do streams perform? explore whether / when parallel streams outperfom seq. streams compare performance of streams to performance of

More information

Java 8 Stream Performance Angelika Langer & Klaus Kreft

Java 8 Stream Performance Angelika Langer & Klaus Kreft Java 8 Stream Performance Angelika Langer & Klaus Kreft agenda introduction loop vs. sequential stream sequential vs. parallel stream Stream Performance (2) what is a stream? equivalent of sequence from

More information

ΠΙΝΑΚΑΣ ΠΛΑΝΟΥ ΕΚΠΑΙΔΕΥΣΗΣ

ΠΙΝΑΚΑΣ ΠΛΑΝΟΥ ΕΚΠΑΙΔΕΥΣΗΣ ΠΑΡΑΡΤΗΜΑ «Β» ΠΙΝΑΚΑΣ ΠΛΑΝΟΥ ΕΚΠΑΙΔΕΥΣΗΣ Α/Α ΠΕΡΙΓΡΑΦΗ ΕΚΠΑΙΔΕΥΣΗΣ ΘΕΜΑΤΙΚΕΣ ΕΝΟΤΗΤΕΣ 1. Java SE8 Fundamentals What Is a Java Program? Introduction to Computer Programs Key Features of the Java Language

More information

Fast Track to Core Java 8 Programming for OO Developers (TT2101-J8) Day(s): 3. Course Code: GK1965. Overview

Fast Track to Core Java 8 Programming for OO Developers (TT2101-J8) Day(s): 3. Course Code: GK1965. Overview Fast Track to Core Java 8 Programming for OO Developers (TT2101-J8) Day(s): 3 Course Code: GK1965 Overview Java 8 Essentials for OO Developers is a three-day, fast-paced, quick start to Java 8 training

More information

C09: Interface, and Abstract Class and Method

C09: Interface, and Abstract Class and Method CISC 3120 C09: Interface, and Abstract Class and Method Hui Chen Department of Computer & Information Science CUNY Brooklyn College 2/28/2018 CUNY Brooklyn College 1 Outline Recap Inheritance and polymorphism

More information

C30b: Inner Class, Anonymous Class, and Lambda Expression

C30b: Inner Class, Anonymous Class, and Lambda Expression CISC 3115 TY3 C30b: Inner Class, Anonymous Class, and Lambda Expression Hui Chen Department of Computer & Information Science CUNY Brooklyn College 12/6/2018 CUNY Brooklyn College 1 Outline Discussed Concept

More information

Functional programming in C#

Functional programming in C# Functional programming in C# A quick approach to another paradigm Nacho Iborra IES San Vicente This work is licensed under the Creative Commons Attribution- NonCommercial-ShareAlike 4.0 International License.

More information

Collections, Maps and Generics

Collections, Maps and Generics Collections API Collections, Maps and Generics You've already used ArrayList for exercises from the previous semester, but ArrayList is just one part of much larger Collections API that Java provides.

More information

Lambdas & Streams: Taking the Hard Work Out of Bulk Operations in Java SE 8.

Lambdas & Streams: Taking the Hard Work Out of Bulk Operations in Java SE 8. Lambdas & Streams: Taking the Hard Work Out of Bulk Operations in Java SE 8 Simon Ritter Head of Java Evangelism Oracle Corporation Twitter: @speakjava 1 Concurrency in Java Project Lambda java.util.concurrent

More information

JVA-103. Java Programming

JVA-103. Java Programming JVA-103. Java Programming Version 8.0 This course teaches programming in the Java language -- i.e. the Java Standard Edition platform. It is intended for programmers with experience in languages other

More information

Collections Algorithms

Collections Algorithms Collections Algorithms 1 / 11 The Collections Framework A collection is an object that represents a group of objects. The collections framework allows different kinds of collections to be dealt with in

More information

Java 8 Programming for OO Experienced Developers

Java 8 Programming for OO Experienced Developers www.peaklearningllc.com Java 8 Programming for OO Experienced Developers (5 Days) This course is geared for developers who have prior working knowledge of object-oriented programming languages such as

More information

Project Lambda: Functional Programming Constructs and Simpler Concurrency in Java SE 8

Project Lambda: Functional Programming Constructs and Simpler Concurrency in Java SE 8 Project Lambda: Functional Programming Constructs and Simpler Concurrency in Java SE 8 Michael Cui Principle Engineer, Java Platform Group Oracle Corporation 1 The following is intended to outline our

More information

PROGRAMMING FUNDAMENTALS

PROGRAMMING FUNDAMENTALS PROGRAMMING FUNDAMENTALS Q1. Name any two Object Oriented Programming languages? Q2. Why is java called a platform independent language? Q3. Elaborate the java Compilation process. Q4. Why do we write

More information

Written Test 2. CSE Section M, Winter p. 1 of 8. Family Name: Given Name(s): Student Number:

Written Test 2. CSE Section M, Winter p. 1 of 8. Family Name: Given Name(s): Student Number: Written Test 2 CSE 1020 3.0 Section M, Winter 2010 p. 1 of 8 Family Name: Given Name(s): Student Number: Guidelines and Instructions: 1. This is a 50-minute test. You can use the textbook, but no electronic

More information

COMP6700/2140 Code as Data

COMP6700/2140 Code as Data COMP6700/2140 Code as Data Alexei B Khorev Research School of Computer Science, ANU March 2017 Alexei B Khorev (RSCS, ANU) COMP6700/2140 Code as Data March 2017 1 / 19 Topics 1 What does treating code

More information

if (x == 0); System.out.println( x=0 ); if (x = 0) System.out.println( x=0 );

if (x == 0); System.out.println( x=0 ); if (x = 0) System.out.println( x=0 ); Sample Final Exam 1. Evaluate each of the following expressions and show the result and data type of each: Expression Value Data Type 14 % 5 1 / 2 + 1 / 3 + 1 / 4 4.0 / 2.0 Math.pow(2.0, 3.0) (double)(2

More information

CSE : Python Programming. Decorators. Announcements. The decorator pattern. The decorator pattern. The decorator pattern

CSE : Python Programming. Decorators. Announcements. The decorator pattern. The decorator pattern. The decorator pattern CSE 399-004: Python Programming Lecture 12: Decorators April 9, 200 http://www.seas.upenn.edu/~cse39904/ Announcements Projects (code and documentation) are due: April 20, 200 at pm There will be informal

More information

Higher-Order Sequential Operations

Higher-Order Sequential Operations Chapter 9 Higher-Order Sequential Operations Many of the operations we wish to perform over lists have common structure. In this chapter, we investigate the most common of these patterns and how we can

More information

Lambda Notes for CS 2102

Lambda Notes for CS 2102 Lambda Notes for CS 2102 Remember filter and map from CS1101/1102: ;; filter: (X- >Boolean) ListOfX - > ListOfX the function argument (X- > Boolean) is a predicate. Filter applies the predicate to each

More information

Server-Side Web Programming: Java. Copyright 2017 by Robert M. Dondero, Ph.D Princeton University

Server-Side Web Programming: Java. Copyright 2017 by Robert M. Dondero, Ph.D Princeton University Server-Side Web Programming: Java Copyright 2017 by Robert M. Dondero, Ph.D Princeton University 1 Objectives You will learn about: Server-side web programming in Java, via Servlets The Spark web app framework

More information

Java 8 Functional Programming with Lambdas Angelika Langer

Java 8 Functional Programming with Lambdas Angelika Langer Java 8 Functional Programming with Lambdas Angelika Langer Training/Consulting objective learn about lambda expressions in Java know the syntax elements understand typical uses Lambda Expressions in Java

More information

An unofficial guide to Java and JDK 1.8. Adam L. Davis. This book is for sale at

An unofficial guide to Java and JDK 1.8. Adam L. Davis. This book is for sale at What s New in Java 8 An unofficial guide to Java and JDK 1.8 Adam L. Davis This book is for sale at http://leanpub.com/whatsnewinjava8 This version was published on 2018-08-01 This is a Leanpub book. Leanpub

More information

Loops. CSE 114, Computer Science 1 Stony Brook University

Loops. CSE 114, Computer Science 1 Stony Brook University Loops CSE 114, Computer Science 1 Stony Brook University http://www.cs.stonybrook.edu/~cse114 1 Motivation Suppose that you need to print a string (e.g., "Welcome to Java!") a user-defined times N: N?

More information

Generics: Past, Present and Future

Generics: Past, Present and Future Generics: Past, Present and Future @richardwarburto insightfullogic.com @raouluk cambridgecoding.com binarysearch(list

More information

Java Review: Objects

Java Review: Objects Outline Java review Abstract Data Types (ADTs) Interfaces Class Hierarchy, Abstract Classes, Inheritance Invariants Lists ArrayList LinkedList runtime analysis Iterators Java references 1 Exam Preparation

More information

Notes from the Boards Set BN19 Page

Notes from the Boards Set BN19 Page 1 The Class, String There are five programs in the class code folder Set17. The first one, String1 is discussed below. The folder StringInput shows simple string input from the keyboard. Processing is

More information

Java How to Program, 10/e. Copyright by Pearson Education, Inc. All Rights Reserved.

Java How to Program, 10/e. Copyright by Pearson Education, Inc. All Rights Reserved. Java How to Program, 10/e Copyright 1992-2015 by Pearson Education, Inc. All Rights Reserved. Data structures Collections of related data items. Discussed in depth in Chapters 16 21. Array objects Data

More information

Notes - Recursion. A geeky definition of recursion is as follows: Recursion see Recursion.

Notes - Recursion. A geeky definition of recursion is as follows: Recursion see Recursion. Notes - Recursion So far we have only learned how to solve problems iteratively using loops. We will now learn how to solve problems recursively by having a method call itself. A geeky definition of recursion

More information

CONTENTS. PART 1 Structured Programming 1. 1 Getting started 3. 2 Basic programming elements 17

CONTENTS. PART 1 Structured Programming 1. 1 Getting started 3. 2 Basic programming elements 17 List of Programs xxv List of Figures xxix List of Tables xxxiii Preface to second version xxxv PART 1 Structured Programming 1 1 Getting started 3 1.1 Programming 3 1.2 Editing source code 5 Source code

More information

Section 9: Design Patterns. Slides by Alex Mariakakis. with material from David Mailhot, Hal Perkins, Mike Ernst

Section 9: Design Patterns. Slides by Alex Mariakakis. with material from David Mailhot, Hal Perkins, Mike Ernst Section 9: Design Patterns Slides by Alex Mariakakis with material from David Mailhot, Hal Perkins, Mike Ernst What Is A Design Pattern A standard solution to a common programming problem A technique for

More information

Introduction to Object-Oriented Programming

Introduction to Object-Oriented Programming Introduction to Object-Oriented Programming Iterators and Streams Christopher Simpkins chris.simpkins@gatech.edu CS 1331 (Georgia Tech) Iterators and Streams 1 / 20 The Collections Framework A collection

More information

CS 101 Exam 1 Spring 200 Id Name

CS 101 Exam 1 Spring 200  Id Name This exam is open text book and closed notes. Different questions have different points associated with them with later occurring questions having more worth than the beginning questions. Because your

More information

Advanced programming for Java platform. Introduction

Advanced programming for Java platform. Introduction Advanced programming for Java platform Introduction About course Petr Hnětynka hnetynka@d3s.mff.cuni.cz http://d3s.mff.cuni.cz/teaching/vsjava/ continuation of "Java (NPRG013)" basic knowledge of Java

More information

Module 2: Choice and Iteration

Module 2: Choice and Iteration Module 2: Choice and Iteration Ron K. Cytron * Department of Computer Science and Engineering * Washington University in Saint Louis Thanks to Alan Waldman for comments that improved these slides Prepared

More information

CS 211: Binary Search and Sorting

CS 211: Binary Search and Sorting CS 211: Binary Search and Sorting Chris Kauffman Week 13-2 Front Matter Deliverables P6 Up, Due Sunday Test Cases Later today Reading BJP: Ch 13 on Searching and Sorting Lab 13: Quiz/Task (Last one) Schedule

More information

Programming Language Concepts Object-Oriented Programming. Janyl Jumadinova 28 February, 2017

Programming Language Concepts Object-Oriented Programming. Janyl Jumadinova 28 February, 2017 Programming Language Concepts Object-Oriented Programming Janyl Jumadinova 28 February, 2017 Three Properties of Object-Oriented Languages: Encapsulation Inheritance Dynamic method binding (polymorphism)

More information

Interfaces. James Brucker

Interfaces. James Brucker Interfaces James Brucker What is an Interface? An interface is a specification of (1) a required behavior any class that claims to "implement" the interface must perform the behavior (2) constant data

More information

CS-140 Fall 2017 Test 1 Version Practice Practice for Nov. 20, Name:

CS-140 Fall 2017 Test 1 Version Practice Practice for Nov. 20, Name: CS-140 Fall 2017 Test 1 Version Practice Practice for Nov. 20, 2017 Name: 1. (10 points) For the following, Check T if the statement is true, the F if the statement is false. (a) T F : If a child overrides

More information

CSC 273 Data Structures

CSC 273 Data Structures CSC 273 Data Structures Lecture 5 - Introduction to Sorting The Interface Comparable Consider the method compareto for class String if s and t are strings, s.compareto(t) is Negative if s comes before

More information

Xtend Programming Language

Xtend Programming Language Xtend Programming Language Produced by: Eamonn de Leastar (edeleastar@wit.ie) Department of Computing and Mathematics http://www.wit.ie/ Agenda Subtitle Excellent Xtend User Guide (Version 2.6) API Docs

More information

CO Java SE 8: Fundamentals

CO Java SE 8: Fundamentals CO-83527 Java SE 8: Fundamentals Summary Duration 5 Days Audience Application Developer, Developer, Project Manager, Systems Administrator, Technical Administrator, Technical Consultant and Web Administrator

More information

CS/B.TECH/CSE(OLD)/SEM-6/CS-605/2012 OBJECT ORIENTED PROGRAMMING. Time Allotted : 3 Hours Full Marks : 70

CS/B.TECH/CSE(OLD)/SEM-6/CS-605/2012 OBJECT ORIENTED PROGRAMMING. Time Allotted : 3 Hours Full Marks : 70 CS/B.TECH/CSE(OLD)/SEM-6/CS-605/2012 2012 OBJECT ORIENTED PROGRAMMING Time Allotted : 3 Hours Full Marks : 70 The figures in the margin indicate full marks. Candidates are required to give their answers

More information

Advanced Programming - JAVA Lecture 4 OOP Concepts in JAVA PART II

Advanced Programming - JAVA Lecture 4 OOP Concepts in JAVA PART II Advanced Programming - JAVA Lecture 4 OOP Concepts in JAVA PART II Mahmoud El-Gayyar elgayyar@ci.suez.edu.eg Ad hoc-polymorphism Outline Method overloading Sub-type Polymorphism Method overriding Dynamic

More information

Introduction to Programming Using Java (98-388)

Introduction to Programming Using Java (98-388) Introduction to Programming Using Java (98-388) Understand Java fundamentals Describe the use of main in a Java application Signature of main, why it is static; how to consume an instance of your own class;

More information

Section 8: Design Patterns. Slides by Alex Mariakakis. with material from David Mailhot, Hal Perkins, Mike Ernst

Section 8: Design Patterns. Slides by Alex Mariakakis. with material from David Mailhot, Hal Perkins, Mike Ernst Section 8: Design Patterns Slides by Alex Mariakakis with material from David Mailhot, Hal Perkins, Mike Ernst Announcements HW8 due tonight 10 pm Quiz 7 due tonight 10 pm Industry guest speaker tomorrow!

More information

Java SE 8 Programmer I and II Syballus( Paper codes : 1z0-808 & 1z0-809)

Java SE 8 Programmer I and II Syballus( Paper codes : 1z0-808 & 1z0-809) Page1 Java SE 8 Programmer 1, also called OCJA 8.0 Exam Number: 1Z0-808 Associated Certifications: Oracle Certified Associate, Java SE 8 Programmer Java Basics Highlights of the Certifications Define the

More information

P2: Advanced Java & Exam Preparation

P2: Advanced Java & Exam Preparation P2: Advanced Java & Exam Preparation Claudio Corrodi May 18 2018 1 Java 8: Default Methods public interface Addressable { public String getstreet(); public String getcity(); public String getfulladdress();

More information