Java Interfaces Explained - 040

  Рет қаралды 155,057

Deege

Deege

8 жыл бұрын

What is a Java interface?. It's a contract that states any class implementing this interface can be typed as the interface and it guarantees the methods listed in the interface will be implemented. So let's talk about how interfaces work, and how we can use them in our applications.
#java #programming #tutorial

Like the video? Don't forget to subscribe! ➜ www.deegeu.com/subscribe

Keep up to date with the newsletter! ➜ www.deegeu.com/newsletter/
Full transcript:
www.deegeu.com/java-interfaces...
Concepts: Java, interfaces, defender methods, functional interfaces, marker interfaces
Social Links: Don't hesitate to contact me if you have any further questions.
WEBSITE : dj@deegeu.com
TWITTER : / deege
FACEBOOK: / deegeu.programming.tut...
GOOGLE+ : google.com/+Deegeu-programming...
Hosted by DJ Spiess
About Me: www.deegeu.com/about-programmi...
Related Videos:
What are static factory methods in Java? - 036
• What are static factor...
Free Java Course Online
• What important Java Te...
Media credits: All images are owned by DJ Spiess unless listed below:
Music
Hackbeat by Kevin MacLeod is licensed under a Creative Commons Attribution license (creativecommons.org/licenses/...)
Source: incompetech.com/music/royalty-...
Artist: incompetech.com/

