SlideShare a Scribd company logo
Why should a Java programmer
shift towards
Functional Programming Paradigm
Presented By :
Rishi Khandelwal
Lead Software Consultant
Knoldus Inc
● My Journey
● Functional Programming definition
● Functional Programming Features
● Imperative vs Declarative
● Optional
● Code examples
Agenda
My journey
As per wiki -
“In computer science, functional programming is a
programming paradigm—a style of building the
structure and elements of computer programs—that
treats computation as the evaluation of
mathematical functions and avoids changing-state
and mutable data.”
Functional Programming Definition
Functional Programming Features
An immutable object is one whose state cannot be modified after it is
created.
An immutable variable is one that can’t change its value.
Shared state is fine if it is immutable. Mutable state is fine if it is not
shared.
Immutability
Imperative:
Immutability
Imperative:
Functional:
Immutability
Imperative:
Declarative
Imperative:
Functional:
Declarative
● Returns the same output for same input values
● Has no side effects
Pure Functions
Pure function ?
Pure Functions
Pure function ? NO
Pure Functions
Pure lambda expression ?
Pure Functions
Pure lambda expression ? NO
Pure Functions
Pure lambda function ?
Pure Functions
● Function as first class citizens
● Pass function as argument
● Return function from a function.
High Order Functions
Closures are nothing but stateful functions!
A few definitions from the web include:
● A closure is a combination of a function bundled together
(enclosed) with references to its surrounding state
● A closure gives you access to an outer function’s scope from an
inner function
Closures
Don’t evaluate immediately, evaluate when it is
needed.
Example:
● && , ||
● ? :
● Lambdas
Lazy evaluation
Should we use Functional
Programming in Java ?
● Easy to read and understand
● Easy to maintain
● Easy to reason
● Less error prone
● Improve testability
● Easy to parallelize
Yes, ofcourse
Imperative vs Declarative
● How | What
● Mutate | Transform
● Side effect | Pure
● Pass Objects | Pass functions
● Hard to compose | Function composition
● Eager Evaluation | Lazy evaluation
Imperative vs Declarative
● A new class introduced in java.util package
● Makes code more readable
● Null checks are not required.
● No more NullPointerException at run-time.
● No more Boilerplate code
Optional
Some useful methods:
● of()
● ofNullable()
● empty();
● ifPresent()
● isPresent()
● map()
● filter()
● flatMap()
● orElse()
Optional
Let’s see few more examples
26
Thank You
rishi@knoldus.com
@rishckt
https://www.linkedin.com/in/rishckt/
Stay in touch
Ad

Recommended

Functional Programming in Ruby
Functional Programming in Ruby
Alex Teut
 
Introduction to Higher Order Functions in Scala
Introduction to Higher Order Functions in Scala
Knoldus Inc.
 
Introduction to Functional programming
Introduction to Functional programming
Ny Fanilo Andrianjafy, B.Eng.
 
Functional programming
Functional programming
ijcd
 
JavaScript Introductin to Functions
JavaScript Introductin to Functions
Charles Russell
 
Programming in python w6
Programming in python w6
Priya Nayak
 
Kotlin & arrow: the functional way
Kotlin & arrow: the functional way
nluaces
 
Angular directives and pipes
Angular directives and pipes
Knoldus Inc.
 
Kotlin & Arrow the functional way
Kotlin & Arrow the functional way
Thoughtworks
 
Introduction to functional programming, with Elixir
Introduction to functional programming, with Elixir
kirandanduprolu
 
Functional programing jargon
Functional programing jargon
Remo Jansen
 
Running Through Typescript
Running Through Typescript
Nikhil Wanpal
 
Functional Programming For All - Scala Matsuri 2016
Functional Programming For All - Scala Matsuri 2016
Zachary Abbott
 
Internal domain-specific languages
Internal domain-specific languages
Mikhail Barash
 
XII Computer Science- Chapter 1-Function
XII Computer Science- Chapter 1-Function
Prem Joel
 
Design Patterns in Ruby
Design Patterns in Ruby
Mindfire Solutions
 
Thinking Functionally
Thinking Functionally
Piyush Katariya
 
Pure functions
Pure functions
Per Arneng
 
