how to wrire a class which produces only one object.

will that be done by declaring class as a synchronized

[61 byte] By [kanike.rajesha] at [2007-11-27 11:26:03]
# 1

Are you thinking of a singleton? Google it if you don't know what it is.

hunter9000a at 2007-7-29 16:08:09 > top of Java-index,Java Essentials,Java Programming...
# 2

> will that be done by declaring class as a synchronized

No.

Read up on the singleton pattern.

E.g. here:

http://en.wikipedia.org/wiki/Singleton_pattern

dwga at 2007-7-29 16:08:09 > top of Java-index,Java Essentials,Java Programming...
# 3

dont forget to look at the pitfalls as well!!!

kilyasa at 2007-7-29 16:08:09 > top of Java-index,Java Essentials,Java Programming...
# 4

And don't bother with any fancy "oh, this factory method allows for lazy loading of your singleton" either. Keep it simple!

georgemca at 2007-7-29 16:08:09 > top of Java-index,Java Essentials,Java Programming...