Blog Archives

09: Java FP – CompletableFuture Error Handling

handle(…) returns a result or an exception A dummy exception is thrown from “f” to demonstrate an exceptional scenario. The “java.util.concurrent.ExecutionException” potentially thrown by f.get(), g.get(), and h.get() is a checked exception. Hence catching it and re throwing as an unchecked (i.e. RuntimeException) exception.

Output “Reached here…” is printed…...

Members Only Content

This content is for the members with any one of the following paid subscriptions:

30-Day-Java-JEE-Career-Companion, 90-Day-Java-JEE-Career-Companion, 180-Day-Java-JEE-Career-Companion, 365-Day-Java-JEE-Career-Companion and 2-Year-Java-JEE-Career-Companion Log In | Register | Try free FAQs | Home
Posted in member-paid, OOP vs FP Coding Java 8

08: CompletableFuture monadic chaining with examples – part 2

This extends Java FP – CompletableFuture monadic chaining with examples – part 1. f and g are processed asynchronously, and then combined A “Supplier” returns a result by taking nothing as an argument.

“CompletableFuture.supplyAsync” executes a “Supplier” without blocking. This means executes it asynchronously. By using the Async suffix,…...

Members Only Content

This content is for the members with any one of the following paid subscriptions:

30-Day-Java-JEE-Career-Companion, 90-Day-Java-JEE-Career-Companion, 180-Day-Java-JEE-Career-Companion, 365-Day-Java-JEE-Career-Companion and 2-Year-Java-JEE-Career-Companion Log In | Register | Try free FAQs | Home
Posted in member-paid, Multithreading, OOP vs FP Coding Java 8

07: Java FP – CompletableFuture monadic chaining with examples – part 1

This extends Future Vs. CompletableFuture interview Q&As with Java 8 functional programming (i.e. FP). Q1. Why was CompletableFuture introduced in Java 8 when you already had the Future interface? A1. The CompletableFuture implements both CompletionStage<T> and Future<T> interfaces. Hence it provides the functionality of the Future interface in terms of…...

Members Only Content

This content is for the members with any one of the following paid subscriptions:

30-Day-Java-JEE-Career-Companion, 90-Day-Java-JEE-Career-Companion, 180-Day-Java-JEE-Career-Companion, 365-Day-Java-JEE-Career-Companion and 2-Year-Java-JEE-Career-Companion Log In | Register | Try free FAQs | Home
Posted in member-paid, Multithreading, OOP vs FP Coding Java 8

06: Java FP – handling checked exceptions

FP error handling – checked exceptions The code below breaks the flow of execution as the input “ABC” throws a checked exception – “NumberFormatException”.

Outputs:

What if you want to just mark all the inputs that throw a “NumberFormatException” as -1, and move on? FP checked exceptions –…...

Members Only Content

This content is for the members with any one of the following paid subscriptions:

30-Day-Java-JEE-Career-Companion, 90-Day-Java-JEE-Career-Companion, 180-Day-Java-JEE-Career-Companion, 365-Day-Java-JEE-Career-Companion and 2-Year-Java-JEE-Career-Companion Log In | Register | Try free FAQs | Home
Posted in member-paid, OOP vs FP Coding Java 8

05: Java OOP vs FP – Handling unchecked exceptions

int result = input / divideBy will throw an unchecked exception if divideBy = 0. OOP error handling by throwing exceptions In OOP errors are handled by throwing & catching exceptions. Here is a very simple OOP example. Step 1: Define an interface.

Step 2: Define an implementation. The…...

Members Only Content

This content is for the members with any one of the following paid subscriptions:

30-Day-Java-JEE-Career-Companion, 90-Day-Java-JEE-Career-Companion, 180-Day-Java-JEE-Career-Companion, 365-Day-Java-JEE-Career-Companion and 2-Year-Java-JEE-Career-Companion Log In | Register | Try free FAQs | Home
Posted in member-paid, OOP vs FP Coding Java 8

04: Java OOP vs FP – Builder Pattern

Current Balance = Initial Amounts + Credits – Debits OOP approach using the builder design pattern Creating a constructor to take three BigDecimal values is NOT only readable, but also prone to errors as you can inadvertently supply the debit value instead of the credit value, and so on. Hence,…...

Members Only Content

This content is for the members with any one of the following paid subscriptions:

30-Day-Java-JEE-Career-Companion, 90-Day-Java-JEE-Career-Companion, 180-Day-Java-JEE-Career-Companion, 365-Day-Java-JEE-Career-Companion and 2-Year-Java-JEE-Career-Companion Log In | Register | Try free FAQs | Home
Posted in member-paid, OOP vs FP Coding Java 8

03: Java FP composing functions example – calculate discount

FP – calculate the invoice price Invoice Price = (markedPrice * (100 – discountRate)/100) + deliveryCharge Example

“f.andThen(g)” is the composition of functions. This can be described as g(f()) where f() is 270.0 (i.e. 300.00 * (100 – 10)/100), and g(f()) is 270.00 + 50.00 = 320.00; DiscountCalaculator that…...

Members Only Content

This content is for the members with any one of the following paid subscriptions:

30-Day-Java-JEE-Career-Companion, 90-Day-Java-JEE-Career-Companion, 180-Day-Java-JEE-Career-Companion, 365-Day-Java-JEE-Career-Companion and 2-Year-Java-JEE-Career-Companion Log In | Register | Try free FAQs | Home
Posted in member-paid, OOP vs FP Coding Java 8

04b: 6 Java FP partial functions & currying interview Q&As

Q1. The “java.util.function” package only have “Function<T,R&rt;“, which takes an input and returns an output, and “BiFunction<T,U,R>“, which takes two inputs and returns an output. How would you then use a function with 3 or more input arguments? A1. If you are using three arguments then for example say 3…...

Members Only Content

This content is for the members with any one of the following paid subscriptions:

30-Day-Java-JEE-Career-Companion, 90-Day-Java-JEE-Career-Companion, 180-Day-Java-JEE-Career-Companion, 365-Day-Java-JEE-Career-Companion and 2-Year-Java-JEE-Career-Companion Log In | Register | Try free FAQs | Home
Posted in FP, member-paid
Page 1 of 1812345678910...Last »

800+ Interview Q&As – ♥ Free | ♦ FAQs

open all | close all

Pressed for time? 200+ Quick Prep

open all | close all

16 Technical Key Areas to be a top-notch

open all | close all

100+ Java Tutorials – Step by step

open all | close all

100+ Java Coding Exercises

open all | close all

How good are your

open all | close all