Pure functions and usage in Angular
Pure functions and usage in Angular
MA Jiangfan
 
Implementing GraphQL API in Elixir – Victor Deryagin
Implementing GraphQL API in Elixir – Victor Deryagin
Elixir Club
 
Functional Programming for OO Programmers (part 1)
Functional Programming for OO Programmers (part 1)
Calvin Cheng
 
Inline functions & macros
Inline functions & macros
Anand Kumar
 
Java Batch
Java Batch
Software Infrastructure
 
Let's Graph
Let's Graph
Fabien de Maestri
 
Reactive cocoa 101改
Reactive cocoa 101改
Jeff Lee
 
Sprint Boot & Kotlin - Meetup.pdf
Sprint Boot & Kotlin - Meetup.pdf
Christian Zellot
 
What is dev ops?
What is dev ops?
Mukta Aphale
 
Rails data migrations
Rails data migrations
Andrei Kaleshka
 
Introduction to Functional Programming
Introduction to Functional Programming
Dave Fancher
 
Functional programming with Java 8
Functional programming with Java 8
LivePerson
 

More Related Content

What's hot (20)

Kotlin & Arrow the functional way
Kotlin & Arrow the functional way
Thoughtworks
 
Introduction to functional programming, with Elixir
Introduction to functional programming, with Elixir
kirandanduprolu
 
Functional programing jargon
Functional programing jargon
Remo Jansen
 
Running Through Typescript
Running Through Typescript
Nikhil Wanpal
 
Functional Programming For All - Scala Matsuri 2016
Functional Programming For All - Scala Matsuri 2016
Zachary Abbott
 
Internal domain-specific languages
Internal domain-specific languages
Mikhail Barash
 
XII Computer Science- Chapter 1-Function
XII Computer Science- Chapter 1-Function
Prem Joel
 
Design Patterns in Ruby
Design Patterns in Ruby
Mindfire Solutions
 
Thinking Functionally
Thinking Functionally
Piyush Katariya
 
Pure functions
Pure functions
Per Arneng
 
Pure functions and usage in Angular
Pure functions and usage in Angular
MA Jiangfan
 
Implementing GraphQL API in Elixir – Victor Deryagin
Implementing GraphQL API in Elixir – Victor Deryagin
Elixir Club
 
Functional Programming for OO Programmers (part 1)
Functional Programming for OO Programmers (part 1)
Calvin Cheng
 
Inline functions & macros
Inline functions & macros
Anand Kumar
 
Java Batch
Java Batch
Software Infrastructure
 
Let's Graph
Let's Graph
Fabien de Maestri
 
Reactive cocoa 101改
Reactive cocoa 101改
Jeff Lee
 
Sprint Boot & Kotlin - Meetup.pdf
Sprint Boot & Kotlin - Meetup.pdf
Christian Zellot
 
What is dev ops?
What is dev ops?
Mukta Aphale
 
Rails data migrations
Rails data migrations
Andrei Kaleshka
 
Kotlin & Arrow the functional way
Kotlin & Arrow the functional way
Thoughtworks
 
Introduction to functional programming, with Elixir
Introduction to functional programming, with Elixir
kirandanduprolu
 
Functional programing jargon
Functional programing jargon
Remo Jansen
 
Running Through Typescript
Running Through Typescript
Nikhil Wanpal
 
Functional Programming For All - Scala Matsuri 2016
Functional Programming For All - Scala Matsuri 2016
Zachary Abbott
 
Internal domain-specific languages
Internal domain-specific languages
Mikhail Barash
 
XII Computer Science- Chapter 1-Function
XII Computer Science- Chapter 1-Function
Prem Joel
 
Pure functions
Pure functions
Per Arneng
 
Pure functions and usage in Angular
Pure functions and usage in Angular
MA Jiangfan
 
Implementing GraphQL API in Elixir – Victor Deryagin
Implementing GraphQL API in Elixir – Victor Deryagin
Elixir Club
 
Functional Programming for OO Programmers (part 1)
Functional Programming for OO Programmers (part 1)
Calvin Cheng
 
Inline functions & macros
Inline functions & macros
Anand Kumar
 
Reactive cocoa 101改
Reactive cocoa 101改
Jeff Lee
 
