Posts

Showing posts from 2015

OOPS: Decomposition and Abstraction

When we write a a program and if the the code is expected to be less than few hundred of lines then we can afford to write a monolithic program but if the number of lines increase it becomes difficult  to maintain that program or adding new features to that program.  so how to handle this ? In order to write a program for a problem , the problem should be broken into multiple smaller problems and then each smaller problem should be solved  and make sure that solving all such smaller problem solves the actual , bigger problem. the process of breaking a problem into multiple smaller problem efficiently involves Decomposition and Abstraction. Definitions Decomposition- How to decompose large programming problems into small ones is called decomposition Abstraction - Abstraction is a way to do decomposition productively by changing the level of detail to be considered. In each iteration the irrelevant information can be removed. The process of abstraction can be seen as an app...
Generics Array Java does not permit the construction of generic array. Suppose, for example, that we want to design a class that has an array field public class Table<AnyType> { private AnyType[] contents = new AnyType[5]; ... } It's hard to understand, but this is illegal! A workaround is to construct an array of objects with a type-cast: public class Table<AnyType> { private AnyType[] stack = (AnyType[]) new Object[5]; ... } source - http://www.cs.cmu.edu/~adamchik/15-121/lectures/Collections/collections.html

Java threads

Thread Creation  There are two ways to create a thread. 1. Extend the  java.lang.Thread  class. 2. Implement the  java.lang.Runnable  interface. Thread states  A thread can be in one of the following states: NEW A thread that has not yet started is in this state. RUNNABLE A thread executing in the Java virtual machine is in this state. BLOCKED A thread that is blocked waiting for a monitor lock is in this state. WAITING A thread that is waiting indefinitely for another thread to perform a particular action is in this state. TIMED_WAITING A thread that is waiting for another thread to perform an action for up to a specified waiting time is in this state. TERMINATED A thread that has exited is in this state. A thread can be in only one state at a given point in time. These states are virtual machine states which do not reflect any operating system thread states. Note: The values that represent these states are encapsulated in the  java.lang.Thread.State ...