The new aspect of Java with functional programming

The new aspect of Java with functional programming

Functional programming is a well-known concept in Javascript and Python. But, it’s a fancy thing for a java developer. Prior to Java 8, Java has been a pure OOP where objects are first-class citizens.

Functional programming is a well-known concept in Javascript and Python. But, it’s a fancy thing for a java developer. Prior to Java 8, Java has been a pure OOP where objects are first-class citizens. We used to do imperative coding in Java. From version 8 onwards, Java brings in the new capabilities to do functional programming. However, Java is not a functional programming language like Javascript.

Image for post

What is functional programming?

In order to understand functional programming, we need to understand some basic concepts first.

  1. Imperative programming: In this programming paradigm, we need to tell what is required to be done and how can it be done? It relies on statements like if, when, for, forEach, etc.
public class Programming {

    //remove duplicates from the list of numbers
    public static void main(String[] args) {

        List<Integer> numbers = Arrays.asList(1,2,2,3,4,5,6,7,7,8,9,9,8);

        //imperative style of removing duplicates from the list
        List<Integer> newList = new ArrayList<>();

        for(Integer number: numbers) {
            if(!newList.contains(number)) {
                newList.add(number);
            }
        }
        System.out.println(newList);
    }
}

2. Declarative programming: It just requires what to do, it depends on expressions rather than statements. Declarative code focuses on building the logic of software without actually describing its flow.

java functional-programming function

Bootstrap 5 Complete Course with Examples

Bootstrap 5 Tutorial - Bootstrap 5 Crash Course for Beginners

Nest.JS Tutorial for Beginners

Hello Vue 3: A First Look at Vue 3 and the Composition API

Building a simple Applications with Vue 3

Deno Crash Course: Explore Deno and Create a full REST API with Deno

How to Build a Real-time Chat App with Deno and WebSockets

Convert HTML to Markdown Online

HTML entity encoder decoder Online

How to Install OpenJDK 11 on CentOS 8

What is OpenJDK? OpenJDk or Open Java Development Kit is a free, open-source framework of the Java Platform, Standard Edition (or Java SE).

A Glimpse of Functional Programming with Java

Java is an object-Oriented programming language. By including functional programming elements in Java, what we have is a mixture of both paradigms (somehow). Therefore, we have object-oriented elements (classes, objects, attributes, methods, etc.), and starting with Java 8, we are able to enhance our solutions with functional approaches.

Functional Programming Techniques in Java with Examples

In this article, I will write about how to write code using Java’s API for functional programming. In the end, we will write our own stream API so we can understand how to implement a functional programming style in Java.

Functional Programming in Java

A comprehensive overview of Functional Programming in Java. 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.

Functional Programming

Functional Programming: Functional Programming is a Declarative style of Programming Paradigm for writing computer programs.