Why default method in Java 8 || Default method || (Most Asked Interview Question) | Code Decode

preview_player
Показать описание
In this video of code decode we will figure out why default method were introduced in Java 8

Udemy Course of Code Decode on Microservice k8s AWS CICD link:

Course Description Video :

Before Java 8, interfaces could have only abstract methods. The implementation of these methods has to be provided in a separate class. So, if a new method is to be added in an interface, then its implementation code has to be provided in the class implementing the same interface. To overcome this issue, Java 8 has introduced the concept of default methods which allow the interfaces to have methods with implementation without affecting the classes that implement the interface.

#whydefaultmethodinjava8 #java8 #defaultmethod
Рекомендации по теме
Комментарии
Автор

want to add a few more sentences, why default was added and changed the definition of Interface. The explanation, which you gave is the USE of having a default method, but not the real reason to add it in the interface... So actually, when Lambda and stream API functions were added in Java-8, we were not able to use these features in existing collections classes. e.g. forEach() method in Map Interface. it is the default method. if Java developers just want to add this method as a normal method in the Map interface, then they have to make the changes in all its derived classes. In short, the default was added in the existing Java interface for backward compatibility due to the addition of the lambda function. :)

arunbhardwaj
Автор

You are making me fall in love with java, all over again!

AishwaryaMehta
Автор

It was just to make sure the backward compatibility without breaking the contract.
And, as we know, the purpose of interface is just for creating/designing the contract, it doesn't make sense modifying that contract at all, because there would have been lot of clients accessing/implementing the same.

gyvsr
Автор

awesome, explanation on default method in Java 8

abhishekgowlikar
Автор

seriously so much good content in this channel .

shashankgarg
Автор

excellent, your explanation is very good.

spiderweb
Автор

Great help... but it Seems this playlist is not properly created..

SriHariChukka
Автор

Just curious to know, how an interface with default method is different from an abstract class ? I mean I can an abstract class to define a concrete method which would be available for all the subclasses

rajeshg
Автор

do have spring boot experience? if yes could you please upload spring boot tutorials by the way nice explanation ;)

nagendrapp
Автор

Can you pls make and upload the all new and important features of java 8 with practical examples 🙏🙏

saurabhkailashchandrapuran
Автор

Why default was introduced but not public???

snehazz
Автор

"It does not have legs!" -- good vid

vismarkjuarez
Автор

then one question when default method (with implementation) is there then now what's the use of abstract class in java ? can you explain ?

AdityaSingh-qnrf
Автор

Can you please explain why abstract class in Java 8, we have default method in Java 8

prashanthdhn
Автор

Activate windows, you are using commercially!!

reynasebasti