Sprint Boot & Kotlin - Meetup.pdf
Sprint Boot & Kotlin - Meetup.pdf
Christian Zellot
 

Similar to Why should a Java programmer shifts towards Functional Programming Paradigm (20)

Introduction to Functional Programming
Introduction to Functional Programming
Dave Fancher
 
Functional programming with Java 8
Functional programming with Java 8
LivePerson
 
The Rise of Functional Programming
The Rise of Functional Programming
Tjerk W
 
Functional Programming in Java
Functional Programming in Java
Jim Bethancourt
 
Functional programming with Java 8
Functional programming with Java 8
Talha Ocakçı
 
Lambdas, Collections Framework, Stream API
Lambdas, Collections Framework, Stream API
Prabu U
 
14274730 (1).ppt
14274730 (1).ppt
aptechaligarh
 
Functional Programming in Java
Functional Programming in Java
Narendran Solai Sridharan
 
Fun with java 8
Fun with java 8
Victor Perepelitsky
 
Functional programming principles and Java 8
Functional programming principles and Java 8
Dragos Balan
 
Functional programming with Xtend
Functional programming with Xtend
Sven Efftinge
 
Introduction to functional programming with java 8
Introduction to functional programming with java 8
JavaBrahman
 
Functional programming
Functional programming
S M Asaduzzaman
 
From Imperative to Functional Programming (for Absolute Beginners)
From Imperative to Functional Programming (for Absolute Beginners)
Alex Bunardzic
 
Introduction Functional Programming - Tech Hangout #11 - 2013.01.16
Introduction Functional Programming - Tech Hangout #11 - 2013.01.16
Innovecs
 
Introductory func prog
Introductory func prog
Oleksandr Khomenko
 
Functional Programming 101 for Java 7 Developers
Functional Programming 101 for Java 7 Developers
Jayaram Sankaranarayanan
 
Functional Programming In Jdk8
Functional Programming In Jdk8
Bansilal Haudakari
 
Intro to functional programming - Confoo
Intro to functional programming - Confoo
felixtrepanier
 
The joy of functional programming
The joy of functional programming
Steve Zhang
 
Introduction to Functional Programming
Introduction to Functional Programming
Dave Fancher
 
Functional programming with Java 8
Functional programming with Java 8
LivePerson
 
The Rise of Functional Programming
The Rise of Functional Programming
Tjerk W
 
Functional Programming in Java
Functional Programming in Java
Jim Bethancourt
 
Functional programming with Java 8
Functional programming with Java 8
Talha Ocakçı
 
Lambdas, Collections Framework, Stream API
Lambdas, Collections Framework, Stream API
Prabu U
 
Functional programming principles and Java 8
Functional programming principles and Java 8
Dragos Balan
 
Functional programming with Xtend
Functional programming with Xtend
Sven Efftinge
 
Introduction to functional programming with java 8
Introduction to functional programming with java 8
JavaBrahman
 
From Imperative to Functional Programming (for Absolute Beginners)
From Imperative to Functional Programming (for Absolute Beginners)
Alex Bunardzic
 
Introduction Functional Programming - Tech Hangout #11 - 2013.01.16
Introduction Functional Programming - Tech Hangout #11 - 2013.01.16
Innovecs
 
Functional Programming 101 for Java 7 Developers
Functional Programming 101 for Java 7 Developers
Jayaram Sankaranarayanan
 
Functional Programming In Jdk8
Functional Programming In Jdk8
Bansilal Haudakari
 
Intro to functional programming - Confoo
Intro to functional programming - Confoo
felixtrepanier
 
The joy of functional programming
The joy of functional programming
Steve Zhang
 
Ad

More from Tech Triveni (20)

UI Dev in Big data world using open source
UI Dev in Big data world using open source
Tech Triveni
 
Reactive - Is it really a Magic Pill?
Reactive - Is it really a Magic Pill?
Tech Triveni
 
Let’s go reactive with JAVA
Let’s go reactive with JAVA
Tech Triveni
 
Tackling Asynchrony with Kotlin Coroutines
Tackling Asynchrony with Kotlin Coroutines
Tech Triveni
 
