Blog Archives

01: ♦ 19 Java 8 Functional Programming (i.e. FP) interview Q&As

Good handle on Java OOP concepts and FP concepts are very important NOT only from writing quality code perspective, but also from job interviews perspective to be able to do well in written tests & technical interviews. Q1. Can you explain your understanding of Functional Programming (FP)? A1. In a…...

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 FAQs OOP & FP, FP, Java 8, member-paid

01: OOP vs FP with Java example – placing a trade

A Trade goes through 3 state changes – placed, filled, and settled. Let’s solve this simple problem using both OOP & FP approaches. Place –> Fill –> Settle OOP approach by mutating the state State changes are maintained via a variable named “status“, which is mutable. Here is the “OrderService.java”,

Read more ›

Posted in OOP vs FP Coding Java 8

02: ♦ Java 8 Streams, lambdas, intermediate vs terminal ops, and lazy loading with simple examples

A stream is an infinite sequence of consumable elements (i.e a data structure) for the consumption of an operation or iteration. Any Collection<T> can be exposed as a stream. It looks complex, but once you get it, it is very simple. The operations you perform on a stream can either…...

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 Collection and Data structures, FP, Java 8, Java 8 Tutorial, member-paid
Tags:

02: OOP vs FP with Java example – Conversion strategy pattern

Java code to convert given input values from KM to Meter, Meter to Centimetres, etc. OOP approach using the strategy design pattern Step 1: Define an interface. Step 2: Define a generic “MyMetricConverter” that implements the “Converter”. Step 3: Define different strategy classes that return different conversion rates. KM to…...

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: ♦ Functional interfaces and Lambda expressions Q&A

The functional interfaces and Lambda expressions are going to make your code concise when coding with Java 8. These are the most awaited features among Java developers. If you understand the following examples, you will know what a lambda expression is & why functional interfaces were introduced in Java 8 to…...

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, Java 8, member-paid

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 applies…...

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: ♦♥ 5 FAQs on transforming your thinking from OOP to FP

One needs to get used to the transformation from imperative programming to functional programming. You like it or not, you will be using functional programming in Java, and interviewers are going to quiz you on functional programming. Fortunately, Java is not a fully functional programming language, and hence one does

Read more ›

Posted in FAQs OOP & FP, FP, Java 8
Tags: ,

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

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

05: ♥ 7 Java FP (lambda expressions) real life examples in wrangling normal & big data

This post extends Transforming your thinking from OOP to FP. In Big-data, functional programming is prevalent when working with data sets. For example, writing a Spark job to work with RDDs (Resilient Distributed Data sets). In Imperative (E.g. OOP, procedural programming, etc) programming you can say where you are assigning

Read more ›

Posted in FP, 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 implementation…...

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

06: 5 Java FP interview Q&As on category theory & monoids

Q01. What is a category theory from a functional programming language perspective? A01. The category theory is all about abstracting complexities in computations. OO is good for abstracting over Data, and FP is good for abstracting over behavior. Composition “f” and “g” are functions, and “A” and “B” are types.

Read more ›

Posted in FP

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 – wrapped method…...

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

07: 4 Java FP Functors Interview Q&As

Q01. What do you understand by the terms functors, monads, and applicatives ? A01. Functors, Monads, and Applicatives are concepts or patterns that abstract complexities in computations, and are NOT interfaces or classes. You can think of them as container type classes like List<T>, Option<T>, Futures<T>, MyContainer<T>, etc that fulfil…...

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

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
Page 1 of 212

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

open all | close all

100+ Java Tutorials – Step by step

open all | close all

How good are your

open all | close all