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

  Рет қаралды 46,117

Code Decode

Code Decode

Күн бұрын

Пікірлер
@arunbhardwaj1979
@arunbhardwaj1979 4 жыл бұрын
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. :)
@puneethshivalingaiah
@puneethshivalingaiah 3 жыл бұрын
yes and couldn't agree more :)
@shivamupmanyu8940
@shivamupmanyu8940 Жыл бұрын
Actually i was looking for this answer throughout the whole videoand I found it in the comment section
@Reviewbyjuhi
@Reviewbyjuhi 3 жыл бұрын
You are making me fall in love with java, all over again!
@CodeDecode
@CodeDecode 3 жыл бұрын
Thanks for the motivation aishwarya
@gyvsr
@gyvsr 2 жыл бұрын
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
@abhishekgowlikar Жыл бұрын
awesome, explanation on default method in Java 8
@CodeDecode
@CodeDecode Жыл бұрын
Thanks
@shashankgarg8128
@shashankgarg8128 3 жыл бұрын
seriously so much good content in this channel .
@CodeDecode
@CodeDecode 3 жыл бұрын
Thanks Shashank.....
@SriHariChukka1210
@SriHariChukka1210 2 жыл бұрын
Great help... but it Seems this playlist is not properly created..
@rajeshg3570
@rajeshg3570 4 жыл бұрын
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
@CodeDecode
@CodeDecode 4 жыл бұрын
Abstract class can still contain constructors. Interface can't
@CodeDecode
@CodeDecode 4 жыл бұрын
All the variables of interface are still constants ( public final static) no such restrictions on abstract classes
@rajeshg3570
@rajeshg3570 4 жыл бұрын
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
@CodeDecode
@CodeDecode 4 жыл бұрын
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.
@CodeDecode
@CodeDecode 4 жыл бұрын
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.6196
@darshanhelode.6196 2 жыл бұрын
Love the way u teach mam thank you!
@CodeDecode
@CodeDecode 2 жыл бұрын
🙂🙂
@spiderweb5747
@spiderweb5747 4 жыл бұрын
excellent, your explanation is very good.
@nagendrapp2213
@nagendrapp2213 4 жыл бұрын
do have spring boot experience? if yes could you please upload spring boot tutorials by the way nice explanation ;)
@CodeDecode
@CodeDecode 4 жыл бұрын
I'll upload it soon ....!
@saurabhkailashchandrapuran8609
@saurabhkailashchandrapuran8609 4 жыл бұрын
Can you pls make and upload the all new and important features of java 8 with practical examples 🙏🙏
@CodeDecode
@CodeDecode 4 жыл бұрын
Sure I will upload soon. With live demo examples
@srideviprathipati8188
@srideviprathipati8188 4 жыл бұрын
Great job
@CodeDecode
@CodeDecode 4 жыл бұрын
Thanks
@vismarkjuarez8102
@vismarkjuarez8102 3 жыл бұрын
"It does not have legs!" -- good vid
@CodeDecode
@CodeDecode 3 жыл бұрын
Thanks.....
@snehazz5284
@snehazz5284 2 жыл бұрын
Why default was introduced but not public???
@CodeDecode
@CodeDecode 2 жыл бұрын
Don't confuse Default methods with default access modifier Sneha. They both are different concepts
@AdityaSingh-qn7rf
@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
@Ammu-Alwin Жыл бұрын
I do have the same question.
@reeltorealworld5660
@reeltorealworld5660 4 жыл бұрын
U way of xplaining is v appreaciating.....
@CodeDecode
@CodeDecode 4 жыл бұрын
Thanks.
@prashanthdhn5216
@prashanthdhn5216 3 жыл бұрын
Can you please explain why abstract class in Java 8, we have default method in Java 8
@codingtrix525
@codingtrix525 3 жыл бұрын
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.
@yaswanthyv3837
@yaswanthyv3837 5 ай бұрын
Angular 8😅
@reynasebasti3635
@reynasebasti3635 3 жыл бұрын
Activate windows, you are using commercially!!
@CodeDecode
@CodeDecode 3 жыл бұрын
In our recent videos it's activated
КОНЦЕРТЫ:  2 сезон | 1 выпуск | Камызяки
46:36
ТНТ Смотри еще!
Рет қаралды 3,7 МЛН
Маусымашар-2023 / Гала-концерт / АТУ қоштасу
1:27:35
Jaidarman OFFICIAL / JCI
Рет қаралды 390 М.
I Sent a Subscriber to Disneyland
0:27
MrBeast
Рет қаралды 104 МЛН
Java overloaded methods ☎️
5:39
Bro Code
Рет қаралды 94 М.
Abstract Classes and Methods in Java Explained in 7 Minutes
7:00
Coding with John
Рет қаралды 577 М.
Java Strings are Immutable - Here's What That Actually Means
7:06
Coding with John
Рет қаралды 629 М.
Method Reference In Java 8 - How it really works ?
1:20:27
Selenium Express
Рет қаралды 9 М.
КОНЦЕРТЫ:  2 сезон | 1 выпуск | Камызяки
46:36
ТНТ Смотри еще!
Рет қаралды 3,7 МЛН