WEBVTT

00:00.020 --> 00:00.530
Hi everyone.

00:00.530 --> 00:01.930
Welcome back to this tutorial.

00:01.940 --> 00:06.230
In this tutorial we will talk about supplier functional interface.

00:06.230 --> 00:08.300
Let's explore and code this one.

00:09.770 --> 00:16.070
First up, I'm going to search for the supplier functional interface and it is part of the Java.util

00:16.070 --> 00:17.480
dot function package.

00:17.730 --> 00:18.620
Select that.

00:19.680 --> 00:20.420
You take a look at it.

00:20.430 --> 00:25.740
It got introduced as part of Java eight and it has the functional interface annotation.

00:26.660 --> 00:33.050
This particular functional interface has just one method called get, and it returns something to the

00:33.050 --> 00:33.610
caller.

00:33.620 --> 00:36.890
So basically it is going to return a type to the caller.

00:37.070 --> 00:41.660
This one is exactly opposite to the consumer function interface.

00:42.020 --> 00:44.600
Compare this to search for consumer.

00:45.410 --> 00:49.190
The consumer is again part of the Java.util dot function package.

00:49.400 --> 00:50.970
We take a look at the consumer.

00:50.990 --> 00:54.740
It accepts an input and it doesn't return any output.

00:54.740 --> 01:00.950
But supplier doesn't take any input, but it returns an output.

01:01.460 --> 01:02.960
Let's go ahead and code this one.

01:07.270 --> 01:08.110
A player.

01:14.230 --> 01:15.760
I make this class executable?

01:15.970 --> 01:17.740
Add public static, void main.

01:18.100 --> 01:18.880
There you go.

01:19.300 --> 01:23.110
And then let's create an instance of a player.

01:23.680 --> 01:24.550
A player.

01:27.040 --> 01:30.370
So it is going to return a student object.

01:33.300 --> 01:36.630
As part of this one, I'm going to name this one as student sub player.

01:36.870 --> 01:41.040
So what it is going to do is it is going to return a student, Right.

01:41.520 --> 01:43.740
So it doesn't take any input.

01:44.850 --> 01:46.130
And then we're going to have it like this.

01:46.140 --> 01:51.710
It is going to return a student, new student.

01:51.930 --> 01:59.400
So if you take a look at the student, it accepts name, grade level GPA, gender and list of activities.

02:00.030 --> 02:03.190
So I'm going to open I'm going to expand this data package.

02:03.190 --> 02:05.140
It's going to have the student database.

02:05.410 --> 02:06.730
I'm going to copy one of these.

02:06.730 --> 02:07.420
And then.

02:08.640 --> 02:09.240
Senate under.

02:11.370 --> 02:12.090
Then statement.

02:13.300 --> 02:13.860
There you go.

02:13.870 --> 02:15.190
So this one.

02:16.410 --> 02:18.590
Is going to return a student.

02:19.990 --> 02:20.470
Right.

02:21.070 --> 02:22.000
Let's call this one.

02:22.000 --> 02:23.890
How do we invoke the supplier?

02:28.680 --> 02:36.120
Thus I'm going to call student supplier as soon as I press the I mean, as soon as I enter that it is

02:36.120 --> 02:42.780
going to give me this get method that this get method is going to return the student that is as part

02:42.780 --> 02:44.340
of the student supplier.

02:46.250 --> 02:47.270
Function interface.

02:47.950 --> 02:50.470
Now let's take a look at one more example.

02:51.360 --> 02:52.500
Go to the student database.

02:52.500 --> 02:55.440
Here we are having a static method.

02:55.440 --> 02:58.530
This static method is returning the list of students.

02:59.040 --> 03:02.880
How can we achieve the same thing using the supplier?

03:03.720 --> 03:06.240
So let's create one more instance of supplier.

03:07.050 --> 03:14.550
The player is going to take the input as meaning the type as list of students.

03:16.430 --> 03:17.210
And then.

03:19.880 --> 03:20.780
Give it a name.

03:22.050 --> 03:23.100
The supplier.

03:23.920 --> 03:25.570
This is going to.

03:26.940 --> 03:28.200
Of something like.

03:30.060 --> 03:31.530
It doesn't take an input.

03:33.070 --> 03:36.280
Student database dot get all students.

03:36.910 --> 03:44.200
So this student supplier instance, meaning the list of player instance is going to return you a list

03:44.200 --> 03:48.940
of students instead of a single student that we coded just a moment ago.

03:49.420 --> 03:52.120
Now I'm going to call this.

03:53.430 --> 03:57.540
Students are the colon.

03:57.660 --> 04:00.210
Then list supplier dot.

04:03.700 --> 04:05.080
I run this example.

04:05.820 --> 04:08.200
See here it printed all the students.

04:09.430 --> 04:16.300
Let's summarize this one supplier doesn't take any input, but when it's invoked, it is going to supply

04:16.300 --> 04:17.620
something to the caller.

04:18.190 --> 04:20.110
With this, we came to the end of this tutorial.

04:20.140 --> 04:21.310
Thank you for watching.
