Shallow Copy vs Deep copy, Cloning: Shallow copy is the Object.clone() implementation. If an object being copied has a reference to another object, aside from primitive types and immutable classes, then only the reference is copied. The object that the reference points to is not cloned. A deep copy is where the clone method is overridden for the copied object and all objects it holds references to, else code would not be able to call Object's protected clone() method on those objects. The object returned now has copies of all objects inside of it with copies of any objects inside those, and so on. Primitive values and immutable objects are copied normally.
Marker Interfaces: Serializable, Clonnable, Remote, Test... Interfaces that "mark" the class as available for some function to the compiler. The marker interface usually has no methods to override and is used really to classify code in certain ways. It is possible to mark a class as implementing ThreadSafe, for example, when the class has passed all programmer checks for thread safety. It seems though that using annotations to do this is a better, more readable option.
Annotations: @Documented, @Override, @SuppressWarnings, @Deprecated
Annotations have no direct effect on the compiler or the code it is trying to compile. However, annotations can inform the compiler to make checks on certain things, like in the case of @Override where, because of the annotation, the compiler can check to make sure the overriding method has implemented the superclass method properly. @SuppressWarnings({"unchecked", "deprecation"}) suppresses the two categories of warnings. The compiler warnings have no effect on runtime performance of the application, but do crop up to warn the programmer of unintended or faulty behavior can occur given the situation, typically when using raw collections instead of typed ones.
Thread Safe code: Writing thread safe code can be done in a few ways. Marking a method "synchronized" will make threads unable to call that method at the same time. Using immutable objects or synchronized objects like vector, hashtable, String, etc. Copying variables to the local scope and using those local variables is another way to achieve thread safety in code.
No comments:
Post a Comment