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 Жыл бұрын
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
@Riley-ml9vo2 жыл бұрын
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!
@pawewodarczyk15462 жыл бұрын
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.
@mariovelez5782 жыл бұрын
You explain these concepts really well. Even after 5 years of coding Java, I still learn from you
@Brahvim2 жыл бұрын
I have the same amount of experience and I agree with you!
@Sollace2 жыл бұрын
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.
@Djaenzee2 жыл бұрын
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...
@harleyspeedthrust40132 жыл бұрын
and then one day you realized, the best solution is just to not use java
@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 Жыл бұрын
@@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.
@rikschaaf2 жыл бұрын
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.
@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! 🎉
@JamieCrew4 ай бұрын
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!
@ShadoFXPerino2 жыл бұрын
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-dn3tf2 жыл бұрын
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.
@moomoomoo3092 жыл бұрын
Default implementations on interfaces are similar to MI for Java, so you could have used that, probably.
@gabrieljonsson78212 жыл бұрын
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).
@Quinteger2 жыл бұрын
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.
@jozef_franek2 жыл бұрын
maybe in this topic could have been mentioned implementation of method from two different Interfaces with same method signature
@CodingWithJohn2 жыл бұрын
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.
@DelzDerMeister2 жыл бұрын
The same logic could be applied to multi inheritance. The only thing that would be problematic are non-private fields.
@nonswag47392 жыл бұрын
Would be interesting to know why two similar methods but with different type parameters are not allowed in one class
@PieJee12 жыл бұрын
@@nonswag4739 in some strict languages that actually exists
@nonswag47392 жыл бұрын
@@PieJee1 I know, that's why I'm wondering why java does not allow this
@Tech_Publica2 жыл бұрын
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.
@joeysarie15202 жыл бұрын
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.
@andreassumerauer50282 жыл бұрын
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.
@dgront2 жыл бұрын
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.
@harleyspeedthrust40132 жыл бұрын
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
@Speiger2 жыл бұрын
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!
@kikoalbiol2 жыл бұрын
At the end Java arrived to same solutions that C++ and other older languages arrived 20 years before
@bluecup252 жыл бұрын
@@kikoalbiol Yeah, same for C#.
@ManosSef2 жыл бұрын
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.
@veggieboy12 жыл бұрын
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
@johngeverett2 жыл бұрын
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'.
@jbragg332 жыл бұрын
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.
@CodingWithJohn2 жыл бұрын
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?
@Sheikhhamiz2 жыл бұрын
@@baranosiu as far as I know multiple inheritance and mixins are two different things, mixins can be used to copy methods to prototype
@jbragg332 жыл бұрын
@@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 :)
@zhalagurbanzade6362 жыл бұрын
The explanation is very clear and concise. James Gosling would be envious.
@lucashenrique60762 жыл бұрын
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!
@ericpenrose36492 жыл бұрын
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?
@stephenJpollei2 жыл бұрын
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.
@DrSpooglemon2 жыл бұрын
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.
@harleyspeedthrust40132 жыл бұрын
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
@aminembh60942 жыл бұрын
Great video as usual! You do a fantastic work, it’s appreciated, we need more people like you 🎉
@thomaslong15762 жыл бұрын
I wish everyone could teach like you.
@deconline13202 жыл бұрын
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.
@TBiscuit12 жыл бұрын
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
@rubenlarochelle18812 жыл бұрын
An alternative could be to allow multiple inheritance for the cases without conflicts and only give out an error when a diamond happens...
@kikoalbiol2 жыл бұрын
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.
@RenderDragon2 жыл бұрын
Good video, especially at the end :)
@samluther26492 жыл бұрын
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.
@christopherbaviera1972 жыл бұрын
For instance, since makeNoise() is a behavior, could be implemented as an interface describing better animals possibilities
@satricon Жыл бұрын
Hahaha, this was awesome! I chucked at the "cog" fetch of "the cat does it if it feels like it" 😆
@JamieCrew4 ай бұрын
Am I correct in saying that Method Resolution Order is that ruleset that other languages use to decipher multiple inheritance prioritisation?
@nitika9769 Жыл бұрын
keep making these videos, get to learn so much from from you
@javalady6 ай бұрын
"I dont beleive you" was really good :))
@hz43532 жыл бұрын
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.
@AllanAquinoVieira2 жыл бұрын
Is it possible to declare an optional methods in an interface, or all methods declared in an interface must be implemented?
@darkferiousity2 жыл бұрын
This cog class got my head grinding gears.
@gonegahgah2 жыл бұрын
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...
@toby99993 ай бұрын
The cat / dog example is the wrong one to be using for knocking multiple inheritance.
@gonegahgah3 ай бұрын
@@toby9999 One year ago, wow! That is the problem I encountered. Please elucidate the accurate example?
@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.
@bauckrob2 жыл бұрын
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?
@harleyspeedthrust40132 жыл бұрын
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
@blazernitrox63292 жыл бұрын
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++.
@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?
@raphaelmateusdasneves7722 жыл бұрын
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
@schwingedeshaehers2 жыл бұрын
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
@schwingedeshaehers2 жыл бұрын
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
@raphaelmateusdasneves7722 жыл бұрын
@@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 { ... }"
@schwingedeshaehers2 жыл бұрын
@@raphaelmateusdasneves772 we have a function in one class that returns an Integer, and one, that returns a string. -> how should that be handled?
@raphaelmateusdasneves7722 жыл бұрын
@@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.
@rubenlarochelle18812 жыл бұрын
If I made a language, my pseudocode for the Cog would be: class Animal {...} class Cat inherits Animal {...} class Dog inherits Animal { function Fetch(...); ... } class Cog inherits Cat { from Dog import Fetch ... } Kinda feels more natural for the programmer, other than being simpler.
@the00one452 жыл бұрын
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.
@Rnhardt5422 жыл бұрын
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.
@harleyspeedthrust40132 жыл бұрын
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...
@johannes71102 жыл бұрын
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?
@ChrisAthanas9 ай бұрын
Eclipse is deprecated and JetBrains is multiplatform Do the math!
@lorenzmuller50832 жыл бұрын
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?
@JorgetePanete2 жыл бұрын
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
@gabrieljonsson78212 жыл бұрын
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.
@redcrafterlppa3032 жыл бұрын
Can you please make a video about the java9 module system.
@aamirshekh9342 жыл бұрын
we want more conceptual java video like: Streams
@motivationalthinking712 жыл бұрын
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.
@CodingWithJohn2 жыл бұрын
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.
@francoisemond35152 жыл бұрын
Thanks John, keep up the great work. I always look forward to watching your next video.
@cyberkiller832 жыл бұрын
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?
@chethans74362 жыл бұрын
You can't implement a method in an interface. Hope this helps 🙌
@CodingWithJohn2 жыл бұрын
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!
@chethans74362 жыл бұрын
@@cyberkiller83 Yes, that's right.
@cyberkiller832 жыл бұрын
@@CodingWithJohn Thank you John. I love your videos, i feel they make me a better developer.
@DerDoMeN2 жыл бұрын
@@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 :)
@dashknow50822 жыл бұрын
Topic Suggestion : Shallow Copy vs Deep Copy of List or any Collections in Java
@CodingWithJohn2 жыл бұрын
I like it, it's on the list!
@jaylawlmc19152 жыл бұрын
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
@kchemutai3483 Жыл бұрын
I actually enjoyed it. Thank you
@asyakatanani81812 жыл бұрын
Well, John, very clear and to the point. I like it, thanks...
@4srinivas Жыл бұрын
That must have been an intense discussion
@SamKhan-kb3kg2 жыл бұрын
Great elaboration, absolutely loved this video
@santi97752 жыл бұрын
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! :)
@CodingWithJohn2 жыл бұрын
I'll try and use a dark background on the board next time!
@santi97752 жыл бұрын
@@CodingWithJohn Thanks! :)
@shis102 жыл бұрын
Amazing Video. 🙌🏻 Please make full video on Interfaces, has relationship and is a relationship.
@dhilip772 жыл бұрын
Can you explain list
@talk94152 жыл бұрын
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.
@CodingWithJohn2 жыл бұрын
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.
@matiturock2 жыл бұрын
Could you make a video explaining the principles SOLID, DRY, KISS, and more?
@charleswelty27352 жыл бұрын
I couldn't find where to buy your Java text. Shop takes me to Area 120. Is that where the store is?
@CodingWithJohn2 жыл бұрын
I should remove that shop option, it's just not working right. There should be a link in the description.
@maninswe22 жыл бұрын
Wanna see a video on Streams 😁🙏
@BlueRey22 жыл бұрын
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!
@fraidoonhu92842 жыл бұрын
Great man Great video Great language And a great "I don't believe you"
@TheAnonymmynona2 жыл бұрын
Besides the mentioned solution to the Diamond problem, you could also limit the ban to just diamond shaped inheritance or force the programmer to overwrite conflicting methods (which seems like the best solution to me). So to me, the diamond problem is a very weak argument against multiple inheritance.
@artworld97992 жыл бұрын
Very beautiful and interesting work!!
@smallbluemachine2 жыл бұрын
Honestly, anyone that laid eyes on that feature in C++ should have rejected multiple inheritance. -I love C++, but that doesn't mean embracing every idea they throw into the standard.
@delarosomccay2 жыл бұрын
Multiple inheritance violates single responsibility. Assuming both base classes have a single responsibility, that would make the the inherited class have multiple responsibilities, hence it violates single responsibility. You can argue that it also violates Liskov, since it could potentially inherit features from one of the base classes that are not present in the other, therefore violating Liskov. Then there are problems inherit with multiple inheritance including the diamond problem. It usually, in my experience, results in hard to maintain code that is not very extensible. Again, violating another SOLID principle - the open/closed principle. After 10 years of C++ and another almost 20 years of C# and Java I have to say that, while it's possible with any framework or language to write poor code, C++ makes it so much easier to do so :). I lump C# and Java together, because to me they feel very similar. I feel that that experience with Java factored into the design of C#, because there are a lot of similarities between the languages. I think I remember reading that Java was kicking Microsoft to the curb in the business world, and in my experience I did see that Java quickly replaced C++ in the late 90s early 00s. Microsoft created C# as a result. To create a language that was type safe, garbage collected, and executed by a VM, so theoretically it could run anywhere. Although it took Microsoft over awhile before the last part was realized you can run C# on Linux - even ARM based Linux. You can run it on Macs - both Intel and Apple silicon. It's also freemium software, so you don't have to worry about licensing fees (Oracle - I give you the stink eye).
@harleyspeedthrust40132 жыл бұрын
solid principles my ass. talk about overengineering and YAGNI
@delarosomccay2 жыл бұрын
@@harleyspeedthrust4013 SOLID helps prevent those anti-patterns. SOLID isn't a pattern, it's a set of guidelines that you can use to make your code extendable and maintainable.
@andihuang86382 жыл бұрын
let alone multiple inheritance.. even single inheritance is hard to maintain.. remember, top rule in design pattern, prefer composition than inheritance.
@nonswag47392 жыл бұрын
Can someone recommend a good source for learning about jni or (preferred) panama?
@ripanpramanick4252 жыл бұрын
It would be really helpful if you could bring some Design pattern videos
@gohardovlatyan6003 Жыл бұрын
This is brilliant, thank you so much
@anketpatel23122 жыл бұрын
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();
@CodingWithJohn2 жыл бұрын
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
@mukynas11 ай бұрын
What's the point of implementing interfaces if I then have to write again every single method that I implemented in the class?
@lilygranger62642 жыл бұрын
Loved the video john! May you please making a video on interfaces?
@alejandrobravo12212 жыл бұрын
Hi teacher, what theme are you using?
@CodingWithJohn2 жыл бұрын
Just the IntelliJ default dark theme, with the background manually darkened a little more
@luischavarria61042 жыл бұрын
John is there any book I may read for good practices at programming?
@CodingWithJohn2 жыл бұрын
My favorite is Clean Code. I have some links for it in the description!
@ceceliadixon7652 жыл бұрын
Hey John, would you please do a video on double dispatch :)
@brunogreco2902 жыл бұрын
Hello, please a vídeo of Functional Interfaces. Predicate, Consumer, Supplier
@bruhmoment18352 жыл бұрын
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.
@achetadomesticus2 жыл бұрын
Thats the reason for me to Extends the Suscribe class and implement the Like interface ❤ Derpalerp!!
@toby99993 ай бұрын
I don't use multiple inheritance a lot (in C++), but it's good to have. Leaving it out of Java was the wrong decision, in my opinion. I get the purist argument, but I disagree with it.
@mrf1yn5612 жыл бұрын
Idea for next topic: Java Agents
@henriquesenadev21942 жыл бұрын
Nice video bringing core concepts and a good mood!
@naveenchowdary29982 жыл бұрын
Could you teach c# in this way coz it's very effective
@bacon374602 жыл бұрын
Another awesome video. Thanks John for your efforts. Could you please make a video for us about dependency injection (DI and IoC)?
@-karter-45562 жыл бұрын
can you do a video on sockets?
@MrAikien2 жыл бұрын
Great video! Thanks! 👌👍
@mastershonobi1102 жыл бұрын
Great video. Thanks for the review. 🙌🏿🙏🏾
@malakabuhejleh358 Жыл бұрын
It’s very helpful thank you
@lovetyagi52662 жыл бұрын
please make video on java multithreding and cuncurrency
@tomok2842 жыл бұрын
Thanks for sharing. Could you make a video about the differences between abstract class and interface and when uses which?
@JohannesJurieCoetzer Жыл бұрын
Looks like good classes, only bad thing is that it is not organized into a followable course.