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. :)
@puneethshivalingaiah3 жыл бұрын
yes and couldn't agree more :)
@shivamupmanyu8940 Жыл бұрын
Actually i was looking for this answer throughout the whole videoand I found it in the comment section
@Reviewbyjuhi3 жыл бұрын
You are making me fall in love with java, all over again!
@CodeDecode3 жыл бұрын
Thanks for the motivation aishwarya
@gyvsr2 жыл бұрын
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.
@abhishekgowlikar Жыл бұрын
awesome, explanation on default method in Java 8
@CodeDecode Жыл бұрын
Thanks
@shashankgarg81283 жыл бұрын
seriously so much good content in this channel .
@CodeDecode3 жыл бұрын
Thanks Shashank.....
@SriHariChukka12102 жыл бұрын
Great help... but it Seems this playlist is not properly created..
@rajeshg35704 жыл бұрын
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
@CodeDecode4 жыл бұрын
Abstract class can still contain constructors. Interface can't
@CodeDecode4 жыл бұрын
All the variables of interface are still constants ( public final static) no such restrictions on abstract classes
@rajeshg35704 жыл бұрын
Thanks for the reply. I've a follow up question here - if I don't have to have any constants, then how do I choose between interface with default method and an abstract class with a concrete method. As far as I remember, you can't instantiate an abstract class, so, I'm wondering how does the constructor in an abstract class would help
@CodeDecode4 жыл бұрын
Nice question. Answer to your first query is that creating class in Java is costlier in terms of memory and performance. Hence interface is a better choice.
@CodeDecode4 жыл бұрын
For your send query , it's a myth that constructor in Java is just used for object creation. Constructor constructs the object by initialising the members ( instance variables ) with default initial values. Hence constructors main job is to do initialisation. And abstract class constructor is called by child or implementing class constructor by default. Hence abstract class constructor is a useful thing.
@darshanhelode.61962 жыл бұрын
Love the way u teach mam thank you!
@CodeDecode2 жыл бұрын
🙂🙂
@spiderweb57474 жыл бұрын
excellent, your explanation is very good.
@nagendrapp22134 жыл бұрын
do have spring boot experience? if yes could you please upload spring boot tutorials by the way nice explanation ;)
@CodeDecode4 жыл бұрын
I'll upload it soon ....!
@saurabhkailashchandrapuran86094 жыл бұрын
Can you pls make and upload the all new and important features of java 8 with practical examples 🙏🙏
@CodeDecode4 жыл бұрын
Sure I will upload soon. With live demo examples
@srideviprathipati81884 жыл бұрын
Great job
@CodeDecode4 жыл бұрын
Thanks
@vismarkjuarez81023 жыл бұрын
"It does not have legs!" -- good vid
@CodeDecode3 жыл бұрын
Thanks.....
@snehazz52842 жыл бұрын
Why default was introduced but not public???
@CodeDecode2 жыл бұрын
Don't confuse Default methods with default access modifier Sneha. They both are different concepts
@AdityaSingh-qn7rf Жыл бұрын
then one question when default method (with implementation) is there then now what's the use of abstract class in java ? can you explain ?
@Ammu-Alwin Жыл бұрын
I do have the same question.
@reeltorealworld56604 жыл бұрын
U way of xplaining is v appreaciating.....
@CodeDecode4 жыл бұрын
Thanks.
@prashanthdhn52163 жыл бұрын
Can you please explain why abstract class in Java 8, we have default method in Java 8
@codingtrix5253 жыл бұрын
Abstract class in java is to achieve abstraction to hide methods implementation that will be in class which will extend attract class, and about default method basically default method is used when we want to provide default implementation for a particular method then we can use default method to provide default implementation and also with the help of default method in interface we can achieve multiple inheritance.