Java 8 Functional Programming Overview
E N D
Presentation Transcript
Introduction to Functional Programming with Java-8 Dhruv Rai Puri JavaBrahman.com
HELLO! I am Dhruv Rai Puri I am a Java Architect and run the technical blog JavaBrahman.com • dhruvraipuri@javabrahman.com • Twitter~ @javabrahman • facebook.com/JavaBrahman • plus.google.com/+JavaBrahman • You can reach me at
Whats going to be covered in this presentation Functional Programming What is functional programming How it’s different from imperative programming Important New Features in Java 8 Functional Interfaces Lambda Expressions
What is Functional Programming Focusses on WHAT is to be done Subset of Declarative Style of Programming
Functional V/S Imperative Programming Style of Coding Mutability of Variables Order of Execution Functions as 1st Class Objects Primary Language Structures Flow Control Mechanisms For in-depth understanding refer: http://www.javabrahman.com/programming-principles/imperative-versus-functional-programming-paradigms-conceptual/
New Functional Features in Java – 8 Functional Interfaces Eg: @FunctionalInterface public interface Predicate<T> { boolean test(T t); } Lambda Expressions Eg:(String param)->{System.out.println("My lambda says "+param);}; (cont…)
New Functional Features in Java – 8(cont…) Method References • Eg: Function doubleConvertor=Double::parseDouble; • Constructor Reference: <ClassName>::new Streams API Eg: List filteredList = employeeList.stream() .limit(2) . collect(toList()); For learning all new features in Java-8 refer: http://www.javabrahman.com/java-8/new-features-in-java-8/
Functional Interfaces › interface which has only a single abstract method 3 Types of functional interfaces 1› Custom or User Defined public interface CustomFunctionalInterface { public void firstMethod(); } (cont…)
Functional Interfaces(cont..) 2› Newly defined functional interfaces in Java 8 //java.util.function.Predicate<T> @FunctionalInterface public interface Predicate<T> { boolean test(T t); } 3› Pre-existing functional interfaces in Java @FunctionalInterface public interface Runnable { public abstract void run(); } For learning in-depth about functional interfaces refer: • http://www.javabrahman.com/java-8/functional-interfaces-java-8/
Lambda Expressions › anonymous function which can be passed around as a parameter thus achieving Behavior Parameterization Functional Interface @FunctionalInterface public interface FirstInterface { //the abstract method public void singleMethod(String param); } Corresponding Lambda Expressions (String param)->{System.out.println("My lambda says "+param);}; For learning in-depth about lambda expressions refer: • http://www.javabrahman.com/java-8/lambda-expressions-java-8-explained-examples/
For further reading on Java-8 • http://www.javabrahman.com/java-8/new-features-in-java-8/ • http://www.javabrahman.com/java-8/functional-interfaces-java-8/ • http://www.javabrahman.com/java-8/lambda-expressions-java-8-explained-examples/ • http://www.javabrahman.com/java-8/java-8-method-references-tutorial-examples/ • http://www.javabrahman.com/java-8/constructor-references-java-8-simplified-tutorial/ • http://www.javabrahman.com/java-8/java-8-streams-api-tutorial-with-examples/