byte length = fileReadBytes[xyz]; //say 0xb0 short unsignedLen = length; //its 0xffb0 unsignedLen &= 0x00FF;
public class TestLoopThread { public static void main(String[] args) { { LoopThread lThread = new LoopThread(); lThread.start(); //NOTE: if exit() is not present loop thead continues and main thread waits. //if exit() present, main thread also exits. //System.exit(0); } class LoopThread extends Thread { public void run() { String s= "LoopThread: looping..."; while(true){ System.out.println(s); try {Thread.sleep(500);} catch (Exception e) {;} } } }
public class SimpleBean implements java.io.Serializable { private String name = null; /* Empty Constructor */ public SimpleBean() {} /* Getter and Setter Methods */ public String getName() { return name; } public void setName(String s) { name = s; } }
The only strict principles that you must follow for clone are:
This is what is known as a safe clone. There are cases where it may make sense to provide what is called a shallow clone, especially with collection classes. Such a shallow clone only duplicates the top-level structure of the object, not the lower levels. A shallow clone is useful in many circumstances so long as programmers can somehow still implement a deep clone on top of those objects. Ideally, such classes would implement both with different names.
A safe clone is different than a deep clone, which copies the object and all of its fields recursively. A safe copy does not need to copy any field that is irrelevant to Clone Independence. For example, a String field does not need to be cloned. Because Strings are immutable, even if one String is shared by two objects, the contents of the string cannot be changed, and thus cannot break Clone Independence. Similarly, if a field cannot be altered through the class API, then it can be shared between two objects without breaking Clone Independence.