Last week, we had the author of TDD for a Shopping Website LiveProject. Friday at 11am Ranch time, Steven Solomon will be hosting a live TDD session just for us. See for the agenda and registration link
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Jeanne Boyarsky
  • Tim Cooke
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Frits Walraven
Bartenders:
  • Piet Souris
  • Himai Minh

some doubts in core java

 
Ranch Hand
Posts: 32
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi,
i have some doubts in some core java topics. i am writing list of the questions. thanks a lot in advance.

1) can we clone a singleton instance? do we need to implement clonable interface for this? if so then why because clone method is available in Object class.
2) If we clone the object it will loose its singleton property. so to stop cloning what we can do?
3) if we serialize an object and De serialize it twice how many objects we will get?

 
lowercase baba
Posts: 13050
67
Chrome Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If an object is meant to be a singleton, then you probably don't want to let it be cloned. Therefore, you should not implement the cloneable interface. And if you don't, calling the clone() method inherited from the Object class throws an exception, if i recall correctly.

So the answer to #2 is to not implement the cloneable interface.
 
Ranch Hand
Posts: 57
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Kaushik Baral wrote:
3) if we serialize an object and De serialize it twice how many objects we will get?



Why don't you write some code to find the answer?
 
Ranch Hand
Posts: 326
Android Mac OS X Firefox Browser
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Good article on clone in Java.

http://en.wikipedia.org/wiki/Clone_%28Java_method%29
 
Marshal
Posts: 75697
354
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Or you might find the 3rd chapter of the old edition of Bloch's Effective Java™ here. That tells you about clone(). Remember it is the old edition.
 
I didn't like the taste of tongue and it didn't like the taste of me. I will now try this tiny ad:
Free, earth friendly heat - from the CodeRanch trailboss
https://www.kickstarter.com/projects/paulwheaton/free-heat
reply
    Bookmark Topic Watch Topic
  • New Topic