H Paul

Ranch Hand
+ Follow
since Jul 26, 2011
Merit badge: grant badges
For More
Cows and Likes
Total received
In last 30 days
Total given
Total received
Received in last 30 days
Total given
Given in last 30 days
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by H Paul

"Life, Liberty and the pursuit of Happiness"

is part of the US Constitution.

So is Immutability part of Functional Declaration?

And Immutability is part of the journal.
7 years ago
If it helps:
As a way of answering to Knute's question:
Check the database table definition (the columns) to see how they are defined.
Use Sql command line or console and do 1 INSERT statement to ensure it's inserted OK.

Then review Java side as questioned and helped by others.
A side note, step-wise learning: To have client/caller controls the parallel switch

I changed the original from:


7 years ago

1. Thanks for NPE and the Field keyword. +1 for your Certs.

2. (A side note: On a piece of paper, the point 1 and point 2 are the same,
I thought it would be magically for the compiler to see point 1 as the point 2 "implicitly Forward Declaration"
That way, I don't have to worry about the order when in the future I can add any function composition.)

My Back to the future:
8.3.3. Forward References During Field Initialization
7 years ago
Please see below 3 points. Why compiler allowed point 2 and not point 1?

Point 2 leads to NPE in point 3,
Why does the compiler allowed point 2 in the first place?
I expected the compiler to give a compilation error as in point 1.


Compilation error: As I expected:

Multiple markers at this line
- Cannot reference a field before it is
- Cannot reference a field before it is

2. But then I solved the compilation error by using FtNpeInterface.doubleFT

3. But then at rumtime, Caused by: java.lang.NullPointerException

At first, I did not see why.
But tracing down from sequential timing point of view, I see why NullPointerException occured.
7 years ago
1. A question based upon my below side notice:

Is the function interface java.util.function.Supplier the functionally way of creating new object?

2. Just a side notice:

While looking at above ways of creating an instance for a functional interface,
I encapsulate it into a factory as full code down below:

I see a readability? :-D

7 years ago
Within the context of this thread: Simple Use case: Get the list of Class name.

I see n ways of of doing 1 same things for above use case. I choosed following 3 for learning purpose:

1. Way 1: Using toList collector.
2. Way 2: Using Stephen's way assuming toList collector does not exist (for the sake of learning.)
3. Way 3: Using original mine: parallel reduce (version corrected after a read of Stephen's explanation regarding threading issues)

I refactored the 3 specific ways of doing 1 same things.
I found that the code looks like a Strategy Pattern in action functionally.
See below code: Way 1.

Now: Is it safe to say that we can refactor Strategy Pattern code "functionally"?

7 years ago
1. Back to the future: A question out of curiosity/notice (Not on performance nor readability nor on best practice)

From my  1st posted log and your explanation for sequential stream().reduce(...): the combiner is not called.

2. Why does reduce required one (combiner)? See above code.

I just passed in null, it complained NullPointerException.
at java.util.Objects.requireNonNull(Objects.java:203)
at java.util.stream.ReduceOps.makeRef(ReduceOps.java:71)
at java.util.stream.ReferencePipeline.reduce(ReferencePipeline.java:484)

So to make it happy? :-D. I passed a FT combiner which has no meaning: simple return null.
7 years ago
Yes, Master! will follow your lengthy explanation on 2 points: performance/efficiency and readability.

(My examples are just a way to explore how things work. Thanks.)
7 years ago
0) Thank-you, Ron McLeod.  

1) Following Stephen's lengthy explanation: to make stream().parallelStream().reduce(...) work
See below code.
2) Following Stephen's lengthy explanation: to make stream()..parallelStream().collect(Collectors.reducing(...)) work
This is new. See below code.

3) How Imperative follows Functional declarative footstep (How OP sees Stephen's Functional declarative )
Reply to Stephen's posted code.    See below.

1) Following Stephen's lengthy explanation: to make stream().parallelStream().reduce(...) work

2) Following Stephen's lengthy explanation: to make stream()..parallelStream().collect(Collectors.reducing(...)) work

3) How Imperative follows Functional declarative (How OP sees Stephen's Functional declarative )

7 years ago
Master Stephan,

1. I read what your 1st post of lengthy explanation and wanted to give you a cow for that.  (Unless you tell me how, master.      

What you explained confirmed my trouble shooting code posted to see what is happening.

2. I will have look at your next "coded" post.
7 years ago
To trouble shooting programmatically to explain output Logs that I posted earlier.

1) I use Thread information.
2) I use hashcode to see the List memory address. But this is NOT good.
3) I identityHashCode to see the List memory address. And this is GOOD! Help from


1 and 3 showed only 1 List passed around (one Sharedable List)

See below code: I use three classes.
See below Log: I have 2 set of logs:
a. In 1 set of log: Luckly, I saw 2 different threads: ForkJoinPool.commonPool-worker-1 and main
b. In 2nd set of log: I saw the correct identityHashCode of List memory address.

7 years ago
1. Basically, I rewrite using lambdas expression for stream().reduce() and parallelStream().reduce().

The output is the same as I posted earlier using non-lambdas expression.

a. stream().reduce() output correct result but combiner is not called
b. parallelStream().reduce() did NOT output correctly but combiner is called.

2. If possible, can some check if the code for identity, accumulator and combiner are correct?


7 years ago
1. Simple Use case: Get the list of Class name.

2. See below Code 1.

I want to learn/understand the mechanical of many things simultaneously.
I want to use Stream reduce method and not using lambda expression.
I used old way: Interface interface = new InterfaceImpl();

3. See below Log output with sequential .stream() and Log output with .parallelStream()

From log, I did not see the output from combiner BinaryOperator ft (with code using .stream())
By chance/accident not by design   , I switch from sequential stream() to parallelStream(),
I saw the output from combiner BinaryOperator ft.

But with sequential stream(), the end result is correct: Got a list of 2 class name.
With parallelStream, the end result is NOT correct: Got a list of 2 class name appeared twice (i.e a list of 4)

How to make sense of this? Can some one provide an explanation for stream().reduce vs parallelStream().reduce output?

7 years ago
If you can not troubleshoot the logic/flow of your App by just reading the code as Norm sugested,
then use the IDE debugger:
1. run QuizServer in debug mode
2. For example:  set a breakpoint at the line where NPE occured: line 121 in HandleValidation class.

See the exception you posted:

(A side note: I learned many things by using a debugger :-D)
7 years ago