Well, though this is true there are certain things this might not protect the code from. For instance a serialized and then unserialized version could cause a conflict to where getInstance does not match the original instance, where Enum has taken care of such things. A corner case (ie: unlikely) but if one is writing a web application becomes very like as serialization happens a lot due to the application being over multiple servers.
Cool video dude .Thanx for sharing ur knowledge.one thing i would like to ask how to compile and execute a packaged source code without using the IDE. i work on windows xp and vista .
@bablobko well it is not as easy, you need to be able to use your command prompt. Which will mean adding an Environment Variable (if one doesn't exist) to point to your java library. If you don't have one you need to download the compiler from java.sun.com you will be redirected. Netbeans, Eclipse, IntelliJ should work on any current Operating System, just watch the videos on how to install and go from there. Have fun programming Java!
I do like to avoid singletons, though its not much penalty here at all, there are still issues when this object is serialized and deserialized of having more then one singleton, or different objects etc....
I dont mind the singleton method when coding for myself because it usually is not complex, and very simple to track.... Professionally however, one should use Enum, this is one of the things it was designed for.... Especially with threads!
Hi. I like your tutorias, especially wicket tutorials. Just one comment on Singletons. I think it would have been easy to make a private constructor on School instead of an enum.
Yes, that would indeed limit the issues in creating a constructor, though there might be some other issues whether thread safety, or serialization. That being said, when I make an app for personal use... I likely wont have threads or serialization, so private constructors would work just fine. That being said, why not use enums? I don't use them often so I stray away, but I like most Java developers should use them even though many programmers I am guessing don't.
just make the constructor private. this way you can't make an instance of the class.
so, when you want to get the current instance, you call a function like getInstance() and you're all set.
andreibranescu 10 months ago
@andreibranescu
Well, though this is true there are certain things this might not protect the code from. For instance a serialized and then unserialized version could cause a conflict to where getInstance does not match the original instance, where Enum has taken care of such things. A corner case (ie: unlikely) but if one is writing a web application becomes very like as serialization happens a lot due to the application being over multiple servers.
ProgramJava 10 months ago
Thanx for this video, it helped me alot :) keep up the good work!
fpcoolw 1 year ago
@fpcoolw Thanks for the support I appreciate it!
ProgramJava 1 year ago
Cool video dude .Thanx for sharing ur knowledge.one thing i would like to ask how to compile and execute a packaged source code without using the IDE. i work on windows xp and vista .
bablobko 1 year ago
@bablobko well it is not as easy, you need to be able to use your command prompt. Which will mean adding an Environment Variable (if one doesn't exist) to point to your java library. If you don't have one you need to download the compiler from java.sun.com you will be redirected. Netbeans, Eclipse, IntelliJ should work on any current Operating System, just watch the videos on how to install and go from there. Have fun programming Java!
Thanks for watching and leaving a comment.
ProgramJava 1 year ago
one thing i would like to ask how to compile and execute a packaged source code without using the IDE. i work on windows xp and vista
bablobko 1 year ago
you are already doing great job keep it up.
aelgali 1 year ago
Hi, you need to synchronize the block when u create the new instance to just to avoid having multiple instances.
public static MySingleton getInstance() { if (_instance==null) { synchronized (MySingleton.class) { _instance = new MySingleton(); } } return _instance;
}
aelgali 1 year ago
@aelgali
I do like to avoid singletons, though its not much penalty here at all, there are still issues when this object is serialized and deserialized of having more then one singleton, or different objects etc....
I dont mind the singleton method when coding for myself because it usually is not complex, and very simple to track.... Professionally however, one should use Enum, this is one of the things it was designed for.... Especially with threads!
ProgramJava 1 year ago
Hi. I like your tutorias, especially wicket tutorials. Just one comment on Singletons. I think it would have been easy to make a private constructor on School instead of an enum.
What do you think about? Regards.
leonardoauer 1 year ago
@leonardoauer
Yes, that would indeed limit the issues in creating a constructor, though there might be some other issues whether thread safety, or serialization. That being said, when I make an app for personal use... I likely wont have threads or serialization, so private constructors would work just fine. That being said, why not use enums? I don't use them often so I stray away, but I like most Java developers should use them even though many programmers I am guessing don't.
ProgramJava 1 year ago
singleton sounds lonely
qwertyfshag 1 year ago