Programmatic Ad Tracking: Let the power of Reactive Microservices do talking
Programmatic Ad Tracking: Let the power of Reactive Microservices do talking
Tech Triveni
 
Let's refine your Scala Code
Let's refine your Scala Code
Tech Triveni
 
Supercharged imperative programming with Haskell and Functional Programming
Supercharged imperative programming with Haskell and Functional Programming
Tech Triveni
 
Observability at scale with Neural Networks: A more proactive approach
Observability at scale with Neural Networks: A more proactive approach
Tech Triveni
 
Semi-Supervised Insight Generation from Petabyte Scale Text Data
Semi-Supervised Insight Generation from Petabyte Scale Text Data
Tech Triveni
 
Finding the best solution for Image Processing
Finding the best solution for Image Processing
Tech Triveni
 
Proximity Targeting at Scale using Big Data Platforms
Proximity Targeting at Scale using Big Data Platforms
Tech Triveni
 
Effecting Pure Change - How anything ever gets done in functional programming...
Effecting Pure Change - How anything ever gets done in functional programming...
Tech Triveni
 
Becoming a Functional Programmer - Harit Himanshu (Nomis Solutions)
Becoming a Functional Programmer - Harit Himanshu (Nomis Solutions)
Tech Triveni
 
Live coding session on AI / ML using Google Tensorflow (Python) - Tanmoy Deb ...
Live coding session on AI / ML using Google Tensorflow (Python) - Tanmoy Deb ...
Tech Triveni
 
Distributing the SMACK stack - Kubernetes VS DCOS - Sahil Sawhney (Knoldus Inc.)
Distributing the SMACK stack - Kubernetes VS DCOS - Sahil Sawhney (Knoldus Inc.)
Tech Triveni
 
Blue Pill / Red Pill : The Matrix of thousands of data streams - Himanshu Gup...
Blue Pill / Red Pill : The Matrix of thousands of data streams - Himanshu Gup...
Tech Triveni
 
UX in Big Data Analytics - Paramjit Jolly (Guavus)
UX in Big Data Analytics - Paramjit Jolly (Guavus)
Tech Triveni
 
Simplified Scala Monads And Transformation - Harmeet Singh (Knoldus Inc.)
Simplified Scala Monads And Transformation - Harmeet Singh (Knoldus Inc.)
Tech Triveni
 
Micro Frontends Architecture - Jitendra kumawat (Guavus)
Micro Frontends Architecture - Jitendra kumawat (Guavus)
Tech Triveni
 
Apache CarbonData+Spark to realize data convergence and Unified high performa...
Apache CarbonData+Spark to realize data convergence and Unified high performa...
Tech Triveni
 
UI Dev in Big data world using open source
UI Dev in Big data world using open source
Tech Triveni
 
Reactive - Is it really a Magic Pill?
Reactive - Is it really a Magic Pill?
Tech Triveni
 
Let’s go reactive with JAVA
Let’s go reactive with JAVA
Tech Triveni
 
Tackling Asynchrony with Kotlin Coroutines
Tackling Asynchrony with Kotlin Coroutines
Tech Triveni
 
Programmatic Ad Tracking: Let the power of Reactive Microservices do talking
Programmatic Ad Tracking: Let the power of Reactive Microservices do talking
Tech Triveni
 
Let's refine your Scala Code
Let's refine your Scala Code
Tech Triveni
 
Supercharged imperative programming with Haskell and Functional Programming
Supercharged imperative programming with Haskell and Functional Programming
Tech Triveni
 
Observability at scale with Neural Networks: A more proactive approach
Observability at scale with Neural Networks: A more proactive approach
Tech Triveni
 
Semi-Supervised Insight Generation from Petabyte Scale Text Data
Semi-Supervised Insight Generation from Petabyte Scale Text Data
Tech Triveni
 
Finding the best solution for Image Processing
Finding the best solution for Image Processing
Tech Triveni
 
Proximity Targeting at Scale using Big Data Platforms
Proximity Targeting at Scale using Big Data Platforms
Tech Triveni
 
Effecting Pure Change - How anything ever gets done in functional programming...
Effecting Pure Change - How anything ever gets done in functional programming...
Tech Triveni
 
