Docsity
Docsity

Prepare for your exams
Prepare for your exams

Study with the several resources on Docsity


Earn points to download
Earn points to download

Earn points by helping other students or get them with a premium plan


Guidelines and tips
Guidelines and tips

Technolhy and other stuf, Summaries of Low Power Electronic Systems

it about software technolohies and

Typology: Summaries

2023/2024

Uploaded on 09/20/2023

eneskara3501
eneskara3501 🇹🇷

1 document

1 / 18

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
JAVA FUNCTIONAL
PROGRAMMING TRAINING
pf3
pf4
pf5
pf8
pf9
pfa
pfd
pfe
pff
pf12

Partial preview of the text

Download Technolhy and other stuf and more Summaries Low Power Electronic Systems in PDF only on Docsity!

JAVA FUNCTIONAL

PROGRAMMING TRAINING

c

● Having knowledge of functional programming. ● Learning the details of streams, lambda expressions, optionals. ● Practising with real life examples.

PURPOSE

WHY

● Functional programming is becoming popular. ● Allows you to think from a different point of view. ● In Trendyol, we use depending on the requirements.

Keywords

Lambda

Expressions

Functional

Programming

Pure

Functions

Referential

Transparency

High Order

Functions

Null Pointer

Exception

Optionals

Functional Programming

● Functional programming is a programming

paradigm in which we try to bind everything in

pure mathematical functions style.

● It is a declarative type of programming style.

● Its main focus is on “what to solve” in contrast to

an imperative style where the main focus is “how

to solve”.

● Programming languages: ○ Haskell, Scala, ○ Erlang, JavaScript, ○ Python, Java ○ Many other languages

● Functions can be: ○ Variable ○ Parameter ○ Return type ○ Expressions

● Benefits: ○ Performance ○ Effective code ○ Less code ○ Improved debugging

● Some terms ○ Pure Functions ○ High Order Functions ○ Referential Transparency

Functional Programming

It is a declarative programming paradigm.

Contains multiple pure functions. Function chaning is core flow.

Can not change state of any object or value. Immutability is important. Avoids mutable data. (^) Programming is done with expressions.

Functions return the same output for a given set of inputs.

Has no side effect. There is no impact of external parameter on the output of function.

Functional programs are inherently thread-safe.

Its main focus is on “what to solve”

Inherent parallelism allows for better utilization of hardware resources, leading to improved performance and scalability.

Encourages the use of lazy evaluation, where computations are only performed when their results are actually needed

Functional Programming in Java

Functional interfaces are also called Single Abstract Method Interfaces.

As the name suggests, they are interfaces that permit exactly one unimplemented method inside them.

Functional interfaces can be implemented, and the implemented class can be used to create an object that represents a function

Functional Interfaces

● Starting with Java 8 , functional programming has been gaining real improvements in Java, with lambdas, Streams API etc. ● Before Java 8, we need to create separate interfaces and their implementations for each purpose. ● With this new version of Java, we have built-in interfaces, streams, optionals, lambda expressions - which make coding easier. ● The Java API contains a set of functional interfaces designed for commonly occuring use cases. ● We don’t have to create our own functional interfaces for every little use case. ● They have located in the java.util.function package

Lambda Expressions

● A lambda expression is a short block of code used as a replacement for a method declaration. ● It takes in parameters and returns a value. ● It doesn’t need a name and it can be implemented right inside the body of another method. ● It can be used to implement a single method directly from a Functional Interface. ● Simplifies the usage of Function, Predicate etc interfaces in Java. ● Arrow -> helps us to define lambda expressions.

A simple lambda function looks like:

Streams

● Streams are the structure of processing a collection in functional style. ● A stream represents a sequence of elements and supports different kind of operations to perform computations upon those elements. ● Original collection is not modified. ● Stream operations are either intermediate or terminal.

Imperative Functional

Operetion

Parallelizing Operations

Parallel Operator

Parallel Operator^ Result

● By default, any stream operation in Java is processed sequentially, unless explicitly specified as parallel. ● Sequential streams use a single thread to process the pipeline. ● A sequential stream can be converted to a parallel one when we have actual performance requirements. ● We can achieve this by adding the parallel method to a sequential stream or by creating a stream using the parallelStream method of a collection.

● Sometimes parallelizing is not a good choice. ● It is not performance effective every time. ● A large amount of data and many computations done per element indicate that parallelism could be a good option. ● A small amount of data, unevenly splitting sources, expensive merge operations and poor memory locality indicate a potential problem for parallel execution.

Parallel Operator

● Parallel streams enable us to execute code in parallel on separate cores. ● The final result is the combination of each individual outcome.

Optional Usage

● We can chain functions in FP, having null input is not desired and throw NPE. ● Between chains we should check if value present or not ● Optionals inform you about possibility of not exists. ○ ifPresent ○ ifPresentOrElse ○ isPresent ○ orElseThrow ● We can use above and more built-in methods to take action.

Null References

● Null is a value that is not actually a value. ● Hard to determine whether the value not present or just has no value. ● Called as “A billion dollar mistake”. ● Functional programming avoids null.

● Hard to read.

● Causes to Null Pointer Exception.

Quiz

Let’s play a game!

Please enter following code to Kahoot website

or mobile application.

https://kahoot.it

Q&A

What can we do

better or different?

Questions

Feedbacks