<?xml version='1.0' encoding='UTF-8'?><?xml-stylesheet href="http://www.blogger.com/styles/atom.css" type="text/css"?><feed xmlns='http://www.w3.org/2005/Atom' xmlns:openSearch='http://a9.com/-/spec/opensearchrss/1.0/' xmlns:georss='http://www.georss.org/georss' xmlns:gd='http://schemas.google.com/g/2005' xmlns:thr='http://purl.org/syndication/thread/1.0'><id>tag:blogger.com,1999:blog-4844902456784005421</id><updated>2011-11-27T16:09:49.646-08:00</updated><category term='Innovation'/><category term='Python'/><category term='Fibonacci sequence'/><category term='GCD'/><category term='StringTemplate'/><category term='Useful Tools'/><category term='Technology'/><category term='Remote Server'/><category term='XCODE'/><category term='APK'/><category term='I18N'/><category term='Deploying Web Application'/><category term='GSON'/><category term='Peter Norvig'/><category term='Interesting Ideas'/><category term='AI'/><category term='Objective-C'/><category term='General Knowledge'/><category term='File Manipulation'/><category term='Tomcat Apache'/><category term='Configuration Files'/><category term='JSON'/><category term='Android'/><category term='Funny'/><category term='Creating Folders'/><category term='jQuery'/><category term='XSL'/><category term='Log Management'/><category term='Location-Based Services'/><category term='ISO 3166-1-alpha-2'/><category term='Project'/><category term='Stack'/><category term='XML'/><category term='Recursion'/><category term='Useful Method'/><category term='Java'/><category term='Algorithms'/><category term='Binary Tree'/><category term='Splunk'/><category term='URL package'/><category term='Bitwise Operators'/><category term='Eclipse'/><category term='GPS'/><category term='Trivia'/><category term='Internationalization'/><category term='Country Codes'/><category term='iPhone App'/><category term='Interface Builder'/><category term='Cool Gadgets'/><title type='text'>Web Journal</title><subtitle type='html'></subtitle><link rel='http://schemas.google.com/g/2005#feed' type='application/atom+xml' href='http://nicholaskey.blogspot.com/feeds/posts/default'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4844902456784005421/posts/default?max-results=100'/><link rel='alternate' type='text/html' href='http://nicholaskey.blogspot.com/'/><link rel='hub' href='http://pubsubhubbub.appspot.com/'/><author><name>Nicholas Key</name><uri>http://www.blogger.com/profile/05768297019453812096</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='http://4.bp.blogspot.com/_OQU38yb-Uq0/SwL5VBlHCII/AAAAAAAAA6U/lXUy53mS7gQ/S220/hamster.jpg'/></author><generator version='7.00' uri='http://www.blogger.com'>Blogger</generator><openSearch:totalResults>94</openSearch:totalResults><openSearch:startIndex>1</openSearch:startIndex><openSearch:itemsPerPage>100</openSearch:itemsPerPage><entry><id>tag:blogger.com,1999:blog-4844902456784005421.post-4667236554681668874</id><published>2010-07-05T11:39:00.001-07:00</published><updated>2010-07-05T11:39:39.556-07:00</updated><title type='text'>Long Hiatus</title><content type='html'>I have been extremely busy for the past few months and I was so tied up that I don't even have time to write an article or two in this blog! Challenges as a customer facing software engineer - tight datelines to meet, challenging projects to complete, customers to talk to - you name it, I might have already faced it.&lt;br /&gt;&lt;br /&gt;I will post interesting programming puzzles and solutions soon. Stay tuned!&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4844902456784005421-4667236554681668874?l=nicholaskey.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://nicholaskey.blogspot.com/feeds/4667236554681668874/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://nicholaskey.blogspot.com/2010/07/long-hiatus.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4844902456784005421/posts/default/4667236554681668874'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4844902456784005421/posts/default/4667236554681668874'/><link rel='alternate' type='text/html' href='http://nicholaskey.blogspot.com/2010/07/long-hiatus.html' title='Long Hiatus'/><author><name>Nicholas Key</name><uri>http://www.blogger.com/profile/05768297019453812096</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='http://4.bp.blogspot.com/_OQU38yb-Uq0/SwL5VBlHCII/AAAAAAAAA6U/lXUy53mS7gQ/S220/hamster.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4844902456784005421.post-3383025431809237001</id><published>2009-12-15T11:03:00.007-08:00</published><updated>2011-08-03T07:40:44.432-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='JSON'/><category scheme='http://www.blogger.com/atom/ns#' term='Java'/><category scheme='http://www.blogger.com/atom/ns#' term='GSON'/><title type='text'>Using GSON to parse Yelp JSON result</title><content type='html'>This is a very basic example about using GSON to parse JSON result from Yelp. These few lines of codes will do the trick:&lt;pre&gt;&lt;br /&gt;  URL URLsource = null;&lt;br /&gt;  JsonElement jse = null;&lt;br /&gt;  BufferedReader in;&lt;br /&gt;  try {&lt;br /&gt;   URLsource = new URL("YELP_API_REQUEST");&lt;br /&gt;   in = new BufferedReader(new InputStreamReader(URLsource.openStream(), "UTF-8"));&lt;br /&gt;   jse = new JsonParser().parse(in);&lt;br /&gt;   in.close();&lt;br /&gt;   System.out.println(jse.toString());&lt;br /&gt;   JsonArray jsa = jse.getAsJsonObject().getAsJsonArray("businesses");&lt;br /&gt;   System.out.println(jsa.size());&lt;br /&gt;   &lt;br /&gt;   for (int i= 0; i&amp;lt;jsa.size(); i++ ) {&lt;br /&gt;    System.out.println(jsa.get(i));&lt;br /&gt;    System.out.println("===========================================================");&lt;br /&gt;   }&lt;br /&gt;  } catch (MalformedURLException e) {&lt;br /&gt;   e.printStackTrace();&lt;br /&gt;  } catch (UnsupportedEncodingException e) {&lt;br /&gt;   e.printStackTrace();&lt;br /&gt;  } catch (IOException e) {&lt;br /&gt;   e.printStackTrace();&lt;br /&gt;  }&lt;/pre&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4844902456784005421-3383025431809237001?l=nicholaskey.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://nicholaskey.blogspot.com/feeds/3383025431809237001/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://nicholaskey.blogspot.com/2009/12/using-gson-to-parse-yelp-json-result.html#comment-form' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4844902456784005421/posts/default/3383025431809237001'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4844902456784005421/posts/default/3383025431809237001'/><link rel='alternate' type='text/html' href='http://nicholaskey.blogspot.com/2009/12/using-gson-to-parse-yelp-json-result.html' title='Using GSON to parse Yelp JSON result'/><author><name>Nicholas Key</name><uri>http://www.blogger.com/profile/05768297019453812096</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='http://4.bp.blogspot.com/_OQU38yb-Uq0/SwL5VBlHCII/AAAAAAAAA6U/lXUy53mS7gQ/S220/hamster.jpg'/></author><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4844902456784005421.post-7812648307599297127</id><published>2009-12-14T09:42:00.007-08:00</published><updated>2009-12-14T09:45:25.141-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='AI'/><category scheme='http://www.blogger.com/atom/ns#' term='Peter Norvig'/><title type='text'>Models and Theories by Peter Norvig</title><content type='html'>&lt;div style="text-align:center"&gt;&lt;object width="720" height="406"&gt;&lt;param name="allowfullscreen" value="true" /&gt;&lt;param name="allowscriptaccess" value="always" /&gt;&lt;param name="movie" value="http://vimeo.com/moogaloop.swf?clip_id=4725365&amp;amp;server=vimeo.com&amp;amp;show_title=0&amp;amp;show_byline=0&amp;amp;show_portrait=0&amp;amp;color=00ADEF&amp;amp;fullscreen=1" /&gt;&lt;embed src="http://vimeo.com/moogaloop.swf?clip_id=4725365&amp;amp;server=vimeo.com&amp;amp;show_title=0&amp;amp;show_byline=0&amp;amp;show_portrait=0&amp;amp;color=00ADEF&amp;amp;fullscreen=1" type="application/x-shockwave-flash" allowfullscreen="true" allowscriptaccess="always" width="720" height="406"&gt;&lt;/embed&gt;&lt;/object&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4844902456784005421-7812648307599297127?l=nicholaskey.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://nicholaskey.blogspot.com/feeds/7812648307599297127/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://nicholaskey.blogspot.com/2009/12/models-and-theories-by-peter-norvig.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4844902456784005421/posts/default/7812648307599297127'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4844902456784005421/posts/default/7812648307599297127'/><link rel='alternate' type='text/html' href='http://nicholaskey.blogspot.com/2009/12/models-and-theories-by-peter-norvig.html' title='Models and Theories by Peter Norvig'/><author><name>Nicholas Key</name><uri>http://www.blogger.com/profile/05768297019453812096</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='http://4.bp.blogspot.com/_OQU38yb-Uq0/SwL5VBlHCII/AAAAAAAAA6U/lXUy53mS7gQ/S220/hamster.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4844902456784005421.post-5061444442938479397</id><published>2009-12-13T10:02:00.005-08:00</published><updated>2009-12-13T10:14:10.628-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Java'/><category scheme='http://www.blogger.com/atom/ns#' term='GPS'/><category scheme='http://www.blogger.com/atom/ns#' term='Android'/><category scheme='http://www.blogger.com/atom/ns#' term='Location-Based Services'/><title type='text'>Getting current GPS coordinates in Android</title><content type='html'>All you need are these few lines of codes:&lt;textarea name="code" class="java" cols="60" rows="1000"&gt;&lt;br /&gt;String latLongString = "";&lt;br /&gt;LocationManager locationManager = (LocationManager)getSystemService(Context.LOCATION_SERVICE);&lt;br /&gt;Location location = locationManager.getLastKnownLocation(LocationManager.GPS_PROVIDER);&lt;br /&gt;if (location != null) {&lt;br /&gt;  double lat = location.getLatitude();&lt;br /&gt;  double lng = location.getLongitude();&lt;br /&gt;  latLongString = "Lat:" + lat + "\nLong:" + lng;&lt;br /&gt;} else {&lt;br /&gt;  latLongString = "No location found";&lt;br /&gt;}&lt;br /&gt;Log.d("GPS coordinates ======&gt; ", latLongString);&lt;/textarea&gt;Also don't forget to add this permission in the manifest file:&lt;br /&gt;&lt;span style="font-weight:bold;"&gt;&amp;lt;uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"&gt;&amp;lt;/uses-permission&gt;&lt;/span&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4844902456784005421-5061444442938479397?l=nicholaskey.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://nicholaskey.blogspot.com/feeds/5061444442938479397/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://nicholaskey.blogspot.com/2009/12/getting-current-gps-coordinates-in.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4844902456784005421/posts/default/5061444442938479397'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4844902456784005421/posts/default/5061444442938479397'/><link rel='alternate' type='text/html' href='http://nicholaskey.blogspot.com/2009/12/getting-current-gps-coordinates-in.html' title='Getting current GPS coordinates in Android'/><author><name>Nicholas Key</name><uri>http://www.blogger.com/profile/05768297019453812096</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='http://4.bp.blogspot.com/_OQU38yb-Uq0/SwL5VBlHCII/AAAAAAAAA6U/lXUy53mS7gQ/S220/hamster.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4844902456784005421.post-8465401097772850302</id><published>2009-11-27T09:04:00.009-08:00</published><updated>2009-11-27T09:08:47.155-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Java'/><category scheme='http://www.blogger.com/atom/ns#' term='Android'/><title type='text'>Nonblocking mechanism for Android GUI</title><content type='html'>Do you realize that fetching data from the web, for example a GET request, may actually block the GUI and then creates an error? I experienced that and would want to share my thoughts on resolving it. I have not implemented a sound solution but these are the things I have in my mind. There are two components to implement in the code:&lt;br /&gt;1. Thread&lt;br /&gt;2. Handler&lt;br /&gt;&lt;br /&gt;Let's see if this works :)&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4844902456784005421-8465401097772850302?l=nicholaskey.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://nicholaskey.blogspot.com/feeds/8465401097772850302/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://nicholaskey.blogspot.com/2009/11/nonblocking-mechanism-for-android-gui.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4844902456784005421/posts/default/8465401097772850302'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4844902456784005421/posts/default/8465401097772850302'/><link rel='alternate' type='text/html' href='http://nicholaskey.blogspot.com/2009/11/nonblocking-mechanism-for-android-gui.html' title='Nonblocking mechanism for Android GUI'/><author><name>Nicholas Key</name><uri>http://www.blogger.com/profile/05768297019453812096</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='http://4.bp.blogspot.com/_OQU38yb-Uq0/SwL5VBlHCII/AAAAAAAAA6U/lXUy53mS7gQ/S220/hamster.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4844902456784005421.post-5900021927033129393</id><published>2009-11-25T22:47:00.009-08:00</published><updated>2009-11-27T23:52:47.727-08:00</updated><title type='text'>Developers are born brave</title><content type='html'>This is something motivational I want to share with the readers :)&lt;br /&gt;Credits to the creative artist.&lt;br /&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://2.bp.blogspot.com/_OQU38yb-Uq0/SxDWUBK3uTI/AAAAAAAAA60/3RRxKU-XaBc/s1600/developersarebornbrave.jpg"&gt;&lt;img style="display:block; margin:0px auto 10px; text-align:center;cursor:pointer; cursor:hand;width: 500px;" src="http://2.bp.blogspot.com/_OQU38yb-Uq0/SxDWUBK3uTI/AAAAAAAAA60/3RRxKU-XaBc/s400/developersarebornbrave.jpg" border="0" alt=""id="BLOGGER_PHOTO_ID_5409058791871723826" /&gt;&lt;/a&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4844902456784005421-5900021927033129393?l=nicholaskey.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://nicholaskey.blogspot.com/feeds/5900021927033129393/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://nicholaskey.blogspot.com/2009/11/developers-are-born-brave.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4844902456784005421/posts/default/5900021927033129393'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4844902456784005421/posts/default/5900021927033129393'/><link rel='alternate' type='text/html' href='http://nicholaskey.blogspot.com/2009/11/developers-are-born-brave.html' title='Developers are born brave'/><author><name>Nicholas Key</name><uri>http://www.blogger.com/profile/05768297019453812096</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='http://4.bp.blogspot.com/_OQU38yb-Uq0/SwL5VBlHCII/AAAAAAAAA6U/lXUy53mS7gQ/S220/hamster.jpg'/></author><media:thumbnail xmlns:media='http://search.yahoo.com/mrss/' url='http://2.bp.blogspot.com/_OQU38yb-Uq0/SxDWUBK3uTI/AAAAAAAAA60/3RRxKU-XaBc/s72-c/developersarebornbrave.jpg' height='72' width='72'/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4844902456784005421.post-557678022665844351</id><published>2009-11-21T10:06:00.001-08:00</published><updated>2009-11-23T08:07:36.892-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Android'/><title type='text'>Removing status and title bars in an Android app (suggested method)</title><content type='html'>I discovered that the status and title bars can be removed in an Android app by inserting one simple line in the manifest xml file. Feel free to try this out and let's discuss if this does not work for you.&lt;br /&gt;&lt;br /&gt;&amp;lt;activity android:name=".YOUR_ACTIVITY_NAME"&lt;br /&gt;                  android:label="@string/app_name"&lt;br /&gt;                  android:screenOrientation="portrait"&lt;br /&gt;                  &lt;span style="font-weight:bold;color:red;"&gt;android:theme="@android:style/Theme.Black.NoTitleBar.Fullscreen"&lt;/span&gt;&gt;&lt;br /&gt;            &amp;lt;intent-filter&gt;&lt;br /&gt;                &amp;lt;action android:name="android.intent.action.MAIN" /&gt;&lt;br /&gt;                &amp;lt;category android:name="android.intent.category.LAUNCHER" /&gt;&lt;br /&gt;            &amp;lt;/intent-filter&gt;&lt;br /&gt;        &amp;lt;/activity&gt;&lt;br /&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://1.bp.blogspot.com/_OQU38yb-Uq0/Sv2YzxLKaYI/AAAAAAAAA6I/iI8iMF15osE/s1600-h/Picture+3.png"&gt;&lt;img style="display:block; margin:0px auto 10px; text-align:center;cursor:pointer; cursor:hand;width: 256px; height: 400px;" src="http://1.bp.blogspot.com/_OQU38yb-Uq0/Sv2YzxLKaYI/AAAAAAAAA6I/iI8iMF15osE/s400/Picture+3.png" border="0" alt=""id="BLOGGER_PHOTO_ID_5403643143055370626" /&gt;&lt;/a&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4844902456784005421-557678022665844351?l=nicholaskey.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://nicholaskey.blogspot.com/feeds/557678022665844351/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://nicholaskey.blogspot.com/2009/11/removing-status-and-title-bars-in_21.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4844902456784005421/posts/default/557678022665844351'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4844902456784005421/posts/default/557678022665844351'/><link rel='alternate' type='text/html' href='http://nicholaskey.blogspot.com/2009/11/removing-status-and-title-bars-in_21.html' title='Removing status and title bars in an Android app (suggested method)'/><author><name>Nicholas Key</name><uri>http://www.blogger.com/profile/05768297019453812096</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='http://4.bp.blogspot.com/_OQU38yb-Uq0/SwL5VBlHCII/AAAAAAAAA6U/lXUy53mS7gQ/S220/hamster.jpg'/></author><media:thumbnail xmlns:media='http://search.yahoo.com/mrss/' url='http://1.bp.blogspot.com/_OQU38yb-Uq0/Sv2YzxLKaYI/AAAAAAAAA6I/iI8iMF15osE/s72-c/Picture+3.png' height='72' width='72'/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4844902456784005421.post-1755673690179220794</id><published>2009-11-19T09:28:00.000-08:00</published><updated>2011-08-03T06:17:16.355-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Java'/><category scheme='http://www.blogger.com/atom/ns#' term='Algorithms'/><title type='text'>Distinct intersecting values of two arrays</title><content type='html'>I have written two different methods that gives the same output. The output is a list of distinct intersecting values of two arrays. I am amazed with the different amount of time taken to solve this problem. It would be something interesting to investigate. Here are the suggested solutions:&lt;br /&gt;&lt;pre&gt;import java.util.ArrayList;&lt;br /&gt;import java.util.HashSet;&lt;br /&gt;import java.util.Set;&lt;br /&gt;&lt;br /&gt;public class ArraysIntersection {&lt;br /&gt;&lt;br /&gt; private void findIntersectionMethod1(int[] a, int[] b){&lt;br /&gt;  long start = System.nanoTime();&lt;br /&gt;  int indexA = 0;&lt;br /&gt;  int indexB = 0;&lt;br /&gt;  ArrayList&lt;Integer&gt; unique = new ArrayList&lt;Integer&gt;();&lt;br /&gt;  while (indexA &lt; a.length &amp;&amp; indexB &lt; b.length) {&lt;br /&gt;   if (a[indexA] == b[indexB]) {&lt;br /&gt;    if (!unique.contains(a[indexA])) {&lt;br /&gt;     unique.add(a[indexA]);&lt;br /&gt;    }&lt;br /&gt;    indexA++;&lt;br /&gt;    indexB++;&lt;br /&gt;   } else if (a[indexA] &lt; b[indexB]) {&lt;br /&gt;    indexA++;&lt;br /&gt;   } else {&lt;br /&gt;    indexB++;&lt;br /&gt;   }&lt;br /&gt;  }&lt;br /&gt;  long elapsed = (System.nanoTime() - start);&lt;br /&gt;  System.out.println("Elapsed time (findIntersectionMethod1): " + elapsed + "ns");&lt;br /&gt;  System.out.println("Intersection of elements: " + unique);&lt;br /&gt; }&lt;br /&gt;&lt;br /&gt; private void findIntersectionMethod2(int[] arr1, int[] arr2){&lt;br /&gt;  long start = System.nanoTime();&lt;br /&gt;  ArrayList&lt;Integer&gt; unique = new ArrayList&lt;Integer&gt;();&lt;br /&gt;  for (int i = 0; i &lt; arr1.length; i++) {&lt;br /&gt;   for (int j = 0; j &lt; arr2.length; j++) {&lt;br /&gt;    if (arr1[i] == arr2[j]) {&lt;br /&gt;     if (!unique.contains(arr1[i])) {&lt;br /&gt;      unique.add(arr1[i]);&lt;br /&gt;     }&lt;br /&gt;    }&lt;br /&gt;   }&lt;br /&gt;  }&lt;br /&gt;  long elapsed = (System.nanoTime() - start);&lt;br /&gt;  System.out.println("Elapsed time (findIntersectionMethod2): " + elapsed + "ns");&lt;br /&gt;  System.out.println("Intersection of elements: " + unique);&lt;br /&gt; }&lt;br /&gt;&lt;br /&gt; private void findIntersectionMethod3(int[] a, int[] b){&lt;br /&gt;  long start = System.nanoTime();&lt;br /&gt;  Set&lt;Integer&gt; unique = new HashSet&lt;Integer&gt;();&lt;br /&gt;  int indexA = 0;&lt;br /&gt;  int indexB = 0;&lt;br /&gt;  while (indexA &lt; a.length &amp;&amp; indexB &lt; b.length) {&lt;br /&gt;   if (a[indexA] == b[indexB]) {&lt;br /&gt;    unique.add(a[indexA]);&lt;br /&gt;    indexA++;&lt;br /&gt;    indexB++;&lt;br /&gt;   } else if (a[indexA] &lt; b[indexB]) {&lt;br /&gt;    indexA++;&lt;br /&gt;   } else {&lt;br /&gt;    indexB++;&lt;br /&gt;   }&lt;br /&gt;  }&lt;br /&gt;&lt;br /&gt;  long elapsed = (System.nanoTime() - start);&lt;br /&gt;  System.out.println("Elapsed time (findIntersectionMethod3): " + elapsed + "ns");&lt;br /&gt;  System.out.println("Intersection of elements: " + unique);&lt;br /&gt; }&lt;br /&gt;&lt;br /&gt; public static void main(String[] args) {&lt;br /&gt;&lt;br /&gt;  int a[]={1, 1, 2, 4, 4, 7, 8, 8, 9, 14, 14, 20, 20, 20};&lt;br /&gt;  int b[]={1, 1, 1, 2, 2, 8, 8, 20};&lt;br /&gt;&lt;br /&gt;  ArraysIntersection arrIntersect = new ArraysIntersection();&lt;br /&gt;  arrIntersect.findIntersectionMethod1(a, b); &lt;br /&gt;  arrIntersect.findIntersectionMethod2(a, b); &lt;br /&gt;  arrIntersect.findIntersectionMethod3(a, b); &lt;br /&gt; }&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;&lt;/pre&gt;The output of these methods are as below (I'm telling you, you'll be amazed looking at the time taken for each method):&lt;br /&gt;&lt;pre&gt;Elapsed time (findIntersectionMethod1): 455000ns&lt;br /&gt;Intersection of elements: [1, 2, 8, 20]&lt;br /&gt;Elapsed time (findIntersectionMethod2): 15000ns&lt;br /&gt;Intersection of elements: [1, 2, 8, 20]&lt;br /&gt;Elapsed time (findIntersectionMethod3): 65000ns&lt;br /&gt;Intersection of elements: [2, 8, 1, 20]&lt;br /&gt;&lt;br /&gt;&lt;/pre&gt;I'm sure there are much better solutions to solve this interesting problem that I have not thought of.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4844902456784005421-1755673690179220794?l=nicholaskey.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://nicholaskey.blogspot.com/feeds/1755673690179220794/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://nicholaskey.blogspot.com/2009/11/distinct-intersecting-values-of-two.html#comment-form' title='9 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4844902456784005421/posts/default/1755673690179220794'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4844902456784005421/posts/default/1755673690179220794'/><link rel='alternate' type='text/html' href='http://nicholaskey.blogspot.com/2009/11/distinct-intersecting-values-of-two.html' title='Distinct intersecting values of two arrays'/><author><name>Nicholas Key</name><uri>http://www.blogger.com/profile/05768297019453812096</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='http://4.bp.blogspot.com/_OQU38yb-Uq0/SwL5VBlHCII/AAAAAAAAA6U/lXUy53mS7gQ/S220/hamster.jpg'/></author><thr:total>9</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4844902456784005421.post-2758840269233705216</id><published>2009-11-18T17:19:00.007-08:00</published><updated>2009-11-19T16:09:20.377-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Java'/><category scheme='http://www.blogger.com/atom/ns#' term='Android'/><title type='text'>Quizzie with improved user interface</title><content type='html'>This is Quizzie v1.1 with much better user interface. I hope you enjoy watching this video. Quizzie v1.0 is &lt;a href="http://nicholaskey.blogspot.com/2009/11/quizzie-my-first-android-application.html"&gt;&lt;span style="font-weight:bold;"&gt;available here&lt;/span&gt;&lt;/a&gt;.&lt;br /&gt;&lt;br /&gt;&lt;div style="text-align:center"&gt;&lt;object width="388" height="727" classid="clsid:D27CDB6E-AE6D-11CF-96B8-444553540000" class="embeddedObject"&gt;&lt;param value="http://content.screencast.com/users/nicholaskeytholeong/folders/Jing/media/d94f15cd-c48d-40ae-ba70-9243a9c8d8f2/jingswfplayer.swf" name="movie"/&gt;&lt;param value="high" name="quality"/&gt;&lt;param value="#FFFFFF" name="bgcolor"/&gt;&lt;param value="containerwidth=388&amp;amp;containerheight=727&amp;amp;thumb=http://content.screencast.com/users/nicholaskeytholeong/folders/Jing/media/d94f15cd-c48d-40ae-ba70-9243a9c8d8f2/FirstFrame.jpg&amp;amp;content=http://content.screencast.com/users/nicholaskeytholeong/folders/Jing/media/d94f15cd-c48d-40ae-ba70-9243a9c8d8f2/00000003.swf&amp;amp;blurover=false" name="flashVars"/&gt;&lt;param value="true" name="allowFullScreen"/&gt;&lt;param value="showall" name="scale"/&gt;&lt;param value="always" name="allowScriptAccess"/&gt;&lt;param value="http://content.screencast.com/users/nicholaskeytholeong/folders/Jing/media/d94f15cd-c48d-40ae-ba70-9243a9c8d8f2/" name="base"/&gt;&lt;embed width="388" height="727" scale="showall" base="http://content.screencast.com/users/nicholaskeytholeong/folders/Jing/media/d94f15cd-c48d-40ae-ba70-9243a9c8d8f2/" allowfullscreen="true" flashvars="containerwidth=388&amp;amp;containerheight=727&amp;amp;thumb=http://content.screencast.com/users/nicholaskeytholeong/folders/Jing/media/d94f15cd-c48d-40ae-ba70-9243a9c8d8f2/FirstFrame.jpg&amp;amp;content=http://content.screencast.com/users/nicholaskeytholeong/folders/Jing/media/d94f15cd-c48d-40ae-ba70-9243a9c8d8f2/00000003.swf&amp;amp;blurover=false" allowscriptaccess="always" type="application/x-shockwave-flash" bgcolor="#FFFFFF" quality="high" src="http://content.screencast.com/users/nicholaskeytholeong/folders/Jing/media/d94f15cd-c48d-40ae-ba70-9243a9c8d8f2/jingswfplayer.swf" class="embeddedObject"&gt;&lt;/embed&gt; &lt;/object&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4844902456784005421-2758840269233705216?l=nicholaskey.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://nicholaskey.blogspot.com/feeds/2758840269233705216/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://nicholaskey.blogspot.com/2009/11/quizzie-with-improved-user-interface.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4844902456784005421/posts/default/2758840269233705216'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4844902456784005421/posts/default/2758840269233705216'/><link rel='alternate' type='text/html' href='http://nicholaskey.blogspot.com/2009/11/quizzie-with-improved-user-interface.html' title='Quizzie with improved user interface'/><author><name>Nicholas Key</name><uri>http://www.blogger.com/profile/05768297019453812096</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='http://4.bp.blogspot.com/_OQU38yb-Uq0/SwL5VBlHCII/AAAAAAAAA6U/lXUy53mS7gQ/S220/hamster.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4844902456784005421.post-1708705712134244358</id><published>2009-11-18T17:19:00.005-08:00</published><updated>2009-11-18T17:41:01.715-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Splunk'/><title type='text'>Remote log management and monitoring? There's an Android app for that</title><content type='html'>I'm thinking of writing an Android app using Splunk's API. Not sure if it's possible but I think it can be done. Here is my concept about the application.&lt;br /&gt;&lt;br /&gt;We can actually see the outputs of the activities in Android by using &lt;span style="font-weight:bold;"&gt;adb logcat&lt;/span&gt;. What if I am able to pipe out the stream into a file and then push it to my local Splunk web server. hhhmmm interesting ...&lt;br /&gt;&lt;br /&gt;"Remote log management and monitoring? There's an Android app for that"&lt;br /&gt;&lt;br /&gt;:D&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4844902456784005421-1708705712134244358?l=nicholaskey.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://nicholaskey.blogspot.com/feeds/1708705712134244358/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://nicholaskey.blogspot.com/2009/11/remote-log-management-and-monitoring.html#comment-form' title='2 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4844902456784005421/posts/default/1708705712134244358'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4844902456784005421/posts/default/1708705712134244358'/><link rel='alternate' type='text/html' href='http://nicholaskey.blogspot.com/2009/11/remote-log-management-and-monitoring.html' title='Remote log management and monitoring? There&apos;s an Android app for that'/><author><name>Nicholas Key</name><uri>http://www.blogger.com/profile/05768297019453812096</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='http://4.bp.blogspot.com/_OQU38yb-Uq0/SwL5VBlHCII/AAAAAAAAA6U/lXUy53mS7gQ/S220/hamster.jpg'/></author><thr:total>2</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4844902456784005421.post-6159272187210122973</id><published>2009-11-14T08:57:00.003-08:00</published><updated>2009-11-17T10:37:46.902-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Android'/><category scheme='http://www.blogger.com/atom/ns#' term='Python'/><title type='text'>Jython in Android</title><content type='html'>I think it's possible. But why are there so limited references to use Jython in Android?&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4844902456784005421-6159272187210122973?l=nicholaskey.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://nicholaskey.blogspot.com/feeds/6159272187210122973/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://nicholaskey.blogspot.com/2009/11/jython-in-android.html#comment-form' title='4 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4844902456784005421/posts/default/6159272187210122973'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4844902456784005421/posts/default/6159272187210122973'/><link rel='alternate' type='text/html' href='http://nicholaskey.blogspot.com/2009/11/jython-in-android.html' title='Jython in Android'/><author><name>Nicholas Key</name><uri>http://www.blogger.com/profile/05768297019453812096</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='http://4.bp.blogspot.com/_OQU38yb-Uq0/SwL5VBlHCII/AAAAAAAAA6U/lXUy53mS7gQ/S220/hamster.jpg'/></author><thr:total>4</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4844902456784005421.post-8525483257203411046</id><published>2009-11-13T09:32:00.009-08:00</published><updated>2009-11-17T10:36:19.070-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Java'/><category scheme='http://www.blogger.com/atom/ns#' term='Android'/><title type='text'>Removing status and title bars in an Android app</title><content type='html'>Here are a few options to display the status and title bars in your Android app. The first image shown below is exactly the output you are getting if you do not do any configurations.&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://2.bp.blogspot.com/_OQU38yb-Uq0/Sv2YmfQxHgI/AAAAAAAAA5w/fOaBKjwf1lY/s1600-h/Picture+5.png"&gt;&lt;img style="display:block; margin:0px auto 10px; text-align:center;cursor:pointer; cursor:hand;width: 256px; height: 400px;" src="http://2.bp.blogspot.com/_OQU38yb-Uq0/Sv2YmfQxHgI/AAAAAAAAA5w/fOaBKjwf1lY/s400/Picture+5.png" border="0" alt=""id="BLOGGER_PHOTO_ID_5403642914908741122" /&gt;&lt;/a&gt;&lt;br /&gt;To get this output, add this line in the onCreate method:&lt;br /&gt;&lt;span style="font-weight:bold;"&gt;getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);&lt;/span&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://4.bp.blogspot.com/_OQU38yb-Uq0/Sv2Ywa1XPbI/AAAAAAAAA6A/myb1D5NsFL8/s1600-h/Picture+6.png"&gt;&lt;img style="display:block; margin:0px auto 10px; text-align:center;cursor:pointer; cursor:hand;width: 255px; height: 400px;" src="http://4.bp.blogspot.com/_OQU38yb-Uq0/Sv2Ywa1XPbI/AAAAAAAAA6A/myb1D5NsFL8/s400/Picture+6.png" border="0" alt=""id="BLOGGER_PHOTO_ID_5403643085518749106" /&gt;&lt;/a&gt;&lt;br /&gt;To get this output, add this line in the onCreate method:&lt;br /&gt;&lt;span style="font-weight:bold;"&gt;requestWindowFeature(Window.FEATURE_NO_TITLE);&lt;/span&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://1.bp.blogspot.com/_OQU38yb-Uq0/Sv2YrigLaLI/AAAAAAAAA54/IAQMJ7f5ZJA/s1600-h/Picture+4.png"&gt;&lt;img style="display:block; margin:0px auto 10px; text-align:center;cursor:pointer; cursor:hand;width: 256px; height: 400px;" src="http://1.bp.blogspot.com/_OQU38yb-Uq0/Sv2YrigLaLI/AAAAAAAAA54/IAQMJ7f5ZJA/s400/Picture+4.png" border="0" alt=""id="BLOGGER_PHOTO_ID_5403643001678031026" /&gt;&lt;/a&gt;&lt;br /&gt;To get this output, add these two lines in the onCreate method:&lt;br /&gt;&lt;span style="font-weight:bold;"&gt;requestWindowFeature(Window.FEATURE_NO_TITLE);&lt;br /&gt;getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);&lt;/span&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://1.bp.blogspot.com/_OQU38yb-Uq0/Sv2YzxLKaYI/AAAAAAAAA6I/iI8iMF15osE/s1600-h/Picture+3.png"&gt;&lt;img style="display:block; margin:0px auto 10px; text-align:center;cursor:pointer; cursor:hand;width: 256px; height: 400px;" src="http://1.bp.blogspot.com/_OQU38yb-Uq0/Sv2YzxLKaYI/AAAAAAAAA6I/iI8iMF15osE/s400/Picture+3.png" border="0" alt=""id="BLOGGER_PHOTO_ID_5403643143055370626" /&gt;&lt;/a&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4844902456784005421-8525483257203411046?l=nicholaskey.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://nicholaskey.blogspot.com/feeds/8525483257203411046/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://nicholaskey.blogspot.com/2009/11/removing-status-and-title-bars-in.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4844902456784005421/posts/default/8525483257203411046'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4844902456784005421/posts/default/8525483257203411046'/><link rel='alternate' type='text/html' href='http://nicholaskey.blogspot.com/2009/11/removing-status-and-title-bars-in.html' title='Removing status and title bars in an Android app'/><author><name>Nicholas Key</name><uri>http://www.blogger.com/profile/05768297019453812096</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='http://4.bp.blogspot.com/_OQU38yb-Uq0/SwL5VBlHCII/AAAAAAAAA6U/lXUy53mS7gQ/S220/hamster.jpg'/></author><media:thumbnail xmlns:media='http://search.yahoo.com/mrss/' url='http://2.bp.blogspot.com/_OQU38yb-Uq0/Sv2YmfQxHgI/AAAAAAAAA5w/fOaBKjwf1lY/s72-c/Picture+5.png' height='72' width='72'/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4844902456784005421.post-3799549910564894791</id><published>2009-11-11T21:35:00.008-08:00</published><updated>2009-11-11T22:53:14.058-08:00</updated><title type='text'>The very music that reminds me to be innovative</title><content type='html'>I know this song is quite old but I have been listening to it ever since it was introduced to the public. This is "Here Comes Another Bubble" and it is adapted from "We Didn't Start The Fire". Being a software developer, I personally prefer the technical version of the song about coming up with innovative and brilliant ideas that change the world; not so much about the wars and scandals that took place throughout the course of history. &lt;br /&gt;&lt;div style="text-align:center"&gt;&lt;br /&gt;&lt;object width="425" height="344"&gt;&lt;param name="movie" value="http://www.youtube.com/v/I6IQ_FOCE6I&amp;hl=en_US&amp;fs=1&amp;"&gt;&lt;/param&gt;&lt;param name="allowFullScreen" value="true"&gt;&lt;/param&gt;&lt;param name="allowscriptaccess" value="always"&gt;&lt;/param&gt;&lt;embed src="http://www.youtube.com/v/I6IQ_FOCE6I&amp;hl=en_US&amp;fs=1&amp;" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="425" height="344"&gt;&lt;/embed&gt;&lt;/object&gt;&lt;/div&gt;&lt;div style="text-align:center"&gt;&lt;br /&gt;&lt;object width="425" height="344"&gt;&lt;param name="movie" value="http://www.youtube.com/v/6POmPgeLW2U&amp;hl=en_US&amp;fs=1&amp;"&gt;&lt;/param&gt;&lt;param name="allowFullScreen" value="true"&gt;&lt;/param&gt;&lt;param name="allowscriptaccess" value="always"&gt;&lt;/param&gt;&lt;embed src="http://www.youtube.com/v/6POmPgeLW2U&amp;hl=en_US&amp;fs=1&amp;" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="425" height="344"&gt;&lt;/embed&gt;&lt;/object&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4844902456784005421-3799549910564894791?l=nicholaskey.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://nicholaskey.blogspot.com/feeds/3799549910564894791/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://nicholaskey.blogspot.com/2009/11/very-music-that-reminds-me-to-be.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4844902456784005421/posts/default/3799549910564894791'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4844902456784005421/posts/default/3799549910564894791'/><link rel='alternate' type='text/html' href='http://nicholaskey.blogspot.com/2009/11/very-music-that-reminds-me-to-be.html' title='The very music that reminds me to be innovative'/><author><name>Nicholas Key</name><uri>http://www.blogger.com/profile/05768297019453812096</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='http://4.bp.blogspot.com/_OQU38yb-Uq0/SwL5VBlHCII/AAAAAAAAA6U/lXUy53mS7gQ/S220/hamster.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4844902456784005421.post-1950172185622246088</id><published>2009-11-09T11:03:00.002-08:00</published><updated>2009-11-13T11:42:37.929-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Python'/><category scheme='http://www.blogger.com/atom/ns#' term='Algorithms'/><title type='text'>Java Codes in Python (Part 4)</title><content type='html'>Here is a suggested solution to get unique values from a list without using a map or set data structure&lt;textarea name="code" class="python" cols="60" rows="1000"&gt;&lt;br /&gt;def uniqueElements(input):&lt;br /&gt;    uniqElems = []&lt;br /&gt;    uniq = input[0]&lt;br /&gt;    uniqElems.append(uniq)&lt;br /&gt;    for i in input[1:]:&lt;br /&gt;        if (i != uniq):&lt;br /&gt;            uniqElems.append(i)&lt;br /&gt;            uniq = i&lt;br /&gt;    return uniqElems&lt;br /&gt;&lt;/textarea&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4844902456784005421-1950172185622246088?l=nicholaskey.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://nicholaskey.blogspot.com/feeds/1950172185622246088/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://nicholaskey.blogspot.com/2009/11/java-codes-in-python-part-4.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4844902456784005421/posts/default/1950172185622246088'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4844902456784005421/posts/default/1950172185622246088'/><link rel='alternate' type='text/html' href='http://nicholaskey.blogspot.com/2009/11/java-codes-in-python-part-4.html' title='Java Codes in Python (Part 4)'/><author><name>Nicholas Key</name><uri>http://www.blogger.com/profile/05768297019453812096</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='http://4.bp.blogspot.com/_OQU38yb-Uq0/SwL5VBlHCII/AAAAAAAAA6U/lXUy53mS7gQ/S220/hamster.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4844902456784005421.post-6476681339965594720</id><published>2009-11-09T11:03:00.001-08:00</published><updated>2011-08-03T06:18:36.410-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Java'/><category scheme='http://www.blogger.com/atom/ns#' term='Algorithms'/><title type='text'>Extracting unique element(s) from a sorted list</title><content type='html'>&lt;span style="font-weight:bold;color:red"&gt;PROBLEM:&lt;/span&gt; you have a list of sorted elements. All elements are sorted (it could be in ascending order or descending order). You are printing out the unique elements in the sorted list.&lt;br /&gt;&lt;span style="font-weight:bold;color:red;"&gt;COMPLEXITY:&lt;/span&gt; &lt;span style="font-weight:bold;"&gt;O(n)&lt;/span&gt;&lt;br /&gt;&lt;pre&gt;&lt;br /&gt;public class UniqueNumbers {&lt;br /&gt; public static void main(String[] args) {&lt;br /&gt;  int a[]={1, 1, 1, 2, 4, 4, 7, 8, 9, 14, 14, 20, 20, 20};&lt;br /&gt;  //int a[]={1};&lt;br /&gt;  //int a[]={2, 2, 4, 5};&lt;br /&gt;  //int a[]={1, 1, 1, 2, 2, 8};&lt;br /&gt;  //int a[]={1, 1, 1};&lt;br /&gt;  int uniq = a[a.length-1];&lt;br /&gt;  boolean numberExists = false;&lt;br /&gt;  for (int i = 0; i &lt; a.length; i++) {&lt;br /&gt;   if (a[i] == uniq) {&lt;br /&gt;    if (!numberExists) {&lt;br /&gt;     System.out.println("Position: " + i + " Unique Element =&gt; " + a[i]);&lt;br /&gt;     numberExists = true;&lt;br /&gt;    }&lt;br /&gt;   }&lt;br /&gt;   else {&lt;br /&gt;    System.out.println("Position: " + i + " Unique Element =&gt; " + a[i]);&lt;br /&gt;    uniq = a[i];&lt;br /&gt;    numberExists = true;&lt;br /&gt;   }&lt;br /&gt;  }&lt;br /&gt; }&lt;br /&gt;}&lt;br /&gt;&lt;/pre&gt;The output is shown below:&lt;pre&gt;&lt;br /&gt;{1, 1, 1, 2, 4, 4, 7, 8, 9, 14, 14, 20, 20, 20}&lt;br /&gt;Position: 0 Unique Element =&gt; 1&lt;br /&gt;Position: 3 Unique Element =&gt; 2&lt;br /&gt;Position: 4 Unique Element =&gt; 4&lt;br /&gt;Position: 6 Unique Element =&gt; 7&lt;br /&gt;Position: 7 Unique Element =&gt; 8&lt;br /&gt;Position: 8 Unique Element =&gt; 9&lt;br /&gt;Position: 9 Unique Element =&gt; 14&lt;br /&gt;Position: 11 Unique Element =&gt; 20&lt;br /&gt;&lt;br /&gt;{1}&lt;br /&gt;Position: 0 Unique Element =&gt; 1&lt;br /&gt;&lt;br /&gt;{2, 2, 4, 5}&lt;br /&gt;Position: 0 Unique Element =&gt; 2&lt;br /&gt;Position: 2 Unique Element =&gt; 4&lt;br /&gt;Position: 3 Unique Element =&gt; 5&lt;br /&gt;&lt;br /&gt;{1, 1, 1, 2, 2, 8}&lt;br /&gt;Position: 0 Unique Element =&gt; 1&lt;br /&gt;Position: 3 Unique Element =&gt; 2&lt;br /&gt;Position: 5 Unique Element =&gt; 8&lt;br /&gt;&lt;br /&gt;{1, 1, 1}&lt;br /&gt;Position: 0 Unique Element =&gt; 1&lt;br /&gt;&lt;/pre&gt;&lt;span style="font-weight:bold;color:red"&gt;Update:&lt;/span&gt; my solution is not that elegant after all. I had the opportunity to discuss the algorithm with Mark and he has a much better way to solve this problem. Thank you, Mark (you know who you are :D).&lt;br /&gt;&lt;pre&gt;&lt;br /&gt; public static void main(String[] args) {&lt;br /&gt;  int a[]={1, 1, 1, 2, 4, 4, 7, 8, 9, 14, 14, 20, 20, 20};&lt;br /&gt;  //int a[]={1};&lt;br /&gt;  //int a[]={2, 2, 4, 5};&lt;br /&gt;  //int a[]={1, 1, 1, 2, 2, 8};&lt;br /&gt;  //int a[]={1, 1, 1};&lt;br /&gt;  int uniq = a[0];&lt;br /&gt;  System.out.println("Position: " + 0 + " Unique Element =&gt; " + uniq);&lt;br /&gt;  for (int i = 1; i &lt; a.length; i++) {&lt;br /&gt;   if (a[i] != uniq) {&lt;br /&gt;    System.out.println("Position: " + i + " Unique Element =&gt; " + a[i]);&lt;br /&gt;    uniq = a[i];&lt;br /&gt;   }&lt;br /&gt;  }&lt;br /&gt; }&lt;br /&gt;&lt;/pre&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4844902456784005421-6476681339965594720?l=nicholaskey.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://nicholaskey.blogspot.com/feeds/6476681339965594720/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://nicholaskey.blogspot.com/2009/11/extracting-unique-elements-from-sorted.html#comment-form' title='2 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4844902456784005421/posts/default/6476681339965594720'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4844902456784005421/posts/default/6476681339965594720'/><link rel='alternate' type='text/html' href='http://nicholaskey.blogspot.com/2009/11/extracting-unique-elements-from-sorted.html' title='Extracting unique element(s) from a sorted list'/><author><name>Nicholas Key</name><uri>http://www.blogger.com/profile/05768297019453812096</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='http://4.bp.blogspot.com/_OQU38yb-Uq0/SwL5VBlHCII/AAAAAAAAA6U/lXUy53mS7gQ/S220/hamster.jpg'/></author><thr:total>2</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4844902456784005421.post-2313158926861427690</id><published>2009-11-07T09:04:00.001-08:00</published><updated>2009-11-09T19:48:58.940-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Java'/><category scheme='http://www.blogger.com/atom/ns#' term='XML'/><category scheme='http://www.blogger.com/atom/ns#' term='Android'/><title type='text'>Setting defined colors for your Android UI components</title><content type='html'>I don't think the Android SDK manual is helpful enough when it comes to setting the colors that you defined in the XML file (in my example, res -&gt; values -&gt; color.xml). There is actually a workaround instead of following rigidly the guidelines to use the &lt;span style="font-weight:bold;"&gt;setTextColor(int color)&lt;/span&gt; method. &lt;br /&gt;&lt;br /&gt;I believe you must have read the guidelines how to set the color of TextView from &lt;a href="http://developer.android.com/reference/android/widget/TextView.html#setTextColor%28android.content.res.ColorStateList%29"&gt;this URL&lt;/a&gt; and &lt;a href="http://developer.android.com/reference/android/content/res/ColorStateList.html"&gt;this URL&lt;/a&gt; and do not really feel like constructing another XML file as mentioned in the manual.&lt;br /&gt;&lt;br /&gt;I also believe that you must have used this approach to set the color from the Java code,&lt;br /&gt;&lt;span style="font-weight:bold;"&gt;btnInstance.setTextColor(R.color.YOUR_DEFINED_COLOR);&lt;/span&gt;&lt;br /&gt;simply because the setTextColor asks for an Integer as the parameter but you don't see the changes taking place.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight:bold;color:red;"&gt;SOLUTION:&lt;/span&gt; this is &lt;span style="font-weight:bold;"&gt;THE&lt;/span&gt; workaround to set the color of your UI components from the codes.&lt;br /&gt;&lt;span style="font-weight:bold;"&gt;btnInstance.setTextColor(&lt;span style="font-weight:bold;color:red"&gt;getResources().getColor(R.color.YOUR_DEFINED_COLOR&lt;/span&gt;));&lt;/span&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4844902456784005421-2313158926861427690?l=nicholaskey.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://nicholaskey.blogspot.com/feeds/2313158926861427690/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://nicholaskey.blogspot.com/2009/11/setting-defined-colors-for-your-android.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4844902456784005421/posts/default/2313158926861427690'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4844902456784005421/posts/default/2313158926861427690'/><link rel='alternate' type='text/html' href='http://nicholaskey.blogspot.com/2009/11/setting-defined-colors-for-your-android.html' title='Setting defined colors for your Android UI components'/><author><name>Nicholas Key</name><uri>http://www.blogger.com/profile/05768297019453812096</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='http://4.bp.blogspot.com/_OQU38yb-Uq0/SwL5VBlHCII/AAAAAAAAA6U/lXUy53mS7gQ/S220/hamster.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4844902456784005421.post-2146970427130292770</id><published>2009-11-07T09:03:00.001-08:00</published><updated>2011-08-03T06:19:18.119-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Java'/><category scheme='http://www.blogger.com/atom/ns#' term='Interesting Ideas'/><category scheme='http://www.blogger.com/atom/ns#' term='Algorithms'/><title type='text'>The 12 balls puzzle</title><content type='html'>A solution to solve the 12 ball puzzle.&lt;br /&gt;Fact: you know that 11 balls are equally weighted and 1 of them is not&lt;br /&gt;Constraint: you can only use the weighing machine at most 3 times to determine the heaviest ball&lt;pre&gt;&lt;br /&gt;import java.util.Random;&lt;br /&gt;&lt;br /&gt;public class TheHeaviestBall {&lt;br /&gt;&lt;br /&gt; private int count = 0;&lt;br /&gt; private int indexHeaviestBall = 0;&lt;br /&gt; private Random myRand = new Random();&lt;br /&gt; private int[] balls = {1,1,1,1,1,1,1,1,1,1,1,1};&lt;br /&gt; private int[] arrangeBalls(){&lt;br /&gt;  balls[myRand.nextInt(12)] = 2;&lt;br /&gt;  for (int aBall : balls) {&lt;br /&gt;   System.out.print(aBall + " ");&lt;br /&gt;  }&lt;br /&gt;  return balls;&lt;br /&gt; }&lt;br /&gt;&lt;br /&gt; public void weighingCount(){&lt;br /&gt;  count++;&lt;br /&gt;  if (count &gt; 3) {&lt;br /&gt;   System.out.println("Your algorithm fails");&lt;br /&gt;  }&lt;br /&gt; }&lt;br /&gt;&lt;br /&gt; public int theBALL(){&lt;br /&gt;  int myBalls[] = arrangeBalls();&lt;br /&gt;  weighingCount();&lt;br /&gt;  if ((myBalls[0]+myBalls[1]+myBalls[2]+myBalls[3]) &gt; (myBalls[4]+myBalls[5]+myBalls[6]+myBalls[7])) {&lt;br /&gt;   weighingCount();&lt;br /&gt;   if ((myBalls[0]+myBalls[1]) &gt; (myBalls[2]+myBalls[3])) {&lt;br /&gt;    weighingCount();&lt;br /&gt;    if (myBalls[0] &gt; myBalls[1]) {&lt;br /&gt;     indexHeaviestBall = 0;&lt;br /&gt;     return myBalls[0];&lt;br /&gt;    } else {&lt;br /&gt;     indexHeaviestBall = 1;&lt;br /&gt;     return myBalls[1];&lt;br /&gt;    }&lt;br /&gt;   } else {&lt;br /&gt;    weighingCount();&lt;br /&gt;    if (myBalls[2] &gt; myBalls[3]) {&lt;br /&gt;     indexHeaviestBall = 2;&lt;br /&gt;     return myBalls[2];&lt;br /&gt;    } else {&lt;br /&gt;     indexHeaviestBall = 3;&lt;br /&gt;     return myBalls[3];&lt;br /&gt;    }&lt;br /&gt;   }&lt;br /&gt;  }&lt;br /&gt;  else if ((myBalls[4]+myBalls[5]+myBalls[6]+myBalls[7]) &gt; (myBalls[0]+myBalls[1]+myBalls[2]+myBalls[3])) {&lt;br /&gt;   weighingCount();&lt;br /&gt;   if ((myBalls[4]+myBalls[5]) &gt; (myBalls[6]+myBalls[7])) {&lt;br /&gt;    weighingCount();&lt;br /&gt;    if (myBalls[4] &gt; myBalls[5]) {&lt;br /&gt;     indexHeaviestBall = 4;&lt;br /&gt;     return myBalls[4];&lt;br /&gt;    } else {&lt;br /&gt;     indexHeaviestBall = 5;&lt;br /&gt;     return myBalls[5];&lt;br /&gt;    }&lt;br /&gt;   } else {&lt;br /&gt;    weighingCount();&lt;br /&gt;    if (myBalls[6] &gt; myBalls[7]) {&lt;br /&gt;     indexHeaviestBall = 6;&lt;br /&gt;     return myBalls[6];&lt;br /&gt;    } else {&lt;br /&gt;     indexHeaviestBall = 7;&lt;br /&gt;     return myBalls[7];&lt;br /&gt;    }&lt;br /&gt;   }&lt;br /&gt;  }&lt;br /&gt;  else {&lt;br /&gt;   weighingCount();&lt;br /&gt;   if ((myBalls[8]+myBalls[9]) &gt; (myBalls[10]+myBalls[11])) {&lt;br /&gt;    weighingCount();&lt;br /&gt;    if (myBalls[8] &gt; myBalls[9]) {&lt;br /&gt;     indexHeaviestBall = 8;&lt;br /&gt;     return myBalls[8];&lt;br /&gt;    } else {&lt;br /&gt;     indexHeaviestBall = 9;&lt;br /&gt;     return myBalls[9];&lt;br /&gt;    }&lt;br /&gt;   } else {&lt;br /&gt;    weighingCount();&lt;br /&gt;    if (myBalls[10] &gt; myBalls[11]) {&lt;br /&gt;     indexHeaviestBall = 10;&lt;br /&gt;     return myBalls[10];&lt;br /&gt;    } else {&lt;br /&gt;     indexHeaviestBall = 11;&lt;br /&gt;     return myBalls[11];&lt;br /&gt;    }&lt;br /&gt;   }&lt;br /&gt;  }&lt;br /&gt; }&lt;br /&gt;&lt;br /&gt; public static void getMyHeaviestBall(){&lt;br /&gt;  TheHeaviestBall hb = new TheHeaviestBall();&lt;br /&gt;  //Algorithm validation&lt;br /&gt;  if (hb.count &gt; 3) {&lt;br /&gt;   System.out.println("You can do better");&lt;br /&gt;  } else {&lt;br /&gt;   System.out.println("\nThe heaviest ball [ " + hb.theBALL() + " ] is the " + (hb.indexHeaviestBall + 1) + "th ball from the left");&lt;br /&gt;  }&lt;br /&gt; }&lt;br /&gt;&lt;br /&gt; public static void main(String[] args) {&lt;br /&gt;  getMyHeaviestBall();&lt;br /&gt; }&lt;br /&gt;}&lt;br /&gt;&lt;/pre&gt;&lt;span style="font-weight:bold;color:red;"&gt;Update: &lt;/span&gt;&lt;a href="http://nicholaskey.blogspot.com/2009/11/8-balls-puzzle.html"&gt;Click here&lt;/a&gt; to view the solution to solve the 8 balls puzzle&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4844902456784005421-2146970427130292770?l=nicholaskey.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://nicholaskey.blogspot.com/feeds/2146970427130292770/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://nicholaskey.blogspot.com/2009/11/12-balls-puzzle.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4844902456784005421/posts/default/2146970427130292770'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4844902456784005421/posts/default/2146970427130292770'/><link rel='alternate' type='text/html' href='http://nicholaskey.blogspot.com/2009/11/12-balls-puzzle.html' title='The 12 balls puzzle'/><author><name>Nicholas Key</name><uri>http://www.blogger.com/profile/05768297019453812096</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='http://4.bp.blogspot.com/_OQU38yb-Uq0/SwL5VBlHCII/AAAAAAAAA6U/lXUy53mS7gQ/S220/hamster.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4844902456784005421.post-1058926499865796937</id><published>2009-11-06T10:47:00.009-08:00</published><updated>2011-08-03T06:20:01.544-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Java'/><category scheme='http://www.blogger.com/atom/ns#' term='Interesting Ideas'/><category scheme='http://www.blogger.com/atom/ns#' term='Algorithms'/><title type='text'>The 8 balls puzzle</title><content type='html'>Here is an interesting puzzle about selecting the heaviest ball among 7 other equally weighted balls. For example a collection of the 8 balls would look like this [2,1,1,1,1,1,1,1].&lt;br /&gt;&lt;br /&gt;The goal is to choose the heaviest ball by performing only two weighings.&lt;br /&gt;Fact: You know that all 7 other balls are equally weighted but you could not figure out the heaviest ball. &lt;br /&gt;Solution: In order to do so, you are using the weighing machine but as a challenge you can only use the weighing machine at most twice&lt;pre&gt;&lt;br /&gt;import java.util.Random;&lt;br /&gt;&lt;br /&gt;public class TheHeaviestBall {&lt;br /&gt;&lt;br /&gt; private int count = 0;&lt;br /&gt; private int indexHeaviestBall = 0;&lt;br /&gt; private Random myRand = new Random();&lt;br /&gt; private int[] balls = {1,1,1,1,1,1,1,1};&lt;br /&gt; private int[] arrangeBalls(){&lt;br /&gt;  balls[myRand.nextInt(8)] = 2;&lt;br /&gt;  for (int aBall : balls) {&lt;br /&gt;   System.out.print(aBall + " ");&lt;br /&gt;  }&lt;br /&gt;  return balls;&lt;br /&gt; }&lt;br /&gt;&lt;br /&gt; public void weighingCount(){&lt;br /&gt;  count++;&lt;br /&gt;  if (count &gt; 2) {&lt;br /&gt;   System.out.println("Your algorithm fails");&lt;br /&gt;  }&lt;br /&gt; }&lt;br /&gt;&lt;br /&gt; public int theBALL(){&lt;br /&gt;  int myBalls[] = arrangeBalls();&lt;br /&gt;  weighingCount();&lt;br /&gt;  if ((myBalls[0]+myBalls[1]+myBalls[2]) &gt; (myBalls[3]+myBalls[4]+myBalls[5])) {&lt;br /&gt;   weighingCount();&lt;br /&gt;   if (myBalls[1] == myBalls[2]) {&lt;br /&gt;    indexHeaviestBall = 0;&lt;br /&gt;    return myBalls[0];&lt;br /&gt;   } else {&lt;br /&gt;    if (myBalls[1] &gt;= myBalls[2]) {&lt;br /&gt;     indexHeaviestBall = 1;&lt;br /&gt;     return myBalls[1];&lt;br /&gt;    } else {&lt;br /&gt;     indexHeaviestBall = 2;&lt;br /&gt;     return myBalls[2];&lt;br /&gt;    }&lt;br /&gt;   }&lt;br /&gt;  }&lt;br /&gt;  else if ((myBalls[3]+myBalls[4]+myBalls[5]) &gt; (myBalls[0]+myBalls[1]+myBalls[2])) {&lt;br /&gt;   weighingCount();&lt;br /&gt;   if (myBalls[4] == myBalls[5]) {&lt;br /&gt;    return myBalls[3];&lt;br /&gt;   } else {&lt;br /&gt;    if (myBalls[4] &gt;= myBalls[5]) {&lt;br /&gt;     indexHeaviestBall = 4;&lt;br /&gt;     return myBalls[4];&lt;br /&gt;    }&lt;br /&gt;    else {&lt;br /&gt;     indexHeaviestBall = 5;&lt;br /&gt;     return myBalls[5];&lt;br /&gt;    }&lt;br /&gt;   }&lt;br /&gt;  }&lt;br /&gt;  else {&lt;br /&gt;   weighingCount();&lt;br /&gt;   if (myBalls[6] &gt;= myBalls[7]) {&lt;br /&gt;    indexHeaviestBall = 6;&lt;br /&gt;    return myBalls[6];&lt;br /&gt;   }&lt;br /&gt;   else {&lt;br /&gt;    indexHeaviestBall = 7;&lt;br /&gt;    return myBalls[7];&lt;br /&gt;   }&lt;br /&gt;  }&lt;br /&gt; }&lt;br /&gt;&lt;br /&gt; public static void getMyHeaviestBall(){&lt;br /&gt;  TheHeaviestBall hb = new TheHeaviestBall();&lt;br /&gt;  //Algorithm validation&lt;br /&gt;  if (hb.count &gt; 2) {&lt;br /&gt;   System.out.println("You can do better");&lt;br /&gt;  } else {&lt;br /&gt;   System.out.println("\nThe heaviest ball [ " + hb.theBALL() + " ] is the " + (hb.indexHeaviestBall + 1) + "th ball from the left");&lt;br /&gt;  }&lt;br /&gt; }&lt;br /&gt;&lt;br /&gt; public static void main(String[] args) {&lt;br /&gt;  getMyHeaviestBall();&lt;br /&gt; }&lt;br /&gt;}&lt;br /&gt;&lt;/pre&gt;&lt;span style="font-weight:bold;color:red;"&gt;Update: &lt;/span&gt;&lt;a href="http://nicholaskey.blogspot.com/2009/11/12-balls-puzzle.html"&gt;Click here&lt;/a&gt; to view the solution to solve the 12 balls puzzle&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4844902456784005421-1058926499865796937?l=nicholaskey.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://nicholaskey.blogspot.com/feeds/1058926499865796937/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://nicholaskey.blogspot.com/2009/11/8-balls-puzzle.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4844902456784005421/posts/default/1058926499865796937'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4844902456784005421/posts/default/1058926499865796937'/><link rel='alternate' type='text/html' href='http://nicholaskey.blogspot.com/2009/11/8-balls-puzzle.html' title='The 8 balls puzzle'/><author><name>Nicholas Key</name><uri>http://www.blogger.com/profile/05768297019453812096</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='http://4.bp.blogspot.com/_OQU38yb-Uq0/SwL5VBlHCII/AAAAAAAAA6U/lXUy53mS7gQ/S220/hamster.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4844902456784005421.post-3674380929199728258</id><published>2009-11-06T10:47:00.007-08:00</published><updated>2009-11-06T18:30:28.418-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Java'/><category scheme='http://www.blogger.com/atom/ns#' term='Android'/><category scheme='http://www.blogger.com/atom/ns#' term='Interesting Ideas'/><title type='text'>Quizzie - my first Android application</title><content type='html'>Behold ... my very first fully functional Android application. The development process is very short. I always have this philosophy that if you know what you want to do and achieve, you will know what to do and how to achieve it. Therefore the design process is shortened. &lt;br /&gt;&lt;br /&gt;This game is all about Mathematics. Seemingly simple mathematical expressions but good enough to induce carelessness to choose the wrong answer.&lt;div style="text-align:center;"&gt;&lt;object width="400" height="730"&gt; &lt;param name="movie" value="http://content.screencast.com/users/nicholaskeytholeong/folders/Jing/media/3d484994-012a-4bf5-99be-8eaa60a51d83/bootstrap.swf"&gt;&lt;/param&gt; &lt;param name="quality" value="high"&gt;&lt;/param&gt; &lt;param name="bgcolor" value="#FFFFFF"&gt;&lt;/param&gt; &lt;param name="flashVars" value="thumb=http://content.screencast.com/users/nicholaskeytholeong/folders/Jing/media/3d484994-012a-4bf5-99be-8eaa60a51d83/FirstFrame.jpg&amp;containerwidth=400&amp;containerheight=730&amp;content=http://content.screencast.com/users/nicholaskeytholeong/folders/Jing/media/3d484994-012a-4bf5-99be-8eaa60a51d83/2009-11-06_1624.swf&amp;advseek=true"&gt;&lt;/param&gt; &lt;param name="allowFullScreen" value="true"&gt;&lt;/param&gt; &lt;param name="scale" value="showall"&gt;&lt;/param&gt; &lt;param name="allowScriptAccess" value="always"&gt;&lt;/param&gt; &lt;param name="base" value="http://content.screencast.com/users/nicholaskeytholeong/folders/Jing/media/3d484994-012a-4bf5-99be-8eaa60a51d83/"&gt;&lt;/param&gt;  &lt;embed src="http://content.screencast.com/users/nicholaskeytholeong/folders/Jing/media/3d484994-012a-4bf5-99be-8eaa60a51d83/bootstrap.swf" quality="high" bgcolor="#FFFFFF" width="400" height="730" type="application/x-shockwave-flash" allowScriptAccess="always" flashVars="thumb=http://content.screencast.com/users/nicholaskeytholeong/folders/Jing/media/3d484994-012a-4bf5-99be-8eaa60a51d83/FirstFrame.jpg&amp;containerwidth=400&amp;containerheight=730&amp;content=http://content.screencast.com/users/nicholaskeytholeong/folders/Jing/media/3d484994-012a-4bf5-99be-8eaa60a51d83/2009-11-06_1624.swf&amp;advseek=true" allowFullScreen="true" base="http://content.screencast.com/users/nicholaskeytholeong/folders/Jing/media/3d484994-012a-4bf5-99be-8eaa60a51d83/" scale="showall"&gt;&lt;/embed&gt; &lt;/object&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4844902456784005421-3674380929199728258?l=nicholaskey.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://nicholaskey.blogspot.com/feeds/3674380929199728258/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://nicholaskey.blogspot.com/2009/11/quizzie-my-first-android-application.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4844902456784005421/posts/default/3674380929199728258'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4844902456784005421/posts/default/3674380929199728258'/><link rel='alternate' type='text/html' href='http://nicholaskey.blogspot.com/2009/11/quizzie-my-first-android-application.html' title='Quizzie - my first Android application'/><author><name>Nicholas Key</name><uri>http://www.blogger.com/profile/05768297019453812096</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='http://4.bp.blogspot.com/_OQU38yb-Uq0/SwL5VBlHCII/AAAAAAAAA6U/lXUy53mS7gQ/S220/hamster.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4844902456784005421.post-1357616960345179869</id><published>2009-11-04T09:09:00.007-08:00</published><updated>2009-11-06T07:35:29.732-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Funny'/><title type='text'>Splunk in Movie Characters Timeline</title><content type='html'>These are the graphs that could be possibly (fictitiously) generated using Splunk to search for the characters in movies. Take a look at this:&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://3.bp.blogspot.com/_OQU38yb-Uq0/SvG2EOxX-sI/AAAAAAAAA5o/OxB1M8-sLTA/s1600-h/movie_narrative_charts_large.png"&gt;&lt;img style="display:block; margin:0px auto 10px; text-align:center;cursor:pointer; cursor:hand;width: 400px; height: 252px;" src="http://3.bp.blogspot.com/_OQU38yb-Uq0/SvG2EOxX-sI/AAAAAAAAA5o/OxB1M8-sLTA/s400/movie_narrative_charts_large.png" border="0" alt=""id="BLOGGER_PHOTO_ID_5400297611994856130" /&gt;&lt;/a&gt;&lt;a href="http://xkcd.com/657/large/"&gt;&lt;span style="font-weight:bold;"&gt;Click here&lt;/span&gt;&lt;/a&gt; to view the original source of the picture from xkcd.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4844902456784005421-1357616960345179869?l=nicholaskey.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://nicholaskey.blogspot.com/feeds/1357616960345179869/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://nicholaskey.blogspot.com/2009/11/splunk-in-movie-characters-timeline.html#comment-form' title='3 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4844902456784005421/posts/default/1357616960345179869'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4844902456784005421/posts/default/1357616960345179869'/><link rel='alternate' type='text/html' href='http://nicholaskey.blogspot.com/2009/11/splunk-in-movie-characters-timeline.html' title='Splunk in Movie Characters Timeline'/><author><name>Nicholas Key</name><uri>http://www.blogger.com/profile/05768297019453812096</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='http://4.bp.blogspot.com/_OQU38yb-Uq0/SwL5VBlHCII/AAAAAAAAA6U/lXUy53mS7gQ/S220/hamster.jpg'/></author><media:thumbnail xmlns:media='http://search.yahoo.com/mrss/' url='http://3.bp.blogspot.com/_OQU38yb-Uq0/SvG2EOxX-sI/AAAAAAAAA5o/OxB1M8-sLTA/s72-c/movie_narrative_charts_large.png' height='72' width='72'/><thr:total>3</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4844902456784005421.post-1884673696337051252</id><published>2009-11-04T09:09:00.003-08:00</published><updated>2009-11-04T19:55:15.063-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Funny'/><title type='text'>Saying that something is wrong to someone</title><content type='html'>This is a hilarious way to express to someone if something is wrong. By the way if Cartman thinks that it is wrong, it must be really really wrong. :))&lt;br /&gt;&lt;div style="text-align:center"&gt;&lt;object width="425" height="344"&gt;&lt;param name="movie" value="http://www.youtube.com/v/7hBTqgCGnhU&amp;hl=en&amp;fs=1&amp;"&gt;&lt;/param&gt;&lt;param name="allowFullScreen" value="true"&gt;&lt;/param&gt;&lt;param name="allowscriptaccess" value="always"&gt;&lt;/param&gt;&lt;embed src="http://www.youtube.com/v/7hBTqgCGnhU&amp;hl=en&amp;fs=1&amp;" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="425" height="344"&gt;&lt;/embed&gt;&lt;/object&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4844902456784005421-1884673696337051252?l=nicholaskey.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://nicholaskey.blogspot.com/feeds/1884673696337051252/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://nicholaskey.blogspot.com/2009/11/saying-that-something-is-wrong-to.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4844902456784005421/posts/default/1884673696337051252'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4844902456784005421/posts/default/1884673696337051252'/><link rel='alternate' type='text/html' href='http://nicholaskey.blogspot.com/2009/11/saying-that-something-is-wrong-to.html' title='Saying that something is wrong to someone'/><author><name>Nicholas Key</name><uri>http://www.blogger.com/profile/05768297019453812096</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='http://4.bp.blogspot.com/_OQU38yb-Uq0/SwL5VBlHCII/AAAAAAAAA6U/lXUy53mS7gQ/S220/hamster.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4844902456784005421.post-9208840724020612535</id><published>2009-11-02T08:46:00.005-08:00</published><updated>2009-11-02T08:53:24.342-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Java'/><category scheme='http://www.blogger.com/atom/ns#' term='Android'/><title type='text'>Sound Management in Android Application</title><content type='html'>This is a suggestion from myself about adjusting the volume of the sound effects or background music in your Android Activity(ies). The sample code is as below:&lt;textarea name="code" class="java" cols="60" rows="1000"&gt;&lt;br /&gt; public boolean onKeyDown(int keyCode, KeyEvent event) {                  &lt;br /&gt;  AudioManager audioMgr = (AudioManager)getSystemService(AUDIO_SERVICE);&lt;br /&gt;  switch (keyCode) {&lt;br /&gt;  case KeyEvent.KEYCODE_VOLUME_UP :&lt;br /&gt;   audioMgr.adjustStreamVolume(AudioManager.STREAM_MUSIC,&lt;br /&gt;     AudioManager.ADJUST_RAISE, &lt;br /&gt;     AudioManager.FLAG_SHOW_UI);&lt;br /&gt;   return true;&lt;br /&gt;  case KeyEvent.KEYCODE_VOLUME_DOWN:&lt;br /&gt;   audioMgr.adjustStreamVolume(AudioManager.STREAM_MUSIC, &lt;br /&gt;     AudioManager.ADJUST_LOWER, &lt;br /&gt;     AudioManager.FLAG_SHOW_UI);&lt;br /&gt;   return true;&lt;br /&gt;  }&lt;br /&gt;  return false;&lt;br /&gt; }&lt;br /&gt;&lt;br /&gt; public boolean onKeyUp(int keyCode, KeyEvent event) {&lt;br /&gt;  AudioManager audioMgr = (AudioManager)getSystemService(AUDIO_SERVICE);&lt;br /&gt;  switch (keyCode) {&lt;br /&gt;  case KeyEvent.KEYCODE_VOLUME_UP :&lt;br /&gt;   audioMgr.adjustStreamVolume(AudioManager.STREAM_MUSIC, &lt;br /&gt;     AudioManager.ADJUST_SAME, &lt;br /&gt;     AudioManager.FLAG_SHOW_UI);&lt;br /&gt;   return true;&lt;br /&gt;  case KeyEvent.KEYCODE_VOLUME_DOWN:&lt;br /&gt;   audioMgr.adjustStreamVolume(AudioManager.STREAM_MUSIC, &lt;br /&gt;     AudioManager.ADJUST_SAME, &lt;br /&gt;     AudioManager.FLAG_SHOW_UI);&lt;br /&gt;   return true;&lt;br /&gt;  }&lt;br /&gt;  return false;&lt;br /&gt; }&lt;br /&gt;&lt;/textarea&gt;onKeyDown method is called when a button is pressed and onKeyUp is called when the button is released. In this example specifically, we are raising and lowering the volumes when the volume keys are pressed and retain the values when the buttons are released.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4844902456784005421-9208840724020612535?l=nicholaskey.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://nicholaskey.blogspot.com/feeds/9208840724020612535/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://nicholaskey.blogspot.com/2009/11/sound-management-in-android-application.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4844902456784005421/posts/default/9208840724020612535'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4844902456784005421/posts/default/9208840724020612535'/><link rel='alternate' type='text/html' href='http://nicholaskey.blogspot.com/2009/11/sound-management-in-android-application.html' title='Sound Management in Android Application'/><author><name>Nicholas Key</name><uri>http://www.blogger.com/profile/05768297019453812096</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='http://4.bp.blogspot.com/_OQU38yb-Uq0/SwL5VBlHCII/AAAAAAAAA6U/lXUy53mS7gQ/S220/hamster.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4844902456784005421.post-2479415044753461022</id><published>2009-11-02T08:46:00.001-08:00</published><updated>2009-11-02T18:41:44.682-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Java'/><category scheme='http://www.blogger.com/atom/ns#' term='Android'/><title type='text'>Adding Vibration to your Android Application</title><content type='html'>Below are the simple steps to enable the vibration feature for your Android application. There are two things you will need to take care of - the AndroidManifest.xml file and the Vibrate class.&lt;br /&gt;&lt;br /&gt;[1] Add this line in manifest file:&lt;br /&gt;&amp;lt;?xml version="1.0" encoding="utf-8"?&gt; &lt;br /&gt;  &amp;lt;manifest xmlns:android="http://schemas.android.com/apk/res/android"&lt;br /&gt;  . . .&lt;br /&gt;  . . .&lt;br /&gt;  . . .&lt;br /&gt;  &lt;span style="font-weight:bold;color:red;"&gt;&amp;lt;uses-permission android:name="android.permission.VIBRATE"&gt;&lt;/uses- &lt;br /&gt;permission&gt; &lt;/span&gt;&lt;br /&gt;&amp;lt;/manifest&gt; &lt;br /&gt;&lt;br /&gt;[2] Add these two lines in your class definition.&lt;textarea name="code" class="java" cols="60" rows="1000"&gt;&lt;br /&gt;Vibrator vibrate = (Vibrator) getSystemService(VIBRATOR_SERVICE); &lt;br /&gt;//vibrate for 300 miliseconds&lt;br /&gt;vibrate.vibrate(300);&lt;br /&gt;&lt;/textarea&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4844902456784005421-2479415044753461022?l=nicholaskey.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://nicholaskey.blogspot.com/feeds/2479415044753461022/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://nicholaskey.blogspot.com/2009/11/adding-vibration-to-your-android.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4844902456784005421/posts/default/2479415044753461022'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4844902456784005421/posts/default/2479415044753461022'/><link rel='alternate' type='text/html' href='http://nicholaskey.blogspot.com/2009/11/adding-vibration-to-your-android.html' title='Adding Vibration to your Android Application'/><author><name>Nicholas Key</name><uri>http://www.blogger.com/profile/05768297019453812096</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='http://4.bp.blogspot.com/_OQU38yb-Uq0/SwL5VBlHCII/AAAAAAAAA6U/lXUy53mS7gQ/S220/hamster.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4844902456784005421.post-1596061678680916427</id><published>2009-10-31T23:16:00.003-07:00</published><updated>2009-12-01T22:53:57.261-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Eclipse'/><category scheme='http://www.blogger.com/atom/ns#' term='APK'/><category scheme='http://www.blogger.com/atom/ns#' term='Android'/><title type='text'>Deploying Android package (.apk) into Mobile Device from Eclipse IDE</title><content type='html'>Feeling very frustrated trying to understand the deployment guidelines in the Android SDK website, I am writing this article to share my knowledge and experience in deploying Android applications from Eclipse into Android-powered mobile devices in Debug Mode to the readers who are also interested in developing Android applications. I have not explore the processes of signing an Android application for Public Release Mode, yet.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight:bold;color:red;"&gt;A major correction:&lt;/span&gt;&lt;br /&gt;You can actually deploy your Android application without signing it in Debug Mode. Simply follow these steps and you are ready to test your application.&lt;br /&gt;&lt;br /&gt;Things to do with the mobile device:&lt;br /&gt;1. Press Menu button&lt;br /&gt;2. Tap on Settings button&lt;br /&gt;3. Tap on Applications in the menu&lt;br /&gt;4. Put a check for Unknown Sources (to allow installation of non-Market applications)&lt;br /&gt;5. Tap on Development (to set options for application development)&lt;br /&gt;6. Put a check on USB debugging (to enable the Debug Mode when USB is connected)&lt;br /&gt;7. Press Back button to go back to to the Settings menu&lt;br /&gt;8. Plug your USB cable into the computer&lt;br /&gt;&lt;br /&gt;Things to do with the console:&lt;br /&gt;1. Go to the bin directory that places the APK file.&lt;br /&gt;2. Type adb install &lt;APK_FILE_NAME&gt;&lt;br /&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://3.bp.blogspot.com/_OQU38yb-Uq0/Su03z_kokCI/AAAAAAAAA5g/lWgG-mBrBAI/s1600-h/Picture+2.png"&gt;&lt;img style="display:block; margin:0px auto 10px; text-align:center;cursor:pointer; cursor:hand;width: 400px; height: 80px;" src="http://3.bp.blogspot.com/_OQU38yb-Uq0/Su03z_kokCI/AAAAAAAAA5g/lWgG-mBrBAI/s400/Picture+2.png" border="0" alt=""id="BLOGGER_PHOTO_ID_5399032894665035810" /&gt;&lt;/a&gt;&lt;br /&gt;Optional:&lt;br /&gt;You may do zipalign in the console if you wish to do so.&lt;br /&gt;&lt;br /&gt;I hope this article is useful and informative enough for the Android developer community. Please leave your comments in the comments section if this does not work for you.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight:bold;color:red;"&gt;UPDATE:&lt;/span&gt; you may actually deploy your Android app by right-clicking at your project name. Select "Run As" and then click at "Android Application."&lt;br /&gt;&lt;br /&gt;As simple as that. :)&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4844902456784005421-1596061678680916427?l=nicholaskey.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://nicholaskey.blogspot.com/feeds/1596061678680916427/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://nicholaskey.blogspot.com/2009/10/deploying-android-package-apk-into.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4844902456784005421/posts/default/1596061678680916427'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4844902456784005421/posts/default/1596061678680916427'/><link rel='alternate' type='text/html' href='http://nicholaskey.blogspot.com/2009/10/deploying-android-package-apk-into.html' title='Deploying Android package (.apk) into Mobile Device from Eclipse IDE'/><author><name>Nicholas Key</name><uri>http://www.blogger.com/profile/05768297019453812096</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='http://4.bp.blogspot.com/_OQU38yb-Uq0/SwL5VBlHCII/AAAAAAAAA6U/lXUy53mS7gQ/S220/hamster.jpg'/></author><media:thumbnail xmlns:media='http://search.yahoo.com/mrss/' url='http://3.bp.blogspot.com/_OQU38yb-Uq0/Su03z_kokCI/AAAAAAAAA5g/lWgG-mBrBAI/s72-c/Picture+2.png' height='72' width='72'/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4844902456784005421.post-7565866518335017204</id><published>2009-10-28T00:30:00.005-07:00</published><updated>2009-10-28T22:43:54.776-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Android'/><title type='text'>Motorola Droid (Android 2.0)</title><content type='html'>The Droid looks fancy but I think any smartphones will look a lot more attractive with some shades of metallic coating or aluminum casing. This is the video from CNET showcasing Motorola Droid.&lt;div style="text-align:center;"&gt;&lt;object width="560" height="340"&gt;&lt;param name="movie" value="http://www.youtube.com/v/RDviTGDCvGM&amp;hl=en&amp;fs=1&amp;"&gt;&lt;/param&gt;&lt;param name="allowFullScreen" value="true"&gt;&lt;/param&gt;&lt;param name="allowscriptaccess" value="always"&gt;&lt;/param&gt;&lt;embed src="http://www.youtube.com/v/RDviTGDCvGM&amp;hl=en&amp;fs=1&amp;" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="560" height="340"&gt;&lt;/embed&gt;&lt;/object&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4844902456784005421-7565866518335017204?l=nicholaskey.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://nicholaskey.blogspot.com/feeds/7565866518335017204/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://nicholaskey.blogspot.com/2009/10/motorola-droid-android-20.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4844902456784005421/posts/default/7565866518335017204'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4844902456784005421/posts/default/7565866518335017204'/><link rel='alternate' type='text/html' href='http://nicholaskey.blogspot.com/2009/10/motorola-droid-android-20.html' title='Motorola Droid (Android 2.0)'/><author><name>Nicholas Key</name><uri>http://www.blogger.com/profile/05768297019453812096</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='http://4.bp.blogspot.com/_OQU38yb-Uq0/SwL5VBlHCII/AAAAAAAAA6U/lXUy53mS7gQ/S220/hamster.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4844902456784005421.post-8220868982950798387</id><published>2009-10-28T00:30:00.003-07:00</published><updated>2009-10-28T19:49:16.647-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Splunk'/><category scheme='http://www.blogger.com/atom/ns#' term='Log Management'/><title type='text'>Search Assistant in Splunk 4</title><content type='html'>Being a software developer whose passion evolves about search, mobile applications and analytics and love to look at log files, I find that the most useful and technically attractive feature as I play along with the free version of Splunk&gt; is the Search feature. It is so helpful that contextual suggestions will be given to you as you type your search phrases in the textfield. Initially I was completely clueless about how to perform a search. &lt;br /&gt;&lt;br /&gt;The screenshots are as shown below. The top most image is the untouched search string. At first I was afraid to type anything into the textfield having the similar fear that Google might crash if we search for "google". Nah ... just kidding:P As a fail-safe software developer I assume that Splunk has an excellent exception handlings. However, I tried searching for the usage manual but I did not know how to search for it (for example the appropriate search strings to search for the manual and such).&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://1.bp.blogspot.com/_OQU38yb-Uq0/Suj3XE8y1yI/AAAAAAAAA3s/7nBw2iOecPg/s1600-h/Picture+5.png"&gt;&lt;img style="display:block; margin:0px auto 10px; text-align:center;cursor:pointer; cursor:hand;width: 400px; height: 177px;" src="http://1.bp.blogspot.com/_OQU38yb-Uq0/Suj3XE8y1yI/AAAAAAAAA3s/7nBw2iOecPg/s400/Picture+5.png" border="0" alt=""id="BLOGGER_PHOTO_ID_5397836129241323298" /&gt;&lt;/a&gt;Imagine myself greeting you "Hi, this is Nicholas Key and I'm a software engineer. EEErrrggghhh..."&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://2.bp.blogspot.com/_OQU38yb-Uq0/Suj7DexODRI/AAAAAAAAA38/2UcI4ioNaGc/s1600-h/Picture+7.png"&gt;&lt;img style="display:block; margin:0px auto 10px; text-align:center;cursor:pointer; cursor:hand;width: 400px; height: 180px;" src="http://2.bp.blogspot.com/_OQU38yb-Uq0/Suj7DexODRI/AAAAAAAAA38/2UcI4ioNaGc/s400/Picture+7.png" border="0" alt=""id="BLOGGER_PHOTO_ID_5397840190621224210" /&gt;&lt;/a&gt;This video provides you an excellent way to get started, in my opinion.&lt;div style="text-align:center;"&gt;&lt;br /&gt;&lt;embed id="movie_article_4070" width="625" height="372" flashvars="file=http://coverall.splunk.com//web_assets/video/2009/dev/Carasso/Search_Assist_Carasso.flv&amp;streamer=lighttpd&amp;autostart=false" allowfullscreen="true" allowscriptaccess="always" quality="high" bgcolor="#ffffff" name="movie_article_4070" style="" src="http://coverall.splunk.com/web_assets/video/flash_components/player3.swf" type="application/x-shockwave-flash"&gt;&lt;/embed&gt;&lt;/div&gt;&lt;br /&gt;&lt;span style="font-weight:bold;color:red;"&gt;Update:&lt;/span&gt; Actually there is an introduction that teaches you how to use the Search feature but I overlooked it. Instead of clicking at Getting Started, I clicked at *NIX. You may find a brief explanation about using various techniques to perform search. Screenshots are as below:&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://1.bp.blogspot.com/_OQU38yb-Uq0/SukCb1eeGhI/AAAAAAAAA4E/MLpbdHy5Ku8/s1600-h/Picture+2.png"&gt;&lt;img style="display:block; margin:0px auto 10px; text-align:center;cursor:pointer; cursor:hand;width: 400px; height: 247px;" src="http://1.bp.blogspot.com/_OQU38yb-Uq0/SukCb1eeGhI/AAAAAAAAA4E/MLpbdHy5Ku8/s400/Picture+2.png" border="0" alt=""id="BLOGGER_PHOTO_ID_5397848305614854674" /&gt;&lt;/a&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://1.bp.blogspot.com/_OQU38yb-Uq0/SukCj8uyf7I/AAAAAAAAA4M/Qv5788NOA9U/s1600-h/Picture+8.png"&gt;&lt;img style="display:block; margin:0px auto 10px; text-align:center;cursor:pointer; cursor:hand;width: 400px; height: 284px;" src="http://1.bp.blogspot.com/_OQU38yb-Uq0/SukCj8uyf7I/AAAAAAAAA4M/Qv5788NOA9U/s400/Picture+8.png" border="0" alt=""id="BLOGGER_PHOTO_ID_5397848445001301938" /&gt;&lt;/a&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4844902456784005421-8220868982950798387?l=nicholaskey.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://nicholaskey.blogspot.com/feeds/8220868982950798387/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://nicholaskey.blogspot.com/2009/10/search-assistant-in-splunk-4.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4844902456784005421/posts/default/8220868982950798387'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4844902456784005421/posts/default/8220868982950798387'/><link rel='alternate' type='text/html' href='http://nicholaskey.blogspot.com/2009/10/search-assistant-in-splunk-4.html' title='Search Assistant in Splunk 4'/><author><name>Nicholas Key</name><uri>http://www.blogger.com/profile/05768297019453812096</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='http://4.bp.blogspot.com/_OQU38yb-Uq0/SwL5VBlHCII/AAAAAAAAA6U/lXUy53mS7gQ/S220/hamster.jpg'/></author><media:thumbnail xmlns:media='http://search.yahoo.com/mrss/' url='http://1.bp.blogspot.com/_OQU38yb-Uq0/Suj3XE8y1yI/AAAAAAAAA3s/7nBw2iOecPg/s72-c/Picture+5.png' height='72' width='72'/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4844902456784005421.post-5573494041019951039</id><published>2009-10-28T00:30:00.001-07:00</published><updated>2009-10-28T21:05:33.410-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Python'/><category scheme='http://www.blogger.com/atom/ns#' term='Algorithms'/><title type='text'>My Java codes in Python (Part 3)</title><content type='html'>Prologue: I feel like making a tag cloud for the labels of my articles ;)&lt;textarea name="code" class="python" cols="60" rows="1000"&gt;&lt;br /&gt;### Calculate GCD&lt;br /&gt;### http://nicholaskey.blogspot.com/2009/07/greatest-common-divisor-recursion.html&lt;br /&gt;def GCD(numberA, numberB):&lt;br /&gt;    if (numberB == 0):&lt;br /&gt;        return numberA&lt;br /&gt;    else:&lt;br /&gt;        return GCD(numberB, numberA % numberB);&lt;br /&gt;&lt;br /&gt;### Removes duplicate characters in a string&lt;br /&gt;### http://nicholaskey.blogspot.com/2009/05/deduplication.html&lt;br /&gt;def removeDuplicates(text):&lt;br /&gt;    uniq = []&lt;br /&gt;    for char in text:&lt;br /&gt;        if char not in uniq:&lt;br /&gt;            uniq.append(char)&lt;br /&gt;    return ''.join(aChar for aChar in uniq)&lt;br /&gt;&lt;/textarea&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4844902456784005421-5573494041019951039?l=nicholaskey.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://nicholaskey.blogspot.com/feeds/5573494041019951039/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://nicholaskey.blogspot.com/2009/10/my-java-codes-in-python-part-2_28.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4844902456784005421/posts/default/5573494041019951039'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4844902456784005421/posts/default/5573494041019951039'/><link rel='alternate' type='text/html' href='http://nicholaskey.blogspot.com/2009/10/my-java-codes-in-python-part-2_28.html' title='My Java codes in Python (Part 3)'/><author><name>Nicholas Key</name><uri>http://www.blogger.com/profile/05768297019453812096</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='http://4.bp.blogspot.com/_OQU38yb-Uq0/SwL5VBlHCII/AAAAAAAAA6U/lXUy53mS7gQ/S220/hamster.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4844902456784005421.post-3355120384313731376</id><published>2009-10-28T00:29:00.000-07:00</published><updated>2009-10-28T10:00:21.305-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Python'/><category scheme='http://www.blogger.com/atom/ns#' term='Algorithms'/><title type='text'>My Java codes in Python (Part 2)</title><content type='html'>&lt;textarea name="code" class="python" cols="60" rows="1000"&gt;&lt;br /&gt;### Returns a boolean value True if a substring is found&lt;br /&gt;### print "Contains substring:", substr("Nicholas", "cho")&lt;br /&gt;### print "Contains substring:", substr("Nicholas", "JohnDoe")&lt;br /&gt;### http://nicholaskey.blogspot.com/2009/04/finding-substring-in-string.html&lt;br /&gt;def substr(inputStr, subStr):&lt;br /&gt;    found = False&lt;br /&gt;    check = 0&lt;br /&gt;    newString = ""&lt;br /&gt;    for char in inputStr:&lt;br /&gt;        if (char == subStr[check]):&lt;br /&gt;            newString = newString + char&lt;br /&gt;            check += 1&lt;br /&gt;            if (newString == subStr):&lt;br /&gt;                found = True&lt;br /&gt;                break&lt;br /&gt;    return found&lt;br /&gt;&lt;br /&gt;### Returns a string with white space stripped off&lt;br /&gt;### print "Stripped whitespace:", stripWhiteSpace("Nicholas Key likes to write codes")&lt;br /&gt;### http://nicholaskey.blogspot.com/2009/04/whitespace-stripper.html&lt;br /&gt;def stripWhiteSpace(text):&lt;br /&gt;    cleanText = ""&lt;br /&gt;    for char in text:&lt;br /&gt;        if char != ' ':&lt;br /&gt;            cleanText = cleanText + char&lt;br /&gt;    return cleanText&lt;br /&gt;&lt;br /&gt;### Truncates a string with a given maximum length&lt;br /&gt;### print truncate("Nicholas", 5)&lt;br /&gt;### http://nicholaskey.blogspot.com/2009/05/truncating-sentence.html&lt;br /&gt;def truncate(text, length):&lt;br /&gt;    if (len(text) &lt;= length):&lt;br /&gt;        return text&lt;br /&gt;    else:&lt;br /&gt;        return text[0:length] + " ..."&lt;br /&gt;&lt;/textarea&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4844902456784005421-3355120384313731376?l=nicholaskey.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://nicholaskey.blogspot.com/feeds/3355120384313731376/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://nicholaskey.blogspot.com/2009/10/my-java-codes-in-python-part-2.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4844902456784005421/posts/default/3355120384313731376'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4844902456784005421/posts/default/3355120384313731376'/><link rel='alternate' type='text/html' href='http://nicholaskey.blogspot.com/2009/10/my-java-codes-in-python-part-2.html' title='My Java codes in Python (Part 2)'/><author><name>Nicholas Key</name><uri>http://www.blogger.com/profile/05768297019453812096</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='http://4.bp.blogspot.com/_OQU38yb-Uq0/SwL5VBlHCII/AAAAAAAAA6U/lXUy53mS7gQ/S220/hamster.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4844902456784005421.post-2300750581227259937</id><published>2009-10-27T12:46:00.005-07:00</published><updated>2009-10-28T19:56:05.938-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Java'/><title type='text'>Another Web Journal Success (my personal minor achievement)</title><content type='html'>Web Journal is ranked top in Korean language for blog search. I can understand some Korean words and if I'm not mistaken, the Korean words in the header area literally means "Blog".&lt;br /&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://2.bp.blogspot.com/_OQU38yb-Uq0/Suf4bPnk-bI/AAAAAAAAA3k/jVXyVzniYmk/s1600-h/Picture+2.png"&gt;&lt;img style="display:block; margin:0px auto 10px; text-align:center;cursor:pointer; cursor:hand;width: 400px; height: 319px;" src="http://2.bp.blogspot.com/_OQU38yb-Uq0/Suf4bPnk-bI/AAAAAAAAA3k/jVXyVzniYmk/s400/Picture+2.png" border="0" alt=""id="BLOGGER_PHOTO_ID_5397555825359518130" /&gt;&lt;/a&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4844902456784005421-2300750581227259937?l=nicholaskey.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://nicholaskey.blogspot.com/feeds/2300750581227259937/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://nicholaskey.blogspot.com/2009/10/another-web-journal-success-my-personal.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4844902456784005421/posts/default/2300750581227259937'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4844902456784005421/posts/default/2300750581227259937'/><link rel='alternate' type='text/html' href='http://nicholaskey.blogspot.com/2009/10/another-web-journal-success-my-personal.html' title='Another Web Journal Success (my personal minor achievement)'/><author><name>Nicholas Key</name><uri>http://www.blogger.com/profile/05768297019453812096</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='http://4.bp.blogspot.com/_OQU38yb-Uq0/SwL5VBlHCII/AAAAAAAAA6U/lXUy53mS7gQ/S220/hamster.jpg'/></author><media:thumbnail xmlns:media='http://search.yahoo.com/mrss/' url='http://2.bp.blogspot.com/_OQU38yb-Uq0/Suf4bPnk-bI/AAAAAAAAA3k/jVXyVzniYmk/s72-c/Picture+2.png' height='72' width='72'/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4844902456784005421.post-2815657616065698776</id><published>2009-10-27T12:46:00.003-07:00</published><updated>2011-08-03T06:20:55.970-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Python'/><category scheme='http://www.blogger.com/atom/ns#' term='Algorithms'/><title type='text'>My Java codes in Python (Part 1)</title><content type='html'>&lt;pre&gt;&lt;br /&gt;### To check if a given input String is empty&lt;br /&gt;### http://nicholaskey.blogspot.com/2009/04/my-first-address-to-world.html&lt;br /&gt;### def isEmpty(inputStr):&lt;br /&gt;###    return ((inputStr == "") or (len(inputStr) == 0))&lt;br /&gt;      &lt;br /&gt;### CORRECTION (Leo, thanks for your comment):&lt;br /&gt;### You may test isEmpty method this way:&lt;br /&gt;### a = None&lt;br /&gt;### print "Is empty string:", isEmpty(a)&lt;br /&gt;def isEmpty(inputStr):&lt;br /&gt;    return ((inputStr == None) or (len(inputStr) == 0) or (inputStr == ""))&lt;br /&gt;  &lt;br /&gt;### To check if a given number is a squared number&lt;br /&gt;### http://nicholaskey.blogspot.com/2009/04/is-this-square.html&lt;br /&gt;def isSquare(input):&lt;br /&gt;    result = 0&lt;br /&gt;    pow = 1&lt;br /&gt;    while(True):&lt;br /&gt;        result = pow * pow&lt;br /&gt;        if (result == input):&lt;br /&gt;            return True&lt;br /&gt;        elif (result &gt; input):&lt;br /&gt;            return False&lt;br /&gt;        pow += 1&lt;br /&gt;&lt;br /&gt;if __name__ == '__main__' :&lt;br /&gt;    print "Is empty string:", isEmpty('')&lt;br /&gt;    print "Is empty string:", isEmpty('Nicholas')&lt;br /&gt;    &lt;br /&gt;    print "Is a square:", isSquare(4)&lt;br /&gt;    print "Is a square:", isSquare(7)&lt;br /&gt;&lt;/pre&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4844902456784005421-2815657616065698776?l=nicholaskey.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://nicholaskey.blogspot.com/feeds/2815657616065698776/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://nicholaskey.blogspot.com/2009/10/my-java-codes-in-python.html#comment-form' title='2 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4844902456784005421/posts/default/2815657616065698776'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4844902456784005421/posts/default/2815657616065698776'/><link rel='alternate' type='text/html' href='http://nicholaskey.blogspot.com/2009/10/my-java-codes-in-python.html' title='My Java codes in Python (Part 1)'/><author><name>Nicholas Key</name><uri>http://www.blogger.com/profile/05768297019453812096</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='http://4.bp.blogspot.com/_OQU38yb-Uq0/SwL5VBlHCII/AAAAAAAAA6U/lXUy53mS7gQ/S220/hamster.jpg'/></author><thr:total>2</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4844902456784005421.post-13438890507092693</id><published>2009-10-27T12:46:00.001-07:00</published><updated>2009-10-28T19:44:09.562-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Splunk'/><category scheme='http://www.blogger.com/atom/ns#' term='Log Management'/><title type='text'>Splunk&gt; User Interface</title><content type='html'>Here I am at the login page of Splunk&gt;. The username/password is &lt;span style="font-weight:bold;"&gt;admin/changeme&lt;/span&gt; by default. You will have to click at the "First time signing in?" link to get the clue ;)&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://2.bp.blogspot.com/_OQU38yb-Uq0/SufSeD7IwmI/AAAAAAAAA3M/xuPYP3anOXQ/s1600-h/Picture+7.png"&gt;&lt;img style="display:block; margin:0px auto 10px; text-align:center;cursor:pointer; cursor:hand;width: 400px; height: 304px;" src="http://2.bp.blogspot.com/_OQU38yb-Uq0/SufSeD7IwmI/AAAAAAAAA3M/xuPYP3anOXQ/s400/Picture+7.png" border="0" alt=""id="BLOGGER_PHOTO_ID_5397514092318081634" /&gt;&lt;/a&gt;&lt;br /&gt;I think that the UI is really welcoming and slick. The snapshot is as below.&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://2.bp.blogspot.com/_OQU38yb-Uq0/SufUIbg_CfI/AAAAAAAAA3U/rENo55Qb6fo/s1600-h/Picture+4.png"&gt;&lt;img style="display:block; margin:0px auto 10px; text-align:center;cursor:pointer; cursor:hand;width: 400px; height: 280px;" src="http://2.bp.blogspot.com/_OQU38yb-Uq0/SufUIbg_CfI/AAAAAAAAA3U/rENo55Qb6fo/s400/Picture+4.png" border="0" alt=""id="BLOGGER_PHOTO_ID_5397515919716977138" /&gt;&lt;/a&gt;&lt;br /&gt;Since I feel like first trying out the *NIX application, I'll have to enable the feature before launching it. Even the AJAX powered loading modal looks impressive. Don't believe me? Take a look at it yourself :)&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://1.bp.blogspot.com/_OQU38yb-Uq0/SufSYswxxWI/AAAAAAAAA3E/zOk7xSnAEac/s1600-h/Picture+3.png"&gt;&lt;img style="display:block; margin:0px auto 10px; text-align:center;cursor:pointer; cursor:hand;width: 400px; height: 179px;" src="http://1.bp.blogspot.com/_OQU38yb-Uq0/SufSYswxxWI/AAAAAAAAA3E/zOk7xSnAEac/s400/Picture+3.png" border="0" alt=""id="BLOGGER_PHOTO_ID_5397514000201270626" /&gt;&lt;/a&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://4.bp.blogspot.com/_OQU38yb-Uq0/SufeI9ITEsI/AAAAAAAAA3c/XWVB7KhjhC4/s1600-h/Picture+2.png"&gt;&lt;img style="display:block; margin:0px auto 10px; text-align:center;cursor:pointer; cursor:hand;width: 400px; height: 184px;" src="http://4.bp.blogspot.com/_OQU38yb-Uq0/SufeI9ITEsI/AAAAAAAAA3c/XWVB7KhjhC4/s400/Picture+2.png" border="0" alt=""id="BLOGGER_PHOTO_ID_5397526923856515778" /&gt;&lt;/a&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4844902456784005421-13438890507092693?l=nicholaskey.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://nicholaskey.blogspot.com/feeds/13438890507092693/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://nicholaskey.blogspot.com/2009/10/splunk-user-interface.html#comment-form' title='2 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4844902456784005421/posts/default/13438890507092693'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4844902456784005421/posts/default/13438890507092693'/><link rel='alternate' type='text/html' href='http://nicholaskey.blogspot.com/2009/10/splunk-user-interface.html' title='Splunk&gt; User Interface'/><author><name>Nicholas Key</name><uri>http://www.blogger.com/profile/05768297019453812096</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='http://4.bp.blogspot.com/_OQU38yb-Uq0/SwL5VBlHCII/AAAAAAAAA6U/lXUy53mS7gQ/S220/hamster.jpg'/></author><media:thumbnail xmlns:media='http://search.yahoo.com/mrss/' url='http://2.bp.blogspot.com/_OQU38yb-Uq0/SufSeD7IwmI/AAAAAAAAA3M/xuPYP3anOXQ/s72-c/Picture+7.png' height='72' width='72'/><thr:total>2</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4844902456784005421.post-4242572079521171686</id><published>2009-10-27T12:45:00.003-07:00</published><updated>2009-10-28T19:44:25.277-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Splunk'/><category scheme='http://www.blogger.com/atom/ns#' term='Log Management'/><title type='text'>Trying out Splunk&gt; 4.0.5 build 69401</title><content type='html'>This is my first time trying out an intelligent application that helps you monitor the content of your log files. Let's see how much I progress being a new user installing this application.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight:bold;"&gt;[1] Downloading a copy of Splunk&gt;&lt;/span&gt;&lt;br /&gt;This is the &lt;a href="http://www.splunk.com/download"&gt;&lt;span style="font-weight:bold;"&gt;URL&lt;/span&gt;&lt;/a&gt; if you want to try out the free version of Splunk&gt;. There are many choices of platforms for you to choose. I chose the MacOS 10.5 version and downloaded the DMG file. The version that I downloaded when I first wrote this article is splunk-4.0.5-69401-macosx-10.5-universal.dmg&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://3.bp.blogspot.com/_OQU38yb-Uq0/Sue7sbC8aAI/AAAAAAAAA2c/Wba97EbQzGw/s1600-h/Picture+2.png"&gt;&lt;img style="display:block; margin:0px auto 10px; text-align:center;cursor:pointer; cursor:hand;width: 400px; height: 184px;" src="http://3.bp.blogspot.com/_OQU38yb-Uq0/Sue7sbC8aAI/AAAAAAAAA2c/Wba97EbQzGw/s400/Picture+2.png" border="0" alt=""id="BLOGGER_PHOTO_ID_5397489050275571714" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;span style="font-weight:bold;"&gt;[2] Installing Splunk&gt;&lt;/span&gt;&lt;br /&gt;If you are stumped trying to install Splunk&gt;, there is a wiki page at your convenience. &lt;span style="font-weight:bold;"&gt;&lt;a href="http://www.splunk.com/base/Documentation/latest/Installation/WhatsintheInstallationManual"&gt;Click here&lt;/a&gt;&lt;/span&gt; to take a look at their help page and then select the appropriate version of the copy you downloaded. I clicked at version 4.0.5 and selected &lt;a href="http://www.splunk.com/base/Documentation:Installation:InstallonMacOS:4.0"&gt;&lt;span style="font-weight:bold;"&gt;the link&lt;/span&gt;&lt;/a&gt; that guides me how to install it into my computer.&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://3.bp.blogspot.com/_OQU38yb-Uq0/Sue-FIehEZI/AAAAAAAAA2k/os7tProT1V0/s1600-h/Picture+3.png"&gt;&lt;img style="display:block; margin:0px auto 10px; text-align:center;cursor:pointer; cursor:hand;width: 400px; height: 172px;" src="http://3.bp.blogspot.com/_OQU38yb-Uq0/Sue-FIehEZI/AAAAAAAAA2k/os7tProT1V0/s400/Picture+3.png" border="0" alt=""id="BLOGGER_PHOTO_ID_5397491673810932114" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;span style="font-weight:bold;"&gt;[3] Installation steps&lt;/span&gt;&lt;br /&gt;The installation was a breeze until I wanted to launch it. According to the manual, I'll have to type this out &lt;span style="font-weight:bold;"&gt;$INSTALLATION_DIRECTORY/bin/splunk start&lt;/span&gt;. It did not work but I had this "gotcha" moment and did a &lt;span style="font-weight:bold;"&gt;./splunk start&lt;/span&gt; and it worked just fine. You do not actually need to do &lt;span style="font-weight:bold;"&gt;$INSTALLATION_DIRECTORY/bin/splunk start --accept-license&lt;/span&gt; because you'll have to agree with the agreement during the installation by typing y (the second picture illustrates that).&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://1.bp.blogspot.com/_OQU38yb-Uq0/Sue-i7PMVUI/AAAAAAAAA2s/GcXo09UVm58/s1600-h/Picture+4.png"&gt;&lt;img style="display:block; margin:0px auto 10px; text-align:center;cursor:pointer; cursor:hand;width: 400px; height: 162px;" src="http://1.bp.blogspot.com/_OQU38yb-Uq0/Sue-i7PMVUI/AAAAAAAAA2s/GcXo09UVm58/s400/Picture+4.png" border="0" alt=""id="BLOGGER_PHOTO_ID_5397492185653073218" /&gt;&lt;/a&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://3.bp.blogspot.com/_OQU38yb-Uq0/Sue-wypmdRI/AAAAAAAAA20/iIN1FkUnyfE/s1600-h/Picture+5.png"&gt;&lt;img style="display:block; margin:0px auto 10px; text-align:center;cursor:pointer; cursor:hand;width: 400px; height: 232px;" src="http://3.bp.blogspot.com/_OQU38yb-Uq0/Sue-wypmdRI/AAAAAAAAA20/iIN1FkUnyfE/s400/Picture+5.png" border="0" alt=""id="BLOGGER_PHOTO_ID_5397492423866086674" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;span style="font-weight:bold;"&gt;[4] Installation process completed&lt;/span&gt;&lt;br /&gt;I was shown these lines at the bottom of the output:&lt;br /&gt;&lt;br /&gt;If you get stuck, we're here to help.  &lt;br /&gt;Look for answers here: http://www.splunk.com/base/Documentation&lt;br /&gt;&lt;br /&gt;The Splunk web interface is at http://nicholas-keys-macbook-pro.local:8000&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight:bold;"&gt;[5] There's no step 5 :P&lt;/span&gt;&lt;br /&gt;Just kidding. The fifth step is to start exploring the features of Splunk&gt; and understand why it is good as how people claim it is. Splunk's themes are very catchy and I particularly like this theme "Finding your faults just like mum". Sample snapshot of Splunk&gt; in my browser is shown below.&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://2.bp.blogspot.com/_OQU38yb-Uq0/Sue_zsx-WpI/AAAAAAAAA28/ufTy7MA2kY4/s1600-h/Picture+6.png"&gt;&lt;img style="display:block; margin:0px auto 10px; text-align:center;cursor:pointer; cursor:hand;width: 400px; height: 249px;" src="http://2.bp.blogspot.com/_OQU38yb-Uq0/Sue_zsx-WpI/AAAAAAAAA28/ufTy7MA2kY4/s400/Picture+6.png" border="0" alt=""id="BLOGGER_PHOTO_ID_5397493573341829778" /&gt;&lt;/a&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4844902456784005421-4242572079521171686?l=nicholaskey.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://nicholaskey.blogspot.com/feeds/4242572079521171686/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://nicholaskey.blogspot.com/2009/10/trying-out-splunk-405-build-69401.html#comment-form' title='2 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4844902456784005421/posts/default/4242572079521171686'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4844902456784005421/posts/default/4242572079521171686'/><link rel='alternate' type='text/html' href='http://nicholaskey.blogspot.com/2009/10/trying-out-splunk-405-build-69401.html' title='Trying out Splunk&gt; 4.0.5 build 69401'/><author><name>Nicholas Key</name><uri>http://www.blogger.com/profile/05768297019453812096</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='http://4.bp.blogspot.com/_OQU38yb-Uq0/SwL5VBlHCII/AAAAAAAAA6U/lXUy53mS7gQ/S220/hamster.jpg'/></author><media:thumbnail xmlns:media='http://search.yahoo.com/mrss/' url='http://3.bp.blogspot.com/_OQU38yb-Uq0/Sue7sbC8aAI/AAAAAAAAA2c/Wba97EbQzGw/s72-c/Picture+2.png' height='72' width='72'/><thr:total>2</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4844902456784005421.post-2991926273380296410</id><published>2009-10-27T12:45:00.001-07:00</published><updated>2011-08-03T06:21:37.948-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Java'/><category scheme='http://www.blogger.com/atom/ns#' term='Stack'/><category scheme='http://www.blogger.com/atom/ns#' term='Algorithms'/><title type='text'>CustomStack upgrades</title><content type='html'>My CustomStack now comes with several other new features. I can actually check if an Object exists in the Stack. Once the Object is found, a boolean true is returned. In addition to that, I've also added a method to retrieve an element with a given 0-based index number. I call it elementAt and it has a similar functionality of get. To the readers who are accustomed to the methods of a Stack, I have also added the method peek. Basically, it's a method to retrieve the element at the top of the Stack. The method search returns the 0-based index number of the first found element and -1 is returned if the element is not found. Here are the summary of methods of the newly improved CustomStack:&lt;br /&gt;&lt;span style="font-weight:bold;"&gt;contains(Object input)&lt;br /&gt;elementAt(int index)&lt;br /&gt;peek()&lt;br /&gt;search(Object input)&lt;/span&gt;&lt;br /&gt;Below is the code snippet.&lt;pre&gt;&lt;br /&gt; public boolean contains(Object input){&lt;br /&gt;  boolean found = false;&lt;br /&gt;  if(empty()){&lt;br /&gt;   throw new RuntimeException( "Stack is already empty. No elements to check." );&lt;br /&gt;  }&lt;br /&gt;  for(int i = 0; i&amp;lt;size(); i++) {&lt;br /&gt;   if (stackElements[i].hashCode() == input.hashCode()) {&lt;br /&gt;    found = true;&lt;br /&gt;    break;&lt;br /&gt;   }&lt;br /&gt;  }&lt;br /&gt;  return found;&lt;br /&gt; }&lt;br /&gt;&lt;br /&gt; public Object elementAt(int index){&lt;br /&gt;  return get(index);&lt;br /&gt; }&lt;br /&gt; &lt;br /&gt; public Object peek(){&lt;br /&gt;  return top();&lt;br /&gt; }&lt;br /&gt; &lt;br /&gt; public int search(Object input){&lt;br /&gt;  int index = -1;&lt;br /&gt;  if(empty()){&lt;br /&gt;   throw new RuntimeException( "Stack is already empty. No elements to search." );&lt;br /&gt;  }&lt;br /&gt;  for(int i = 0; i&amp;lt;size(); i++) {&lt;br /&gt;   if (stackElements[i].hashCode() == input.hashCode()) {&lt;br /&gt;    index = i;&lt;br /&gt;    break;&lt;br /&gt;   }&lt;br /&gt;  }&lt;br /&gt;  return index;&lt;br /&gt; }&lt;br /&gt; &lt;br /&gt;&lt;/pre&gt;&lt;a href="http://nicholaskey.blogspot.com/2009/10/stack-implementation.html"&gt;Click here&lt;/a&gt; to view the previous code of CustomStack.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4844902456784005421-2991926273380296410?l=nicholaskey.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://nicholaskey.blogspot.com/feeds/2991926273380296410/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://nicholaskey.blogspot.com/2009/10/customstack-upgrade.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4844902456784005421/posts/default/2991926273380296410'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4844902456784005421/posts/default/2991926273380296410'/><link rel='alternate' type='text/html' href='http://nicholaskey.blogspot.com/2009/10/customstack-upgrade.html' title='CustomStack upgrades'/><author><name>Nicholas Key</name><uri>http://www.blogger.com/profile/05768297019453812096</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='http://4.bp.blogspot.com/_OQU38yb-Uq0/SwL5VBlHCII/AAAAAAAAA6U/lXUy53mS7gQ/S220/hamster.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4844902456784005421.post-3181394904507007726</id><published>2009-10-26T12:24:00.003-07:00</published><updated>2011-08-03T06:22:34.156-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Java'/><category scheme='http://www.blogger.com/atom/ns#' term='Stack'/><category scheme='http://www.blogger.com/atom/ns#' term='Algorithms'/><title type='text'>Stack Implementation in Java</title><content type='html'>Below is my code to implement Stack from ground-up. I tried (in a very short time) to emulate the behavior of Stack in the Java Util package. The methods I have written are:&lt;br /&gt;&lt;span style="font-weight:bold; color:red;"&gt;size()&lt;br /&gt;get(int index)&lt;br /&gt;empty()&lt;br /&gt;clear()&lt;br /&gt;pop()&lt;br /&gt;push(Object input)&lt;br /&gt;bottom()&lt;br /&gt;top()&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;I call my Stack implementation as CustomStack as it may evolve over time. I have also provided some test cases to validate that the implementation actually works. The sample output is shown below the codes.&lt;pre&gt;&lt;br /&gt;import java.lang.reflect.Array;&lt;br /&gt;&lt;br /&gt;public class CustomStack {&lt;br /&gt;&lt;br /&gt; private Object[] stackElements;&lt;br /&gt; private int stackIndex = -1;&lt;br /&gt; private int stackSize = 0;&lt;br /&gt; private static final int INIT_SIZE = 3;&lt;br /&gt; private boolean stackSizeGiven = false;&lt;br /&gt; private int sizeHolder = 0;&lt;br /&gt;&lt;br /&gt; public CustomStack(){&lt;br /&gt;  stackElements = new Object[ INIT_SIZE ];&lt;br /&gt;  stackSizeGiven = false;&lt;br /&gt; }&lt;br /&gt;&lt;br /&gt; public CustomStack(int inputSize){&lt;br /&gt;  sizeHolder = inputSize;&lt;br /&gt;  stackElements = new Object[ sizeHolder ];&lt;br /&gt;  stackSizeGiven = true;&lt;br /&gt; }&lt;br /&gt; &lt;br /&gt; public int size(){&lt;br /&gt;  return stackSize;&lt;br /&gt; }&lt;br /&gt;&lt;br /&gt; public Object get(int index){&lt;br /&gt;  if ((index &lt; 0) || (index &gt; (stackSize))) {&lt;br /&gt;   throw new RuntimeException("Index out of bound. Supplied " + index);&lt;br /&gt;  }&lt;br /&gt;  return stackElements[ index ];&lt;br /&gt; }&lt;br /&gt; &lt;br /&gt; public boolean empty() {&lt;br /&gt;  return stackIndex == -1;&lt;br /&gt; }&lt;br /&gt;&lt;br /&gt; public void clear() {&lt;br /&gt;  if (stackSizeGiven) {&lt;br /&gt;   stackElements = new Object[ sizeHolder ];&lt;br /&gt;  } else {&lt;br /&gt;   stackElements = new Object[ INIT_SIZE ];&lt;br /&gt;  }&lt;br /&gt;  stackIndex = -1;&lt;br /&gt;  stackSize = 0;&lt;br /&gt; }&lt;br /&gt; &lt;br /&gt; public void pop() {&lt;br /&gt;  if(empty()){&lt;br /&gt;   throw new RuntimeException( "Stack is already empty. No elements to pop." );&lt;br /&gt;  }&lt;br /&gt;  stackIndex--;&lt;br /&gt;  stackSize--;&lt;br /&gt; }&lt;br /&gt;&lt;br /&gt; public void push(Object input) {&lt;br /&gt;  if( stackIndex + 1 == stackElements.length ) {&lt;br /&gt;   int arrayLength = Array.getLength(stackElements);&lt;br /&gt;   Object [] newArray = (Object[]) Array.newInstance(stackElements.getClass().getComponentType(), (arrayLength + arrayLength ));&lt;br /&gt;   System.arraycopy(stackElements, 0, newArray, 0, arrayLength);&lt;br /&gt;   stackElements = newArray;&lt;br /&gt;  }&lt;br /&gt;  stackElements[ ++stackIndex ] = input;&lt;br /&gt;  stackSize++;&lt;br /&gt; }&lt;br /&gt;&lt;br /&gt; public Object bottom(){&lt;br /&gt;  if(empty())&lt;br /&gt;   throw new RuntimeException( "Stack is already empty. No elements at bottom." );&lt;br /&gt;  return stackElements[ 0 ];&lt;br /&gt; }&lt;br /&gt; &lt;br /&gt; public Object top() {&lt;br /&gt;  if(empty())&lt;br /&gt;   throw new RuntimeException( "Stack is already empty. No elements at top." );&lt;br /&gt;  return stackElements[ stackIndex ];&lt;br /&gt; }&lt;br /&gt;&lt;br /&gt; public static void testCases(){&lt;br /&gt;  CustomStack aStack = new CustomStack();&lt;br /&gt;  System.out.println("Stack is empty: " + aStack.empty());&lt;br /&gt;  aStack.push("Nicholas Key");&lt;br /&gt;  aStack.push(3.142);&lt;br /&gt;  aStack.push(false);&lt;br /&gt;  // Prints false&lt;br /&gt;  System.out.println("Element at top of Stack: " + aStack.top());&lt;br /&gt;  System.out.println("Size of current Stack: " + aStack.size());&lt;br /&gt;&lt;br /&gt;  aStack.push("Java Developer");&lt;br /&gt;  aStack.push("Android App Developer");&lt;br /&gt;  // Prints Android App Developer&lt;br /&gt;  System.out.println("Element at top of Stack: " + aStack.top());&lt;br /&gt;  &lt;br /&gt;  aStack.push("Web App Developer");&lt;br /&gt;  aStack.push("Blogger");&lt;br /&gt;  aStack.push(2009);&lt;br /&gt;  // Prints 2009&lt;br /&gt;  System.out.println("Element at top of Stack: " + aStack.top());&lt;br /&gt;  System.out.println("Size of current Stack: " + aStack.size());&lt;br /&gt;  &lt;br /&gt;  // Prints Stack elements&lt;br /&gt;  for (int i= 0; i&lt; aStack.size(); i++) {&lt;br /&gt;   System.out.println("Index " + i + ": " + aStack.get(i));&lt;br /&gt;  }&lt;br /&gt;&lt;br /&gt;  // Pops 2009&lt;br /&gt;  aStack.pop();&lt;br /&gt;  // Prints Blogger&lt;br /&gt;  System.out.println("Element at top of Stack: " + aStack.top());&lt;br /&gt;  &lt;br /&gt;  // Pops Blogger&lt;br /&gt;  aStack.pop();&lt;br /&gt;  // Prints Web App Developer&lt;br /&gt;  System.out.println("Element at top of Stack: " + aStack.top());&lt;br /&gt;&lt;br /&gt;  // Prints Stack elements&lt;br /&gt;  for (int i= 0; i&lt; aStack.size(); i++) {&lt;br /&gt;   System.out.println("Index " + i + ": " + aStack.get(i));&lt;br /&gt;  }&lt;br /&gt;&lt;br /&gt;  System.out.println("Element at bottom of Stack: " + aStack.bottom());&lt;br /&gt;&lt;br /&gt;  // Pops out all Stack elements&lt;br /&gt;  aStack.clear();  &lt;br /&gt;  System.out.println("Stack is empty: " + aStack.empty());&lt;br /&gt;&lt;br /&gt;  System.out.println(aStack.get(1));&lt;br /&gt;  &lt;br /&gt;  System.out.println(aStack.get(aStack.size() + 300));&lt;br /&gt; }&lt;br /&gt; &lt;br /&gt; public static void main(String[] args) {&lt;br /&gt;  testCases(); &lt;br /&gt; }&lt;br /&gt;}&lt;br /&gt;&lt;/pre&gt;&lt;pre&gt;&lt;br /&gt;Stack is empty: true&lt;br /&gt;Element at top of Stack: false&lt;br /&gt;Size of current Stack: 3&lt;br /&gt;Element at top of Stack: Android App Developer&lt;br /&gt;Element at top of Stack: 2009&lt;br /&gt;Size of current Stack: 8&lt;br /&gt;Index 0: Nicholas Key&lt;br /&gt;Index 1: 3.142&lt;br /&gt;Index 2: false&lt;br /&gt;Index 3: Java Developer&lt;br /&gt;Index 4: Android App Developer&lt;br /&gt;Index 5: Web App Developer&lt;br /&gt;Index 6: Blogger&lt;br /&gt;Index 7: 2009&lt;br /&gt;Element at top of Stack: Blogger&lt;br /&gt;Element at top of Stack: Web App Developer&lt;br /&gt;Index 0: Nicholas Key&lt;br /&gt;Index 1: 3.142&lt;br /&gt;Index 2: false&lt;br /&gt;Index 3: Java Developer&lt;br /&gt;Index 4: Android App Developer&lt;br /&gt;Index 5: Web App Developer&lt;br /&gt;Element at bottom of Stack: Nicholas Key&lt;br /&gt;Stack is empty: true&lt;br /&gt;Exception in thread "main" java.lang.RuntimeException: Index out of bound. Supplied 1&lt;br /&gt; at CustomStack.get(CustomStack.java:29)&lt;br /&gt; at CustomStack.testCases(CustomStack.java:128)&lt;br /&gt; at CustomStack.main(CustomStack.java:136)&lt;br /&gt;&lt;/pre&gt;&lt;span style="font-weight:bold;color:red;"&gt;Update:&lt;/span&gt; I've added several methods to make my CustomStack more robust ;) &lt;a href="http://nicholaskey.blogspot.com/2009/10/customstack-upgrade.html"&gt;Click here&lt;/a&gt; to look at the improvements.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4844902456784005421-3181394904507007726?l=nicholaskey.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://nicholaskey.blogspot.com/feeds/3181394904507007726/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://nicholaskey.blogspot.com/2009/10/stack-implementation.html#comment-form' title='2 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4844902456784005421/posts/default/3181394904507007726'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4844902456784005421/posts/default/3181394904507007726'/><link rel='alternate' type='text/html' href='http://nicholaskey.blogspot.com/2009/10/stack-implementation.html' title='Stack Implementation in Java'/><author><name>Nicholas Key</name><uri>http://www.blogger.com/profile/05768297019453812096</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='http://4.bp.blogspot.com/_OQU38yb-Uq0/SwL5VBlHCII/AAAAAAAAA6U/lXUy53mS7gQ/S220/hamster.jpg'/></author><thr:total>2</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4844902456784005421.post-8991972195994523629</id><published>2009-10-25T00:45:00.001-07:00</published><updated>2009-10-25T14:49:21.947-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='General Knowledge'/><title type='text'>What happens when you type in a URL into the browser ...</title><content type='html'>These are the processes taken place. &lt;br /&gt;&lt;span style="font-weight:bold;"&gt;[Immense credits to &lt;a href="http://www.expresshostpro.com/index.php/faq/general/5-what-happens-when-you-type-wwwgooglecom-into-a-web-browser-internet-flow-chart"&gt;EXPRESS HOST PRO&lt;/a&gt; for the detailed explanation]&lt;/span&gt;&lt;br /&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://3.bp.blogspot.com/_OQU38yb-Uq0/SuTDwebXhKI/AAAAAAAAA2U/fplxj89Wbz8/s1600-h/faqdns01.jpg"&gt;&lt;img style="display:block; margin:0px auto 10px; text-align:center;cursor:pointer; cursor:hand;width: 400px; height: 284px;" src="http://3.bp.blogspot.com/_OQU38yb-Uq0/SuTDwebXhKI/AAAAAAAAA2U/fplxj89Wbz8/s400/faqdns01.jpg" border="0" alt=""id="BLOGGER_PHOTO_ID_5396653491065685154" /&gt;&lt;/a&gt;&lt;span style="font-weight:bold; color:red;"&gt;Step 1: Request a record&lt;/span&gt;&lt;br /&gt;You begin by asking your computer to resolve a hostname, such as visiting 'http://www.google.com' in a web browser. The first place your computer looks is its local DNS cache, which stores DNS information that the computer has recently retrieved.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight:bold; color:red;"&gt;Step 2: Ask the Recursive DNS servers&lt;/span&gt;&lt;br /&gt;If the records are not stored locally, your computer queries (or contacts) your ISP's recursive DNS servers. These machines perform the legwork of DNS queries on behalf of their customers. The recursive DNS servers have their own caches, which they check before continuing with the query.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight:bold; color:red;"&gt;Step 3: Ask the Root DNS servers&lt;/span&gt;&lt;br /&gt;If the recursive DNS servers do not have the record cached, they contact the root nameservers. These thirteen nameservers contain pointers for all of the Top-Level Domains (TLDs), such as '.com', '.net' and '.org'. If you are looking for 'www.google.com.', the root nameservers look at the TLD for the domain - 'www.google.com'- and direct the query to the TLD DNS nameservers responsible for all '.com' pointers.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight:bold; color:red;"&gt;Step 4: Ask the TLD DNS servers&lt;/span&gt;&lt;br /&gt;The TLD DNS servers do not store the DNS records for individual domains; instead, they keep track of the authoritative nameservers for all the domains within their TLD. The TLD DNS servers look at the next part of the query from right to left - 'www.google.com' - then direct the query to the authoritative nameservers for 'google.com'.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight:bold; color:red;"&gt;Step 5: Ask the Authoritative DNS servers&lt;/span&gt;&lt;br /&gt;Authoritative nameservers contain all of the DNS records for a given domain, such as host records (which store IP addresses), MX records (which identify nameservers for a domain), and so on. Since you are looking for the IP address of 'www.google.com', the recursive server queries the authoritative nameservers and asks for the host record for 'www.google.com'.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight:bold; color:red;"&gt;Step 6: Retrieving the record&lt;/span&gt;&lt;br /&gt;The recursive DNS server receives the host record for 'www.google.com' from the authoritative nameservers, and stores the record in its local cache. If anyone else requests the host record for 'www.google.com', the recursive servers will already have the answer, and will not need to go through the lookup process again until the record expires from cache.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight:bold; color:red;"&gt;Step 7: The Answer!&lt;/span&gt;&lt;br /&gt;Finally, the recursive server gives the host record back to your computer. Your computer stores the record in its cache, reads the IP address from the record, then passes this information to the web browser. Your browser then opens a connection to the IP address '72.14.207.99' on port 80 (for HTTP), and our webserver passes the web page to your browser, which displays Google.&lt;br /&gt;&lt;br /&gt;You may visit the original content at &lt;a href="http://www.expresshostpro.com/index.php/faq/general/5-what-happens-when-you-type-wwwgooglecom-into-a-web-browser-internet-flow-chart"&gt;this URL&lt;/a&gt;.&lt;br /&gt;&lt;br /&gt;Here's my understanding to the processes:&lt;br /&gt;&lt;br /&gt;We type in a URL and hit GO.&lt;br /&gt;The browser translates the URL into an IP address.&lt;br /&gt;In order to do that, the browser contacts DNS to resolve the IP address.&lt;br /&gt;The browser checks if the IP address is cached.&lt;br /&gt;If not, it makes a DNS query to my ISP's DNS server.&lt;br /&gt;DNS replies back with the IP address of the site.&lt;br /&gt;Browser opens TCP connection to the server at port 80.&lt;br /&gt;Displays the content in browser.&lt;br /&gt;Stores the IP address in the DNS cache for future use.&lt;br /&gt;When the browser is closed, TCP connection is terminated.&lt;br /&gt;&lt;br /&gt;The HTTP request being made is a &lt;span style="font-weight:bold;"&gt;GET&lt;/span&gt; request.&lt;br /&gt;Correct me if I'm wrong.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4844902456784005421-8991972195994523629?l=nicholaskey.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://nicholaskey.blogspot.com/feeds/8991972195994523629/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://nicholaskey.blogspot.com/2009/10/what-happens-when-you-type-in-url-into.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4844902456784005421/posts/default/8991972195994523629'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4844902456784005421/posts/default/8991972195994523629'/><link rel='alternate' type='text/html' href='http://nicholaskey.blogspot.com/2009/10/what-happens-when-you-type-in-url-into.html' title='What happens when you type in a URL into the browser ...'/><author><name>Nicholas Key</name><uri>http://www.blogger.com/profile/05768297019453812096</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='http://4.bp.blogspot.com/_OQU38yb-Uq0/SwL5VBlHCII/AAAAAAAAA6U/lXUy53mS7gQ/S220/hamster.jpg'/></author><media:thumbnail xmlns:media='http://search.yahoo.com/mrss/' url='http://3.bp.blogspot.com/_OQU38yb-Uq0/SuTDwebXhKI/AAAAAAAAA2U/fplxj89Wbz8/s72-c/faqdns01.jpg' height='72' width='72'/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4844902456784005421.post-5055638542804486527</id><published>2009-10-24T10:29:00.009-07:00</published><updated>2009-11-20T08:10:21.224-08:00</updated><title type='text'>Steve Ballmer on Windows 7</title><content type='html'>Tell me you are not seeing the MacBook Pro at the big LCD screen. While it is true that you can actually operate Windows on a Mac provided that you installed VMware, I really think that one of the many other OEM brands is more appropriate to be shown in that big screen.&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://2.bp.blogspot.com/_OQU38yb-Uq0/SuM6kAyYdBI/AAAAAAAAA2E/FgPZmfQnx9c/s1600-h/Picture+2.png"&gt;&lt;img style="display:block; margin:0px auto 10px; text-align:center;cursor:pointer; cursor:hand;width: 512px;" src="http://2.bp.blogspot.com/_OQU38yb-Uq0/SuM6kAyYdBI/AAAAAAAAA2E/FgPZmfQnx9c/s400/Picture+2.png" border="0" alt=""id="BLOGGER_PHOTO_ID_5396221168881005586" /&gt;&lt;/a&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://3.bp.blogspot.com/_OQU38yb-Uq0/SuM6uDtl5zI/AAAAAAAAA2M/whV-jM_UDZI/s1600-h/Picture+3.png"&gt;&lt;img style="display:block; margin:0px auto 10px; text-align:center;cursor:pointer; cursor:hand;width: 512px;" src="http://3.bp.blogspot.com/_OQU38yb-Uq0/SuM6uDtl5zI/AAAAAAAAA2M/whV-jM_UDZI/s400/Picture+3.png" border="0" alt=""id="BLOGGER_PHOTO_ID_5396221341464913714" /&gt;&lt;/a&gt;Take a look at Steve's face when he is holding the Dell Adamo XPS notebook. I guess he must be thinking "Why is this guy shoving a MacBook Air to me? I feel like snapping this notebook into halves. It reminds me ths fragility of the Air!" Look at his face again :) Priceless! :P&lt;br /&gt;&lt;br /&gt;Pictures are attributed to NBC.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4844902456784005421-5055638542804486527?l=nicholaskey.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://nicholaskey.blogspot.com/feeds/5055638542804486527/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://nicholaskey.blogspot.com/2009/10/steve-ballmer-on-windows-7.html#comment-form' title='4 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4844902456784005421/posts/default/5055638542804486527'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4844902456784005421/posts/default/5055638542804486527'/><link rel='alternate' type='text/html' href='http://nicholaskey.blogspot.com/2009/10/steve-ballmer-on-windows-7.html' title='Steve Ballmer on Windows 7'/><author><name>Nicholas Key</name><uri>http://www.blogger.com/profile/05768297019453812096</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='http://4.bp.blogspot.com/_OQU38yb-Uq0/SwL5VBlHCII/AAAAAAAAA6U/lXUy53mS7gQ/S220/hamster.jpg'/></author><media:thumbnail xmlns:media='http://search.yahoo.com/mrss/' url='http://2.bp.blogspot.com/_OQU38yb-Uq0/SuM6kAyYdBI/AAAAAAAAA2E/FgPZmfQnx9c/s72-c/Picture+2.png' height='72' width='72'/><thr:total>4</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4844902456784005421.post-8589263464513143564</id><published>2009-10-23T09:09:00.007-07:00</published><updated>2011-08-03T06:23:22.383-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Java'/><category scheme='http://www.blogger.com/atom/ns#' term='Algorithms'/><title type='text'>Sorting Algorithms (Bubble sort, Selection sort &amp; Insertion Sort)</title><content type='html'>I want to refresh my mind about sorting algorithms and here are the first three simple sorting algorithms in this article - Bubble Sort, Selection Sort and Insertion Sort. I attribute the explanations to Wikipedia.&lt;pre&gt;&lt;br /&gt;import java.util.Random;&lt;br /&gt;&lt;br /&gt;public class SortingAlgorithm {&lt;br /&gt;&lt;br /&gt; private final int SIZE = 2000;&lt;br /&gt; private Random myRand = new Random();&lt;br /&gt; private int[] numbers = new int[SIZE];&lt;br /&gt;&lt;br /&gt; public SortingAlgorithm(){}&lt;br /&gt;&lt;br /&gt; private void randomizeNumbers(){&lt;br /&gt;  for (int i = 0; i &amp;lt; numbers.length; i++) {&lt;br /&gt;   numbers[i] = myRand.nextInt( 2000 ) + 1;&lt;br /&gt;  } &lt;br /&gt; }&lt;br /&gt;&lt;br /&gt; private void printArray(){&lt;br /&gt;  for(int i: numbers){&lt;br /&gt;   System.out.print(i + " ");&lt;br /&gt;  }&lt;br /&gt;  System.out.println();&lt;br /&gt; }&lt;br /&gt;&lt;br /&gt; public void bubbleSort() {&lt;br /&gt;  randomizeNumbers();&lt;br /&gt;  System.out.println("BUBBLE SORT");&lt;br /&gt;  System.out.println("Presorted numbers: ");&lt;br /&gt;  printArray();&lt;br /&gt;  long start = System.nanoTime();&lt;br /&gt;&lt;br /&gt;  /**&lt;br /&gt;   * Bubblesort algorithm&lt;br /&gt;   * Wikipedia:&lt;br /&gt;   * works by repeatedly stepping through the list to be sorted, &lt;br /&gt;   * comparing each pair of adjacent items and swapping them if &lt;br /&gt;   * they are in the wrong order. The pass through the list is &lt;br /&gt;   * repeated until no swaps are needed, which indicates that the &lt;br /&gt;   * list is sorted. The algorithm gets its name from the way smaller &lt;br /&gt;   * elements "bubble" to the top of the list.&lt;br /&gt;   * Complexity: &lt;br /&gt;   * Worst = O(n^2)&lt;br /&gt;   * Average = O(n^2)&lt;br /&gt;   * Best = O(n)&lt;br /&gt;   */&lt;br /&gt;  int n = numbers.length;&lt;br /&gt;  for (int pass=1; pass &amp;lt; n; pass++) { &lt;br /&gt;   for (int i=0; i &amp;lt; n-pass; i++) {&lt;br /&gt;    if (numbers[i] &gt; numbers[i+1]) {&lt;br /&gt;     int temp = numbers[i];  &lt;br /&gt;     numbers[i] = numbers[i+1];  &lt;br /&gt;     numbers[i+1] = temp;&lt;br /&gt;    }&lt;br /&gt;   }&lt;br /&gt;  }&lt;br /&gt;&lt;br /&gt;  long elapsed = (System.nanoTime() - start);&lt;br /&gt;  System.out.println("Bubble-sorted numbers: ");&lt;br /&gt;  printArray();&lt;br /&gt;  System.out.println("Elapsed time: " + elapsed + "ns\n");&lt;br /&gt; }&lt;br /&gt;&lt;br /&gt; public void selectionSort(){&lt;br /&gt;  randomizeNumbers();&lt;br /&gt;  System.out.println("SELECTION SORT");&lt;br /&gt;  System.out.println("Presorted numbers: ");&lt;br /&gt;  printArray();&lt;br /&gt;  long start = System.nanoTime();&lt;br /&gt;&lt;br /&gt;  /**&lt;br /&gt;   * Selectionsort Algoritm&lt;br /&gt;   * Wikipedia:&lt;br /&gt;   * 1. Find the minimum value in the list&lt;br /&gt;   * 2. Swap it with the value in the first position&lt;br /&gt;   * 3. Repeat the steps above for the remainder of the list (starting &lt;br /&gt;   *    at the second position and advancing each time)&lt;br /&gt;   * Complexity:&lt;br /&gt;   * Worst = O(n^2)&lt;br /&gt;   * Average = O(n^2)&lt;br /&gt;   * Best = O(n^2)&lt;br /&gt;   */&lt;br /&gt;  for (int i=0; i&amp;lt;numbers.length-1; i++) {&lt;br /&gt;   int minIndex = i;&lt;br /&gt;   for (int j=i+1; j&amp;lt;numbers.length; j++) {&lt;br /&gt;    if (numbers[minIndex] &gt; numbers[j]) {&lt;br /&gt;     minIndex = j;&lt;br /&gt;    }&lt;br /&gt;   }&lt;br /&gt;   if (minIndex != i) { &lt;br /&gt;    int temp = numbers[i];&lt;br /&gt;    numbers[i] = numbers[minIndex];&lt;br /&gt;    numbers[minIndex] = temp;&lt;br /&gt;   }&lt;br /&gt;  }&lt;br /&gt;&lt;br /&gt;  long elapsed = (System.nanoTime() - start);&lt;br /&gt;  System.out.println("Selection-sorted numbers: ");&lt;br /&gt;  printArray();&lt;br /&gt;  System.out.println("Elapsed time: " + elapsed + "ns\n");&lt;br /&gt; }&lt;br /&gt;&lt;br /&gt; public void insertionSort(){&lt;br /&gt;  randomizeNumbers();&lt;br /&gt;  System.out.println("INSERTION SORT");&lt;br /&gt;  System.out.println("Presorted numbers: ");&lt;br /&gt;  printArray();&lt;br /&gt;  long start = System.nanoTime();&lt;br /&gt;&lt;br /&gt;  /**&lt;br /&gt;   * Insertionsort Algorithm&lt;br /&gt;   * Wikipedia:&lt;br /&gt;   * much less efficient on large lists than more advanced algorithms &lt;br /&gt;   * such as quicksort, heapsort, or merge sort. However, insertion sort &lt;br /&gt;   * provides several advantages:&lt;br /&gt;   * 1. simple implementation&lt;br /&gt;   * 2. efficient for (quite) small data sets&lt;br /&gt;   * 3. adaptive, i.e. efficient for data sets that are already substantially &lt;br /&gt;   *    sorted: the time complexity is O(n + d), where d is the number of inversions&lt;br /&gt;   * 4. more efficient in practice than most other simple quadratic (i.e. O(n^2)) algorithms &lt;br /&gt;   *    such as selection sort or bubble sort&lt;br /&gt;   * Complexity:&lt;br /&gt;   * Worst = O(n^2)&lt;br /&gt;   * Average = O(n^2)&lt;br /&gt;   * Best = O(n)&lt;br /&gt;   */&lt;br /&gt;  int in, out;&lt;br /&gt;  for(out=1; out&amp;lt;numbers.length; out++){&lt;br /&gt;   int temp = numbers[out];&lt;br /&gt;   in = out;&lt;br /&gt;   while(in&gt;0 &amp;&amp; numbers[in-1] &gt;= temp){&lt;br /&gt;    numbers[in] = numbers[in-1];&lt;br /&gt;    --in;&lt;br /&gt;   }&lt;br /&gt;   numbers[in] = temp;&lt;br /&gt;  }&lt;br /&gt;&lt;br /&gt;  long elapsed = (System.nanoTime() - start);&lt;br /&gt;  System.out.println("Insertion-sorted numbers: ");&lt;br /&gt;  printArray();&lt;br /&gt;  System.out.println("Elapsed time: " + elapsed + "ns\n");&lt;br /&gt; }&lt;br /&gt;&lt;br /&gt; public static void main(String[] args) {&lt;br /&gt;  SortingAlgorithm sa = new SortingAlgorithm();&lt;br /&gt;  sa.bubbleSort();&lt;br /&gt;  sa.selectionSort();&lt;br /&gt;  sa.insertionSort();&lt;br /&gt; }&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;&lt;/pre&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4844902456784005421-8589263464513143564?l=nicholaskey.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://nicholaskey.blogspot.com/feeds/8589263464513143564/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://nicholaskey.blogspot.com/2009/10/sorting-algorithms-bubble-sort.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4844902456784005421/posts/default/8589263464513143564'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4844902456784005421/posts/default/8589263464513143564'/><link rel='alternate' type='text/html' href='http://nicholaskey.blogspot.com/2009/10/sorting-algorithms-bubble-sort.html' title='Sorting Algorithms (Bubble sort, Selection sort &amp; Insertion Sort)'/><author><name>Nicholas Key</name><uri>http://www.blogger.com/profile/05768297019453812096</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='http://4.bp.blogspot.com/_OQU38yb-Uq0/SwL5VBlHCII/AAAAAAAAA6U/lXUy53mS7gQ/S220/hamster.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4844902456784005421.post-8104264896311054757</id><published>2009-10-23T09:09:00.003-07:00</published><updated>2009-10-26T12:30:04.062-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Algorithms'/><title type='text'>BFS and DFS (intro)</title><content type='html'>BFS:&lt;br /&gt;- works in a queue manner (FIFO)&lt;br /&gt;&lt;br /&gt;DFS:&lt;br /&gt;- works in a stack manner (LIFO)&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4844902456784005421-8104264896311054757?l=nicholaskey.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://nicholaskey.blogspot.com/feeds/8104264896311054757/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://nicholaskey.blogspot.com/2009/10/bfs-and-dfs-intro.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4844902456784005421/posts/default/8104264896311054757'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4844902456784005421/posts/default/8104264896311054757'/><link rel='alternate' type='text/html' href='http://nicholaskey.blogspot.com/2009/10/bfs-and-dfs-intro.html' title='BFS and DFS (intro)'/><author><name>Nicholas Key</name><uri>http://www.blogger.com/profile/05768297019453812096</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='http://4.bp.blogspot.com/_OQU38yb-Uq0/SwL5VBlHCII/AAAAAAAAA6U/lXUy53mS7gQ/S220/hamster.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4844902456784005421.post-6418788316734670190</id><published>2009-10-22T10:32:00.009-07:00</published><updated>2009-10-22T18:36:14.724-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Java'/><title type='text'>Web Journal's Ranking in Google Blog Search</title><content type='html'>Tell me you would be very happy if you are a blogger yourself and your blog is ranked top in the search result. I am thrilled to see this ;) Thanks to all the readers who make this possible.&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://4.bp.blogspot.com/_OQU38yb-Uq0/SuCXrxom91I/AAAAAAAAA10/bOOAovXeEFU/s1600-h/Picture+2.png"&gt;&lt;img style="display:block; margin:0px auto 10px; text-align:center;cursor:pointer; cursor:hand;width: 400px; height: 222px;" src="http://4.bp.blogspot.com/_OQU38yb-Uq0/SuCXrxom91I/AAAAAAAAA10/bOOAovXeEFU/s400/Picture+2.png" border="0" alt=""id="BLOGGER_PHOTO_ID_5395479131903686482" /&gt;&lt;/a&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4844902456784005421-6418788316734670190?l=nicholaskey.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://nicholaskey.blogspot.com/feeds/6418788316734670190/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://nicholaskey.blogspot.com/2009/10/web-journals-ranking-in-google-blog.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4844902456784005421/posts/default/6418788316734670190'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4844902456784005421/posts/default/6418788316734670190'/><link rel='alternate' type='text/html' href='http://nicholaskey.blogspot.com/2009/10/web-journals-ranking-in-google-blog.html' title='Web Journal&apos;s Ranking in Google Blog Search'/><author><name>Nicholas Key</name><uri>http://www.blogger.com/profile/05768297019453812096</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='http://4.bp.blogspot.com/_OQU38yb-Uq0/SwL5VBlHCII/AAAAAAAAA6U/lXUy53mS7gQ/S220/hamster.jpg'/></author><media:thumbnail xmlns:media='http://search.yahoo.com/mrss/' url='http://4.bp.blogspot.com/_OQU38yb-Uq0/SuCXrxom91I/AAAAAAAAA10/bOOAovXeEFU/s72-c/Picture+2.png' height='72' width='72'/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4844902456784005421.post-2422248664153457645</id><published>2009-10-22T10:32:00.007-07:00</published><updated>2009-10-22T19:46:19.741-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Java'/><title type='text'>Mirror by Jonas</title><content type='html'>This is a very special segment of my blog because I'm helping a reader of my blog to promote his API about Java Reflection. Many thanks to Jonas for coming up with such convenient API. You may take a look at his project "Mirror" at this &lt;a href="http://projetos.vidageek.net/mirror/mirror/"&gt;link&lt;/a&gt;.&lt;br /&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://1.bp.blogspot.com/_OQU38yb-Uq0/SuEYDub_OlI/AAAAAAAAA18/PMyHQJ1zTI0/s1600-h/Picture+3.png"&gt;&lt;img style="display:block; margin:0px auto 10px; text-align:center;cursor:pointer; cursor:hand;width: 400px; height: 250px;" src="http://1.bp.blogspot.com/_OQU38yb-Uq0/SuEYDub_OlI/AAAAAAAAA18/PMyHQJ1zTI0/s400/Picture+3.png" border="0" alt=""id="BLOGGER_PHOTO_ID_5395620280850659922" /&gt;&lt;/a&gt;I would want to liken this Mirror API it to using Velocity to generate dynamic HTML in a sense that it eases your coding complexity.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4844902456784005421-2422248664153457645?l=nicholaskey.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://nicholaskey.blogspot.com/feeds/2422248664153457645/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://nicholaskey.blogspot.com/2009/10/mirror-by-jonas.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4844902456784005421/posts/default/2422248664153457645'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4844902456784005421/posts/default/2422248664153457645'/><link rel='alternate' type='text/html' href='http://nicholaskey.blogspot.com/2009/10/mirror-by-jonas.html' title='Mirror by Jonas'/><author><name>Nicholas Key</name><uri>http://www.blogger.com/profile/05768297019453812096</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='http://4.bp.blogspot.com/_OQU38yb-Uq0/SwL5VBlHCII/AAAAAAAAA6U/lXUy53mS7gQ/S220/hamster.jpg'/></author><media:thumbnail xmlns:media='http://search.yahoo.com/mrss/' url='http://1.bp.blogspot.com/_OQU38yb-Uq0/SuEYDub_OlI/AAAAAAAAA18/PMyHQJ1zTI0/s72-c/Picture+3.png' height='72' width='72'/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4844902456784005421.post-4548988480051517585</id><published>2009-10-21T15:30:00.001-07:00</published><updated>2011-08-03T06:24:27.016-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Java'/><category scheme='http://www.blogger.com/atom/ns#' term='General Knowledge'/><category scheme='http://www.blogger.com/atom/ns#' term='Useful Method'/><category scheme='http://www.blogger.com/atom/ns#' term='Algorithms'/><title type='text'>Traversing Folder and Files</title><content type='html'>Here is an updated code to inform you if the file or folder specified does not exists. You may take a look at the original code at this &lt;a href="http://nicholaskey.blogspot.com/2009/10/traversing-folders-and-files.html"&gt;article&lt;/a&gt;. &lt;pre&gt;&lt;br /&gt;&lt;br /&gt; public void traverseFilesFolders () {&lt;br /&gt;  if (referencedFile.exists()) {&lt;br /&gt;   traverseFilesFolders(referencedFile);&lt;br /&gt;  } else {&lt;br /&gt;   System.out.println("File or Folder does not exist");&lt;br /&gt;  }&lt;br /&gt; }&lt;br /&gt;&lt;br /&gt;&lt;/pre&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4844902456784005421-4548988480051517585?l=nicholaskey.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://nicholaskey.blogspot.com/feeds/4548988480051517585/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://nicholaskey.blogspot.com/2009/10/traversing-folder-and-files.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4844902456784005421/posts/default/4548988480051517585'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4844902456784005421/posts/default/4548988480051517585'/><link rel='alternate' type='text/html' href='http://nicholaskey.blogspot.com/2009/10/traversing-folder-and-files.html' title='Traversing Folder and Files'/><author><name>Nicholas Key</name><uri>http://www.blogger.com/profile/05768297019453812096</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='http://4.bp.blogspot.com/_OQU38yb-Uq0/SwL5VBlHCII/AAAAAAAAA6U/lXUy53mS7gQ/S220/hamster.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4844902456784005421.post-4893479625824010807</id><published>2009-10-21T09:01:00.007-07:00</published><updated>2009-10-21T15:29:08.591-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Java'/><category scheme='http://www.blogger.com/atom/ns#' term='General Knowledge'/><title type='text'>Final vs Finally vs Finalize</title><content type='html'>&lt;span style="font-weight:bold;"&gt;A short note for myself:&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;Final: used for defining a class non-subclassable, and making a member variable as a &lt;br /&gt;constant which cannot be modified, and declare a method non-overridable.&lt;br /&gt;&lt;br /&gt;Finally: to provide the capability to execute code no matter whether or &lt;br /&gt;not an exception is thrown or caught in the try-catch exception handler. &lt;br /&gt;&lt;br /&gt;Finalize: helps in garbage collection to clean up objects that are no longer required. Usualy Java will do the garbage collection automatically.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4844902456784005421-4893479625824010807?l=nicholaskey.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://nicholaskey.blogspot.com/feeds/4893479625824010807/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://nicholaskey.blogspot.com/2009/10/final-vs-finally-vs-finalize.html#comment-form' title='2 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4844902456784005421/posts/default/4893479625824010807'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4844902456784005421/posts/default/4893479625824010807'/><link rel='alternate' type='text/html' href='http://nicholaskey.blogspot.com/2009/10/final-vs-finally-vs-finalize.html' title='Final vs Finally vs Finalize'/><author><name>Nicholas Key</name><uri>http://www.blogger.com/profile/05768297019453812096</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='http://4.bp.blogspot.com/_OQU38yb-Uq0/SwL5VBlHCII/AAAAAAAAA6U/lXUy53mS7gQ/S220/hamster.jpg'/></author><thr:total>2</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4844902456784005421.post-8167174137622514785</id><published>2009-10-19T17:00:00.007-07:00</published><updated>2011-08-03T06:25:29.259-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Java'/><category scheme='http://www.blogger.com/atom/ns#' term='General Knowledge'/><category scheme='http://www.blogger.com/atom/ns#' term='Useful Method'/><title type='text'>Java Reflection</title><content type='html'>The Reflection API allows the user to get the complete, but not limited to, information about classes, constructors, interfaces and methods that are being used. There are many things we can achieve with this API and the methods are:&lt;br /&gt;&lt;span style="font-weight:bold;"&gt;getInterfaces()&lt;br /&gt;getName()&lt;br /&gt;getClass()&lt;br /&gt;getSuperclass()&lt;br /&gt;getMethods()&lt;br /&gt;getFields()&lt;br /&gt;getConstructors()&lt;/span&gt;&lt;pre&gt;&lt;br /&gt;import java.lang.reflect.Constructor;&lt;br /&gt;import java.lang.reflect.Field;&lt;br /&gt;import java.lang.reflect.Method;&lt;br /&gt;&lt;br /&gt;public class ReflectionTool {&lt;br /&gt;&lt;br /&gt; private static final String padding = "\t";&lt;br /&gt; &lt;br /&gt; public void retrieveInterfaces(){&lt;br /&gt;  System.out.println("Retrieve Interface(s):");&lt;br /&gt;  for (Class&lt;?&gt; anInterface: java.util.Date.class.getInterfaces()) {&lt;br /&gt;   System.out.println(padding + anInterface);&lt;br /&gt;  }&lt;br /&gt; }&lt;br /&gt;&lt;br /&gt; public void retrieveName(){&lt;br /&gt;  System.out.println("Retrieve Name of Class:");&lt;br /&gt;     System.out.println(padding + java.util.concurrent.atomic.AtomicInteger.class.getName());&lt;br /&gt; }&lt;br /&gt; &lt;br /&gt; public void retrieveClass(){&lt;br /&gt;  System.out.println("Retrieve Runtime Class:");&lt;br /&gt;  System.out.println(padding + java.util.zip.CRC32.class.getClass());&lt;br /&gt; }&lt;br /&gt;&lt;br /&gt; public void retrieveSuperClass(){&lt;br /&gt;  System.out.println("Retrieve Superclass:");&lt;br /&gt;  System.out.println(padding + java.util.zip.CRC32.class.getClass().getSuperclass());&lt;br /&gt; }&lt;br /&gt;&lt;br /&gt; public void retrieveMethods(){&lt;br /&gt;  System.out.println("Retrieve Methods:");&lt;br /&gt;  for (Method aMethod: java.util.List.class.getMethods()) {&lt;br /&gt;   System.out.println(padding + aMethod);&lt;br /&gt;  }&lt;br /&gt; }&lt;br /&gt; &lt;br /&gt; public void retrieveFields(){&lt;br /&gt;  System.out.println("Retrieve Fields:");&lt;br /&gt;  for (Field aField: java.lang.Double.class.getFields()) {&lt;br /&gt;   System.out.println(padding + aField);&lt;br /&gt;  }&lt;br /&gt; }&lt;br /&gt; &lt;br /&gt; public void retrieveConstructors(){&lt;br /&gt;  System.out.println("Retrieve Constructors:");&lt;br /&gt;  for (Constructor&lt;?&gt; aConstructor: java.lang.Double.class.getConstructors()) {&lt;br /&gt;   System.out.println(padding + aConstructor);&lt;br /&gt;  }&lt;br /&gt; }&lt;br /&gt; &lt;br /&gt; public static void main(String[] args) {&lt;br /&gt;  ReflectionTool rt = new ReflectionTool();&lt;br /&gt;  rt.retrieveInterfaces();&lt;br /&gt;  rt.retrieveName();&lt;br /&gt;  rt.retrieveClass();&lt;br /&gt;  rt.retrieveSuperClass();&lt;br /&gt;  rt.retrieveMethods();&lt;br /&gt;  rt.retrieveFields();&lt;br /&gt;  rt.retrieveConstructors();&lt;br /&gt; }&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;&lt;/pre&gt;The output of the code is as follow. Nothing fancy, nothing complicated. Everything is straightforward.&lt;pre&gt;&lt;br /&gt;Retrieve Interface(s):&lt;br /&gt; interface java.io.Serializable&lt;br /&gt; interface java.lang.Cloneable&lt;br /&gt; interface java.lang.Comparable&lt;br /&gt;Retrieve Name of Class:&lt;br /&gt; java.util.concurrent.atomic.AtomicInteger&lt;br /&gt;Retrieve Runtime Class:&lt;br /&gt; class java.lang.Class&lt;br /&gt;Retrieve Superclass:&lt;br /&gt; class java.lang.Object&lt;br /&gt;Retrieve Methods:&lt;br /&gt; public abstract int java.util.List.hashCode()&lt;br /&gt; public abstract boolean java.util.List.equals(java.lang.Object)&lt;br /&gt; public abstract java.lang.Object java.util.List.get(int)&lt;br /&gt; public abstract boolean java.util.List.add(java.lang.Object)&lt;br /&gt; public abstract void java.util.List.add(int,java.lang.Object)&lt;br /&gt; public abstract int java.util.List.indexOf(java.lang.Object)&lt;br /&gt; public abstract void java.util.List.clear()&lt;br /&gt; public abstract int java.util.List.lastIndexOf(java.lang.Object)&lt;br /&gt; public abstract boolean java.util.List.contains(java.lang.Object)&lt;br /&gt; public abstract boolean java.util.List.addAll(java.util.Collection)&lt;br /&gt; public abstract boolean java.util.List.addAll(int,java.util.Collection)&lt;br /&gt; public abstract int java.util.List.size()&lt;br /&gt; public abstract java.lang.Object[] java.util.List.toArray()&lt;br /&gt; public abstract java.lang.Object[] java.util.List.toArray(java.lang.Object[])&lt;br /&gt; public abstract java.util.Iterator java.util.List.iterator()&lt;br /&gt; public abstract java.lang.Object java.util.List.set(int,java.lang.Object)&lt;br /&gt; public abstract boolean java.util.List.remove(java.lang.Object)&lt;br /&gt; public abstract java.lang.Object java.util.List.remove(int)&lt;br /&gt; public abstract boolean java.util.List.isEmpty()&lt;br /&gt; public abstract boolean java.util.List.containsAll(java.util.Collection)&lt;br /&gt; public abstract boolean java.util.List.removeAll(java.util.Collection)&lt;br /&gt; public abstract boolean java.util.List.retainAll(java.util.Collection)&lt;br /&gt; public abstract java.util.List java.util.List.subList(int,int)&lt;br /&gt; public abstract java.util.ListIterator java.util.List.listIterator()&lt;br /&gt; public abstract java.util.ListIterator java.util.List.listIterator(int)&lt;br /&gt;Retrieve Fields:&lt;br /&gt; public static final double java.lang.Double.POSITIVE_INFINITY&lt;br /&gt; public static final double java.lang.Double.NEGATIVE_INFINITY&lt;br /&gt; public static final double java.lang.Double.NaN&lt;br /&gt; public static final double java.lang.Double.MAX_VALUE&lt;br /&gt; public static final double java.lang.Double.MIN_VALUE&lt;br /&gt; public static final int java.lang.Double.SIZE&lt;br /&gt; public static final java.lang.Class java.lang.Double.TYPE&lt;br /&gt;Retrieve Constructors:&lt;br /&gt; public java.lang.Double(double)&lt;br /&gt; public java.lang.Double(java.lang.String) throws java.lang.NumberFormatException&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;/pre&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4844902456784005421-8167174137622514785?l=nicholaskey.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://nicholaskey.blogspot.com/feeds/8167174137622514785/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://nicholaskey.blogspot.com/2009/10/java-reflection.html#comment-form' title='3 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4844902456784005421/posts/default/8167174137622514785'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4844902456784005421/posts/default/8167174137622514785'/><link rel='alternate' type='text/html' href='http://nicholaskey.blogspot.com/2009/10/java-reflection.html' title='Java Reflection'/><author><name>Nicholas Key</name><uri>http://www.blogger.com/profile/05768297019453812096</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='http://4.bp.blogspot.com/_OQU38yb-Uq0/SwL5VBlHCII/AAAAAAAAA6U/lXUy53mS7gQ/S220/hamster.jpg'/></author><thr:total>3</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4844902456784005421.post-9055715230764138050</id><published>2009-10-16T14:40:00.009-07:00</published><updated>2011-08-03T06:26:00.242-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Java'/><category scheme='http://www.blogger.com/atom/ns#' term='General Knowledge'/><category scheme='http://www.blogger.com/atom/ns#' term='Useful Method'/><category scheme='http://www.blogger.com/atom/ns#' term='Algorithms'/><title type='text'>Traversing Folders and Files Recursively</title><content type='html'>Both files and folders are represented as File object in the java.io package. We are recognizing if an object is a file by using the method "isFile()" and a folder with the method "isDirectory()".&lt;pre&gt;&lt;br /&gt;import java.io.File;&lt;br /&gt;&lt;br /&gt;public class FilesFoldersTraversal {&lt;br /&gt;&lt;br /&gt; private final char SEPARATOR = File.separatorChar;&lt;br /&gt; private File originalFile;&lt;br /&gt; private File referencedFile;&lt;br /&gt; private String pad = null;&lt;br /&gt; private String absolutePathOriginalFile = null;&lt;br /&gt;&lt;br /&gt; public FilesFoldersTraversal(String inputFileString) {&lt;br /&gt;  File inputFile = new File(inputFileString);&lt;br /&gt;  originalFile = inputFile;&lt;br /&gt;  referencedFile = inputFile;&lt;br /&gt;  absolutePathOriginalFile = originalFile.getAbsolutePath();&lt;br /&gt; }&lt;br /&gt;&lt;br /&gt; public void traverseFilesFolders () {&lt;br /&gt;  traverseFilesFolders(referencedFile);&lt;br /&gt; }&lt;br /&gt;&lt;br /&gt; private void traverseFilesFolders(File referencedFile){ &lt;br /&gt;  if (referencedFile.isDirectory()){&lt;br /&gt;   pad = getPadding(referencedFile);&lt;br /&gt;   processFolders(referencedFile);&lt;br /&gt;  }&lt;br /&gt;  else if (referencedFile.isFile()){&lt;br /&gt;   processFiles(referencedFile);&lt;br /&gt;  }&lt;br /&gt; }&lt;br /&gt;&lt;br /&gt; private void processFolders(File referencedFile){&lt;br /&gt;  System.out.println(pad + "Folder: " + referencedFile.getName());&lt;br /&gt;  File listFiles[] = referencedFile.listFiles();&lt;br /&gt;  for(File singleFile : listFiles){&lt;br /&gt;   traverseFilesFolders(singleFile);&lt;br /&gt;  }&lt;br /&gt; }&lt;br /&gt;&lt;br /&gt; private void processFiles(File referencedFile){&lt;br /&gt;  System.out.println(pad  + "  " + "File: " + referencedFile.getName());&lt;br /&gt; }&lt;br /&gt;&lt;br /&gt; private String getPadding(File referencedFile){&lt;br /&gt;  String padding = ""; &lt;br /&gt;  String fileAbsolutePath = referencedFile.getAbsolutePath();  &lt;br /&gt;  String filePathSubString = fileAbsolutePath.substring(absolutePathOriginalFile.length(), fileAbsolutePath.length());&lt;br /&gt;&lt;br /&gt;  int index = 0;&lt;br /&gt;  int subStringLength = filePathSubString.length();&lt;br /&gt;  while (index &lt; subStringLength) {&lt;br /&gt;   if (filePathSubString.charAt(index) == SEPARATOR){&lt;br /&gt;    padding += "  ";&lt;br /&gt;   }&lt;br /&gt;   index++;&lt;br /&gt;  }&lt;br /&gt;&lt;br /&gt;  return padding;&lt;br /&gt; }&lt;br /&gt;&lt;br /&gt; public static void main(String[] args) {&lt;br /&gt;  FilesFoldersTraversal fft = new FilesFoldersTraversal("/Users/YOUR_USER_NAME/Documents");&lt;br /&gt;  fft.traverseFilesFolders();&lt;br /&gt; }&lt;br /&gt;&lt;br /&gt;}&lt;br /&gt;&lt;/pre&gt;There are many interesting things you can do with the example shown. You may add a few lines of codes to compile a list of files of a specific file extension, for example ".txt" or ".class".&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4844902456784005421-9055715230764138050?l=nicholaskey.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://nicholaskey.blogspot.com/feeds/9055715230764138050/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://nicholaskey.blogspot.com/2009/10/traversing-folders-and-files.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4844902456784005421/posts/default/9055715230764138050'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4844902456784005421/posts/default/9055715230764138050'/><link rel='alternate' type='text/html' href='http://nicholaskey.blogspot.com/2009/10/traversing-folders-and-files.html' title='Traversing Folders and Files Recursively'/><author><name>Nicholas Key</name><uri>http://www.blogger.com/profile/05768297019453812096</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='http://4.bp.blogspot.com/_OQU38yb-Uq0/SwL5VBlHCII/AAAAAAAAA6U/lXUy53mS7gQ/S220/hamster.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4844902456784005421.post-7133760877475931629</id><published>2009-10-08T23:44:00.009-07:00</published><updated>2009-10-09T13:46:05.656-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Technology'/><category scheme='http://www.blogger.com/atom/ns#' term='Java'/><category scheme='http://www.blogger.com/atom/ns#' term='Android'/><title type='text'>MediaPlayer vs SoundPool</title><content type='html'>Here is my recommendation if you are not sure which class to use - MediaPlayer or SoundPool when developing an Android application. &lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight:bold;"&gt;MediaPlayer&lt;/span&gt;:&lt;br /&gt;If you were to play a background music in your application, you should go for MediaPlayer. MediaPlayer is my preferred class because it allows you to playback a lengthy audio file.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight:bold;"&gt;SoundPool&lt;/span&gt;:&lt;br /&gt;As the name explains itself, SoundPool class allows you to playback a collection of short sound effects quickly and it does not lag much. Imagine yourself writing a game with several sound effects meant for different actions. You may use a HashMap to compile the list of SFXs and then play it by accessing the index number (key in the HashMap).&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight:bold;"&gt;Summary&lt;/span&gt;: &lt;br /&gt;Notice the adjectives I used for different classes. &lt;br /&gt;Lengthy, theme = MediaPlayer&lt;br /&gt;Short, effect = SoundPool&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4844902456784005421-7133760877475931629?l=nicholaskey.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://nicholaskey.blogspot.com/feeds/7133760877475931629/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://nicholaskey.blogspot.com/2009/10/mediaplayer-vs-soundpool.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4844902456784005421/posts/default/7133760877475931629'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4844902456784005421/posts/default/7133760877475931629'/><link rel='alternate' type='text/html' href='http://nicholaskey.blogspot.com/2009/10/mediaplayer-vs-soundpool.html' title='MediaPlayer vs SoundPool'/><author><name>Nicholas Key</name><uri>http://www.blogger.com/profile/05768297019453812096</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='http://4.bp.blogspot.com/_OQU38yb-Uq0/SwL5VBlHCII/AAAAAAAAA6U/lXUy53mS7gQ/S220/hamster.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4844902456784005421.post-5908278254755790791</id><published>2009-10-05T00:20:00.009-07:00</published><updated>2009-10-05T08:50:10.613-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Technology'/><category scheme='http://www.blogger.com/atom/ns#' term='Java'/><category scheme='http://www.blogger.com/atom/ns#' term='XML'/><category scheme='http://www.blogger.com/atom/ns#' term='Android'/><title type='text'>Reading XML in Android platform</title><content type='html'>I find these XmlResourceParser and XmlPullParser classes useful to read XML files when we are dealing with Android platform. Below is the code sample I use in my Android project:&lt;textarea name="code" class="java" cols="60" rows="1000"&gt;&lt;br /&gt;private XmlResourceParser xrp;&lt;br /&gt;&lt;br /&gt;public void onCreate(Bundle savedInstanceState) {&lt;br /&gt;  . . .&lt;br /&gt;  . . .&lt;br /&gt;  . . .&lt;br /&gt;  xrp = this.getResources().getXml(R.xml.YOUR_FILE_NAME);&lt;br /&gt;  try {&lt;br /&gt;    xrp.next();&lt;br /&gt;    int eventType = xrp.getEventType(); &lt;br /&gt;    while (eventType != XmlPullParser.END_DOCUMENT){&lt;br /&gt;      readXML(eventType);&lt;br /&gt;      eventType = xrp.next();&lt;br /&gt;    }&lt;br /&gt;  } catch (XmlPullParserException e) {&lt;br /&gt;    e.printStackTrace();&lt;br /&gt;  } catch (IOException e) {&lt;br /&gt;    e.printStackTrace();&lt;br /&gt;  } &lt;br /&gt;  . . .&lt;br /&gt;  . . .&lt;br /&gt;  . . .&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;public void readXML(int eventType){&lt;br /&gt;  if(eventType == XmlPullParser.START_DOCUMENT) { } &lt;br /&gt;  else if(eventType == XmlPullParser.END_TAG) { &lt;br /&gt;    System.out.println("End tag "+xpp.getName());&lt;br /&gt;  } &lt;br /&gt;  else if(eventType == XmlPullParser.START_TAG) { &lt;br /&gt;    System.out.println("Start tag "+xrp.getName());&lt;br /&gt;  } &lt;br /&gt;  else if(eventType == XmlPullParser.TEXT) { &lt;br /&gt;    System.out.println("Text "+xrp.getText());&lt;br /&gt;  }&lt;br /&gt;}&lt;br /&gt;&lt;/textarea&gt;Here is an example from the &lt;a href="http://developer.android.com/reference/org/xmlpull/v1/XmlPullParser.html"&gt;Android Developers website&lt;/a&gt;.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4844902456784005421-5908278254755790791?l=nicholaskey.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://nicholaskey.blogspot.com/feeds/5908278254755790791/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://nicholaskey.blogspot.com/2009/10/reading-xml-in-android-platform.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4844902456784005421/posts/default/5908278254755790791'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4844902456784005421/posts/default/5908278254755790791'/><link rel='alternate' type='text/html' href='http://nicholaskey.blogspot.com/2009/10/reading-xml-in-android-platform.html' title='Reading XML in Android platform'/><author><name>Nicholas Key</name><uri>http://www.blogger.com/profile/05768297019453812096</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='http://4.bp.blogspot.com/_OQU38yb-Uq0/SwL5VBlHCII/AAAAAAAAA6U/lXUy53mS7gQ/S220/hamster.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4844902456784005421.post-7282504354610876657</id><published>2009-10-05T00:20:00.001-07:00</published><updated>2009-10-14T17:21:33.656-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Country Codes'/><category scheme='http://www.blogger.com/atom/ns#' term='Java'/><category scheme='http://www.blogger.com/atom/ns#' term='General Knowledge'/><category scheme='http://www.blogger.com/atom/ns#' term='XSL'/><category scheme='http://www.blogger.com/atom/ns#' term='XML'/><category scheme='http://www.blogger.com/atom/ns#' term='ISO 3166-1-alpha-2'/><title type='text'>Detailed explanation of using XSL to scrape ISO country codes</title><content type='html'>I apologize if you couldn't understand how I managed to scrape the country codes from the &lt;a href="http://www.iso.org/iso/country_codes/iso_3166_code_lists/english_country_names_and_code_elements.htm"&gt;ISO&lt;/a&gt; website as mentioned in my previous article. Here are the detailed steps to scrape the codes accordingly. You'll need 3 things to achieve the goal: manual editing (I know it's primitive otherwise you are more than welcomed to write your HTML tag stripper to recognize the elements in the web page), XML file and XSL file.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight:bold; color:red;"&gt;[1] Copy the table element:&lt;/span&gt;&lt;br /&gt;- Copy the entire table element that contains the country names and codes&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight:bold; color:red;"&gt;[2] Editing the XML file:&lt;/span&gt;&lt;br /&gt;- Open an empty file&lt;br /&gt;- Save it as "countries.xml"&lt;br /&gt;- Add this line at the top of the XML file:&lt;br /&gt;&lt;span style="font-weight:bold;"&gt;&amp;lt;?xml version="1.0" encoding="UTF-8"?&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-weight:bold;"&gt;&amp;lt;?xml-stylesheet type="text/xsl" href="countries.xsl"?&gt;&lt;/span&gt;&lt;br /&gt;- Paste the table element you copied earlier&lt;br /&gt;- Remove the table row that contains "Country names" and "ISO 3166-1-alpha-2 code"&lt;br /&gt;- The screenshot is as below:&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://4.bp.blogspot.com/_OQU38yb-Uq0/StZm70GYNiI/AAAAAAAAA1k/iWfi4B0_xCE/s1600-h/pic3.png"&gt;&lt;img style="display:block; margin:0px auto 10px; text-align:center;cursor:pointer; cursor:hand;width: 400px; height: 259px;" src="http://4.bp.blogspot.com/_OQU38yb-Uq0/StZm70GYNiI/AAAAAAAAA1k/iWfi4B0_xCE/s400/pic3.png" border="0" alt=""id="BLOGGER_PHOTO_ID_5392610781606458914" /&gt;&lt;/a&gt;&lt;span style="font-weight:bold; color:red;"&gt;[3] Editing the XSL file:&lt;/span&gt;&lt;br /&gt;- Copy the XPath codes I demonstrated in this &lt;a href="http://nicholaskey.blogspot.com/2009/09/scraping-iso-3166-1-alpha-2-code.html"&gt;article&lt;/a&gt;&lt;br /&gt;- Save it as "countries.xsl"&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight:bold; color:red;"&gt;[4] You are all set!&lt;/span&gt;&lt;br /&gt;- Here is the sample output translating the XML using XPath&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://2.bp.blogspot.com/_OQU38yb-Uq0/StZqiaokoVI/AAAAAAAAA1s/630sFKhHaFA/s1600-h/abb.png"&gt;&lt;img style="display:block; margin:0px auto 10px; text-align:center;cursor:pointer; cursor:hand;width: 25px; height: 192px;" src="http://2.bp.blogspot.com/_OQU38yb-Uq0/StZqiaokoVI/AAAAAAAAA1s/630sFKhHaFA/s400/abb.png" border="0" alt=""id="BLOGGER_PHOTO_ID_5392614743320338770" /&gt;&lt;/a&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4844902456784005421-7282504354610876657?l=nicholaskey.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://nicholaskey.blogspot.com/feeds/7282504354610876657/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://nicholaskey.blogspot.com/2009/10/detailed-explanation-of-using-xsl-to.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4844902456784005421/posts/default/7282504354610876657'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4844902456784005421/posts/default/7282504354610876657'/><link rel='alternate' type='text/html' href='http://nicholaskey.blogspot.com/2009/10/detailed-explanation-of-using-xsl-to.html' title='Detailed explanation of using XSL to scrape ISO country codes'/><author><name>Nicholas Key</name><uri>http://www.blogger.com/profile/05768297019453812096</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='http://4.bp.blogspot.com/_OQU38yb-Uq0/SwL5VBlHCII/AAAAAAAAA6U/lXUy53mS7gQ/S220/hamster.jpg'/></author><media:thumbnail xmlns:media='http://search.yahoo.com/mrss/' url='http://4.bp.blogspot.com/_OQU38yb-Uq0/StZm70GYNiI/AAAAAAAAA1k/iWfi4B0_xCE/s72-c/pic3.png' height='72' width='72'/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4844902456784005421.post-3985965025424683332</id><published>2009-09-30T15:09:00.001-07:00</published><updated>2009-09-30T17:43:56.058-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Technology'/><category scheme='http://www.blogger.com/atom/ns#' term='Java'/><category scheme='http://www.blogger.com/atom/ns#' term='Android'/><title type='text'>Maintain Layout Orientation in Android Applications</title><content type='html'>Here is a one-liner statement in your manifest xml (AndroidManifest.xml) to maintain your preferred portrait layout orientation. Simply add this line in the XML:&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight:bold;"&gt;android:screenOrientation="portrait"&lt;/span&gt;&lt;br /&gt;&lt;textarea name="code" class="java" cols="60" rows="1000"&gt;&lt;br /&gt;&amp;lt;activity android:name=".ACTIVITY_NAME"&lt;br /&gt;  android:label="@string/app_name"&lt;br /&gt;  android:screenOrientation="portrait"&gt;&lt;br /&gt;    &amp;lt;intent-filter&gt;&lt;br /&gt;      &amp;lt;action android:name="android.intent.action.MAIN" /&gt;&lt;br /&gt;      &amp;lt;category android:name="android.intent.category.LAUNCHER" /&gt;&lt;br /&gt;    &amp;lt;/intent-filter&gt;&lt;br /&gt;&amp;lt;/activity&gt;&lt;/textarea&gt;Otherwise, you may also use "landscape" as the value.&lt;br /&gt;&lt;span style="font-weight:bold;"&gt;android:screenOrientation="landscape"&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;Further information is available at the &lt;a href="http://developer.android.com/reference/android/R.styleable.html#AndroidManifestActivity_screenOrientation"&gt;Android Developers Website&lt;/a&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4844902456784005421-3985965025424683332?l=nicholaskey.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://nicholaskey.blogspot.com/feeds/3985965025424683332/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://nicholaskey.blogspot.com/2009/09/maintain-layout-orientation-in-android.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4844902456784005421/posts/default/3985965025424683332'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4844902456784005421/posts/default/3985965025424683332'/><link rel='alternate' type='text/html' href='http://nicholaskey.blogspot.com/2009/09/maintain-layout-orientation-in-android.html' title='Maintain Layout Orientation in Android Applications'/><author><name>Nicholas Key</name><uri>http://www.blogger.com/profile/05768297019453812096</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='http://4.bp.blogspot.com/_OQU38yb-Uq0/SwL5VBlHCII/AAAAAAAAA6U/lXUy53mS7gQ/S220/hamster.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4844902456784005421.post-933454767926040482</id><published>2009-09-30T15:08:00.007-07:00</published><updated>2009-09-30T17:44:08.150-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Technology'/><category scheme='http://www.blogger.com/atom/ns#' term='Java'/><category scheme='http://www.blogger.com/atom/ns#' term='Android'/><title type='text'>Changing the Orientation of Android Emulator</title><content type='html'>Simply use these key combination: &lt;br /&gt;&lt;span style="font-weight:bold; color:red;"&gt;fn + control + F12&lt;/span&gt;&lt;br /&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://2.bp.blogspot.com/_OQU38yb-Uq0/SsPdpcsjf9I/AAAAAAAAA1c/gKpboJo-0dk/s1600-h/Picture+4.png"&gt;&lt;img style="display:block; margin:0px auto 10px; text-align:center;cursor:pointer; cursor:hand;width: 400px; height: 240px;" src="http://2.bp.blogspot.com/_OQU38yb-Uq0/SsPdpcsjf9I/AAAAAAAAA1c/gKpboJo-0dk/s400/Picture+4.png" border="0" alt=""id="BLOGGER_PHOTO_ID_5387393283412688850" /&gt;&lt;/a&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4844902456784005421-933454767926040482?l=nicholaskey.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://nicholaskey.blogspot.com/feeds/933454767926040482/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://nicholaskey.blogspot.com/2009/09/changing-orientation-of-android.html#comment-form' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4844902456784005421/posts/default/933454767926040482'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4844902456784005421/posts/default/933454767926040482'/><link rel='alternate' type='text/html' href='http://nicholaskey.blogspot.com/2009/09/changing-orientation-of-android.html' title='Changing the Orientation of Android Emulator'/><author><name>Nicholas Key</name><uri>http://www.blogger.com/profile/05768297019453812096</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='http://4.bp.blogspot.com/_OQU38yb-Uq0/SwL5VBlHCII/AAAAAAAAA6U/lXUy53mS7gQ/S220/hamster.jpg'/></author><media:thumbnail xmlns:media='http://search.yahoo.com/mrss/' url='http://2.bp.blogspot.com/_OQU38yb-Uq0/SsPdpcsjf9I/AAAAAAAAA1c/gKpboJo-0dk/s72-c/Picture+4.png' height='72' width='72'/><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4844902456784005421.post-223697112425156595</id><published>2009-09-22T09:10:00.001-07:00</published><updated>2011-08-03T06:26:42.138-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Recursion'/><category scheme='http://www.blogger.com/atom/ns#' term='Java'/><category scheme='http://www.blogger.com/atom/ns#' term='Algorithms'/><title type='text'>Tokenizing String Recursively</title><content type='html'>This is an update to the blog entry "&lt;a href="http://nicholaskey.blogspot.com/2009/09/string-tokenizer-by-hand.html"&gt;String tokenizer by hand&lt;/a&gt;". In this article, I am demonstrating an example of tokenizing a given string in a recursive manner. The code is as below:&lt;pre&gt;&lt;br /&gt;import java.util.ArrayList;&lt;br /&gt;&lt;br /&gt;public class StringTokenizer {&lt;br /&gt; &lt;br /&gt; private static ArrayList&lt;StringBuffer&gt; tokenizedStr = new ArrayList&lt;StringBuffer&gt;();&lt;br /&gt; private static StringBuffer str = new StringBuffer();&lt;br /&gt; &lt;br /&gt; public static ArrayList&lt;StringBuffer&gt; tokenizer(String input){&lt;br /&gt;  int strLength = input.length();&lt;br /&gt;  return tokenizer(input, 0, strLength);&lt;br /&gt; }&lt;br /&gt;&lt;br /&gt; public static ArrayList&lt;StringBuffer&gt; tokenizer(String input, int currentIndex, int strLength){&lt;br /&gt;  if (currentIndex &lt; strLength) {&lt;br /&gt;   char curr = input.charAt(currentIndex);&lt;br /&gt;   if (curr != ' ') {&lt;br /&gt;    str.append(curr);&lt;br /&gt;   } else {&lt;br /&gt;    if (str.length() != 0) {&lt;br /&gt;     tokenizedStr.add(str);&lt;br /&gt;    }&lt;br /&gt;    str = new StringBuffer();&lt;br /&gt;   }&lt;br /&gt;   if ((currentIndex == strLength-1 ) &amp;&amp; (curr != ' ')) {&lt;br /&gt;    tokenizedStr.add(str);&lt;br /&gt;   }&lt;br /&gt;   currentIndex++;&lt;br /&gt;   tokenizer(input, currentIndex, strLength);&lt;br /&gt;  }&lt;br /&gt;  return tokenizedStr;&lt;br /&gt; }&lt;br /&gt; &lt;br /&gt; public static void main(String[] args) {&lt;br /&gt;  System.out.println(tokenizer("  Hello World   This is     Nicholas Key.  How         are you?  "));&lt;br /&gt; }&lt;br /&gt;&lt;br /&gt;}&lt;/pre&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4844902456784005421-223697112425156595?l=nicholaskey.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://nicholaskey.blogspot.com/feeds/223697112425156595/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://nicholaskey.blogspot.com/2009/09/tokenizing-string-recursively.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4844902456784005421/posts/default/223697112425156595'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4844902456784005421/posts/default/223697112425156595'/><link rel='alternate' type='text/html' href='http://nicholaskey.blogspot.com/2009/09/tokenizing-string-recursively.html' title='Tokenizing String Recursively'/><author><name>Nicholas Key</name><uri>http://www.blogger.com/profile/05768297019453812096</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='http://4.bp.blogspot.com/_OQU38yb-Uq0/SwL5VBlHCII/AAAAAAAAA6U/lXUy53mS7gQ/S220/hamster.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4844902456784005421.post-1745309243332832561</id><published>2009-09-22T09:09:00.001-07:00</published><updated>2009-09-26T15:27:34.354-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Java'/><category scheme='http://www.blogger.com/atom/ns#' term='Android'/><title type='text'>Screenshot of Android 1.6 SDK</title><content type='html'>This is how the most recent Android 1.6 SDK looks like :)&lt;br /&gt;&lt;br /&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://2.bp.blogspot.com/_OQU38yb-Uq0/Sr6U_j1nRQI/AAAAAAAAA1U/q2hujui99Vk/s1600-h/Picture3.png"&gt;&lt;img style="display:block; margin:0px auto 10px; text-align:center;cursor:pointer; cursor:hand;width: 400px; height: 271px;" src="http://2.bp.blogspot.com/_OQU38yb-Uq0/Sr6U_j1nRQI/AAAAAAAAA1U/q2hujui99Vk/s400/Picture3.png" border="0" alt=""id="BLOGGER_PHOTO_ID_5385906024054473986" /&gt;&lt;/a&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4844902456784005421-1745309243332832561?l=nicholaskey.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://nicholaskey.blogspot.com/feeds/1745309243332832561/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://nicholaskey.blogspot.com/2009/09/screenshot-of-android-16-sdk.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4844902456784005421/posts/default/1745309243332832561'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4844902456784005421/posts/default/1745309243332832561'/><link rel='alternate' type='text/html' href='http://nicholaskey.blogspot.com/2009/09/screenshot-of-android-16-sdk.html' title='Screenshot of Android 1.6 SDK'/><author><name>Nicholas Key</name><uri>http://www.blogger.com/profile/05768297019453812096</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='http://4.bp.blogspot.com/_OQU38yb-Uq0/SwL5VBlHCII/AAAAAAAAA6U/lXUy53mS7gQ/S220/hamster.jpg'/></author><media:thumbnail xmlns:media='http://search.yahoo.com/mrss/' url='http://2.bp.blogspot.com/_OQU38yb-Uq0/Sr6U_j1nRQI/AAAAAAAAA1U/q2hujui99Vk/s72-c/Picture3.png' height='72' width='72'/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4844902456784005421.post-5565909030031087397</id><published>2009-09-16T23:33:00.009-07:00</published><updated>2009-09-17T11:22:33.379-07:00</updated><title type='text'>Venture Capitalists and Investors</title><content type='html'>This is an interesting video for us to ponder together and to reflect ourselves.&lt;br /&gt;&lt;br /&gt;&lt;object width="425" height="344"&gt;&lt;param name="movie" value="http://www.youtube.com/v/HDczbpIO85g&amp;hl=en&amp;fs=1&amp;"&gt;&lt;/param&gt;&lt;param name="allowFullScreen" value="true"&gt;&lt;/param&gt;&lt;param name="allowscriptaccess" value="always"&gt;&lt;/param&gt;&lt;embed src="http://www.youtube.com/v/HDczbpIO85g&amp;hl=en&amp;fs=1&amp;" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="425" height="344"&gt;&lt;/embed&gt;&lt;/object&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4844902456784005421-5565909030031087397?l=nicholaskey.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://nicholaskey.blogspot.com/feeds/5565909030031087397/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://nicholaskey.blogspot.com/2009/09/venture-capitalists-and-investors.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4844902456784005421/posts/default/5565909030031087397'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4844902456784005421/posts/default/5565909030031087397'/><link rel='alternate' type='text/html' href='http://nicholaskey.blogspot.com/2009/09/venture-capitalists-and-investors.html' title='Venture Capitalists and Investors'/><author><name>Nicholas Key</name><uri>http://www.blogger.com/profile/05768297019453812096</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='http://4.bp.blogspot.com/_OQU38yb-Uq0/SwL5VBlHCII/AAAAAAAAA6U/lXUy53mS7gQ/S220/hamster.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4844902456784005421.post-3074494164461323304</id><published>2009-09-15T19:32:00.009-07:00</published><updated>2009-09-15T19:37:58.841-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Java'/><category scheme='http://www.blogger.com/atom/ns#' term='Objective-C'/><category scheme='http://www.blogger.com/atom/ns#' term='iPhone App'/><category scheme='http://www.blogger.com/atom/ns#' term='Android'/><title type='text'>Android, iPhone, PalmOS</title><content type='html'>These are the screenshots of the desktop from three smartphones. From left to right: Android, iPhone and PalmOS. I personally prefer to write applications on Android simply because I'm familiar with Eclipse as the IDE and Java as the programming language, followed by iPhone simply because of the demand in the market and lastly, the PalmOS.&lt;br /&gt;&lt;br /&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://4.bp.blogspot.com/_OQU38yb-Uq0/SrBOfRpwE2I/AAAAAAAAA1M/u_bV26aY86U/s1600-h/Picture+1.png"&gt;&lt;img style="display:block; margin:0px auto 10px; text-align:center;cursor:pointer; cursor:hand;width: 400px; height: 208px;" src="http://4.bp.blogspot.com/_OQU38yb-Uq0/SrBOfRpwE2I/AAAAAAAAA1M/u_bV26aY86U/s400/Picture+1.png" border="0" alt=""id="BLOGGER_PHOTO_ID_5381887853929173858" /&gt;&lt;/a&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4844902456784005421-3074494164461323304?l=nicholaskey.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://nicholaskey.blogspot.com/feeds/3074494164461323304/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://nicholaskey.blogspot.com/2009/09/android-iphone-palmos.html#comment-form' title='2 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4844902456784005421/posts/default/3074494164461323304'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4844902456784005421/posts/default/3074494164461323304'/><link rel='alternate' type='text/html' href='http://nicholaskey.blogspot.com/2009/09/android-iphone-palmos.html' title='Android, iPhone, PalmOS'/><author><name>Nicholas Key</name><uri>http://www.blogger.com/profile/05768297019453812096</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='http://4.bp.blogspot.com/_OQU38yb-Uq0/SwL5VBlHCII/AAAAAAAAA6U/lXUy53mS7gQ/S220/hamster.jpg'/></author><media:thumbnail xmlns:media='http://search.yahoo.com/mrss/' url='http://4.bp.blogspot.com/_OQU38yb-Uq0/SrBOfRpwE2I/AAAAAAAAA1M/u_bV26aY86U/s72-c/Picture+1.png' height='72' width='72'/><thr:total>2</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4844902456784005421.post-691209768079445225</id><published>2009-09-13T11:00:00.009-07:00</published><updated>2011-08-03T06:27:21.374-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Java'/><category scheme='http://www.blogger.com/atom/ns#' term='General Knowledge'/><category scheme='http://www.blogger.com/atom/ns#' term='Binary Tree'/><category scheme='http://www.blogger.com/atom/ns#' term='Algorithms'/><title type='text'>Binary Tree and its popular methods</title><content type='html'>This is something convenient I think to do a brief revision on Binary Tree other than reading about it on &lt;a href="http://en.wikipedia.org/wiki/Binary_tree"&gt;Wikipedia&lt;/a&gt;. This implementation demonstrates the construction of binary tree with some elements and the typical methods related to it such as:&lt;br /&gt;[1] Pre-Order Traversal&lt;br /&gt;[2] In-Order Traversal&lt;br /&gt;[3] Post-Order Traversal&lt;br /&gt;[4] Getting the size of the binary tree&lt;br /&gt;[5] Get the minimum value&lt;br /&gt;[6] Get the maximum value&lt;br /&gt;[7] Get root value&lt;br /&gt;[8] Inserting new elements&lt;br /&gt;&lt;br /&gt;My implementation does not include duplication of elements. You may copy the code and test it yourself.&lt;pre&gt;&lt;br /&gt;import java.util.ArrayList;&lt;br /&gt;import java.util.Collections;&lt;br /&gt;import java.util.Random;&lt;br /&gt;&lt;br /&gt;public class BinaryTree {&lt;br /&gt;&lt;br /&gt; private static class TreeNode {&lt;br /&gt;  TreeNode left;&lt;br /&gt;  TreeNode right;&lt;br /&gt;  int nodeValue;&lt;br /&gt;  TreeNode(int data) {&lt;br /&gt;   left = null;&lt;br /&gt;   right = null;&lt;br /&gt;   nodeValue = data;&lt;br /&gt;  }&lt;br /&gt; }&lt;br /&gt;&lt;br /&gt; private TreeNode root;&lt;br /&gt; &lt;br /&gt; public BinaryTree() {&lt;br /&gt;  root = null;&lt;br /&gt; } &lt;br /&gt;&lt;br /&gt; public void constructBinaryTreeHardCoded() {&lt;br /&gt;  root = null;&lt;br /&gt;  &lt;br /&gt;  root = new TreeNode(6);   &lt;br /&gt;  //root = insertData(root, 6);&lt;br /&gt;  &lt;br /&gt;  root = insertData(root, 2);&lt;br /&gt;  root = insertData(root, 7);&lt;br /&gt;  root = insertData(root, 1);&lt;br /&gt;  root = insertData(root, 4);&lt;br /&gt;  root = insertData(root, 9);&lt;br /&gt;  root = insertData(root, 3);&lt;br /&gt;  root = insertData(root, 5);&lt;br /&gt;  root = insertData(root, 8);&lt;br /&gt; } &lt;br /&gt; &lt;br /&gt; public void testHarness(){&lt;br /&gt;  root = null;&lt;br /&gt;  &lt;br /&gt;  Random rand = new Random();&lt;br /&gt;  int rootValue = rand.nextInt( 20 ) + 1;&lt;br /&gt;  root = new TreeNode(rootValue);&lt;br /&gt;  System.out.println("Random seeded root value: " + rootValue);&lt;br /&gt;  int numberOfNodes = rand.nextInt( 18 ) + 1;&lt;br /&gt;  System.out.println("Random number of children to be generated: " + numberOfNodes);&lt;br /&gt;  for (int i = 0; i &lt; numberOfNodes; i++) {&lt;br /&gt;   int randValue = rand.nextInt( 30 ) + 1;&lt;br /&gt;   System.out.println("Inserting: " + randValue);&lt;br /&gt;   root = insertData(root, randValue);&lt;br /&gt;  }&lt;br /&gt; }&lt;br /&gt; &lt;br /&gt; public TreeNode insertData(TreeNode node, int data) {&lt;br /&gt;  if (node == null) {&lt;br /&gt;   node = new TreeNode(data);&lt;br /&gt;  } else {&lt;br /&gt;   if (data &lt; node.nodeValue) {&lt;br /&gt;    if (node.left != null) {&lt;br /&gt;     node.left = insertData(node.left, data);&lt;br /&gt;    } else {&lt;br /&gt;     node.left = new TreeNode(data);&lt;br /&gt;     System.out.println("Inserted " + data + " to the left of " + node.nodeValue);&lt;br /&gt;    }&lt;br /&gt;   } else if (data &gt; node.nodeValue) {&lt;br /&gt;    if (node.right != null) {&lt;br /&gt;     node.right = insertData(node.right, data);&lt;br /&gt;    } else {&lt;br /&gt;     node.right = new TreeNode(data);     &lt;br /&gt;     System.out.println("Inserted " + data + " to the right of " + node.nodeValue);&lt;br /&gt;    }&lt;br /&gt;   } else {&lt;br /&gt;    System.out.println("Not inserting " + data + " because it already exists in the tree");&lt;br /&gt;   }   &lt;br /&gt;  }&lt;br /&gt;  return(node);&lt;br /&gt; } &lt;br /&gt;&lt;br /&gt; public boolean isIdenticalTree(BinaryTree comparedTree) {&lt;br /&gt;  return (isIdenticalTree(root, comparedTree.root));&lt;br /&gt; }&lt;br /&gt;&lt;br /&gt; private boolean isIdenticalTree(TreeNode first, TreeNode second) {&lt;br /&gt;  if (first == null &amp;&amp; second == null) {&lt;br /&gt;   return true;&lt;br /&gt;  } else if (first != null &amp;&amp; second != null) {&lt;br /&gt;   return (&lt;br /&gt;    first.nodeValue == second.nodeValue &amp;&amp;&lt;br /&gt;    isIdenticalTree(first.left, second.left) &amp;&amp;&lt;br /&gt;    isIdenticalTree(first.right, second.right)&lt;br /&gt;   );&lt;br /&gt;  } else {&lt;br /&gt;   return false;&lt;br /&gt;  }&lt;br /&gt; } &lt;br /&gt; &lt;br /&gt; public int getSize() {&lt;br /&gt;  return(setSize(root));&lt;br /&gt; }&lt;br /&gt;&lt;br /&gt; private int setSize(TreeNode node) {&lt;br /&gt;  if (node == null) { &lt;br /&gt;   return 0;&lt;br /&gt;  } else {&lt;br /&gt;   return(setSize(node.left) + 1 + setSize(node.right));&lt;br /&gt;  }&lt;br /&gt; } &lt;br /&gt;&lt;br /&gt; public void printTreeTraversal() {&lt;br /&gt;  System.out.print("Inorder Traversal: ");&lt;br /&gt;  printInOrder(root);&lt;br /&gt;  System.out.print("\nPreorder Traversal: ");&lt;br /&gt;  printPreOrder(root);&lt;br /&gt;  System.out.print("\nPostorder Traversal: ");&lt;br /&gt;  printPostOrder(root);&lt;br /&gt;  System.out.println();&lt;br /&gt; }&lt;br /&gt;&lt;br /&gt;&lt;br /&gt; private void printInOrder(TreeNode node) {&lt;br /&gt;  if (node == null) {&lt;br /&gt;   return;  &lt;br /&gt;  }&lt;br /&gt;  printInOrder(node.left);&lt;br /&gt;  visitTreeNode(node);&lt;br /&gt;  printInOrder(node.right);&lt;br /&gt; } &lt;br /&gt;&lt;br /&gt; private void printPreOrder(TreeNode node) {&lt;br /&gt;  if (node == null) {&lt;br /&gt;   return;  &lt;br /&gt;  }&lt;br /&gt;  visitTreeNode(node);&lt;br /&gt;  printPreOrder(node.left);&lt;br /&gt;  printPreOrder(node.right);&lt;br /&gt; } &lt;br /&gt; &lt;br /&gt; private void printPostOrder(TreeNode node) {&lt;br /&gt;  if (node == null) {&lt;br /&gt;   return;  &lt;br /&gt;  }&lt;br /&gt;  printPostOrder(node.left);&lt;br /&gt;  printPostOrder(node.right);&lt;br /&gt;  visitTreeNode(node);&lt;br /&gt; } &lt;br /&gt;&lt;br /&gt; private void visitTreeNode(TreeNode node){&lt;br /&gt;  System.out.print(node.nodeValue + "  ");  &lt;br /&gt; }&lt;br /&gt; &lt;br /&gt; public int getMinValue() {&lt;br /&gt;  return (getMinValue(root));&lt;br /&gt; }&lt;br /&gt;&lt;br /&gt; private int getMinValue(TreeNode node) {&lt;br /&gt;  while (node.left != null) {&lt;br /&gt;   node = node.left;&lt;br /&gt;  }&lt;br /&gt;  return (node.nodeValue);&lt;br /&gt; } &lt;br /&gt; &lt;br /&gt;&lt;br /&gt; public int getMaxValue() {&lt;br /&gt;  return (getMaxValue(root));&lt;br /&gt; }&lt;br /&gt;&lt;br /&gt; private int getMaxValue(TreeNode node) {&lt;br /&gt;  while (node.right != null) {&lt;br /&gt;   node = node.right;&lt;br /&gt;  }&lt;br /&gt;  return (node.nodeValue);&lt;br /&gt; } &lt;br /&gt;&lt;br /&gt; public int getMaxDepth() {&lt;br /&gt;  int depth = getMaxDepth(root);&lt;br /&gt;  return ((depth &gt; 0) ? (depth - 1) : 0);&lt;br /&gt; }&lt;br /&gt;&lt;br /&gt; private int getMaxDepth(TreeNode node) {&lt;br /&gt;  if (node == null) {&lt;br /&gt;   return 0;&lt;br /&gt;  } else {&lt;br /&gt;   int leftDepth = getMaxDepth(node.left);&lt;br /&gt;   int rightDepth = getMaxDepth(node.right);&lt;br /&gt;   return (((leftDepth &gt; rightDepth) ? leftDepth : rightDepth) + 1);&lt;br /&gt;  }&lt;br /&gt; } &lt;br /&gt;&lt;br /&gt; public boolean containsData(int data) {&lt;br /&gt;  return(containsData(root, data));&lt;br /&gt; }&lt;br /&gt;&lt;br /&gt; private boolean containsData(TreeNode node, int data) {&lt;br /&gt;  if (node == null) {&lt;br /&gt;   return false;&lt;br /&gt;  } &lt;br /&gt;  if (data == node.nodeValue) {&lt;br /&gt;   return true;&lt;br /&gt;  } else if (data &lt; node.nodeValue) {&lt;br /&gt;   return(containsData(node.left, data));&lt;br /&gt;  } else {&lt;br /&gt;   return(containsData(node.right, data));&lt;br /&gt;  }&lt;br /&gt; } &lt;br /&gt; &lt;br /&gt; public int getRootValue(){&lt;br /&gt;  return root.nodeValue;&lt;br /&gt; }&lt;br /&gt; &lt;br /&gt; public boolean containsSumInPath(int total) {&lt;br /&gt;  return( containsSumInPath(root, total) );&lt;br /&gt; }&lt;br /&gt;&lt;br /&gt; private boolean containsSumInPath(TreeNode node, int total) {&lt;br /&gt;  if (node == null) {&lt;br /&gt;   return(total == 0);&lt;br /&gt;  } else {&lt;br /&gt;   int remainder = total - node.nodeValue;&lt;br /&gt;   if (containsSumInPath(node.left, remainder) || containsSumInPath(node.right, remainder)) {&lt;br /&gt;    addPaths( remainder, node.nodeValue, total);     &lt;br /&gt;   } &lt;br /&gt;   return(containsSumInPath(node.left, remainder) || containsSumInPath(node.right, remainder));&lt;br /&gt;  }&lt;br /&gt; } &lt;br /&gt;&lt;br /&gt; private ArrayList&lt;Integer&gt; path = new ArrayList&lt;Integer&gt;();&lt;br /&gt; &lt;br /&gt; private void addPaths(int remainder, int currentNodeValue, int total){&lt;br /&gt;  if (!path.contains(currentNodeValue)) {&lt;br /&gt;   path.add(currentNodeValue);&lt;br /&gt;  }&lt;br /&gt; }&lt;br /&gt; &lt;br /&gt; public ArrayList&lt;Integer&gt; getSumOfPath(){&lt;br /&gt;  Collections.reverse(path);&lt;br /&gt;  return path;&lt;br /&gt; }&lt;br /&gt; &lt;br /&gt; public static void main(String[] args) {&lt;br /&gt;  BinaryTree bTree1 = new BinaryTree();&lt;br /&gt;  BinaryTree bTree2 = new BinaryTree();&lt;br /&gt;&lt;br /&gt;  bTree1.constructBinaryTreeHardCoded();  &lt;br /&gt;  System.out.println("Size of the binary tree: " + bTree1.getSize());&lt;br /&gt;  System.out.println("Root value in the binary tree: " + bTree1.getRootValue());&lt;br /&gt;  System.out.println("Smallest value in the binary tree: " + bTree1.getMinValue());&lt;br /&gt;  System.out.println("Largest value in the binary tree: " + bTree1.getMaxValue());&lt;br /&gt;  System.out.println("Maximum depth of the binary tree: " + bTree1.getMaxDepth());&lt;br /&gt;  System.out.println("Contains node value 4: " + bTree1.containsData(4));&lt;br /&gt;  System.out.println("Path has sum of 30: " + bTree1.containsSumInPath(30) + " = " + bTree1.getSumOfPath());&lt;br /&gt;  bTree1.printTreeTraversal();&lt;br /&gt;&lt;br /&gt;  System.out.println();&lt;br /&gt;&lt;br /&gt;  bTree2.testHarness();&lt;br /&gt;  System.out.println("Size of the binary tree: " + bTree2.getSize());&lt;br /&gt;  System.out.println("Root value in the binary tree: " + bTree2.getRootValue());&lt;br /&gt;  System.out.println("Smallest value in the binary tree: " + bTree2.getMinValue());&lt;br /&gt;  System.out.println("Largest value in the binary tree: " + bTree2.getMaxValue());&lt;br /&gt;  System.out.println("Maximum depth of the binary tree: " + bTree2.getMaxDepth());&lt;br /&gt;  System.out.println("Contains node value 11: " + bTree2.containsData(11));&lt;br /&gt;  &lt;br /&gt;  Random rand = new Random();&lt;br /&gt;  int find = rand.nextInt( 30 ) + 1;&lt;br /&gt;  System.out.println("Path has sum of "+ find +": " + bTree2.containsSumInPath(find) + " = " + bTree2.getSumOfPath());&lt;br /&gt;  bTree2.printTreeTraversal();&lt;br /&gt;  &lt;br /&gt;  System.out.println("Are identical binary trees: " + bTree1.isIdenticalTree(bTree2));&lt;br /&gt;  &lt;br /&gt;  System.out.println("\nChanged elements in binary tree");&lt;br /&gt;  bTree2.constructBinaryTreeHardCoded();&lt;br /&gt;  System.out.println("Are identical binary trees: " + bTree1.isIdenticalTree(bTree2));&lt;br /&gt; }&lt;br /&gt;}&lt;/pre&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4844902456784005421-691209768079445225?l=nicholaskey.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://nicholaskey.blogspot.com/feeds/691209768079445225/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://nicholaskey.blogspot.com/2009/09/binary-tree-and-its-popular-methods.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4844902456784005421/posts/default/691209768079445225'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4844902456784005421/posts/default/691209768079445225'/><link rel='alternate' type='text/html' href='http://nicholaskey.blogspot.com/2009/09/binary-tree-and-its-popular-methods.html' title='Binary Tree and its popular methods'/><author><name>Nicholas Key</name><uri>http://www.blogger.com/profile/05768297019453812096</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='http://4.bp.blogspot.com/_OQU38yb-Uq0/SwL5VBlHCII/AAAAAAAAA6U/lXUy53mS7gQ/S220/hamster.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4844902456784005421.post-5314830805046353764</id><published>2009-09-13T11:00:00.007-07:00</published><updated>2009-09-16T23:52:45.723-07:00</updated><title type='text'>Kanye West doesn't like this blog :P</title><content type='html'>This interesting picture is generated from http://kanyelicio.us&lt;br /&gt;Simply append your desired URL after that domain to see the funny end result.&lt;br /&gt;For example http://kanyelicio.us/http://nicholaskey.blogspot.com :P&lt;br /&gt;&lt;br /&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://photos-f.ak.fbcdn.net/hphotos-ak-snc1/hs228.snc1/7526_134415714397_518084397_2548957_1511745_n.jpg"&gt;&lt;img style="display:block; margin:0px auto 10px; text-align:center;cursor:pointer; cursor:hand;width: 604px; height: 310px;" src="http://photos-f.ak.fbcdn.net/hphotos-ak-snc1/hs228.snc1/7526_134415714397_518084397_2548957_1511745_n.jpg" border="0" alt="" /&gt;&lt;/a&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4844902456784005421-5314830805046353764?l=nicholaskey.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://nicholaskey.blogspot.com/feeds/5314830805046353764/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://nicholaskey.blogspot.com/2009/09/dfg-n.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4844902456784005421/posts/default/5314830805046353764'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4844902456784005421/posts/default/5314830805046353764'/><link rel='alternate' type='text/html' href='http://nicholaskey.blogspot.com/2009/09/dfg-n.html' title='Kanye West doesn&apos;t like this blog :P'/><author><name>Nicholas Key</name><uri>http://www.blogger.com/profile/05768297019453812096</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='http://4.bp.blogspot.com/_OQU38yb-Uq0/SwL5VBlHCII/AAAAAAAAA6U/lXUy53mS7gQ/S220/hamster.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4844902456784005421.post-8728069238149898842</id><published>2009-09-12T12:44:00.009-07:00</published><updated>2009-10-14T17:21:04.261-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Country Codes'/><category scheme='http://www.blogger.com/atom/ns#' term='Java'/><category scheme='http://www.blogger.com/atom/ns#' term='General Knowledge'/><category scheme='http://www.blogger.com/atom/ns#' term='XSL'/><category scheme='http://www.blogger.com/atom/ns#' term='XML'/><category scheme='http://www.blogger.com/atom/ns#' term='ISO 3166-1-alpha-2'/><title type='text'>Scraping ISO 3166-1-alpha-2 country codes</title><content type='html'>I have written a simple XSL to scrape the ISO 2-letter country codes from the &lt;a href="http://www.iso.org/iso/country_codes/iso_3166_code_lists/english_country_names_and_code_elements.htm"&gt;ISO website&lt;/a&gt; First I copied the table that contains the country names and codes and then I constructed the XSL. This is how the XSL looks like:&lt;textarea name="code" class="java" cols="60" rows="1000"&gt;&lt;br /&gt;&lt;?xml version="1.0"?&gt;&lt;br /&gt;&lt;xsl:stylesheet version="1.0"&lt;br /&gt;xmlns:xsl="http://www.w3.org/1999/XSL/Transform"&gt;&lt;br /&gt;  &lt;xsl:template match="/"&gt;&lt;br /&gt;    &amp;lt;html&gt;&lt;br /&gt;      &amp;lt;body&gt;&lt;br /&gt;        &amp;lt;xsl:for-each select="table/tbody/tr"&gt;&lt;br /&gt;          &amp;lt;xsl:if test="string-length(td[last()]) = 11"&gt;&lt;br /&gt;            &amp;lt;xsl:value-of select="translate(normalize-space(td[last()]),'ABCDEFGHIJKLMNOPQRSTUVWXYZ','abcdefghijklmnopqrstuvwxyz')"/&gt;&lt;br/&gt;&lt;br /&gt;          &amp;lt;/xsl:if&gt;&lt;br /&gt;        &amp;lt;/xsl:for-each&gt;&lt;br /&gt;      &amp;lt;/body&gt;&lt;br /&gt;    &amp;lt;/html&gt;&lt;br /&gt;  &amp;lt;/xsl:template&gt;&lt;br /&gt;&amp;lt;/xsl:stylesheet&gt;&lt;/textarea&gt;&lt;span style="color:red"&gt;UPDATE:&lt;/span&gt;&lt;br /&gt;Please insert the breakline HTML element in the if block after the translate statement. Because without it, the country codes won't be displayed in separate lines. I have written another blog entry about scraping the codes. Please take a look &lt;a href="http://nicholaskey.blogspot.com/2009/10/detailed-explanation-of-using-xsl-to.html"&gt;here&lt;/a&gt;.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4844902456784005421-8728069238149898842?l=nicholaskey.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://nicholaskey.blogspot.com/feeds/8728069238149898842/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://nicholaskey.blogspot.com/2009/09/scraping-iso-3166-1-alpha-2-code.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4844902456784005421/posts/default/8728069238149898842'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4844902456784005421/posts/default/8728069238149898842'/><link rel='alternate' type='text/html' href='http://nicholaskey.blogspot.com/2009/09/scraping-iso-3166-1-alpha-2-code.html' title='Scraping ISO 3166-1-alpha-2 country codes'/><author><name>Nicholas Key</name><uri>http://www.blogger.com/profile/05768297019453812096</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='http://4.bp.blogspot.com/_OQU38yb-Uq0/SwL5VBlHCII/AAAAAAAAA6U/lXUy53mS7gQ/S220/hamster.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4844902456784005421.post-1751144082208545797</id><published>2009-09-11T16:52:00.007-07:00</published><updated>2009-09-12T16:09:56.149-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='URL package'/><category scheme='http://www.blogger.com/atom/ns#' term='Java'/><category scheme='http://www.blogger.com/atom/ns#' term='Creating Folders'/><category scheme='http://www.blogger.com/atom/ns#' term='File Manipulation'/><category scheme='http://www.blogger.com/atom/ns#' term='Remote Server'/><category scheme='http://www.blogger.com/atom/ns#' term='Algorithms'/><title type='text'>Grabbing Files from Remote Server</title><content type='html'>I have written a helpful method to grab files from remote server and save them into a local folder. This example works as follow:&lt;br /&gt;[1] The input file will be read line by line&lt;br /&gt;[2] The resource names will be appended to the URL of the remote server&lt;br /&gt;[3] Resources that are found in the remote server will be written to the local folder&lt;br /&gt;[4] Otherwise, show error messages if the resources are not found&lt;textarea name="code" class="java" cols="60" rows="1000"&gt;&lt;br /&gt;import java.io.BufferedInputStream;&lt;br /&gt;import java.io.BufferedOutputStream;&lt;br /&gt;import java.io.BufferedReader;&lt;br /&gt;import java.io.File;&lt;br /&gt;import java.io.FileNotFoundException;&lt;br /&gt;import java.io.FileOutputStream;&lt;br /&gt;import java.io.FileReader;&lt;br /&gt;import java.io.IOException;&lt;br /&gt;import java.net.MalformedURLException;&lt;br /&gt;import java.net.URL;&lt;br /&gt;&lt;br /&gt;public class FileDownloader {&lt;br /&gt;  private final static String templatePath = FileDownloader.class.getResource("").getPath().replaceAll("%20", " ");&lt;br /&gt;&lt;br /&gt;  private static final String folderStr = templatePath + "/pics";&lt;br /&gt;  &lt;br /&gt;  private static void readText() {&lt;br /&gt;    File folder = new File(folderStr);&lt;br /&gt;    if (!folder.exists()) {&lt;br /&gt;      folder.mkdir();&lt;br /&gt;    }&lt;br /&gt;    BufferedReader br;&lt;br /&gt;    FileReader fr;&lt;br /&gt;    String line;&lt;br /&gt;    try {&lt;br /&gt;      fr = new FileReader(YOUR_FILE_NAME);&lt;br /&gt;      br = new BufferedReader(fr);&lt;br /&gt;      while ((line = br.readLine()) != null) {&lt;br /&gt;        grabFile(line, folderStr);&lt;br /&gt;      }&lt;br /&gt;    } catch (FileNotFoundException e) {&lt;br /&gt;      System.err.println("File not found!");&lt;br /&gt;      e.printStackTrace();&lt;br /&gt;    }catch (IOException e) {&lt;br /&gt;      System.err.println("Error reading file");&lt;br /&gt;      e.printStackTrace();&lt;br /&gt;    }&lt;br /&gt;  }&lt;br /&gt;&lt;br /&gt;  private static void grabFile(String input, String folder){&lt;br /&gt;    byte[] bytes = new byte[4096];&lt;br /&gt;    BufferedInputStream in;&lt;br /&gt;    BufferedOutputStream out;&lt;br /&gt;    URL URLsource = null;&lt;br /&gt;    try {&lt;br /&gt;      URLsource = new URL(REMOTE_SERVER_URL + input.trim());&lt;br /&gt;      in = new BufferedInputStream (URLsource.openStream());&lt;br /&gt;      out = new BufferedOutputStream(new FileOutputStream( new File( folder + "/" + input.trim() )));&lt;br /&gt;      int pos = in.read( bytes );&lt;br /&gt;      while ( pos != -1 ){&lt;br /&gt;        out.write( bytes, 0, pos );&lt;br /&gt;        pos = in.read( bytes );&lt;br /&gt;      }&lt;br /&gt;      out.close();&lt;br /&gt;      System.out.println("Downloaded: " + input);&lt;br /&gt;    } catch (MalformedURLException e) {&lt;br /&gt;      e.printStackTrace();&lt;br /&gt;    } catch (IOException e) {&lt;br /&gt;      System.err.println("Fail to download: " + input);&lt;br /&gt;      e.printStackTrace();&lt;br /&gt;    } catch (InterruptedException e) {&lt;br /&gt;      e.printStackTrace();&lt;br /&gt;    }&lt;br /&gt;  }&lt;br /&gt;&lt;br /&gt;  public static void main(String[] args) {&lt;br /&gt;    readText();&lt;br /&gt;  }&lt;br /&gt;}&lt;/textarea&gt;Happy coding everyone :)&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4844902456784005421-1751144082208545797?l=nicholaskey.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://nicholaskey.blogspot.com/feeds/1751144082208545797/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://nicholaskey.blogspot.com/2009/09/grabbing-files-from-remote-server.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4844902456784005421/posts/default/1751144082208545797'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4844902456784005421/posts/default/1751144082208545797'/><link rel='alternate' type='text/html' href='http://nicholaskey.blogspot.com/2009/09/grabbing-files-from-remote-server.html' title='Grabbing Files from Remote Server'/><author><name>Nicholas Key</name><uri>http://www.blogger.com/profile/05768297019453812096</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='http://4.bp.blogspot.com/_OQU38yb-Uq0/SwL5VBlHCII/AAAAAAAAA6U/lXUy53mS7gQ/S220/hamster.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4844902456784005421.post-8102042110282998198</id><published>2009-09-08T11:32:00.009-07:00</published><updated>2011-08-03T06:28:12.223-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Java'/><category scheme='http://www.blogger.com/atom/ns#' term='Algorithms'/><category scheme='http://www.blogger.com/atom/ns#' term='Trivia'/><title type='text'>Replacing whitespace characters in a string</title><content type='html'>Here is an example of method overloading - same method name with different number of parameters. The complexity of this algorithm is O(n) because the input string is scanned character by character. &lt;br /&gt;&lt;br /&gt;But what if there is a input with a massive size? I would want to partition out the string into several portion depending on the size threshold which can be set in the method and the hash the partitioned texts into a hashmap. Threading is possible in this context because the texts will be processed synchronously instead of sequentially. &lt;pre&gt;&lt;br /&gt;public static StringBuffer removeSpace(String input){&lt;br /&gt;  return removeSpace(input, "%20");&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;public static StringBuffer removeSpace(String input, String fillerString){&lt;br /&gt;  StringBuffer sb = new StringBuffer();&lt;br /&gt;  int strLength = input.length();&lt;br /&gt;  int index = 0;&lt;br /&gt;  while(index != (strLength)){&lt;br /&gt;    if (input.charAt(index) != ' ') {&lt;br /&gt;      sb.append(input.charAt(index));&lt;br /&gt;    } else {&lt;br /&gt;      sb.append(fillerString);&lt;br /&gt;    }&lt;br /&gt;    index++;&lt;br /&gt;  }&lt;br /&gt;  return sb;&lt;br /&gt;}&lt;/pre&gt; You may test this code with this sample method calls: &lt;br /&gt;&lt;pre&gt;&lt;br /&gt;System.out.println(removeSpace("Hello World, I am Nicholas Key"));&lt;br /&gt;System.out.println(removeSpace("Hello World, I am Nicholas Key", "[SPACE]"));&lt;br /&gt;&lt;/pre&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4844902456784005421-8102042110282998198?l=nicholaskey.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://nicholaskey.blogspot.com/feeds/8102042110282998198/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://nicholaskey.blogspot.com/2009/09/replace-whitespace-characters-in-string.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4844902456784005421/posts/default/8102042110282998198'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4844902456784005421/posts/default/8102042110282998198'/><link rel='alternate' type='text/html' href='http://nicholaskey.blogspot.com/2009/09/replace-whitespace-characters-in-string.html' title='Replacing whitespace characters in a string'/><author><name>Nicholas Key</name><uri>http://www.blogger.com/profile/05768297019453812096</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='http://4.bp.blogspot.com/_OQU38yb-Uq0/SwL5VBlHCII/AAAAAAAAA6U/lXUy53mS7gQ/S220/hamster.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4844902456784005421.post-7328728469242142352</id><published>2009-09-08T11:32:00.003-07:00</published><updated>2011-08-03T06:30:12.158-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Java'/><category scheme='http://www.blogger.com/atom/ns#' term='Algorithms'/><category scheme='http://www.blogger.com/atom/ns#' term='Trivia'/><title type='text'>Usefulness of BigInteger</title><content type='html'>It's way much better than Integer, the primitive type; simply because we won't be restricted with arithmetic overflow issue. An example is in this method to compute factorial. &lt;pre&gt;&lt;br /&gt;public static BigInteger factorial(int n){&lt;br /&gt;  BigInteger result = BigInteger.ONE;&lt;br /&gt;  for (int count = 1; count &lt;= n; count++) {&lt;br /&gt;    result = result.multiply(BigInteger.valueOf(count));&lt;br /&gt;  }&lt;br /&gt;  return result;&lt;br /&gt;}&lt;/pre&gt;The precision is still well maintained even if you iterate through the first 38 numbers. Give it a try if you are not convinced :)&lt;br /&gt;&lt;span style="font-weight:bold;color:red"&gt;UPDATE:&lt;/span&gt; there is a fundamental flaw in this loop. In the previous code, I demonstrated for (int count = 1; count &lt; n; count++). It has changed to for (int count = 1; count &lt;span style="font-weight:bold;"&gt;&lt;=&lt;/span&gt; n; count++)&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4844902456784005421-7328728469242142352?l=nicholaskey.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://nicholaskey.blogspot.com/feeds/7328728469242142352/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://nicholaskey.blogspot.com/2009/09/usefulness-of-biginteger.html#comment-form' title='2 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4844902456784005421/posts/default/7328728469242142352'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4844902456784005421/posts/default/7328728469242142352'/><link rel='alternate' type='text/html' href='http://nicholaskey.blogspot.com/2009/09/usefulness-of-biginteger.html' title='Usefulness of BigInteger'/><author><name>Nicholas Key</name><uri>http://www.blogger.com/profile/05768297019453812096</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='http://4.bp.blogspot.com/_OQU38yb-Uq0/SwL5VBlHCII/AAAAAAAAA6U/lXUy53mS7gQ/S220/hamster.jpg'/></author><thr:total>2</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4844902456784005421.post-6812312114403319407</id><published>2009-09-07T13:27:00.009-07:00</published><updated>2011-08-03T06:28:54.385-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Java'/><category scheme='http://www.blogger.com/atom/ns#' term='Algorithms'/><category scheme='http://www.blogger.com/atom/ns#' term='Trivia'/><title type='text'>Numbers with commas</title><content type='html'>Here's a simple method to include commas after every third digit from the right:&lt;br /&gt;&lt;pre&gt;&lt;br /&gt;public class Utilities{&lt;br /&gt;  private static int startingPivot;&lt;br /&gt;  private static final int INDENT = 3;&lt;br /&gt;&lt;br /&gt;  public static StringBuffer decimalize(int input){&lt;br /&gt;    String conv = Integer.toString(input);&lt;br /&gt;    StringBuffer sb = new StringBuffer();&lt;br /&gt;&lt;br /&gt;    int commaIndex = conv.length() / INDENT ; &lt;br /&gt;    int strLength = conv.length();&lt;br /&gt;&lt;br /&gt;    startingPivot = (strLength) - (commaIndex * INDENT );&lt;br /&gt;    if (startingPivot == 0) {&lt;br /&gt;      startingPivot = INDENT ;&lt;br /&gt;    }&lt;br /&gt;&lt;br /&gt;    for (int index = 0; index &lt; strLength; index++) {&lt;br /&gt;      if (index == startingPivot) {&lt;br /&gt;        sb.append(",");&lt;br /&gt;        startingPivot = startingPivot + INDENT;&lt;br /&gt;      }&lt;br /&gt;      sb.append(conv.charAt(index));&lt;br /&gt;    }&lt;br /&gt;    return sb;&lt;br /&gt;  }&lt;br /&gt;}&lt;br /&gt;&lt;/pre&gt;You may try this code by making this method call&lt;br /&gt;&lt;pre&gt;&lt;br /&gt;System.out.println(Utilities.decimalize(1234567890));&lt;br /&gt;&lt;/pre&gt;and the output is &lt;span style="font-weight:bold;"&gt;1,234,567,890&lt;/span&gt; &lt;br /&gt;NEAT :D&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4844902456784005421-6812312114403319407?l=nicholaskey.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://nicholaskey.blogspot.com/feeds/6812312114403319407/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://nicholaskey.blogspot.com/2009/09/numbers-with-commas.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4844902456784005421/posts/default/6812312114403319407'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4844902456784005421/posts/default/6812312114403319407'/><link rel='alternate' type='text/html' href='http://nicholaskey.blogspot.com/2009/09/numbers-with-commas.html' title='Numbers with commas'/><author><name>Nicholas Key</name><uri>http://www.blogger.com/profile/05768297019453812096</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='http://4.bp.blogspot.com/_OQU38yb-Uq0/SwL5VBlHCII/AAAAAAAAA6U/lXUy53mS7gQ/S220/hamster.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4844902456784005421.post-6336214096201741690</id><published>2009-09-06T18:58:00.007-07:00</published><updated>2011-08-03T06:29:37.621-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Java'/><category scheme='http://www.blogger.com/atom/ns#' term='Algorithms'/><category scheme='http://www.blogger.com/atom/ns#' term='Trivia'/><title type='text'>String tokenizer by hand</title><content type='html'>I was thinking of implementing my custom "StringTokenizer" and here it is. The complexity is O(n) which means it depends on the size of the string. &lt;pre&gt;&lt;br /&gt;public static ArrayList&lt;StringBuffer&gt; tokenizer(String input){&lt;br /&gt;  ArrayList&lt;StringBuffer&gt; tokenizedStr = new ArrayList&lt;StringBuffer&gt;();&lt;br /&gt;  StringBuffer str = new StringBuffer();&lt;br /&gt;  int strLength = input.length();&lt;br /&gt;  int index = 0;&lt;br /&gt;  while (index &lt; strLength) {&lt;br /&gt;    char curr = input.charAt(index);&lt;br /&gt;    if (curr != ' '){&lt;br /&gt;      str.append(curr);&lt;br /&gt;    } else {&lt;br /&gt;      tokenizedStr.add(str);&lt;br /&gt;      str = new StringBuffer();&lt;br /&gt;    } &lt;br /&gt;    if ((index == strLength-1 ) &amp;&amp; (curr != ' ')) {&lt;br /&gt;      tokenizedStr.add(str);&lt;br /&gt;    }&lt;br /&gt;    index++;&lt;br /&gt;  }&lt;br /&gt;  return tokenizedStr;&lt;br /&gt;}&lt;br /&gt;&lt;/pre&gt;The most interesting part of this method if the condition to check if we have reached the last character of the string and to make sure if it is also not a whitespace character.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight:bold;color:red;"&gt;UPDATE:&lt;/span&gt;&lt;br /&gt;On a second thought, the algorithm in this method is not perfect because it will still retain inline whitespace characters. This is a much better way to tokenize the strings&lt;br /&gt;&lt;pre&gt;&lt;br /&gt;  while (index &lt; strLength) {&lt;br /&gt;    char curr = input.charAt(index);&lt;br /&gt;    if (curr != ' '){&lt;br /&gt;      str.append(curr);&lt;br /&gt;    } else {&lt;br /&gt;      if (str.length() != 0) {&lt;br /&gt;        tokenizedStr.add(str);&lt;br /&gt;      }&lt;br /&gt;      str = new StringBuffer();&lt;br /&gt;    } &lt;br /&gt;    if ((index == strLength-1 ) &amp;&amp; (curr != ' ')) {&lt;br /&gt;      tokenizedStr.add(str);&lt;br /&gt;    }&lt;br /&gt;    index++;&lt;br /&gt;  }&lt;br /&gt;&lt;/pre&gt;An example of solving this in recursion is at "&lt;a href="http://nicholaskey.blogspot.com/2009/09/tokenizing-string-recursively.html"&gt;Tokenizing String Recursively&lt;/a&gt;".&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4844902456784005421-6336214096201741690?l=nicholaskey.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://nicholaskey.blogspot.com/feeds/6336214096201741690/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://nicholaskey.blogspot.com/2009/09/string-tokenizer-by-hand.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4844902456784005421/posts/default/6336214096201741690'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4844902456784005421/posts/default/6336214096201741690'/><link rel='alternate' type='text/html' href='http://nicholaskey.blogspot.com/2009/09/string-tokenizer-by-hand.html' title='String tokenizer by hand'/><author><name>Nicholas Key</name><uri>http://www.blogger.com/profile/05768297019453812096</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='http://4.bp.blogspot.com/_OQU38yb-Uq0/SwL5VBlHCII/AAAAAAAAA6U/lXUy53mS7gQ/S220/hamster.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4844902456784005421.post-394415922269753324</id><published>2009-09-03T14:16:00.008-07:00</published><updated>2009-09-04T00:54:06.640-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Interface Builder'/><category scheme='http://www.blogger.com/atom/ns#' term='Useful Tools'/><category scheme='http://www.blogger.com/atom/ns#' term='Objective-C'/><category scheme='http://www.blogger.com/atom/ns#' term='iPhone App'/><category scheme='http://www.blogger.com/atom/ns#' term='XCODE'/><title type='text'>Screencast of my iPhone App</title><content type='html'>&lt;embed width="386" height="742" scale="showall" base="http://content.screencast.com/users/nicholaskeytholeong/folders/Jing/media/ff6819cb-7f5c-48c3-829a-c83e2d78a0d0/" allowfullscreen="true" flashvars="containerwidth=386&amp;amp;containerheight=742&amp;amp;thumb=http://content.screencast.com/users/nicholaskeytholeong/folders/Jing/media/ff6819cb-7f5c-48c3-829a-c83e2d78a0d0/FirstFrame.jpg&amp;amp;loaderstyle=jing&amp;amp;content=http://content.screencast.com/users/nicholaskeytholeong/folders/Jing/media/ff6819cb-7f5c-48c3-829a-c83e2d78a0d0/00000002.swf&amp;amp;blurover=false" allowscriptaccess="always" type="application/x-shockwave-flash" bgcolor="#FFFFFF" quality="high" src="http://content.screencast.com/users/nicholaskeytholeong/folders/Jing/media/ff6819cb-7f5c-48c3-829a-c83e2d78a0d0/jingswfplayer.swf" class="embeddedObject"&gt;&lt;/embed&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4844902456784005421-394415922269753324?l=nicholaskey.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://nicholaskey.blogspot.com/feeds/394415922269753324/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://nicholaskey.blogspot.com/2009/09/screencast-of-my-iphone-app.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4844902456784005421/posts/default/394415922269753324'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4844902456784005421/posts/default/394415922269753324'/><link rel='alternate' type='text/html' href='http://nicholaskey.blogspot.com/2009/09/screencast-of-my-iphone-app.html' title='Screencast of my iPhone App'/><author><name>Nicholas Key</name><uri>http://www.blogger.com/profile/05768297019453812096</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='http://4.bp.blogspot.com/_OQU38yb-Uq0/SwL5VBlHCII/AAAAAAAAA6U/lXUy53mS7gQ/S220/hamster.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4844902456784005421.post-932963875478512570</id><published>2009-09-01T17:20:00.009-07:00</published><updated>2011-08-03T06:31:01.212-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Recursion'/><category scheme='http://www.blogger.com/atom/ns#' term='Java'/><category scheme='http://www.blogger.com/atom/ns#' term='Useful Method'/><category scheme='http://www.blogger.com/atom/ns#' term='Fibonacci sequence'/><category scheme='http://www.blogger.com/atom/ns#' term='Trivia'/><title type='text'>Fibonacci Sequence</title><content type='html'>Here's an interesting usage of "memoization". According to Wikipedia, "&lt;span style="font-weight:bold;"&gt;&lt;span style="font-style:italic;"&gt;In computing, memoization is an optimization technique used primarily to speed up computer programs by having function calls avoid repeating the calculation of results for previously-processed inputs.&lt;/span&gt;&lt;/span&gt;".&lt;br /&gt;&lt;br /&gt;There is actually a drawback if we are using plain and simple recursion to compute the Fibonacci sequence using &lt;span style="font-weight:bold;"&gt;long&lt;/span&gt; datatype (because we are only limited to hold the first 48 Fibonacci numbers). Memoization helps to speed up the computation time by saving already computed values into memory (and we can use &lt;span style="font-weight:bold;"&gt;BigInteger&lt;/span&gt; datatype). An example implementation is as below:&lt;pre&gt;&lt;br /&gt;import java.math.BigInteger;&lt;br /&gt;import java.util.ArrayList;&lt;br /&gt;&lt;br /&gt;public class Fibonacci {&lt;br /&gt;&lt;br /&gt;  /** Variables for memoization **/&lt;br /&gt;  private static ArrayList&lt;BigInteger&gt; fibMemoized = new ArrayList&lt;BigInteger&gt;();&lt;br /&gt;  static {&lt;br /&gt;    fibMemoized.add(BigInteger.ZERO);&lt;br /&gt;    fibMemoized.add(BigInteger.ONE);&lt;br /&gt;  }&lt;br /&gt;&lt;br /&gt;  /** Memoized method to retrieve stored computed values **/&lt;br /&gt;  public static BigInteger fibonacci(int n) {&lt;br /&gt;    if (n &gt;= fibMemoized.size()) {&lt;br /&gt;      fibMemoized.add(n, fibonacci(n-1).add(fibonacci(n-2)));&lt;br /&gt;    }&lt;br /&gt;    return fibMemoized.get(n);&lt;br /&gt;  }&lt;br /&gt;&lt;br /&gt;  /** Old school recursion **/&lt;br /&gt;  public static long fib(int n) {&lt;br /&gt;    if (n &lt;= 1) return n;&lt;br /&gt;    else return fib(n-1) + fib(n-2);&lt;br /&gt;  }&lt;br /&gt;&lt;br /&gt;  /** Driver **/&lt;br /&gt;  public static void main(String[] args) {&lt;br /&gt;    int N = 45;&lt;br /&gt;    System.out.println(fibonacci(N));&lt;br /&gt;    System.out.println(fib(N));&lt;br /&gt;  }&lt;br /&gt;&lt;br /&gt;}&lt;/pre&gt;You may try copying the codes and run it locally to observe the difference in performance. The typical recursive method runs slower because it computes the Fibonnaci numbers from scratch many times. Unlike the memoized method, the ArrayList is used to store the previously computed values. While memoized method is more superior in terms of speed, we are actually sacrificing space in order to achieve greater speed.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4844902456784005421-932963875478512570?l=nicholaskey.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://nicholaskey.blogspot.com/feeds/932963875478512570/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://nicholaskey.blogspot.com/2009/09/my-first-iphone-app.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4844902456784005421/posts/default/932963875478512570'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4844902456784005421/posts/default/932963875478512570'/><link rel='alternate' type='text/html' href='http://nicholaskey.blogspot.com/2009/09/my-first-iphone-app.html' title='Fibonacci Sequence'/><author><name>Nicholas Key</name><uri>http://www.blogger.com/profile/05768297019453812096</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='http://4.bp.blogspot.com/_OQU38yb-Uq0/SwL5VBlHCII/AAAAAAAAA6U/lXUy53mS7gQ/S220/hamster.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4844902456784005421.post-3927061791471119671</id><published>2009-08-23T15:17:00.007-07:00</published><updated>2009-09-12T16:12:19.943-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='General Knowledge'/><category scheme='http://www.blogger.com/atom/ns#' term='Algorithms'/><title type='text'>Recursion vs iteration</title><content type='html'>Situations not to use recursion:&lt;br /&gt;- recomputation of values (fibonacci, factorial, GCD)&lt;br /&gt;- exhaust memory very quickly&lt;br /&gt;&lt;br /&gt;Advisable to use iteration or memoization, instead, if you are so keen and persistent to implement recursion.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4844902456784005421-3927061791471119671?l=nicholaskey.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://nicholaskey.blogspot.com/feeds/3927061791471119671/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://nicholaskey.blogspot.com/2009/08/recursion-vs-iteration.html#comment-form' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4844902456784005421/posts/default/3927061791471119671'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4844902456784005421/posts/default/3927061791471119671'/><link rel='alternate' type='text/html' href='http://nicholaskey.blogspot.com/2009/08/recursion-vs-iteration.html' title='Recursion vs iteration'/><author><name>Nicholas Key</name><uri>http://www.blogger.com/profile/05768297019453812096</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='http://4.bp.blogspot.com/_OQU38yb-Uq0/SwL5VBlHCII/AAAAAAAAA6U/lXUy53mS7gQ/S220/hamster.jpg'/></author><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4844902456784005421.post-7468647012172994054</id><published>2009-08-16T22:23:00.005-07:00</published><updated>2009-08-16T23:35:51.131-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Technology'/><category scheme='http://www.blogger.com/atom/ns#' term='General Knowledge'/><title type='text'>How to record the behavior of Internet users</title><content type='html'>I would like to discuss about this interesting topic which is sometimes wrongly perceived by many people as a menacing way practiced by some, if not many, Internet companies to invade one's privacy. I supposed there is a huge gap or the level of understanding that separates the consumers and the business people. &lt;br /&gt;&lt;br /&gt;The technological perspective that I am illustrating in this article is about implementing "click-tracking". For software engineers that really know and understand whatever they are implementing, the server has no control over the dynamic HTML pages once the bits and bytes are presented to the end-users. For now, do we agree unanimously at this stage? &lt;br /&gt;&lt;br /&gt;Great, thank you for agreeing to my thoughts! If so, I shall elaborate further about how "click-tracking" is implemented, especially at the anchor element &lt;span style="font-weight:bold;"&gt;&amp;lt;a&gt;&lt;/span&gt; in the HTML document. There are at least three significant ways to track the links the users are clicking. I am taking an online video company as an example.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight:bold;"&gt;[1] Redirecting users to different servlets&lt;/span&gt;&lt;br /&gt;This is the most common way to track user clicks. Imagine you are a registered user and while your session is still active:&lt;br /&gt;1. You do a keyword search&lt;br /&gt;2. You get a compiled list of result items in the result page &lt;br /&gt;(eg: http://www.example.com/search/?q=keyword_string&amp;pg=1)&lt;br /&gt;3. You click at the link you think is most relevant to you&lt;br /&gt;(eg: http://www.example.com/view/?videoID=12345678)&lt;br /&gt;4. You enjoy watching the selected video&lt;br /&gt;5. You demand for more videos and you reiterate step 1 again.&lt;br /&gt;But WAIT ... what laymen do not know is that while they are busy with their viewing activities, the servers are busy harvesting the clicks of the links. Technically speaking, the servlet that is related to the URL request will update the user database with the unique video IDs, which I think is the most important element. Many interesting things can take place from here and one of them is to count the number of viewed videos.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight:bold;"&gt;[2] AJAX&lt;/span&gt;&lt;br /&gt;Some of you might have this question popping in your mind "But what if the page is loaded dynamically using AJAX?". The implementation is actually quite similar to the one mentioned previously but with a slightly different flavor. By using AJAX, you can implement an asynchronous method to pass the video ID as an argument to the servlet using GET or POST method. The servlet will then take care of the rest without the user knowing whatever happens behind the scene (or their clicks are monitored).&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight:bold;"&gt;[3] Javascript / AJAX&lt;/span&gt;&lt;br /&gt;The other method to perform "click-track" is by using Javascript. This is used in the scenario where the search result page contains links that redirect users to the original sources and not within their domain. In other words, a totally different URL altogether. A GET or POST method is used to send the data back to the server.&lt;br /&gt;&lt;br /&gt;While the 3 suggested implementations seem similar, they are actually not the same. I hope you find this article a good read and insightful about performing "click-track".&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4844902456784005421-7468647012172994054?l=nicholaskey.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://nicholaskey.blogspot.com/feeds/7468647012172994054/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://nicholaskey.blogspot.com/2009/08/how-to-record-behavior-of-internet.html#comment-form' title='2 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4844902456784005421/posts/default/7468647012172994054'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4844902456784005421/posts/default/7468647012172994054'/><link rel='alternate' type='text/html' href='http://nicholaskey.blogspot.com/2009/08/how-to-record-behavior-of-internet.html' title='How to record the behavior of Internet users'/><author><name>Nicholas Key</name><uri>http://www.blogger.com/profile/05768297019453812096</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='http://4.bp.blogspot.com/_OQU38yb-Uq0/SwL5VBlHCII/AAAAAAAAA6U/lXUy53mS7gQ/S220/hamster.jpg'/></author><thr:total>2</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4844902456784005421.post-5012749935581820497</id><published>2009-08-10T23:53:00.007-07:00</published><updated>2009-09-13T13:06:44.955-07:00</updated><title type='text'>Binary Tree != B-tree</title><content type='html'>&lt;span style="color:red"&gt;NOTE TO SELF:&lt;/span&gt; Binary tree is not B-tree&lt;br /&gt;&lt;a href="http://en.wikipedia.org/wiki/B-tree"&gt;B-tree&lt;/a&gt; is commonly used in databases and filesystems.&lt;br /&gt;&lt;a href="http://en.wikipedia.org/wiki/Binary_tree"&gt;Binary tree&lt;/a&gt; is used for binary search.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4844902456784005421-5012749935581820497?l=nicholaskey.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://nicholaskey.blogspot.com/feeds/5012749935581820497/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://nicholaskey.blogspot.com/2009/08/binary-tree-b-tree.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4844902456784005421/posts/default/5012749935581820497'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4844902456784005421/posts/default/5012749935581820497'/><link rel='alternate' type='text/html' href='http://nicholaskey.blogspot.com/2009/08/binary-tree-b-tree.html' title='Binary Tree != B-tree'/><author><name>Nicholas Key</name><uri>http://www.blogger.com/profile/05768297019453812096</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='http://4.bp.blogspot.com/_OQU38yb-Uq0/SwL5VBlHCII/AAAAAAAAA6U/lXUy53mS7gQ/S220/hamster.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4844902456784005421.post-8397589565840034321</id><published>2009-08-03T19:19:00.005-07:00</published><updated>2009-09-12T16:13:17.712-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Project'/><category scheme='http://www.blogger.com/atom/ns#' term='I18N'/><category scheme='http://www.blogger.com/atom/ns#' term='Internationalization'/><category scheme='http://www.blogger.com/atom/ns#' term='Innovation'/><title type='text'>My pet project web-based music jukebox (part 2)</title><content type='html'>I have added a major feature in my web application to internationalize the page content. Hope you enjoy watching this video :)&lt;br /&gt;&lt;br /&gt;&lt;object width="560" height="340"&gt;&lt;param name="movie" value="http://www.youtube.com/v/1ztvU4AaeH0&amp;hl=en&amp;fs=1&amp;"&gt;&lt;/param&gt;&lt;param name="allowFullScreen" value="true"&gt;&lt;/param&gt;&lt;param name="allowscriptaccess" value="always"&gt;&lt;/param&gt;&lt;embed src="http://www.youtube.com/v/1ztvU4AaeH0&amp;hl=en&amp;fs=1&amp;" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="560" height="340"&gt;&lt;/embed&gt;&lt;/object&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4844902456784005421-8397589565840034321?l=nicholaskey.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://nicholaskey.blogspot.com/feeds/8397589565840034321/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://nicholaskey.blogspot.com/2009/08/my-pet-project-web-based-music-jukebox.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4844902456784005421/posts/default/8397589565840034321'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4844902456784005421/posts/default/8397589565840034321'/><link rel='alternate' type='text/html' href='http://nicholaskey.blogspot.com/2009/08/my-pet-project-web-based-music-jukebox.html' title='My pet project web-based music jukebox (part 2)'/><author><name>Nicholas Key</name><uri>http://www.blogger.com/profile/05768297019453812096</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='http://4.bp.blogspot.com/_OQU38yb-Uq0/SwL5VBlHCII/AAAAAAAAA6U/lXUy53mS7gQ/S220/hamster.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4844902456784005421.post-4100223500441913223</id><published>2009-07-29T23:55:00.009-07:00</published><updated>2011-08-03T06:31:53.400-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Java'/><category scheme='http://www.blogger.com/atom/ns#' term='Useful Method'/><category scheme='http://www.blogger.com/atom/ns#' term='Algorithms'/><title type='text'>Sorting a vector of objects using Comparator</title><content type='html'>Here is something really cool about sorting a Vector of objects. At least it is appealing to me. Let say we have a vector of "Students" objects and we are interested to sort the objects using one of its private fields, say, "StudentID" which is of data type Integer. &lt;br /&gt;&lt;br /&gt;The code is as follow:&lt;pre&gt;&lt;br /&gt;public static void anyMethod(){&lt;br /&gt;  try {&lt;br /&gt;    Collections.sort(yourVectorThatContainsObjects, ComparatorName);&lt;br /&gt;  } catch (Exception ex) {}&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;public static Comparator&amp;lt;Object&gt; ComparatorName = new Comparator&amp;lt;Object&gt;() {&lt;br /&gt;  public int compare(Object resultItem1, Object resultItem2) {&lt;br /&gt;    Integer id1 = ((Students)resultItem1).StudentID;&lt;br /&gt;    Integer id2 = ((Students)resultItem2).StudentID;&lt;br /&gt;    return id2.compareTo(id1);&lt;br /&gt;  }&lt;br /&gt;};&lt;br /&gt;&lt;/pre&gt;The result of this sort is in descending order, eg largest to smallest. However there is a simple trick to sort it in an ascending order. Simply use "&lt;span style="font-weight:bold;"&gt;return id1.compareTo(id2);&lt;/span&gt;" It works for me. I hope it works for you too. Otherwise, please feel free to leave a comment so that I can investigate my code :)&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4844902456784005421-4100223500441913223?l=nicholaskey.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://nicholaskey.blogspot.com/feeds/4100223500441913223/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://nicholaskey.blogspot.com/2009/07/sorting-vector-of-objects-using.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4844902456784005421/posts/default/4100223500441913223'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4844902456784005421/posts/default/4100223500441913223'/><link rel='alternate' type='text/html' href='http://nicholaskey.blogspot.com/2009/07/sorting-vector-of-objects-using.html' title='Sorting a vector of objects using Comparator'/><author><name>Nicholas Key</name><uri>http://www.blogger.com/profile/05768297019453812096</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='http://4.bp.blogspot.com/_OQU38yb-Uq0/SwL5VBlHCII/AAAAAAAAA6U/lXUy53mS7gQ/S220/hamster.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4844902456784005421.post-53035853980526639</id><published>2009-07-27T23:53:00.005-07:00</published><updated>2009-09-12T16:13:59.278-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Java'/><category scheme='http://www.blogger.com/atom/ns#' term='Project'/><category scheme='http://www.blogger.com/atom/ns#' term='jQuery'/><category scheme='http://www.blogger.com/atom/ns#' term='Innovation'/><title type='text'>My pet project</title><content type='html'>This is a brief introduction of my pet project. I hope you find this interesting. I am utilizing Java, jQuery and YouTube API to develop the entire web application. Here is the video.&lt;br /&gt;&lt;br /&gt;&lt;object width="560" height="340"&gt;&lt;param name="movie" value="http://www.youtube.com/v/g8-_d8BXRMM&amp;hl=en&amp;fs=1&amp;"&gt;&lt;/param&gt;&lt;param name="allowFullScreen" value="true"&gt;&lt;/param&gt;&lt;param name="allowscriptaccess" value="always"&gt;&lt;/param&gt;&lt;embed src="http://www.youtube.com/v/g8-_d8BXRMM&amp;hl=en&amp;fs=1&amp;" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="560" height="340"&gt;&lt;/embed&gt;&lt;/object&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4844902456784005421-53035853980526639?l=nicholaskey.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://nicholaskey.blogspot.com/feeds/53035853980526639/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://nicholaskey.blogspot.com/2009/07/my-pet-project.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4844902456784005421/posts/default/53035853980526639'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4844902456784005421/posts/default/53035853980526639'/><link rel='alternate' type='text/html' href='http://nicholaskey.blogspot.com/2009/07/my-pet-project.html' title='My pet project'/><author><name>Nicholas Key</name><uri>http://www.blogger.com/profile/05768297019453812096</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='http://4.bp.blogspot.com/_OQU38yb-Uq0/SwL5VBlHCII/AAAAAAAAA6U/lXUy53mS7gQ/S220/hamster.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4844902456784005421.post-4539687316106608042</id><published>2009-07-22T11:50:00.001-07:00</published><updated>2009-09-12T16:14:37.680-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Interesting Ideas'/><title type='text'>An insightful presentation about Social Media</title><content type='html'>&lt;object style="margin:0px" width="425" height="355"&gt;&lt;param name="movie" value="http://static.slidesharecdn.com/swf/ssplayer2.swf?doc=wtfissocialmedia5-090716070117-phpapp01&amp;stripped_title=what-the-fk-is-social-media-one-year-later" /&gt;&lt;param name="allowFullScreen" value="true"/&gt;&lt;param name="allowScriptAccess" value="always"/&gt;&lt;embed src="http://static.slidesharecdn.com/swf/ssplayer2.swf?doc=wtfissocialmedia5-090716070117-phpapp01&amp;stripped_title=what-the-fk-is-social-media-one-year-later" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="425" height="355"&gt;&lt;/embed&gt;&lt;/object&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4844902456784005421-4539687316106608042?l=nicholaskey.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://nicholaskey.blogspot.com/feeds/4539687316106608042/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://nicholaskey.blogspot.com/2009/07/insightful-presentation-about-social.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4844902456784005421/posts/default/4539687316106608042'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4844902456784005421/posts/default/4539687316106608042'/><link rel='alternate' type='text/html' href='http://nicholaskey.blogspot.com/2009/07/insightful-presentation-about-social.html' title='An insightful presentation about Social Media'/><author><name>Nicholas Key</name><uri>http://www.blogger.com/profile/05768297019453812096</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='http://4.bp.blogspot.com/_OQU38yb-Uq0/SwL5VBlHCII/AAAAAAAAA6U/lXUy53mS7gQ/S220/hamster.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4844902456784005421.post-6581951431200902208</id><published>2009-07-03T22:52:00.001-07:00</published><updated>2011-08-03T06:32:35.241-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Recursion'/><category scheme='http://www.blogger.com/atom/ns#' term='Java'/><category scheme='http://www.blogger.com/atom/ns#' term='GCD'/><title type='text'>Greatest Common Divisor (Recursion)</title><content type='html'>Here's a sample solution to solve the GCD recursively.&lt;pre&gt;&lt;br /&gt; public long GCD(long numberA, long numberB) {&lt;br /&gt;  if (numberB==0) &lt;br /&gt;   return numberA;&lt;br /&gt;  else&lt;br /&gt;   return GCD(numberB, numberA % numberB);&lt;br /&gt; } &lt;br /&gt;&lt;/pre&gt;&lt;span style="font-weight:bold;color:red;"&gt;Update:&lt;/span&gt; The code is also available in Python in &lt;a href="http://nicholaskey.blogspot.com/2009/10/my-java-codes-in-python-part-2_28.html"&gt;this entry&lt;/a&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4844902456784005421-6581951431200902208?l=nicholaskey.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://nicholaskey.blogspot.com/feeds/6581951431200902208/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://nicholaskey.blogspot.com/2009/07/greatest-common-divisor-recursion.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4844902456784005421/posts/default/6581951431200902208'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4844902456784005421/posts/default/6581951431200902208'/><link rel='alternate' type='text/html' href='http://nicholaskey.blogspot.com/2009/07/greatest-common-divisor-recursion.html' title='Greatest Common Divisor (Recursion)'/><author><name>Nicholas Key</name><uri>http://www.blogger.com/profile/05768297019453812096</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='http://4.bp.blogspot.com/_OQU38yb-Uq0/SwL5VBlHCII/AAAAAAAAA6U/lXUy53mS7gQ/S220/hamster.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4844902456784005421.post-551076057785859158</id><published>2009-06-12T17:52:00.001-07:00</published><updated>2009-09-12T16:15:01.372-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Interesting Ideas'/><title type='text'>The Myth of the Genius Programmer</title><content type='html'>This is a video recorded at Google I/O 2009. It's very informative and enlightening :) Basically the presenters were talking about being ready to accept failures and criticisms and also admit mistakes. Failing at different things is good but failing at the same thing over and over again means that you are not learning.&lt;br /&gt;&lt;object width="425" height="344"&gt;&lt;param name="movie" value="http://www.youtube.com/v/0SARbwvhupQ&amp;rel=0&amp;color1=0xb1b1b1&amp;color2=0xcfcfcf&amp;hl=en&amp;feature=player_embedded&amp;fs=1"&gt;&lt;/param&gt;&lt;param name="allowFullScreen" value="true"&gt;&lt;/param&gt;&lt;param name="allowScriptAccess" value="always"&gt;&lt;/param&gt;&lt;embed src="http://www.youtube.com/v/0SARbwvhupQ&amp;rel=0&amp;color1=0xb1b1b1&amp;color2=0xcfcfcf&amp;hl=en&amp;feature=player_embedded&amp;fs=1" type="application/x-shockwave-flash" allowfullscreen="true" allowScriptAccess="always" width="425" height="344"&gt;&lt;/embed&gt;&lt;/object&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4844902456784005421-551076057785859158?l=nicholaskey.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://nicholaskey.blogspot.com/feeds/551076057785859158/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://nicholaskey.blogspot.com/2009/06/myth-of-genius-programmer.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4844902456784005421/posts/default/551076057785859158'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4844902456784005421/posts/default/551076057785859158'/><link rel='alternate' type='text/html' href='http://nicholaskey.blogspot.com/2009/06/myth-of-genius-programmer.html' title='The Myth of the Genius Programmer'/><author><name>Nicholas Key</name><uri>http://www.blogger.com/profile/05768297019453812096</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='http://4.bp.blogspot.com/_OQU38yb-Uq0/SwL5VBlHCII/AAAAAAAAA6U/lXUy53mS7gQ/S220/hamster.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4844902456784005421.post-388961782198990601</id><published>2009-06-11T15:58:00.009-07:00</published><updated>2009-06-14T00:57:47.474-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Java'/><category scheme='http://www.blogger.com/atom/ns#' term='StringTemplate'/><category scheme='http://www.blogger.com/atom/ns#' term='Useful Tools'/><category scheme='http://www.blogger.com/atom/ns#' term='Tomcat Apache'/><title type='text'>A simple example with StringTemplate</title><content type='html'>I have always wanted to write this article but often find myself preoccupied with many other things. Please spend 20 minutes of your day to read this article. It is a food for thought in my opinion and the main audience are Java developers developing web applications using Eclipse together with Apache Tomcat.&lt;br /&gt;&lt;br /&gt;I would like to introduce a very powerful and convenient tool to generate HTML pages using StringTemplate. This tutorial assumes that the readers are well versed with writing servlets, configuring web server and Java programming. The main intention and focus of this article is to expose ourselves to the power of this template engine using Apache Tomcat web server; not Jetty, not Resin, nor JBOSS. I hope you find this blog entry useful although I will not go in depth with the nitty gritty of the details.&lt;br /&gt;&lt;br /&gt;A short history of StringTemplate: this tool is written by Terence Parr, my former Computer Science professor at University of San Francisco. It is a useful tool to generate HTML pages dynamically and enforces a distinct and clear separation between view and model in the MVC model.&lt;br /&gt;&lt;br /&gt;Tools that I use: Eclipse 3.4.0, Apache Tomcat 6.0 and of course the two important jar files that you need to download from the &lt;a href="http://www.stringtemplate.org/download/stringtemplate-3.2.tar.gz"&gt;StrngTemplate official website&lt;/a&gt;. They are &lt;span style="font-weight:bold;"&gt;antlr-2.7.7.jar&lt;/span&gt; and &lt;span style="font-weight:bold;"&gt;stringtemplate.jar&lt;/span&gt;. Unpack the compressed file and copy the two jar files into &lt;span style="font-weight:bold;"&gt;WebContent/WEB-INF/lib&lt;/span&gt; folder of your project in the Eclipse IDE.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight:bold;"&gt;DISCLAIMER:&lt;/span&gt; the codes shown below are adapted from Terence Parr's sample implementation at his &lt;a href="http://www.cs.usfca.edu/~parrt/course/601/lectures/stringtemplate.html"&gt;website&lt;/a&gt;.&lt;br /&gt;&lt;br /&gt;Now let us get into the meaty part of this article by introducing the servlet dispatcher. Imagine the job of a postman sending letters to different destinations. However in our context, my servlet dispatcher is actually dispatching the users' requests to the appropriate servlets. I will name this class FrontendServletDispatcher and a sample of implementation is as below:&lt;textarea name="code" class="java" cols="60" rows="1000"&gt;&lt;br /&gt;  package com.UI;&lt;br /&gt;  import java.io.IOException;&lt;br /&gt;  import java.util.Enumeration;&lt;br /&gt;  import javax.servlet.ServletException;&lt;br /&gt;  import javax.servlet.http.HttpServlet;&lt;br /&gt;  import javax.servlet.http.HttpServletRequest;&lt;br /&gt;  import javax.servlet.http.HttpServletResponse;&lt;br /&gt;  import com.pages.InvalidPage;&lt;br /&gt;  import com.pages.LandingPage;&lt;br /&gt;  import com.pages.LoginPage;&lt;br /&gt;  import com.pages.Page;&lt;br /&gt;&lt;br /&gt;  /**&lt;br /&gt;   * Servlet implementation class FrontendServletDispatcher&lt;br /&gt;   */&lt;br /&gt;  public class FrontendServletDispatcher extends HttpServlet {&lt;br /&gt;    private static final long serialVersionUID = 1L;&lt;br /&gt;    private static String[] SERVLET_NAMES = {"", "login"};&lt;br /&gt;&lt;br /&gt;    public FrontendServletDispatcher() {&lt;br /&gt;      super();&lt;br /&gt;    }&lt;br /&gt;&lt;br /&gt;    protected void doGet(HttpServletRequest request, HttpServletResponse response) &lt;br /&gt;      throws ServletException, IOException {&lt;br /&gt;      doRequest(request, response);&lt;br /&gt;    }&lt;br /&gt;&lt;br /&gt;    private void doRequest(HttpServletRequest request, HttpServletResponse response) &lt;br /&gt;      throws ServletException, IOException {&lt;br /&gt;      Page pageType = null;&lt;br /&gt;      int servletName = -1;&lt;br /&gt;      String servletPath = request.getServletPath();&lt;br /&gt;      if (servletPath != null) {&lt;br /&gt;        if (servletPath.startsWith("/")) {&lt;br /&gt;          servletPath = servletPath.substring(1);&lt;br /&gt;          for (int i=0; i&amp;lt;SERVLET_NAMES.length; i++) {&lt;br /&gt;            if (servletPath.equalsIgnoreCase(SERVLET_NAMES[i]))&lt;br /&gt;              servletName = i;&lt;br /&gt;          }&lt;br /&gt;        }&lt;br /&gt;      }&lt;br /&gt;      switch(servletName){&lt;br /&gt;        case 0:&lt;br /&gt;          pageType = new LandingPage();&lt;br /&gt;          generateContent(pageType, request, response);&lt;br /&gt;          System.out.println("Landing Page");&lt;br /&gt;          break;&lt;br /&gt;&lt;br /&gt;        case 1:&lt;br /&gt;          pageType = new LoginPage();&lt;br /&gt;          generateContent(pageType, request, response);&lt;br /&gt;          System.out.println("Login Page");&lt;br /&gt;          break;&lt;br /&gt;&lt;br /&gt;        default:&lt;br /&gt;          pageType = new InvalidPage();&lt;br /&gt;          generateContent(pageType, request, response); &lt;br /&gt;          System.out.println("Invalid Page");&lt;br /&gt;          break;&lt;br /&gt;      }&lt;br /&gt;    }&lt;br /&gt;&lt;br /&gt;    private void generateContent(Page pageType, HttpServletRequest request, HttpServletResponse response) &lt;br /&gt;      throws IOException {&lt;br /&gt;      pageType.request = request;&lt;br /&gt;      pageType.response = response;&lt;br /&gt;      pageType.generate();&lt;br /&gt;    }&lt;br /&gt;}&lt;br /&gt;&lt;/textarea&gt;As you may notice in the implementation of FrontendServletDispatcher, there is a class called InvalidPage that subclasses Page. I wrote that class as a way to prevent users from going into illegal servlet paths. At least the users are informed that the path they are trying to go is not available. Details of other classes that subclass Page are followed after the demonstration of web.xml. This is a file you cannot ignore when you are developing web application with Tomcat Apache.&lt;textarea name="code" class="java" cols="60" rows="1000"&gt;&lt;br /&gt;&lt;?xml version="1.0" encoding="UTF-8"?&gt;&lt;br /&gt;&lt;web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" id="WebApp_ID" version="2.5"&gt;&lt;br /&gt;  &lt;display-name&gt;tutorial&lt;/display-name&gt;&lt;br /&gt;  &lt;servlet&gt;&lt;br /&gt;    &lt;description&gt;&lt;/description&gt;&lt;br /&gt;    &lt;display-name&gt;FrontendServletDispatcher&lt;/display-name&gt;&lt;br /&gt;    &lt;servlet-name&gt;FrontendServletDispatcher&lt;/servlet-name&gt;&lt;br /&gt;    &lt;servlet-class&gt;com.UI.FrontendServletDispatcher&lt;/servlet-class&gt;&lt;br /&gt;  &lt;/servlet&gt;&lt;br /&gt;  &lt;servlet-mapping&gt;&lt;br /&gt;    &lt;servlet-name&gt;FrontendServletDispatcher&lt;/servlet-name&gt;&lt;br /&gt;    &lt;url-pattern&gt;/&lt;/url-pattern&gt;&lt;br /&gt;    &lt;url-pattern&gt;/login&lt;/url-pattern&gt;&lt;br /&gt;  &lt;/servlet-mapping&gt;&lt;br /&gt;&lt;/web-app&gt;&lt;br /&gt;&lt;/textarea&gt;After that, I create a folder called "templates" in the com.pages package. This is where all the st files are located. The next thing to focus is the Page class and the subclasses (LandingPage, LoginPage and InvalidPage). The code shown below demonstrates to you the implementation of the super class Page and the introduction of StringTemplate and StringTemplateGroup.&lt;textarea name="code" class="java" cols="60" rows="1000"&gt;&lt;br /&gt;  package com.pages;&lt;br /&gt;  import java.io.IOException;&lt;br /&gt;  import java.io.PrintWriter;&lt;br /&gt;  import javax.servlet.http.HttpServletRequest;&lt;br /&gt;  import javax.servlet.http.HttpServletResponse;&lt;br /&gt;  import org.antlr.stringtemplate.StringTemplate;&lt;br /&gt;  import org.antlr.stringtemplate.StringTemplateGroup;&lt;br /&gt;&lt;br /&gt;  public class Page {&lt;br /&gt;    public HttpServletRequest request;&lt;br /&gt;    public HttpServletResponse response;&lt;br /&gt;    PrintWriter out;&lt;br /&gt;    &lt;br /&gt;    private final static String templatePath = &lt;br /&gt;      Page.class.getResource("").getPath().replaceAll("%20", " ") + "/templates";&lt;br /&gt;    &lt;br /&gt;    static StringTemplateGroup templates = &lt;br /&gt;      new StringTemplateGroup("templates", templatePath);&lt;br /&gt;&lt;br /&gt;    static {&lt;br /&gt;      templates.setRefreshInterval(0); // don't cache templates&lt;br /&gt;    }&lt;br /&gt;&lt;br /&gt;    public void generate() throws IOException {&lt;br /&gt;      out = response.getWriter();&lt;br /&gt;      StringTemplate pageST = templates.getInstanceOf("templateLayout");&lt;br /&gt;      StringTemplate bodyST = body();&lt;br /&gt;      pageST.setAttribute("body", bodyST);&lt;br /&gt;      pageST.setAttribute("title", getTitle());&lt;br /&gt;      out.print(pageST);&lt;br /&gt;      out.close();&lt;br /&gt;    }&lt;br /&gt;&lt;br /&gt;    public StringTemplate body() { return null; }&lt;br /&gt;&lt;br /&gt;    public String getTitle() { return null; }&lt;br /&gt;}&lt;br /&gt;&lt;/textarea&gt;Page class gets an instance of "templateLayout" from the folder "template". "templateLayout" serves as a skeletal or a building block of dynamic content in a web page. I include all four necessary st files for our reference in this discussion. The first st file is called "templateLayout.st", followed by "landingPage.st", "loginPage.st" and "invalidPage.st"&lt;textarea name="code" class="java" cols="60" rows="1000"&gt;&lt;br /&gt;&lt;!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"&lt;br /&gt;   "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"&gt;&lt;br /&gt;&amp;lt;html&gt;&lt;br /&gt;&amp;lt;head&gt;&lt;br /&gt;&amp;lt;title&gt;$title$&amp;lt;/title&gt;&lt;br /&gt;&amp;lt;/head&gt;&lt;br /&gt;&amp;lt;body&gt;&lt;br /&gt;&lt;br /&gt;$body$&lt;br /&gt;&lt;br /&gt;&amp;lt;/body&gt;&lt;br /&gt;&amp;lt;/html&gt;&lt;br /&gt;&lt;/textarea&gt;&lt;textarea name="code" class="html" cols="60" rows="1000"&gt;&lt;br /&gt;This is a landing page&lt;br/&gt;&lt;br /&gt;&lt;a href="login"&gt;login&lt;/a&gt;&lt;br /&gt;&lt;/textarea&gt;&lt;textarea name="code" class="html" cols="60" rows="1000"&gt;&lt;br /&gt;This is a LOGIN page&lt;br/&gt;&lt;br /&gt;&lt;form action="" method="post"&gt;&lt;br /&gt;  &lt;input type="text" name="username" size="20"/&gt;&lt;br /&gt;  &lt;input type="submit" value="Submit"/&gt;&lt;br /&gt;&lt;/form&gt;&lt;br /&gt;&lt;/textarea&gt;&lt;textarea name="code" class="html" cols="60" rows="1000"&gt;&lt;br /&gt;Missing resource or invalid URL&lt;br/&gt;&lt;br /&gt;&lt;a href="login"&gt;login&lt;/a&gt;&lt;br /&gt;&lt;/textarea&gt;Last but not least, here are the implementations of LandingPage, LoginPage and InvalidPage classes.&lt;textarea name="code" class="java" cols="60" rows="1000"&gt;&lt;br /&gt;  package com.pages;&lt;br /&gt;  import org.antlr.stringtemplate.StringTemplate;&lt;br /&gt;  &lt;br /&gt;  public class LandingPage extends Page{&lt;br /&gt;    public StringTemplate body() {&lt;br /&gt;      StringTemplate bodyST = templates.getInstanceOf("landingPage");&lt;br /&gt;      return bodyST;&lt;br /&gt;    }&lt;br /&gt;&lt;br /&gt;    public String getTitle() { return "Landing Page"; }&lt;br /&gt;  }&lt;br /&gt;&lt;/textarea&gt;&lt;textarea name="code" class="java" cols="60" rows="1000"&gt;&lt;br /&gt;  package com.pages;&lt;br /&gt;  import org.antlr.stringtemplate.StringTemplate;&lt;br /&gt;  &lt;br /&gt;  public class LoginPage extends Page{&lt;br /&gt;    public StringTemplate body() {&lt;br /&gt;      StringTemplate bodyST = templates.getInstanceOf("loginPage");&lt;br /&gt;      return bodyST;&lt;br /&gt;    }&lt;br /&gt;&lt;br /&gt;    public String getTitle() { return "Login Page"; }&lt;br /&gt;  }&lt;br /&gt;&lt;/textarea&gt;&lt;textarea name="code" class="java" cols="60" rows="1000"&gt;&lt;br /&gt;  package com.pages;&lt;br /&gt;  import org.antlr.stringtemplate.StringTemplate;&lt;br /&gt;&lt;br /&gt;  public class InvalidPage extends Page{&lt;br /&gt;    public StringTemplate body() {&lt;br /&gt;      StringTemplate bodyST = templates.getInstanceOf("invalidPage");&lt;br /&gt;      return bodyST;&lt;br /&gt;    }&lt;br /&gt;&lt;br /&gt;    public String getTitle() { return "Invalid Page"; }&lt;br /&gt;  }&lt;br /&gt;&lt;/textarea&gt;For a start, you may try changing the string of the titles. You do not actually need to restart the server as the changes will take effect immediately, somewhat similar to what we know as hot-deploy. I hope you have fun trying this out and please feel free to drop any comments that further improves this article :)&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4844902456784005421-388961782198990601?l=nicholaskey.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://nicholaskey.blogspot.com/feeds/388961782198990601/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://nicholaskey.blogspot.com/2009/06/dynamic-web-application-development.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4844902456784005421/posts/default/388961782198990601'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4844902456784005421/posts/default/388961782198990601'/><link rel='alternate' type='text/html' href='http://nicholaskey.blogspot.com/2009/06/dynamic-web-application-development.html' title='A simple example with StringTemplate'/><author><name>Nicholas Key</name><uri>http://www.blogger.com/profile/05768297019453812096</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='http://4.bp.blogspot.com/_OQU38yb-Uq0/SwL5VBlHCII/AAAAAAAAA6U/lXUy53mS7gQ/S220/hamster.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4844902456784005421.post-7509694194783665740</id><published>2009-06-09T00:06:00.009-07:00</published><updated>2009-06-09T00:46:35.547-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Tomcat Apache'/><category scheme='http://www.blogger.com/atom/ns#' term='Configuration Files'/><category scheme='http://www.blogger.com/atom/ns#' term='Deploying Web Application'/><title type='text'>localhost:8080 and not localhost:8080/projectname</title><content type='html'>Typical scenario: &lt;br /&gt;[1] You are developing a dynamic web application using Eclipse in Java with project name, say "ServletTutorial".&lt;br /&gt;[2] You have configured your web.xml in the WEB-INF folder.&lt;br /&gt;[3] Everything looks fine when you are testing your web application within Eclipse and with the URL localhost:8080/ServletTutorial&lt;br /&gt;&lt;br /&gt;You feel happy BUT ... you are not that happy and not completely satisfied and you want to set the root URL of your web application at localhost:8080&lt;br /&gt;&lt;br /&gt;Soon after that, you tried to look at the web.xml, context.xml and server.xml and perhaps, not only looking at those files but also editing them hoping to get your web application running at localhost:8080 instead of localhost:8080/ServletTutorial&lt;br /&gt;&lt;br /&gt;You feel frustrated and do more online research. Googling, Binging and Yahooing with the keyword string "do not show java project name in localhost:8080" does not yield any relevant results. Even worse, you type in "localhost:8080 does not show java project name" and the search engines thought that you are experiencing some issue with Tomcat or with localhost:8080 and suggest you links about showing the project name. Frustration is mounting and your web application is still running at localhost:8080/ServletTutorial but not at localhost:8080&lt;br /&gt;&lt;br /&gt;You then bang at the wall or the table or try to suffocate yourself with the pillow if you are doing programming lying on the bed.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight:bold;"&gt;SOLUTION: &lt;/span&gt;After spending quite some time tinkering with Tomcat Apache and doing lots of reading by myself, I have finally come out with a simple solution. As simple as it may be, many IT Operations Engineers may have other much better suggestions and probably disagree with this solution. &lt;br /&gt;&lt;br /&gt;My solution works anyway, otherwise it is not a solution, isn't it?&lt;br /&gt;&lt;br /&gt;This is what I did eventually:&lt;br /&gt;[1] Export your project as ROOT.war&lt;br /&gt;[2] Keep in mind that it is case-sensitive ROOT.war&lt;br /&gt;[3] Copy the ROOT.war file into the webapps folder of your Tomcat directory&lt;br /&gt;[4] Tomcat will unpack the war file by itself&lt;br /&gt;&lt;br /&gt;You will now able to run your web application at localhost:8080 and you are smiling again :)&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4844902456784005421-7509694194783665740?l=nicholaskey.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://nicholaskey.blogspot.com/feeds/7509694194783665740/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://nicholaskey.blogspot.com/2009/06/localhost8080-and-not.html#comment-form' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4844902456784005421/posts/default/7509694194783665740'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4844902456784005421/posts/default/7509694194783665740'/><link rel='alternate' type='text/html' href='http://nicholaskey.blogspot.com/2009/06/localhost8080-and-not.html' title='localhost:8080 and not localhost:8080/projectname'/><author><name>Nicholas Key</name><uri>http://www.blogger.com/profile/05768297019453812096</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='http://4.bp.blogspot.com/_OQU38yb-Uq0/SwL5VBlHCII/AAAAAAAAA6U/lXUy53mS7gQ/S220/hamster.jpg'/></author><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4844902456784005421.post-726862789681472094</id><published>2009-06-05T15:10:00.009-07:00</published><updated>2011-08-03T06:33:10.946-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Java'/><category scheme='http://www.blogger.com/atom/ns#' term='Bitwise Operators'/><title type='text'>2 to the power of N</title><content type='html'>Here is a one-liner statement to check if a given integer is of 2 to the power of N.&lt;br /&gt;&lt;pre&gt;&lt;br /&gt;  public static boolean twoPowerN(int x){  &lt;br /&gt;    return ((x &amp; -x) == x) ? true : false;  &lt;br /&gt;  }&lt;br /&gt;&lt;/pre&gt;You may try the method using this test case:&lt;br /&gt;&lt;span style="font-weight:bold;"&gt;System.out.println(twoPowerN((int) Math.pow(2, 8)));&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;Basically it returns true for all integers 2powN, for example 2^100 or 2^7 or 2^33. A false will be returned for values other than 2powN. Well, that's the purpose of this method anyway (to check if a method is 2 to the power of N), right? :)&lt;br /&gt;&lt;br /&gt;Have a good day everyone!&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4844902456784005421-726862789681472094?l=nicholaskey.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://nicholaskey.blogspot.com/feeds/726862789681472094/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://nicholaskey.blogspot.com/2009/06/2-to-power-of-n.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4844902456784005421/posts/default/726862789681472094'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4844902456784005421/posts/default/726862789681472094'/><link rel='alternate' type='text/html' href='http://nicholaskey.blogspot.com/2009/06/2-to-power-of-n.html' title='2 to the power of N'/><author><name>Nicholas Key</name><uri>http://www.blogger.com/profile/05768297019453812096</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='http://4.bp.blogspot.com/_OQU38yb-Uq0/SwL5VBlHCII/AAAAAAAAA6U/lXUy53mS7gQ/S220/hamster.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4844902456784005421.post-8671441265625245666</id><published>2009-06-05T15:10:00.001-07:00</published><updated>2011-08-03T06:33:38.888-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Recursion'/><category scheme='http://www.blogger.com/atom/ns#' term='Java'/><category scheme='http://www.blogger.com/atom/ns#' term='General Knowledge'/><category scheme='http://www.blogger.com/atom/ns#' term='Algorithms'/><category scheme='http://www.blogger.com/atom/ns#' term='Trivia'/><title type='text'>Solving Palindrome Using Recursion</title><content type='html'>This is a follow-up article about solving palindrome using recursion. While we solved this problem previously using iteration (&lt;a href="http://nicholaskey.blogspot.com/2009/05/palindrome.html"&gt;link to previous article&lt;/a&gt;), I am demonstrating the way of solving it in a recursive manner.&lt;pre&gt;&lt;br /&gt;  public static void isPalindromeRecursive(String text){&lt;br /&gt;    text = text.toLowerCase().replaceAll("[\\W\\_*]", "");&lt;br /&gt;    if (helperFunction(text, 0, text.length()-1)) {&lt;br /&gt;      System.out.println("Is a Palindrome");&lt;br /&gt;    } else {&lt;br /&gt;      System.out.println("Is not a Palindrome");&lt;br /&gt;    }&lt;br /&gt;  }&lt;br /&gt;&lt;br /&gt;  private static boolean helperFunction(String input, int leftIndex, int rightIndex){&lt;br /&gt;    if (leftIndex &lt; rightIndex) {&lt;br /&gt;      if (!(input.charAt(leftIndex) == input.charAt(rightIndex))) {&lt;br /&gt;        return false;&lt;br /&gt;      }&lt;br /&gt;      leftIndex++;&lt;br /&gt;      rightIndex--;&lt;br /&gt;      helperFunction(input, leftIndex, rightIndex);&lt;br /&gt;    }&lt;br /&gt;    return true;&lt;br /&gt;  }&lt;br /&gt;&lt;/pre&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4844902456784005421-8671441265625245666?l=nicholaskey.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://nicholaskey.blogspot.com/feeds/8671441265625245666/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://nicholaskey.blogspot.com/2009/06/solving-palindrome-using-recursion.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4844902456784005421/posts/default/8671441265625245666'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4844902456784005421/posts/default/8671441265625245666'/><link rel='alternate' type='text/html' href='http://nicholaskey.blogspot.com/2009/06/solving-palindrome-using-recursion.html' title='Solving Palindrome Using Recursion'/><author><name>Nicholas Key</name><uri>http://www.blogger.com/profile/05768297019453812096</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='http://4.bp.blogspot.com/_OQU38yb-Uq0/SwL5VBlHCII/AAAAAAAAA6U/lXUy53mS7gQ/S220/hamster.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4844902456784005421.post-2936375814554290519</id><published>2009-06-01T23:04:00.001-07:00</published><updated>2009-06-01T23:05:31.203-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Cool Gadgets'/><category scheme='http://www.blogger.com/atom/ns#' term='Innovation'/><title type='text'>The Wii Killer?</title><content type='html'>&lt;object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" width="437" height="288" id="viddler"&gt;&lt;param name="movie" value="http://www.viddler.com/player/44771808/" /&gt;&lt;param name="allowScriptAccess" value="always" /&gt;&lt;param name="allowFullScreen" value="true" /&gt;&lt;embed src="http://www.viddler.com/player/44771808/" width="437" height="288" type="application/x-shockwave-flash" allowScriptAccess="always" allowFullScreen="true" name="viddler" &gt;&lt;/embed&gt;&lt;/object&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4844902456784005421-2936375814554290519?l=nicholaskey.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://nicholaskey.blogspot.com/feeds/2936375814554290519/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://nicholaskey.blogspot.com/2009/06/wii-killer.html#comment-form' title='2 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4844902456784005421/posts/default/2936375814554290519'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4844902456784005421/posts/default/2936375814554290519'/><link rel='alternate' type='text/html' href='http://nicholaskey.blogspot.com/2009/06/wii-killer.html' title='The Wii Killer?'/><author><name>Nicholas Key</name><uri>http://www.blogger.com/profile/05768297019453812096</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='http://4.bp.blogspot.com/_OQU38yb-Uq0/SwL5VBlHCII/AAAAAAAAA6U/lXUy53mS7gQ/S220/hamster.jpg'/></author><thr:total>2</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4844902456784005421.post-2922746374563591258</id><published>2009-05-29T11:15:00.009-07:00</published><updated>2011-08-03T06:34:28.982-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Java'/><category scheme='http://www.blogger.com/atom/ns#' term='General Knowledge'/><category scheme='http://www.blogger.com/atom/ns#' term='Bitwise Operators'/><title type='text'>Swapping 2 Integers</title><content type='html'>I believe many of us out there came across, at least once in their lifetime, the problem to swap two numbers. Here are the three sample solutions that I could think to swap two numbers.&lt;br /&gt;&lt;span style="font-weight:bold;"&gt;Solution A:&lt;/span&gt;&lt;br /&gt;&lt;pre&gt;&lt;br /&gt;  temp = a;&lt;br /&gt;  a = b;&lt;br /&gt;  b = temp;&lt;br /&gt;&lt;/pre&gt;Solution A introduces an additional auxiliary variable called "temp" in the code to hold one of the values (either a or b) which increases the footprint of the compiled class.&lt;br /&gt;&lt;span style="font-weight:bold;"&gt;Solution B:&lt;/span&gt;&lt;br /&gt;&lt;pre&gt;&lt;br /&gt;  a = a ^ b;&lt;br /&gt;  b = b ^ a;&lt;br /&gt;  a = a ^ b;&lt;br /&gt;&lt;/pre&gt;Solution B on the other side swaps two numbers using bitwise operation. The XOR (Exclusive OR) is introduced in this code.&lt;br /&gt;&lt;span style="font-weight:bold;"&gt;Solution C:&lt;/span&gt;&lt;br /&gt;&lt;pre&gt;&lt;br /&gt;  a = a + b;&lt;br /&gt;  b = a - b;&lt;br /&gt;  a = a - b; &lt;br /&gt;&lt;/pre&gt;Last but not least, Solution C swaps two numbers using arithmetic operations, both addition and subtraction. &lt;br /&gt;&lt;span style="font-weight:bold;"&gt;Conclusion&lt;/span&gt;: In terms of speed, I would personally rank Solution B being the fastest, Solution C the second fastest and Solution A the slowest. &lt;span style="font-weight:bold;"&gt;(B -&gt; C -&gt; A)&lt;/span&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4844902456784005421-2922746374563591258?l=nicholaskey.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://nicholaskey.blogspot.com/feeds/2922746374563591258/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://nicholaskey.blogspot.com/2009/05/swapping-2-integers.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4844902456784005421/posts/default/2922746374563591258'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4844902456784005421/posts/default/2922746374563591258'/><link rel='alternate' type='text/html' href='http://nicholaskey.blogspot.com/2009/05/swapping-2-integers.html' title='Swapping 2 Integers'/><author><name>Nicholas Key</name><uri>http://www.blogger.com/profile/05768297019453812096</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='http://4.bp.blogspot.com/_OQU38yb-Uq0/SwL5VBlHCII/AAAAAAAAA6U/lXUy53mS7gQ/S220/hamster.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4844902456784005421.post-430942903961315508</id><published>2009-05-28T20:52:00.005-07:00</published><updated>2009-05-29T14:46:02.878-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Java'/><category scheme='http://www.blogger.com/atom/ns#' term='Useful Tools'/><category scheme='http://www.blogger.com/atom/ns#' term='XSL'/><category scheme='http://www.blogger.com/atom/ns#' term='XML'/><title type='text'>Translating XML with XSL in Java</title><content type='html'>I do not consider the codes in this blog entry as intensive as other entries. This is just merely an example to show you how to translate a XML document with a XSL stylesheet in a Java class. It could be a very handy tool for some Java developers out there that want to translate a given XML content into another completely different XML content on the fly.&lt;br /&gt;&lt;textarea name="code" class="java" cols="60" rows="10"&gt;&lt;br /&gt;import java.io.StringWriter;&lt;br /&gt;import javax.xml.transform.OutputKeys;&lt;br /&gt;import javax.xml.transform.Transformer;&lt;br /&gt;import javax.xml.transform.TransformerFactory;&lt;br /&gt;import javax.xml.transform.stream.StreamResult;&lt;br /&gt;import javax.xml.transform.stream.StreamSource;&lt;br /&gt;&lt;br /&gt;public class TranslateXML {&lt;br /&gt;  public synchronized String XMLtranslet() {&lt;br /&gt;    TransformerFactory factory = TransformerFactory.newInstance();&lt;br /&gt;    Transformer transformer = null;&lt;br /&gt;    String resultString = null;&lt;br /&gt;    try {&lt;br /&gt;      StreamSource source;&lt;br /&gt;      source = new StreamSource("YOUR_XML_FILE");&lt;br /&gt;&lt;br /&gt;      StreamSource style;&lt;br /&gt;      style = new StreamSource("YOUR_XSL_FILE");&lt;br /&gt;&lt;br /&gt;      StreamResult result;&lt;br /&gt;      result = new StreamResult(new StringWriter());&lt;br /&gt;&lt;br /&gt;      transformer = factory.newTransformer(style);&lt;br /&gt;      transformer.setOutputProperty(OutputKeys.ENCODING,"UTF-8");&lt;br /&gt;      transformer.transform(source, result);&lt;br /&gt;&lt;br /&gt;      resultString = (result != null) ? ((StringWriter)result.getWriter()).toString() : null;&lt;br /&gt;&lt;br /&gt;    } catch (Exception e) {}&lt;br /&gt;    return resultString;&lt;br /&gt;  }&lt;br /&gt;&lt;br /&gt;  public static void main(String[] args) {&lt;br /&gt;    TranslateXML xml = new TranslateXML();&lt;br /&gt;    System.out.println(xml.XMLtranslet());&lt;br /&gt;  }&lt;br /&gt;}&lt;br /&gt;&lt;/textarea&gt;Do not forget to set the encoding of your Java codes to UTF-8 if you are manipulating non-English XML content - for example, Traditional Chinese, Simplified Chinese, Russian, Korean or Japanese - if you would want to see the output in your Eclipse IDE, which is my current IDE to write Java codes. &lt;br /&gt;&lt;br /&gt;The usefulness of this approach is that you do not need to include a reference of a XSL file in the XML, say for example,&lt;br /&gt;&lt;br /&gt;&amp;lt;?xml version="1.0" encoding="UTF-8"?&gt;&lt;br /&gt;  &amp;lt;?xml-stylesheet type="text/xsl" href="myXMLstylesheet.xsl"?&gt;&lt;br /&gt;&amp;lt;catalog/&gt;&lt;br /&gt;&lt;br /&gt;Hope you have fun trying this out! :)&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4844902456784005421-430942903961315508?l=nicholaskey.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://nicholaskey.blogspot.com/feeds/430942903961315508/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://nicholaskey.blogspot.com/2009/05/translating-xml-with-xsl-in-java.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4844902456784005421/posts/default/430942903961315508'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4844902456784005421/posts/default/430942903961315508'/><link rel='alternate' type='text/html' href='http://nicholaskey.blogspot.com/2009/05/translating-xml-with-xsl-in-java.html' title='Translating XML with XSL in Java'/><author><name>Nicholas Key</name><uri>http://www.blogger.com/profile/05768297019453812096</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='http://4.bp.blogspot.com/_OQU38yb-Uq0/SwL5VBlHCII/AAAAAAAAA6U/lXUy53mS7gQ/S220/hamster.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4844902456784005421.post-7155179163987229177</id><published>2009-05-24T14:27:00.001-07:00</published><updated>2011-08-03T06:35:01.198-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Java'/><category scheme='http://www.blogger.com/atom/ns#' term='Useful Tools'/><category scheme='http://www.blogger.com/atom/ns#' term='Algorithms'/><title type='text'>Indexes of indexOf</title><content type='html'>Have you ever come across a situation in which you want to gather a list of indexes of the one particular substring in a string but you are limited to using only indexOf() method? I did and I wrote this method to ease my work in the future in the event that I need to get the list of indexes of the given substring. The code is as follow.&lt;br /&gt;&lt;pre&gt;&lt;br /&gt;public static ArrayList&lt;Integer&gt; indices(String inputString, String sampleString){&lt;br /&gt;  int length = inputString.length();&lt;br /&gt;  int inputStringIndex = -1;&lt;br /&gt;  StringBuffer newString = new StringBuffer(); &lt;br /&gt;  int index = 0;  &lt;br /&gt;  int check = 0;&lt;br /&gt;  ArrayList&lt;Integer&gt; compile = new ArrayList&lt;Integer&gt;();&lt;br /&gt;  while (index &lt; length) {&lt;br /&gt;    try {&lt;br /&gt;      if (inputString.charAt(index) == sampleString.charAt(check)) {&lt;br /&gt;        newString.append(inputString.charAt(index));&lt;br /&gt;        check++;&lt;br /&gt;        if (newString.toString().equals(sampleString)) {&lt;br /&gt;          inputStringIndex = (index - check) + 1 ;&lt;br /&gt;          compile.add(inputStringIndex);&lt;br /&gt;          newString.setLength(0);&lt;br /&gt;        }&lt;br /&gt;      }&lt;br /&gt;      if (check == (sampleString.length())) {&lt;br /&gt;        check = 0;&lt;br /&gt;      }&lt;br /&gt;    } catch (Exception ex){}&lt;br /&gt;    index++;&lt;br /&gt;  }  &lt;br /&gt;  if (compile.size() == 0) {&lt;br /&gt;    compile.add(inputStringIndex);&lt;br /&gt;  }  &lt;br /&gt;  return compile;&lt;br /&gt;}&lt;br /&gt;&lt;/pre&gt;The usage of this static method is very simple and trivial. Given a string "Nicholas Key Key Key Nicholas Key" and a sample substring "Key", you will get the result of [9, 13, 17, 30].&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4844902456784005421-7155179163987229177?l=nicholaskey.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://nicholaskey.blogspot.com/feeds/7155179163987229177/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://nicholaskey.blogspot.com/2009/05/indexes-of-indexof.html#comment-form' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4844902456784005421/posts/default/7155179163987229177'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4844902456784005421/posts/default/7155179163987229177'/><link rel='alternate' type='text/html' href='http://nicholaskey.blogspot.com/2009/05/indexes-of-indexof.html' title='Indexes of indexOf'/><author><name>Nicholas Key</name><uri>http://www.blogger.com/profile/05768297019453812096</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='http://4.bp.blogspot.com/_OQU38yb-Uq0/SwL5VBlHCII/AAAAAAAAA6U/lXUy53mS7gQ/S220/hamster.jpg'/></author><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4844902456784005421.post-6463733203086062413</id><published>2009-05-21T20:10:00.000-07:00</published><updated>2011-08-03T06:35:42.427-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Java'/><category scheme='http://www.blogger.com/atom/ns#' term='Useful Tools'/><category scheme='http://www.blogger.com/atom/ns#' term='Algorithms'/><title type='text'>Converting decimals into different base numbers</title><content type='html'>I have this function that might be useful and interesting for you. Probably some of us are thinking how to convert a decimal number into hexadecimal, octal and binary. To those readers that never heard of these four words, decimal is a base 10 number, hexadecimal is a base 16 number, octal is a base 8 number and binary is a base 2 number. I wrote this function simply because I wanted to learn what happens behind the API methods in the Java SDK that help you to convert a given decimal into the three different base numbers.&lt;br /&gt;&lt;br /&gt;The methods that are available for us the developers in the Java 1.5 SDK are:&lt;br /&gt;&lt;span style="font-weight:bold;"&gt;Integer.toBinaryString(input);&lt;br /&gt;Integer.toOctalString(input);&lt;br /&gt;Integer.toHexString(input);&lt;/span&gt;&lt;br /&gt;&lt;pre&gt;&lt;br /&gt;public static class DecimalConverter{&lt;br /&gt;  static StringBuffer result = new StringBuffer();&lt;br /&gt;  static int divisorBIN = 2;&lt;br /&gt;  static int divisorOCT = 8;&lt;br /&gt;  static int divisorHEX = 16;&lt;br /&gt;  static char[] code = {'0','1','2','3','4','5','6','7','8','9','A','B','C','D','E','F'};&lt;br /&gt;&lt;br /&gt;  public static String converterHelper(int number, int divisor) {&lt;br /&gt;    if (number == 0) {&lt;br /&gt;      return "";&lt;br /&gt;    }&lt;br /&gt;    else {&lt;br /&gt;      converterHelper(number/divisor, divisor);&lt;br /&gt;      result.append(code[number%divisor]);&lt;br /&gt;    }&lt;br /&gt;    return result.toString();&lt;br /&gt;  }&lt;br /&gt;&lt;br /&gt;  public static String toHex(int number) {&lt;br /&gt;    //reset StringBuffer result&lt;br /&gt;    result.setLength(0);&lt;br /&gt;    return converterHelper(number, divisorHEX);&lt;br /&gt;  }&lt;br /&gt;&lt;br /&gt;  public static String toOct(int number) {&lt;br /&gt;    //reset StringBuffer result&lt;br /&gt;    result.setLength(0);&lt;br /&gt;    return converterHelper(number, divisorOCT);&lt;br /&gt;  }&lt;br /&gt;&lt;br /&gt;  public static String toBin(int number){&lt;br /&gt;    //reset StringBuffer result&lt;br /&gt;    result.setLength(0);&lt;br /&gt;    return converterHelper(number, divisorBIN);&lt;br /&gt;  }  &lt;br /&gt;}&lt;br /&gt;&lt;/pre&gt;From the method as shown, we have 16 characters in the array "code". This is because we want to accommodate all the valid the characters in base 16 numbers (hexadecimals). This method is quite a recursive method to convert the base 10 numbers (decimals) into 3 different bases of numbers. I hope you find these method useful. :) We can make use of this method by calling these static methods in the DecimalConverter class. Static methods are especially easy and useful when we want to call or make use of them from other classes. This is how the method is demonstrated.&lt;br /&gt;&lt;pre&gt;&lt;br /&gt;public static void main(String[] args) {&lt;br /&gt;  System.out.println(DecimalConverter.toOct(207));&lt;br /&gt;  System.out.println(DecimalConverter.toBin(207));&lt;br /&gt;  System.out.println(DecimalConverter.toHex(207));&lt;br /&gt;}&lt;br /&gt;&lt;/pre&gt;The recursion takes place in this statement &lt;span style="font-weight:bold;"&gt;converterHelper(number/divisor, divisor);&lt;/span&gt;. converterHelper method calls itself as long as the number is not 0 and then it looks into the array and find the matching character according to the index from the modulo operation. You may try out this method and use the numbers in the conversion table to determine if this helper class is useful for you. Click &lt;a href="http://www.ascii.cl/conversion.htm"&gt;here&lt;/a&gt; to view the conversion table.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4844902456784005421-6463733203086062413?l=nicholaskey.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://nicholaskey.blogspot.com/feeds/6463733203086062413/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://nicholaskey.blogspot.com/2009/05/converting-decimals-into-different-base.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4844902456784005421/posts/default/6463733203086062413'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4844902456784005421/posts/default/6463733203086062413'/><link rel='alternate' type='text/html' href='http://nicholaskey.blogspot.com/2009/05/converting-decimals-into-different-base.html' title='Converting decimals into different base numbers'/><author><name>Nicholas Key</name><uri>http://www.blogger.com/profile/05768297019453812096</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='http://4.bp.blogspot.com/_OQU38yb-Uq0/SwL5VBlHCII/AAAAAAAAA6U/lXUy53mS7gQ/S220/hamster.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4844902456784005421.post-4775149640376001</id><published>2009-05-20T14:15:00.009-07:00</published><updated>2011-08-03T06:36:09.858-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Java'/><category scheme='http://www.blogger.com/atom/ns#' term='Algorithms'/><category scheme='http://www.blogger.com/atom/ns#' term='Trivia'/><title type='text'>The one missing number</title><content type='html'>This question sounds rather intimidating but when you analyze it deep enough, you will be amazed about the way this problem is solved - &lt;span style="font-weight:bold;"&gt;"Given an array of size n, containing every element from 1 to n+1, except one. Find the missing element."&lt;/span&gt; Many of us might have quickly jumped into the solution in which many fancy data structures are being used. But actually there is a much easier way to solve this problem. The suggested code is as follow. I think the complexity of this suggested algorithm is O(n). It is a linear operation as you can see in the implementation.&lt;br /&gt;&lt;pre&gt;&lt;br /&gt;public static int missingNumber(int input[]){&lt;br /&gt;  int arrSize = input.length;&lt;br /&gt;  int totalLength = arrSize + 1;&lt;br /&gt;  int missingNumber = 0;&lt;br /&gt;  for (int count=1; count &lt;= totalLength; count++) {&lt;br /&gt;    missingNumber = missingNumber + count;&lt;br /&gt;    if ((count-1) &lt; arrSize) {&lt;br /&gt;      missingNumber = missingNumber - input[(count-1)];&lt;br /&gt;    }&lt;br /&gt;  }  &lt;br /&gt;  return missingNumber;&lt;br /&gt;} &lt;br /&gt;&lt;/pre&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4844902456784005421-4775149640376001?l=nicholaskey.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://nicholaskey.blogspot.com/feeds/4775149640376001/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://nicholaskey.blogspot.com/2009/05/one-missing-number.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4844902456784005421/posts/default/4775149640376001'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4844902456784005421/posts/default/4775149640376001'/><link rel='alternate' type='text/html' href='http://nicholaskey.blogspot.com/2009/05/one-missing-number.html' title='The one missing number'/><author><name>Nicholas Key</name><uri>http://www.blogger.com/profile/05768297019453812096</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='http://4.bp.blogspot.com/_OQU38yb-Uq0/SwL5VBlHCII/AAAAAAAAA6U/lXUy53mS7gQ/S220/hamster.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4844902456784005421.post-4747269382147831368</id><published>2009-05-19T22:12:00.007-07:00</published><updated>2011-08-03T06:36:41.664-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Java'/><category scheme='http://www.blogger.com/atom/ns#' term='Algorithms'/><title type='text'>Index of a sample string in a string</title><content type='html'>I am sure many of us who write codes in Java use the method indexOf() to get the index of a string in a given string. I use this method quite frequently too and I thought of writing a method that replicates the functionality of indexOf() that is readily available in the Java SDK. In addition to that, I thought this could be an exciting thing to do - dissecting and reverse engineering Java API methods.&lt;br /&gt;&lt;br /&gt;Well, I wrote this code and would like to share with the readers of this blog. I hope you find it useful. Please feel free to drop a line if you have a better way to solve this problem. The code is quite self explanatory. It mainly reads through the original string and while reading it, the sample string is being compared.&lt;br /&gt;&lt;pre&gt; &lt;br /&gt;// To get the index of the first occurrence of a matching substring&lt;br /&gt;public static int indexOf(String inputString, String sampleString){&lt;br /&gt;  // set the length of input string&lt;br /&gt;  int length = inputString.length();&lt;br /&gt;  int inputStringIndex = -1;&lt;br /&gt;  StringBuffer newString = new StringBuffer();&lt;br /&gt;  // to keep track of current index of character of input string&lt;br /&gt;  int index = 0;&lt;br /&gt;  // to keep track of current index of character of sample string&lt;br /&gt;  int check = 0;&lt;br /&gt;  while (index &lt; length) {&lt;br /&gt;    try {&lt;br /&gt;      if (inputString.charAt(index) == sampleString.charAt(check)) {&lt;br /&gt;        newString.append(inputString.charAt(index));&lt;br /&gt;        check++;&lt;br /&gt;        if (newString.toString().equals(sampleString)) {&lt;br /&gt;        /**&lt;br /&gt;          * set the index of the first occurrence of the &lt;br /&gt;          * matching substring&lt;br /&gt;          */&lt;br /&gt;          inputStringIndex = (index - check) + 1 ;&lt;br /&gt;          break;&lt;br /&gt;        }&lt;br /&gt;      }&lt;br /&gt;    } catch (Exception ex){} &lt;br /&gt;    index++;&lt;br /&gt;  }  &lt;br /&gt;  return inputStringIndex;&lt;br /&gt;}&lt;br /&gt;&lt;/pre&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4844902456784005421-4747269382147831368?l=nicholaskey.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://nicholaskey.blogspot.com/feeds/4747269382147831368/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://nicholaskey.blogspot.com/2009/05/missing-element.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4844902456784005421/posts/default/4747269382147831368'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4844902456784005421/posts/default/4747269382147831368'/><link rel='alternate' type='text/html' href='http://nicholaskey.blogspot.com/2009/05/missing-element.html' title='Index of a sample string in a string'/><author><name>Nicholas Key</name><uri>http://www.blogger.com/profile/05768297019453812096</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='http://4.bp.blogspot.com/_OQU38yb-Uq0/SwL5VBlHCII/AAAAAAAAA6U/lXUy53mS7gQ/S220/hamster.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4844902456784005421.post-2960521092457581113</id><published>2009-05-11T22:24:00.007-07:00</published><updated>2009-05-12T00:08:57.625-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='General Knowledge'/><category scheme='http://www.blogger.com/atom/ns#' term='Useful Tools'/><title type='text'>CoffeeCup HTML Editor</title><content type='html'>This is a HTML Editor that you may want to give it a try. I love to use this application because, first of all, it is absolutely free. You can get it right &lt;a href="http://www.coffeecup.com/free-editor/download/"&gt;here&lt;/a&gt; for free without any cost! Here is a screenshot of how their website looks like. &lt;br /&gt;&lt;br /&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://1.bp.blogspot.com/_OQU38yb-Uq0/SgkYT74yCxI/AAAAAAAAA0k/RV3qQILYuKQ/s1600-h/CoffeeCup.png"&gt;&lt;img style="display:block; margin:0px auto 10px; text-align:center;cursor:pointer; cursor:hand;width: 400px; height: 223px;" src="http://1.bp.blogspot.com/_OQU38yb-Uq0/SgkYT74yCxI/AAAAAAAAA0k/RV3qQILYuKQ/s400/CoffeeCup.png" border="0" alt=""id="BLOGGER_PHOTO_ID_5334821964369496850" /&gt;&lt;/a&gt;Most of the time, free stuffs are not actually free. Some companies will insist to get at least your email address in order to download their "free" software. For those of you that might be wondering why some companies tempt you to give them your email address or phone number, the reason being that your contact information will be harvested by spammers or so called business affiliates. Do not fall into that trap. Privacy is becoming more and more invaded these days. CoffeeCup does not ask for your email address nor telephone number. You will just need to download this HTML Editor from their website and the application is up and running. No strings attached!&lt;br /&gt;&lt;br /&gt;I have tested this application and it is loaded with many interesting features including syntax highlighting. It also allows you to preview your HTML design in the same window. Since I have started to tinker with PHP at my &lt;a href="http://nicholaskey.uuuq.com"&gt;playground&lt;/a&gt;, the editor is able to highlight the PHP statements nicely. The most important feature, for me personally, to use this application, is the FTP which is used to perform file uploads and downloads. No more paying a hefty sum of money to buy FrontPage or Dreamweaver - IDEs that helps you most of the frontend but leave you clueless about the underlying HTML codes.&lt;br /&gt;&lt;br /&gt;Other than that, the interface is very intuitive. Everything that I wanted to do is within my estimation, which means that I know intuitively what buttons to point and click or which drop down menu to look at, the first time I was using this application. This is true when I configured the FTP settings.&lt;br /&gt;&lt;br /&gt;But hey, since CoffeeCup HTML Editor is free, you should not expect that it is very feature-packed just like those off-the-shelf HTML editors. I have mentioned the pros earlier so here are some of the disadvantages. I have only came across one - CoffeeCup HTML Editor is only available for Windows and that is sad.&lt;br /&gt;&lt;br /&gt;Anyway, this is the link again to download &lt;a href="http://www.coffeecup.com/free-editor/download/"&gt;CoffeeCup HTML Editor&lt;/a&gt;. Have fun trying it!&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight:bold;"&gt;DISCLAIMER&lt;/span&gt;: I am recommending CoffeeCup HTML Editor as a software developer that has tried its features and I think it is useful for other web developer and I do not receive any endorsement fee from CoffeeCup to write this article :)&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4844902456784005421-2960521092457581113?l=nicholaskey.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://nicholaskey.blogspot.com/feeds/2960521092457581113/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://nicholaskey.blogspot.com/2009/05/coffeecup-html-editor.html#comment-form' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4844902456784005421/posts/default/2960521092457581113'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4844902456784005421/posts/default/2960521092457581113'/><link rel='alternate' type='text/html' href='http://nicholaskey.blogspot.com/2009/05/coffeecup-html-editor.html' title='CoffeeCup HTML Editor'/><author><name>Nicholas Key</name><uri>http://www.blogger.com/profile/05768297019453812096</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='http://4.bp.blogspot.com/_OQU38yb-Uq0/SwL5VBlHCII/AAAAAAAAA6U/lXUy53mS7gQ/S220/hamster.jpg'/></author><media:thumbnail xmlns:media='http://search.yahoo.com/mrss/' url='http://1.bp.blogspot.com/_OQU38yb-Uq0/SgkYT74yCxI/AAAAAAAAA0k/RV3qQILYuKQ/s72-c/CoffeeCup.png' height='72' width='72'/><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4844902456784005421.post-2087952910485634382</id><published>2009-05-08T15:08:00.005-07:00</published><updated>2009-05-08T17:18:58.428-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='General Knowledge'/><category scheme='http://www.blogger.com/atom/ns#' term='Useful Tools'/><title type='text'>The syntax highlighter</title><content type='html'>I believe some of my readers might be thinking to themselves how does Nicholas wraps around the codes that he demonstrates in his blog entries in a text area filled with interleaving colors. It also comes with the copying feature and viewing the codes in plain texts. Many thanks to Alex Gorbatchev for this wonderful Javascript library that allows us to read codes more easily in blogs or online journals. This is &lt;a href="http://alexgorbatchev.com/wiki/SyntaxHighlighter"&gt;his website&lt;/a&gt; if you would want to take a look at his work. Or you can actually go to Google Code website to download the package. There are several steps for you to follow if you want to get your codes display nicely in the encapsulated and decorated text area.&lt;br /&gt;&lt;br /&gt;[1] Go to the &lt;a href="http://code.google.com/p/syntaxhighlighter/downloads/list"&gt;syntaxhighlighter&lt;/a&gt; website at Google Code to download the latest version of the Javascript library. &lt;br /&gt;&lt;br /&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://1.bp.blogspot.com/_OQU38yb-Uq0/SgSw8_ZHsXI/AAAAAAAAA0c/jgqwMPtRNwo/s1600-h/download.png"&gt;&lt;img style="display:block; margin:0px auto 10px; text-align:center;cursor:pointer; cursor:hand;width: 400px; height: 146px;" src="http://1.bp.blogspot.com/_OQU38yb-Uq0/SgSw8_ZHsXI/AAAAAAAAA0c/jgqwMPtRNwo/s400/download.png" border="0" alt=""id="BLOGGER_PHOTO_ID_5333582420568945010" /&gt;&lt;/a&gt;&lt;br /&gt;[2] Download the compressed file and unzip it in your remote hosting. I may suggest Google Apps to host the uncompressed files. You will have to use &lt;a href="http://www.rarsoft.com/"&gt;WinRAR&lt;/a&gt; to unzip the contents. I rename the folder called "dp.SyntaxHighlighter" to "SyntaxHighlighter". There are 2 folders that I make use in the uncompressed file namely "Styles" and "Scripts". &lt;br /&gt;&lt;br /&gt;[3] Edit your blog template to insert these lines of codes, preferably at the footer part of the template that reads "&amp;lt;!-- end outer-wrapper --&gt; ".&lt;br /&gt;&lt;textarea name="code" class="javascript" cols="60" rows="10"&gt;&lt;br /&gt;&lt;!-- end outer-wrapper --&gt; &lt;br /&gt;&lt;br /&gt;&lt;script type='text/javascript'&gt; &lt;br /&gt;window.isBloggerMode = true;&lt;br /&gt;&lt;/script&gt; &lt;br /&gt;&lt;br /&gt;&amp;lt;link href='http://[YOUR_HOST]/Styles/SyntaxHighlighter.css' rel='stylesheet' type='text/css'/&gt; &lt;br /&gt;&lt;script class='javascript' src='http://[YOUR_HOST]/Scripts/shCore.js'&gt;&lt;/script&gt; &lt;br /&gt;&lt;script class='javascript' src='http://[YOUR_HOST]/Scripts/shBrushCSharp.js'&gt;&lt;/script&gt; &lt;br /&gt;&lt;script class='javascript' src='http://[YOUR_HOST]/Scripts/shBrushPhp.js'&gt;&lt;/script&gt; &lt;br /&gt;&lt;script class='javascript' src='http://[YOUR_HOST]/Scripts/shBrushJScript.js'&gt;&lt;/script&gt; &lt;br /&gt;&lt;script class='javascript' src='http://[YOUR_HOST]/Scripts/shBrushJava.js'&gt;&lt;/script&gt; &lt;br /&gt;&lt;script class='javascript' src='http://[YOUR_HOST]/Scripts/shBrushVb.js'&gt;&lt;/script&gt; &lt;br /&gt;&lt;script class='javascript' src='http://[YOUR_HOST]/Scripts/shBrushSql.js'&gt;&lt;/script&gt; &lt;br /&gt;&lt;script class='javascript' src='http://[YOUR_HOST]/Scripts/shBrushXml.js'&gt;&lt;/script&gt; &lt;br /&gt;&lt;script class='javascript' src='http://[YOUR_HOST]/Scripts/shBrushDelphi.js'&gt;&lt;/script&gt; &lt;br /&gt;&lt;script class='javascript' src='http://[YOUR_HOST]/Scripts/shBrushPython.js'&gt;&lt;/script&gt; &lt;br /&gt;&lt;script class='javascript' src='http://[YOUR_HOST]/Scripts/shBrushRuby.js'&gt;&lt;/script&gt; &lt;br /&gt;&lt;script class='javascript' src='http://[YOUR_HOST]/Scripts/shBrushCss.js'&gt;&lt;/script&gt; &lt;br /&gt;&lt;script class='javascript' src='http://[YOUR_HOST]/Scripts/shBrushCpp.js'&gt;&lt;/script&gt; &lt;br /&gt;&lt;script class='javascript' src='http://[YOUR_HOST]/Scripts/shBrushScala.js'&gt;&lt;/script&gt; &lt;br /&gt;&lt;script class='javascript' src='http://[YOUR_HOST]/Scripts/shBrushGroovy.js'&gt;&lt;/script&gt; &lt;br /&gt;&lt;script class='javascript' src='http://[YOUR_HOST]/Scripts/shBrushBash.js'&gt;&lt;/script&gt; &lt;br /&gt;&lt;script class='javascript'&gt; &lt;br /&gt;  if(window.isBloggerMode == true)&lt;br /&gt;  dp.SyntaxHighlighter.BloggerMode();&lt;br /&gt;&lt;br /&gt;  dp.SyntaxHighlighter.ClipboardSwf = 'http://[YOUR_HOST]/Scripts/clipboard.swf';&lt;br /&gt;  dp.SyntaxHighlighter.HighlightAll('code');&lt;br /&gt;&lt;/script&gt; &lt;br /&gt;&lt;/textarea&gt;&lt;br /&gt;[4] The next step is to try inserting your code snippets into this textarea&lt;br /&gt;&amp;lt;textarea name="code" class="javascript" cols="60" rows="10"&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;code...&lt;br /&gt;&amp;nbsp;&amp;nbsp;code...&lt;br /&gt;&amp;nbsp;&amp;nbsp;code...&lt;br /&gt;&amp;lt;/textarea&gt;&lt;br /&gt;&lt;br /&gt;Hope you have fun trying this out! :)&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4844902456784005421-2087952910485634382?l=nicholaskey.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://nicholaskey.blogspot.com/feeds/2087952910485634382/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://nicholaskey.blogspot.com/2009/05/syntax-highlighter.html#comment-form' title='2 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4844902456784005421/posts/default/2087952910485634382'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4844902456784005421/posts/default/2087952910485634382'/><link rel='alternate' type='text/html' href='http://nicholaskey.blogspot.com/2009/05/syntax-highlighter.html' title='The syntax highlighter'/><author><name>Nicholas Key</name><uri>http://www.blogger.com/profile/05768297019453812096</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='http://4.bp.blogspot.com/_OQU38yb-Uq0/SwL5VBlHCII/AAAAAAAAA6U/lXUy53mS7gQ/S220/hamster.jpg'/></author><media:thumbnail xmlns:media='http://search.yahoo.com/mrss/' url='http://1.bp.blogspot.com/_OQU38yb-Uq0/SgSw8_ZHsXI/AAAAAAAAA0c/jgqwMPtRNwo/s72-c/download.png' height='72' width='72'/><thr:total>2</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4844902456784005421.post-6440005253799693346</id><published>2009-05-07T08:13:00.007-07:00</published><updated>2011-08-03T06:37:26.732-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Java'/><category scheme='http://www.blogger.com/atom/ns#' term='Algorithms'/><category scheme='http://www.blogger.com/atom/ns#' term='Trivia'/><title type='text'>Nicholas is salohciN</title><content type='html'>I have been thinking a lot about solving a problem optimally and efficiently. Let us take a look at a seemingly easy computer science problem but might take some of us quite a bit of time to come up with an elegant solution. It is the problem about reversing a string - be it by letters or by words. Below is my solution to reverse a string by letters.&lt;br /&gt;&lt;pre&gt;&lt;br /&gt;public static String reverseCharacters(String text){&lt;br /&gt;  StringBuffer reversed = new StringBuffer();  &lt;br /&gt;  int len = text.length()-1;&lt;br /&gt;  for (int i=len; i&gt;=0; i--) {&lt;br /&gt;    reversed.append(text.charAt(i));&lt;br /&gt;  }&lt;br /&gt;  return reversed.toString();&lt;br /&gt;}&lt;br /&gt;&lt;/pre&gt;It is observed that I am decrementing the counter in the for-loop. Why is that? It is simply because I want to start to look at the given string in a backward manner. A StringBuffer is used to append the letters because append() operation is not as costly as we would have used a string and concatenate the letters. Simple isn't it? Many of us might thought that we could have used the reverse() method instead, rather than coding this unnecessarily. I would say this suggested solution is very reliable if we are looking at solving this problem more discretely.&lt;br /&gt;&lt;br /&gt;Next we will explore how to reverse a string by words. Once again I am suggesting the cheapest way to solve it. Some of us might thought that we have to first split the strings by a whitespace and then push the words into a stack, which we will then pop every single item out from the stack. Here is my approach in solving it using very little copying and no temporary variables.&lt;br /&gt;&lt;pre&gt;&lt;br /&gt;public static String reverseWords(String text) {&lt;br /&gt;  StringBuffer reverse = new StringBuffer();&lt;br /&gt;  String[] textArray= text.split("[\\s*]");&lt;br /&gt;  int len = textArray.length-1;&lt;br /&gt;  for (int i=len; i&gt;=0; i--) {&lt;br /&gt;    reverse.append(textArray[i]).append(" ");&lt;br /&gt;  }&lt;br /&gt;  return reverse.toString();&lt;br /&gt;}&lt;br /&gt;&lt;/pre&gt;I am looking backwards again. This time it is the array of split texts. I am splitting the text using the split() method and provide a regular expression statement [\s*]. The StringBuffer is used instead of String because it is less costly to append strings using the append() method. The method reverseWords() returns "sky blue clear very" if the given string is "very clear blue sky".&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4844902456784005421-6440005253799693346?l=nicholaskey.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://nicholaskey.blogspot.com/feeds/6440005253799693346/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://nicholaskey.blogspot.com/2009/05/nicholas-is-salohcin.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4844902456784005421/posts/default/6440005253799693346'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4844902456784005421/posts/default/6440005253799693346'/><link rel='alternate' type='text/html' href='http://nicholaskey.blogspot.com/2009/05/nicholas-is-salohcin.html' title='Nicholas is salohciN'/><author><name>Nicholas Key</name><uri>http://www.blogger.com/profile/05768297019453812096</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='http://4.bp.blogspot.com/_OQU38yb-Uq0/SwL5VBlHCII/AAAAAAAAA6U/lXUy53mS7gQ/S220/hamster.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4844902456784005421.post-937456909611306943</id><published>2009-05-06T01:09:00.001-07:00</published><updated>2011-08-03T06:37:57.751-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Java'/><category scheme='http://www.blogger.com/atom/ns#' term='Algorithms'/><category scheme='http://www.blogger.com/atom/ns#' term='Trivia'/><title type='text'>Deduplication</title><content type='html'>Here is a Java static method that removes recurring characters in a string. Given an input string "[Nicholas N I cho L[A]s!]", this method returns a string that reads "[Nicholas ILA]!"&lt;br /&gt;&lt;pre&gt;&lt;br /&gt;public static String removeDuplicates(String text){&lt;br /&gt;  StringBuffer uniq = new StringBuffer(); &lt;br /&gt;  int len = text.length();&lt;br /&gt;  for (int i=0; i&amp;lt;len; i++) {  &lt;br /&gt;    if (uniq.indexOf(Character.toString(text.charAt(i))) &lt; 0) {&lt;br /&gt;      uniq.append(text.charAt(i));&lt;br /&gt;    }&lt;br /&gt;  }  &lt;br /&gt;  return uniq.toString();&lt;br /&gt;}&lt;br /&gt;&lt;/pre&gt;Initially I thought of using a set to compile a group of unique characters but that would be adding extra code executions. I figured that I can solve this rather easily by going back to the basics. You may see that as I am constructing a new string "uniq", I am using the indexOf() method to look up for a particular character in that string. A value less than 0 means that the character that we are looking for does not exist at that moment. So we are appending it to "uniq". Another problem solved :)&lt;br /&gt;&lt;span style="font-weight:bold;color:red;"&gt;Update:&lt;/span&gt; The code is also available in Python in &lt;a href="http://nicholaskey.blogspot.com/2009/10/my-java-codes-in-python-part-2_28.html"&gt;this entry&lt;/a&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4844902456784005421-937456909611306943?l=nicholaskey.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://nicholaskey.blogspot.com/feeds/937456909611306943/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://nicholaskey.blogspot.com/2009/05/deduplication.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4844902456784005421/posts/default/937456909611306943'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4844902456784005421/posts/default/937456909611306943'/><link rel='alternate' type='text/html' href='http://nicholaskey.blogspot.com/2009/05/deduplication.html' title='Deduplication'/><author><name>Nicholas Key</name><uri>http://www.blogger.com/profile/05768297019453812096</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='http://4.bp.blogspot.com/_OQU38yb-Uq0/SwL5VBlHCII/AAAAAAAAA6U/lXUy53mS7gQ/S220/hamster.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4844902456784005421.post-3846943741806950211</id><published>2009-05-05T18:15:00.000-07:00</published><updated>2011-08-03T06:38:25.888-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Java'/><category scheme='http://www.blogger.com/atom/ns#' term='General Knowledge'/><category scheme='http://www.blogger.com/atom/ns#' term='Algorithms'/><category scheme='http://www.blogger.com/atom/ns#' term='Trivia'/><title type='text'>Palindrome</title><content type='html'>A palindrome is a word or phrase that reads the same forward as it does backward. Some of the simple examples are "kayak", "Hannah" and "refer" if we would like to know how do palindromic words look like. There are also palindrome-like phrases such as "Dennis and Edna sinned" and "Draw pupil's lip upward".&lt;br /&gt;&lt;br /&gt;It would not be too difficult to determine algorithmically if a word or sentence is a palindrome. There are many ways to solve it but we also need to consider if our solution is not computationally expensive.&lt;br /&gt;&lt;br /&gt;I have thought of a simple and yet an efficient solution to our discussion. This is a static method that strips off the punctuations and also white character spacings. The method returns a boolean value true if the input string is a palindrome otherwise it returns false.&lt;br /&gt;&lt;pre&gt;&lt;br /&gt;public static boolean isPalindrome(String text){&lt;br /&gt;  //Sets an index at the far left of the word or phrase&lt;br /&gt;  int leftIndex = 0;&lt;br /&gt;&lt;br /&gt;  //Converts input text into lower case and remove&lt;br /&gt;  //any single non-alphanumeric and underscore&lt;br /&gt;  text = text.toLowerCase().replaceAll("[\\W\\_*]", "");&lt;br /&gt;&lt;br /&gt;  //Sets an index at the far right of the word or phrase&lt;br /&gt;  int rightIndex = text.length()-1;&lt;br /&gt;  while (leftIndex &lt; rightIndex) {&lt;br /&gt;    if (!(text.charAt(leftIndex) == text.charAt(rightIndex))) {&lt;br /&gt;      //returns a false and get out from the while loop&lt;br /&gt;      return false;&lt;br /&gt;    }&lt;br /&gt;&lt;br /&gt;    //gets the indexes from both sides closer&lt;br /&gt;    leftIndex++;&lt;br /&gt;    rightIndex--; &lt;br /&gt;  }&lt;br /&gt;  //returns a true if all the characters mirrors to each other&lt;br /&gt;  return true;&lt;br /&gt;}&lt;br /&gt;&lt;/pre&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4844902456784005421-3846943741806950211?l=nicholaskey.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://nicholaskey.blogspot.com/feeds/3846943741806950211/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://nicholaskey.blogspot.com/2009/05/palindrome.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4844902456784005421/posts/default/3846943741806950211'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4844902456784005421/posts/default/3846943741806950211'/><link rel='alternate' type='text/html' href='http://nicholaskey.blogspot.com/2009/05/palindrome.html' title='Palindrome'/><author><name>Nicholas Key</name><uri>http://www.blogger.com/profile/05768297019453812096</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='http://4.bp.blogspot.com/_OQU38yb-Uq0/SwL5VBlHCII/AAAAAAAAA6U/lXUy53mS7gQ/S220/hamster.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4844902456784005421.post-4982096601115854844</id><published>2009-05-01T23:56:00.001-07:00</published><updated>2011-08-03T06:15:31.166-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Java'/><category scheme='http://www.blogger.com/atom/ns#' term='Trivia'/><title type='text'>Truncating a sentence</title><content type='html'>Here is something that we often ask ourselves how do we truncate a sentence and then append it with a trailing "...". We see this in articles, newspapers, texts in television advertisements. I am suggesting a method that might be useful for front-end developers to truncate the sentences pulled out from the database.&lt;br /&gt;&lt;pre&gt;&lt;br /&gt;public static String truncate(String text, int length) {&lt;br /&gt;  return (text.length() &lt;= length) ? text : text.substring(0, length) + " ...";&lt;br /&gt;}&lt;br /&gt;&lt;/pre&gt;Simple isn't it? The use of this static method allows you to set a maximum length of the sentence to be truncated and then append it with the trailing "...".&lt;br /&gt;&lt;span style="font-weight:bold;color:red;"&gt;Update:&lt;/span&gt; The code is also available in Python in &lt;a href="http://nicholaskey.blogspot.com/2009/10/my-java-codes-in-python-part-2.html"&gt;this entry&lt;/a&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4844902456784005421-4982096601115854844?l=nicholaskey.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://nicholaskey.blogspot.com/feeds/4982096601115854844/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://nicholaskey.blogspot.com/2009/05/truncating-sentence.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4844902456784005421/posts/default/4982096601115854844'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4844902456784005421/posts/default/4982096601115854844'/><link rel='alternate' type='text/html' href='http://nicholaskey.blogspot.com/2009/05/truncating-sentence.html' title='Truncating a sentence'/><author><name>Nicholas Key</name><uri>http://www.blogger.com/profile/05768297019453812096</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='http://4.bp.blogspot.com/_OQU38yb-Uq0/SwL5VBlHCII/AAAAAAAAA6U/lXUy53mS7gQ/S220/hamster.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4844902456784005421.post-5857953088407713452</id><published>2009-04-27T22:20:00.001-07:00</published><updated>2011-08-03T06:39:04.454-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Java'/><category scheme='http://www.blogger.com/atom/ns#' term='Algorithms'/><category scheme='http://www.blogger.com/atom/ns#' term='Trivia'/><title type='text'>The hopping grasshopper</title><content type='html'>I came across this quiz from the Internet (credits go to whoever prepared this question) and thought of giving it a try. The question is as follow: &lt;br /&gt;&lt;br /&gt;A grasshopper is hopping forth and back in the field. Each time it hops, the distance is equal to the number of the hop. So for the first hop the distance is one unit, the second hop the distance is two units etc. However, the grasshopper would not hop back if it will otherwise land beyond the origin where it has started.&lt;br /&gt;&lt;br /&gt;Your task is to write a program to determine whether the grasshopper can be N units from where it begins if it makes N hops, and the number of hopping patterns.&lt;br /&gt;&lt;br /&gt;The following diagram shows that for 4 hops, there is only one possible hopping pattern.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight:bold;"&gt;Input:&lt;/span&gt; An integer not more than 25.&lt;br /&gt;&lt;span style="font-weight:bold;"&gt;Output:&lt;/span&gt; The number of hopping patterns or zero if no such hop pattern is possible for the given input number.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight:bold;"&gt;Sample Input:&lt;/span&gt; 4&lt;br /&gt;&lt;span style="font-weight:bold;"&gt;Sample Output:&lt;/span&gt; 1&lt;br /&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://1.bp.blogspot.com/_OQU38yb-Uq0/SgJEkz8J8SI/AAAAAAAAA0M/gaPQ26i6Up0/s1600-h/grasshopper.png"&gt;&lt;img style="display:block; margin:0px auto 10px; text-align:center;cursor:pointer; cursor:hand;width: 320px; height: 162px;" src="http://1.bp.blogspot.com/_OQU38yb-Uq0/SgJEkz8J8SI/AAAAAAAAA0M/gaPQ26i6Up0/s320/grasshopper.png" border="0" alt=""id="BLOGGER_PHOTO_ID_5332900307968586018" /&gt;&lt;/a&gt;Here's my solution to the trivia. It may be perfect, it may be not. Please feel free to drop a comment if you feel there is a simpler way to solve this.&lt;br /&gt;&lt;pre&gt;&lt;br /&gt;public static int hop(int numberOfHops){  &lt;br /&gt;  int hopCount = 1;&lt;br /&gt;  int unitCount = 0;&lt;br /&gt;  int pattern = 0;&lt;br /&gt;  int currentIndex = 0; &lt;br /&gt;&lt;br /&gt;  if (numberOfHops &lt; 1 || numberOfHops &gt; 25) {&lt;br /&gt;    //returns a 0 if the supplied input is more than 25 &lt;br /&gt;    //or less than 1&lt;br /&gt;    return 0;&lt;br /&gt;  }&lt;br /&gt;&lt;br /&gt;  while (hopCount &lt;= numberOfHops) {   &lt;br /&gt;    unitCount = unitCount + 1;&lt;br /&gt;    currentIndex = currentIndex + unitCount;&lt;br /&gt;    if (currentIndex &gt; numberOfHops) {&lt;br /&gt;      //bounces back the grasshopper if it is about to&lt;br /&gt;      //hop out of bound from the current spot&lt;br /&gt;      currentIndex = currentIndex - (unitCount*2);&lt;br /&gt;    }&lt;br /&gt;    if (hopCount == numberOfHops) {&lt;br /&gt;      if (currentIndex == numberOfHops) {&lt;br /&gt;        pattern++;&lt;br /&gt;      }&lt;br /&gt;    }   &lt;br /&gt;    hopCount++;&lt;br /&gt;  }&lt;br /&gt;  return pattern;&lt;br /&gt;} &lt;br /&gt;&lt;/pre&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4844902456784005421-5857953088407713452?l=nicholaskey.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://nicholaskey.blogspot.com/feeds/5857953088407713452/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://nicholaskey.blogspot.com/2009/04/hopping-grasshopper-happily-away.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4844902456784005421/posts/default/5857953088407713452'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4844902456784005421/posts/default/5857953088407713452'/><link rel='alternate' type='text/html' href='http://nicholaskey.blogspot.com/2009/04/hopping-grasshopper-happily-away.html' title='The hopping grasshopper'/><author><name>Nicholas Key</name><uri>http://www.blogger.com/profile/05768297019453812096</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='http://4.bp.blogspot.com/_OQU38yb-Uq0/SwL5VBlHCII/AAAAAAAAA6U/lXUy53mS7gQ/S220/hamster.jpg'/></author><media:thumbnail xmlns:media='http://search.yahoo.com/mrss/' url='http://1.bp.blogspot.com/_OQU38yb-Uq0/SgJEkz8J8SI/AAAAAAAAA0M/gaPQ26i6Up0/s72-c/grasshopper.png' height='72' width='72'/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4844902456784005421.post-2807105878736364172</id><published>2009-04-24T00:25:00.000-07:00</published><updated>2011-08-03T00:50:11.169-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Java'/><category scheme='http://www.blogger.com/atom/ns#' term='Algorithms'/><category scheme='http://www.blogger.com/atom/ns#' term='Trivia'/><title type='text'>The Whitespace Stripper</title><content type='html'>This is yet another method written in Java that deals with string manipulations. I have written a method that returns the same result of the regular expression [\s*]. The regular expression "[\s*]" translated into plain English is "Match 0 or more of the preceeding whitespace character (spaces, tabs, line breaks) in the set".&lt;br /&gt;&lt;br /&gt;Below is the suggested solution in Java to strip off whitespace characters without using regular expressions. The code itself is quite straight forward. "NicholasKey" will be returned as the result of this method with the given input "Nicholas Key".&lt;br /&gt;&lt;pre&gt;&lt;br /&gt;public static String stripWhiteSpace(String text){&lt;br /&gt;  StringBuffer cleanText = new StringBuffer();&lt;br /&gt;  int len = text.length();&lt;br /&gt;  for (int i=0; i&amp;lt;len; i++) {&lt;br /&gt;    if (text.charAt(i) != ' ') {&lt;br /&gt;      cleanText.append(text.charAt(i));&lt;br /&gt;    }&lt;br /&gt;  } &lt;br /&gt;  return cleanText.toString();&lt;br /&gt;}&lt;br /&gt;&lt;/pre&gt;&lt;span style="font-weight:bold;color:red;"&gt;Update:&lt;/span&gt; The code is also available in Python in &lt;a href="http://nicholaskey.blogspot.com/2009/10/my-java-codes-in-python-part-2.html"&gt;this entry&lt;/a&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4844902456784005421-2807105878736364172?l=nicholaskey.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://nicholaskey.blogspot.com/feeds/2807105878736364172/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://nicholaskey.blogspot.com/2009/04/whitespace-stripper.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4844902456784005421/posts/default/2807105878736364172'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4844902456784005421/posts/default/2807105878736364172'/><link rel='alternate' type='text/html' href='http://nicholaskey.blogspot.com/2009/04/whitespace-stripper.html' title='The Whitespace Stripper'/><author><name>Nicholas Key</name><uri>http://www.blogger.com/profile/05768297019453812096</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='http://4.bp.blogspot.com/_OQU38yb-Uq0/SwL5VBlHCII/AAAAAAAAA6U/lXUy53mS7gQ/S220/hamster.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4844902456784005421.post-9137183014784658925</id><published>2009-04-22T23:12:00.000-07:00</published><updated>2011-08-03T00:48:54.329-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Java'/><category scheme='http://www.blogger.com/atom/ns#' term='Algorithms'/><title type='text'>Finding a substring in a string</title><content type='html'>&lt;pre&gt;&lt;br /&gt;public static boolean substr(String inputStr, String subStr){&lt;br /&gt;  int length = inputStr.length();&lt;br /&gt;  int index = 0;&lt;br /&gt;  int check = 0;&lt;br /&gt;  boolean found = false;&lt;br /&gt;  StringBuffer newString = new StringBuffer();&lt;br /&gt;  while (index &lt; length) {&lt;br /&gt;    try {&lt;br /&gt;      if (inputStr.charAt(index) == subStr.charAt(check)) {&lt;br /&gt;        newString.append(inputStr.charAt(index));&lt;br /&gt;        check++;&lt;br /&gt;        if (newString.toString().equals(subStr)) {&lt;br /&gt;          found = true;&lt;br /&gt;          break;&lt;br /&gt;        }&lt;br /&gt;      }&lt;br /&gt;    } catch (Exception ex){}&lt;br /&gt;    index++;&lt;br /&gt;  }&lt;br /&gt;  return found;&lt;br /&gt;}&lt;br /&gt;&lt;/pre&gt;&lt;span style="font-weight:bold;color:red;"&gt;Update:&lt;/span&gt; The code is also available in Python in &lt;a href="http://nicholaskey.blogspot.com/2009/10/my-java-codes-in-python-part-2.html"&gt;this entry&lt;/a&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4844902456784005421-9137183014784658925?l=nicholaskey.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://nicholaskey.blogspot.com/feeds/9137183014784658925/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://nicholaskey.blogspot.com/2009/04/finding-substring-in-string.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4844902456784005421/posts/default/9137183014784658925'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4844902456784005421/posts/default/9137183014784658925'/><link rel='alternate' type='text/html' href='http://nicholaskey.blogspot.com/2009/04/finding-substring-in-string.html' title='Finding a substring in a string'/><author><name>Nicholas Key</name><uri>http://www.blogger.com/profile/05768297019453812096</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='http://4.bp.blogspot.com/_OQU38yb-Uq0/SwL5VBlHCII/AAAAAAAAA6U/lXUy53mS7gQ/S220/hamster.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4844902456784005421.post-8350319546403098168</id><published>2009-04-22T22:56:00.000-07:00</published><updated>2011-08-03T00:46:54.343-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Java'/><category scheme='http://www.blogger.com/atom/ns#' term='Algorithms'/><title type='text'>Is this a square?</title><content type='html'>Simple method to compute if a given integer is a square. It's a O(n) algorithm as it steps through each number and multiplies itself.&lt;br /&gt;&lt;pre&gt;&lt;br /&gt;public static boolean isSquare(int input){&lt;br /&gt;  int pow = 1;&lt;br /&gt;  int result = 0;&lt;br /&gt;  while (true){&lt;br /&gt;    result = pow * pow;&lt;br /&gt;    if (result == input){&lt;br /&gt;      return true;&lt;br /&gt;    } else if (result &gt; input) {&lt;br /&gt;      return false;&lt;br /&gt;    }&lt;br /&gt;    pow++;&lt;br /&gt;  }&lt;br /&gt;}&lt;br /&gt;&lt;/pre&gt;The "else if" condition is extremely important so that we won't end up in an infinite loop.&lt;br /&gt;&lt;span style="font-weight:bold;color:red;"&gt;Update:&lt;/span&gt; The code is also available in Python in &lt;a href="http://nicholaskey.blogspot.com/2009/10/my-java-codes-in-python.html"&gt;this entry&lt;/a&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4844902456784005421-8350319546403098168?l=nicholaskey.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://nicholaskey.blogspot.com/feeds/8350319546403098168/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://nicholaskey.blogspot.com/2009/04/is-this-square.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4844902456784005421/posts/default/8350319546403098168'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4844902456784005421/posts/default/8350319546403098168'/><link rel='alternate' type='text/html' href='http://nicholaskey.blogspot.com/2009/04/is-this-square.html' title='Is this a square?'/><author><name>Nicholas Key</name><uri>http://www.blogger.com/profile/05768297019453812096</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='http://4.bp.blogspot.com/_OQU38yb-Uq0/SwL5VBlHCII/AAAAAAAAA6U/lXUy53mS7gQ/S220/hamster.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4844902456784005421.post-2209027409919432831</id><published>2009-04-22T00:07:00.000-07:00</published><updated>2011-08-03T00:45:25.649-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Java'/><category scheme='http://www.blogger.com/atom/ns#' term='Trivia'/><title type='text'>Null or not null or empty</title><content type='html'>This is something very common among developers and could be quite handy in the event they want to check if a string is empty or null. I have written a simple static Java method that returns a boolean value if an input string is empty and I hope this is useful to other developers.&lt;br /&gt;&lt;pre&gt;&lt;br /&gt;public static boolean isEmpty(String inputText) {&lt;br /&gt;  return (inputText.trim().length() == 0 || inputText == null || inputText.trim().equals(""));&lt;br /&gt;}&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;I think the code is self-explanatory and does not require much elaboration. The return statement consists of two OR conditionals so that a boolean value true is returned in the event either one of the conditions is satisfied . The trim() method is used to remove leading and trailing white spaces if there are any. This method is too simple not to be forgotten.&lt;br /&gt;&lt;br /&gt;On a second thought, a NullPointerException will be thrown if a null string is given. Because the statement is read from left-to-right, it is reasonable to first check if the string is null instead of trimming it and then get the length of the string. The suggested modified code would look like this.&lt;br /&gt;&lt;pre&gt;&lt;br /&gt;public static boolean isEmpty(String inputText) {&lt;br /&gt;  return (inputText == null || inputText.trim().length() == 0 || inputText.trim().equals(""));&lt;br /&gt;}&lt;br /&gt;&lt;/pre&gt;&lt;span style="font-weight:bold;color:red;"&gt;Update:&lt;/span&gt; The code is also available in Python in &lt;a href="http://nicholaskey.blogspot.com/2009/10/my-java-codes-in-python.html"&gt;this entry&lt;/a&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4844902456784005421-2209027409919432831?l=nicholaskey.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://nicholaskey.blogspot.com/feeds/2209027409919432831/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://nicholaskey.blogspot.com/2009/04/my-first-address-to-world.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4844902456784005421/posts/default/2209027409919432831'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4844902456784005421/posts/default/2209027409919432831'/><link rel='alternate' type='text/html' href='http://nicholaskey.blogspot.com/2009/04/my-first-address-to-world.html' title='Null or not null or empty'/><author><name>Nicholas Key</name><uri>http://www.blogger.com/profile/05768297019453812096</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='http://4.bp.blogspot.com/_OQU38yb-Uq0/SwL5VBlHCII/AAAAAAAAA6U/lXUy53mS7gQ/S220/hamster.jpg'/></author><thr:total>0</thr:total></entry></feed>