Becoming a Functional Programmer - Harit Himanshu (Nomis Solutions)
Becoming a Functional Programmer - Harit Himanshu (Nomis Solutions)
Tech Triveni
 
Live coding session on AI / ML using Google Tensorflow (Python) - Tanmoy Deb ...
Live coding session on AI / ML using Google Tensorflow (Python) - Tanmoy Deb ...
Tech Triveni
 
Distributing the SMACK stack - Kubernetes VS DCOS - Sahil Sawhney (Knoldus Inc.)
Distributing the SMACK stack - Kubernetes VS DCOS - Sahil Sawhney (Knoldus Inc.)
Tech Triveni
 
Blue Pill / Red Pill : The Matrix of thousands of data streams - Himanshu Gup...
Blue Pill / Red Pill : The Matrix of thousands of data streams - Himanshu Gup...
Tech Triveni
 
UX in Big Data Analytics - Paramjit Jolly (Guavus)
UX in Big Data Analytics - Paramjit Jolly (Guavus)
Tech Triveni
 
Simplified Scala Monads And Transformation - Harmeet Singh (Knoldus Inc.)
Simplified Scala Monads And Transformation - Harmeet Singh (Knoldus Inc.)
Tech Triveni
 
Micro Frontends Architecture - Jitendra kumawat (Guavus)
Micro Frontends Architecture - Jitendra kumawat (Guavus)
Tech Triveni
 
Apache CarbonData+Spark to realize data convergence and Unified high performa...
Apache CarbonData+Spark to realize data convergence and Unified high performa...
Tech Triveni
 
Ad

Recently uploaded (20)

AudGram Review: Build Visually Appealing, AI-Enhanced Audiograms to Engage Yo...
AudGram Review: Build Visually Appealing, AI-Enhanced Audiograms to Engage Yo...
SOFTTECHHUB
 
Raman Bhaumik - Passionate Tech Enthusiast
Raman Bhaumik - Passionate Tech Enthusiast
Raman Bhaumik
 
Data Validation and System Interoperability
Data Validation and System Interoperability
Safe Software
 
June Patch Tuesday
June Patch Tuesday
Ivanti
 
Integration of Utility Data into 3D BIM Models Using a 3D Solids Modeling Wor...
Integration of Utility Data into 3D BIM Models Using a 3D Solids Modeling Wor...
Safe Software
 
Murdledescargadarkweb.pdfvolumen1 100 elementary
Murdledescargadarkweb.pdfvolumen1 100 elementary
JorgeSemperteguiMont
 
Kubernetes Security Act Now Before It’s Too Late
Kubernetes Security Act Now Before It’s Too Late
Michael Furman
 
AI vs Human Writing: Can You Tell the Difference?
AI vs Human Writing: Can You Tell the Difference?
Shashi Sathyanarayana, Ph.D
 
vertical-cnc-processing-centers-drillteq-v-200-en.pdf
vertical-cnc-processing-centers-drillteq-v-200-en.pdf
AmirStern2
 
“Key Requirements to Successfully Implement Generative AI in Edge Devices—Opt...
“Key Requirements to Successfully Implement Generative AI in Edge Devices—Opt...
Edge AI and Vision Alliance
 
FIDO Seminar: Targeting Trust: The Future of Identity in the Workforce.pptx
FIDO Seminar: Targeting Trust: The Future of Identity in the Workforce.pptx
FIDO Alliance
 
Bridging the divide: A conversation on tariffs today in the book industry - T...
Bridging the divide: A conversation on tariffs today in the book industry - T...
BookNet Canada
 
AI VIDEO MAGAZINE - June 2025 - r/aivideo
AI VIDEO MAGAZINE - June 2025 - r/aivideo
1pcity Studios, Inc
 
Edge-banding-machines-edgeteq-s-200-en-.pdf
Edge-banding-machines-edgeteq-s-200-en-.pdf
AmirStern2
 
FME for Good: Integrating Multiple Data Sources with APIs to Support Local Ch...
FME for Good: Integrating Multiple Data Sources with APIs to Support Local Ch...
Safe Software
 
FIDO Seminar: Perspectives on Passkeys & Consumer Adoption.pptx
FIDO Seminar: Perspectives on Passkeys & Consumer Adoption.pptx
FIDO Alliance
 
