Object Oriented Programming

December 19, 2012


Object is an instance of a class.  All objects have a state and behavior.


Class is the blueprint from which individual objects are created


Object-oriented programming allows classes to inherit commonly used state and behavior from other classes. In Java programming language, each class is allowed to have one direct superclass, and each superclass has the potential for an unlimited number of subclasses.


Methods form the object’s interface with the outside world. An interface is a group of related methods with empty bodies.  Interface separates implementation and defines the structure. It is useful when the implementation changes frequently.  Interface forms a contract between the class and the outside world.

Abstract Class

Abstract classes cannot be instantiated.  It can only be used as a super class for other classes that extend the abstract class.  Abstract classes are declared with keyword abstract.  Abstract class methods can have implementations. Abstract class’s methods can’t have implementation only when declared abstract.


Encapsulation is inclusion within a program object of all the resources needed for the object to function.  It allows class to change its internal implementation without hurting the overall functioning of the system.


Polymorphism is the ability to request that the same operations be performed by a wide range of different types of things.

Method overloading

Ability to define several methods all with the same name

Method overridding

Subclass overrides a specific implementation of a method that is already provided by one of its super classes.





Java Collections

December 16, 2012

A collection is a object that groups multiple elements into a single unit.

List of core collection Java interfaces.

  • Collection – This interface is the least common denominator that all collections implement and is used to pass collections around and manipulate them where maximum generality is desired.
  • Set – A collection that cannot contain duplicate elements
  • List – A ordered collection that can contain duplicate elements. Elements can be accessed by their integer index.
  • Queue – A collection which orders elements in first-in, first-out manner.
  • Map – An object which maps keys to values. There cannot be duplicate keys.
  • SortedSet – A set that maintains its elements in ascending order.
  • SortedMap – A map that maintains its mappings in ascending order.

Ways to traverse a collection.

  • for-each
for (Object o : collection)
  • Iterators – It enables to traverse a collection and to remove elements selectively. Iterator.remove is the only safe way to modify a collection during iteration
static void filter(Collection<?> c) {
    for (Iterator<?> it = c.iterator(); it.hasNext(); )
        if (!cond(it.next()))

toArray method – translates collection to array.

Object[] a = c.toArray();
String[] a = c.toArray(new String[0]);

Set Implementations.

  • HashSet – Stores elements in hash table. Good performance, but makes no guarantee about order.
  • TreeSet – Stores elements in red-black tree, orders elements by values, slower than HashSet. SortedSet implementation.
  • LinkedHashSet – Implements a hash table with a linked list running through it, orders elements based on the order in which they were inserted.

List Implementations.

  • ArrayList – provides constant time positional access and is fast
  • LinkedList – offers better performance under certain circumstances. If you add elements to beginning of list or iterate over the list to delete elements.

Map Implementations.

  • HashMap – Provides maximum speed, but not ordered.
  • TreeMap – Ordered by the keys. SortedMap implementation.
  • LinkedHashMap – Provides intermediate performance of the above two implementation. Ordered by insertion.



Java update tool jusched.exe occupying HTTP port 80

September 2, 2010

Today when I started my Tomcat server it was not starting, saying that port 80 was occupied. Then I downloaded this useful tool TCP View – http://technet.microsoft.com/en-us/sysinternals/bb897437.aspx

which showed me that jusched.exe was occupying port 80, then I killed the process, and then started the Tomcat server. Strange why java update tool is occupying port 80