Venkat is phenomenal teacher. Of all Java speakers on UA-cam, he is my favourite. I've been watching his talks since about 2015. In many ways his style of teaching is even better than most online courses.
Saw a comment in another of Venkat's talks..."the best stand-up comedian". he absolutely is...amazing how effortlessly he walks over such complex stuff. the mutant jaws...creating a new species with "mapFlattening" vs "flatMap" - man!!! hilarious.
I'm now a fan... I just started following him and a nice way to update my skills too. Functional programming is in-line with clean coding as well. Thanks so much for sharing.. Hope to have more of your videos.. Hope there are also updated videos of him.. :)
One minor correction, the term "idempotent function" means something different - it means applying the function on a result it gives yields again the same result. Sorting is a good example - if you have a list and you sort it, it can change, but if you sort it again, it stays the same.
Here is how to get the oldest Person in every City: (value = Optional) Map oldestPersonByCity = Person.getPersonList().stream() .collect( groupingBy(Person::getCity, maxBy(comparing(Person::getAge))));
This is how get the name of the oldest Person with one statement: No NEED for collect(), no need for maxBy(), no need for collectingAndThen(). String nameOfOldestPerson = Person.getPersonList().stream() .max(Comparator.comparing(Person::getAge)) .map(Person::getName).orElse("Oldest not found"); Sometimes Venkat exaggerate a little bit :-)
Man I learned to love streams, but I know how it felt like to see them when I haven't learned about them yet.. I wonder how my supervisor will feel like when he sees my thesis full of streams.
1. Java and Functional Programming 0:00 a. Lazy evaluation vs eager evaluation 2. Common operations: filter 2:00, map 5:50, reduce 6:20
3. Functions should be pure 4. Avoid shared mutability 5. A little example …gone wrong 6. The right way, - delegate, be declarative, 7. collect is a reduce operation 8. Collectors utility class 9. toList, toSet 30:00 10. Should we not honor immutability? leave it to the APIs
In the last 1 hour of this talk, I feel that I was looking at the complex or messy part of such functional programming. So, as Venkat says 'Once you get used to it...', it reminded me his earlier statement about the difference between simple & familiar. So after doing such functional programming, it becomes familiar & not simple...I think. I think one needs to have very fine balance between usage of Functional & Imperative programming to keep things simple & not just familiar. And if such stuffing goes on in Functional programming, then I fear that another Venkat will be giving lectures to use Imperative programming to get rid of complexities in Functional programing. Too much purity or Immutability, also sucks while doing programming. Please let me know if you have other thoughts to correct me.
I agree. The groupingBy example with the nested Collectors is barely understandable for people familiar with the Streams API, let alone someone that's used to imperative style. Honestly in that case the imperative code is easier to work with, at least you can see what it's doing line-by-line/per-instruction explicitly without having to figure out the method signatures from documentation. The functional code is less understandable in that case because it hides the signatures and assumes you know the API and its semantics, whereas imperative code makes it clear what the interactions are. Oh and good luck debugging lambdas in streams / collectors. Admittedly however one can temporarily convert them to AICs using the IDE and convert them back after.
Venkat made it indeed too complex, because he just loosed the orientation in the stream API: if you want to get the name of the oldest Person: String nameOfOldestPerson = Person.getPersonList().stream() .max(Comparator.comparing(Person::getAge)) .map(Person::getName).orElse("Oldest not found"); It is a matter of training to become familiar with the Stream API and in that case you will be able to pick the easiest syntax to get your job done.
It is excellent. No doubt about that. But, how is he able to print directly from groupingBy / partioningBy without iterating as (K,V) it returns map..Any pointers, please?
Java can print collections directly as they all have a toString method. However if you have a collection of Primitives, then it will print the hashcode insted and in that case u need to iterate manually.
I hear Venkat & really like his talks..but...but...The kind of Lazy Evaluation, he talks I see it as how the creators of such APIs want & write. The APIs which are marked as Lazy, are being termed as intermediate functions as he told himself & eager functions are Terminal ones as he told that also. So, intermediate functions are not supposed to be executed till Terminal function is called i.e. till this point the intermediate functions are being stacked only. And I say this as purely 'Postponing the actions' & it is smart way also, but not a lazy one. For example - When you need to purchase some item from the market & you don't need that right now, then you keep noting such items in a list. And when you see that you have sufficient number of items to buy from the market then you get out to buy them, so if you think such behavior as 'Lazy' one then can say it, else for me it is a smart decision to postpone certain actions till the right moment comes. But a lazy person, will be buying these items & may be not all or may be at his/her speed or may be not at the right time. So what is 'Lazy' in the definition given by Venkat, when these functions are not allowed to execute. These functions would have been lazy when they are allowed to execute immediately but still will execute only when they like. It is like, someone tie you with rope & then tag you saying that you are lazy & don't do any work.
Lazy loading is a term used for deferred initialization/run. It is used in other languages, dbs and scripts too. It is not a new term coined just for streams here. It does sound a bit funny the way you put it though.
I was trying reduce Operation and i saw when i turned it to parallel stream it started giving error so i believe we cannot use parallel streams for reduce for the exampe mentioned at ua-cam.com/video/pGroX3gmeP8/v-deo.html .
What is the fastest Java implementation of Collections used these days? Eclipse (former Goldman Sachs) collections, Guava collections? Any other famous implementation?
tl,dr: imo, one should not strive to find the fastest collection implementation library if performance is not your direct job. I believe every implementation you mentioned is fast enough. The fastest one depends on hardware, running OS, implementation of JVM, kind of input data and Collections implementation. This basically means that if you want to see a real impact of having the fastest collection in your particular case, you need to write your code using interfaces and make an experiment for exactly your case: your hardware, your os, your JVM, your input data, and test several collection implementations. Only this way you can be sure that you've chosen the fastest (for your particular case). Disclaimer: I had a subject in a university when I was given a task to implement several searching algorithms for finding a substring in text. Back in those days, I was inexperienced just like my friends. Our instructor was a deeply theoretical man who decided to check our code by running performance tests. Based on benchmarks he wanted to check that our code was implemented correctly. We didn't believe our eyes when the same exact code showed completely different results on different machines. Moreover, sometimes, the same algorithm showed completely different results launched several times in a row. Sadly, the instructor didn't believe us and we were forced to fake the results by adding hackish "Thread.sleeps" just to pass the exam. Only later I had a class about computer architecture and realized what was going on. I finished my studies 5 years ago.
Totally agree. And not to forget the randomness in the collection. Some algorithms are great when there some orderliness in the elements (even if not completely ordered) and some work better in scenarios where randomness is more.
The lovely Venkat does not make the difference between max() and maxBy(). The example with maxBy() is not good at all. You can do the same with max(): people.stream().max(comparator) and the rest of the statement is not good programming at all. It seams that Venkat is trying to make an example with maxBy by any means. After a goggle search, it seams that the most people do not know good use cases for maxBy() and in almost all examples it was clear, that it is possible to use max(comparator) instead of collect(maxBy()) with surely les verbose code.
Venkat is phenomenal teacher. Of all Java speakers on UA-cam, he is my favourite. I've been watching his talks since about 2015. In many ways his style of teaching is even better than most online courses.
Totally agree!
Don’t forget about his recent arrest, for (I believe so don’t quote me) having naughty child pictures.
@@tibettenballs4962 Where did you hear about this??
Everybody likes Venkat
Yeah but one person not ;)
Oracle should add an honorary Yeeinteger class for Venkat.
Saw a comment in another of Venkat's talks..."the best stand-up comedian". he absolutely is...amazing how effortlessly he walks over such complex stuff.
the mutant jaws...creating a new species with "mapFlattening" vs "flatMap" - man!!! hilarious.
"Haskel feels like Cathedral and Java is like Bazzar" :) 17:00
"It works" 21:45
51:42 motivation of groupingBy
51:56 imperative way of grouping - 52:11 question to resolve
57:00 groupingBy
I'm now a fan... I just started following him and a nice way to update my skills too. Functional programming is in-line with clean coding as well. Thanks so much for sharing.. Hope to have more of your videos.. Hope there are also updated videos of him.. :)
One word for you, "Eloquent". Thank you Sir.
Venkat - YOU ARE THE BEST!!!
The golden conference everybody need to watch.
Terrific session. Venkat is master
This guy is awesome
My favorite guy, best thing i learn from him👌
This was really cool
A true Guru.
Goosebumps & speechless
what a legend Venkat is !
From 🇳🇵?
@@ganga5809 yes !
Excellent explanation of stream collectors
Very fun when he talk about flat map. Thank sir
Awesome talk Venkat.
My code hero!!!
One minor correction, the term "idempotent function" means something different - it means applying the function on a result it gives yields again the same result. Sorting is a good example - if you have a list and you sort it, it can change, but if you sort it again, it stays the same.
Thanks for clarification. I was confused when Venkat said that about idempotent function, as I remember the definition being exactly as you described.
mapFlatten to flatMap reasoning was hilarious :D
Here is how to get the oldest Person in every City: (value = Optional)
Map oldestPersonByCity = Person.getPersonList().stream()
.collect( groupingBy(Person::getCity,
maxBy(comparing(Person::getAge))));
Long live Venkat
Fantastic.
58:35 CameraMan is also lazy like Java Streams :)
Sir you are just awesome
Venkat is THE master
This is how get the name of the oldest Person with one statement:
No NEED for collect(), no need for maxBy(), no need for collectingAndThen().
String nameOfOldestPerson = Person.getPersonList().stream()
.max(Comparator.comparing(Person::getAge))
.map(Person::getName).orElse("Oldest not found");
Sometimes Venkat exaggerate a little bit :-)
Man I learned to love streams, but I know how it felt like to see them when I haven't learned about them yet.. I wonder how my supervisor will feel like when he sees my thesis full of streams.
1. Java and Functional Programming 0:00
a. Lazy evaluation vs eager evaluation
2. Common operations: filter 2:00, map 5:50, reduce 6:20
3. Functions should be pure
4. Avoid shared mutability
5. A little example
…gone wrong
6. The right way, - delegate, be declarative,
7. collect is a reduce operation
8. Collectors utility class
9. toList, toSet 30:00
10. Should we not honor immutability?
leave it to the APIs
In the last 1 hour of this talk, I feel that I was looking at the complex or messy part of such functional programming.
So, as Venkat says 'Once you get used to it...', it reminded me his earlier statement about the difference between simple & familiar.
So after doing such functional programming, it becomes familiar & not simple...I think.
I think one needs to have very fine balance between usage of Functional & Imperative programming to keep things simple & not just familiar.
And if such stuffing goes on in Functional programming, then I fear that another Venkat will be giving lectures to use Imperative programming to get rid of complexities in Functional programing.
Too much purity or Immutability, also sucks while doing programming. Please let me know if you have other thoughts to correct me.
I agree. The groupingBy example with the nested Collectors is barely understandable for people familiar with the Streams API, let alone someone that's used to imperative style. Honestly in that case the imperative code is easier to work with, at least you can see what it's doing line-by-line/per-instruction explicitly without having to figure out the method signatures from documentation. The functional code is less understandable in that case because it hides the signatures and assumes you know the API and its semantics, whereas imperative code makes it clear what the interactions are. Oh and good luck debugging lambdas in streams / collectors. Admittedly however one can temporarily convert them to AICs using the IDE and convert them back after.
Venkat made it indeed too complex, because he just loosed the orientation in the stream API:
if you want to get the name of the oldest Person:
String nameOfOldestPerson = Person.getPersonList().stream()
.max(Comparator.comparing(Person::getAge))
.map(Person::getName).orElse("Oldest not found");
It is a matter of training to become familiar with the Stream API and in that case you will be able to pick the easiest syntax to get your job done.
@1:26:47
Java becoming Lisp
It is excellent. No doubt about that. But, how is he able to print directly from groupingBy / partioningBy without iterating as (K,V) it returns map..Any pointers, please?
Map has toString I think which works for wrappers or strings (I'm away from keyboard so not definite)
Java can print collections directly as they all have a toString method. However if you have a collection of Primitives, then it will print the hashcode insted and in that case u need to iterate manually.
I hear Venkat & really like his talks..but...but...The kind of Lazy Evaluation, he talks I see it as how the creators of such APIs want & write.
The APIs which are marked as Lazy, are being termed as intermediate functions as he told himself & eager functions are Terminal ones as he told that also. So, intermediate functions are not supposed to be executed till Terminal function is called i.e. till this point the intermediate functions are being stacked only. And I say this as purely 'Postponing the actions' & it is smart way also, but not a lazy one.
For example - When you need to purchase some item from the market & you don't need that right now, then you keep noting such items in a list. And when you see that you have sufficient number of items to buy from the market then you get out to buy them, so if you think such behavior as 'Lazy' one then can say it, else for me it is a smart decision to postpone certain actions till the right moment comes.
But a lazy person, will be buying these items & may be not all or may be at his/her speed or may be not at the right time.
So what is 'Lazy' in the definition given by Venkat, when these functions are not allowed to execute. These functions would have been lazy when they are allowed to execute immediately but still will execute only when they like.
It is like, someone tie you with rope & then tag you saying that you are lazy & don't do any work.
Lazy loading is a term used for deferred initialization/run. It is used in other languages, dbs and scripts too. It is not a new term coined just for streams here. It does sound a bit funny the way you put it though.
How is teeing() different from reducing()?
Super sir
Great sir.. Can tell me what IDE you used??
As shown in this video, I think he is using 'TextMate'
You're right..
Is grouping by in java 8?
yes
I was trying reduce Operation and i saw when i turned it to parallel stream it started giving error so i believe we cannot use parallel streams for reduce for the exampe mentioned at ua-cam.com/video/pGroX3gmeP8/v-deo.html .
omg, how can he speak so much without pauses :)))))
"Brian is overloaded" ... lol xD 1:10:20
True statement Paul is missing 23:12. People really missing Apostle Paul and are lost.
2hrs 😱
What is the fastest Java implementation of Collections used these days? Eclipse (former Goldman Sachs) collections, Guava collections? Any other famous implementation?
tl,dr: imo, one should not strive to find the fastest collection implementation library if performance is not your direct job.
I believe every implementation you mentioned is fast enough. The fastest one depends on hardware, running OS, implementation of JVM, kind of input data and Collections implementation. This basically means that if you want to see a real impact of having the fastest collection in your particular case, you need to write your code using interfaces and make an experiment for exactly your case: your hardware, your os, your JVM, your input data, and test several collection implementations. Only this way you can be sure that you've chosen the fastest (for your particular case).
Disclaimer: I had a subject in a university when I was given a task to implement several searching algorithms for finding a substring in text. Back in those days, I was inexperienced just like my friends. Our instructor was a deeply theoretical man who decided to check our code by running performance tests. Based on benchmarks he wanted to check that our code was implemented correctly. We didn't believe our eyes when the same exact code showed completely different results on different machines. Moreover, sometimes, the same algorithm showed completely different results launched several times in a row. Sadly, the instructor didn't believe us and we were forced to fake the results by adding hackish "Thread.sleeps" just to pass the exam. Only later I had a class about computer architecture and realized what was going on. I finished my studies 5 years ago.
Totally agree. And not to forget the randomness in the collection. Some algorithms are great when there some orderliness in the elements (even if not completely ordered) and some work better in scenarios where randomness is more.
The lovely Venkat does not make the difference between max() and maxBy().
The example with maxBy() is not good at all.
You can do the same with max():
people.stream().max(comparator) and the rest of the statement is not good programming at all.
It seams that Venkat is trying to make an example with maxBy by any means.
After a goggle search, it seams that the most people do not know good use cases for maxBy() and in almost all examples it was clear, that it is possible to use max(comparator) instead of collect(maxBy()) with surely les verbose code.
what are the features that are available in java 8?
This is the exhaustive list. www.oracle.com/java/technologies/javase/8-whats-new.html
Venkat is always enthusiastic, but IMO he could've easily skipped the first 40 minutes since it was a basic refresher on Streams.