Win a copy of Reactive Streams in Java: Concurrency with RxJava, Reactor, and Akka Streams this week in the Reactive Progamming forum!

Pablo Napoli

Ranch Hand
+ Follow
since Jun 28, 2019
Cows and Likes
Cows
Total received
2
In last 30 days
1
Total given
0
Likes
Total received
3
Received in last 30 days
2
Total given
23
Given in last 30 days
6
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Pablo Napoli

Great!!!. For people that never saw all this stuff before I think it's a bit hard, because it's like a change of paradigm, where you should focus more on what to do so rather than how it do it, but the book explains it very clear. Just I was stuck because I haven't had in mind the theory that I read at all.


Stream.generate( () -> "Thank you!").forEach(System.out::println);
Hi guys. I'm studying chapter 4 of ocp Study Guide by Jeanne and Scott and inspired in one exercise of page 201 I did another one to understand more how peek() works but I can't understand what's going on.

First of all I want to say that I noticed it by chance that if I add count() method at the end, the stream works as I expect, but my question is why?.



As you can see, now the output is [alex, anna, toby] but if I remove count() method, the result is [], so neither element is added to the list.

Thank you guys, I'm really breaking my head trying to solve it but still nothing.
Hi guys. This time I wanted to ask you about if currently developers are using most of the stuff from Java 8 like lambdas and streams. I was developing before (like almost 4 years ago) for a company and we didn't use even Java 8. So still I'm not developing again (I wanto to pass the ocp exam before) so I'd like to know for you all if in your projects you are using all of these "new" features.

For me it's being a bit hard to assimilate all of these things because it's like a change of paradigm but It's really interesting anyway.

Cheers!
Hi Ritchie. The book is OCP study guide of Jeanne and Scott and the picture is from the page 185.
1 week ago
Thanks guys for your replies so far. And Junilu Lacar about you said, I agree haha. But I wasn't sure really and these are the big differences between we can find in a book and on the other hand, in real life.

I will attach a pic about what the book says about it (OCP Study guide).

Said that, I'm very grateful to have these books with me, They're the best I found.

Anyway I'd like to read opinions where people say if either this feature is a good tool, o not, and why. Beause maybe it's a very good feaure that it's not implemented because the low level coding of programmers.

Let me say, in my opinion (I discovered it 2hs ago) It's not so intuitive. So to understand how it works you should look the class in deep. So I prefer code more readable that so technical.
1 week ago
Hi guys. My questions is about if developers today, in the everyday work, use Optional instead of null.
I ask it because I spend almost four years without working in a formal way as developer for a company and I don't know if people use this features of Java 8.

Before I was woking in average 2 years with Java 4, 6 and 7 and it's like there has been a lot of water under the bridge so far.

Thanks for your opinion!
1 week ago
Thanks Vilda, what you say at the end is also specially useful for the exam because that informaton is not in the book and they could ask about what's new in java 8 with hash structures. And now that I understand how it works it feels good

Maybe this is a silly question (I know this is even from oca topics) but I don't understand how does it possible that HashSet does not implement many methods from Set interface. I mean, at first sight, it's like it shouldn't compile.

These are HashSet's methods:

boolean add(E e)
void clear()
Object clone()
boolean contains(Object o)
boolean isEmpty()
Iterator<E> iterator()
boolean remove(Object o)
int size()

And all of this are Set's methods that are not implemente by HashSet:

boolean addAll(Collection<? extends E> c)  
boolean containsAll(Collection<?> c)
boolean equals(Object o)
int hashCode()
boolean removeAll(Collection<?> c)
boolean retainAll(Collection<?> c)
Object[] toArray()
<T> T[] toArray(T[] a)
1 week ago
I'd just like to add an answer to a question that I had before. So why does HashSet have no get() method: The answer is related to the hash code contract because we can have two different objects with the same hash (like two persons with different id but same hash code). In case of HashMap we have get method because the hash is not the object itself (or some of its properties) but a key that must be unique.

Thanks again and it's my grain of sand for others.
1 week ago
Thanks to everyone for your replies. This mornig I've started reading these posts and then I gave with a youtube video that was amazing explained this topic and it enforces everything you tell here.

The link is: https://www.youtube.com/watch?v=c3RVW3KGIIE
1 week ago
Hi Carey, thanks for your reply. This time my email didn't let me know about it. Excuse me but when you said "There ir no 'other'" what did you mean?. I mean, did you want to say that there are no two hash code values? Because tha's my biggest doubt.
1 week ago
Hi guys. Im studying Collections for my ocp exam and I was researching a bit more about some topics so I don't know if my conclusion about HashSet is right. May someone help me?

There are two kinds of hash values. One of the hash values is computed by the hashCode() method that is overriden from the object and is used to create the hash bucket if previously there were no such value in the set. The other hash value is the one computed based on the whole object and stored along with the object in an entry of the hash bucket.

So when searching for an element, the implementation of HashSet selects the appropriate hash bucket (based on the hash value from the hash method) and goes through its entries, comparing the hash value (from the object, not the one computed by hashCode()) stored in each entry with the hash value of the desired element.

I specially based on this in this link: https://www.geeksforgeeks.org/importance-hashcode-method-java/

Thanks!

1 week ago
Oh sorry. It's like an inner anonymous class and the method is not returning an int. I think I'm enough tired for today haha.
I say that the method returns an int value because the result of the lambda should be an int due to compareTo of String returns int. Although maybe there is something that I'm not being able to see. Anyway I'm gonna look into that folder.
Hi Piet, thanks for your reply . But I'm not sure about that method because that lambda is returning an int value while the comparing() method needs to return a Comparator object. Anyway do you know some way to find the implementation of this (or others) methods? Because in the API just I can find the related documentation.
Hi guys. Could someone help me with something? I don't understand how does compare() abstract method implement the behavior of comparing both of those objects by their names? (according to my example). For sure, this information is given by the object that implements Function, but what i mean is, where is the body of compare() method that extracts this from that  object?

I'm in the end of the chapter Generic an Collections from ocp study guide and i wrote the example bellow inspired in a code given by the book (page 149 OCP Study Guide - Jeanne and Scott).

I was looking the API documentation and I understood how comparing() works by receiving an implementation of the interface Function and returning a Comparator.
* https://docs.oracle.com/javase/8/docs/api/java/util/Comparator.html#compare-T-T-
* https://docs.oracle.com/javase/8/docs/api/java/util/function/Function.html

It's not easy for me to be clear in this point, for this I've done my own example to be able to visualize what I don't understand and in which point I stuck.



I think one way to understand it is looking the implementation of the interface Comparator to see the body of the comparing() static method but I don't know from where I can see it.

I really hope have been clear and thanks for read all of this text.