WEBVTT

00:02.130 --> 00:02.700
Hi everyone.

00:02.700 --> 00:04.020
Welcome back to this tutorial.

00:04.020 --> 00:10.170
In this tutorial, I'm going to explain some theory about the default and static methods in interfaces.

00:10.440 --> 00:14.550
Let's talk about what was allowed before Java eight in interfaces.

00:14.550 --> 00:21.840
First, the concept of interfaces is to just define the contract, meaning you are just allowed to declare

00:21.840 --> 00:26.850
the method, but you cannot have any method implementation in interfaces.

00:27.120 --> 00:34.530
The class that implements the interface should implement the logic for the declared method in the interface.

00:34.920 --> 00:42.420
We all know that this limitation had a severe impact for an interface to evolve or upgrade because if

00:42.420 --> 00:49.230
we try to declare new methods in the interfaces, then the class that already implements this interface

00:49.230 --> 00:51.150
should implement the new method.

00:51.180 --> 00:54.240
Otherwise this will lead to compilation issues.

00:54.390 --> 00:58.560
The main impact because of this is for the library creators.

00:58.560 --> 01:04.180
It was really hard to introduce the new functionality parties in the interfaces.

01:04.210 --> 01:12.280
In order to avoid this, the Java creators made the change to allow the method implementation in interfaces

01:12.310 --> 01:16.210
itself via static and default methods.

01:16.240 --> 01:19.180
Let's talk about the default method first.

01:19.840 --> 01:26.620
Default methods in interfaces will have the new default keyword as part of the method signature itself,

01:26.620 --> 01:31.510
which then registers that method as a default method in the interface.

01:33.180 --> 01:36.690
It is an example of a default method from the list interface.

01:36.720 --> 01:41.130
This is a short method which is going to sort the list collection.

01:41.370 --> 01:46.850
If you notice here it has the default keyword as part of the method signature.

01:46.860 --> 01:54.540
With that, the Java compiler will allow the method implementation in interfaces prior to Java eight.

01:54.570 --> 01:59.670
We normally use the collections class to perform the similar operation.

02:01.070 --> 02:08.150
If all methods can be overridden in the implementation class, we will explore all those options in

02:08.150 --> 02:09.770
our future tutorials.

02:10.250 --> 02:17.480
If all methods are going to help the Java developers to introduce the new functionalities in the future

02:17.480 --> 02:23.510
without having any impact to the current classes that implements the interface.

02:24.250 --> 02:25.810
Similar to default methods.

02:25.810 --> 02:30.040
We have static methods also allowed as part of the interfaces.

02:30.070 --> 02:35.080
The only difference between the two meaning between the static method and the default method.

02:35.110 --> 02:40.090
The static method cannot be overridden in the implementation classes.

02:40.240 --> 02:46.090
Let's go ahead and explore all these new methods via code in the following tutorials.

02:46.120 --> 02:48.250
With this we came to the end of this tutorial.

02:48.280 --> 02:49.390
Thank you for watching.
