Saturday, October 8, 2011

Design Patterns

Decorator PatternTo extend or modify the behaviour of ‘an instance’ at runtime decorator design pattern is used. Inheritance is used to extend the abilities of ‘a class’. Unlike inheritance, you can choose any single object of a class and modify its behaviour leaving the other instances unmodified. In implementing the decorator pattern you construct a wrapper around an object by extending its behavior. The wrapper will do its job before or after and delegate the call to the wrapped instance. Design...

Java Exception

What are the causes of exceptions in java?A java exception can be thrown only in the following three scenarios: (1) An abnormal execution condition was synchronously detected by the Java virtual machine. - When evaluation of an expression violates the normal semantics (Example: an integer divide by zero) - An error occurs in loading or linking part of the program - When limitation on a resource is exceeded (Example: using too much memory) (2) A throw statement was executed. (3) An asynchronous exception occurred. - The stop method (deprecated)...

Java Collection

Read Only CollectionsI do build crazy buildings using my collection of Lego blocks. My 11 months old kid Ben curiously stares at me build it. He always wishes to get hold of it. After I complete the building when I give that to his hand, you know what the first thing he does. Modify the building blocks. Though I wish them to be intact forever Lego buildings are built to be modified. But this is not the case in programming. You create a java collection and store objects in it. Then there are...

Abstract and Interface

What is a java marker interface?Java marker interface has no members in it. Marker interface ‘was’ used as a tag to inform a message to the java compiler. Java Marker Interface Examples: java.lang.Cloneable java.io.Serializable java.util.EventListener Lets take the java.io.Serializable marker interface. It doesnot has any members defined it it. When a java class is to be serialized, you should intimate the java compiler in some way that there is a possibility of serializing this java class. In this scenario, marker interfaces are used....