Biniman Idugboe

Ranch Hand
+ Follow
since Jun 09, 2017
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 Biniman Idugboe

I am having unpleasant experience with Apache NetBeans IDE 11.0.  Every time I try to launch the IDE, it goes "Transferring Maven repository index: Central Repository"  The transfer can take more than an hour and use up more than 1.0GB of data.  Every time I try to run a piece of code, there is always something downloading as shown in the image insert below.  What is more annoying?  After all the downloads, the build exercise still fails because of missing dependencies.  I am wondering whether anybody else is having a similar experience.

1 week ago

If an interface provides a default implementation for a method, implementations in classes always take precedence. That's why in an interface, you can't give default implementations for methods that are also declared in Object: their implementation would always be overridden by the implementation given by Object, and therefore useless.

Thank you! That peels off a layer of mystery.
3 weeks ago
Apology for submitting the same response twice.  I was having internet connectivity issues.
Okay, may be I do not truly understand the contextual meaning of "implements".  I was of the understanding that when a class implements an interface, all the methods and fields of the interface are transferred to the class.  Then, the class must add code body to the abstract methods and if need be, override appropriate methods already having code bodies.  In this particular case where  class XXX implements Comparator, XXX class inherits the Object class.  So, XXX class has the equals() method already having a code body.  Now, there is the equals( ) method inherited from Object class and there is equals( ) method transferred from Comparator interface.  Java chooses to discard the equals() method coming from the Comparator.  I see this as Java leaning to a preferred method; prioritizing.  Otherwise, it could just as well have chosen the equals( ) method coming from the Comparator interface.
Permit me to ask.  What happens when a class implements an interface?
3 weeks ago

Lambda expressions create an object that inherits from the Object class, so it also inherits the implementations of the methods declared in Object.

The Object class does not have any abstract method. I have not read the documentation in much detail, but I do not know whether the Comparator interface extends the Object class.  I was of the opinion that the equals( ) method in Object class is different from the equals( ) method in Comparator interface. Looks like they are not different after all.  Is it the case that the equals( ) method in Object class takes precedence over the equals( ) method is Comparator interface?

Functional interfaces are allowed to redeclare the methods that were already declared in Object and the effect will be the same as if they weren't declared at all.

If that is so, why does the equals( ) method in Comparator not count when implementing the Comparator as in the above?

You'll notice when you read the JavaDoc that Comparator.equals() has a more specific description than Object.equals().

boolean         equals(Object obj)
Indicates whether some other object is "equal to" this one.

boolean         equals(Object obj)
Indicates whether some other object is "equal to" this comparator.
Is the equals( ) method in Comparator useless?
3 weeks ago
Yes, that is what the documentation says.  However, there two abstract methods in the Comparator interface.  The lambda expression only provides a body for the compare( ) method.  What about the equals( ) method? Can we implement an interface that has multiple abstract methods with a lambda expression? Are we allowed to provide a body for one of the multiple abstract methods and forget about the other abstract methods? A class (whether anonymous or not) that has any abstract method is an abstract class.  Can we have abstract instance?
3 weeks ago
Source of code snippets:
Java 8 in Action: Lambdas, streams, and functional-style programming
(Raoul-Gabriel Urma, Mario Fusco, and Alan Mycroft)
Page 57.

The anonymouse class can be replace with a lambda expression as in:

The Comaparator interface has two abstract methods and for this reason, the Comparator is not a functional interface.
1.  I thought that when an interface is implemented, all the abstract methods must be overriden. We are not suppose to pick and choose which abstract method to override.  In the above anonymous class, the equals() method was not overridden. Is it the case that the instance created from the anonymous class embeds the abstract equals() method; making the instance an abstract instance? Really, abstract instance?

2.  Again, I thought that a lambda expression is used to implement a functional interface and at the same time create an instance of the implementation.  This means a lambda expression cannot be used to implement a Comparator let alone create an instance of the implementation.  Besides, the right hand side of the lambda expression evaluates to an instance of a BiFunction<Apple, Apple, Integer>. How does a Bifunction become a Comparator?  
I assume the book is autoritative, but these things are kind of confusing.
3 weeks ago
Apology! When I say process line, I am referring to a factory process line, not a processor process.

It might be better to say you are completing the pipeline. Just as whenever I am trying to lead water around the house in copper pipelines, I am not going to turn the water on at the source until I am confident I have connected the other end. When you build a Sahara Pipeline to carry oil across the desert, you don't turn the oil supply on until you are sure the other end is connected correctly.

