1. Introduction

In this tutorial, we’ll understand the functional programming paradigm’s core principles and how to practice them in the Java programming language. We’ll also cover some of the advanced functional programming techniques.

This will also allow us to evaluate the benefits we get from functional programming, especially in Java.

2. What Is Functional Programming

Basically, functional programming is a style of writing computer programs that treat computations as evaluating mathematical functions. So, what is a function in mathematics?

A function is an expression that relates an input set to an output set.

Importantly, the output of a function depends only on its input. More interestingly, we can compose two or more functions together to get a new function.

2.1. Lambda Calculus

To understand why these definitions and properties of mathematical functions are important in programming, we’ll have to go a little back in time. In the 1930s, mathematician Alonzo Chruch developed a formal system to express computations based on function abstraction. This universal model of computation came to be known as the Lambda Calculus.

Lambda calculus had a tremendous impact on developing the theory of programming languages, particularly functional programming languages. Typically, functional programming languages implement lambda calculus.

As lambda calculus focuses on function composition, functional programming languages provide expressive ways to compose software in function composition.

2.2. Categorization of Programming Paradigms

Of course, functional programming is not the only programming style in practice. Broadly speaking, programming styles can be categorized into imperative and declarative programming paradigms:

The imperative approach defines a program as a sequence of statements that change the program’s state until it reaches the final state. Procedural programming is a type of imperative programming where we construct programs using procedures or subroutines. One of the popular programming paradigms known as object-oriented programming (OOP) extends procedural programming concepts.

In contrast, the declarative approach expresses the logic of a computation without describing its control flow in terms of a sequence of statements. Simply put, the declarative approach’s focus is to define what the program has to achieve rather than how it should achieve it. Functional programming is a sub-set of the declarative programming languages.

These categories have further sub-categories, and the taxonomy gets quite complex, but we’ll not get into that for this tutorial.

2.3. Categorization of Programming Languages

Any attempt to formally categorize the programming languages today is an academic effort in itself! However, we’ll try to understand how programming languages are divided based on their support for functional programming for our purposes.

Pure functional languages, like Haskell, only allow pure functional programs.

Other languages, however, allow both functional and procedural programs and are considered impure functional languages. Many languages fall into this category, including Scala, Kotlin, and Java.

It’s important to understand that most of the popular programming languages today are general-purpose languages, and hence they tend to support multiple programming paradigms.

#java #functional #programming #developer

Functional Programming in Java
1.85 GEEK