Introduction to functional idioms in Java 8, language-extending functional libraries and short overview of reasons for adoption of such programming style.
Examples and snippets available here: https://github.com/lbialy/functionaljava8
Java 8 came out early last year and Java 7 is now, at the end of life, making Java 8 the only Oracle supported option. However, since developers value stability over trendiness, many of us are still working with Java 7, or even 6. Let’s look at some features of Java 8, and provide some arguments to persuade your code to upgrade with best practices.
Slides from my JAX London 2016 talk, discussing how the new features affect library design. Follows on from the Java SE 8 Best Practices talk - http://www.slideshare.net/scolebourne/java-se-8-best-practices-53975908
Java 8 came out early last year and Java 7 is now, at the end of life, making Java 8 the only Oracle supported option. However, since developers value stability over trendiness, many of us are still working with Java 7, or even 6. Let’s look at some features of Java 8, and provide some arguments to persuade your code to upgrade with best practices.
Slides from my JAX London 2016 talk, discussing how the new features affect library design. Follows on from the Java SE 8 Best Practices talk - http://www.slideshare.net/scolebourne/java-se-8-best-practices-53975908
In this Meetup Victor Perepelitsky - R&D Technical Leader at LivePerson leading the 'Real Time Event Processing Platform' team , will talk about Java 8', 'Stream API', 'Lambda', and 'Method reference'.
Victor will clarify what functional programming is and how can you use java 8 in order to create better software.
Victor will also cover some pain points that Java 8 did not solve regarding functionality and see how you can work around it.
Presentation on the new features introduced in JDK 8, presented on the 26.02.2013 in Sofia University in front of students and members of the Bulgarian java user group.
Java is Object Oriented Programming. Java 8 is the latest version of the Java which is used by many companies for the development in many areas. Mobile, Web, Standalone applications.
This presentation provides an overview of oracle's associate and professional Java certifications - gives you ideas on how to prepare and crack the exam with ease.
How Green are Java Best Coding Practices? - GreenDays @ Rennes - 2014-07-01Jérôme Rocheteau
This work investigates if best coding practices in Java can stand for eco-design rules as they deal with software performance. It focuses on how validating such an hypothesis for consumed energy, spent execution time and peak allocated memory. It leads to this silent feedback: no need to carry on many measures.
Presentation provides introduction and detailed explanation of the Java 8 Lambda and Streams. Lambda covers with Method references, default methods and Streams covers with stream operations,types of streams, collectors. Also streams are elaborated with parallel streams and benchmarking comparison of sequential and parallel streams.
Additional slides are covered with Optional, Splitators, certain projects based on lambda and streams
OCP Java (OCPJP) 8 Exam Quick Reference CardHari kiran G
If you are preparing to appear for Oracle Certified Professional Java SE 8 Programmer (OCPJP 8) certification exam, this a reference card (sort of long cheat sheet) meant to help you. You may want to print this reference card for your easy and quick reference when you prepare for your exam.
Lambda: A Peek Under The Hood - Brian GoetzJAX London
This is a *highly technical* session on the details of how Lambda expressions are implemented in the Java language, presented by Java Language Architect Brian Goetz
www.denizoguz.com-For an in company JDK 7 orientation I have prepared a presentation which summaries new features of JDK 7. I would like to make it public for everyone who needs it.
Java 8 came out early last year and Java 7 is now, at the end of life, making Java 8 the only Oracle supported option. However, since developers value stability over trendiness, many of us are still working with Java 7, or even 6. Let’s look at some features of Java 8, and provide some arguments to persuade your code to upgrade with best practices.
In this Meetup Victor Perepelitsky - R&D Technical Leader at LivePerson leading the 'Real Time Event Processing Platform' team , will talk about Java 8', 'Stream API', 'Lambda', and 'Method reference'.
Victor will clarify what functional programming is and how can you use java 8 in order to create better software.
Victor will also cover some pain points that Java 8 did not solve regarding functionality and see how you can work around it.
Presentation on the new features introduced in JDK 8, presented on the 26.02.2013 in Sofia University in front of students and members of the Bulgarian java user group.
Java is Object Oriented Programming. Java 8 is the latest version of the Java which is used by many companies for the development in many areas. Mobile, Web, Standalone applications.
This presentation provides an overview of oracle's associate and professional Java certifications - gives you ideas on how to prepare and crack the exam with ease.
How Green are Java Best Coding Practices? - GreenDays @ Rennes - 2014-07-01Jérôme Rocheteau
This work investigates if best coding practices in Java can stand for eco-design rules as they deal with software performance. It focuses on how validating such an hypothesis for consumed energy, spent execution time and peak allocated memory. It leads to this silent feedback: no need to carry on many measures.
Presentation provides introduction and detailed explanation of the Java 8 Lambda and Streams. Lambda covers with Method references, default methods and Streams covers with stream operations,types of streams, collectors. Also streams are elaborated with parallel streams and benchmarking comparison of sequential and parallel streams.
Additional slides are covered with Optional, Splitators, certain projects based on lambda and streams
OCP Java (OCPJP) 8 Exam Quick Reference CardHari kiran G
If you are preparing to appear for Oracle Certified Professional Java SE 8 Programmer (OCPJP 8) certification exam, this a reference card (sort of long cheat sheet) meant to help you. You may want to print this reference card for your easy and quick reference when you prepare for your exam.
Lambda: A Peek Under The Hood - Brian GoetzJAX London
This is a *highly technical* session on the details of how Lambda expressions are implemented in the Java language, presented by Java Language Architect Brian Goetz
www.denizoguz.com-For an in company JDK 7 orientation I have prepared a presentation which summaries new features of JDK 7. I would like to make it public for everyone who needs it.
Java 8 came out early last year and Java 7 is now, at the end of life, making Java 8 the only Oracle supported option. However, since developers value stability over trendiness, many of us are still working with Java 7, or even 6. Let’s look at some features of Java 8, and provide some arguments to persuade your code to upgrade with best practices.
How to generate customized java 8 code from your databaseSpeedment, Inc.
Did you know that database classes, that require many lines of Java and SQL code, may be replaced with a single line of Java 8 code? In this tutorial session you will learn how to use standard Java 8 Streams as an alternative to traditional Object Relational Mappers (ORM). We will use the open-source tool Speedment to show how development speed can be increased and how the application code can be more concise and run faster.
Introduction to Java programming - Java tutorial for beginners to teach Java ...Duckademy IT courses
Check out the course: https://www.duckademy.com/course/java-programming Learn Java from scratch in an easy and entertaining way. The Easy-to-follow Java programming course on Duckademy was made for beginners. In this course we start at the very basics (from zero) and go through lots of interesting exercises and analogies that will take you to an advanced level. By the end of the course you will have all the knowledge needed to move on and specialize in Java. The course is easy to follow and things are well explained. Furthermore, to make your learning easier and more enjoyable throughout the course we will develop a nostalgic, text-based fantasy game.
The course is recommended to anyone who wants to learn Java. Ideal for those who are new to programming, but it can be useful and enjoyable for people who want to switch to Java from a different programming language.
By the end of the course you will be able to build simple, but fully functional programs. You will also gain all the knowledge needed to specialize in Java and become a well-payed Java expert later on.
Check out the course: https://www.duckademy.com/course/java-programming
JavaScript Frameworks and Java EE – A Great MatchReza Rahman
The sea change in JavaScript frameworks is shifting the pendulum away from today's thin-client based server-side web frameworks like Spring MVC and JSF to JavaScript powered rich clients. With strong support for REST, WebSocket and JSON, Java EE is well positioned to adapt to this landscape.
In this heavily code driven session, we will show you how you can utilize today's most popular JavaScript frameworks like AngularJS and React to utilize the core strengths of Java EE using JAX-RS, WebSocket, JSON-P, JSON-B, CDI and Bean Validation.
Should we really be worried of earth infrastructure complaints over webEarth Infra
Earth Infrastructures Ltd. is coming with their flagship residential project Earth Gracia – Greater Noida. Earth Gracia is providing 2 & 3 BHK apartments along with a lifestyle larger than life and is well connected to two important highways, and metro connectivity is also coming up in its neighborhood
Read More
https://medium.com/@earthinfrastructuresltd
This talk introduces the core concepts of functional programming, why it matters now and how these principles are adopted for programming.
Beyond the usage of the functional principles for programming in the small, their applicability to the design of components and further on to the architecture of software systems is also explored along with relevant examples.
The code samples used in the talk are in Haskell / Java 8 / Scala / Elm and JavaScript, but deep understanding of any of these languages are not a pre-requisite.
Mahika Tutorials sharing PPT slide for core java programming language. Go threw this slide and visit our YouTube page too
https://www.youtube.com/c/mahikatutorials
This has been presented in association with Robosepians for Java concepts. Basic concepts of Java including features, conditional statements, loop statements, arrays, string, primitive datatypes, essentials of Java including oops concepts, classes, objects, polymorphism, advance topics including packages, exception handling, multihtreading and network programming have been discussed.
How Testability Inspires AngularJS Design / Ran MizrahiRan Mizrahi
Testability is a major part of design decision making in Angular`s development.
In this sessions we’ll cover what testability is, how it inspires Angular`s design and why it’s good for us.
ASTs are an incredibly powerful tool for understanding and manipulating JavaScript. We'll explore this topic by looking at examples from ESLint, a pluggable static analysis tool, and Browserify, a client-side module bundler. Through these examples we'll see how ASTs can be great for analyzing and even for modifying your JavaScript. This talk should be interesting to anyone that regularly builds apps in JavaScript either on the client-side or on the server-side.
State of ICS and IoT Cyber Threat Landscape Report 2024 previewPrayukth K V
The IoT and OT threat landscape report has been prepared by the Threat Research Team at Sectrio using data from Sectrio, cyber threat intelligence farming facilities spread across over 85 cities around the world. In addition, Sectrio also runs AI-based advanced threat and payload engagement facilities that serve as sinks to attract and engage sophisticated threat actors, and newer malware including new variants and latent threats that are at an earlier stage of development.
The latest edition of the OT/ICS and IoT security Threat Landscape Report 2024 also covers:
State of global ICS asset and network exposure
Sectoral targets and attacks as well as the cost of ransom
Global APT activity, AI usage, actor and tactic profiles, and implications
Rise in volumes of AI-powered cyberattacks
Major cyber events in 2024
Malware and malicious payload trends
Cyberattack types and targets
Vulnerability exploit attempts on CVEs
Attacks on counties – USA
Expansion of bot farms – how, where, and why
In-depth analysis of the cyber threat landscape across North America, South America, Europe, APAC, and the Middle East
Why are attacks on smart factories rising?
Cyber risk predictions
Axis of attacks – Europe
Systemic attacks in the Middle East
Download the full report from here:
https://sectrio.com/resources/ot-threat-landscape-reports/sectrio-releases-ot-ics-and-iot-security-threat-landscape-report-2024/
Epistemic Interaction - tuning interfaces to provide information for AI supportAlan Dix
Paper presented at SYNERGY workshop at AVI 2024, Genoa, Italy. 3rd June 2024
https://alandix.com/academic/papers/synergy2024-epistemic/
As machine learning integrates deeper into human-computer interactions, the concept of epistemic interaction emerges, aiming to refine these interactions to enhance system adaptability. This approach encourages minor, intentional adjustments in user behaviour to enrich the data available for system learning. This paper introduces epistemic interaction within the context of human-system communication, illustrating how deliberate interaction design can improve system understanding and adaptation. Through concrete examples, we demonstrate the potential of epistemic interaction to significantly advance human-computer interaction by leveraging intuitive human communication strategies to inform system design and functionality, offering a novel pathway for enriching user-system engagements.
GraphRAG is All You need? LLM & Knowledge GraphGuy Korland
Guy Korland, CEO and Co-founder of FalkorDB, will review two articles on the integration of language models with knowledge graphs.
1. Unifying Large Language Models and Knowledge Graphs: A Roadmap.
https://arxiv.org/abs/2306.08302
2. Microsoft Research's GraphRAG paper and a review paper on various uses of knowledge graphs:
https://www.microsoft.com/en-us/research/blog/graphrag-unlocking-llm-discovery-on-narrative-private-data/
Key Trends Shaping the Future of Infrastructure.pdfCheryl Hung
Keynote at DIGIT West Expo, Glasgow on 29 May 2024.
Cheryl Hung, ochery.com
Sr Director, Infrastructure Ecosystem, Arm.
The key trends across hardware, cloud and open-source; exploring how these areas are likely to mature and develop over the short and long-term, and then considering how organisations can position themselves to adapt and thrive.
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdf91mobiles
91mobiles recently conducted a Smart TV Buyer Insights Survey in which we asked over 3,000 respondents about the TV they own, aspects they look at on a new TV, and their TV buying preferences.
Neuro-symbolic is not enough, we need neuro-*semantic*Frank van Harmelen
Neuro-symbolic (NeSy) AI is on the rise. However, simply machine learning on just any symbolic structure is not sufficient to really harvest the gains of NeSy. These will only be gained when the symbolic structures have an actual semantics. I give an operational definition of semantics as “predictable inference”.
All of this illustrated with link prediction over knowledge graphs, but the argument is general.
Essentials of Automations: Optimizing FME Workflows with ParametersSafe Software
Are you looking to streamline your workflows and boost your projects’ efficiency? Do you find yourself searching for ways to add flexibility and control over your FME workflows? If so, you’re in the right place.
Join us for an insightful dive into the world of FME parameters, a critical element in optimizing workflow efficiency. This webinar marks the beginning of our three-part “Essentials of Automation” series. This first webinar is designed to equip you with the knowledge and skills to utilize parameters effectively: enhancing the flexibility, maintainability, and user control of your FME projects.
Here’s what you’ll gain:
- Essentials of FME Parameters: Understand the pivotal role of parameters, including Reader/Writer, Transformer, User, and FME Flow categories. Discover how they are the key to unlocking automation and optimization within your workflows.
- Practical Applications in FME Form: Delve into key user parameter types including choice, connections, and file URLs. Allow users to control how a workflow runs, making your workflows more reusable. Learn to import values and deliver the best user experience for your workflows while enhancing accuracy.
- Optimization Strategies in FME Flow: Explore the creation and strategic deployment of parameters in FME Flow, including the use of deployment and geometry parameters, to maximize workflow efficiency.
- Pro Tips for Success: Gain insights on parameterizing connections and leveraging new features like Conditional Visibility for clarity and simplicity.
We’ll wrap up with a glimpse into future webinars, followed by a Q&A session to address your specific questions surrounding this topic.
Don’t miss this opportunity to elevate your FME expertise and drive your projects to new heights of efficiency.
JMeter webinar - integration with InfluxDB and GrafanaRTTS
Watch this recorded webinar about real-time monitoring of application performance. See how to integrate Apache JMeter, the open-source leader in performance testing, with InfluxDB, the open-source time-series database, and Grafana, the open-source analytics and visualization application.
In this webinar, we will review the benefits of leveraging InfluxDB and Grafana when executing load tests and demonstrate how these tools are used to visualize performance metrics.
Length: 30 minutes
Session Overview
-------------------------------------------
During this webinar, we will cover the following topics while demonstrating the integrations of JMeter, InfluxDB and Grafana:
- What out-of-the-box solutions are available for real-time monitoring JMeter tests?
- What are the benefits of integrating InfluxDB and Grafana into the load testing stack?
- Which features are provided by Grafana?
- Demonstration of InfluxDB and Grafana using a practice web application
To view the webinar recording, go to:
https://www.rttsweb.com/jmeter-integration-webinar
Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...Jeffrey Haguewood
Sidekick Solutions uses Bonterra Impact Management (fka Social Solutions Apricot) and automation solutions to integrate data for business workflows.
We believe integration and automation are essential to user experience and the promise of efficient work through technology. Automation is the critical ingredient to realizing that full vision. We develop integration products and services for Bonterra Case Management software to support the deployment of automations for a variety of use cases.
This video focuses on the notifications, alerts, and approval requests using Slack for Bonterra Impact Management. The solutions covered in this webinar can also be deployed for Microsoft Teams.
Interested in deploying notification automations for Bonterra Impact Management? Contact us at sales@sidekicksolutionsllc.com to discuss next steps.
6. What is functional
programming?
• usage of pure functions
• expressions instead of statements
• widespread immutability
• referential transparency
7. What is functional
programming?
• usage of pure functions
• expressions instead of statements
• widespread immutability
• referential transparency
• lazy evaluation
8. What is functional
programming?
• usage of pure functions
• expressions instead of statements
• widespread immutability
• referential transparency
• lazy evaluation
... and functional idioms!
10. What's the gain?
• More predictable execution (same arguments
always yield the same results)
11. What's the gain?
• More predictable execution (same arguments
always yield the same results)
• Easier to reason about
12. What's the gain?
• More predictable execution (same arguments
always yield the same results)
• Easier to reason about
• Easier to enforce strict type correctness
13. What's the gain?
• More predictable execution (same arguments
always yield the same results)
• Easier to reason about
• Easier to enforce strict type correctness
• more precise checks in compile time
14. What's the gain?
• More predictable execution (same arguments
always yield the same results)
• Easier to reason about
• Easier to enforce strict type correctness
• more precise checks in compile time
• less bugs in runtime
16. How does this relate to Java at all?
java.lang.NullPointerException
at org.springsource.loaded.agent.SpringLoadedPreProcessor.tryToEnsureSystemClassesInitialized(SpringLoadedPreProcessor.java:362)
at org.springsource.loaded.agent.SpringLoadedPreProcessor.preProcess(SpringLoadedPreProcessor.java:128)
at org.springsource.loaded.agent.ClassPreProcessorAgentAdapter.transform(ClassPreProcessorAgentAdapter.java:102)
at sun.instrument.TransformerManager.transform(TransformerManager.java:188)
at sun.instrument.InstrumentationImpl.transform(InstrumentationImpl.java:424)
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClass(ClassLoader.java:800)
at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142)
at org.apache.catalina.loader.WebappClassLoader.findClassInternal(WebappClassLoader.java:2818)
at org.apache.catalina.loader.WebappClassLoader.findClass(WebappClassLoader.java:1159)
at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1647)
at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1526)
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClass(ClassLoader.java:800)
at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142)
at org.apache.catalina.loader.WebappClassLoader.findClassInternal(WebappClassLoader.java:2818)
at org.apache.catalina.loader.WebappClassLoader.findClass(WebappClassLoader.java:1159)
at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1647)
at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1526)
at org.springframework.util.ClassUtils.forName(ClassUtils.java:265)
at org.springframework.beans.factory.support.AbstractBeanDefinition.resolveBeanClass(AbstractBeanDefinition.java:419)
at org.springframework.beans.factory.support.AbstractBeanFactory.doResolveBeanClass(AbstractBeanFactory.java:1299)
at org.springframework.beans.factory.support.AbstractBeanFactory.access$000(AbstractBeanFactory.java:109)
at org.springframework.beans.factory.support.AbstractBeanFactory$4.run(AbstractBeanFactory.java:1265)
at org.springframework.beans.factory.support.AbstractBeanFactory$4.run(AbstractBeanFactory.java:1263)
at java.security.AccessController.doPrivileged(Native Method)
at org.springframework.beans.factory.support.AbstractBeanFactory.resolveBeanClass(AbstractBeanFactory.java:1263)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.predictBeanType(AbstractAutowireCapableBeanFactory.java:575)
at org.springframework.beans.factory.support.AbstractBeanFactory.isFactoryBean(AbstractBeanFactory.java:1347)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.doGetBeanNamesForType(DefaultListableBeanFactory.java:358)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.getBeanNamesForType(DefaultListableBeanFactory.java:327)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.getBeansOfType(DefaultListableBeanFactory.java:437)
at org.springframework.context.support.AbstractApplicationContext.invokeBeanFactoryPostProcessors(AbstractApplicationContext.java:626)
at com.xxx.core.web.WebApplicationContext.invokeBeanFactoryPostProcessors(WebApplicationContext.java)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:461)
at com.xxx.core.web.WebApplicationContext.refresh(WebApplicationContext.java)
...
18. Most common errors in Java
• Takipi monitoring service analysed error logs of over 1k
enterprise apps
19. Most common errors in Java
• Takipi monitoring service analysed error logs of over 1k
enterprise apps
• 29,965,285 exceptions over 30 days
20. Most common errors in Java
• Takipi monitoring service analysed error logs of over 1k
enterprise apps
• 29,965,285 exceptions over 30 days
• Just 10 exception types generated 97,3% of all errors
21. Most common errors in Java
• Takipi monitoring service analysed error logs of over 1k
enterprise apps
• 29,965,285 exceptions over 30 days
• Just 10 exception types generated 97,3% of all errors
• Two most common: NullPointerException &
NumberFormatException
22. Most common errors in Java
• Takipi monitoring service analysed error logs of over 1k
enterprise apps
• 29,965,285 exceptions over 30 days
• Just 10 exception types generated 97,3% of all errors
• Two most common: NullPointerException &
NumberFormatException
http://blog.takipi.com/we-crunched-1-billion-java-logged-errors-heres-what-causes-97-of-them/
25. How can FP help?
• Functional style makes implicit rules governing code
explicit, often as a part of type signatures
26. How can FP help?
• Functional style makes implicit rules governing code
explicit, often as a part of type signatures
• Functional style avoids constructs that are not statically
analysable like throwing exceptions, therefore allowing
compiler to do it's job better
27. How can FP help?
• Functional style makes implicit rules governing code
explicit, often as a part of type signatures
• Functional style avoids constructs that are not statically
analysable like throwing exceptions, therefore allowing
compiler to do it's job better
• In concurrent and parallel programming lack of mutable
state removes whole classes of programming errors for free
28. How can FP help?
• Functional style makes implicit rules governing code
explicit, often as a part of type signatures
• Functional style avoids constructs that are not statically
analysable like throwing exceptions, therefore allowing
compiler to do it's job better
• In concurrent and parallel programming lack of mutable
state removes whole classes of programming errors for free
• Yields an elegant and concise code :)
30. 1 package com.example;
2
3 class CharacterOps {
4
5 static Character firstCharacter(String string) {
6 return (string.length() > 0) ? string.charAt(0) : null;
7 }
8
9 static Integer getAlphabetPosition(Character character) {
10 int code = (int) character;
11
12 if (isLowerCase(code))
13 return code - 96;
14 else if (isUpperCase(code))
15 return code - 64;
16 else
17 return null; // or throw exception?
18 }
19
20 private static boolean isLowerCase(int code) {
21 return code >= 97 && code <= 122;
22 }
23
24 private static boolean isUpperCase(int code) {
25 return code >= 65 && code <= 90;
26 }
27
28 }
Optionality
of values
• optionality of value is not explicitly
known from method signature
31. 1 package com.example;
2
3 class CharacterOps {
4
5 static Character firstCharacter(String string) {
6 return (string.length() > 0) ? string.charAt(0) : null;
7 }
8
9 static Integer getAlphabetPosition(Character character) {
10 int code = (int) character;
11
12 if (isLowerCase(code))
13 return code - 96;
14 else if (isUpperCase(code))
15 return code - 64;
16 else
17 return null; // or throw exception?
18 }
19
20 private static boolean isLowerCase(int code) {
21 return code >= 97 && code <= 122;
22 }
23
24 private static boolean isUpperCase(int code) {
25 return code >= 65 && code <= 90;
26 }
27
28 }
Optionality
of values
• optionality of value is not explicitly
known from method signature
32. 1 package com.example;
2
3 class CharacterOps {
4
5 static Character firstCharacter(String string) {
6 return (string.length() > 0) ? string.charAt(0) : null;
7 }
8
9 static Integer getAlphabetPosition(Character character) {
10 int code = (int) character;
11
12 if (isLowerCase(code))
13 return code - 96;
14 else if (isUpperCase(code))
15 return code - 64;
16 else
17 return null; // or throw exception?
18 }
19
20 private static boolean isLowerCase(int code) {
21 return code >= 97 && code <= 122;
22 }
23
24 private static boolean isUpperCase(int code) {
25 return code >= 65 && code <= 90;
26 }
27
28 }
Optionality
of values
• optionality of value is not explicitly
known from method signature
33. 1 package com.example;
2
3 class CharacterOps {
4
5 static Character firstCharacter(String string) {
6 return (string.length() > 0) ? string.charAt(0) : null;
7 }
8
9 static Integer getAlphabetPosition(Character character) {
10 int code = (int) character;
11
12 if (isLowerCase(code))
13 return code - 96;
14 else if (isUpperCase(code))
15 return code - 64;
16 else
17 return null; // or throw exception?
18 }
19
20 private static boolean isLowerCase(int code) {
21 return code >= 97 && code <= 122;
22 }
23
24 private static boolean isUpperCase(int code) {
25 return code >= 65 && code <= 90;
26 }
27
28 }
Optionality
of values
• optionality of value is not explicitly
known from method signature
• not feeling especially bright today?
have a NullPointerException in
runtime
34. 1 package com.example;
2
3 class CharacterOps {
4
5 static Character firstCharacter(String string) {
6 return (string.length() > 0) ? string.charAt(0) : null;
7 }
8
9 static Integer getAlphabetPosition(Character character) {
10 int code = (int) character;
11
12 if (isLowerCase(code))
13 return code - 96;
14 else if (isUpperCase(code))
15 return code - 64;
16 else
17 return null; // or throw exception?
18 }
19
20 private static boolean isLowerCase(int code) {
21 return code >= 97 && code <= 122;
22 }
23
24 private static boolean isUpperCase(int code) {
25 return code >= 65 && code <= 90;
26 }
27
28 }
Optionality
of values
• optionality of value is not explicitly
known from method signature
• not feeling especially bright today?
have a NullPointerException in
runtime
35. 1 package com.example;
2
3 class CharacterOps {
4
5 static Character firstCharacter(String string) {
6 return (string.length() > 0) ? string.charAt(0) : null;
7 }
8
9 static Integer getAlphabetPosition(Character character) {
10 int code = (int) character;
11
12 if (isLowerCase(code))
13 return code - 96;
14 else if (isUpperCase(code))
15 return code - 64;
16 else
17 return null; // or throw exception?
18 }
19
20 private static boolean isLowerCase(int code) {
21 return code >= 97 && code <= 122;
22 }
23
24 private static boolean isUpperCase(int code) {
25 return code >= 65 && code <= 90;
26 }
27
28 }
Optionality
of values
• optionality of value is not explicitly
known from method signature
• not feeling especially bright today?
have a NullPointerException in
runtime
36. 1 package com.example;
2
3 class CharacterOps {
4
5 static Character firstCharacter(String string) {
6 return (string.length() > 0) ? string.charAt(0) : null;
7 }
8
9 static Integer getAlphabetPosition(Character character) {
10 int code = (int) character;
11
12 if (isLowerCase(code))
13 return code - 96;
14 else if (isUpperCase(code))
15 return code - 64;
16 else
17 return null; // or throw exception?
18 }
19
20 private static boolean isLowerCase(int code) {
21 return code >= 97 && code <= 122;
22 }
23
24 private static boolean isUpperCase(int code) {
25 return code >= 65 && code <= 90;
26 }
27
28 }
Optionality
of values
• optionality of value is not explicitly
known from method signature
• not feeling especially bright today?
have a NullPointerException in
runtime
• null is a subtype of every reference
type, so it will be propagated as
a valid object value
37. 1 package com.example;
2
3 class CharacterOps {
4
5 static Character firstCharacter(String string) {
6 return (string.length() > 0) ? string.charAt(0) : null;
7 }
8
9 static Integer getAlphabetPosition(Character character) {
10 int code = (int) character;
11
12 if (isLowerCase(code))
13 return code - 96;
14 else if (isUpperCase(code))
15 return code - 64;
16 else
17 return null; // or throw exception?
18 }
19
20 private static boolean isLowerCase(int code) {
21 return code >= 97 && code <= 122;
22 }
23
24 private static boolean isUpperCase(int code) {
25 return code >= 65 && code <= 90;
26 }
27
28 }
Optionality
of values
• optionality of value is not explicitly
known from method signature
• not feeling especially bright today?
have a NullPointerException in
runtime
• null is a subtype of every reference
type, so it will be propagated as
a valid object value
• tracking null's origination point is so
much fun!
38. What we want:
composability
1 package com.example;
2
3 import org.junit.Test;
4
5 import static com.example.CharacterOps.*;
6
7 public class CharOpsTest {
8
9 @Test
10 public void testComposability() {
11
12 getAlphabetPosition(firstCharacter("cat"));
13
14 getAlphabetPosition(firstCharacter(""));
15
16 }
17
18 }
39. What we want:
composability
1 package com.example;
2
3 import org.junit.Test;
4
5 import static com.example.CharacterOps.*;
6
7 public class CharOpsTest {
8
9 @Test
10 public void testComposability() {
11
12 getAlphabetPosition(firstCharacter("cat"));
13
14 getAlphabetPosition(firstCharacter(""));
15
16 }
17
18 }
• feeding function a "cat" is
fine, we get 3 as result
40. What we want:
composability
1 package com.example;
2
3 import org.junit.Test;
4
5 import static com.example.CharacterOps.*;
6
7 public class CharOpsTest {
8
9 @Test
10 public void testComposability() {
11
12 getAlphabetPosition(firstCharacter("cat"));
13
14 getAlphabetPosition(firstCharacter(""));
15
16 }
17
18 }
• feeding function a "cat" is
fine, we get 3 as result
java.lang.NullPointerException
at com.example.CharacterOps.getAlphabetPosition(CharacterOps.java:10)
at com.example.CharOpsTest.testComposability(CharOpsTest.java:14)
41. What we want:
composability
1 package com.example;
2
3 import org.junit.Test;
4
5 import static com.example.CharacterOps.*;
6
7 public class CharOpsTest {
8
9 @Test
10 public void testComposability() {
11
12 getAlphabetPosition(firstCharacter("cat"));
13
14 getAlphabetPosition(firstCharacter(""));
15
16 }
17
18 }
• feeding function a "cat" is
fine, we get 3 as result
• doesn't work so well for
an empty string though
java.lang.NullPointerException
at com.example.CharacterOps.getAlphabetPosition(CharacterOps.java:10)
at com.example.CharOpsTest.testComposability(CharOpsTest.java:14)
42. 1 package com.example;
2
3 import org.junit.Test;
4
5 import static com.example.CharacterOps.*;
6
7 public class ActualCharOpsTest {
8
9 @Test
10 public void testNullChecks() {
11
12 Character firstChar = firstCharacter("cat");
13
14 if (null == firstChar) {
15 // oops. what now? exception? propagate null?
16 } else {
17 // will throw NPE on digit :(
18 Integer position = getAlphabetPosition(firstChar);
19 // ...
20 }
21
22 }
23
24 }
What we get:
explicit null checks
43. 1 package com.example;
2
3 import org.junit.Test;
4
5 import static com.example.CharacterOps.*;
6
7 public class ActualCharOpsTest {
8
9 @Test
10 public void testNullChecks() {
11
12 Character firstChar = firstCharacter("cat");
13
14 if (null == firstChar) {
15 // oops. what now? exception? propagate null?
16 } else {
17 // will throw NPE on digit :(
18 Integer position = getAlphabetPosition(firstChar);
19 // ...
20 }
21
22 }
23
24 }
• you have to remember to
check for null explicitly or
face NPE hunting
What we get:
explicit null checks
44. 1 package com.example;
2
3 import org.junit.Test;
4
5 import static com.example.CharacterOps.*;
6
7 public class ActualCharOpsTest {
8
9 @Test
10 public void testNullChecks() {
11
12 Character firstChar = firstCharacter("cat");
13
14 if (null == firstChar) {
15 // oops. what now? exception? propagate null?
16 } else {
17 // will throw NPE on digit :(
18 Integer position = getAlphabetPosition(firstChar);
19 // ...
20 }
21
22 }
23
24 }
• you have to remember to
check for null explicitly or
face NPE hunting
• methods don't compose
anymore
What we get:
explicit null checks
45. 1 package com.example;
2
3 import org.junit.Test;
4
5 import static com.example.CharacterOps.*;
6
7 public class ActualCharOpsTest {
8
9 @Test
10 public void testNullChecks() {
11
12 Character firstChar = firstCharacter("cat");
13
14 if (null == firstChar) {
15 // oops. what now? exception? propagate null?
16 } else {
17 // will throw NPE on digit :(
18 Integer position = getAlphabetPosition(firstChar);
19 // ...
20 }
21
22 }
23
24 }
• you have to remember to
check for null explicitly or
face NPE hunting
• methods don't compose
anymore
• ugly :(
What we get:
explicit null checks
83. Case for immutable data
• Mutable state makes it significantly harder to reason about a system due
to multiple code branches that can lead to mutation of state
84. Case for immutable data
• Mutable state makes it significantly harder to reason about a system due
to multiple code branches that can lead to mutation of state
• Shared mutable state in concurrent environment requires
synchronisation which is difficult and leads to subtle and
hard to replicate bugs
85. Case for immutable data
• Mutable state makes it significantly harder to reason about a system due
to multiple code branches that can lead to mutation of state
• Shared mutable state in concurrent environment requires
synchronisation which is difficult and leads to subtle and
hard to replicate bugs
• Immutable objects and persistent data structures have none of those
problems
86. Case for immutable data
• Mutable state makes it significantly harder to reason about a system due
to multiple code branches that can lead to mutation of state
• Shared mutable state in concurrent environment requires
synchronisation which is difficult and leads to subtle and
hard to replicate bugs
• Immutable objects and persistent data structures have none of those
problems
• it's trivial to protect invariants once instance is immutable
87. Case for immutable data
• Mutable state makes it significantly harder to reason about a system due
to multiple code branches that can lead to mutation of state
• Shared mutable state in concurrent environment requires
synchronisation which is difficult and leads to subtle and
hard to replicate bugs
• Immutable objects and persistent data structures have none of those
problems
• it's trivial to protect invariants once instance is immutable
• no need for synchronisation ever
88. Case for immutable data
• Mutable state makes it significantly harder to reason about a system due
to multiple code branches that can lead to mutation of state
• Shared mutable state in concurrent environment requires
synchronisation which is difficult and leads to subtle and
hard to replicate bugs
• Immutable objects and persistent data structures have none of those
problems
• it's trivial to protect invariants once instance is immutable
• no need for synchronisation ever
... so how to do this in Java?
89. Immutable objects
in plain Java
1 package com.example;
2
3 import java.util.Set;
4
5 public class Office {
6
7 private final Set<Room> rooms;
8 private final Set<Employee> employees;
9
10 public Office(Set<Room> rooms, Set<Employee> employees) {
11 this.rooms = rooms;
12 this.employees = employees;
13 }
14
15 public Set<Room> getRooms() {
16 return rooms;
17 }
18
19 public Set<Employee> getEmployees() {
20 return employees;
21 }
22
23 }
90. Immutable objects
in plain Java
• lots of getter noise1 package com.example;
2
3 import java.util.Set;
4
5 public class Office {
6
7 private final Set<Room> rooms;
8 private final Set<Employee> employees;
9
10 public Office(Set<Room> rooms, Set<Employee> employees) {
11 this.rooms = rooms;
12 this.employees = employees;
13 }
14
15 public Set<Room> getRooms() {
16 return rooms;
17 }
18
19 public Set<Employee> getEmployees() {
20 return employees;
21 }
22
23 }
91. Immutable objects
in plain Java
• lots of getter noise
• if we want a builder, we have
to create one and make
constructor private
1 package com.example;
2
3 import java.util.Set;
4
5 public class Office {
6
7 private final Set<Room> rooms;
8 private final Set<Employee> employees;
9
10 public Office(Set<Room> rooms, Set<Employee> employees) {
11 this.rooms = rooms;
12 this.employees = employees;
13 }
14
15 public Set<Room> getRooms() {
16 return rooms;
17 }
18
19 public Set<Employee> getEmployees() {
20 return employees;
21 }
22
23 }
92. Immutable objects
in plain Java
• lots of getter noise
• if we want a builder, we have
to create one and make
constructor private
• optional field is painful as IDE
will cry that fields should
never have type Optional<T>
1 package com.example;
2
3 import java.util.Set;
4
5 public class Office {
6
7 private final Set<Room> rooms;
8 private final Set<Employee> employees;
9
10 public Office(Set<Room> rooms, Set<Employee> employees) {
11 this.rooms = rooms;
12 this.employees = employees;
13 }
14
15 public Set<Room> getRooms() {
16 return rooms;
17 }
18
19 public Set<Employee> getEmployees() {
20 return employees;
21 }
22
23 }
93. Immutable objects
in plain Java
• lots of getter noise
• if we want a builder, we have
to create one and make
constructor private
• optional field is painful as IDE
will cry that fields should
never have type Optional<T>
• how can we get a copy of
instance with only one field
modified?
1 package com.example;
2
3 import java.util.Set;
4
5 public class Office {
6
7 private final Set<Room> rooms;
8 private final Set<Employee> employees;
9
10 public Office(Set<Room> rooms, Set<Employee> employees) {
11 this.rooms = rooms;
12 this.employees = employees;
13 }
14
15 public Set<Room> getRooms() {
16 return rooms;
17 }
18
19 public Set<Employee> getEmployees() {
20 return employees;
21 }
22
23 }
109. About that
javaslang.collection.HashSet
• Javaslang provides immutable, persistent, purely functional
collections that match Java Collections
• Immutable, so every operation returns a new instance
110. About that
javaslang.collection.HashSet
• Javaslang provides immutable, persistent, purely functional
collections that match Java Collections
• Immutable, so every operation returns a new instance
• Persistent, so creation of new instance means that data is
shared between instances of collection and only the reference
to modified element is replaced
111. About that
javaslang.collection.HashSet
• Javaslang provides immutable, persistent, purely functional
collections that match Java Collections
• Immutable, so every operation returns a new instance
• Persistent, so creation of new instance means that data is
shared between instances of collection and only the reference
to modified element is replaced
• Functional, so all operations are referentially transparent
(at least as long as values stored in collection are immutable!)
127. Processing!
• filter out numbers that are too
short
• we need to have original number
and still process it - Tuples!
1 package com.example;
2
3 import javaslang.Tuple;
4 import javaslang.Tuple2;
5 import javaslang.collection.HashMap;
6 import javaslang.collection.HashSet;
7 import javaslang.collection.Map;
8 import javaslang.collection.Set;
9 import org.junit.Test;
10
11 import static java.util.function.Function.identity;
12 import static com.example.PhoneNumberData.*;
13
14 public class GroupNumbersTest {
15
16 @Test
17 public void processNumbers() {
18 Map<String, Set<String>> map = phoneNumbers
19 .filter(num -> num.length() >= 9)
20 .map(number -> Tuple.of(number, number))
21 .map(tuple ->
22 tuple.map(
23 num -> num.replaceFirst("^+?48", ""),
24 identity()
25 )
26 )
27 .groupBy(tuple -> tuple._1().substring(0, 2))
28 .bimap(
29 key -> areas.get(key).getOrElse("Nieznany"),
30 value -> value.map(Tuple2::_2)
31 );
32
33 System.out.println(map);
34 }
35
36 }
128. Processing!
• filter out numbers that are too
short
• we need to have original number
and still process it - Tuples!
1 package com.example;
2
3 import javaslang.Tuple;
4 import javaslang.Tuple2;
5 import javaslang.collection.HashMap;
6 import javaslang.collection.HashSet;
7 import javaslang.collection.Map;
8 import javaslang.collection.Set;
9 import org.junit.Test;
10
11 import static java.util.function.Function.identity;
12 import static com.example.PhoneNumberData.*;
13
14 public class GroupNumbersTest {
15
16 @Test
17 public void processNumbers() {
18 Map<String, Set<String>> map = phoneNumbers
19 .filter(num -> num.length() >= 9)
20 .map(number -> Tuple.of(number, number))
21 .map(tuple ->
22 tuple.map(
23 num -> num.replaceFirst("^+?48", ""),
24 identity()
25 )
26 )
27 .groupBy(tuple -> tuple._1().substring(0, 2))
28 .bimap(
29 key -> areas.get(key).getOrElse("Nieznany"),
30 value -> value.map(Tuple2::_2)
31 );
32
33 System.out.println(map);
34 }
35
36 }
129. Processing!
• filter out numbers that are too
short
• we need to have original number
and still process it - Tuples!
• strip international code from
processed tuple entry, don't do
anything to original
1 package com.example;
2
3 import javaslang.Tuple;
4 import javaslang.Tuple2;
5 import javaslang.collection.HashMap;
6 import javaslang.collection.HashSet;
7 import javaslang.collection.Map;
8 import javaslang.collection.Set;
9 import org.junit.Test;
10
11 import static java.util.function.Function.identity;
12 import static com.example.PhoneNumberData.*;
13
14 public class GroupNumbersTest {
15
16 @Test
17 public void processNumbers() {
18 Map<String, Set<String>> map = phoneNumbers
19 .filter(num -> num.length() >= 9)
20 .map(number -> Tuple.of(number, number))
21 .map(tuple ->
22 tuple.map(
23 num -> num.replaceFirst("^+?48", ""),
24 identity()
25 )
26 )
27 .groupBy(tuple -> tuple._1().substring(0, 2))
28 .bimap(
29 key -> areas.get(key).getOrElse("Nieznany"),
30 value -> value.map(Tuple2::_2)
31 );
32
33 System.out.println(map);
34 }
35
36 }
130. Processing!
• filter out numbers that are too
short
• we need to have original number
and still process it - Tuples!
• strip international code from
processed tuple entry, don't do
anything to original
1 package com.example;
2
3 import javaslang.Tuple;
4 import javaslang.Tuple2;
5 import javaslang.collection.HashMap;
6 import javaslang.collection.HashSet;
7 import javaslang.collection.Map;
8 import javaslang.collection.Set;
9 import org.junit.Test;
10
11 import static java.util.function.Function.identity;
12 import static com.example.PhoneNumberData.*;
13
14 public class GroupNumbersTest {
15
16 @Test
17 public void processNumbers() {
18 Map<String, Set<String>> map = phoneNumbers
19 .filter(num -> num.length() >= 9)
20 .map(number -> Tuple.of(number, number))
21 .map(tuple ->
22 tuple.map(
23 num -> num.replaceFirst("^+?48", ""),
24 identity()
25 )
26 )
27 .groupBy(tuple -> tuple._1().substring(0, 2))
28 .bimap(
29 key -> areas.get(key).getOrElse("Nieznany"),
30 value -> value.map(Tuple2::_2)
31 );
32
33 System.out.println(map);
34 }
35
36 }
131. Processing!
• filter out numbers that are too
short
• we need to have original number
and still process it - Tuples!
• strip international code from
processed tuple entry, don't do
anything to original
• group tuples by area code
obtained from processed tuple
entry
1 package com.example;
2
3 import javaslang.Tuple;
4 import javaslang.Tuple2;
5 import javaslang.collection.HashMap;
6 import javaslang.collection.HashSet;
7 import javaslang.collection.Map;
8 import javaslang.collection.Set;
9 import org.junit.Test;
10
11 import static java.util.function.Function.identity;
12 import static com.example.PhoneNumberData.*;
13
14 public class GroupNumbersTest {
15
16 @Test
17 public void processNumbers() {
18 Map<String, Set<String>> map = phoneNumbers
19 .filter(num -> num.length() >= 9)
20 .map(number -> Tuple.of(number, number))
21 .map(tuple ->
22 tuple.map(
23 num -> num.replaceFirst("^+?48", ""),
24 identity()
25 )
26 )
27 .groupBy(tuple -> tuple._1().substring(0, 2))
28 .bimap(
29 key -> areas.get(key).getOrElse("Nieznany"),
30 value -> value.map(Tuple2::_2)
31 );
32
33 System.out.println(map);
34 }
35
36 }
132. Processing!
• filter out numbers that are too
short
• we need to have original number
and still process it - Tuples!
• strip international code from
processed tuple entry, don't do
anything to original
• group tuples by area code
obtained from processed tuple
entry
1 package com.example;
2
3 import javaslang.Tuple;
4 import javaslang.Tuple2;
5 import javaslang.collection.HashMap;
6 import javaslang.collection.HashSet;
7 import javaslang.collection.Map;
8 import javaslang.collection.Set;
9 import org.junit.Test;
10
11 import static java.util.function.Function.identity;
12 import static com.example.PhoneNumberData.*;
13
14 public class GroupNumbersTest {
15
16 @Test
17 public void processNumbers() {
18 Map<String, Set<String>> map = phoneNumbers
19 .filter(num -> num.length() >= 9)
20 .map(number -> Tuple.of(number, number))
21 .map(tuple ->
22 tuple.map(
23 num -> num.replaceFirst("^+?48", ""),
24 identity()
25 )
26 )
27 .groupBy(tuple -> tuple._1().substring(0, 2))
28 .bimap(
29 key -> areas.get(key).getOrElse("Nieznany"),
30 value -> value.map(Tuple2::_2)
31 );
32
33 System.out.println(map);
34 }
35
36 }
133. Processing!
• filter out numbers that are too
short
• we need to have original number
and still process it - Tuples!
• strip international code from
processed tuple entry, don't do
anything to original
• group tuples by area code
obtained from processed tuple
entry
• map keys and values to either
area name and set of original
phone numbers
1 package com.example;
2
3 import javaslang.Tuple;
4 import javaslang.Tuple2;
5 import javaslang.collection.HashMap;
6 import javaslang.collection.HashSet;
7 import javaslang.collection.Map;
8 import javaslang.collection.Set;
9 import org.junit.Test;
10
11 import static java.util.function.Function.identity;
12 import static com.example.PhoneNumberData.*;
13
14 public class GroupNumbersTest {
15
16 @Test
17 public void processNumbers() {
18 Map<String, Set<String>> map = phoneNumbers
19 .filter(num -> num.length() >= 9)
20 .map(number -> Tuple.of(number, number))
21 .map(tuple ->
22 tuple.map(
23 num -> num.replaceFirst("^+?48", ""),
24 identity()
25 )
26 )
27 .groupBy(tuple -> tuple._1().substring(0, 2))
28 .bimap(
29 key -> areas.get(key).getOrElse("Nieznany"),
30 value -> value.map(Tuple2::_2)
31 );
32
33 System.out.println(map);
34 }
35
36 }
153. Functional Programming in
Java: not needed, right?
• Microservices need linear scalability on instance level,
which is hard to achieve using thread-per-request
model, asynchronous frameworks offer this
out-of-the-box
154. Functional Programming in
Java: not needed, right?
• Microservices need linear scalability on instance level,
which is hard to achieve using thread-per-request
model, asynchronous frameworks offer this
out-of-the-box
• Reactive, event-driven programming model has already
been included into latest Java version - reactive streams
interfaces made it to JDK9!
155. Also - Spring 5:
1 @GetMapping("/accounts/{id}/alerts")
2 public Flux<Alert> getAccountAlerts(@PathVariable Long id) {
3
4 return this.repository.getAccount(id)
5 .flatMap(account ->
6 this.webClient
7 .perform(get("/alerts/{key}", account.getKey()))
8 .extract(bodyStream(Alert.class))
9 );
10 }