That makes it a whole lot easier to understand why a terminal operation is required before the pipeline can start to work.

JShell doesn't help by calling toString() on your Stream objects.

Not sure I understand this.  What is wrong with sortedStream.forEach(m -> System.out.println(m));?

...but it is only worth creating parallel Streams when there is a lot of work to be done. And those Streams are not called sequential.

I suppose parallelizing the stream logically partitions the stream into individual portions. Are you saying the individual portions are not ultimately processed sequentially? is a bit of confusing information JShell has given you.

I have been going around with the notion that using Notepad or something similar is the simplest way to start learning to write Java codes. But, I need jshell to run code snippets. To hear now that jshell could give confusing information, I am lost.

...Start small and simple.

Surely, I would love to, but I have not found a stream that is simple. All the streams I have encountered so far are derivatives of the same complicated Stream.
I appreciate your comments. They are very helpful to me.
1 month ago
Well, it appears the understanding of the concept of stream is for people with special capability. I certainly do not belong in that group.  Nevertheless, I still have questions to ask about stream.
1.  I create a data source:

2.  I create a process line that hooks up to the data source and would allow data to enter the process line sequentially when the process starts.  In Java speak, I think I create a stream from the data source:

3.  I add a data processing station to the line.  That is, I add an intermediate operation to the stream:

What is different between IntPipeline$Head@2a2d45ba and  IntPipeline$9@3c0f93f1? Is the pipeline not one continuous pipeline?
4. So far, I just have a process line; nothing happening yet. I decide to add a viewing station where I can view the data as it passes by.

All I still have is just a process line.  There is nothing to view because the process has not started yet.
5.  I terminate the process line on a processing station that starts the process (that tells IntPipeline$Head@2a2d45ba to start allowing data into the stream).

While the above interpretation may very well be a punishable offence in Java land, please, forgive me. With it, I am relieved of a lot of things complicated.
I reckon I may have millions of data to process.  I want to have parallel streams (with my process line analogy, I am little bit more comfortable talking about stream).
6.  I create a parallel stream from the original data source:

My computer has eight processors and the number of data to process is five, that is three processors more than the number of data to process. I am assuming that five sequential streams have been created.  Is that correct?
7.  For the sake of it, I decided to add a sorted() operation to the stream:

I see sortedStream ==>$OfInt@3632be31.  Is this also a pipeline?
8. I terminate the stream with a forEach() operation:

Again, I am assuming that I ended up with five parallel pipelines as follows:
Processor1:  parallelStream.sorted().forEach(m -> System.out.println(m));
Processor2:  parallelStream.sorted().forEach(m -> System.out.println(m));
Processor3:  parallelStream.sorted().forEach(m -> System.out.println(m));
Processor4:  parallelStream.sorted().forEach(m -> System.out.println(m));
Processor5:  parallelStream.sorted().forEach(m -> System.out.println(m));
Each pipeline has a single data to process and the result of sorting a single data is the single data itself. Thus, the final data printed to the console may not be sorted because the order will depend on the sequence in which the processors finished processing their pipelines.
Is that correct?
1 month ago
Is the term stream a mask of something far more complicated going on behind the scene?  For example, where did ReferencePipeline.filter ( come from?
1 month ago

Streams do not “have” elements; they process them. produces a stream. What process is the stream  performing?

Also, Streams implement lazy execution; an element is only taken by the first Stream when the terminal operation requires it.

In the following, how come the sourceStream has already been operated upon even when there is no terminal operation?
1 month ago

The above pipeline does not have a terminal operation. The map() method has produced a stream named resultOfMapOperation.  Pleases, bear with me, I would like to know the elements that are in the resultOfMapOperation at this stage of the pipeline.
1 month ago
Again I am embarrassed to say that the concept of consumer passed to the tryAdvance() method is eluding me.

1.  The terminal operation is responsible for producing the ultimate result of the pipeline operations.
2.  The terminal operation does not produce a stream, does not produce a spliterator.
3.  The terminal operation creates a consumer, calls the tryAdvance() method of the spliterator created by the preceding operation and passes the consumer to it.
4.  The consumer performs action on the element brought forward by the tryAdvance() method.
In fact, I cannot continue to enumerate the steps because the concept starts to blur from this point forward. An intermediate operation is supposed to do something to the element, still the consumer does yet another thing to the element.  I just don't get it.
2 months ago