What is Singleton Class in Java | Singleton Design Pattern Part 1

  Рет қаралды 440,705

Telusko

Telusko

Күн бұрын

Пікірлер: 156
@misubgify
@misubgify 8 жыл бұрын
thanks for clarifying singleton class. you are a genius. Respect!!! nobody explained it like you did here
@gauravnagar3712
@gauravnagar3712 7 жыл бұрын
+ Misu ZAMAN true totally agree with you
@LabDutta
@LabDutta 6 жыл бұрын
agree with u
@shaistakhalid7761
@shaistakhalid7761 5 жыл бұрын
Firstly, it was hard for me to understand the concept of Singleton pattern even after watching 4-5 videos, but your one video was more clear and was able to understand within few minutes. Thanks for the good stuff!
@rjlifeandtech8675
@rjlifeandtech8675 5 жыл бұрын
Nice explanation. Here I found that, Inside Abc class, "static Abc obj = new Abc();" is defaulted to a public statement, so, inside the main method, java will allow accessing directly static obj object. eg. "Abc obj1 = Abc.obj;", so getInstance() method is never needed to use. To fix this, we can mention like "private static Abc obj = new Abc();" and getInstance() method can be used now.
@gouthamrajesh2745
@gouthamrajesh2745 5 ай бұрын
Thanks 😇
@khalidben9940
@khalidben9940 7 жыл бұрын
It would so good if you gave it with a real life example.Syntax is easy to learn but the implementation in programming daily life problems is so important here. But the video and the explanation is amazing.
@jordirex7711
@jordirex7711 2 жыл бұрын
for example a class for the connection to the database
@gandamraviteja7019
@gandamraviteja7019 2 жыл бұрын
That;s the reason i love navin reddy tutorials he will just make viewers master in the concept what he is teaching Great man u are really great ALIEN..
@drunkmadala
@drunkmadala 2 жыл бұрын
Thanks, I wish I came straight to this post before searching around; you made this concept very easy to understand.
@luyandantabeni2513
@luyandantabeni2513 3 жыл бұрын
this is the most simple explanation of a singleton design pattern i ever came across, thanks a lot
@shubhamchopra5518
@shubhamchopra5518 6 жыл бұрын
I have completed the playlist, and this is the best explanation i have seen on singleton design pattern! Thanks a lot Naveen
@jonuriah5274
@jonuriah5274 3 жыл бұрын
A trick: watch series on Flixzone. I've been using them for watching lots of of movies lately.
@merricklawrence6793
@merricklawrence6793 3 жыл бұрын
@Jon Uriah yea, have been using flixzone for months myself =)
@eihodge
@eihodge 4 жыл бұрын
Thanks man! I have to make one of these for a project I'm working on. This is exactly what I needed to see.
@buildappswithevan
@buildappswithevan 2 жыл бұрын
Great video. Short and to the point. Good explanations.
@youyoudada2250
@youyoudada2250 7 жыл бұрын
Concise, straight to the point. Thanks for sharing your knowledge
@nitinsinging3204
@nitinsinging3204 5 жыл бұрын
Well done mate, amazingly you have explained this in just 5 mins for which I was seeing more than 20 mins videos. Good job 👍
@TheRaj78raj
@TheRaj78raj 8 жыл бұрын
simple and easy explanation...thank you so much sir for clearing my concept.
@dayanandswami8109
@dayanandswami8109 2 жыл бұрын
Very nice explanation sir. Keep making this type of valuable video always. Thanks a lot
@aparnaraj3342
@aparnaraj3342 3 жыл бұрын
Best explanation have ever found... thank you:)
@priyeshbhagat1004
@priyeshbhagat1004 5 жыл бұрын
Happy Teachers Day Sir. Learnt a lot from your videos. Thank you for sharing knowledge :)
@derryyeh
@derryyeh 2 жыл бұрын
Thanks. This is amazing explanation. Easy to understand!
@richardwilkins5241
@richardwilkins5241 2 жыл бұрын
Great explanation
@abvy25
@abvy25 2 жыл бұрын
Concise as always!
@VirajMavani
@VirajMavani 3 жыл бұрын
I agree with some of the comments here. The explanation is really good but an example would have helped a lot. One example for Singleton use is simply Database connections. You don't want more than one instance throughout the application.
@dollytiwari9707
@dollytiwari9707 2 жыл бұрын
you are amazing sir.
@jithinmv6516
@jithinmv6516 4 жыл бұрын
That was a perfect explanation. Thank you❤️
@ankush9386
@ankush9386 2 жыл бұрын
Thank you. Guys please like and share his videos. He really works hard. Thank you sir thank you so much.
@samartajshaikh2601
@samartajshaikh2601 Жыл бұрын
Thanks for explaining this topic so simply.
@shaileshrkumar6813
@shaileshrkumar6813 3 жыл бұрын
great video
@rajatvarshney2721
@rajatvarshney2721 4 жыл бұрын
clear cut to the point explanation
@AshutoshKumar-kq9vh
@AshutoshKumar-kq9vh 5 жыл бұрын
Thanks! The explanation was precise and easy to understand.
@bobybrahmam8653
@bobybrahmam8653 Жыл бұрын
We can also remove the getInstace method and can directly call the object by writing (Abc obj1 = Abc.obj) in main method
@chathuramahasen
@chathuramahasen 4 жыл бұрын
Thanks, sir. This really helps to get a proper understanding of the basics!
@danielendless
@danielendless 3 жыл бұрын
Best explanation of this. Saved me a whole lot of trouble and inefficient alternatives
@harshverm776
@harshverm776 6 ай бұрын
*Thanks for the playlist !!!*
@saifsms91
@saifsms91 3 жыл бұрын
Nice Explanation of Singleton :)
@ayushbagwari3496
@ayushbagwari3496 5 жыл бұрын
You make everything easy.Thanks keep it up
@_HarshitSharma
@_HarshitSharma 2 жыл бұрын
Simple and Amazing explanation!
@SasiKumarsachin12
@SasiKumarsachin12 8 жыл бұрын
very nice tutorial...i can easily understand with your explanation...thanks lot..now am prepare for interview this is very useful for me...thanks once again
@krishnakumarramachandran5888
@krishnakumarramachandran5888 4 жыл бұрын
Thanks for the clear Explanation of Singleton.
@poshettiakhil2664
@poshettiakhil2664 4 жыл бұрын
Awesome explaination of single ton pattern
@MUSTAFA2571992
@MUSTAFA2571992 8 жыл бұрын
Thank you, your explanation is very easy to get
@onerifat
@onerifat 2 жыл бұрын
nice and clear explanation
@nisithmondal7026
@nisithmondal7026 4 жыл бұрын
best explanation about Singleton Class
@Jolopy8000
@Jolopy8000 5 жыл бұрын
Top tier video on singleton right here! Awesome job
@DineshKumar-tn7pu
@DineshKumar-tn7pu 3 жыл бұрын
I have a question. We could have called the static variable in the other class main method, would have acted the same way as it is a static variable itself. Why we need a static method and call the static variable through the method?
@amranhossain7099
@amranhossain7099 6 жыл бұрын
You are a genius , Why don't you make tutorial on every design pattern???????????
@satya121prakash
@satya121prakash 3 жыл бұрын
Today I was asked this question in Java Back End Developer interview for Qualitest.
@ghanshyamb
@ghanshyamb 4 жыл бұрын
You are great style to explain problem scenario. On sidenote, let's keep class variable private.
@codethrusharing8955
@codethrusharing8955 2 жыл бұрын
excellent tutorial, thank you so much, easy to understand!
@janta42
@janta42 3 жыл бұрын
Thanks Naveen! for making java interesting
@mrwhite4137
@mrwhite4137 6 жыл бұрын
So clear Thank you
@utilbook7881
@utilbook7881 4 жыл бұрын
very good explanation. way to go Telusko
@MuazAtik
@MuazAtik 2 жыл бұрын
Amazing 🙏🙏🙏
@aratibugade5845
@aratibugade5845 6 жыл бұрын
Very nice explination...easy and simple...
@mannmerwana476
@mannmerwana476 Жыл бұрын
I awe you respect Sir,Can't thank you enough.🙏🏻 I never understood why do we use a private constructor in a singleton class ,when jvm has automatically a default public constructor defined. Got the answer,: To make it private and not allow clients to make objs with default constructor which is public by default,i.e to simple restrict the user from creating instance of the class . Greatful to you.🙏🏻🫡🙏🏻❣️💯
@johnyhawkahsan
@johnyhawkahsan 6 жыл бұрын
Great explanation! Thank you so much.
@iamsubhadas
@iamsubhadas 4 жыл бұрын
Excellent tutorial. Thank you, sir.
@mariusailisoaie183
@mariusailisoaie183 7 жыл бұрын
Great tutorial! Thank you for your help. I have a question: if we print the hash code of the obj1 and obj2 we get the same code twice. Why is that ? Should it not be only one hash code?
@bablugope2705
@bablugope2705 7 жыл бұрын
if you are getting different hashCode means your class is not singleton class.
@natalievajdova
@natalievajdova 5 жыл бұрын
Thanks, now I understand what Singleton is :-))
@tseponkalai6528
@tseponkalai6528 7 жыл бұрын
wow, only 4 minutes to explain something i have dreaded for the past year!
@priyaj5283
@priyaj5283 3 жыл бұрын
Thankyou for thIs beautiful explanation.. could you also includes the implementation of such concepts in a project
@LifeIsGood1992
@LifeIsGood1992 5 жыл бұрын
clear and concise !! thanks you
@samomamour8531
@samomamour8531 2 жыл бұрын
Thank you a lot 💫
@kostarev2000
@kostarev2000 4 жыл бұрын
The best explanation, thank you.
@abdifatahmohamed8600
@abdifatahmohamed8600 4 жыл бұрын
Thanks... that was straight forward!
@speedbumphu
@speedbumphu 6 жыл бұрын
Great explanation of the implementation.
@sarathbaiju6040
@sarathbaiju6040 3 жыл бұрын
i have a doubt, every time calling the getInstance() there is new instance of Abc class will create, so then how this approach follows singleton design pattern?
@vamsik3693
@vamsik3693 4 ай бұрын
in terms of automation can we implement singleton for creating driver instance where single driver instance can be used through out automation ?
@channelname8300
@channelname8300 4 жыл бұрын
ossssam clarifying man
@gajendraambewadkar7781
@gajendraambewadkar7781 6 ай бұрын
Nice, Thanks
@souravsantra4731
@souravsantra4731 8 жыл бұрын
thnx man.. Net & clean explanation .
@igorbarros3308
@igorbarros3308 5 жыл бұрын
congratulations!! great video
@vareshtuli
@vareshtuli 6 жыл бұрын
It is showing an error on class object "The field obj cannot be declared static in a non-static inner type, unless initialized with a constant expression" so make the class also static. Please let me know why it is so?
@ChrisSch258
@ChrisSch258 6 жыл бұрын
damn, thank you! short explanation and easy to understand now :)
@oguzaktas7277
@oguzaktas7277 6 жыл бұрын
Thanks good explanation.
@thisismm1907
@thisismm1907 4 жыл бұрын
why cant we use Abc.obj instead of Abc.getInstance()..? why should we create the getInstance() method? we can directly write : Abc obj1= Abc.obj; in main method.. please reply sir
@DineshKumar-tn7pu
@DineshKumar-tn7pu 3 жыл бұрын
That was my question too. It would have done the same thing.
@jayanthv5867
@jayanthv5867 2 жыл бұрын
yeah.. same doubt.. may be he could have declared it as private static obj
@TarekFaham
@TarekFaham Жыл бұрын
And, if the singleton needs to call a web service to fetch some values, where do you place the code? Do you place it inside the singleton class or outside?
@shashgo
@shashgo 6 жыл бұрын
navin, I am writing a web service using rest. How do I use the singleton pattern to create a list that will keep getting updated with new elements with every @POST? The problem is that if I use a regular constructor, then whenever the rest service calls that class using a @POST , a new instance of that class is created with the same elements as before, and so the new element added by the previous @POST request to that class does not persist. Now obviously, I can overcome this limitation by updating the date into a table, but is there a way to do this without using a table?
@ousamaelidrissi5886
@ousamaelidrissi5886 6 жыл бұрын
Thank you very much
@asishsahu8186
@asishsahu8186 6 жыл бұрын
i think this singleton class is not working in multi threaded environment and we the static variable is always loads at the time of loading the class so the object is stored in jvm memory if we dont use also the jvm memory will be waste
@NXNAWAFXN
@NXNAWAFXN 5 жыл бұрын
Thanks brother
@dannyyu4227
@dannyyu4227 6 жыл бұрын
thank! so simple
@arifahmed7855
@arifahmed7855 4 жыл бұрын
Boss of JAVA
@prithiviraj6797
@prithiviraj6797 6 жыл бұрын
Thanks bro..
@tsp57
@tsp57 3 жыл бұрын
Thank you
@ramkumaradimulam3430
@ramkumaradimulam3430 6 жыл бұрын
Is it not the otherway? Meaning, since obj needs to be static (so that its shared among all Abc instances), the getter getInstance() needs to be static.
@thellaidhinesh8929
@thellaidhinesh8929 5 жыл бұрын
what is the use of the singleton class in Java sir? and at what situation we use singleton ?
@raghuakuthota4900
@raghuakuthota4900 5 жыл бұрын
how about clone then, I can clon the existing object and I can create another object as well right?
@k0lbis
@k0lbis 6 жыл бұрын
thanks this helped so much!
@stefanelse
@stefanelse 5 жыл бұрын
Awesome, tnx bro,
@manindersingh6371
@manindersingh6371 3 жыл бұрын
Just adding some information here because I was facing the issue. We can create as many as instances inside the class because in the class we can access private constructor but we can't access it from outside the class.
@response2u
@response2u 7 жыл бұрын
Perfect! TNX
@joejones5746
@joejones5746 5 жыл бұрын
Thanks buddy
@youssh4975
@youssh4975 5 жыл бұрын
Would it make sense to declare such a class as abstract?
@natangurfinkel
@natangurfinkel 4 жыл бұрын
Thanks.
@sankarachelliah2872
@sankarachelliah2872 2 жыл бұрын
Hey! Is possible to pass arguments in singleton
@NileshKumar-mk2ze
@NileshKumar-mk2ze 6 жыл бұрын
Hello Sir, I have one question If Two threads are accessing the Singleton class object at a same time then what will happen or what problem will come and how we resolve such problem.
@piyush96arora
@piyush96arora 5 жыл бұрын
To solve your concern you could use synchronized keyword
@sagarghare9829
@sagarghare9829 7 жыл бұрын
Thanks sir!!
@inoxide5454
@inoxide5454 Күн бұрын
Student: Are you Reddy? Navin: Yes i am.
@kleavenae
@kleavenae 7 жыл бұрын
My way: public final class Singleton { public static final Singleton SINGLETON = new Singleton(); private Singleton() {} } usage: import static Singelton.SINGLETON; SINGLETON.method(); Is there any problem with that?
@nanashipersonne4151
@nanashipersonne4151 5 ай бұрын
I know how to make it now, but in what situations is this useful?
@manickam7231
@manickam7231 2 жыл бұрын
Bro y cant we use static class abc Insted of declaring an static abc object
@swapnilsrivastav3477
@swapnilsrivastav3477 9 жыл бұрын
If I use Reflection API then I can call private constructor ... So I wanted to ask if I am using Reflection API it means I can't implement concept of singleton ???
Singleton Design Pattern using Lazy Instantiation Part 2
5:31
Factory Design Pattern in Java
8:50
Telusko
Рет қаралды 505 М.
It works #beatbox #tiktok
00:34
BeatboxJCOP
Рет қаралды 41 МЛН
Chain Game Strong ⛓️
00:21
Anwar Jibawi
Рет қаралды 41 МЛН
Леон киллер и Оля Полякова 😹
00:42
Канал Смеха
Рет қаралды 4,7 МЛН
What is Singleton Pattern in Java - How to achieve this?
15:21
Naveen AutomationLabs
Рет қаралды 23 М.
#40 Encapsulation in Java
11:42
Telusko
Рет қаралды 215 М.
5 Signs of an Inexperienced Self-Taught Developer (and how to fix)
8:40
🔥Singleton Design Pattern in Detail | Multi-Threaded Environments  | Hindi
25:59
Learn Code With Durgesh
Рет қаралды 106 М.
Singleton Design Pattern | Implementation with details & code ✌🏻
21:09
Why Use Design Patterns When Python Has Functions?
23:23
ArjanCodes
Рет қаралды 113 М.
Singleton Pattern - Design Patterns (ep 6)
20:09
Christopher Okhravi
Рет қаралды 254 М.
13. Java Singleton and Immutable Class Explained with Examples | Java Classes in Depth - Part4
28:26
10 Design Patterns Explained in 10 Minutes
11:04
Fireship
Рет қаралды 2,4 МЛН
It works #beatbox #tiktok
00:34
BeatboxJCOP
Рет қаралды 41 МЛН