Skip to main content

Posts

Showing posts from February, 2013

regex

Regular expressions are a kind of language within a language, designed to help programmers with their searching task. in general, a regex search runs from left to right, and once a source's character has been used in match, it can't be reused. metacharacter: \d  digit \s  white space  \w word character (letter, digit or "_") [a-f] range from a to f  [a-fA-F]  looking for the occurrences of a-f or A-f not fA combination ^ to negate the character specified nested brackets  to create a union set && to specify intersection of a set quantifiers "allows to specify number of occurrences to match against " +  one or more *  zero or more ?  zero or one greedy: read first the whole string, if no match, move backward character by character till a match is found. reluctant , however, take the opposite approach: They start at the beginning of the input string, then move forward searching for match The last thing to try is the entire i

including Jars

we have two tools for creating a jar within eclipse framework, one named jar and the other named runnable jar for including a jar library, "to be used within my project" copy it in the project "within the root context" right click on it --> build path -->include in build path runnable jar tool will include it automatic  jar tool include description for mainfist in mainfist.txt include it "libJar.jar" within the same context as my jar ex: Manifest-Version: 1.0 Implementation-Version: 1.0.1 Class-Path: libJar.jar Main-Class: pkg.MainClass

Collection as my bag

When a person decide to travel, he keeps thinking ! ! what will i take, which bag will suits my luggage ?? Collection is our bag, container that we staff our objects in. So which ? for an arrayList removing an element from the middle of an array is expensive "require to move up all elements beyond the removed one". linked list saved the day, since array stores object reference in consecutive memory location, linked list stores each object in a separate link, each link stores reference to next link. however, for linkedList.get(index) result in starting from the first till reach the index "much overhead with each look up, starts again from the beginning ". have to trade off However, when looking for a particular element "Search: require visiting all elements till find match" use hashMap faster but have no control over the order. 

exploring black box

Once loved watching a comic old movie, where a clause was often said:"what's in this ring box ?" accompanied with a surprising answer:"an elephant is in this ring box " :o Reflection discover whats in the black box "an object", could know what is in an object as if a mirror that reflects it content "ability to examine the run-time properties of the object " small ex wanted to return a generic list containing result of a sql query "as if hibernate" List<T>list=new ArrayList<T>(); ResultSetMetaData metadata=resultSet.getMetaData(); String[] columnName=new String[metadata.getColumnCount()]; for(int i=0;i<columnName.length;i++){//column name equivalent to object instance variable      columnName[i]=metadata.getColumnLabel(i+1); } int index=0; T t; while (resultSet.next()) {   list.add((T)cls.newInstance()); t=list.get(index); for(int i=0;i<columnName.length;i++){//initialization

wait / notify in Object not Thread

Within object oriented, an object behaves as if a human behaving so assume you want to sleep and you don't want to trigger an alarm as it annoys you, so you ask your brother to awake you. simple its you are a thread, when telling your brother that you will get asleep "brother.wait( )", an when he awakes you "brother.notify( )".