Java's Creators Rejected Multiple Inheritance - Here's Why

  Рет қаралды 69,849

Coding with John

Coding with John

Күн бұрын

Пікірлер: 283
@Riley-ml9vo
@Riley-ml9vo 2 жыл бұрын
I really appreciate the way you take high level concepts and present them in a digestible manner. I would love to hear you talk about design patters in Java. I feel it's a topic that is somewhat ambiguous and I feel that your high level analysis of it would greatly help me and many others!
@mariovelez578
@mariovelez578 2 жыл бұрын
You explain these concepts really well. Even after 5 years of coding Java, I still learn from you
@Brahvim
@Brahvim Жыл бұрын
I have the same amount of experience and I agree with you!
@SDFC
@SDFC Жыл бұрын
Spicy comment incoming: So, I can tell that this is a beginner friendly channel, but it would've been nice to at least mention in passing that inheritance is a bad practice ("Composition over Inheritance"). Here's a few resources that have great coverage of this concept: - I greatly appreciate that you've included "Effective Java" in the video description, which is a beautifully written book -- it actually covers this concept as Item 18, which is titled... "Composition over Inheritance". - I'd imagine that you're also familiar with the "Design Patterns" book by "the gang of four" (another very classic book in the industry) which also covers the concept of "Composition over Inheritance" in the very first chapter (p. 18 of my copy of the book). - Some languages such as Golang (the language that Google created for their own software engineers) go as far as to not even implement inheritance within the language. The alternative to solution to inheritance would be "delegation", which is composition + forwarding. This is a rather clunky pattern in vanilla approaches to Java, but I saw that you thankfully have a video on Lombok, which has the "@Delegate" syntax sugar as an experimental feature. I see you have some other videos that have already covered a lot of very awesome topics in a concise and beginner-friendly way, like Generics, Reflection ("meta-programming"), Lombok, Records (building block of algebraic data types), Checked vs Unchecked exceptions. The only unturned stone that I can actually think of is "Data vs Object", which Robert Martin covered in a great blog post over here: blog.cleancoder.com/uncle-bob/2019/06/16/ObjectsAndDataStructures.html
@domportera
@domportera Жыл бұрын
while I generally favor composition over inheritance, it's far from considered "bad practice" and is often the best way forward for extending pre-existing functionality. I feel like claiming that inheritance is bad practice is somewhat in-vogue. Granted it can (and often does) get messy, and so you *do* need to be careful with how you abstract things or else you definitely end up with a monster that can be difficult to tame. That being said, opportunities for Composition where it is not overly redundant should generally be preferred
@pawewodarczyk1546
@pawewodarczyk1546 2 жыл бұрын
This problem somewhat returned the moment when interfaces got default implementations in Java 8. So in some cases a developer is forced to choose which interface default implementation he wants to use, but it's compiler enforced and quite rare in practice. As for a diamond issue the bigger problem in my opinion are fields rather than methods. In case of methods you can choose an implementation as mentioned before, but in case of fields you can't just "pick" which field version you want to use safely without potentially messing up something.
@sabei221b
@sabei221b Жыл бұрын
I discovered your channel today, let me tell you, your content is incredible! I love how simplified yet informative your explanations are, it says alot about how well you know what you're doing, I love the jokes you implement here and there as well, the whole thing is very interesting and educational from start to finish, light hearted and well put together. perfect to my taste! 🎉
@Sollace
@Sollace 2 жыл бұрын
8:06 I've had a couple instances where I've wished Java had multiple inheritance. It wasn't really the only solution, just the alternative was a messy approach that involved duplicating a lot of code.
@Djaenzee
@Djaenzee 2 жыл бұрын
We had this multiple times in our code base, although the problem mostly came up when some of the actual java base classes better should have been designed to be interfaces. Seems to be especially true in Java UI classes that did not change mostly due to compatibiltiy reasons...
@harleyspeedthrust4013
@harleyspeedthrust4013 Жыл бұрын
and then one day you realized, the best solution is just to not use java
@th3runaway
@th3runaway Жыл бұрын
I'm curious if you had specific examples. I think in most cases, we've been conditioned to prefer composition instead of inheritance and I think in most cases, the projects I've worked on rely less and less on inheritance for behavior and really just the properties/values.
@Sollace
@Sollace Жыл бұрын
@@th3runaway I think the use cases I had which this would would have helped with are both instances where I don't have control over what the parent classes are doing. From memory, (modding minecraft) one was adding functionality to both Villagers and Zombie Villagers. The other was using the same model for two entities but generic constraits prevent me from doing that, so I have to make a "Proxy" class for the second that wraps the model for the first.
@JamieCrew
@JamieCrew 3 ай бұрын
John, you the definition of what makes a good teacher. You have passion, knowledge, and dedication. Teaching isn't a skill. It's simply someone who understands something so well that they can break it down to it's simplest form and explain it in a way without trying to show off. You just that, every teacher should learn from you!
@rikschaaf
@rikschaaf 2 жыл бұрын
If the diamond problem is the reason for not having multiple inheritance, then why can you implement multiple interfaces that could have the same default method implementation? In my opinion, It would be neater if the subclass would treat a superclass method implementation conflict as an abstract method, so that you'd have to be explicit about which implementation you'd want (or if you wanted a whole different implementation). Only if the method was final it should give an exception.
@jozef_franek
@jozef_franek 2 жыл бұрын
maybe in this topic could have been mentioned implementation of method from two different Interfaces with same method signature
@CodingWithJohn
@CodingWithJohn 2 жыл бұрын
I definitely thought about it! Basically how it works is, as long as the interfaces don't both have default implementations, there's no real conflict to resolve. The class can still implement that method that both interfaces specify. If they do both have default implementations, and you don't specify your own, it's simply a compilation error.
@DelzDerMeister
@DelzDerMeister 2 жыл бұрын
The same logic could be applied to multi inheritance. The only thing that would be problematic are non-private fields.
@nonswag4739
@nonswag4739 2 жыл бұрын
Would be interesting to know why two similar methods but with different type parameters are not allowed in one class
@PieJee1
@PieJee1 2 жыл бұрын
@@nonswag4739 in some strict languages that actually exists
@nonswag4739
@nonswag4739 2 жыл бұрын
@@PieJee1 I know, that's why I'm wondering why java does not allow this
@ShadoFXPerino
@ShadoFXPerino 2 жыл бұрын
8:00 Well here's the sitch: Cat is an abstract class written by someone else that you aren't allowed to change. Dog is from a licensed library package which you don't have the source code for. Your manager is telling you to implement Cog in 5 minutes since "everything's been done already".
@ChrisBrown-dn3tf
@ChrisBrown-dn3tf 2 жыл бұрын
I was wanting for multiple inheritance recently. I had a PythonScript class that acted as a large superclass for anything that was a script (entity script , item script). I also had a class called UserInterface which was a large superclass for classes that are UI (editorUI elements, Main menu UIs). I needed a UIScript class which would extend both and have the needed protected fields from both but it wasn't possible under the current system. UIScript extends PythonScript and within the script file, an object called ScriptedUI is constructed and used as the actual UI. Other than this recent problem, I would never have needed MI.
@moomoomoo309
@moomoomoo309 2 жыл бұрын
Default implementations on interfaces are similar to MI for Java, so you could have used that, probably.
@gabrieljonsson7821
@gabrieljonsson7821 Жыл бұрын
Seems to me what Java actually need is the friend keyword to access protected fields of another class (without the fuss of package private arrangements).
@Quinteger
@Quinteger 2 жыл бұрын
I find the diamond problem argument a bit of a meme because of the existence of default interface methods since Java 8. By that I mean it already exists in the language and you have tools to resolve that conflict while preserving the multi inheritance of interfaces. The more likely reason I can think of is performance - with single inheritance, class fields always have the same offset within the memory of an object and type casting becomes basically free.
@ManosSef
@ManosSef 2 жыл бұрын
I have actually tried to implement annotation interfaces in a class before and I was surprised when I saw you do it too. And yes I made a class that implements Deprecated, and realized that the required methods are actually the annotation members, as well as the annotationType() method. And while testing this, I found out that annotation interfaces without any members are actually functional interfaces, and giving them the @FunctionalInterface annotation works.
@joeysarie1520
@joeysarie1520 2 жыл бұрын
There one case where the multiple inheritance is missing, it's when you want to inherit from a class that it's not yours and don't duplicate code. For exemple, if you have an interface that allow to get/set data from a database with a standardized solution (use of getType() to know table, then fetch provided attribut) and give those function to 2 objects, then you can either duplicate the whole code, or create a common abstract object. But what if you want to add this feature to object that can be create in database, like MyCat & MyDog, but you can't on the Animal, Cat & Dog because it's not your ? Before Java 1.7, it was not possible without code duplication. Since Java 1.8, you may try to provide default function on interface, but you still need a getType() which is not available in your interface. You can trick java by creating this method in the interface, because if the method exist in at least one of your parent, compilation work. The downside is that you need to declare an AnimaleLike interface to provide signature of all needed function to your own interface, so you still have a bit of a duplication.
@andreassumerauer5028
@andreassumerauer5028 Жыл бұрын
To me multiple inheritance is just another useful tool in the box that unfortunately is not available in Java. One appropriate use would be the implementation of modular classes that can then be combined into a whole range of different combinations. Coming from C++ I sometimes do miss that language feature. Of course one can emulate that behavior with Java constructs like helper classes and/or default implementations in interfaces (which again introduces the oh-so-terrible diamond problem that doesn't actually exist in Java.). At the end these workaraounds require me to spread code all over the place that IMO better should be kept together in a single class. Of course one can do all kinds of stupid things using multiple inheritance. As with almost any other advanced tool. Carpenters use nail guns. When used appropriately they increase productivity and allow to work faster and with more accuracy. Sure you can shoot yourself in the foot with a nail gun. That is why you never let the inexperienced apprentice use it unsupervised, you observe best practises and safety procedures and you always wear protective gear. Only the Java language designers would come to the conclusion that nail guns should be banned altogether.
@lucashenrique6076
@lucashenrique6076 2 жыл бұрын
I Really like the way you explain coding stuff, even things I already know I watch the video patiently and learn something new. The way you speak english is nice even for foreign like me. Thanks again John ! See you next time!
@dgront
@dgront 2 жыл бұрын
It has been clear for me that multiple inheritance is not necessary since I started programming in rust. There is no inheritance at all in that language. There are interfaces in rust however.
@harleyspeedthrust4013
@harleyspeedthrust4013 Жыл бұрын
rust did it well. inheritance is unnecessary and encourages you to over-engineer your code. traits in rust are fantastic because you get exactly as much abstraction as you need without going overboard
@hz4353
@hz4353 2 жыл бұрын
John, just a great video, i would appreciate if you can have some more advanced course on Java such as concurrency, i would definitely pay to watch.
@veggieboy1
@veggieboy1 2 жыл бұрын
I've got one!! Please believe me :P I'm working on a graphing package in Java, and one of the superclasses (abstract) is Plot, from which inherit LinePlot and ScatterPlot (not abstract). I have been wanting to create a LineScatterPlot class, and have kept on thinking that this would have been a perfect time for multiple inheritance. But yes, I will find a way around it... :P
@aminembh6094
@aminembh6094 Жыл бұрын
Great video as usual! You do a fantastic work, it’s appreciated, we need more people like you 🎉
@johngeverett
@johngeverett Жыл бұрын
Issues like this exist in any language, and are best resolved by discipline, or 'standards'. The better resolution IMO would be to force the descendant class to implement the duplicate method as though it were a 'virtual method'. The 'interface' just makes you code ALL the methods for EVERY class that needs it. One way I get around the limit of only one parent class is to have a class that has an instance of each additional class that I might want. No ambiguity of methods, since the same-named methods are called by explicit reference to the enclosed object(s). BTW, the resultant creature would be a 'chimera'.
@Tech_Publica
@Tech_Publica 2 жыл бұрын
Overall excellent video, citing Gosling and stressing the "philosophy of simplicity" of Java is spot on, but I think one should make the distinction that using interfaces only gives you the same advantages as multiple inheritance as far as polymorphism is concerned, but NOT as far as code reuse is concerned, and inheritance is at its core a code reuse technique. But then again, there are other ways to achieve code reuse, like composition, so refusing multiple inheritance makes sense if you are after a language that maximise simplicity and not flexibility and power.
@zhalagurbanzade636
@zhalagurbanzade636 2 жыл бұрын
The explanation is very clear and concise. James Gosling would be envious.
@ericpenrose3649
@ericpenrose3649 2 жыл бұрын
Python developer here: Its always baffled me that people actually use multiple inheritance. Not only have I seen it in in multiple stack overflow answers and tutorials, but actually in production. Even if you try to avoid the diamond problem by inheriting from very dissimilar classes, for instance a Pet class inheriting from Animal and say Property or something, and you make sure to avoid generic and common attribute identifiers like 'name', there are still a ton methods included to every class by default which can conflict, at least in Python. Maybe there are instances where they are fine in theory but my experience with them in production is ALWAYS frustrating. To any future or current developer out there: If you find yourself typing multiple-paragraph comments describing the quirks of something, maybe instead spend that time finding a better way which doesn't require it?
@stephenJpollei
@stephenJpollei 2 жыл бұрын
Python is hugely dynamic and has a bunch of duck-typing. Heck, I think that a person could have an fully constructed object that is an Animal and you could inject Pet into it, at run-type.
@DrSpooglemon
@DrSpooglemon 2 жыл бұрын
Multiple inheritance is generally used to combine a stateful class with a behavior class. Like having 'button' behavior which can be attached to an image or a label. Rather that for trying to do something crazy like combine an image and a label.
@harleyspeedthrust4013
@harleyspeedthrust4013 Жыл бұрын
It's always baffled me that people use inheritance at all with non-abstract parents. In my experience inheritance rarely makes sense, and when it does, it only requires one abstract base class with multiple children. I've never needed grandchild classes or these stupidly complex inheritance hierarchies that people make UML diagrams for. That's how you overengineer your code and turn a simple problem into a complex problem and a bunch of "what ifs"... "oh well if Requirement A ever changes then we already have this abstract BeanManagerFactory class and implementing it would be trivial..." "if product ever needs this feature we could implement it easily, all we need to do is create a class for it and override this method from 5 parents up..." if you don't need it then don't build it ffs
@christopherbaviera197
@christopherbaviera197 2 жыл бұрын
For instance, since makeNoise() is a behavior, could be implemented as an interface describing better animals possibilities
@Speiger
@Speiger 2 жыл бұрын
Actually the "Diamond Problem" can happen with Java8 thanks to default implementations in interfaces. Where functions are 100% equal and thanks to 2 different interfaces you have this exact problem. How does java solve it: The class has to actually decide which implementation it uses. So the user gets told please pick for us!
@kikoalbiol
@kikoalbiol 2 жыл бұрын
At the end Java arrived to same solutions that C++ and other older languages arrived 20 years before
@bluecup25
@bluecup25 Жыл бұрын
​@@kikoalbiol Yeah, same for C#.
@jbragg33
@jbragg33 2 жыл бұрын
But there is one thing : Mixins. Java not having multiple inheritance, means it does not have mixins ! My use case was this one : I was using SPRING HATEOAS, and this framework _forces_ you to have "Resource classes" that extend some class : class MyResource extends HateoasResource. Our domain objects all had some common attributes (creationDate, lastModifiedDate, creator, updator, etc), and the *most elegant solution* would have been mixins.
@CodingWithJohn
@CodingWithJohn 2 жыл бұрын
I'll have to check more into that! I'm familiar with hateoas, but haven't used it in any real-world app as of yet. Looking at the documentation though (haven't tried this yet), can you use EntityModel as a kind of wrapper, and have be your domain class extending whatever you need?
@Sheikhhamiz
@Sheikhhamiz 2 жыл бұрын
@@baranosiu as far as I know multiple inheritance and mixins are two different things, mixins can be used to copy methods to prototype
@jbragg33
@jbragg33 2 жыл бұрын
@@CodingWithJohn Hm not sure, we were using "RepresentationModel", the way we did it was creating another Superclass containing the common fields, that works of course, but it needed a bit of refactoring. In the context of "extending existing code", that does not feel good to change a hierarchy, thus mixins were missed by me this time just for elegance. But I agree you can do without them :)
@satricon
@satricon 11 ай бұрын
Hahaha, this was awesome! I chucked at the "cog" fetch of "the cat does it if it feels like it" 😆
@dalcod
@dalcod Жыл бұрын
Hi John, your teaching style is impressive. Do you, by any chance, have plans to create a course or series of videos on Spring Boot?
@deconline1320
@deconline1320 Жыл бұрын
And then they added the Default methods in interfaces in Java 8... which introduced multiple inheritance. Many of Gosling initial design concepts are now gone from modern Java. But that's what usually happens to successful programming languages.
@raphaelmateusdasneves772
@raphaelmateusdasneves772 2 жыл бұрын
When i stumbled across this "missing" feature it was due to game development. It is really useful when you have stuff like a position class with move methods, a rotation class with rotation methods etc and want to apply it for example to a player class. But usually if you run into that you already fucked up your project architecture so its fine i guess. A better solution would have been to force the programmer to pick a method, for example with @Override(Dog.class) protected void makeNoise(); Then the override annotation would actually be useful nowdays lol
@schwingedeshaehers
@schwingedeshaehers 2 жыл бұрын
There was also the idea, that you could be forced to implement the duplicate methods yourself, and the rest is standard behaviour. I think overriding one of more methods with the same name is no good way. Does java has super? (I think so) Than it is important, that you can say which one you want
@schwingedeshaehers
@schwingedeshaehers 2 жыл бұрын
And i think there can be incomplete classes (I think it must also be possible for interfaces) -> you have to similar functions with different return types, but everything else the same. > How do you know which one is needed
@raphaelmateusdasneves772
@raphaelmateusdasneves772 Жыл бұрын
@@schwingedeshaehers My solution to this would be, to either use MyClass.myMethod(); for ambiguous calls or even allow blocks with a syntax like "using MyClass as super { ... }"
@schwingedeshaehers
@schwingedeshaehers Жыл бұрын
@@raphaelmateusdasneves772 we have a function in one class that returns an Integer, and one, that returns a string. -> how should that be handled?
@raphaelmateusdasneves772
@raphaelmateusdasneves772 Жыл бұрын
@@schwingedeshaehers I cannot happen. Unless you have different parameters, which is casual overloading then, you are forced to decide which class to implement. And having two methods with the same signature in one class is impossible anyways.
@RenderDragon
@RenderDragon 2 жыл бұрын
Good video, especially at the end :)
@shis10
@shis10 2 жыл бұрын
Amazing Video. 🙌🏻 Please make full video on Interfaces, has relationship and is a relationship.
@thomaslong1576
@thomaslong1576 2 жыл бұрын
I wish everyone could teach like you.
@rubenlarochelle1881
@rubenlarochelle1881 2 жыл бұрын
An alternative could be to allow multiple inheritance for the cases without conflicts and only give out an error when a diamond happens...
@BlueRey2
@BlueRey2 Жыл бұрын
Hey John! Would be really cool if you made an explanation video for Futures, it seems like a feature like Optionals where it seems to be somewhat overlooked. Thanks!
@francoisemond3515
@francoisemond3515 2 жыл бұрын
Thanks John, keep up the great work. I always look forward to watching your next video.
@javalady
@javalady 5 ай бұрын
"I dont beleive you" was really good :))
@lilygranger6264
@lilygranger6264 2 жыл бұрын
Loved the video john! May you please making a video on interfaces?
@jaylawlmc1915
@jaylawlmc1915 Жыл бұрын
Hello John! I am recommending "Future" and "CompletableFuture" as topic for one of your next videos. Would love to see your take on it. :-) Cheers
@bacon37460
@bacon37460 2 жыл бұрын
Another awesome video. Thanks John for your efforts. Could you please make a video for us about dependency injection (DI and IoC)?
@samluther2649
@samluther2649 2 жыл бұрын
I could be incorrect, but I feel this argument only holds water as long as you only accept the concept of an is-a relationship and reject the idea of a has-a relationship. Whether you like using has-a relationships or not they are a CS concept that would work better with multiple inheritance. Also in addressing the statement "I have never seen a problem that couldn't be addressed without multiple inheritance" I would say that I doubt there exists a problem that absolutely needs inheritance period. I'm quite certain that, while redundancy is bad, it still compiles. I might also say that this extends over multiple inheritance as well. While I could obviously not come up with a problem that needed to be solved with multiple inheritance (duh) I could come up with an example where it may have slightly less redundant code and could be slightly more readable. Especially in the realm of several has-a relationships.
@TBiscuit1
@TBiscuit1 Жыл бұрын
I feel like Java should have done something simillar to what Kotlin does with classes that have grand-parents (Fun fact, Kotlin kind of implement multi-inheritance, tho it is quite complicated and I never touched it) When a class is 3 layer of more, you can do super.function() to choose which version of the function you want So if we have ClassA, ClassB that is a subclass of ClassA and ClassC that is a subclass of ClassB, if they all implement the function "foo()", with ClassC, when you do "foo()" it will do ClassC foo(), if you do super.foo() (or super.foo()) it will do ClassB foo() instead and finally, if you do super.foo(), it will do ClassA foo() I feel like Java should have implemented something like that (detect when an ambigious function is called and cause an error if it cannot choose) Tho I fully agree that Multi-inheritance is extremely rarely useful
@the00one45
@the00one45 2 жыл бұрын
Hello John, nice video! Quick off topic question: I've seen that you have switched from Eclipse to IntelliJ in your videos. Is there a specific reason why? I've heard a lot of people praise it, but besides some preferences never seen the great benefit.
@Rnhardt542
@Rnhardt542 2 жыл бұрын
I can tell you my experience, I was obligated to use Eclipse on one of my projects, HATED IT. From navigation to ease of using plugins and most especially, code suggestions. No matter what I could think of, any action I needed to take in Eclipse I could cut it in half in Intellij, at least this was my experience.
@harleyspeedthrust4013
@harleyspeedthrust4013 Жыл бұрын
because eclipse is shit. try installing a plugin, any plugin. you can't! eclipse just can't do it without throwing some fatal error. and how about that UI? it has no right to be so complicated. good luck importing an existing project into eclipse without fucking it up somehow. and good luck creating a git repo that doesn't have an extra top-level folder...
@dashknow5082
@dashknow5082 Жыл бұрын
Topic Suggestion : Shallow Copy vs Deep Copy of List or any Collections in Java
@CodingWithJohn
@CodingWithJohn Жыл бұрын
I like it, it's on the list!
@nitika9769
@nitika9769 Жыл бұрын
keep making these videos, get to learn so much from from you
@kikoalbiol
@kikoalbiol 2 жыл бұрын
Multiple inheritance is not designed to provide a dog+cat child diamond problem, in fact you can have compiler problems doing so. Multiple inheritance is to adress what was latter provided in Java by interfaces. So multiple inheritance is required in many many problems to provide elegant solutions about what is in an object. The reason is that you can inheritate from an implemented class and this is not posible with interfaces where you must rewrite everything.
@JamieCrew
@JamieCrew 3 ай бұрын
Am I correct in saying that Method Resolution Order is that ruleset that other languages use to decipher multiple inheritance prioritisation?
@gonegahgah
@gonegahgah Жыл бұрын
The other important hiccup with the diamond problem is that if both classes (ie dog and cat) need to both adjust something when a method call occurs, but only one is called, then part of the functionality that should occur does not. Either the dog or the cat fails to do its tandem essential action. There is also the problem where, if dual action is resolved and done, that the cat and dog may try to do the same action in animal when that action is only required once. If they for example both incremented a counter in animal it could be problematic...
@toby9999
@toby9999 2 ай бұрын
The cat / dog example is the wrong one to be using for knocking multiple inheritance.
@gonegahgah
@gonegahgah 2 ай бұрын
@@toby9999 One year ago, wow! That is the problem I encountered. Please elucidate the accurate example?
@darkferiousity
@darkferiousity 2 жыл бұрын
This cog class got my head grinding gears.
@matiturock
@matiturock Жыл бұрын
Could you make a video explaining the principles SOLID, DRY, KISS, and more?
@lorenzmuller5083
@lorenzmuller5083 2 жыл бұрын
Awesome video! Question: is the @override annotation necessary or could it be omitted when implementing the interface methods? If so, when do we need it?
@JorgetePanete
@JorgetePanete 2 жыл бұрын
Override doesn't compile if there is not method to override (for example, when its name changed), if you had no override it wouldn't warn you
@Axel_Andersen
@Axel_Andersen Жыл бұрын
Nice video: couple of comments. Someone somewhere mentioned that Erlang handles multiple inheritance particularly nicely. Being a Java programmer who doesn't want to expand to esoteric languages I have never bothered to find out if this is true or not. I find it odd/wrong that you draw the arrow in the class hierarchy from parent to child. It makes little sense that no parent know about its children and in reality no class knows about the classes that extend it. Not a big deal, but I had to get this off my chest. About interfaces, yes, they are useful and have their place. However with the kind of software that I develop I often want to know what happens when I call a particular method (most of the code is internal to the project so I can and need to check that). If the object type is an interface it is a nuisance cause the IDE does not know the implementing class and thus cannot take me to the code that actually gets called.
@bauckrob
@bauckrob Жыл бұрын
There was a time, long ago, where people thought that extending classes and some of their methods was a great idea. By extending methods, one had a situation where the method in the child would call its base/super class' method, and add some extra behaviour. But which parent should we be calling? In C++, the programmer have to choose. In Python, every class has a "method resolution order" where in this case, a Cog would have Cog -> Cat -> Dog -> Animal. In general, people also thought that mixin classes, e.g. classes that would slightly change some behaviour by overriding methods, was a good idea. It seems like these ideas are mostly gone, however. It might work in the examples, but not in the real world, and modern design tends to have replaced the need for mixins and similar with smaller policy classes/functions. One can ask: If java was designed Today, would it have inheritance at all?
@harleyspeedthrust4013
@harleyspeedthrust4013 Жыл бұрын
if java was designed today it would surely be the same outdated pile of long words that it is right now. generics would be done just as badly, everything would need to be in a damn class, the standard library would still be littered with long names, and function types would still be clunky and ugly. inheritance is overrated and is a good solution to a niche set of problems. most of the time you don't need inheritance and trying to use it slows you down. java encourages you to overengineer your code by forcing you to use inheritance when you probably want something better
@motivationalthinking71
@motivationalthinking71 Жыл бұрын
Hey John, could you explain which IDE is better for Java, Eclipse or IntelliJ IDEA? I was a follower for a couple of months and just realized you switched your ide in the last year.
@CodingWithJohn
@CodingWithJohn Жыл бұрын
I generally prefer IntelliJ these days but I used Eclipse for years and it's great too. I started the channel with Eclipse but ended up doing a poll of viewers and a clear majority were using IntelliJ. So I thought it would be better to use IntelliJ than Eclipse in my videos for that reason.
@cyberkiller83
@cyberkiller83 2 жыл бұрын
Considering that java now supports implementations on interfaces and you can implements from multiple interfaces... so if you have one methjod implementation by each interface, could you be running ons ome kind of diamon problem here?
@chethans7436
@chethans7436 2 жыл бұрын
You can't implement a method in an interface. Hope this helps 🙌
@CodingWithJohn
@CodingWithJohn 2 жыл бұрын
Right, you can have default implementations in interfaces now. To answer your question, if you implement two interfaces that have the same method, both with default implementations, it just won't compile. You are then forced to either add your own implementation or remove one of the interfaces. Give it a try and check it out!
@chethans7436
@chethans7436 2 жыл бұрын
@@cyberkiller83 Yes, that's right.
@cyberkiller83
@cyberkiller83 2 жыл бұрын
@@CodingWithJohn Thank you John. I love your videos, i feel they make me a better developer.
@DerDoMeN
@DerDoMeN 2 жыл бұрын
@@CodingWithJohn That's definition of multiple inheritance while banning diamond inheritance... But some people have to bend over backwards to pretend it's not. I now remember a few (~7 or maybe even more) years ago when I saw that Java got this feature - I was at work and started laughing and then saying to my co workers "is Java trying to become a useful language :) Thanks for reminding me :) So to be honest maybe the initial creator didn't like multiple inheritance but Oracle/later maintainers after the initial author left, certainly disagree with him :)
@johannes7110
@johannes7110 2 жыл бұрын
I'm learning java and started with intellij but then I switched to eclipse and do not look back. I like your older videos where I could follow along better since you use eclipse. Why did you switch to intellij, do you think it is better?
@ChrisAthanas
@ChrisAthanas 8 ай бұрын
Eclipse is deprecated and JetBrains is multiplatform Do the math!
@tomok284
@tomok284 2 жыл бұрын
Thanks for sharing. Could you make a video about the differences between abstract class and interface and when uses which?
@asyakatanani8181
@asyakatanani8181 Жыл бұрын
Well, John, very clear and to the point. I like it, thanks...
@santi9775
@santi9775 Жыл бұрын
Amazing explanation! I have just one suggestion for future videos: I tend to see your videos at night, everything good when you’re writing code, but when you use the board it hurt my eyes! Haha Just a silly suggestion, really appreciate your videos! :)
@CodingWithJohn
@CodingWithJohn Жыл бұрын
I'll try and use a dark background on the board next time!
@santi9775
@santi9775 Жыл бұрын
@@CodingWithJohn Thanks! :)
@4srinivas
@4srinivas Жыл бұрын
That must have been an intense discussion
@ripanpramanick425
@ripanpramanick425 Жыл бұрын
It would be really helpful if you could bring some Design pattern videos
@gabrieljonsson7821
@gabrieljonsson7821 Жыл бұрын
I don't think Java needs multiple inheritance, but I do think to be more flexible it should at least support friend classes. Many problems that at first glance would need it could in fact be solved with a combination a member of the other class combined with the friend operator of C++. So why is there no friend operator in Java? And no I don't think package private concept cuts it.
@talk9415
@talk9415 2 жыл бұрын
perfect explanation, I was wondering, do you only have the basic JAVA course? or do you have something more advanced and professional as spring boot? I would love to purchase.
@CodingWithJohn
@CodingWithJohn 2 жыл бұрын
Just the one Java course for now. I do plan to have a spring boot one next, but it will definitely take time to put together.
@SamKhan-kb3kg
@SamKhan-kb3kg 2 жыл бұрын
Great elaboration, absolutely loved this video
@mouradvip7
@mouradvip7 Жыл бұрын
Hello John, Great content as always, you have a natural gift of explaining complex concepts, and I bet you can explain Design Patterns to a toddler. it will be delightful if you can upload a video on Java Streams API. Much Love.
@CodingWithJohn
@CodingWithJohn Жыл бұрын
I do have a toddler son, so I'll have to give that a try!
@ceceliadixon765
@ceceliadixon765 Жыл бұрын
Hey John, would you please do a video on double dispatch :)
@blazernitrox6329
@blazernitrox6329 2 жыл бұрын
To be fair, Java has multiple inheritance in a round-about way with interfaces, and I feel like that's 99% of the use case for multiple-inheritance in C++. The vast majority of the time I don't use multiple inheritance, and even when I do it's usually inheriting from a base class and some other pure-virtual class (much like an interface). Of course, I started with Java and C#, so maybe that's my past experiences shaping how I work in C++.
@nandhineeneelakandan8156
@nandhineeneelakandan8156 Жыл бұрын
Love your videos. Can you do one executor service?
@Daxbedivlogs
@Daxbedivlogs Жыл бұрын
Thanks for valuable content John... looking forward to Advanced java and framework topics as Spring, SpringBoot, completeable Future or Multithreading, Microservices etc @John
@brunogreco290
@brunogreco290 Жыл бұрын
Hello, please a vídeo of Functional Interfaces. Predicate, Consumer, Supplier
@AllanAquinoVieira
@AllanAquinoVieira Жыл бұрын
Is it possible to declare an optional methods in an interface, or all methods declared in an interface must be implemented?
@kchemutai3483
@kchemutai3483 Жыл бұрын
I actually enjoyed it. Thank you
@saipavan5032
@saipavan5032 2 жыл бұрын
Great Video, It would be great if you can make a video on Interfaces as well.
@mastershonobi110
@mastershonobi110 2 жыл бұрын
Great video. Thanks for the review. 🙌🏿🙏🏾
@aamirshekh934
@aamirshekh934 2 жыл бұрын
we want more conceptual java video like: Streams
@richskater
@richskater 2 жыл бұрын
I was certain that if you didn't specify the access level of a field it would default to protected. Blew my mind that you had access to .name in the main method; I had to go try it for myself. Learned multiple things on this one.
@harleyspeedthrust4013
@harleyspeedthrust4013 Жыл бұрын
It defaults to "package-private," meaning that the field is only visible to classes in the same package. There is no "package-private" keyword so the only way to make a field package-private is to leave the access modifier off. Doesn't make any damn sense for a language that's trying to be simple and explicit
@artworld9799
@artworld9799 Жыл бұрын
Very beautiful and interesting work!!
@omerisk8934
@omerisk8934 2 жыл бұрын
Hey, You are doing a great job thank you for much for all efforts. When you explain a concept it is easy to get the logic but to make it more clear for us would you mind doing some implementation videos from basic to advanced ? Thanks in advance..
@dhilip77
@dhilip77 Жыл бұрын
Can you explain list
@redcrafterlppa303
@redcrafterlppa303 2 жыл бұрын
Can you please make a video about the java9 module system.
@henriquesenadev2194
@henriquesenadev2194 2 жыл бұрын
Nice video bringing core concepts and a good mood!
@charleswelty2735
@charleswelty2735 2 жыл бұрын
I couldn't find where to buy your Java text. Shop takes me to Area 120. Is that where the store is?
@CodingWithJohn
@CodingWithJohn 2 жыл бұрын
I should remove that shop option, it's just not working right. There should be a link in the description.
@gohardovlatyan6003
@gohardovlatyan6003 Жыл бұрын
This is brilliant, thank you so much
@lovetyagi5266
@lovetyagi5266 2 жыл бұрын
please make video on java multithreding and cuncurrency
@achetadomesticus
@achetadomesticus 2 жыл бұрын
Thats the reason for me to Extends the Suscribe class and implement the Like interface ❤ Derpalerp!!
@JohannesJurieCoetzer
@JohannesJurieCoetzer Жыл бұрын
Looks like good classes, only bad thing is that it is not organized into a followable course.
@purplestuffist
@purplestuffist 2 жыл бұрын
This video is amazing. Thanks for sharing this important information! Thanks John :)
@anketpatel2312
@anketpatel2312 Жыл бұрын
Hello . . I think 2 interface with same default method can have the same issue like dimand problem . But we must have to implement it and have to define which one we want to call. Like super.Interface.default();
@CodingWithJohn
@CodingWithJohn Жыл бұрын
When you implement two interfaces with the same default method, it's a compilation error that you can only resolve by implementing that method yourself
@bruhmoment1835
@bruhmoment1835 2 жыл бұрын
7:45 That's a terrible argument for not having a feature. Everything can be written in asm, there's no reason for anything beyond the x86 instruction set.
@-karter-4556
@-karter-4556 Жыл бұрын
can you do a video on sockets?
@maninswe2
@maninswe2 2 жыл бұрын
Wanna see a video on Streams 😁🙏
@naveenchowdary2998
@naveenchowdary2998 2 жыл бұрын
Could you teach c# in this way coz it's very effective
@luischavarria6104
@luischavarria6104 2 жыл бұрын
John is there any book I may read for good practices at programming?
@CodingWithJohn
@CodingWithJohn Жыл бұрын
My favorite is Clean Code. I have some links for it in the description!
@alejandrobravo1221
@alejandrobravo1221 2 жыл бұрын
Hi teacher, what theme are you using?
@CodingWithJohn
@CodingWithJohn 2 жыл бұрын
Just the IntelliJ default dark theme, with the background manually darkened a little more
@malakabuhejleh358
@malakabuhejleh358 Жыл бұрын
It’s very helpful thank you
@MrAikien
@MrAikien Жыл бұрын
Great video! Thanks! 👌👍
@mukynas
@mukynas 10 ай бұрын
What's the point of implementing interfaces if I then have to write again every single method that I implemented in the class?
@fraidoonhu9284
@fraidoonhu9284 2 жыл бұрын
Great man Great video Great language And a great "I don't believe you"
@wolfrikz7238
@wolfrikz7238 2 жыл бұрын
Please do a tut on 'Serialization'
Java Reflection Explained - bɘniɒlqxƎ noiɟɔɘlʇɘЯ ɒvɒᒐ
20:07
Coding with John
Рет қаралды 186 М.
Кәсіпқой бокс | Жәнібек Әлімханұлы - Андрей Михайлович
48:57
Ouch.. 🤕⚽️
00:25
Celine Dept
Рет қаралды 21 МЛН
Cool Parenting Gadget Against Mosquitos! 🦟👶 #gen
00:21
TheSoul Music Family
Рет қаралды 32 МЛН
Vectors in Java: The 1 Situation You Might Want To Use Them
16:13
Coding with John
Рет қаралды 83 М.
Checked vs. Unchecked Exceptions in Java Tutorial - What's The Difference?
10:14
How To Use Bitwise Operators in Python
7:57
Taylor's Software
Рет қаралды 417
.equals() vs. == in Java - The Real Difference
8:48
Coding with John
Рет қаралды 191 М.
LinkedList vs ArrayList in Java Tutorial - Which Should You Use?
11:43
Coding with John
Рет қаралды 599 М.
Generics In Java - Full Simple Tutorial
17:34
Coding with John
Рет қаралды 1,1 МЛН
Lambda Expressions in Java - Full Simple Tutorial
13:05
Coding with John
Рет қаралды 756 М.
Array vs. ArrayList in Java Tutorial - What's The Difference?
17:36
Coding with John
Рет қаралды 539 М.
Selection Sort Tutorial in Java: The Snail's Guide to Sorting
14:17
Coding with John
Рет қаралды 56 М.