FIDO Seminar: Authentication for a Billion Consumers - Amazon.pptx
FIDO Seminar: Authentication for a Billion Consumers - Amazon.pptx
FIDO Alliance
 
FIDO Alliance Seminar State of Passkeys.pptx
FIDO Alliance Seminar State of Passkeys.pptx
FIDO Alliance
 
“Why It’s Critical to Have an Integrated Development Methodology for Edge AI,...
“Why It’s Critical to Have an Integrated Development Methodology for Edge AI,...
Edge AI and Vision Alliance
 
Supporting the NextGen 911 Digital Transformation with FME
Supporting the NextGen 911 Digital Transformation with FME
Safe Software
 
AudGram Review: Build Visually Appealing, AI-Enhanced Audiograms to Engage Yo...
AudGram Review: Build Visually Appealing, AI-Enhanced Audiograms to Engage Yo...
SOFTTECHHUB
 
Raman Bhaumik - Passionate Tech Enthusiast
Raman Bhaumik - Passionate Tech Enthusiast
Raman Bhaumik
 
Data Validation and System Interoperability
Data Validation and System Interoperability
Safe Software
 
June Patch Tuesday
June Patch Tuesday
Ivanti
 
Integration of Utility Data into 3D BIM Models Using a 3D Solids Modeling Wor...
Integration of Utility Data into 3D BIM Models Using a 3D Solids Modeling Wor...
Safe Software
 
Murdledescargadarkweb.pdfvolumen1 100 elementary
Murdledescargadarkweb.pdfvolumen1 100 elementary
JorgeSemperteguiMont
 
Kubernetes Security Act Now Before It’s Too Late
Kubernetes Security Act Now Before It’s Too Late
Michael Furman
 
AI vs Human Writing: Can You Tell the Difference?
AI vs Human Writing: Can You Tell the Difference?
Shashi Sathyanarayana, Ph.D
 
vertical-cnc-processing-centers-drillteq-v-200-en.pdf
vertical-cnc-processing-centers-drillteq-v-200-en.pdf
AmirStern2
 
“Key Requirements to Successfully Implement Generative AI in Edge Devices—Opt...
“Key Requirements to Successfully Implement Generative AI in Edge Devices—Opt...
Edge AI and Vision Alliance
 
FIDO Seminar: Targeting Trust: The Future of Identity in the Workforce.pptx
FIDO Seminar: Targeting Trust: The Future of Identity in the Workforce.pptx
FIDO Alliance
 
Bridging the divide: A conversation on tariffs today in the book industry - T...
Bridging the divide: A conversation on tariffs today in the book industry - T...
BookNet Canada
 
AI VIDEO MAGAZINE - June 2025 - r/aivideo
AI VIDEO MAGAZINE - June 2025 - r/aivideo
1pcity Studios, Inc
 
Edge-banding-machines-edgeteq-s-200-en-.pdf
Edge-banding-machines-edgeteq-s-200-en-.pdf
AmirStern2
 
FME for Good: Integrating Multiple Data Sources with APIs to Support Local Ch...
FME for Good: Integrating Multiple Data Sources with APIs to Support Local Ch...
Safe Software
 
FIDO Seminar: Perspectives on Passkeys & Consumer Adoption.pptx
FIDO Seminar: Perspectives on Passkeys & Consumer Adoption.pptx
FIDO Alliance
 
FIDO Seminar: Authentication for a Billion Consumers - Amazon.pptx
FIDO Seminar: Authentication for a Billion Consumers - Amazon.pptx
FIDO Alliance
 
FIDO Alliance Seminar State of Passkeys.pptx
FIDO Alliance Seminar State of Passkeys.pptx
FIDO Alliance
 
“Why It’s Critical to Have an Integrated Development Methodology for Edge AI,...
“Why It’s Critical to Have an Integrated Development Methodology for Edge AI,...
Edge AI and Vision Alliance
 
Supporting the NextGen 911 Digital Transformation with FME
Supporting the NextGen 911 Digital Transformation with FME
Safe Software
 

Why should a Java programmer shifts towards Functional Programming Paradigm