Пікірлер: 172
@harshulpandav1173
@harshulpandav1173 6 жыл бұрын
Starting a programming video with a real world example. You nailed it. Beginners usually understand how to use interfaces, however, get confused or find it hard to understand the PURPOSE of using interfaces. This video explains the purpose. Great content.
@RedEyedJedi
@RedEyedJedi 6 жыл бұрын
I love the amount of detail you include in your videos. I am learning java so I can pass the Oracle exams and hopefully become a professional programmer. Coding is my favourite hobby besides playing the guitar so it would be amazing to actually get paid for doing something that I love doing. Thank you so much for taking the time to make these videos, it is really helping me.
@samuelmcalpin8761
@samuelmcalpin8761 Жыл бұрын
how's it going, are you currently working as a programmer yet??
@fahada783
@fahada783 10 ай бұрын
I admire your positive words thanks and keep going
@tristanlee1171
@tristanlee1171 4 жыл бұрын
Am I the only one who is still confused
@corey314159
@corey314159 4 жыл бұрын
I was too after first viewing. Then I watched it two more times and realized how great an explanation on interfaces this was!
@KoryGraphic
@KoryGraphic 4 жыл бұрын
You should have a read about interfaces from somewhere else just to know what he's talking about, then everything makes sense.
@mryup6100
@mryup6100 3 жыл бұрын
@@KoryGraphic Yeah, I agree. This is very easy to understand now.
@HotFiya05
@HotFiya05 3 жыл бұрын
I just think he's going way too quickly. Seems like a synopsis
@DrSaav-my5ym
@DrSaav-my5ym 2 жыл бұрын
@@KoryGraphic or he could just explain it in a way that could be understood having no knowledge of interfaces, i wouldn't mind a longer video
@NelsonSteffens
@NelsonSteffens 6 жыл бұрын
Your video has enlightened me. Thank you for explaining the differences between abstract classes and interfaces. It was very unclear to me before but after watching your video, it all makes total sense now! Great videos! Keep 'em coming!
@JorgeEscobarMX
@JorgeEscobarMX 7 жыл бұрын
I'm afraid that interfaces is a complex subject to be handled in a single video, yet this video was great as a tutorial/introduction to interfaces.
@skyhigh9474
@skyhigh9474 4 жыл бұрын
Straight to the point. That's how all others need to start their videos too.
@thecallitaspadechannel2794
@thecallitaspadechannel2794 3 жыл бұрын
This makes so much more sense then where I read about it before, and under ten minutes too!!!
@jeremiahnji6
@jeremiahnji6 7 жыл бұрын
Thank you for the video. Helped me a lot when creating interfaces for one of my applications. You made this two years ago but it is still helping people like me out :)
@waverunzzz
@waverunzzz 7 жыл бұрын
I appreciate the practical explanation of the contexts of using interfaces vs abstract classes. Thanks!
@deegeu
@deegeu 7 жыл бұрын
Thanks for watching!
@victorejiofor8115
@victorejiofor8115 2 жыл бұрын
I would say that this is an informative video and the example of the self-driving cars you mentioned at the beginning of the video made the point of interfaces clear. Thanks very much
@7654321romer
@7654321romer Жыл бұрын
Great explanation, I loved that the video not too long despite the amount of detail.
@KayVirals
@KayVirals 5 жыл бұрын
This video was short and packed with lot of useful information. Love your videos... Thank you.
@JorgeEscobarMX
@JorgeEscobarMX 7 жыл бұрын
I can see your point in 6:20, forcing another developer to understand your inheritence design will cause problems. Interfaces are free of that level of commitment and still work as intended.
@aashutoshtaikar5087
@aashutoshtaikar5087 5 жыл бұрын
Nice explanation. But the biggest difference and an advantage of using interface over abstract class; is that an interface will allow developers to do multiple inheritance which might be needed in certain scenarios. And now that we can have method definitions inside interface we must use interface whenever possible. In 3:59 the instructor says the code will not compile due to ambiguity of two default methods, but he missed to mention that it can be resolved by overriding the implementation of default method wakeDJUp() in the MyCar class, effectively clearing out the ambiguity. Interfaces are really very powerful now. I will shortly post a code on github which explains this. But in all the the explanation is really nice, simple and precise. Thanks!
@adrianperez8695
@adrianperez8695 4 жыл бұрын
Thank you for this video. Helped me understand interfaces better!
@jonasbanhos7373
@jonasbanhos7373 6 жыл бұрын
Great high level explanation! Thanks!
@biodunkehinde1
@biodunkehinde1 7 жыл бұрын
Awesome video, now I understand these concepts better. Thanks so much
@Kobe29261
@Kobe29261 6 жыл бұрын
Thanks man, you are doing awesome work!
@praveenchukka
@praveenchukka 7 жыл бұрын
This is so clear!
@undrgrndhp
@undrgrndhp Жыл бұрын
Great video, Thank you!
@satioOeinas
@satioOeinas Жыл бұрын
This was very helpful! Thank you :)
@dantepillon
@dantepillon Жыл бұрын
This is a good explanation subscribed!
@ghaliahabukhrs1948
@ghaliahabukhrs1948 7 жыл бұрын
Thank you very much , it is amazing information 🌸🌸
@fran14cruz
@fran14cruz 3 жыл бұрын
Best teacher ever. My respects.
@preetham1986
@preetham1986 2 жыл бұрын
Omg your explaination is on point.
@Abdulwahid-ru5wy
@Abdulwahid-ru5wy 6 жыл бұрын
well done men.You teach this concept v.well
@amitrawat8075
@amitrawat8075 6 жыл бұрын
Sir! You are awesome .. I'm feeling blessed that I found you :)
@Joni67sinix
@Joni67sinix 5 жыл бұрын
excellent class!! thanksssss
@KarolStoinski
@KarolStoinski 8 жыл бұрын
Awesome video!
@deegeu
@deegeu 8 жыл бұрын
+Karol Stoiński Thank you!
@yuudaemones2624
@yuudaemones2624 6 жыл бұрын
Makes a Spaceballs reference 5 seconds into video... I already like this guy.
@donniedorko3336
@donniedorko3336 5 жыл бұрын
That was very helpful thank you
@Binyam_G_Kahsay
@Binyam_G_Kahsay 4 жыл бұрын
good way of teaching sir
@baalametsayid8596
@baalametsayid8596 7 жыл бұрын
Hey there! I'm currently working on building a composite class that needs to take methods from any one of six other classes, but needs to ONLY have access to a selection of one to several of those classes at a time, as well as the ability to change from one to the other. I plan to instantiate and release objects of those classes as a form of access control. Would an interface better serve this purpose?
@gurmangill009
@gurmangill009 7 жыл бұрын
Very well explained, Nice Job. Would be really nice to make a video about how everything is public in interface, interface contains constants and stubs(Mehtods without body) only. While in abstract class there can constants, members, stubs and defined members ( can be defined with any visibility) and much more.
@daleoking1
@daleoking1 7 жыл бұрын
hi nice video. Two things. Is Interface like a Struct in c++? and Is ActionListener an Interface? I am still confuse with this subject.
@ifstatementifstatement2704
@ifstatementifstatement2704 Жыл бұрын
Ok but what if someone creates a class that does not extend/implement the interface but yet implements their own version of those methods? Basically bypassing your interface/contract.
@sueason6041
@sueason6041 4 жыл бұрын
Thank you so much!!
@prathameshbhonkhade7801
@prathameshbhonkhade7801 3 жыл бұрын
Very well explained sir 😉
@gigajoules6636
@gigajoules6636 3 жыл бұрын
Great video with the exception of the audio levels flicking between you whispering and then being absolutely deafening
@relaxxxxx620
@relaxxxxx620 6 жыл бұрын
Awesome video
@basuchandaki
@basuchandaki 7 жыл бұрын
really coooool, super!
@chrs-wltrs
@chrs-wltrs 2 жыл бұрын
Wait, if you've got a bundle of constants that you want to include across your project, is it better to implement them as a final class, as opposed to an interface? Doesn't the necessity of class inheritance preclude any possibility of inheriting anything from an actual parent class? It seems like an interface would be easier.
@raaznak
@raaznak Жыл бұрын
my right ear really enjoyed this vid
@jliebss_
@jliebss_ 3 жыл бұрын
He explained more in 42 seconds than my textbook explained in 42 pages
@lomoyang3034
@lomoyang3034 5 жыл бұрын
Could one give me an example of under what situation we will call a default method from another interface? Thank You!
@michaelbrooks6713
@michaelbrooks6713 5 жыл бұрын
Very good video. I do have one question though. You said that the method in an interface can only be void. However if you're implementing a Java Pattern like Strategy, don't you have to pass an object back to the decelerating interface? Thanks in advance.
@NaveenKumar-bh5wk
@NaveenKumar-bh5wk 5 жыл бұрын
Thank you
@MathP3r
@MathP3r 5 жыл бұрын
thank you !
@8o8inSquares
@8o8inSquares 6 жыл бұрын
Thanks!
@pradeephero1
@pradeephero1 7 жыл бұрын
Thanks
@Jacobluke121
@Jacobluke121 6 жыл бұрын
great video. What is the point in the interface, surely we could just declare the methods in the classes that require them rather than having an interface? TIA
@A5mis
@A5mis 5 жыл бұрын
You're good, so good
@mdzahidulislam2980
@mdzahidulislam2980 8 жыл бұрын
Great Tutorial.:)
@deegeu
@deegeu 8 жыл бұрын
+MD Zahidul Islam Thank you for watching!
@ballads7774
@ballads7774 5 жыл бұрын
THANK YOU
@DannydXL
@DannydXL 6 жыл бұрын
It's a bit hard to focus on this video with that music in the background.
@trancedman
@trancedman 3 жыл бұрын
No wonder. It's kids music. Distraction everywhere.
@herionetbrine8826
@herionetbrine8826 3 жыл бұрын
Best example of what happens when living in a loud house. I tuned out the music from the start. I had to focus on trying to hear it, and even then it was only when you mentioned it was there at all. Damn.
@mdzahidulislam2980
@mdzahidulislam2980 8 жыл бұрын
My question for you - i need to use 4 behavior from two interface and 2 from one and 2 from one.Both interface contains 4 methods/behavior.so i have to implement (or keep as empty) 8 method in my class.I dont want to do that.What would be good way around for this scenario.Thanks.
@DreBruh
@DreBruh 2 жыл бұрын
Hey these videos are great, wish you were still making videos. I hope you’re doing well sir
@TheZerosteel
@TheZerosteel 3 жыл бұрын
SelfDrivable.super
@payambassi8784
@payambassi8784 2 жыл бұрын
Hi thank you for the video, I'd just say that it all seems to be going too fast. I think it's always good, specially for computer sciencey stuff to go a little slower, and to explain any new concept from a few different angles.
@anonmisfit
@anonmisfit Жыл бұрын
very helpful! I still struggle with grasping where to actually use interfaces instead of classes in real projects. Sure you can define structures, but where do I actually NEED that? I'm working on a 9 year-old project - implementing interfaces now for old and established functionalities seems far too risky at this point, and like a potential chore going forward.
@xianchen1935
@xianchen1935 5 жыл бұрын
Soo... what's the main difference between acstract classes and interfaces?
@elmago4894
@elmago4894 4 жыл бұрын
quote from a java book im reading, ."One of the most common Java interview questions is, “What is the difference between an interface and an abstract class?” This section provides you the most detailed answer to that question. An interface is not a class, but it does help create classes. An interface is fully abstract; it has no fields, only method definitions (skeletons). A class can implement an interface, and unless the class is abstract, it is forced to provide concrete implementations for them. Each method declared inside an interface is implicitly public and abstract, because methods need to be abstract to force implementing classes to provide implementations and are public, so classes have access to do so."
@jameslowell9656
@jameslowell9656 4 жыл бұрын
You can implement multiple interfaces but can only extend one class at a time
@StoneColdMagic
@StoneColdMagic 7 жыл бұрын
Excellent Video - Subscribed! I've got a quick question for you. What happens if you implement 2 interfaces and they both have a method with the same name?
@piyushbisht1
@piyushbisht1 7 жыл бұрын
You have to provide your definition of conflicting Method in implementing class otherwise compiler will give you an error
@googlygates
@googlygates 6 жыл бұрын
hey you are too good!!!
@hebrux
@hebrux 6 жыл бұрын
awsome
@ersenosman4699
@ersenosman4699 8 жыл бұрын
Thank for making this video. Very helpful. Would it be possible for you to cover Generics in Java next?
@deegeu
@deegeu 8 жыл бұрын
+Ersen Osman Generics are coming very soon. I need to cover exceptions and some class types first.
@mahichasnalla
@mahichasnalla 7 жыл бұрын
where the details of marker interface are define
@skullwise
@skullwise 6 жыл бұрын
very helpful video. Why is it a bad idea to have an interface with only constant?
@hiddenblade999
@hiddenblade999 7 жыл бұрын
Having trouble understanding your argument for interfaces > inheritance. We can implement many interfaces in a class. But with inheritance we are restricted to the methods of the one class?
@deegeu
@deegeu 7 жыл бұрын
The main problem is inheritance forces the user (another programmer) to create a derived class. If everything will always be under the control of one person, or the same team then it's not as much of an issue. The writer of the subclass must know the internal workings of the superclass, otherwise the subclass can be adversely affected by any evolution in the superclass. Much of the internal workings must be exposed through protected methods. This means you must give significant thought on how your class will be subclassed, heavily document it, and you have to test it by writing several subclasses. This doesn't mean inheritance is useless, but if you're just needing to provide a hook for some functionality to be called, interfaces are the way to go.
@SamChalvet
@SamChalvet 5 жыл бұрын
Where is your background? Looks like the Belledonne mountain range in France
@harishchowdarysure8858
@harishchowdarysure8858 7 жыл бұрын
I have a one class who contain 5 methods But my requirement is in between 5 methods I want to apply locking mechanism that multiple thread can’t access at a time but rest 3 methods can be access by multiple thread at a time NOTE:Without using Synchronized key word
@deegeu
@deegeu 7 жыл бұрын
Well you could use a simple semaphore (flag) to block when code is entered. You could use atomic variables (look at AtomicReference). You could also look at locks. This sounds like a homework problem... :)
@andreviniciusbezerradasilv9335
@andreviniciusbezerradasilv9335 Жыл бұрын
thx
@pseudooduesp2805
@pseudooduesp2805 6 жыл бұрын
hi i am sorry but that language stay verbose and oop for me it realy havy processing , when use interface when use abstract class why it 's not clear.
@computerscience901
@computerscience901 7 жыл бұрын
What is package scope ?
@deegeu
@deegeu 7 жыл бұрын
When you define a class if you leave out the scope modifier (public, private, or protected), the default is "package" scope. That means subclasses and other classes cannot access your new class, unless the class is in the same package.
@computerscience901
@computerscience901 7 жыл бұрын
O right. I get you. Thanks.
@saimhassan
@saimhassan 6 жыл бұрын
Awesome!
@gauravjha2558
@gauravjha2558 8 жыл бұрын
can u explain in below paragraph bit detail --------- "a class usually represents one concept ,but it can do many action"
@deegeu
@deegeu 8 жыл бұрын
+Gaurav Kumar A class usually represents on thing. For example, the class could represent a car. The car can do many things (actions) like start, drive, stop, turn, etc..
@agoncharov
@agoncharov 6 жыл бұрын
YOu have explained this very well!. I have already tried 5 other sources, and this was the best! Thanks Deege u!!
@salmankhandu3819
@salmankhandu3819 3 жыл бұрын
1) when to use interface and when to use abstract class. 2) after jdk8 what's major difference between interface and abstract
@W0lfm0ther
@W0lfm0ther 6 жыл бұрын
that shirt is everything
@mattsmith6828
@mattsmith6828 3 жыл бұрын
you said "The most common use for interfaces is to hide the details of a class". I agree with everything else you said about interfaces, but this one statement doesn't make any sense to me. How does an interface HIDE anything? They just force classes & other interfaces that implement or extend them to implement it's methods.
@samitee8336
@samitee8336 8 ай бұрын
from the future, driverless cars now exist!
@shawnl1155
@shawnl1155 4 жыл бұрын
Great material but I believe the gain is too high on the mic. It sounds like it's clipping when you are doing the voice over while showing the computer screen.
@gauravjha2558
@gauravjha2558 8 жыл бұрын
how interface hiding details of class ........please explain me
@deegeu
@deegeu 8 жыл бұрын
+Gaurav Kumar An interface is just a list of method calls. You cannot see any implementation details when calling the interface from another class. You may not even know what class instance is used.
@fatihersoy7559
@fatihersoy7559 4 жыл бұрын
@@deegeu Forgive my ignorance, but why do we need interfaces instead of just implementing in the related classes?
@kisnasur2145
@kisnasur2145 7 жыл бұрын
when we use builtin Interface like comparable, runnable...., why we don't have to override their methods and don't have to impements all the methods of that Interface.
@deegeu
@deegeu 7 жыл бұрын
You do need to implement all the methods. So if your class implements Comparable, you must provide the comareTo method. If you implement the Runnable method, you must provide a run method.
@wdabrilvi
@wdabrilvi 7 жыл бұрын
Hi, i am wondering: why are so important? i can simply ignore it and program like "interfaces" doesnt even exist. but everysingle time i try to read some java code they are all around.
@rolland49
@rolland49 6 жыл бұрын
Wow! The popularity and usability of functional programming has now becomne a feature in Java 8. But I was unaware that "defender methods" were a concept created to insure regression. Java has always been the classical school of OOP coding; e.g. class definitions. I hope future releases will have a better solution than the concept of "defender methods".
@harshalpaturkar2814
@harshalpaturkar2814 7 жыл бұрын
please Explain me what does "Program to interface" means ??
@deegeu
@deegeu 7 жыл бұрын
It means that you create an interface, and when you need to use a class behind the interface, you only access the interface. Not the concrete class. Your code should only call the methods exposed by the interface. A good example is exposing a list of data as a List (interface), but behind the scenes the class is an ArrayList (class).
@harshalpaturkar2814
@harshalpaturkar2814 7 жыл бұрын
thanx a lot sir,and seriously, I'm following ur java video, the explanation is really good
@soiefali4188
@soiefali4188 6 жыл бұрын
super like
@bobyenjoy3758
@bobyenjoy3758 6 жыл бұрын
Sir, Very nicely made video. But it doesn't server any purpose. I doesn't help me understand how to use an interface.. :-((
@junaidtanoli1
@junaidtanoli1 8 жыл бұрын
Nice tuts ! .. where is next video ?
@deegeu
@deegeu 8 жыл бұрын
+Junaid Tanoli It's coming soon. Holidays in the US have disrupted my schedule, but I should have at least one this week. Thanks for watching!
@user-iu9ko7cn6d
@user-iu9ko7cn6d 8 жыл бұрын
Subscribed!Very nice work,i'm gonna check your channel..Thanks :D
@deegeu
@deegeu 8 жыл бұрын
Thanks for watching!
@user-iu9ko7cn6d
@user-iu9ko7cn6d 8 жыл бұрын
Hehehe no prob,thanks for existing ^^
@phoenixbrothers2211
@phoenixbrothers2211 8 жыл бұрын
Thank you for the energy you are putting on these videos, but for the most part they are more like recapping what the user already knows and not much like a tutorial. So what would be the point if the user already familiar with those concepts? If you could put yourself in the position of a learner who is new to all these concepts your videos would be much more educational for sure. Maybe back in time when you were learning yourself.
@deegeu
@deegeu 8 жыл бұрын
+Phoenix Brothers Hm. I've been trying to start assuming no knowledge, and work from there. What do you think I could improve to make the videos more useful?
@tsi4ya
@tsi4ya 6 жыл бұрын
I disagree. I used this vid as a refresher of what I already knew. If you are a beginner then you could cruse the channel or simply google it. In ep 38 he goes over Abstract Classes, which touch on Abstract Methods, if he did that hear that would make the vid to long and then be a turn off for views like me.
@tonnie7079
@tonnie7079 5 жыл бұрын
@@deegeu I am new to Java and I found this so helpful and even made notes, Interfaces have always confused me thanks for the video
@abieniakgog
@abieniakgog 5 жыл бұрын
@@tonnie7079 - the same for me here :) I found it useful while looking for extending some topics from basic java tutorial online. @Deege U - thanks for the energy and smile in your eyes. Happy NY!
@zedzedder1426
@zedzedder1426 5 жыл бұрын
I am learning Java, and I like it. But I got to a point in the course, which is basically the OCA book by Jeanne Boyarsky and Scott Seikoff, so I got to a chapter that is trying to explain lambdas. But it explains lambdas by talking about interfaces, which comes later in the course/book. I need to understand interfaces, but I can't learn the "how" if I don't understand the "why". This was the first explanation I found, that makes me feel comfortable with the notion of interfaces, because now I get why is an interface used.
@arrogantermistkerl4579
@arrogantermistkerl4579 5 жыл бұрын
As I understood Interfaces dont usually have their methods imolemented. Especially not before Java SE 7."All methods of an Interface do not contain implementation (method bodies) as of all versions below Java 8. Starting ". Im citing: en.m.wikipedia.org/wiki/Interface_(Java). If that is correct I just dont understand where for example the method next()from the Iterator interface in the linkedList is implented . Because I dont see the method Next() it in the documentation of the LinkedList. docs.oracle.com/javase/7/docs/api/java/util/LinkedList.html. Can you pls explain or link to a video that does Thanks alot for the super content btw.
@ethan9435
@ethan9435 5 жыл бұрын
Excellent tutorial. Please correct me if I'm wrong; my understanding for the application of interface is that it is used to standardize functionality across selected classes. Is that true?
@dayday8421
@dayday8421 6 жыл бұрын
You got your wish re: driverless cars :)
@jefflee738
@jefflee738 5 жыл бұрын
good good good
@speedbumphu
@speedbumphu 5 жыл бұрын
Good tutorial although I have a question: why an earth does someone wear two tshirts at a time?
@somedude5414
@somedude5414 3 жыл бұрын
Looks like he's in Colorado in December. Maybe he wanted to avoid data shrinkage.
@xs10z
@xs10z 4 жыл бұрын
Yet another learning video with music in the background. When you were in school, did they play music during lectures? No? Why not? Why is this different?
@samsegurazramyi314
@samsegurazramyi314 3 жыл бұрын
I am also watching this video while wearing only underwear, which I couldn't do either while attending lectures. Yeah, this way of learning is different from lectures, and it is different for the better. Go to any educational video on youtube, and I mean ANY educational video, and you will read many comments saying something like "I swear I learn more in KZbin than in school".
@DrSaav-my5ym
@DrSaav-my5ym 2 жыл бұрын
I am still very very confused, I don't see the point of interfaces, very difficult concept to understand for a beginner
@akashnishad8128
@akashnishad8128 7 жыл бұрын
Hi Sir, My Question may sound stupid to you but from long time i am having this doubt interface P { public void add(); public void sub(); } class C implements P { @Override public void add() { System.out.println("addition method"); } @Override public void sub() { System.out.println("substraction method"); } } class Test { public static void main(String [] args) { C c=new C(); c.add(); c.sub(); } } My question is that if there was no interface class still this code will work(few changes req) and we are the one who are proving definition for interface methods then what is the point of interface In short my point is if X and Y interface contains 4 methods each and class Z implements X,Y class Z has to provide method definition of 8 methods .....then what is the point of interface ....we can directly create Z class with 8 methods in it.
@25zsams
@25zsams 7 жыл бұрын
i have the exact same question too : ( whelp!. someone explain please!
@loganphillips1674
@loganphillips1674 7 жыл бұрын
Let me try to explain. And by the way this is not a stupid question at all, it was one that I asked and took me a long time to understand, I still don't completely know everything about interfaces. In your case, you could definitely create class Z with the 8 methods in it and class Z would work fine. That's not necessarily the point though. Interfaces are a key component to object oriented programming. Often in OOP, a programmer creates a class that another programmer can use. A key part of OOP is abstraction. When creating our classes, we want to hide the details of the implementation from who ever will end up using that class in their own program. Say that I create a class that describes different behaviors of robots. We can have various kinds of robots, but they all have the same behaviors. They just do those behaviors in a different way. Every robot walks, jumps, runs, and many other things but they do so depending on what kind of robot they are. So, I create multiple classes that allow someone to create different kinds of robot objects with the proper instance variables and instance methods. Now, someone else should be able to use my class and use it to control the robot in anyway they want without having to worry about the implementation. In other words, they don't have to worry how the code makes the robot work. They should never have to study my code at all. So, I create an interface. The interface explains what any robot can do. The user of my class doesn't need to know how I make the robot walk or jump or talk, but all he needs to know is that if he calls the methods on a robot that he has constructed, it will do those things. In this example, some polymorphism and inheritance would need to be used because we have different kinds of robots that have similar behavior. The interface explains what each method of my class does so that the user of the class can use the methods. The interface basically guarantees that the methods in the class will work the way that they are described. This makes it a lot easier for the user of my class to actually use it because he doesn't have to worry about how I created the class. All he knows is that the class does what I say it does. Another key idea to interfaces in Java is that it allows flexibility. Say that I have a method that makes the robot walk forward a certain number of steps. The user of my class has been using it for years, until one day I realize that there is a better way to write that method. So, I rewrite it. As long as my revision still allows the robot to walk forward a certain number of steps, then it doesn't matter how I changed it. The robot will still walk forward a certain number of steps. Once again, the user of the class doesn't care how the robot walks forward. He just wants the robot to walk forward when he calls the particular method. Another way that interfaces are useful is be using them as types. An interface is a reference type. Similar to how we say int m = 8, or person p1 = new person(); the 'int' and 'person' are both reference types. If I have an interface called robotMovable, then I can say robotMovable r1 = new Robot(); Notice that the robotMovable is the reference type and the Robot(); is creating a type of robot. We cannot say robotMoves r1 = new robotMoves(); because a interface can not be instantiated. The importance of using interfaces as types probably isn't clear from my explanation. I encourage you to read about using interfaces as types in the oracle java tutorials and read about it on stack overflow. That should help. There are other reasons for interfaces, but these are some of the main ones. What I have explained isn't necessarily what interfaces were made for, but interfaces are extremely useful in the scenarios I have described. I hope this clarifies it somewhat.
@akashnishad8128
@akashnishad8128 7 жыл бұрын
thanks a lot sir
@gyaseddintanrkulu
@gyaseddintanrkulu 6 жыл бұрын
Yeah, I have a lot of questions. Number one: Why is Java so hard?
@bryanbojorque
@bryanbojorque 5 жыл бұрын
This video for me creates more questions than closure. I'm probably slow but is that all?
@charliekeane2520
@charliekeane2520 5 жыл бұрын
Had to watch this at 0.75 speed. Slow down friend
@fluffy24
@fluffy24 5 жыл бұрын
Same thing!
@j0rd4nH3nry
@j0rd4nH3nry 8 жыл бұрын
Thank you for this! I'm currently learning and teaching java in Auckland New Zealand (you remember more when you have to explain it right ??) I will be including a link to this video and your channel on my groups discussion board www.meetup.com/Java-Programming-101
@deegeu
@deegeu 8 жыл бұрын
+Marc Henry-wright Thank you for including a link to my videos!! I appreciate that!
Java Exception Handling - 041
9:28
Deege
Рет қаралды 25 М.
Java Interface Tutorial
14:49
Keep On Coding
Рет қаралды 128 М.
Did you find it?! 🤔✨✍️ #funnyart
00:11
Artistomg
Рет қаралды 120 МЛН
ХОТЯ БЫ КИНОДА 2 - официальный фильм
1:35:34
ХОТЯ БЫ В КИНО
Рет қаралды 2,3 МЛН
Abstract Classes vs Interfaces (Java)
9:43
The Code Hard Truth
Рет қаралды 204 М.
#66 What is Interface in Java
8:03
Telusko
Рет қаралды 154 М.
Overriding equals and hashCode in Java - 039
6:30
Deege
Рет қаралды 81 М.
Java Interface Tutorial - Easier than You Think!
12:49
Jack Hodkinson
Рет қаралды 7 М.
Generics In Java - Full Simple Tutorial
17:34
Coding with John
Рет қаралды 1 МЛН
Abstract Classes and Methods in Java Explained in 7 Minutes
7:00
Coding with John
Рет қаралды 470 М.
How principled coders outperform the competition
11:11
Coderized
Рет қаралды 1,5 МЛН
C# interfaces 🐟
5:38
Bro Code
Рет қаралды 116 М.
Java Asynchronous Programming
16:07
Defog Tech
Рет қаралды 144 М.
Lambda Expressions in Java - Full Simple Tutorial
13:05
Coding with John
Рет қаралды 695 М.
Did you find it?! 🤔✨✍️ #funnyart
00:11
Artistomg
Рет қаралды 120 МЛН