Java Stream API : What is a Short Circuiting Stateful Intermediate Operation ? | Java 8 sort() | EP3
Selenium Express Selenium Express
107K subscribers
5,663 views
226

 Published On Jul 19, 2024

In this video we will learn about, What is a Short Circuiting Stateful Intermediate Operation in Java 8 Stream API ? We will explore the difference between stateful and stateless intermediate operations. We will look into short circuiting methods like limit(), takeWhile() and, we will debug the same.

In our stream api tutorials so far, we will understood about one of the Java 8's new features called Stream API.

The java stream api introduced in java 8, changed the way we write and read java code.

Java Stream API is an absolute beast when it comes to data processing as it enables the scope of processing the data in a declarative approach. It opens a way to fusion multiple methods by doing method chaining and gives us a way to write lambda expressions as most of the Java streams methods accepts lambda as a parameter. Thus we can reduce our traditional loops/condition checks / conversion code and significantly improve our code readability.

In this Java Stream api tutorial, We will discuss about the followings :
1. Stream API in Java 8
2. sort() in Java Stream
3. Stateful Operations : Order of Execution
4. Stateful vs Stateless - Java doc
5. limit() as a short circuiting stateful intermediate operation
6. skip() in java 8
7. distinct() in java 8
8. takeWhile() in java 8

TIMESTAMP
------------------------
00:00 - Stream API in Java 8 recap
04:35 - sorting in java
09:56 - What is a stateful operation in Java 8 Stream ?
20:25 - How Java 8 Sorted works under the hood ?
24:53 - infinite Stream - The Iterate() method
34:27 - A stream api interview question
40:39 - Stream API : bringing in takeWhile()
44:25 - What is a short circuiting operation in Stream API
51:31 - skip() in Java 8 Stream
53:32 - distinct() in Java 8 Stream API
54:57 - A thought on takeWhile()
----------
The Story So far :

As we have discussed, The java Stream api is not a data structure but it is used to process a collection of objects.

There are two kind of operations used in Stream API.

One type of operation is called Intermediate operation. Intermediate operations are used to perform operations like filtration of elements , element transformation to another type, limiting data in a stream pipeline etc. After performing any intermediate operation over a stream, we again get a Stream Object back.

One point to note here is , the Streams in java are lazy. They do nothing until a terminal operation invoked over them. So terminal operations are going to trigger or start a stream , helps the stream to start processing the data in the pipeline.

Methods like filter(),map(),limit() are called intermediate operations, where as the methods like forEach(),collect(),count() are called terminal operations.

Another key point to remember is , any intermediate operations that we perform over a stream doesn't modify the source stream object. So streams in java are immutable and any intermediate operations performed over a stream object returns a new stream.

Here one thing to keep in mind is , Once we done consuming data from a stream, the stream pipeline considered as consumed and wont be reusable again.
--------------
As per the java doc the intermediate operations are further divided into two things. One thing is called Stateful operation and another is stateless intermediate functions.

One more thing is few operations are short circuiting in nature.

In this java 8 stream api foundation tutorial, we will discuss everything about it in detail.

For more free/paid courses visit
https://www.seleniumexpress.com

LINKS AND FREE LEARNING RESOURCES
========
Watch my new mock interview series for java developers
   • Java interview questions and answers ...  

Watch my new Hello spring boot series
   • Spring Vs Spring Boot - Why Spring Bo...  

Watch Spring boot Hot topics
   • @Reposicotry Vs @Service | Spring Boo...  

spring core
   • Spring framework tutorial for beginne...  

spring mvc
   • Spring MVC course introduction || Und...  

spring mvc intermediate
   • [INTERMEDIATE] Spring MVC Course Prev...  

Spring JDBC
   • Spring JDBC Course Preview || Let’s t...  

spring live project
   • #1 Build and Deploy A Spring Project ...  

SPRING SECURITY COURSE[NEW]
   • Spring Security Course Preview | Lear...  

For more courses visit
https://www.seleniumexpress.com

Any time you are getting stuck with issues, Feel free to ask for support.
You can send mail to [email protected]

you can ping me on my Facebook page
  / seleniumexpress  

Make sure to join my private Facebook page (Ask me here)
“SeleniumExpress - Support"
  / 187000222361579  

you can ask for support in my website forum
https://www.seleniumexpress.com

Follow me on Insta
  / selenium_express  

show more

Share/Embed