• 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
  • Ron McLeod
  • Paul Clapham
  • Tim Cooke
  • Devaka Cooray
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Rob Spoor
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Piet Souris
  • Mikalai Zaikin
Bartenders:
  • Carey Brown
  • Roland Mueller

cloneable

 
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello,
Can you throw more light on the cloneable interface in Java.
** Its significance
** Applicability
Preferably with an example.
Vrinda
 
Ranch Hand
Posts: 18944
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The clonable interface is implemented by any class that supports or overrides clone() method. The Clone interface declares no method. A class can implement Clone() interface to indicate that it is legal to make a field for field copy of the instance of that class using Object.clone() method.
Clone() interface has the following 3 direct Sub-Interfaces:
1>AclEntry - Used for representing an entry of WIN NT Access Contol List. ACL is used to specify user permissions in WIN NT.
2>AttributedCharacterIterator - to allows iteration through both text and related attribute information.
3>CharacterIterator - defines a protocol for bidirectional iteration over text.
Hope this helps !
Regds,
Milind
 
Sheriff
Posts: 5782
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Vrinda,
As for the Certification exam, it is very important to remember Arrays can be cast to a clonable interface. As Milind said, the Cloneable interface has no methods. It serves as a kind of tag to help JVM detect legal clones.
Expect questions in the exam where an array is cast to a cloneable interface.
<PRE>
public class CastArray
{
public static void main( String[] s)
{
String firstQuarter[] = {"Jan", "Feb", "March"};
Cloneable c = firstQuarter ;
}
}
</PRE>
Well, this code does nothing, however it compiles fine
In the real world, Cloneable can be a very useful interface. You can implement "deep copy" of the objects in your system by using the Cloneable interface and providing a clone() method implementation in your objects. Remember when you say Obj1 = Obj2, you are only copying references. Unless you implement your own cloning, there is no way to produce replicates of your objects with state information.
Hope this helps.
Ajith
 
She'll be back. I'm just gonna wait here. With this tiny ad:
We need your help - Coderanch server fundraiser
https://coderanch.com/wiki/782867/Coderanch-server-fundraiser
reply
    Bookmark Topic Watch Topic
  • New Topic