Your thanks is all I require. I have no interest in money anymore so don't donate money. If you think others would like the site tell them about it and I'll be happy :)
@xipity7 жыл бұрын
Subject's explanation is crystal clear. Minor mistakes that mentioned in comments aren't that distracting. Thanks!
@derekbanas7 жыл бұрын
I'm glad it helped
@Karthik-yy6up9 жыл бұрын
Never thought about the problems that could arise with threading. This is a beautiful tutorial. Thank you Derek.
@derekbanas9 жыл бұрын
+Karthik Iyengar Thank you :) I'm glad that it helped.
@arisapostoloy72676 жыл бұрын
Your lessons are irreplaceable and exciting. Do not miss any elements of your personality. Keep calm and educate people.
@derekbanas6 жыл бұрын
Thank you for the nice compliment :) I'm happy it helped
@derekbanas11 жыл бұрын
You're very welcome :) I'm using Eclipse right now so I can't test it, but yes I'm pretty sure if you just delete the code block with if(firstThread) you won't any problems. Give it a try. There won't be any hidden errors, you'll see what happens immediately
@derekbanas11 жыл бұрын
Thank you :) It is always nice to hear that I cleared a topic up. No, I don't teach anywhere but on youTube. I plan on staying here for a while and everything will always be free.
@shibaramsahoo11 жыл бұрын
Thank you Derek for all your enthusiasm to put it together in a better way... We appreciate your hard work and your support. You Rock!! I just found your tutorials yesterday and been love with your website.. Great job!!
@javaidbolaky781711 жыл бұрын
Thump up man, your design pattern codes example was really really useful. Its 100% understandable than a reading a lot of books without really see how the design should be. Many Thanks for your dedication.
@nehaagrawal173011 жыл бұрын
I came across your tutorials on youtube and I feel blessed that I have found you. Your tutorials are so helpful. God bless you!! Keep up the good work!! Please make some tutorials on Java Concurrency.
@derekbanas11 жыл бұрын
Thank you :) It is great to hear that I cleared everything up. That is the best compliment I could get.
@Laura147HLY9 жыл бұрын
Love your tutorials, they are quick and concise, and to the point. Excellent!
@derekbanas9 жыл бұрын
Laura147HLY Thank you very much :)
@derekbanas12 жыл бұрын
Thank you :) I used them as one source, but also a bunch of others as well as friends for this. I'm glad it helped
@derekbanas11 жыл бұрын
You're welcome :) you use static classes when you are absolutely positive that every method will only be used in a utility type way. It is normally pretty easy to change a singleton if you require multiple instances down the road. That isn't true with a static class
@ajaisinghkhalsa9 жыл бұрын
Thanks Derek!!! Your tutorials are the best thing that happened to my life!! That was just some exaggeration, but they are pretty awesome.
@derekbanas9 жыл бұрын
Ajai Khalsa You're very welcome :) I'm very happy that I can help
@derekbanas12 жыл бұрын
Thank you :) I'll definitely cover JAX-RS in an upcoming tutorial. Thank you for the request. I've been holding off on Java networking stuff, but I'll cover it completely soon
@sambitkabi46178 жыл бұрын
Great one..The intention of Singleton pattern is very well fulfilled.But one thing I would like to suggest is that in multi-threaded environment we need to make the instance variable volatile. Making it volatile will prevent the re-ordering of the instructions and thereby avoiding undesired behavior.
@stepho6708 жыл бұрын
Can you be my professor? The world needs more people like you!
@derekbanas8 жыл бұрын
Thank you for the compliment :) I'm here for free when ever you need me
@derekbanas12 жыл бұрын
Thank you :) Yes, I'll cover Android as soon as I'm done with design patterns. Believe me the work you do here will make making android apps extremely easy
@StefioaneCy11 жыл бұрын
Watched a video in a course about singleton. It was 10 minutes long. I watched it five times and couldn't understand how singleton pattern works. I watched your video and got it in 3 minutes. I don't know if you do, but you should be teaching!
@derekbanas11 жыл бұрын
Yes you are correct. I sometimes try to cover all of the bases in these tutorials. You got it though. Thanks for pointing that out :)
@derekbanas11 жыл бұрын
Thank you very much :) I'm glad you found them useful. I will definitely cover enterprise design patterns, but I haven't covered JEE yet. I decided to make a truly complete java tutorial. i never figured it would take me 2 years to do it. At this rate I'll be making them for another 2 years since Android joined the tutorial.
@altapocalypse10 жыл бұрын
Liked a part about the threads, good explanation of the problem! Thanks
@derekbanas10 жыл бұрын
Vadym Ko Thank you :)
@derekbanas11 жыл бұрын
Thank you :) That is very kind to say. Yes I need to cover some of the topics that demand more attention Java wise. May God bless you as well.
@derekbanas11 жыл бұрын
Thank you :) I greatly appreciate the compliments. I'll try to live up to them. I'm getting very close to doing something very good. I can't wait to cover both games and the math behind them while at the same time cover electronics on a deep level. This is very fun for me.
@heikomeyer24897 жыл бұрын
The whole series on design patterns from you is awesome - thank you very much for your efforts on that! However in my opinion I think they would be twice as awesome if you would simply slow down - say about half the speed. No need to change anything else since the content is already great. Just give us 3 or 4 seconds every time you would otherwise flip to the next screen. For now I'm constantly doing play/pause and my mouse may quit service soon ;-)
@derekbanas7 жыл бұрын
Thank you :) Sorry about the speed. I hope to revisit this topic soon.
@derekbanas12 жыл бұрын
Thank you :) I'm not done with design patterns. I'll be looking at them further in my OOD and refactoring tutorial. Thank you for the request and I plan on covering that topic
@IbrahimAmer9211 жыл бұрын
no problem at all :) ... but your tutorials are still the best on the internet .You really helped me a lot your tutorials are much more better than any design pattern book . Waiting from you more videos and tutorials ;)
@Truthiness23112 жыл бұрын
Sitting here with my copy of Design Patterns (well trust and recommended), and have to say your coverage of usage is better. Thanks much ^.^
@derekbanas12 жыл бұрын
Thank you :) Believe me it makes me very happy to know I'm helping. Good luck on your test
@derekbanas11 жыл бұрын
Yes I was just trying to make a fun little program with it
@QLTEQ11 жыл бұрын
Oh man, these are great. So much that I've seen is making more sense now.
@gujaalsmanda8 жыл бұрын
great tutorial Derek i finally understood what each line does.
@derekbanas8 жыл бұрын
+gujaalsmanda Thank you :) I'm glad it helped.
@fedecacharelli10 жыл бұрын
in the video you typed the following line: System.out.println("2nd Instance ID: " + System.identityHashCode(newInstance)); so, you were calling the HashCode of the first instance.. (that was obviously going to return the same ID number) but in the source code you bring you've fixed this.. However, just wanted to thank you because you really helped me with these videos! Thanks again, greets from Argentina!
@MrSontiny11 жыл бұрын
well, I really look forward to seeing the topic. Anyway, the tutorial is easy to understand for beginners like me. Thanks a lot. Gotta wait the tutorial that you mentioned above.
@derekbanas12 жыл бұрын
Thank you for the input :) I'd love to expand on the different pattern flavors available and will very soon when I cover refactoring. This was a fun tutorial to make and I hope it helps people
@rogerf.175811 жыл бұрын
Hi Derek, really enjoy your tutorials. Helps an old C-programmer to get in to the modern design patterns. Though, just wanted to point out that it's not so good to use threads and this stuff directly. Where I work that is not allowed. We MUST use the concurrent packages to encapsulate all low level details. Perhaps that's a topic for some tutorials as well? Thaks for very understandable tutorials, I will see them all!
@derekbanas11 жыл бұрын
You're very welcome :) I made a little typo there. Sorry about that, but thank you for pointing it out
@mikesaddi11 жыл бұрын
Great video! BTW, I noticed that you wanted to get 7 letters, but used "
@derekbanas12 жыл бұрын
Thank you :) I'm not very good at scrabble, but I may make this into a fully functional game. I figured you guys would know how to do that though. Many game tutorials are coming!
@derekbanas11 жыл бұрын
It is used just as a precaution. Understand that some things that I do, I do because I was taught that way. We all pick up bad habits on our journey. I tend to always stay cautious :)
@derekbanas12 жыл бұрын
Are you talking about the thread part? I ran both threads using the same code so there wasn't a need to write separate code for each thread.
@nomissolution12 жыл бұрын
this person is so money, what a pimp of a programmer, this guy needs an award for being the best and for sure I'd buy a Derek action figure. he's the Jame Bond of software programmers, money!!!! Derek, I'm real good at scrabble, you wanna play scrabble game you just created, on-line?
@FatalRescue12 жыл бұрын
Whoa, I subscribed within the first 30 seconds....very cool presentation! You've saved lives :D
@sambitkabi46178 жыл бұрын
And yes just one thing to add , you can also use the Bill Pugh's singleton implementation which avoids the double checked locking and the synchronization is handled by the JVM itself.
@derekbanas12 жыл бұрын
Thank you :) That is the first time I've received credit for saving lives :D
@derekbanas11 жыл бұрын
Sorry about that. I'm getting better at avoiding mistakes. Yes, thank you for the short cut. I know them, but I don't use them in the video because I thought they may confuse people
@XCasperChristensenX9 жыл бұрын
You are my hero! best supplement for my school book(head first design patterns) - i must say u describe the things better! keep it comming! :D
@derekbanas9 жыл бұрын
+Casper Christensen Thank you for the nice compliment :) I'm glad they are helpful.
@derekbanas11 жыл бұрын
Thank you for pointing that out. I definitely need to make a Java Concurrency tutorial. Ill do my best to keep improving :)
@derekbanas11 жыл бұрын
Thank you :) Yes I return firstInstance to make sure there is only one instance. Maybe I should have used a better name. Sorry about the confusion.
@derekbanas11 жыл бұрын
I hope my tutorials were able to help. I wish you the best of luck
@discursion11 жыл бұрын
There is a mistake in your code when you are demonstrating that both "newInstance" and "instanceTwo" are sharing the same IdentityHashCode. In fact, you are printing twice the same object ID. I know it normally gives the same result, but you should add a note.
@demetrioreylago685610 жыл бұрын
Also the first player tiles are printed twice.... it looks like both players obtain the same set of letters which is not true.
@RolopIsHere10 жыл бұрын
I noticed the same!
@liedebunker12537 жыл бұрын
You are right. He made a mistake, although he is very good.
@omer88367 жыл бұрын
Derek Banas buddy you tutorials are helpful but I guess in this tutorial you made a mistake, you should definitely look into it, you are printing out the same object identityHashCode(newInstance) and playerOneTiles
@buildleadinnovate248 жыл бұрын
superb way of explaining....about all the program line by line!!! Really sometimes its hard to understand why something is done in certain way ad evething is use in some purpose!!
@derekbanas8 жыл бұрын
Thank you :) I'm glad it helped
@nicoapinedo4 жыл бұрын
I have to say, first of all, your tutorials are great, in this particular one there was only one section that had some issues and wasn't reflecting what you were stating during that part of the video (even though your statement was right, just not for that code). Around 11:00 the lines 21-27 for ScrabbleTest.java should be modified to: System.out.println("Instance 2 ID: " + System.identityHashCode(instanceTwo)); System.out.println(instanceTwo.getLetterList()); LikedList playerTwoTiles = instanceTwo.getTiles(7); System.out.println("Player 2: " + playerTwoTiles);
@mdfarooq71457 жыл бұрын
explanation is very neat and clean, Thank you Derek
@derekbanas7 жыл бұрын
Thank you :)
@derekbanas11 жыл бұрын
I use both eager and lazy initialization. I can tell you know the difference from your comment. I didn't bring up the difference because this tutorial is meant to be an easy to digest design patterns tutorial. I haven't really talked about the Java memory model yet, but I'll definitely bring this topic and others when I do.
@arthurmee10 жыл бұрын
Excellent video Derek. Thank you very much.
@derekbanas10 жыл бұрын
Thank you :) I'm glad it helped.
@derekbanas12 жыл бұрын
If you find it useful in your design use it. If not don't. What you'll find over time is that there are many people that like to argue about this stuff because they think it makes them look smart :)
@LegionL-A10 жыл бұрын
Thanks for the awesome tutorial! I'll point out this one little error that slipped in, when getting the letters you used for( i = 0; i
@derekbanas10 жыл бұрын
Thank you for pointing that out. Sorry about that :)
@LegionL-A10 жыл бұрын
Derek Banas Heh, don't be sorry! It's one of many mistakes just about everyone is going to keep making once in a while all the way to the end of their career! :) Awareness is key!
@pkamleshkr9 жыл бұрын
Derek you are really awesome :) Your tutorials are veryyyy gooood !!!
@derekbanas9 жыл бұрын
+kamlesh kumar Thank you :) I try to do my best
@Chaoticaa9 жыл бұрын
Excellent example on when you would want to use a Singleton. :D
@derekbanas9 жыл бұрын
Ali Almohsen Thank you :)
@derekbanas11 жыл бұрын
I'll have to look into that. Sorry about the error. They slip in every once in a while
@Lesterffx9 жыл бұрын
Thank you Derek I have learnt some useful methods which I never used before, such as Arrays.asList() and System.identityHashCode(). Also, I learn how to use the keyword/reserved word, synchronized.
@derekbanas9 жыл бұрын
+Lester You're very welcome :) I'm glad it helped.
@AlexTimification11 жыл бұрын
Thank you so much, I'm making a ChessGame, this tutorial was so friggin useful for me. Thank you so much one more time^^
@IbrahimAmer9211 жыл бұрын
Bill Pugh's method is the best .. It isn't using any special keywords (synchronized) to overcome multi threading problems and it's completly thread safe ... For more information read Singleton design pattern on wikipedia
@derekbanas11 жыл бұрын
Thank you very much :) I try to do the best I can
@586naveen7 жыл бұрын
best explained...... got the concept of Singleton... thanks
@derekbanas7 жыл бұрын
I'm happy it helped :)
@derekbanas11 жыл бұрын
Yes the code will only ever create one instance. Everything else is there to enforce that under any possible circumstance.
@ankitajain41949 жыл бұрын
Hi Derek nice explanation.Could you please also make one video of Singleton pattern using Enum and pros & cons of both approaches ?
@15bigdave8 жыл бұрын
I'm on mobile so I'm not sure if anyone has said anything. in your get tiles loop, it should be strictly less than instead of less than or equal to number of tiles. right now you're returning 8 tiles for getTiles(7).
@derekbanas8 жыл бұрын
+15bigdave Thank you for pointing that out. I'll look at it
@derekbanas11 жыл бұрын
I will soon, but I have my hands full at the moment with Android and C
@gopis1030 Жыл бұрын
This playlist is really helpfull ... Thank you so much Derek ...can u please tell some examples for singleton pattern
@antoniszewczyk59438 жыл бұрын
Hello Derek! Thanks for you tutorial again! What are the advantages and disadvantages of employing lazy instantiation? When should I use it and when it is not a good idea?
@derekbanas11 жыл бұрын
It may take a bit to get it. This is pretty high level programming. It definitely isn't a basic tutorial
@vijaykonduri13706 жыл бұрын
To complete the circle you may want to stop cloning of ur object and also the serialization and deserialization as well.
@michaelbrooks67136 жыл бұрын
Excellent lesson Derek, Thanks!!!!
@ananth31412 жыл бұрын
Very good and informative video. Derek- I have a request. Can you please make some videos on Web Services? This is the area I couldnt follow even after reading so many books and articles.
@robl3910 жыл бұрын
another awesome helpful video... you know what, I know this is an odd request but some x86 assembly language tutorials would be awesome. no one else has them!!! you'd definitely be the guy for the job.
@derekbanas10 жыл бұрын
Thank you :) Before I cover assembly I'd like to make an electronics tutorial that works towards creating a computer using nothing but basic components. I'd love to do that tutorial. I'm not sure if anyone would watch it though?
@aaronbernath40010 жыл бұрын
Derek Banas Coming from a current undergrad student taking x86 Assembly right now, I think that would be a great idea. I have a great teacher, but still, your videos are hard to beat. and +1 for that electronics tutorial. That would be really cool.
@derekbanas11 жыл бұрын
I'm sorry. Some times I write out code to explain what is going on. I write much of this out of my head, so I tend to write code like I write sentences. Thread.sleep() says to put the current thread to sleep. So I was saying in code that I wanted the current thread and then I will put it to sleep. Sometimes by explaining to much I guess I can cause confusion. Sorry about that :)
@derekbanas11 жыл бұрын
I'm glad I was able to help :)
@chongliu93399 жыл бұрын
thank you Derek , your video is great, helps me a lot!
@derekbanas9 жыл бұрын
chong liu You're very welcome :)
@smuralimohan111 жыл бұрын
Thanks Derek for the energetic videos. I have a question related to the concept of Singleton. In a singleton, If we were to maintain only a single 'instance' of a class, why maintain an instance at all? Why can't we just make the constructor private and make the rest of all methods static? What is the advantage of creating a single instance versus using a (static) class with all static methods?
@utsavprabhakar50724 жыл бұрын
Love the question man. I'll think about this and get back to you. I think this has something to do with concurrency and simultanous use of class variables. I'll have to check. Thanks again :)))
@derekbanas11 жыл бұрын
Sorry I'm only on KZbin, google+ and my own website
@detectivedonaldkimball4 жыл бұрын
Derek I have some Qs: In Singleton class, in the method: "public LinkedList getLetterList(){ return firstInstance.letterList;}" Can you just return letterList instead of firstInstance.letterList? It seemed to work the same when I tried. Also, in this example couldn't we just make ScrabbleLetters a static field, and thus avoid having to create a singleton class? Finally, instead of having a nullcheck in getInstance method, can't we just instantiate the firstInstance field where it is declared? Would that also make it thread safe rather than using synchronized?
@sahilrally449111 жыл бұрын
Thank you Derek Banas. :-) . I think you dont need to check firstThread boolean to show the multithreading problem, only Thread.sleep() would suffice and creates the same multithreading issues. I have heard that if we instantiate an object during the class creation, it is thread safe i.e private static Singleton firstInstance = new Singleton(); is totally Thread safe. Is it true ? and what is this called , i mean like the other way is called "Lazy"
@vaironxxrd11 жыл бұрын
They asked a lot about design patterns and oop concepts along with logic in my interview
@sanjeevkumaremail12 жыл бұрын
Hi..Videos are really helpful. Can you cover how singleton handles de-serialization ?
@issiahcantrell48377 жыл бұрын
Can you write synchronized on the private constructor to solve the problem as well?
@derekbanas12 жыл бұрын
If everyone started off the day singing, just think how happy they'd be :)
@derekbanas11 жыл бұрын
Wow I'd like to see your program! I'm very happy if I was able to help :)
@mohmaaya8312 Жыл бұрын
watching in 2023.
@derekbanas11 жыл бұрын
Thank you for the input. I should have covered that here :)
@asdf2568 жыл бұрын
Another way you could do this is by instantiating the Singleton instance in-line. You don't have to initialize it on a narrower scope.
@ericww327 жыл бұрын
YOU ARE AMAZING SIR!
@derekbanas7 жыл бұрын
You are to kind :)
@vladeb11046 жыл бұрын
Why is it so important to slow down first thread? doesn't synchronized(Singleton.class) statement make sure that only one thread will be executed at a time? i have deleted whole "slow down" section from your code and it still worked perfectly.
@anoophallur591410 жыл бұрын
Is there any need to make firstInstance static ? It could have been like any other regular field right?
@derekbanas12 жыл бұрын
I mainly just write mods that blow stuff up and make characters and weapons. I use Minecraft Coder Pack and Mod Loader
@TheSynergism11 жыл бұрын
Thank you... It was clearly explained..
@KoushaTalebian10 жыл бұрын
Great video. Just a quick question. Say that you instantiate your singleton in the declaration, i.e: // Instantiate here public static Singleton firstInstance = new Singleton(); // Then, the getInstance just returns the instance public Singleton getInstance() { return firstInstance; } Would this design: a) First the multi-thread problem b) Be disadvantage over lazy instantiation? Other than the advantage that lazy instantiation would only instantiate if the class needs to be, I don't see any other advantage.
@jaromirdobry83508 жыл бұрын
+Kousha Talebian For singletons, your example is also a lazy instantination because of lazy class-loading mechanism in Java. Of course, if someone does not load the class without using the singleton instance (which has usually no meaning), e.g., by writing: Class singletonClass = Singleton.class; // This will load the Singleton class if not yet done.
@HaiderKhanZ9 жыл бұрын
Just a thought but by looking at the tutorial wouldn't Stacks and Chars be better as an implementation here for singleton?
@samaabhinay8 жыл бұрын
In non-static methods like "getTiles", why did you use the object name to access a non-static variable? firstInstance.letterList Which is as good as just this.letterList since you're already in the object context.