<?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-3946478681282550454</id><updated>2012-01-23T06:38:04.061+05:30</updated><title type='text'>Som's Tech World...</title><subtitle type='html'>This is my own world of software and technologies...</subtitle><link rel='http://schemas.google.com/g/2005#feed' type='application/atom+xml' href='http://som-itsolutions.blogspot.com/feeds/posts/default'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3946478681282550454/posts/default?max-results=100'/><link rel='alternate' type='text/html' href='http://som-itsolutions.blogspot.com/'/><link rel='hub' href='http://pubsubhubbub.appspot.com/'/><author><name>Som</name><uri>http://www.blogger.com/profile/09519633424407534012</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='24' src='http://3.bp.blogspot.com/-XVhL110Tyf8/ThxKF3DBYcI/AAAAAAAAEBo/arVXUPsgtSg/s220/NJ%2B042.JPG'/></author><generator version='7.00' uri='http://www.blogger.com'>Blogger</generator><openSearch:totalResults>64</openSearch:totalResults><openSearch:startIndex>1</openSearch:startIndex><openSearch:itemsPerPage>100</openSearch:itemsPerPage><entry><id>tag:blogger.com,1999:blog-3946478681282550454.post-9099244561083753528</id><published>2012-01-17T06:59:00.006+05:30</published><updated>2012-01-23T06:38:04.071+05:30</updated><title type='text'>FFT based simple Spectrum Analyzer</title><content type='html'>&lt;div dir="ltr" style="text-align: left;" trbidi="on"&gt;i am writing this blogpost to pay homage to my alma mater... i was not at my level best to understand all aspects of Electonics &amp;amp; Telecommunication, the Microprocessor, the Digital Communication, the Digital Signal processing as taught by my professors... however, after so many years while playing around with different software, i understand how valuable was their contribution to make me an engineer. i remember, how important was the lesson of digital communication, and digital signal processing taught by Dr. T.K.Sen... i remember how important was the lesson of Microprocessor taught by A.R.... i remember how important was the lectures of Maths during our engineering course... i remember how important were the concepts of Fourier Transformation, FFT, DFT, Laplace Transformation, Matrix algebra and Complex Algebra...Hats off to all those professors who in spite of all odds helped a small town boy see the outer world...&lt;br /&gt;&lt;br /&gt;&lt;a href="https://docs.google.com/open?id=0B8L15NA4lO_UZGMwNjE3ZTQtMDAzOC00ODc5LWE5NmUtYjFhNmVkMjNjMWZl"&gt;Here&lt;/a&gt; goes the apk of my FFT based&amp;nbsp;simple&amp;nbsp;Spectrum Analyzer for an Android device with a sampling frequency of 8 KHz and audio encoding as 16 bit PCM...&lt;br /&gt;&lt;br /&gt;i was so excited when i finished the coding part (of course with the help of Google...) and saw its working on a real device...&lt;br /&gt;&lt;br /&gt;here are the two screenshots i have taken from an Android device...&lt;br /&gt;&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://3.bp.blogspot.com/-jbzoXtu2H2E/TxUo8DZthEI/AAAAAAAAEGg/tDlr6D0eiEo/s1600/SoundRecordAndAnalysis1.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img border="0" src="http://3.bp.blogspot.com/-jbzoXtu2H2E/TxUo8DZthEI/AAAAAAAAEGg/tDlr6D0eiEo/s1600/SoundRecordAndAnalysis1.png" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://2.bp.blogspot.com/-fMQ00V8APUY/TxUpNSrBESI/AAAAAAAAEGw/38J4Jt7Gdbk/s1600/SoundRecordAndAnalysis2.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img border="0" src="http://2.bp.blogspot.com/-fMQ00V8APUY/TxUpNSrBESI/AAAAAAAAEGw/38J4Jt7Gdbk/s1600/SoundRecordAndAnalysis2.png" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;/div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3946478681282550454-9099244561083753528?l=som-itsolutions.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://som-itsolutions.blogspot.com/feeds/9099244561083753528/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=3946478681282550454&amp;postID=9099244561083753528' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3946478681282550454/posts/default/9099244561083753528'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3946478681282550454/posts/default/9099244561083753528'/><link rel='alternate' type='text/html' href='http://som-itsolutions.blogspot.com/2012/01/fft-based-simple-spectrum-analyzer.html' title='FFT based simple Spectrum Analyzer'/><author><name>Som</name><uri>http://www.blogger.com/profile/09519633424407534012</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='24' src='http://3.bp.blogspot.com/-XVhL110Tyf8/ThxKF3DBYcI/AAAAAAAAEBo/arVXUPsgtSg/s220/NJ%2B042.JPG'/></author><media:thumbnail xmlns:media='http://search.yahoo.com/mrss/' url='http://3.bp.blogspot.com/-jbzoXtu2H2E/TxUo8DZthEI/AAAAAAAAEGg/tDlr6D0eiEo/s72-c/SoundRecordAndAnalysis1.png' height='72' width='72'/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3946478681282550454.post-4948815206875104103</id><published>2011-12-21T09:08:00.002+05:30</published><updated>2011-12-21T09:25:02.586+05:30</updated><title type='text'>How to set up proxy for Android emulator behind a firewall...</title><content type='html'>&lt;div dir="ltr" style="text-align: left;" trbidi="on"&gt;&lt;br /&gt;&lt;div style="background-color: transparent;"&gt;&lt;span id="internal-source-marker_0.7650847886689007"&gt;&lt;/span&gt;&lt;br /&gt;&lt;div&gt;&lt;span id="internal-source-marker_0.7650847886689007"&gt;&lt;span class="Apple-style-span" style="font-family: Arial;"&gt;&lt;span class="Apple-style-span" style="font-size: 15px; white-space: pre-wrap;"&gt;Here is how i had set up my emulator's network settings for browsing the internet on a &lt;b&gt;Windows 7 &lt;/b&gt;machine. for linux the same principle applies...&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;ul&gt;&lt;li style="background-color: transparent; font-family: Arial; font-size: 15px; font-style: normal; font-variant: normal; list-style-type: disc; text-decoration: none; vertical-align: baseline;"&gt;&lt;span id="internal-source-marker_0.7650847886689007"&gt;&lt;span style="background-color: transparent; font-family: Arial; font-size: 15px; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"&gt;Make the emulator pass through the firewall&lt;/span&gt;&lt;/span&gt;&lt;/li&gt;&lt;span id="internal-source-marker_0.7650847886689007"&gt;&lt;li style="background-color: transparent; font-family: Arial; font-size: 15px; font-style: normal; font-variant: normal; list-style-type: disc; text-decoration: none; vertical-align: baseline;"&gt;&lt;span style="background-color: transparent; font-family: Arial; font-size: 15px; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"&gt;if you are behind a proxy go to settings and set up your proxy for the emulator through the following steps-&lt;/span&gt;&lt;/li&gt;&lt;/span&gt;&lt;/ul&gt;&lt;div&gt;&lt;ol style="text-align: left;"&gt;&lt;li&gt;&lt;span id="internal-source-marker_0.7650847886689007"&gt;&lt;span class="Apple-style-span" style="font-family: Arial;"&gt;&lt;span class="Apple-style-span" style="font-size: 15px; white-space: pre-wrap;"&gt;&lt;i&gt;Open the emulator and click on Menu&lt;/i&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/li&gt;&lt;span id="internal-source-marker_0.7650847886689007"&gt;&lt;li&gt;&lt;span class="Apple-style-span" style="font-family: Arial;"&gt;&lt;span class="Apple-style-span" style="font-size: 15px; white-space: pre-wrap;"&gt;&lt;i&gt;Click on Settings&lt;/i&gt;&lt;/span&gt;&lt;/span&gt;&lt;/li&gt;&lt;li&gt;&lt;span class="Apple-style-span" style="font-family: Arial;"&gt;&lt;span class="Apple-style-span" style="font-size: 15px; white-space: pre-wrap;"&gt;&lt;i&gt;Click on Wireless &amp;amp; Networks&lt;/i&gt;&lt;/span&gt;&lt;/span&gt;&lt;/li&gt;&lt;li&gt;&lt;span class="Apple-style-span" style="font-family: Arial;"&gt;&lt;span class="Apple-style-span" style="font-size: 15px; white-space: pre-wrap;"&gt;&lt;i&gt;Go to Mobile Networks&lt;/i&gt;&lt;/span&gt;&lt;/span&gt;&lt;/li&gt;&lt;li&gt;&lt;span class="Apple-style-span" style="font-family: Arial;"&gt;&lt;span class="Apple-style-span" style="font-size: 15px; white-space: pre-wrap;"&gt;&lt;i&gt;Go to Access Point Names and click on it&lt;/i&gt;&lt;/span&gt;&lt;/span&gt;&lt;/li&gt;&lt;li&gt;&lt;span class="Apple-style-span" style="font-family: Arial;"&gt;&lt;span class="Apple-style-span" style="font-size: 15px; white-space: pre-wrap;"&gt;&lt;i&gt;Click on Telkila Internet&lt;/i&gt;&lt;/span&gt;&lt;/span&gt;&lt;/li&gt;&lt;li&gt;&lt;span class="Apple-style-span" style="font-family: Arial;"&gt;&lt;span class="Apple-style-span" style="font-size: 15px; white-space: pre-wrap;"&gt;&lt;i&gt;In the Edit Access Point, input Proxy server and Port&lt;/i&gt;&lt;/span&gt;&lt;/span&gt;&lt;/li&gt;&lt;li&gt;&lt;span class="Apple-style-span" style="font-family: Arial;"&gt;&lt;span class="Apple-style-span" style="font-size: 15px; white-space: pre-wrap;"&gt;&lt;i&gt;Also provide the User Name and Password&lt;/i&gt;&lt;/span&gt;&lt;/span&gt;&lt;/li&gt;&lt;li&gt;&lt;span class="Apple-style-span" style="font-family: Arial;"&gt;&lt;span class="Apple-style-span" style="font-size: 15px; white-space: pre-wrap;"&gt;&lt;i&gt;Keep rest of the fields blank&lt;/i&gt;&lt;/span&gt;&lt;/span&gt;&lt;/li&gt;&lt;/span&gt;&lt;/ol&gt;&lt;/div&gt;&lt;span id="internal-source-marker_0.7650847886689007"&gt;&lt;span style="background-color: transparent; font-family: Arial; font-size: 15px; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"&gt;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;ul&gt;&lt;li style="background-color: transparent; font-family: Arial; font-size: 15px; font-style: normal; font-variant: normal; list-style-type: disc; text-decoration: none; vertical-align: baseline;"&gt;&lt;span id="internal-source-marker_0.7650847886689007"&gt;&lt;span style="background-color: transparent; font-family: Arial; font-size: 15px; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"&gt;Sometimes the DNS of the host PC is not recognized by the emulator... &amp;nbsp;in that case use the following command in the command prompt...&lt;/span&gt;&lt;span class="Apple-style-span" style="font-family: 'Times New Roman'; font-size: small;"&gt;&lt;span style="background-color: transparent; font-family: Arial; font-size: 15px; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"&gt;emulator -avd &lt;give device="" here="" name="" the="" virtual=""&gt;-dns -server 8.8.8.8 (8.8.8.8 is the Googles default DNS) and change the DNS server of your machine to 8.8.8.8.&lt;/give&gt;&lt;/span&gt;&amp;nbsp;otherwise you may opt for the DNS your company is using in the emulator -avd -dns -server command...&lt;/span&gt;&lt;/span&gt;&lt;/li&gt;&lt;span id="internal-source-marker_0.7650847886689007"&gt; &lt;/span&gt;&lt;/ul&gt;&lt;div&gt;&lt;span id="internal-source-marker_0.7650847886689007" style="font-family: Arial, Helvetica, sans-serif;"&gt;Hope this discussion comes handy for the Android newbies...&lt;/span&gt;&lt;/div&gt;&lt;div dir="ltr" style="margin-bottom: 0pt; margin-left: 36pt; margin-top: 0pt; text-indent: 36pt;"&gt;&lt;div style="text-align: left;"&gt;&lt;span id="internal-source-marker_0.7650847886689007"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3946478681282550454-4948815206875104103?l=som-itsolutions.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://som-itsolutions.blogspot.com/feeds/4948815206875104103/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=3946478681282550454&amp;postID=4948815206875104103' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3946478681282550454/posts/default/4948815206875104103'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3946478681282550454/posts/default/4948815206875104103'/><link rel='alternate' type='text/html' href='http://som-itsolutions.blogspot.com/2011/12/how-to-set-up-proxy-for-android.html' title='How to set up proxy for Android emulator behind a firewall...'/><author><name>Som</name><uri>http://www.blogger.com/profile/09519633424407534012</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='24' src='http://3.bp.blogspot.com/-XVhL110Tyf8/ThxKF3DBYcI/AAAAAAAAEBo/arVXUPsgtSg/s220/NJ%2B042.JPG'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3946478681282550454.post-3203454587379079429</id><published>2011-11-21T19:12:00.004+05:30</published><updated>2011-11-23T18:57:56.537+05:30</updated><title type='text'>An implementation of Finite State Machine in Android using Handler...</title><content type='html'>&lt;div dir="ltr" style="text-align: left;" trbidi="on"&gt;&lt;span class="Apple-style-span" style="font-family: Arial; font-size: 15px; white-space: pre-wrap;"&gt;As i was doing some research on different concepts in Android, i came out with this implementation of Finite State Machine using the Handler class... i would like to share it with you... the state diagram of the application will look as the following:&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="font-family: Arial; font-size: 15px; white-space: pre-wrap;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://2.bp.blogspot.com/-RsxPyEZrF6g/TsuF85DT_mI/AAAAAAAAEGQ/TFoUstf9OPA/s1600/State+Machine.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img border="0" height="133" src="http://2.bp.blogspot.com/-RsxPyEZrF6g/TsuF85DT_mI/AAAAAAAAEGQ/TFoUstf9OPA/s320/State+Machine.png" width="320" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;span class="Apple-style-span" style="font-family: Arial; font-size: 15px; white-space: pre-wrap;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;&lt;div style="background-color: transparent;"&gt;&lt;span id="internal-source-marker_0.2987896231934428" style="background-color: transparent; font-family: Arial; font-size: 15px; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"&gt; &lt;/span&gt;&lt;/div&gt;&lt;div style="background-color: transparent;"&gt;&lt;span id="internal-source-marker_0.2987896231934428" style="background-color: transparent; font-family: Arial; font-size: 15px; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"&gt;The main Activity class looks like the following:&lt;/span&gt;&lt;/div&gt;&lt;div style="background-color: transparent;"&gt;&lt;br /&gt;&lt;div style="background-color: transparent;"&gt;&lt;span style="background-color: transparent; font-family: Arial; font-size: 15px; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"&gt;package com.android.training.statepattern;&lt;/span&gt;&lt;br /&gt;&lt;span style="background-color: transparent; font-family: Arial; font-size: 15px; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="background-color: transparent; font-family: Arial; font-size: 15px; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"&gt;import android.app.Activity;&lt;/span&gt;&lt;br /&gt;&lt;span style="background-color: transparent; font-family: Arial; font-size: 15px; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"&gt;import android.os.Bundle;&lt;/span&gt;&lt;br /&gt;&lt;span style="background-color: transparent; font-family: Arial; font-size: 15px; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"&gt;import android.view.View;&lt;/span&gt;&lt;br /&gt;&lt;span style="background-color: transparent; font-family: Arial; font-size: 15px; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"&gt;import android.widget.Button;&lt;/span&gt;&lt;br /&gt;&lt;span style="background-color: transparent; font-family: Arial; font-size: 15px; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="background-color: transparent; font-family: Arial; font-size: 15px; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="background-color: transparent; font-family: Arial; font-size: 15px; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"&gt;public class StatePatternActivity extends Activity implements View.OnClickListener{&lt;/span&gt;&lt;br /&gt;&lt;span style="background-color: transparent; font-family: Arial; font-size: 15px; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"&gt;&lt;span class="Apple-tab-span" style="white-space: pre;"&gt; &lt;/span&gt;private Button startStatePattern;&lt;/span&gt;&lt;br /&gt;&lt;span style="background-color: transparent; font-family: Arial; font-size: 15px; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"&gt;&lt;span class="Apple-tab-span" style="white-space: pre;"&gt; &lt;/span&gt;private MyHandler handler;&lt;/span&gt;&lt;br /&gt;&lt;span style="background-color: transparent; font-family: Arial; font-size: 15px; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"&gt; &amp;nbsp;&amp;nbsp;&amp;nbsp;/** Called when the activity is first created. */&lt;/span&gt;&lt;br /&gt;&lt;span style="background-color: transparent; font-family: Arial; font-size: 15px; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"&gt; &amp;nbsp;&amp;nbsp;&amp;nbsp;@Override&lt;/span&gt;&lt;br /&gt;&lt;span style="background-color: transparent; font-family: Arial; font-size: 15px; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"&gt; &amp;nbsp;&amp;nbsp;&amp;nbsp;public void onCreate(Bundle savedInstanceState) {&lt;/span&gt;&lt;br /&gt;&lt;span style="background-color: transparent; font-family: Arial; font-size: 15px; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"&gt; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;super.onCreate(savedInstanceState);&lt;/span&gt;&lt;br /&gt;&lt;span style="background-color: transparent; font-family: Arial; font-size: 15px; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"&gt; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;setContentView(R.layout.main);&lt;/span&gt;&lt;br /&gt;&lt;span style="background-color: transparent; font-family: Arial; font-size: 15px; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"&gt; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;br /&gt;&lt;span style="background-color: transparent; font-family: Arial; font-size: 15px; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"&gt; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;startStatePattern = (Button)findViewById(R.id.button1);&lt;/span&gt;&lt;br /&gt;&lt;span style="background-color: transparent; font-family: Arial; font-size: 15px; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"&gt; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;br /&gt;&lt;span style="background-color: transparent; font-family: Arial; font-size: 15px; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"&gt; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;startStatePattern.setOnClickListener(this);&lt;/span&gt;&lt;br /&gt;&lt;span style="background-color: transparent; font-family: Arial; font-size: 15px; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"&gt; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;handler = new MyHandler(this);&lt;/span&gt;&lt;br /&gt;&lt;span style="background-color: transparent; font-family: Arial; font-size: 15px; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"&gt; &amp;nbsp;&amp;nbsp;&amp;nbsp;}&lt;/span&gt;&lt;br /&gt;&lt;span style="background-color: transparent; font-family: Arial; font-size: 15px; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"&gt; &amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;br /&gt;&lt;span style="background-color: transparent; font-family: Arial; font-size: 15px; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"&gt; &amp;nbsp;&amp;nbsp;&amp;nbsp;public void onClick(View v){&lt;/span&gt;&lt;br /&gt;&lt;span style="background-color: transparent; font-family: Arial; font-size: 15px; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"&gt; &amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span class="Apple-tab-span" style="white-space: pre;"&gt; &lt;/span&gt;if(v.equals(startStatePattern)){&lt;/span&gt;&lt;br /&gt;&lt;span style="background-color: transparent; font-family: Arial; font-size: 15px; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"&gt; &amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span class="Apple-tab-span" style="white-space: pre;"&gt; &lt;/span&gt;&lt;span class="Apple-tab-span" style="white-space: pre;"&gt; &lt;/span&gt;handler.sendEmptyMessage(1);&lt;/span&gt;&lt;br /&gt;&lt;span style="background-color: transparent; font-family: Arial; font-size: 15px; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"&gt; &amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span class="Apple-tab-span" style="white-space: pre;"&gt; &lt;/span&gt;}&lt;/span&gt;&lt;br /&gt;&lt;span style="background-color: transparent; font-family: Arial; font-size: 15px; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"&gt; &amp;nbsp;&amp;nbsp;&amp;nbsp;}&lt;/span&gt;&lt;span style="background-color: transparent; font-family: Arial; font-size: 15px; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"&gt;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;br /&gt;&lt;span style="background-color: transparent; font-family: Arial; font-size: 15px; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"&gt;}&lt;/span&gt;&lt;br /&gt;&lt;span style="background-color: transparent; font-family: Arial; font-size: 15px; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"&gt;&lt;/span&gt;&lt;span class="Apple-style-span" style="font-family: Arial;"&gt;&lt;span class="Apple-style-span" style="font-size: 15px; white-space: pre-wrap;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div style="background-color: transparent;"&gt;&lt;span style="background-color: transparent; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline;"&gt;&lt;/span&gt;&lt;span class="Apple-style-span" style="font-family: Arial;"&gt;&lt;span class="Apple-style-span" style="font-size: 15px; white-space: pre-wrap;"&gt;And the other class is as follows;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div style="background-color: transparent;"&gt;&lt;span style="background-color: transparent; font-family: Arial; font-size: 15px; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"&gt; &lt;/span&gt;&lt;/div&gt;&lt;div style="background-color: transparent;"&gt;&lt;span style="background-color: transparent; font-family: Arial; font-size: 15px; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"&gt;package com.android.training.statepattern;&lt;/span&gt;&lt;br /&gt;&lt;span style="background-color: transparent; font-family: Arial; font-size: 15px; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="background-color: transparent; font-family: Arial; font-size: 15px; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"&gt;import android.os.Handler;&lt;/span&gt;&lt;br /&gt;&lt;span style="background-color: transparent; font-family: Arial; font-size: 15px; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"&gt;import android.os.Message;&lt;/span&gt;&lt;br /&gt;&lt;span style="background-color: transparent; font-family: Arial; font-size: 15px; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"&gt;import android.widget.Toast;&lt;/span&gt;&lt;br /&gt;&lt;span style="background-color: transparent; font-family: Arial; font-size: 15px; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="background-color: transparent; font-family: Arial; font-size: 15px; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"&gt;public class MyHandler extends Handler {&lt;/span&gt;&lt;br /&gt;&lt;span style="background-color: transparent; font-family: Arial; font-size: 15px; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"&gt;&lt;span class="Apple-tab-span" style="white-space: pre;"&gt; &lt;/span&gt;private StatePatternActivity MainActivity;&lt;/span&gt;&lt;br /&gt;&lt;span style="background-color: transparent; font-family: Arial; font-size: 15px; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"&gt;&lt;span class="Apple-tab-span" style="white-space: pre;"&gt; &lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="background-color: transparent; font-family: Arial; font-size: 15px; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"&gt;&lt;span class="Apple-tab-span" style="white-space: pre;"&gt; &lt;/span&gt;MyHandler(StatePatternActivity a){&lt;/span&gt;&lt;br /&gt;&lt;span style="background-color: transparent; font-family: Arial; font-size: 15px; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"&gt;&lt;span class="Apple-tab-span" style="white-space: pre;"&gt; &lt;/span&gt;&lt;span class="Apple-tab-span" style="white-space: pre;"&gt; &lt;/span&gt;this.MainActivity = a;&lt;/span&gt;&lt;br /&gt;&lt;span style="background-color: transparent; font-family: Arial; font-size: 15px; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"&gt;&lt;span class="Apple-tab-span" style="white-space: pre;"&gt; &lt;/span&gt;}&lt;/span&gt;&lt;br /&gt;&lt;span style="background-color: transparent; font-family: Arial; font-size: 15px; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"&gt;&lt;span class="Apple-tab-span" style="white-space: pre;"&gt; &lt;/span&gt;//state transition logic is strongly coupled with the different states...&lt;/span&gt;&lt;br /&gt;&lt;span style="background-color: transparent; font-family: Arial; font-size: 15px; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"&gt;&lt;span class="Apple-tab-span" style="white-space: pre;"&gt; &lt;/span&gt; public void handleMessage(Message msg){&lt;/span&gt;&lt;br /&gt;&lt;span style="background-color: transparent; font-family: Arial; font-size: 15px; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"&gt;&lt;span class="Apple-tab-span" style="white-space: pre;"&gt; &lt;/span&gt;&lt;span class="Apple-tab-span" style="white-space: pre;"&gt; &lt;/span&gt; switch(msg.what){&lt;/span&gt;&lt;br /&gt;&lt;span style="background-color: transparent; font-family: Arial; font-size: 15px; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"&gt;&lt;span class="Apple-tab-span" style="white-space: pre;"&gt; &lt;/span&gt;&lt;span class="Apple-tab-span" style="white-space: pre;"&gt; &lt;/span&gt; case 1:&lt;/span&gt;&lt;br /&gt;&lt;span style="background-color: transparent; font-family: Arial; font-size: 15px; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"&gt;&lt;span class="Apple-tab-span" style="white-space: pre;"&gt; &lt;/span&gt;&lt;span class="Apple-tab-span" style="white-space: pre;"&gt; &lt;/span&gt;&lt;span class="Apple-tab-span" style="white-space: pre;"&gt; &lt;/span&gt; ////do the processing&lt;/span&gt;&lt;br /&gt;&lt;span style="background-color: transparent; font-family: Arial; font-size: 15px; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"&gt;&lt;span class="Apple-tab-span" style="white-space: pre;"&gt; &lt;/span&gt;&lt;span class="Apple-tab-span" style="white-space: pre;"&gt; &lt;/span&gt;&lt;span class="Apple-tab-span" style="white-space: pre;"&gt; &lt;/span&gt; Toast.makeText(MainActivity.getApplicationContext(),"Inside State 1", 2000).show();&lt;/span&gt;&lt;br /&gt;&lt;span style="background-color: transparent; font-family: Arial; font-size: 15px; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"&gt;&lt;span class="Apple-tab-span" style="white-space: pre;"&gt; &lt;/span&gt;&lt;span class="Apple-tab-span" style="white-space: pre;"&gt; &lt;/span&gt;&lt;span class="Apple-tab-span" style="white-space: pre;"&gt; &lt;/span&gt; this.sendEmptyMessage(2);&lt;/span&gt;&lt;br /&gt;&lt;span style="background-color: transparent; font-family: Arial; font-size: 15px; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"&gt;&lt;span class="Apple-tab-span" style="white-space: pre;"&gt; &lt;/span&gt;&lt;span class="Apple-tab-span" style="white-space: pre;"&gt; &lt;/span&gt;&lt;span class="Apple-tab-span" style="white-space: pre;"&gt; &lt;/span&gt; break;&lt;/span&gt;&lt;span style="background-color: transparent; font-family: Arial; font-size: 15px; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"&gt; &lt;/span&gt;&lt;br /&gt;&lt;span style="background-color: transparent; font-family: Arial; font-size: 15px; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"&gt;&lt;span class="Apple-tab-span" style="white-space: pre;"&gt; &lt;/span&gt;&lt;span class="Apple-tab-span" style="white-space: pre;"&gt; &lt;/span&gt; case 2:&lt;/span&gt;&lt;br /&gt;&lt;span style="background-color: transparent; font-family: Arial; font-size: 15px; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"&gt;&lt;span class="Apple-tab-span" style="white-space: pre;"&gt; &lt;/span&gt;&lt;span class="Apple-tab-span" style="white-space: pre;"&gt; &lt;/span&gt;&lt;span class="Apple-tab-span" style="white-space: pre;"&gt; &lt;/span&gt; ///do the processing&lt;/span&gt;&lt;br /&gt;&lt;span style="background-color: transparent; font-family: Arial; font-size: 15px; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"&gt;&lt;span class="Apple-tab-span" style="white-space: pre;"&gt; &lt;/span&gt;&lt;span class="Apple-tab-span" style="white-space: pre;"&gt; &lt;/span&gt;&lt;span class="Apple-tab-span" style="white-space: pre;"&gt; &lt;/span&gt; Toast.makeText(MainActivity.getApplicationContext(),"Inside State 2", 2000).show();&lt;/span&gt;&lt;br /&gt;&lt;span style="background-color: transparent; font-family: Arial; font-size: 15px; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"&gt;&lt;span class="Apple-tab-span" style="white-space: pre;"&gt; &lt;/span&gt;&lt;span class="Apple-tab-span" style="white-space: pre;"&gt; &lt;/span&gt;&lt;span class="Apple-tab-span" style="white-space: pre;"&gt; &lt;/span&gt; this.sendEmptyMessage(3);&lt;/span&gt;&lt;br /&gt;&lt;span style="background-color: transparent; font-family: Arial; font-size: 15px; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"&gt;&lt;span class="Apple-tab-span" style="white-space: pre;"&gt; &lt;/span&gt;&lt;span class="Apple-tab-span" style="white-space: pre;"&gt; &lt;/span&gt;&lt;span class="Apple-tab-span" style="white-space: pre;"&gt; &lt;/span&gt; break;&lt;/span&gt;&lt;span class="Apple-style-span" style="font-family: Arial;"&gt;&lt;span class="Apple-style-span" style="font-size: 15px; white-space: pre-wrap;"&gt; &lt;/span&gt;&lt;/span&gt;&lt;span style="background-color: transparent; font-family: Arial; font-size: 15px; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"&gt;&lt;span class="Apple-tab-span" style="white-space: pre;"&gt; &lt;/span&gt;&lt;span class="Apple-tab-span" style="white-space: pre;"&gt; &lt;/span&gt; case 3:&lt;/span&gt;&lt;br /&gt;&lt;span style="background-color: transparent; font-family: Arial; font-size: 15px; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"&gt;&lt;span class="Apple-tab-span" style="white-space: pre;"&gt; &lt;/span&gt;&lt;span class="Apple-tab-span" style="white-space: pre;"&gt; &lt;/span&gt;&lt;span class="Apple-tab-span" style="white-space: pre;"&gt; &lt;/span&gt; ///do the processing&lt;/span&gt;&lt;br /&gt;&lt;span style="background-color: transparent; font-family: Arial; font-size: 15px; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"&gt;&lt;span class="Apple-tab-span" style="white-space: pre;"&gt; &lt;/span&gt;&lt;span class="Apple-tab-span" style="white-space: pre;"&gt; &lt;/span&gt;&lt;span class="Apple-tab-span" style="white-space: pre;"&gt; &lt;/span&gt; Toast.makeText(MainActivity.getApplicationContext(),"Inside State 3", 2000).show();&lt;/span&gt;&lt;br /&gt;&lt;span style="background-color: transparent; font-family: Arial; font-size: 15px; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"&gt;&lt;span class="Apple-tab-span" style="white-space: pre;"&gt; &lt;/span&gt;&lt;span class="Apple-tab-span" style="white-space: pre;"&gt; &lt;/span&gt;&lt;span class="Apple-tab-span" style="white-space: pre;"&gt; &lt;/span&gt; this.sendEmptyMessage(4);&lt;/span&gt;&lt;br /&gt;&lt;span style="background-color: transparent; font-family: Arial; font-size: 15px; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"&gt;&lt;span class="Apple-tab-span" style="white-space: pre;"&gt; &lt;/span&gt;&lt;span class="Apple-tab-span" style="white-space: pre;"&gt; &lt;/span&gt;&lt;span class="Apple-tab-span" style="white-space: pre;"&gt; &lt;/span&gt; break;&lt;/span&gt;&lt;br /&gt;&lt;span style="background-color: transparent; font-family: Arial; font-size: 15px; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"&gt;&lt;span class="Apple-tab-span" style="white-space: pre;"&gt; &lt;/span&gt;&lt;span class="Apple-tab-span" style="white-space: pre;"&gt; &lt;/span&gt; case 4:&lt;/span&gt;&lt;br /&gt;&lt;span style="background-color: transparent; font-family: Arial; font-size: 15px; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"&gt;&lt;span class="Apple-tab-span" style="white-space: pre;"&gt; &lt;/span&gt;&lt;span class="Apple-tab-span" style="white-space: pre;"&gt; &lt;/span&gt;&lt;span class="Apple-tab-span" style="white-space: pre;"&gt; &lt;/span&gt; break;&lt;/span&gt;&lt;br /&gt;&lt;span style="background-color: transparent; font-family: Arial; font-size: 15px; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"&gt;&lt;span class="Apple-tab-span" style="white-space: pre;"&gt; &lt;/span&gt;&lt;span class="Apple-tab-span" style="white-space: pre;"&gt; &lt;/span&gt;default:&lt;/span&gt;&lt;br /&gt;&lt;span style="background-color: transparent; font-family: Arial; font-size: 15px; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"&gt;&lt;span class="Apple-tab-span" style="white-space: pre;"&gt; &lt;/span&gt;&lt;span class="Apple-tab-span" style="white-space: pre;"&gt; &lt;/span&gt;&lt;span class="Apple-tab-span" style="white-space: pre;"&gt; &lt;/span&gt;break;&lt;span class="Apple-tab-span" style="white-space: pre;"&gt; &lt;/span&gt;&lt;span class="Apple-tab-span" style="white-space: pre;"&gt; &lt;/span&gt; &lt;/span&gt;&lt;br /&gt;&lt;span style="background-color: transparent; font-family: Arial; font-size: 15px; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"&gt;&lt;span class="Apple-tab-span" style="white-space: pre;"&gt; &lt;/span&gt;&lt;span class="Apple-tab-span" style="white-space: pre;"&gt; &lt;/span&gt; }&lt;/span&gt;&lt;br /&gt;&lt;span style="background-color: transparent; font-family: Arial; font-size: 15px; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"&gt;&lt;span class="Apple-tab-span" style="white-space: pre;"&gt; &lt;/span&gt; }&lt;/span&gt;&lt;span style="background-color: transparent; font-family: Arial; font-size: 15px; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"&gt; &lt;/span&gt;&lt;br /&gt;&lt;span style="background-color: transparent; font-family: Arial; font-size: 15px; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"&gt;}&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="background-color: #fff5cd; color: #4c4c4c; font-family: verdana; font-size: 11px; line-height: 18px;"&gt;&lt;/span&gt;&lt;br /&gt;&lt;div style="background-color: transparent;"&gt;&lt;span style="background-color: transparent; font-family: Arial; font-size: 15px; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"&gt;Let me explain the code a bit... here the crux of the solution lies in the MyHandler class derived from Handler.. The main activity class HAS MyHandler..&lt;/span&gt;&lt;/div&gt;&lt;div style="background-color: transparent;"&gt;&lt;span style="background-color: transparent; font-family: Arial; font-size: 15px; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"&gt;We start the State machine by sending a message (integer 1) through the function SendEmptyMessage called on MyHandler object. As a result, the callback function called handleMessage of the Handler is called and we handle this state's functionality here... the next all starte transitions happen sequentially from this callback function...&lt;/span&gt;&lt;/div&gt;&lt;div style="background-color: transparent;"&gt;&lt;span style="background-color: transparent; font-family: Arial; font-size: 15px; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"&gt;Hope this throws some lights on a specific design concept in Android...&lt;/span&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3946478681282550454-3203454587379079429?l=som-itsolutions.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://som-itsolutions.blogspot.com/feeds/3203454587379079429/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=3946478681282550454&amp;postID=3203454587379079429' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3946478681282550454/posts/default/3203454587379079429'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3946478681282550454/posts/default/3203454587379079429'/><link rel='alternate' type='text/html' href='http://som-itsolutions.blogspot.com/2011/11/implementation-of-finite-state-machine.html' title='An implementation of Finite State Machine in Android using Handler...'/><author><name>Som</name><uri>http://www.blogger.com/profile/09519633424407534012</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='24' src='http://3.bp.blogspot.com/-XVhL110Tyf8/ThxKF3DBYcI/AAAAAAAAEBo/arVXUPsgtSg/s220/NJ%2B042.JPG'/></author><media:thumbnail xmlns:media='http://search.yahoo.com/mrss/' url='http://2.bp.blogspot.com/-RsxPyEZrF6g/TsuF85DT_mI/AAAAAAAAEGQ/TFoUstf9OPA/s72-c/State+Machine.png' height='72' width='72'/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3946478681282550454.post-3971011701295990307</id><published>2011-11-17T14:15:00.002+05:30</published><updated>2011-11-17T18:33:16.958+05:30</updated><title type='text'>Robotium - automated unit test tool for Android...</title><content type='html'>&lt;div dir="ltr" style="text-align: left;" trbidi="on"&gt;&lt;span class="Apple-style-span" style="font-family: Arial; font-size: 15px; white-space: pre-wrap;"&gt;the following text explains how to use Robotium in Eclipse.. Robotium is an automated unit testing tool for Android...&lt;/span&gt;&lt;br /&gt;&lt;div style="background-color: transparent;"&gt;&lt;span style="background-color: transparent; font-family: Arial; font-size: 11pt; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"&gt;for this we need to download the Robotium.jar file from &lt;/span&gt;&lt;a href="http://code.google.com/p/robotium/wiki/Getting_Started"&gt;&lt;span style="background-color: transparent; font-family: Arial; font-size: 11pt; font-style: normal; font-variant: normal; text-decoration: underline; vertical-align: baseline; white-space: pre-wrap;"&gt;here&lt;/span&gt;&lt;/a&gt;&lt;span style="background-color: transparent; font-family: Arial; font-size: 11pt; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"&gt;...&lt;/span&gt;&lt;br /&gt;&lt;span style="background-color: transparent; font-family: Arial; font-size: 11pt; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"&gt;setting up the environment is easy...&lt;/span&gt;&lt;br /&gt;&lt;span style="background-color: transparent; font-family: Arial; font-size: 11pt; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"&gt;&lt;/span&gt;&lt;br /&gt;&lt;ul&gt;&lt;li style="background-color: transparent; font-family: Arial; font-size: 11pt; font-style: normal; font-variant: normal; list-style-type: disc; text-decoration: none; vertical-align: baseline;"&gt;&lt;span style="background-color: transparent; font-family: Arial; font-size: 11pt; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"&gt;put the above jar in the build path’s library section...&lt;/span&gt;&lt;/li&gt;&lt;/ul&gt;&lt;ul&gt;&lt;li style="background-color: transparent; font-family: Arial; font-size: 11pt; font-style: normal; font-variant: normal; list-style-type: disc; text-decoration: none; vertical-align: baseline;"&gt;&lt;span style="background-color: transparent; font-family: Arial; font-size: 11pt; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"&gt;add the following lines of code in the manifest.xml file in the manifest section (i.e. outside the app section)...&lt;/span&gt;&lt;/li&gt;&lt;/ul&gt;&lt;span style="background-color: transparent; font-family: Arial; font-size: 11pt; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"&gt;(instrumentation android:name="android.test.InstrumentationTestRunner"&lt;/span&gt;&lt;br /&gt;&lt;span style="background-color: transparent; font-family: Arial; font-size: 11pt; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"&gt; &amp;nbsp;&amp;nbsp;&amp;nbsp;android:targetPackage="training.android.trainingunitconverter"&lt;/span&gt;&lt;br /&gt;&lt;span style="background-color: transparent; font-family: Arial; font-size: 11pt; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"&gt; &amp;nbsp;&amp;nbsp;&amp;nbsp;android:label="1" /)&lt;/span&gt;&lt;br /&gt;&lt;span style="background-color: transparent; font-family: Arial; font-size: 11pt; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="background-color: transparent; font-family: Arial; font-size: 11pt; font-style: normal; font-variant: normal; font-weight: bold; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"&gt;the below snippet of code is to test the UnitConverter app...&lt;/span&gt;&lt;br /&gt;&lt;span style="background-color: transparent; font-family: Arial; font-size: 11pt; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"&gt;&lt;/span&gt;&lt;br /&gt;&lt;ul&gt;&lt;li style="background-color: transparent; font-family: Arial; font-size: 11pt; font-style: normal; font-variant: normal; list-style-type: disc; text-decoration: none; vertical-align: baseline;"&gt;&lt;span style="background-color: transparent; font-family: Arial; font-size: 11pt; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"&gt;create a file(say UnitConverterTest.java) and add the following piece of code...&lt;/span&gt;&lt;/li&gt;&lt;/ul&gt;&lt;span style="background-color: transparent; font-family: Arial; font-size: 11pt; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"&gt;&lt;/span&gt;&lt;br /&gt;&lt;div style="background-color: transparent;"&gt;&lt;span style="background-color: transparent; font-family: Arial; font-size: 11pt; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"&gt;&lt;span style="background-color: transparent; font-family: Arial; font-size: 11pt; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"&gt;&lt;code&gt;&lt;/code&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;code&gt;&lt;span style="background-color: transparent; font-family: Arial; font-size: 11pt; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"&gt;package training.android.trainingunitconverter;&lt;/span&gt;&lt;/code&gt;&lt;/div&gt;&lt;div style="background-color: transparent;"&gt;&lt;code&gt;&lt;span class="Apple-style-span" style="font-family: Arial;"&gt;&lt;span class="Apple-style-span" style="font-size: 15px; white-space: pre-wrap;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style="background-color: transparent; font-family: Arial; font-size: 11pt; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"&gt;import java.util.ArrayList;&lt;/span&gt;&lt;br /&gt;&lt;span style="background-color: transparent; font-family: Arial; font-size: 11pt; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"&gt;import android.test.ActivityInstrumentationTestCase2;&lt;/span&gt;&lt;br /&gt;&lt;span style="background-color: transparent; font-family: Arial; font-size: 11pt; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"&gt;import android.test.suitebuilder.annotation.Smoke;&lt;/span&gt;&lt;br /&gt;&lt;span style="background-color: transparent; font-family: Arial; font-size: 11pt; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"&gt;import android.widget.EditText;&lt;/span&gt;&lt;br /&gt;&lt;span style="background-color: transparent; font-family: Arial; font-size: 11pt; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"&gt;import android.widget.Spinner;&lt;/span&gt;&lt;br /&gt;&lt;span style="background-color: transparent; font-family: Arial; font-size: 11pt; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"&gt;import com.jayway.android.robotium.solo.Solo;&lt;/span&gt;&lt;br /&gt;&lt;span style="background-color: transparent; font-family: Arial; font-size: 11pt; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"&gt;&lt;/span&gt;&lt;span style="background-color: transparent; font-family: Arial; font-size: 11pt; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="background-color: transparent; font-family: Arial; font-size: 11pt; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"&gt;public class UnitConverterTest extends ActivityInstrumentationTestCase2&lt;unitconverter&gt;{&lt;/unitconverter&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="background-color: transparent; font-family: Arial; font-size: 11pt; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"&gt;&lt;span class="Apple-tab-span" style="white-space: pre;"&gt; &lt;/span&gt;private Solo solo;&lt;/span&gt;&lt;br /&gt;&lt;span style="background-color: transparent; font-family: Arial; font-size: 11pt; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"&gt;&lt;span class="Apple-tab-span" style="white-space: pre;"&gt; &lt;/span&gt;public UnitConverterTest() {&lt;/span&gt;&lt;br /&gt;&lt;span style="background-color: transparent; font-family: Arial; font-size: 11pt; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"&gt;&lt;span class="Apple-tab-span" style="white-space: pre;"&gt; &lt;/span&gt;&lt;span class="Apple-tab-span" style="white-space: pre;"&gt; &lt;/span&gt;super("training.android.trainingunitconverter", UnitConverter.class);&lt;/span&gt;&lt;br /&gt;&lt;span style="background-color: transparent; font-family: Arial; font-size: 11pt; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"&gt;&lt;span class="Apple-tab-span" style="white-space: pre;"&gt; &lt;/span&gt;}&lt;/span&gt;&lt;br /&gt;&lt;span style="background-color: transparent; font-family: Arial; font-size: 11pt; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"&gt;&lt;span class="Apple-tab-span" style="white-space: pre;"&gt; &lt;/span&gt;public void setUp() throws Exception {&lt;/span&gt;&lt;br /&gt;&lt;span style="background-color: transparent; font-family: Arial; font-size: 11pt; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"&gt;&lt;span class="Apple-tab-span" style="white-space: pre;"&gt; &lt;/span&gt;&lt;span class="Apple-tab-span" style="white-space: pre;"&gt; &lt;/span&gt;solo = new Solo(getInstrumentation(), getActivity());&lt;/span&gt;&lt;br /&gt;&lt;span style="background-color: transparent; font-family: Arial; font-size: 11pt; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"&gt;&lt;span class="Apple-tab-span" style="white-space: pre;"&gt; &lt;/span&gt;}&lt;/span&gt;&lt;br /&gt;&lt;span style="background-color: transparent; font-family: Arial; font-size: 11pt; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"&gt;&lt;span class="Apple-tab-span" style="white-space: pre;"&gt; &lt;/span&gt;@Smoke&lt;/span&gt;&lt;br /&gt;&lt;span style="background-color: transparent; font-family: Arial; font-size: 11pt; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"&gt;&lt;span class="Apple-tab-span" style="white-space: pre;"&gt; &lt;/span&gt;public void testUnitDropDown() throws Exception {&lt;/span&gt;&lt;br /&gt;&lt;span style="background-color: transparent; font-family: Arial; font-size: 11pt; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"&gt;&lt;span class="Apple-tab-span" style="white-space: pre;"&gt; &lt;/span&gt;&lt;span class="Apple-tab-span" style="white-space: pre;"&gt; &lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="background-color: transparent; font-family: Arial; font-size: 11pt; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"&gt;&lt;span class="Apple-tab-span" style="white-space: pre;"&gt; &lt;/span&gt;&lt;span class="Apple-tab-span" style="white-space: pre;"&gt; &lt;/span&gt;solo.assertCurrentActivity("Expected UnitConverter activity", "UnitConverter"); &lt;/span&gt;&lt;br /&gt;&lt;span style="background-color: transparent; font-family: Arial; font-size: 11pt; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"&gt;&lt;span class="Apple-tab-span" style="white-space: pre;"&gt; &lt;/span&gt;&lt;/span&gt;&lt;span style="background-color: transparent; font-family: Arial; font-size: 11pt; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"&gt;&lt;span class="Apple-tab-span" style="white-space: pre;"&gt; &lt;/span&gt;&lt;/span&gt;&lt;span style="background-color: transparent; font-family: Arial; font-size: 11pt; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"&gt;solo.pressSpinnerItem(0, 1);&lt;/span&gt;&lt;br /&gt;&lt;span style="background-color: transparent; font-family: Arial; font-size: 11pt; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"&gt;&lt;span class="Apple-tab-span" style="white-space: pre;"&gt; &lt;/span&gt;&lt;span class="Apple-tab-span" style="white-space: pre;"&gt; &lt;/span&gt;solo.sleep(2000);&lt;/span&gt;&lt;br /&gt;&lt;span style="background-color: transparent; font-family: Arial; font-size: 11pt; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"&gt;&lt;span class="Apple-tab-span" style="white-space: pre;"&gt; &lt;/span&gt;&lt;span class="Apple-tab-span" style="white-space: pre;"&gt; &lt;/span&gt;EditText value = (EditText)solo.getView(R.id.EditTextValue);&lt;/span&gt;&lt;br /&gt;&lt;span style="background-color: transparent; font-family: Arial; font-size: 11pt; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"&gt;&lt;span class="Apple-tab-span" style="white-space: pre;"&gt; &lt;/span&gt;&lt;span class="Apple-tab-span" style="white-space: pre;"&gt; &lt;/span&gt;solo.enterText(value, "1");&lt;/span&gt;&lt;br /&gt;&lt;span style="background-color: transparent; font-family: Arial; font-size: 11pt; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"&gt;&lt;span class="Apple-tab-span" style="white-space: pre;"&gt; &lt;/span&gt;&lt;span class="Apple-tab-span" style="white-space: pre;"&gt; &lt;/span&gt;solo.pressSpinnerItem(1,0);&lt;/span&gt;&lt;br /&gt;&lt;span style="background-color: transparent; font-family: Arial; font-size: 11pt; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"&gt;&lt;span class="Apple-tab-span" style="white-space: pre;"&gt; &lt;/span&gt;&lt;span class="Apple-tab-span" style="white-space: pre;"&gt; &lt;/span&gt;solo.sleep(1000);&lt;/span&gt;&lt;br /&gt;&lt;span style="background-color: transparent; font-family: Arial; font-size: 11pt; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"&gt;&lt;span class="Apple-tab-span" style="white-space: pre;"&gt; &lt;/span&gt;&lt;span class="Apple-tab-span" style="white-space: pre;"&gt; &lt;/span&gt;solo.pressSpinnerItem(2,1);&lt;/span&gt;&lt;br /&gt;&lt;span style="background-color: transparent; font-family: Arial; font-size: 11pt; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"&gt;&lt;span class="Apple-tab-span" style="white-space: pre;"&gt; &lt;/span&gt;&lt;span class="Apple-tab-span" style="white-space: pre;"&gt; &lt;/span&gt;solo.sleep(1000);&lt;/span&gt;&lt;br /&gt;&lt;span style="background-color: transparent; font-family: Arial; font-size: 11pt; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"&gt;&lt;span class="Apple-tab-span" style="white-space: pre;"&gt; &lt;/span&gt;&lt;span class="Apple-tab-span" style="white-space: pre;"&gt; &lt;/span&gt;solo.clickOnButton(0);&lt;/span&gt;&lt;br /&gt;&lt;span style="background-color: transparent; font-family: Arial; font-size: 11pt; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"&gt;&lt;span class="Apple-tab-span" style="white-space: pre;"&gt; &lt;/span&gt;&lt;span class="Apple-tab-span" style="white-space: pre;"&gt; &lt;/span&gt;assertTrue(solo.searchText("1000.0"));&lt;/span&gt;&lt;br /&gt;&lt;span style="background-color: transparent; font-family: Arial; font-size: 11pt; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"&gt;&lt;span class="Apple-tab-span" style="white-space: pre;"&gt; &lt;/span&gt;}&lt;/span&gt;&lt;br /&gt;&lt;span style="background-color: transparent; font-family: Arial; font-size: 11pt; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"&gt;&lt;span class="Apple-tab-span" style="white-space: pre;"&gt; &lt;/span&gt;@Override&lt;/span&gt;&lt;br /&gt;&lt;span style="background-color: transparent; font-family: Arial; font-size: 11pt; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"&gt;&lt;span class="Apple-tab-span" style="white-space: pre;"&gt; &lt;/span&gt;public void tearDown() throws Exception {&lt;/span&gt;&lt;br /&gt;&lt;span style="background-color: transparent; font-family: Arial; font-size: 11pt; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"&gt;&lt;span class="Apple-tab-span" style="white-space: pre;"&gt; &lt;/span&gt;&lt;span class="Apple-tab-span" style="white-space: pre;"&gt; &lt;/span&gt;//Robotium will finish all the activities that have been opened&lt;/span&gt;&lt;br /&gt;&lt;span style="background-color: transparent; font-family: Arial; font-size: 11pt; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"&gt;&lt;span class="Apple-tab-span" style="white-space: pre;"&gt; &lt;/span&gt;&lt;span class="Apple-tab-span" style="white-space: pre;"&gt; &lt;/span&gt;solo.finishOpenedActivities();&lt;/span&gt;&lt;br /&gt;&lt;span style="background-color: transparent; font-family: Arial; font-size: 11pt; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"&gt;&lt;span class="Apple-tab-span" style="white-space: pre;"&gt; &lt;/span&gt;}&lt;/span&gt;&lt;br /&gt;&lt;span style="background-color: transparent; font-family: Arial; font-size: 11pt; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"&gt;}&lt;/span&gt;&lt;br /&gt;&lt;span style="background-color: transparent; font-family: Arial; font-size: 11pt; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"&gt;&lt;/span&gt;&lt;/code&gt;&lt;br /&gt;&lt;span style="background-color: transparent; font-family: Arial; font-size: 11pt; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"&gt;however, it seems that the solo.PressSpinnerItem() is not functioning properly on the emulator (either Android 2.2 or Android 1.6)... hopefully this issue will be fixed in the next release of Robotium...&lt;/span&gt;&lt;br /&gt;&lt;span style="background-color: transparent; font-family: Arial; font-size: 11pt; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="background-color: transparent; font-family: Arial; font-size: 11pt; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"&gt;to run it in the emulator, right click on the Project... go to Run As.. and press &amp;nbsp;Android JUnit Test...&lt;/span&gt;&lt;br /&gt;&lt;span style="background-color: transparent; font-family: Arial; font-size: 11pt; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="background-color: transparent; font-family: Arial; font-size: 11pt; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"&gt;the screen shot for the above test condition is&amp;nbsp;&lt;/span&gt;&lt;/div&gt;&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://2.bp.blogspot.com/-UYF3B75sES4/TsTIuTCdejI/AAAAAAAAEGE/YfYSACGpiuA/s1600/UnitConverterRobotiumTest.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;span class="Apple-style-span" style="color: black;"&gt;&lt;img border="0" height="256" src="http://2.bp.blogspot.com/-UYF3B75sES4/TsTIuTCdejI/AAAAAAAAEGE/YfYSACGpiuA/s320/UnitConverterRobotiumTest.png" width="320" /&gt;&lt;/span&gt;&lt;/a&gt;&lt;/div&gt;&lt;div style="background-color: transparent;"&gt;&lt;span class="Apple-style-span" style="font-family: Arial;"&gt;&lt;span class="Apple-style-span" style="font-size: 15px; white-space: pre-wrap;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style="background-color: transparent; font-family: Arial; font-size: 11pt; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"&gt;as from the test case &lt;/span&gt;&lt;br /&gt;&lt;span style="background-color: transparent; font-family: Arial; font-size: 11pt; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"&gt;@Smoke&lt;/span&gt;&lt;br /&gt;&lt;span style="background-color: transparent; font-family: Arial; font-size: 11pt; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"&gt;&lt;span class="Apple-tab-span" style="white-space: pre;"&gt; &lt;/span&gt;public void testUnitDropDown() it is clear, that we are first asking the test framework to select the item having index 1 (that is Weight) from the first spinner. then we are asking the framework to put a value 1 in the edittext. we are then asking the test framework to select item with 0th index (that is Kg) from the second spinner and item with index 1 (that is gm) from the third spinner... and we are asking the framework to press Convert button... so the expected result will be 1000.0... and we search in the test case if it has the value 1000.0. then the test case will &lt;/span&gt;&lt;span style="background-color: transparent; font-family: Arial; font-size: 11pt; font-style: normal; font-variant: normal; font-weight: bold; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"&gt;PASS &lt;/span&gt;&lt;span style="background-color: transparent; font-family: Arial; font-size: 11pt; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"&gt;…&lt;/span&gt;&lt;br /&gt;&lt;span style="background-color: transparent; font-family: Arial; font-size: 11pt; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"&gt;similarly we can test different scenarios automatically by having more such functions as testUnitDropDown...&lt;/span&gt;&lt;br /&gt;&lt;span style="background-color: transparent; font-family: Arial; font-size: 11pt; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="background-color: transparent; font-family: Arial; font-size: 11pt; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"&gt;&lt;i&gt;note: &amp;nbsp;the source code of the UnitConverter App can be cloned from &lt;/i&gt;&lt;/span&gt;&lt;a href="https://github.com/sommukhopadhyay/UnitConverter"&gt;&lt;span style="background-color: transparent; font-family: Arial; font-size: 11pt; font-style: normal; font-variant: normal; text-decoration: underline; vertical-align: baseline; white-space: pre-wrap;"&gt;https://github.com/sommukhopadhyay/UnitConverter&lt;/span&gt;&lt;/a&gt;&lt;span style="background-color: transparent; color: black; font-family: Arial; font-size: 11pt; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"&gt;&lt;/span&gt;&lt;/div&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3946478681282550454-3971011701295990307?l=som-itsolutions.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://som-itsolutions.blogspot.com/feeds/3971011701295990307/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=3946478681282550454&amp;postID=3971011701295990307' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3946478681282550454/posts/default/3971011701295990307'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3946478681282550454/posts/default/3971011701295990307'/><link rel='alternate' type='text/html' href='http://som-itsolutions.blogspot.com/2011/11/robotium-automated-unit-test-tool-for.html' title='Robotium - automated unit test tool for Android...'/><author><name>Som</name><uri>http://www.blogger.com/profile/09519633424407534012</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='24' src='http://3.bp.blogspot.com/-XVhL110Tyf8/ThxKF3DBYcI/AAAAAAAAEBo/arVXUPsgtSg/s220/NJ%2B042.JPG'/></author><media:thumbnail xmlns:media='http://search.yahoo.com/mrss/' url='http://2.bp.blogspot.com/-UYF3B75sES4/TsTIuTCdejI/AAAAAAAAEGE/YfYSACGpiuA/s72-c/UnitConverterRobotiumTest.png' height='72' width='72'/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3946478681282550454.post-7740608550961701920</id><published>2011-11-17T11:35:00.001+05:30</published><updated>2011-11-17T11:37:12.760+05:30</updated><title type='text'>Git &amp; GitHub</title><content type='html'>&lt;div dir="ltr" style="text-align: left;" trbidi="on"&gt;&lt;span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;"&gt;i think by now most of the people know about Git and Github. however,&amp;nbsp;as i am  still&amp;nbsp; not very much hands-on&amp;nbsp;vis-a-vis contributing in the open source  community, i think this piece of information will be useful to others... &amp;nbsp;&lt;/span&gt;&lt;br /&gt;&lt;div&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;"&gt;Git is an opensource version comtrol system developed by the same person  who had created Linux. And using free version of Github, we can share our source  code to the open source community.&amp;nbsp;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;"&gt;For this one will just have to open an account at&lt;a href="http://www.github.com/"&gt; www.github.com&lt;/a&gt;, create his own repository.  However, to push your source code to this github repository, one has to install  Git in the local machine. The latest version of eclipse comes with EGit plugin,  which is of great help to push the project from the eclipse workspace.&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;"&gt;i think its a good step towards contributing in the open source  community...&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;"&gt;here are the step by step screenshots of how one can push his project into the GitHub directly from the eclipse workspace...&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://2.bp.blogspot.com/-JM0RSjSu8ss/TsSi2ZY84tI/AAAAAAAAEFE/df-YcWZtEVQ/s1600/Git1.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img border="0" height="256" src="http://2.bp.blogspot.com/-JM0RSjSu8ss/TsSi2ZY84tI/AAAAAAAAEFE/df-YcWZtEVQ/s320/Git1.png" width="320" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;step1&lt;/span&gt;&lt;/div&gt;&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://2.bp.blogspot.com/-EeTunXzxh9w/TsSjJrqzUSI/AAAAAAAAEFM/FRiXoGdIyig/s1600/Git2.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img border="0" height="256" src="http://2.bp.blogspot.com/-EeTunXzxh9w/TsSjJrqzUSI/AAAAAAAAEFM/FRiXoGdIyig/s320/Git2.png" width="320" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; step 2&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://1.bp.blogspot.com/-32PUO3ANbig/TsSjXc3192I/AAAAAAAAEFU/nKo3pMtkG78/s1600/Git3.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img border="0" height="256" src="http://1.bp.blogspot.com/-32PUO3ANbig/TsSjXc3192I/AAAAAAAAEFU/nKo3pMtkG78/s320/Git3.png" width="320" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;step 3&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://4.bp.blogspot.com/-dKYWQn53GJ4/TsSjhyzQdJI/AAAAAAAAEFc/3dJlVTXF2hc/s1600/Git4.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img border="0" height="256" src="http://4.bp.blogspot.com/-dKYWQn53GJ4/TsSjhyzQdJI/AAAAAAAAEFc/3dJlVTXF2hc/s320/Git4.png" width="320" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;step 4&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://4.bp.blogspot.com/-mLu26E_4gU8/TsSjrTN_XEI/AAAAAAAAEFk/u-n6OK_GBDo/s1600/Git5.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img border="0" height="256" src="http://4.bp.blogspot.com/-mLu26E_4gU8/TsSjrTN_XEI/AAAAAAAAEFk/u-n6OK_GBDo/s320/Git5.png" width="320" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;step 5&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://3.bp.blogspot.com/-7ffqplOTtls/TsSj1HHXgpI/AAAAAAAAEFs/Ivf5svVVtRA/s1600/Git6.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img border="0" height="256" src="http://3.bp.blogspot.com/-7ffqplOTtls/TsSj1HHXgpI/AAAAAAAAEFs/Ivf5svVVtRA/s320/Git6.png" width="320" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; step 6&lt;/span&gt;&lt;/div&gt;&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://4.bp.blogspot.com/-VNMPlSdYEjo/TsSj8llux-I/AAAAAAAAEF0/4YiMTDI2dS0/s1600/Git7.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img border="0" height="256" src="http://4.bp.blogspot.com/-VNMPlSdYEjo/TsSj8llux-I/AAAAAAAAEF0/4YiMTDI2dS0/s320/Git7.png" width="320" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; step 7&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://3.bp.blogspot.com/-nm-4IsN8FCg/TsSkELC8tCI/AAAAAAAAEF8/Z_1cof1vQ7s/s1600/Git8.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img border="0" height="256" src="http://3.bp.blogspot.com/-nm-4IsN8FCg/TsSkELC8tCI/AAAAAAAAEF8/Z_1cof1vQ7s/s320/Git8.png" width="320" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; step 8&lt;/span&gt;&lt;/div&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3946478681282550454-7740608550961701920?l=som-itsolutions.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://som-itsolutions.blogspot.com/feeds/7740608550961701920/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=3946478681282550454&amp;postID=7740608550961701920' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3946478681282550454/posts/default/7740608550961701920'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3946478681282550454/posts/default/7740608550961701920'/><link rel='alternate' type='text/html' href='http://som-itsolutions.blogspot.com/2011/11/i-think-by-now-most-of-people-know.html' title='Git &amp; GitHub'/><author><name>Som</name><uri>http://www.blogger.com/profile/09519633424407534012</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='24' src='http://3.bp.blogspot.com/-XVhL110Tyf8/ThxKF3DBYcI/AAAAAAAAEBo/arVXUPsgtSg/s220/NJ%2B042.JPG'/></author><media:thumbnail xmlns:media='http://search.yahoo.com/mrss/' url='http://2.bp.blogspot.com/-JM0RSjSu8ss/TsSi2ZY84tI/AAAAAAAAEFE/df-YcWZtEVQ/s72-c/Git1.png' height='72' width='72'/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3946478681282550454.post-7765496260181292409</id><published>2011-11-10T05:32:00.016+05:30</published><updated>2011-12-17T19:20:17.128+05:30</updated><title type='text'>Handling exception at construction in C++ using Boost's shared_ptr</title><content type='html'>&lt;div dir="ltr" style="text-align: left;" trbidi="on"&gt;&lt;span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;"&gt;&lt;span class="Apple-style-span" style="white-space: pre-wrap;"&gt;Its a very common problem in C++ that if a class's constructor throws an exception (say memory allocation exception) how we should handle it. Think about the following piece of code. Here class A's constructor has thrown an exception.. so the best way to handle such situation is to instantiate A inside a try block...if exception is thrown in the constructor of A, i will be destroyed by stack unwinding and the thrown exception will be caught...&lt;/span&gt; try-catch block in exception is very important as constructor cannot return anything to indicate to the caller that something wrong has happened...&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="font-family: Arial; font-size: 15px; white-space: pre-wrap;"&gt;&lt;code&gt;&lt;/code&gt;&lt;/span&gt;&lt;br /&gt;&lt;div style="background-color: transparent;"&gt;&lt;code&gt;&lt;span style="background-color: transparent; font-family: Arial; font-size: 11pt; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"&gt;&lt;/span&gt;&lt;/code&gt;&lt;br /&gt;&lt;code&gt;&lt;span style="background-color: transparent; font-family: Arial; font-size: 11pt; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"&gt;&lt;/span&gt;&lt;/code&gt;&lt;br /&gt;&lt;code&gt;&lt;span style="background-color: transparent; font-family: Arial; font-size: 11pt; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"&gt;&lt;i&gt;#include (iostream)&lt;iostream&gt;&lt;/iostream&gt;&lt;/i&gt;&lt;/span&gt;&lt;/code&gt;&lt;br /&gt;&lt;code&gt;&lt;i&gt;&lt;span style="background-color: transparent; font-family: Arial; font-size: 11pt; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"&gt;&lt;/span&gt;&lt;/i&gt;&lt;/code&gt;&lt;br /&gt;&lt;span style="background-color: transparent; font-family: Arial; font-size: 11pt; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"&gt;&lt;i&gt;#include (string)&lt;/i&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="background-color: transparent; font-family: Arial; font-size: 11pt; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"&gt;&lt;i&gt;#include (memory)&lt;/i&gt;&lt;/span&gt;&lt;br /&gt;&lt;i&gt;&lt;span style="background-color: transparent; font-family: Arial; font-size: 11pt; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"&gt;&lt;/span&gt;&lt;/i&gt;&lt;br /&gt;&lt;span style="background-color: transparent; font-family: Arial; font-size: 11pt; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"&gt;&lt;i&gt;class MyException(string str){&lt;/i&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="background-color: transparent; font-family: Arial; font-size: 11pt; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"&gt;&lt;i&gt;private: &lt;/i&gt;&lt;/span&gt;&lt;br /&gt;&lt;div dir="ltr" style="margin-bottom: 0pt; margin-top: 0pt; text-indent: 36pt;"&gt;&lt;span style="background-color: transparent; font-family: Arial; font-size: 11pt; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"&gt;&lt;i&gt;string &amp;nbsp;msg;&lt;/i&gt;&lt;/span&gt;&lt;/div&gt;&lt;span style="background-color: transparent; font-family: Arial; font-size: 11pt; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"&gt;&lt;i&gt;public:&lt;/i&gt;&lt;/span&gt;&lt;br /&gt;&lt;div dir="ltr" style="margin-bottom: 0pt; margin-left: 36pt; margin-top: 0pt;"&gt;&lt;span style="background-color: transparent; font-family: Arial; font-size: 11pt; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"&gt;&lt;i&gt;MyException(string str){&lt;/i&gt;&lt;/span&gt;&lt;/div&gt;&lt;div dir="ltr" style="margin-bottom: 0pt; margin-left: 36pt; margin-top: 0pt;"&gt;&lt;span style="background-color: transparent; font-family: Arial; font-size: 11pt; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"&gt;&lt;i&gt;msg = str;&lt;/i&gt;&lt;/span&gt;&lt;/div&gt;&lt;div dir="ltr" style="margin-bottom: 0pt; margin-left: 36pt; margin-top: 0pt;"&gt;&lt;span style="background-color: transparent; font-family: Arial; font-size: 11pt; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"&gt;&lt;i&gt;}&lt;/i&gt;&lt;/span&gt;&lt;/div&gt;&lt;div dir="ltr" style="margin-bottom: 0pt; margin-left: 36pt; margin-top: 0pt;"&gt;&lt;span style="background-color: transparent; font-family: Arial; font-size: 11pt; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"&gt;&lt;i&gt;void printerrmsg(){&lt;/i&gt;&lt;/span&gt;&lt;/div&gt;&lt;div dir="ltr" style="margin-bottom: 0pt; margin-left: 36pt; margin-top: 0pt;"&gt;&lt;span style="background-color: transparent; font-family: Arial; font-size: 11pt; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"&gt;&lt;i&gt;cout((msg.c_str()((endl;&lt;/i&gt;&lt;/span&gt;&lt;/div&gt;&lt;div dir="ltr" style="margin-bottom: 0pt; margin-left: 36pt; margin-top: 0pt;"&gt;&lt;span style="background-color: transparent; font-family: Arial; font-size: 11pt; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"&gt;&lt;i&gt;}&lt;/i&gt;&lt;/span&gt;&lt;/div&gt;&lt;span style="background-color: transparent; font-family: Arial; font-size: 11pt; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"&gt;&lt;i&gt;}&lt;/i&gt;&lt;/span&gt;&lt;br /&gt;&lt;i&gt;&lt;span style="background-color: transparent; font-family: Arial; font-size: 11pt; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"&gt;&lt;/span&gt;&lt;/i&gt;&lt;br /&gt;&lt;span style="background-color: transparent; font-family: Arial; font-size: 11pt; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"&gt;&lt;i&gt;class A{&lt;/i&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="background-color: transparent; font-family: Arial; font-size: 11pt; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"&gt;&lt;i&gt;private: int i;&lt;/i&gt;&lt;/span&gt;&lt;br /&gt;&lt;i&gt;&lt;span style="background-color: transparent; font-family: Arial; font-size: 11pt; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"&gt;&lt;/span&gt;&lt;/i&gt;&lt;br /&gt;&lt;span style="background-color: transparent; font-family: Arial; font-size: 11pt; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"&gt;&lt;i&gt;//if exception is thrown in the constructor of A, i will de destroyed by stack unwinding&lt;/i&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="background-color: transparent; font-family: Arial; font-size: 11pt; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"&gt;&lt;i&gt;//and the thrown exception will be caught&lt;/i&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="background-color: transparent; font-family: Arial; font-size: 11pt; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"&gt;&lt;i&gt;A()&lt;/i&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="background-color: transparent; font-family: Arial; font-size: 11pt; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"&gt;&lt;i&gt;{&lt;/i&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="background-color: transparent; font-family: Arial; font-size: 11pt; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"&gt;&lt;i&gt;i = 10;&lt;/i&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="background-color: transparent; font-family: Arial; font-size: 11pt; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"&gt;&lt;i&gt;throw MyException(“Exception thrown in constructor of A()”);&lt;/i&gt;&lt;/span&gt;&lt;br /&gt;&lt;div dir="ltr" style="margin-bottom: 0pt; margin-top: 0pt; text-indent: 36pt;"&gt;&lt;span style="background-color: transparent; font-family: Arial; font-size: 11pt; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"&gt;&lt;i&gt;}&lt;/i&gt;&lt;/span&gt;&lt;/div&gt;&lt;span style="background-color: transparent; font-family: Arial; font-size: 11pt; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"&gt;&lt;i&gt;};&lt;/i&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="background-color: transparent; font-family: Arial; font-size: 11pt; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"&gt;&lt;i&gt;void main(){&lt;/i&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="background-color: transparent; font-family: Arial; font-size: 11pt; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"&gt;&lt;i&gt;try{&lt;/i&gt;&lt;/span&gt;&lt;br /&gt;&lt;div dir="ltr" style="margin-bottom: 0pt; margin-top: 0pt; text-indent: 36pt;"&gt;&lt;span style="background-color: transparent; font-family: Arial; font-size: 11pt; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"&gt;&lt;i&gt;A();&lt;/i&gt;&lt;/span&gt;&lt;/div&gt;&lt;span style="background-color: transparent; font-family: Arial; font-size: 11pt; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"&gt;&lt;i&gt;}&lt;/i&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="background-color: transparent; font-family: Arial; font-size: 11pt; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"&gt;&lt;i&gt;catch(MyException&amp;amp; e){&lt;/i&gt;&lt;/span&gt;&lt;br /&gt;&lt;div dir="ltr" style="margin-bottom: 0pt; margin-top: 0pt; text-indent: 36pt;"&gt;&lt;span style="background-color: transparent; font-family: Arial; font-size: 11pt; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"&gt;&lt;i&gt;e.printerrmsg();&lt;/i&gt;&lt;/span&gt;&lt;/div&gt;&lt;div dir="ltr" style="margin-bottom: 0pt; margin-left: 36pt; margin-top: 0pt;"&gt;&lt;span style="background-color: transparent; font-family: Arial; font-size: 11pt; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"&gt;&lt;i&gt;}&lt;/i&gt;&lt;/span&gt;&lt;/div&gt;&lt;span style="background-color: transparent; font-family: Arial; font-size: 11pt; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"&gt;&lt;i&gt;}&lt;/i&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="background-color: transparent; font-family: Arial; font-size: 11pt; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="background-color: transparent; font-family: Arial; font-size: 11pt; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"&gt;now there is another point... suppose we need to allocate some dynamic memory in the constructor... and while doing that the constructor throws a memory exception... so the stack based pointer which was referencing the heap based memory will be destroyed because of the stack unwinding... so we will have some memory which is referenced by no pointer and hence we cannot access that... so obviously its a memory leak... &amp;nbsp;so, how can we handle that...&lt;/span&gt;&lt;br /&gt;&lt;span style="background-color: transparent; font-family: Arial; font-size: 11pt; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="background-color: transparent; font-family: Arial; font-size: 11pt; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"&gt;the best way to handle this kind of situation in modern C++ is to use auto_ptr/shared_ptr/shared_array ... so the solution will look something as the following:&lt;/span&gt;&lt;br /&gt;&lt;span style="background-color: transparent; font-family: Arial; font-size: 11pt; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="background-color: transparent; font-family: Arial; font-size: 11pt; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="background-color: transparent; font-family: Arial; font-size: 11pt; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"&gt;&lt;i&gt;#include (iostream)&lt;/i&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="background-color: transparent; font-family: Arial; font-size: 11pt; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"&gt;&lt;i&gt;#include (string)&lt;/i&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="background-color: transparent; font-family: Arial; font-size: 11pt; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"&gt;&lt;i&gt;#include (memory)&lt;/i&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="background-color: transparent; font-family: Arial; font-size: 11pt; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"&gt;&lt;i&gt;#include (boost/shared_ptr.hpp)&lt;/i&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="background-color: transparent; font-family: Arial; font-size: 11pt; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"&gt;&lt;i&gt;#include (boost/shared_array.hpp)&lt;/i&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="background-color: transparent; font-family: Arial; font-size: 11pt; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"&gt;&lt;i&gt;&lt;br /&gt;&lt;/i&gt;&lt;/span&gt;&lt;br /&gt;&lt;i&gt;&lt;span style="background-color: transparent; font-family: Arial; font-size: 11pt; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"&gt;&lt;/span&gt;&lt;/i&gt;&lt;br /&gt;&lt;span style="background-color: transparent; font-family: Arial; font-size: 11pt; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"&gt;&lt;i&gt;using namespace std;&lt;/i&gt;&lt;/span&gt;&lt;br /&gt;&lt;i&gt;&lt;span style="background-color: transparent; font-family: Arial; font-size: 11pt; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"&gt;&lt;/span&gt;&lt;/i&gt;&lt;br /&gt;&lt;span style="background-color: transparent; font-family: Arial; font-size: 11pt; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"&gt;&lt;i&gt;class SomeClass{&lt;/i&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="background-color: transparent; font-family: Arial; font-size: 11pt; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"&gt;&lt;i&gt;public:&lt;/i&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="background-color: transparent; font-family: Arial; font-size: 11pt; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"&gt;&lt;i&gt;&lt;span class="Apple-tab-span" style="white-space: pre;"&gt; &lt;/span&gt;SomeClass(){}&lt;/i&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="background-color: transparent; font-family: Arial; font-size: 11pt; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"&gt;&lt;i&gt;&lt;span class="Apple-tab-span" style="white-space: pre;"&gt; &lt;/span&gt;~SomeClass(){};&lt;/i&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="background-color: transparent; font-family: Arial; font-size: 11pt; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"&gt;&lt;i&gt;};&lt;/i&gt;&lt;/span&gt;&lt;br /&gt;&lt;i&gt;&lt;span style="background-color: transparent; font-family: Arial; font-size: 11pt; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"&gt;&lt;/span&gt;&lt;/i&gt;&lt;br /&gt;&lt;span style="background-color: transparent; font-family: Arial; font-size: 11pt; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"&gt;&lt;i&gt;typedef boost::shared_ptr(SomeClass) pSomeClass;&lt;/i&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="background-color: transparent; font-family: Arial; font-size: 11pt; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"&gt;&lt;i&gt;typedef boost::shared_ptr(char) pChar;&lt;/i&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="background-color: transparent; font-family: Arial; font-size: 11pt; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"&gt;&lt;i&gt;typedef boost::shard_array(char) &lt;char&gt;charBuff;&lt;/char&gt;&lt;/i&gt;&lt;/span&gt;&lt;br /&gt;&lt;i&gt;&lt;span style="background-color: transparent; font-family: Arial; font-size: 11pt; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"&gt;&lt;/span&gt;&lt;/i&gt;&lt;br /&gt;&lt;span style="background-color: transparent; font-family: Arial; font-size: 11pt; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"&gt;&lt;i&gt;class MyException{&lt;/i&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="background-color: transparent; font-family: Arial; font-size: 11pt; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"&gt;&lt;i&gt;public:&lt;/i&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="background-color: transparent; font-family: Arial; font-size: 11pt; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"&gt;&lt;i&gt;&lt;span class="Apple-tab-span" style="white-space: pre;"&gt; &lt;/span&gt;MyException(string str){&lt;/i&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="background-color: transparent; font-family: Arial; font-size: 11pt; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"&gt;&lt;i&gt;&lt;span class="Apple-tab-span" style="white-space: pre;"&gt; &lt;/span&gt;msg = str;&lt;/i&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="background-color: transparent; font-family: Arial; font-size: 11pt; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"&gt;&lt;i&gt;&lt;span class="Apple-tab-span" style="white-space: pre;"&gt; &lt;/span&gt;}&lt;/i&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="background-color: transparent; font-family: Arial; font-size: 11pt; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"&gt;&lt;i&gt;&lt;span class="Apple-tab-span" style="white-space: pre;"&gt; &lt;/span&gt;void printerrmsg(){&lt;/i&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="background-color: transparent; font-family: Arial; font-size: 11pt; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"&gt;&lt;i&gt;&lt;span class="Apple-tab-span" style="white-space: pre;"&gt; &lt;/span&gt;&lt;span class="Apple-tab-span" style="white-space: pre;"&gt; &lt;/span&gt;cout((msg.c_str()((endl;&lt;/i&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="background-color: transparent; font-family: Arial; font-size: 11pt; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"&gt;&lt;i&gt;&lt;span class="Apple-tab-span" style="white-space: pre;"&gt; &lt;/span&gt;}&lt;/i&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="background-color: transparent; font-family: Arial; font-size: 11pt; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"&gt;&lt;i&gt;private:&lt;/i&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="background-color: transparent; font-family: Arial; font-size: 11pt; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"&gt;&lt;i&gt;&lt;span class="Apple-tab-span" style="white-space: pre;"&gt; &lt;/span&gt;string msg;&lt;/i&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="background-color: transparent; font-family: Arial; font-size: 11pt; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"&gt;&lt;i&gt;};&lt;/i&gt;&lt;/span&gt;&lt;br /&gt;&lt;i&gt;&lt;span style="background-color: transparent; font-family: Arial; font-size: 11pt; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"&gt;&lt;/span&gt;&lt;/i&gt;&lt;br /&gt;&lt;i&gt;&lt;span style="background-color: transparent; font-family: Arial; font-size: 11pt; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"&gt;&lt;/span&gt;&lt;/i&gt;&lt;br /&gt;&lt;span style="background-color: transparent; font-family: Arial; font-size: 11pt; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"&gt;&lt;i&gt;class A{&lt;/i&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="background-color: transparent; font-family: Arial; font-size: 11pt; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"&gt;&lt;i&gt;private:&lt;/i&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="background-color: transparent; font-family: Arial; font-size: 11pt; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"&gt;&lt;i&gt;&lt;span class="Apple-tab-span" style="white-space: pre;"&gt; &lt;/span&gt;int i;&lt;/i&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="background-color: transparent; font-family: Arial; font-size: 11pt; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"&gt;&lt;i&gt;&lt;span class="Apple-tab-span" style="white-space: pre;"&gt; &lt;/span&gt;pChar m_ptrChar;&lt;/i&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="background-color: transparent; font-family: Arial; font-size: 11pt; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"&gt;&lt;i&gt;&lt;span class="Apple-tab-span" style="white-space: pre;"&gt; &lt;/span&gt;pSomeClass m_ptrSomeClass;&lt;/i&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="background-color: transparent; font-family: Arial; font-size: 11pt; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"&gt;&lt;i&gt;charBuff m_pcharBuff;&lt;/i&gt;&lt;/span&gt;&lt;br /&gt;&lt;i&gt;&lt;span style="background-color: transparent; font-family: Arial; font-size: 11pt; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"&gt;&lt;/span&gt;&lt;/i&gt;&lt;br /&gt;&lt;span style="background-color: transparent; font-family: Arial; font-size: 11pt; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"&gt;&lt;i&gt;&lt;span class="Apple-tab-span" style="white-space: pre;"&gt; &lt;/span&gt;//if exception is thrown in the constructor of A, i will be destroyed by stack unwinding&lt;/i&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="background-color: transparent; font-family: Arial; font-size: 11pt; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"&gt;&lt;i&gt;&lt;span class="Apple-tab-span" style="white-space: pre;"&gt; &lt;/span&gt;//and the thrown exception will be caught&lt;/i&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="background-color: transparent; font-family: Arial; font-size: 11pt; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"&gt;&lt;i&gt;public:&lt;/i&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="background-color: transparent; font-family: Arial; font-size: 11pt; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"&gt;&lt;i&gt;&lt;span class="Apple-tab-span" style="white-space: pre;"&gt; &lt;/span&gt;A():m_ptrChar(new char),m_ptrSomeClass(new SomeClass),m_pcharBuff(new char[100])&lt;/i&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="background-color: transparent; font-family: Arial; font-size: 11pt; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"&gt;&lt;i&gt;&lt;span class="Apple-tab-span" style="white-space: pre;"&gt; &lt;/span&gt;{&lt;/i&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="background-color: transparent; font-family: Arial; font-size: 11pt; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"&gt;&lt;i&gt;&lt;span class="Apple-tab-span" style="white-space: pre;"&gt; &lt;/span&gt;i = 10;&lt;/i&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="background-color: transparent; font-family: Arial; font-size: 11pt; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"&gt;&lt;i&gt;&lt;span class="Apple-tab-span" style="white-space: pre;"&gt; &lt;/span&gt;throw MyException("Exception at A's constructor");&lt;/i&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="background-color: transparent; font-family: Arial; font-size: 11pt; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"&gt;&lt;i&gt;&lt;span class="Apple-tab-span" style="white-space: pre;"&gt; &lt;/span&gt;}&lt;/i&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="background-color: transparent; font-family: Arial; font-size: 11pt; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"&gt;&lt;i&gt;};&lt;/i&gt;&lt;/span&gt;&lt;br /&gt;&lt;i&gt;&lt;span style="background-color: transparent; font-family: Arial; font-size: 11pt; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"&gt;&lt;/span&gt;&lt;/i&gt;&lt;br /&gt;&lt;i&gt;&lt;span style="background-color: transparent; font-family: Arial; font-size: 11pt; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"&gt;&lt;/span&gt;&lt;/i&gt;&lt;br /&gt;&lt;span style="background-color: transparent; font-family: Arial; font-size: 11pt; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"&gt;&lt;i&gt;int main(){&lt;/i&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="background-color: transparent; font-family: Arial; font-size: 11pt; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"&gt;&lt;i&gt;&lt;span class="Apple-tab-span" style="white-space: pre;"&gt; &lt;/span&gt;try{&lt;/i&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="background-color: transparent; font-family: Arial; font-size: 11pt; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"&gt;&lt;i&gt;&lt;span class="Apple-tab-span" style="white-space: pre;"&gt; &lt;/span&gt;A objA;&lt;/i&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="background-color: transparent; font-family: Arial; font-size: 11pt; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"&gt;&lt;i&gt;&lt;span class="Apple-tab-span" style="white-space: pre;"&gt; &lt;/span&gt;}&lt;/i&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="background-color: transparent; font-family: Arial; font-size: 11pt; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"&gt;&lt;i&gt;&lt;span class="Apple-tab-span" style="white-space: pre;"&gt; &lt;/span&gt;catch(MyException&amp;amp; e){&lt;/i&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="background-color: transparent; font-family: Arial; font-size: 11pt; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"&gt;&lt;i&gt;&lt;span class="Apple-tab-span" style="white-space: pre;"&gt; &lt;/span&gt;&lt;span class="Apple-tab-span" style="white-space: pre;"&gt; &lt;/span&gt;e.printerrmsg();&lt;/i&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="background-color: transparent; font-family: Arial; font-size: 11pt; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"&gt;&lt;i&gt;&lt;span class="Apple-tab-span" style="white-space: pre;"&gt; &lt;/span&gt;}&lt;/i&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="background-color: transparent; font-family: Arial; font-size: 11pt; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"&gt;&lt;i&gt;&lt;span class="Apple-tab-span" style="white-space: pre;"&gt; &lt;/span&gt;return 1;&lt;/i&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="background-color: transparent; font-family: Arial; font-size: 11pt; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"&gt;&lt;i&gt;&lt;span class="Apple-tab-span" style="white-space: pre;"&gt; &lt;/span&gt;}&lt;/i&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="background-color: transparent; font-family: Arial; font-size: 11pt; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="background-color: transparent; font-family: Arial, Helvetica, sans-serif; font-size: 11pt; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"&gt;In Symbian C++, it is handled by a concept called two phase constructor... (it came into the picture because there was no template concept in earlier Symbian C++, and hence there was no auto_ptr)... in this process, if we want to create a dynamic memory allocation at the heap pointed by say *pMem, then in the first phase of construction we initialize the *pMem by NULL. obviously this cannot throw exception...then this pMem is pushed to a cleanupstack(this is something new in Symbian) so that we have a reference in the CleanupStack for future reference... and in the second phase of construction, we allocate memory pointed by pMem... so, if the constructor fails, we still have a reference of pMem in the cleanup stack... we just need to pop it and destroy it... hence there is no chance of memory leak...&lt;/span&gt;&lt;/div&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;"&gt;hope this discussion comes handy for C++ learners...&lt;/span&gt;&lt;br /&gt;&lt;div style="background-color: transparent;"&gt;&lt;span style="background-color: transparent; color: black; font-family: Arial; font-size: 11pt; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="background-color: transparent; color: black; font-family: Arial; font-size: 11pt; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"&gt;&lt;/span&gt;&lt;/div&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3946478681282550454-7765496260181292409?l=som-itsolutions.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://som-itsolutions.blogspot.com/feeds/7765496260181292409/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=3946478681282550454&amp;postID=7765496260181292409' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3946478681282550454/posts/default/7765496260181292409'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3946478681282550454/posts/default/7765496260181292409'/><link rel='alternate' type='text/html' href='http://som-itsolutions.blogspot.com/2011/11/handling-exception-at-construction-in-c.html' title='Handling exception at construction in C++ using Boost&apos;s shared_ptr'/><author><name>Som</name><uri>http://www.blogger.com/profile/09519633424407534012</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='24' src='http://3.bp.blogspot.com/-XVhL110Tyf8/ThxKF3DBYcI/AAAAAAAAEBo/arVXUPsgtSg/s220/NJ%2B042.JPG'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3946478681282550454.post-8489393011176216676</id><published>2011-11-05T10:10:00.003+05:30</published><updated>2011-11-06T09:58:26.347+05:30</updated><title type='text'>How to launch an Android App from the Browser</title><content type='html'>&lt;div dir="ltr" style="text-align: left;" trbidi="on"&gt;&lt;span class="Apple-style-span" style="font-size: 13px; white-space: pre-wrap;"&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;As i was doing some experimentation with android, i tried to launch a native app from a browser link... and i was successful... i would like to share whatever i have done with you..&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;div style="background-color: transparent;"&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;&lt;span style="background-color: transparent; font-size: 10pt; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"&gt;The first thing one has to do to launch an app from a browser’s link is to add an additional intent filter in the app’s &amp;nbsp;Manifest file... for example to launch my native app (called UnitConverter) i have added the following few lines in the App’s manifest...&lt;/span&gt;&lt;br /&gt;&lt;span style="background-color: transparent; font-size: 10pt; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"&gt;&lt;intent-filter&gt;&lt;/intent-filter&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="background-color: transparent; font-size: 10pt; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"&gt; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span class="Apple-tab-span" style="white-space: pre;"&gt; &amp;lt;&lt;/span&gt;data android:scheme="unitconverter" /&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="background-color: transparent; font-size: 10pt; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"&gt; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span class="Apple-tab-span" style="white-space: pre;"&gt; &amp;lt;&lt;/span&gt;action android:name="android.intent.action.VIEW" /&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="background-color: transparent; font-size: 10pt; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"&gt; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span class="Apple-tab-span" style="white-space: pre;"&gt; &amp;lt;&lt;/span&gt;category android:name="android.intent.category.BROWSABLE" /&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="background-color: transparent; font-size: 10pt; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"&gt; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span class="Apple-tab-span" style="white-space: pre;"&gt; &amp;lt;&lt;/span&gt;category android:name="android.intent.category.DEFAULT" /&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="background-color: transparent; font-size: 10pt; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="background-color: transparent; font-size: 10pt; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"&gt;and in the web app i have added html code as (a href="unitconverter://")Launch UnitConverter App(/a)&lt;/span&gt;&lt;br /&gt;&lt;span style="background-color: transparent; font-size: 10pt; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"&gt;and it has worked fine..&lt;/span&gt;&lt;br /&gt;&lt;span style="background-color: transparent; font-size: 10pt; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"&gt;however, sometimes we may need to pass some query parameters in the html query tag like &lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="font-size: 13px; white-space: pre-wrap;"&gt;(a href="unitconverter://?param1key=param1value&amp;amp;param2key=param2value)Launch UnitConverter App(/a)&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;&lt;span style="background-color: transparent; font-size: 10pt; font-style: normal; font-variant: normal; vertical-align: baseline; white-space: pre-wrap;"&gt;to catch these query parameters inside the Android app, i have written the following piece of code and added it in the onCreate function of the main Activity just after the line super.onCreate(savedInstanceState).&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="font-size: x-small;"&gt;&lt;span style="background-color: transparent; font-size: 10pt; font-style: normal; font-variant: normal; vertical-align: baseline; white-space: pre-wrap;"&gt;&lt;/span&gt;&lt;/span&gt; &lt;span style="background-color: transparent; font-size: 10pt; font-style: normal; font-variant: normal; vertical-align: baseline; white-space: pre-wrap;"&gt;&lt;code&gt;&lt;/code&gt;&lt;/span&gt;&lt;code&gt;&lt;br /&gt;&lt;span style="background-color: transparent; font-size: 10pt; font-style: normal; font-variant: normal; vertical-align: baseline; white-space: pre-wrap;"&gt;//to get the parameter passed from the URI that has launched this app&lt;/span&gt;&lt;br /&gt;&lt;span style="background-color: transparent; font-size: 10pt; font-style: normal; font-variant: normal; vertical-align: baseline; white-space: pre-wrap;"&gt; &amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span class="Apple-tab-span" style="white-space: pre;"&gt; &lt;/span&gt;final Intent intent = getIntent();&lt;/span&gt;&lt;br /&gt;&lt;span style="background-color: transparent; font-size: 10pt; font-style: normal; font-variant: normal; vertical-align: baseline; white-space: pre-wrap;"&gt; &amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span class="Apple-tab-span" style="white-space: pre;"&gt; &lt;/span&gt;String scheme = intent.getScheme();&lt;/span&gt;&lt;br /&gt;&lt;span style="background-color: transparent; font-size: 10pt; font-style: normal; font-variant: normal; vertical-align: baseline; white-space: pre-wrap;"&gt; &amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span class="Apple-tab-span" style="white-space: pre;"&gt; &lt;/span&gt;if(scheme != null){&lt;/span&gt;&lt;br /&gt;&lt;span style="background-color: transparent; font-size: 10pt; font-style: normal; font-variant: normal; vertical-align: baseline; white-space: pre-wrap;"&gt; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span class="Apple-tab-span" style="white-space: pre;"&gt; &lt;/span&gt;final Uri myURI=intent.getData();&lt;/span&gt;&lt;br /&gt;&lt;span style="background-color: transparent; font-size: 10pt; font-style: normal; font-variant: normal; vertical-align: baseline; white-space: pre-wrap;"&gt; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span class="Apple-tab-span" style="white-space: pre;"&gt; &lt;/span&gt;String queryString = new String();&lt;/span&gt;&lt;br /&gt;&lt;span style="background-color: transparent; font-size: 10pt; font-style: normal; font-variant: normal; vertical-align: baseline; white-space: pre-wrap;"&gt; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;br /&gt;&lt;span style="background-color: transparent; font-size: 10pt; font-style: normal; font-variant: normal; vertical-align: baseline; white-space: pre-wrap;"&gt; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span class="Apple-tab-span" style="white-space: pre;"&gt; &lt;/span&gt;if(myURI!=null)&lt;/span&gt;&lt;br /&gt;&lt;span style="background-color: transparent; font-size: 10pt; font-style: normal; font-variant: normal; vertical-align: baseline; white-space: pre-wrap;"&gt; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span class="Apple-tab-span" style="white-space: pre;"&gt; &lt;/span&gt;{&lt;/span&gt;&lt;br /&gt;&lt;span style="background-color: transparent; font-size: 10pt; font-style: normal; font-variant: normal; vertical-align: baseline; white-space: pre-wrap;"&gt; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span class="Apple-tab-span" style="white-space: pre;"&gt; &lt;/span&gt;queryString = myURI.getQuery();&lt;/span&gt;&lt;br /&gt;&lt;span style="background-color: transparent; font-size: 10pt; font-style: normal; font-variant: normal; vertical-align: baseline; white-space: pre-wrap;"&gt; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span class="Apple-tab-span" style="white-space: pre;"&gt; &lt;/span&gt;}&lt;/span&gt;&lt;br /&gt;&lt;span style="background-color: transparent; font-size: 10pt; font-style: normal; font-variant: normal; vertical-align: baseline; white-space: pre-wrap;"&gt; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span class="Apple-tab-span" style="white-space: pre;"&gt; &lt;/span&gt;String split1 = "&amp;amp;";&lt;/span&gt;&lt;br /&gt;&lt;span style="background-color: transparent; font-size: 10pt; font-style: normal; font-variant: normal; vertical-align: baseline; white-space: pre-wrap;"&gt; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span class="Apple-tab-span" style="white-space: pre;"&gt; &lt;/span&gt;String split2 = "=";&lt;/span&gt;&lt;br /&gt;&lt;span style="background-color: transparent; font-size: 10pt; font-style: normal; font-variant: normal; vertical-align: baseline; white-space: pre-wrap;"&gt; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;br /&gt;&lt;span style="background-color: transparent; font-size: 10pt; font-style: normal; font-variant: normal; vertical-align: baseline; white-space: pre-wrap;"&gt; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span class="Apple-tab-span" style="white-space: pre;"&gt; &lt;/span&gt;if (queryString != null)&lt;/span&gt;&lt;br /&gt;&lt;span style="background-color: transparent; font-size: 10pt; font-style: normal; font-variant: normal; vertical-align: baseline; white-space: pre-wrap;"&gt; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span class="Apple-tab-span" style="white-space: pre;"&gt; &lt;/span&gt;{&lt;/span&gt;&lt;br /&gt;&lt;span style="background-color: transparent; font-size: 10pt; font-style: normal; font-variant: normal; vertical-align: baseline; white-space: pre-wrap;"&gt; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span class="Apple-tab-span" style="white-space: pre;"&gt; &lt;/span&gt;final String[] arrParameters = queryString.split("&amp;amp;");&lt;/span&gt;&lt;br /&gt;&lt;span style="background-color: transparent; font-size: 10pt; font-style: normal; font-variant: normal; vertical-align: baseline; white-space: pre-wrap;"&gt; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span class="Apple-tab-span" style="white-space: pre;"&gt; &lt;/span&gt;for (final String tempParameterString : arrParameters)&lt;/span&gt;&lt;br /&gt;&lt;span style="background-color: transparent; font-size: 10pt; font-style: normal; font-variant: normal; vertical-align: baseline; white-space: pre-wrap;"&gt; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span class="Apple-tab-span" style="white-space: pre;"&gt; &lt;/span&gt;{&lt;/span&gt;&lt;br /&gt;&lt;span style="background-color: transparent; font-size: 10pt; font-style: normal; font-variant: normal; vertical-align: baseline; white-space: pre-wrap;"&gt; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span class="Apple-tab-span" style="white-space: pre;"&gt; &lt;/span&gt;final String[] arrTempParameter = tempParameterString.split("=");&lt;/span&gt;&lt;br /&gt;&lt;span style="background-color: transparent; font-size: 10pt; font-style: normal; font-variant: normal; vertical-align: baseline; white-space: pre-wrap;"&gt; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span class="Apple-tab-span" style="white-space: pre;"&gt; &lt;/span&gt;if (arrTempParameter.length( )== 2)&lt;/span&gt;&lt;br /&gt;&lt;span style="background-color: transparent; font-size: 10pt; font-style: normal; font-variant: normal; vertical-align: baseline; white-space: pre-wrap;"&gt; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span class="Apple-tab-span" style="white-space: pre;"&gt; &lt;/span&gt;{&lt;/span&gt;&lt;br /&gt;&lt;span style="background-color: transparent; font-size: 10pt; font-style: normal; font-variant: normal; vertical-align: baseline; white-space: pre-wrap;"&gt; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span class="Apple-tab-span" style="white-space: pre;"&gt; &lt;/span&gt;final String parameterKey = arrTempParameter[0];&lt;/span&gt;&lt;br /&gt;&lt;span style="background-color: transparent; font-size: 10pt; font-style: normal; font-variant: normal; vertical-align: baseline; white-space: pre-wrap;"&gt; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span class="Apple-tab-span" style="white-space: pre;"&gt; &lt;/span&gt;final String parameterValue = arrTempParameter[1];&lt;/span&gt;&lt;br /&gt;&lt;span style="background-color: transparent; font-size: 10pt; font-style: normal; font-variant: normal; vertical-align: baseline; white-space: pre-wrap;"&gt; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span class="Apple-tab-span" style="white-space: pre;"&gt; &lt;/span&gt;//do something with the parameters&lt;/span&gt;&lt;br /&gt;&lt;span style="background-color: transparent; font-size: 10pt; font-style: normal; font-variant: normal; vertical-align: baseline; white-space: pre-wrap;"&gt; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span class="Apple-tab-span" style="white-space: pre;"&gt; &lt;/span&gt;Toast.makeText(this, parameterValue, 500).show();&lt;/span&gt;&lt;br /&gt;&lt;span style="background-color: transparent; font-size: 10pt; font-style: normal; font-variant: normal; vertical-align: baseline; white-space: pre-wrap;"&gt; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span class="Apple-tab-span" style="white-space: pre;"&gt; &lt;/span&gt;}&lt;/span&gt;&lt;br /&gt;&lt;span style="background-color: transparent; font-size: 10pt; font-style: normal; font-variant: normal; vertical-align: baseline; white-space: pre-wrap;"&gt; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span class="Apple-tab-span" style="white-space: pre;"&gt; &lt;/span&gt;}&lt;/span&gt;&lt;br /&gt;&lt;span style="background-color: transparent; font-size: 10pt; font-style: normal; font-variant: normal; vertical-align: baseline; white-space: pre-wrap;"&gt; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span class="Apple-tab-span" style="white-space: pre;"&gt; &lt;/span&gt;}&lt;/span&gt;&lt;span style="background-color: transparent; font-size: 10pt; font-style: normal; font-variant: normal; vertical-align: baseline; white-space: pre-wrap;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;br /&gt;&lt;span style="background-color: transparent; font-size: 10pt; font-style: normal; font-variant: normal; vertical-align: baseline; white-space: pre-wrap;"&gt; &amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span class="Apple-tab-span" style="white-space: pre;"&gt; &lt;/span&gt;}&lt;/span&gt;&lt;br /&gt;&lt;span style="background-color: transparent; font-size: 10pt; font-style: normal; font-variant: normal; vertical-align: baseline; white-space: pre-wrap;"&gt;&lt;/span&gt;&lt;/code&gt;&lt;br /&gt;&lt;span style="background-color: transparent; font-size: 10pt; font-style: normal; font-variant: normal; vertical-align: baseline; white-space: pre-wrap;"&gt;And voila!!! it has worked perfectly...&lt;/span&gt;&lt;br /&gt;&lt;span style="background-color: transparent; font-size: 10pt; font-style: normal; font-variant: normal; vertical-align: baseline; white-space: pre-wrap;"&gt;Hope this discussion comes handy for the Android learners... &lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3946478681282550454-8489393011176216676?l=som-itsolutions.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://som-itsolutions.blogspot.com/feeds/8489393011176216676/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=3946478681282550454&amp;postID=8489393011176216676' title='2 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3946478681282550454/posts/default/8489393011176216676'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3946478681282550454/posts/default/8489393011176216676'/><link rel='alternate' type='text/html' href='http://som-itsolutions.blogspot.com/2011/11/how-to-launch-android-app-from-browser.html' title='How to launch an Android App from the Browser'/><author><name>Som</name><uri>http://www.blogger.com/profile/09519633424407534012</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='24' src='http://3.bp.blogspot.com/-XVhL110Tyf8/ThxKF3DBYcI/AAAAAAAAEBo/arVXUPsgtSg/s220/NJ%2B042.JPG'/></author><thr:total>2</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3946478681282550454.post-6324188549818408093</id><published>2011-10-31T19:45:00.010+05:30</published><updated>2011-11-30T13:28:04.664+05:30</updated><title type='text'>Tackling the Circular Dependency in Java...</title><content type='html'>&lt;div dir="ltr" style="text-align: left;" trbidi="on"&gt;&lt;span class="Apple-style-span" style="font-family: Arial; font-size: 15px; white-space: pre-wrap;"&gt;Let me first define what we mean by circular dependency in OOAD terms vis-a-vis Java.&lt;/span&gt;&lt;br /&gt;&lt;div style="background-color: transparent;"&gt;&lt;span style="background-color: transparent; font-family: Arial; font-size: 11pt; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="background-color: transparent; font-family: Arial; font-size: 11pt; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"&gt;Suppose we have a class called A which has class B’s Object. (in UML terms A HAS B). at the same time we class B is also composed of Object of class A (in UML terms B HAS A). obviously this represents circular dependency because while creating the object of A, the compiler must know the size of B... on the other hand while creating object of B, the compiler must know the size of A. this is something like egg vs. chicken problem...&lt;/span&gt;&lt;br /&gt;&lt;span style="background-color: transparent; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline;"&gt;&lt;/span&gt;&lt;span class="Apple-style-span" style="font-family: Arial;"&gt;&lt;span class="Apple-style-span" style="font-size: 15px; white-space: pre-wrap;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div style="background-color: transparent;"&gt;&lt;span style="background-color: transparent; font-family: Arial; font-size: 11pt; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"&gt;this may be possible in real life situation as well. for example suppose a multi storied building has a lift. so in the UML terms, the &lt;/span&gt;&lt;span style="background-color: transparent; font-family: Arial; font-size: 11pt; font-style: normal; font-variant: normal; font-weight: bold; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"&gt;building HAS lift&lt;/span&gt;&lt;span style="background-color: transparent; font-family: Arial; font-size: 11pt; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"&gt;... but at the same time, suppose, while constructing the lift object, we need to give it the information about the building object to access various functionalities of the Building class... for example, suppose the speed of the lift is set depending on the number of floors of the Building... hence while constructing the Lift object it must access the functionalities of the Building object which will give the number of floors the building has got...hence in UML terms the &lt;/span&gt;&lt;span style="background-color: transparent; font-family: Arial; font-size: 11pt; font-style: normal; font-variant: normal; font-weight: bold; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"&gt;lift HAS building&lt;/span&gt;&lt;span style="background-color: transparent; font-family: Arial; font-size: 11pt; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"&gt;... so this is a sure case of circular dependency...&lt;/span&gt;&lt;br /&gt;&lt;span style="background-color: transparent; font-family: Arial; font-size: 11pt; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="background-color: transparent; font-family: Arial; font-size: 11pt; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"&gt;in real java code it will look something as follows:&lt;/span&gt;&lt;br /&gt;&lt;span style="background-color: transparent; font-family: Arial; font-size: 11pt; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"&gt;&lt;code&gt;&lt;/code&gt;&lt;/span&gt;&lt;br /&gt;&lt;code&gt;&lt;span style="background-color: transparent; font-family: Arial; font-size: 11pt; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"&gt;&lt;/span&gt;&lt;/code&gt;&lt;br /&gt;&lt;code&gt;&lt;span style="background-color: transparent; font-family: Arial; font-size: 11pt; font-style: italic; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"&gt;public class Building {&lt;/span&gt;&lt;/code&gt;&lt;br /&gt;&lt;code&gt;&lt;span style="background-color: transparent; font-family: Arial; font-size: 11pt; font-style: italic; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"&gt;private Lift lift;&lt;/span&gt;&lt;/code&gt;&lt;br /&gt;&lt;code&gt;&lt;span style="background-color: transparent; font-family: Arial; font-size: 11pt; font-style: italic; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"&gt;private int floor;&lt;/span&gt;&lt;/code&gt;&lt;br /&gt;&lt;code&gt;&lt;span style="background-color: transparent; font-family: Arial; font-size: 11pt; font-style: italic; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"&gt;public Building(){&lt;/span&gt;&lt;/code&gt;&lt;br /&gt;&lt;code&gt;&lt;span style="background-color: transparent; font-family: Arial; font-size: 11pt; font-style: italic; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"&gt;&lt;span class="Apple-tab-span" style="white-space: pre;"&gt; &lt;/span&gt;lift = new Lift();&lt;/span&gt;&lt;/code&gt;&lt;br /&gt;&lt;code&gt;&lt;span style="background-color: transparent; font-family: Arial; font-size: 11pt; font-style: italic; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"&gt;setFloor(15);&lt;/span&gt;&lt;/code&gt;&lt;br /&gt;&lt;code&gt;&lt;span style="background-color: transparent; font-family: Arial; font-size: 11pt; font-style: italic; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"&gt;&lt;span class="Apple-tab-span" style="white-space: pre;"&gt; &lt;/span&gt;}&lt;/span&gt;&lt;/code&gt;&lt;br /&gt;&lt;code&gt;&lt;span style="background-color: transparent; font-family: Arial; font-size: 11pt; font-style: italic; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"&gt;public int getFloor(){&lt;/span&gt;&lt;/code&gt;&lt;br /&gt;&lt;code&gt;&lt;span style="background-color: transparent; font-family: Arial; font-size: 11pt; font-style: italic; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"&gt;&lt;span class="Apple-tab-span" style="white-space: pre;"&gt; &lt;/span&gt;return floor;&lt;/span&gt;&lt;/code&gt;&lt;br /&gt;&lt;code&gt;&lt;span style="background-color: transparent; font-family: Arial; font-size: 11pt; font-style: italic; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"&gt;&lt;span class="Apple-tab-span" style="white-space: pre;"&gt; &lt;/span&gt;}&lt;/span&gt;&lt;/code&gt;&lt;br /&gt;&lt;code&gt;&lt;span style="background-color: transparent; font-family: Arial; font-size: 11pt; font-style: italic; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"&gt;&lt;/span&gt;&lt;/code&gt;&lt;br /&gt;&lt;code&gt;&lt;span style="background-color: transparent; font-family: Arial; font-size: 11pt; font-style: italic; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"&gt;public void setFloor(int floor){&lt;/span&gt;&lt;/code&gt;&lt;br /&gt;&lt;code&gt;&lt;span style="background-color: transparent; font-family: Arial; font-size: 11pt; font-style: italic; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"&gt;&lt;span class="Apple-tab-span" style="white-space: pre;"&gt; &lt;/span&gt;this.floor = floor;&lt;/span&gt;&lt;/code&gt;&lt;br /&gt;&lt;code&gt;&lt;span style="background-color: transparent; font-family: Arial; font-size: 11pt; font-style: italic; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"&gt;&lt;span class="Apple-tab-span" style="white-space: pre;"&gt; &lt;/span&gt;}&lt;/span&gt;&lt;/code&gt;&lt;br /&gt;&lt;code&gt;&lt;span style="background-color: transparent; font-family: Arial; font-size: 11pt; font-style: italic; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"&gt;}//end of class building&lt;/span&gt;&lt;span style="background-color: transparent; font-family: Arial; font-size: 11pt; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"&gt;&lt;/span&gt;&lt;/code&gt;&lt;/div&gt;&lt;div style="background-color: transparent;"&gt;&lt;code&gt;//&lt;i&gt;class Lift&lt;/i&gt;&lt;/code&gt;&lt;br /&gt;&lt;code&gt;&lt;span style="background-color: transparent; font-family: Arial; font-size: 11pt; font-style: italic; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"&gt;public class Lift {&lt;/span&gt;&lt;/code&gt;&lt;br /&gt;&lt;code&gt;&lt;span style="background-color: transparent; font-family: Arial; font-size: 11pt; font-style: italic; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"&gt;private Building building;&lt;/span&gt;&lt;/code&gt;&lt;br /&gt;&lt;code&gt;&lt;span style="background-color: transparent; font-family: Arial; font-size: 11pt; font-style: italic; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"&gt;private int Speed;&lt;/span&gt;&lt;/code&gt;&lt;br /&gt;&lt;code&gt;&lt;span style="background-color: transparent; font-family: Arial; font-size: 11pt; font-style: italic; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"&gt;public Lift(){&lt;/span&gt;&lt;/code&gt;&lt;br /&gt;&lt;code&gt;&lt;span style="background-color: transparent; font-family: Arial; font-size: 11pt; font-style: italic; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"&gt;&lt;span class="Apple-tab-span" style="white-space: pre;"&gt; &lt;/span&gt;building = new Building();&lt;/span&gt;&lt;/code&gt;&lt;br /&gt;&lt;code&gt;&lt;span style="background-color: transparent; font-family: Arial; font-size: 11pt; font-style: italic; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"&gt;setSpeed();&lt;/span&gt;&lt;/code&gt;&lt;br /&gt;&lt;code&gt;&lt;span style="background-color: transparent; font-family: Arial; font-size: 11pt; font-style: italic; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"&gt;&lt;span class="Apple-tab-span" style="white-space: pre;"&gt; &lt;/span&gt;}&lt;/span&gt;&lt;/code&gt;&lt;br /&gt;&lt;code&gt;&lt;span style="background-color: transparent; font-family: Arial; font-size: 11pt; font-style: italic; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"&gt;&lt;/span&gt;&lt;/code&gt;&lt;br /&gt;&lt;code&gt;&lt;span style="background-color: transparent; font-family: Arial; font-size: 11pt; font-style: italic; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"&gt;public void setSpeed(){&lt;/span&gt;&lt;/code&gt;&lt;br /&gt;&lt;code&gt;&lt;span style="background-color: transparent; font-family: Arial; font-size: 11pt; font-style: italic; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"&gt;&lt;span class="Apple-tab-span" style="white-space: pre;"&gt; &lt;/span&gt;if (building.getFloor()&amp;gt;20){&lt;/span&gt;&lt;/code&gt;&lt;br /&gt;&lt;code&gt;&lt;span style="background-color: transparent; font-family: Arial; font-size: 11pt; font-style: italic; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"&gt;&lt;span class="Apple-tab-span" style="white-space: pre;"&gt; &lt;/span&gt;&lt;span class="Apple-tab-span" style="white-space: pre;"&gt; &lt;/span&gt;//one set of functionalities&lt;/span&gt;&lt;/code&gt;&lt;br /&gt;&lt;code&gt;&lt;span style="background-color: transparent; font-family: Arial; font-size: 11pt; font-style: italic; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"&gt;&lt;span class="Apple-tab-span" style="white-space: pre;"&gt; &lt;/span&gt;&lt;span class="Apple-tab-span" style="white-space: pre;"&gt; &lt;/span&gt;//may be the the speed of the lift will be more&lt;/span&gt;&lt;/code&gt;&lt;br /&gt;&lt;code&gt;&lt;span style="background-color: transparent; font-family: Arial; font-size: 11pt; font-style: italic; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"&gt;&lt;span class="Apple-tab-span" style="white-space: pre;"&gt; &lt;/span&gt;&lt;span class="Apple-tab-span" style="white-space: pre;"&gt; &lt;/span&gt;this.Speed = 10;&lt;/span&gt;&lt;/code&gt;&lt;br /&gt;&lt;code&gt;&lt;span style="background-color: transparent; font-family: Arial; font-size: 11pt; font-style: italic; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"&gt;&lt;span class="Apple-tab-span" style="white-space: pre;"&gt; &lt;/span&gt;&lt;span class="Apple-tab-span" style="white-space: pre;"&gt; &lt;/span&gt;}&lt;/span&gt;&lt;/code&gt;&lt;br /&gt;&lt;code&gt;&lt;span style="background-color: transparent; font-family: Arial; font-size: 11pt; font-style: italic; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"&gt;&lt;span class="Apple-tab-span" style="white-space: pre;"&gt; &lt;/span&gt;else {&lt;/span&gt;&lt;/code&gt;&lt;br /&gt;&lt;code&gt;&lt;span style="background-color: transparent; font-family: Arial; font-size: 11pt; font-style: italic; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"&gt;&lt;span class="Apple-tab-span" style="white-space: pre;"&gt; &lt;/span&gt;&lt;span class="Apple-tab-span" style="white-space: pre;"&gt; &lt;/span&gt;//different set of functionalities&lt;/span&gt;&lt;/code&gt;&lt;br /&gt;&lt;code&gt;&lt;span style="background-color: transparent; font-family: Arial; font-size: 11pt; font-style: italic; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"&gt;&lt;span class="Apple-tab-span" style="white-space: pre;"&gt; &lt;/span&gt;&lt;span class="Apple-tab-span" style="white-space: pre;"&gt; &lt;/span&gt;//may be the speed of the lift will be less&lt;/span&gt;&lt;/code&gt;&lt;br /&gt;&lt;code&gt;&lt;span style="background-color: transparent; font-family: Arial; font-size: 11pt; font-style: italic; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"&gt;&lt;span class="Apple-tab-span" style="white-space: pre;"&gt; &lt;/span&gt;&lt;span class="Apple-tab-span" style="white-space: pre;"&gt; &lt;/span&gt;this.Speed = 5;&lt;/span&gt;&lt;/code&gt;&lt;br /&gt;&lt;code&gt;&lt;span style="background-color: transparent; font-family: Arial; font-size: 11pt; font-style: italic; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"&gt;&lt;span class="Apple-tab-span" style="white-space: pre;"&gt; &lt;/span&gt;&lt;span class="Apple-tab-span" style="white-space: pre;"&gt; &lt;/span&gt;}&lt;/span&gt;&lt;/code&gt;&lt;br /&gt;&lt;code&gt;&lt;span style="background-color: transparent; font-family: Arial; font-size: 11pt; font-style: italic; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"&gt;&lt;span class="Apple-tab-span" style="white-space: pre;"&gt; &lt;/span&gt;}&lt;/span&gt;&lt;/code&gt;&lt;br /&gt;&lt;code&gt;&lt;span style="background-color: transparent; font-family: Arial; font-size: 11pt; font-style: italic; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"&gt;&lt;/span&gt;&lt;/code&gt;&lt;br /&gt;&lt;code&gt;&lt;span style="background-color: transparent; font-family: Arial; font-size: 11pt; font-style: italic; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"&gt;public int getSpeed(){&lt;/span&gt;&lt;/code&gt;&lt;br /&gt;&lt;code&gt;&lt;span style="background-color: transparent; font-family: Arial; font-size: 11pt; font-style: italic; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"&gt;&lt;span class="Apple-tab-span" style="white-space: pre;"&gt; &lt;/span&gt;return Speed;&lt;/span&gt;&lt;/code&gt;&lt;br /&gt;&lt;code&gt;&lt;span style="background-color: transparent; font-family: Arial; font-size: 11pt; font-style: italic; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"&gt;&lt;span class="Apple-tab-span" style="white-space: pre;"&gt; &lt;/span&gt;}&lt;/span&gt;&lt;/code&gt;&lt;br /&gt;&lt;code&gt;&lt;span style="background-color: transparent; font-family: Arial; font-size: 11pt; font-style: italic; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"&gt;}//end of class Lift&lt;/span&gt;&lt;/code&gt;&lt;br /&gt;&lt;code&gt;&lt;span style="background-color: transparent; font-family: Arial; font-size: 11pt; font-style: italic; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"&gt;&lt;/span&gt;&lt;/code&gt;&lt;br /&gt;&lt;span style="background-color: transparent; font-family: Arial; font-size: 11pt; font-style: italic; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"&gt;&lt;/span&gt;&lt;span style="background-color: transparent; font-family: Arial; font-size: 11pt; font-style: italic; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"&gt;&lt;/span&gt;&lt;span style="background-color: transparent; font-family: Arial; font-size: 11pt; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="background-color: transparent; font-family: Arial; font-size: 11pt; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"&gt;As it becomes clear from the above code, that while creating the Building object it will create the Lift object, and while creating the Lift object, it will try to create a Building object to access some of its functionalities... So, ultimately it will go out of memory and we get a StackOverflow runtime exception... &lt;/span&gt;&lt;br /&gt;&lt;span style="background-color: transparent; font-family: Arial; font-size: 11pt; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="background-color: transparent; font-family: Arial; font-size: 11pt; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"&gt;So how do we handle this problem in Java? We actually tackle this problem by declaring an IBuildingProxy interface and by deriving our Building class from that... the lift class, instead of &lt;/span&gt;&lt;span style="background-color: transparent; font-family: Arial; font-size: 11pt; font-style: normal; font-variant: normal; font-weight: bold; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"&gt;Having&lt;/span&gt;&lt;span style="background-color: transparent; font-family: Arial; font-size: 11pt; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"&gt; Building object, it &lt;/span&gt;&lt;span style="background-color: transparent; font-family: Arial; font-size: 11pt; font-style: normal; font-variant: normal; font-weight: bold; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"&gt;Has &lt;/span&gt;&lt;span style="background-color: transparent; font-family: Arial; font-size: 11pt; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"&gt;IBuildingProxy...&lt;/span&gt;&lt;br /&gt;&lt;span style="background-color: transparent; font-family: Arial; font-size: 11pt; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="background-color: transparent; font-family: Arial; font-size: 11pt; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"&gt;the source code of the solution looks like the following...&lt;/span&gt;&lt;br /&gt;&lt;span style="background-color: transparent; font-family: Arial; font-size: 11pt; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"&gt;&lt;/span&gt;&lt;span style="background-color: transparent; font-family: Arial; font-size: 11pt; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"&gt;&lt;/span&gt;&lt;span style="background-color: transparent; font-family: Arial; font-size: 11pt; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"&gt;&lt;/span&gt;&lt;span style="background-color: transparent; font-family: Arial; font-size: 11pt; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"&gt;&lt;/span&gt;&lt;span style="background-color: transparent; font-family: Arial; font-size: 11pt; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"&gt;&lt;/span&gt;&lt;span style="background-color: transparent; font-family: Arial; font-size: 11pt; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="background-color: transparent; font-family: Arial; font-size: 11pt; font-style: italic; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"&gt;&lt;code&gt;&lt;/code&gt;&lt;/span&gt;&lt;br /&gt;&lt;code&gt;&lt;span style="background-color: transparent; font-family: Arial; font-size: 11pt; font-style: italic; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"&gt;//IBuildingProxy&lt;/span&gt;&lt;/code&gt;&lt;br /&gt;&lt;code&gt;&lt;span style="background-color: transparent; font-family: Arial; font-size: 11pt; font-style: italic; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"&gt;public interface IBuildingProxy {&lt;/span&gt;&lt;/code&gt;&lt;br /&gt;&lt;code&gt;&lt;span style="background-color: transparent; font-family: Arial; font-size: 11pt; font-style: italic; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"&gt;&lt;span class="Apple-tab-span" style="white-space: pre;"&gt; &lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;br /&gt;&lt;code&gt;&lt;span style="background-color: transparent; font-family: Arial; font-size: 11pt; font-style: italic; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"&gt;&lt;span class="Apple-tab-span" style="white-space: pre;"&gt; &lt;/span&gt;int getFloor();&lt;/span&gt;&lt;/code&gt;&lt;br /&gt;&lt;code&gt;&lt;span style="background-color: transparent; font-family: Arial; font-size: 11pt; font-style: italic; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"&gt;&lt;span class="Apple-tab-span" style="white-space: pre;"&gt; &lt;/span&gt;void setFloor(int floor); &lt;/span&gt;&lt;/code&gt;&lt;br /&gt;&lt;code&gt;&lt;span style="background-color: transparent; font-family: Arial; font-size: 11pt; font-style: italic; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"&gt;}//IBuildingProxy&lt;/span&gt;&lt;/code&gt;&lt;br /&gt;&lt;code&gt;&lt;span style="background-color: transparent; font-family: Arial; font-size: 11pt; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"&gt;&lt;/span&gt;&lt;span style="background-color: transparent; font-family: Arial; font-size: 11pt; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"&gt;&lt;/span&gt;&lt;/code&gt;&lt;br /&gt;&lt;code&gt;&lt;span style="background-color: transparent; font-family: Arial; font-size: 11pt; font-style: italic; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"&gt; &lt;/span&gt;&lt;/code&gt;&lt;br /&gt;&lt;code&gt;&lt;span style="background-color: transparent; font-family: Arial; font-size: 11pt; font-style: italic; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"&gt;//class Building&lt;/span&gt;&lt;/code&gt;&lt;br /&gt;&lt;code&gt;&lt;span style="background-color: transparent; font-family: Arial; font-size: 11pt; font-style: italic; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"&gt;public class Building implements IBuildingProxy{&lt;/span&gt;&lt;/code&gt;&lt;br /&gt;&lt;code&gt;&lt;span style="background-color: transparent; font-family: Arial; font-size: 11pt; font-style: italic; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"&gt;private Lift lift;&lt;/span&gt;&lt;/code&gt;&lt;br /&gt;&lt;code&gt;&lt;span style="background-color: transparent; font-family: Arial; font-size: 11pt; font-style: italic; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"&gt;private int floor;&lt;/span&gt;&lt;/code&gt;&lt;br /&gt;&lt;code&gt;&lt;span style="background-color: transparent; font-family: Arial; font-size: 11pt; font-style: italic; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"&gt;public Building(){&lt;/span&gt;&lt;/code&gt;&lt;br /&gt;&lt;code&gt;&lt;span style="background-color: transparent; font-family: Arial; font-size: 11pt; font-style: italic; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"&gt;&lt;span class="Apple-tab-span" style="white-space: pre;"&gt; &lt;/span&gt;lift = new Lift(this);&lt;/span&gt;&lt;/code&gt;&lt;br /&gt;&lt;code&gt;&lt;span class="Apple-style-span" style="font-family: Arial;"&gt;&lt;span class="Apple-style-span" style="font-size: 15px; white-space: pre;"&gt;&lt;i&gt;setFloor(15);&lt;/i&gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;br /&gt;&lt;code&gt;&lt;span style="background-color: transparent; font-family: Arial; font-size: 11pt; font-style: italic; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"&gt;&lt;span class="Apple-tab-span" style="white-space: pre;"&gt; &lt;/span&gt;}&lt;/span&gt;&lt;/code&gt;&lt;br /&gt;&lt;code&gt;&lt;span style="background-color: transparent; font-family: Arial; font-size: 11pt; font-style: italic; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"&gt;public int getFloor(){&lt;/span&gt;&lt;/code&gt;&lt;br /&gt;&lt;code&gt;&lt;span style="background-color: transparent; font-family: Arial; font-size: 11pt; font-style: italic; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"&gt;&lt;span class="Apple-tab-span" style="white-space: pre;"&gt; &lt;/span&gt;return floor;&lt;/span&gt;&lt;/code&gt;&lt;br /&gt;&lt;code&gt;&lt;span style="background-color: transparent; font-family: Arial; font-size: 11pt; font-style: italic; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"&gt;&lt;span class="Apple-tab-span" style="white-space: pre;"&gt; &lt;/span&gt;}&lt;/span&gt;&lt;/code&gt;&lt;br /&gt;&lt;code&gt;&lt;span style="background-color: transparent; font-family: Arial; font-size: 11pt; font-style: italic; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"&gt;&lt;/span&gt;&lt;/code&gt;&lt;br /&gt;&lt;code&gt;&lt;span style="background-color: transparent; font-family: Arial; font-size: 11pt; font-style: italic; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"&gt;public void setFloor(int floor){&lt;/span&gt;&lt;/code&gt;&lt;br /&gt;&lt;code&gt;&lt;span style="background-color: transparent; font-family: Arial; font-size: 11pt; font-style: italic; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"&gt;&lt;span class="Apple-tab-span" style="white-space: pre;"&gt; &lt;/span&gt;this.floor = floor;&lt;/span&gt;&lt;/code&gt;&lt;br /&gt;&lt;code&gt;&lt;span style="background-color: transparent; font-family: Arial; font-size: 11pt; font-style: italic; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"&gt;&lt;span class="Apple-tab-span" style="white-space: pre;"&gt; &lt;/span&gt;}&lt;/span&gt;&lt;/code&gt;&lt;br /&gt;&lt;code&gt;&lt;span style="background-color: transparent; font-family: Arial; font-size: 11pt; font-style: italic; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"&gt;}&lt;/span&gt;&lt;/code&gt;&lt;br /&gt;&lt;code&gt;&lt;span style="background-color: transparent; font-family: Arial; font-size: 11pt; font-style: italic; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"&gt;&lt;/span&gt;&lt;/code&gt;&lt;br /&gt;&lt;code&gt;&lt;span style="background-color: transparent; font-family: Arial; font-size: 11pt; font-style: italic; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"&gt;//class Lift&lt;/span&gt;&lt;/code&gt;&lt;br /&gt;&lt;code&gt;&lt;span style="background-color: transparent; font-family: Arial; font-size: 11pt; font-style: italic; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"&gt;public class Lift {&lt;/span&gt;&lt;/code&gt;&lt;br /&gt;&lt;code&gt;&lt;span style="background-color: transparent; font-family: Arial; font-size: 11pt; font-style: italic; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"&gt;private IBuildingProxy building;&lt;/span&gt;&lt;/code&gt;&lt;br /&gt;&lt;code&gt;&lt;span style="background-color: transparent; font-family: Arial; font-size: 11pt; font-style: italic; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"&gt;private int Speed;&lt;/span&gt;&lt;/code&gt;&lt;br /&gt;&lt;code&gt;&lt;span style="background-color: transparent; font-family: Arial; font-size: 11pt; font-style: italic; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"&gt;public Lift(Building b){&lt;/span&gt;&lt;/code&gt;&lt;br /&gt;&lt;code&gt;&lt;span style="background-color: transparent; font-family: Arial; font-size: 11pt; font-style: italic; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"&gt;&lt;span class="Apple-tab-span" style="white-space: pre;"&gt; &lt;/span&gt;this.building = b;&lt;/span&gt;&lt;/code&gt;&lt;br /&gt;&lt;code&gt;&lt;span style="background-color: transparent; font-family: Arial; font-size: 11pt; font-style: italic; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"&gt;setSpeed();&lt;/span&gt;&lt;/code&gt;&lt;br /&gt;&lt;code&gt;&lt;span style="background-color: transparent; font-family: Arial; font-size: 11pt; font-style: italic; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"&gt;&lt;span class="Apple-tab-span" style="white-space: pre;"&gt; &lt;/span&gt;}&lt;/span&gt;&lt;/code&gt;&lt;br /&gt;&lt;code&gt;&lt;span style="background-color: transparent; font-family: Arial; font-size: 11pt; font-style: italic; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"&gt;public void setSpeed(){&lt;/span&gt;&lt;/code&gt;&lt;br /&gt;&lt;code&gt;&lt;span style="background-color: transparent; font-family: Arial; font-size: 11pt; font-style: italic; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"&gt;&lt;span class="Apple-tab-span" style="white-space: pre;"&gt; &lt;/span&gt;if (building.getFloor()&amp;gt;20){&lt;/span&gt;&lt;/code&gt;&lt;br /&gt;&lt;code&gt;&lt;span style="background-color: transparent; font-family: Arial; font-size: 11pt; font-style: italic; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"&gt;&lt;span class="Apple-tab-span" style="white-space: pre;"&gt; &lt;/span&gt;&lt;span class="Apple-tab-span" style="white-space: pre;"&gt; &lt;/span&gt;//one set of functionalities&lt;/span&gt;&lt;/code&gt;&lt;br /&gt;&lt;code&gt;&lt;span style="background-color: transparent; font-family: Arial; font-size: 11pt; font-style: italic; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"&gt;&lt;span class="Apple-tab-span" style="white-space: pre;"&gt; &lt;/span&gt;&lt;span class="Apple-tab-span" style="white-space: pre;"&gt; &lt;/span&gt;//may be the the speed of the lift will be more&lt;/span&gt;&lt;/code&gt;&lt;br /&gt;&lt;code&gt;&lt;span style="background-color: transparent; font-family: Arial; font-size: 11pt; font-style: italic; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"&gt;&lt;span class="Apple-tab-span" style="white-space: pre;"&gt; &lt;/span&gt;&lt;span class="Apple-tab-span" style="white-space: pre;"&gt; &lt;/span&gt;this.Speed = 10;&lt;/span&gt;&lt;/code&gt;&lt;br /&gt;&lt;code&gt;&lt;span style="background-color: transparent; font-family: Arial; font-size: 11pt; font-style: italic; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"&gt;&lt;span class="Apple-tab-span" style="white-space: pre;"&gt; &lt;/span&gt;&lt;span class="Apple-tab-span" style="white-space: pre;"&gt; &lt;/span&gt;}&lt;/span&gt;&lt;/code&gt;&lt;br /&gt;&lt;code&gt;&lt;span style="background-color: transparent; font-family: Arial; font-size: 11pt; font-style: italic; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"&gt;&lt;span class="Apple-tab-span" style="white-space: pre;"&gt; &lt;/span&gt;else {&lt;/span&gt;&lt;/code&gt;&lt;br /&gt;&lt;code&gt;&lt;span style="background-color: transparent; font-family: Arial; font-size: 11pt; font-style: italic; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"&gt;&lt;span class="Apple-tab-span" style="white-space: pre;"&gt; &lt;/span&gt;&lt;span class="Apple-tab-span" style="white-space: pre;"&gt; &lt;/span&gt;//different set of functionalities&lt;/span&gt;&lt;/code&gt;&lt;br /&gt;&lt;code&gt;&lt;span style="background-color: transparent; font-family: Arial; font-size: 11pt; font-style: italic; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"&gt;&lt;span class="Apple-tab-span" style="white-space: pre;"&gt; &lt;/span&gt;&lt;span class="Apple-tab-span" style="white-space: pre;"&gt; &lt;/span&gt;//may be the speed of the lift will be less&lt;/span&gt;&lt;/code&gt;&lt;br /&gt;&lt;code&gt;&lt;span style="background-color: transparent; font-family: Arial; font-size: 11pt; font-style: italic; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"&gt;&lt;span class="Apple-tab-span" style="white-space: pre;"&gt; &lt;/span&gt;&lt;span class="Apple-tab-span" style="white-space: pre;"&gt; &lt;/span&gt;this.Speed = 5;&lt;/span&gt;&lt;/code&gt;&lt;br /&gt;&lt;code&gt;&lt;span style="background-color: transparent; font-family: Arial; font-size: 11pt; font-style: italic; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"&gt;&lt;span class="Apple-tab-span" style="white-space: pre;"&gt; &lt;/span&gt;&lt;span class="Apple-tab-span" style="white-space: pre;"&gt; &lt;/span&gt;}&lt;/span&gt;&lt;/code&gt;&lt;br /&gt;&lt;code&gt;&lt;span style="background-color: transparent; font-family: Arial; font-size: 11pt; font-style: italic; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"&gt;&lt;span class="Apple-tab-span" style="white-space: pre;"&gt; &lt;/span&gt;}&lt;/span&gt;&lt;/code&gt;&lt;br /&gt;&lt;code&gt;&lt;span style="background-color: transparent; font-family: Arial; font-size: 11pt; font-style: italic; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"&gt;&lt;/span&gt;&lt;/code&gt;&lt;br /&gt;&lt;code&gt;&lt;span style="background-color: transparent; font-family: Arial; font-size: 11pt; font-style: italic; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"&gt;public int getSpeed(){&lt;/span&gt;&lt;/code&gt;&lt;br /&gt;&lt;code&gt;&lt;span style="background-color: transparent; font-family: Arial; font-size: 11pt; font-style: italic; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"&gt;&lt;span class="Apple-tab-span" style="white-space: pre;"&gt; &lt;/span&gt;return Speed;&lt;/span&gt;&lt;/code&gt;&lt;br /&gt;&lt;code&gt;&lt;span style="background-color: transparent; font-family: Arial; font-size: 11pt; font-style: italic; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"&gt;&lt;span class="Apple-tab-span" style="white-space: pre;"&gt; &lt;/span&gt;}&lt;/span&gt;&lt;/code&gt;&lt;br /&gt;&lt;code&gt;&lt;span style="background-color: transparent; font-family: Arial; font-size: 11pt; font-style: italic; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"&gt;}&lt;/span&gt;&lt;/code&gt;&lt;br /&gt;&lt;code&gt;&lt;span style="background-color: transparent; font-family: Arial; font-size: 11pt; font-style: italic; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"&gt;&lt;/span&gt;&lt;/code&gt;&lt;br /&gt;&lt;code&gt;&lt;span style="background-color: transparent; font-family: Arial; font-size: 11pt; font-style: italic; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"&gt;and the code of the main class is&lt;/span&gt;&lt;/code&gt;&lt;br /&gt;&lt;code&gt;&lt;span style="background-color: transparent; font-family: Arial; font-size: 11pt; font-style: italic; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"&gt;&lt;/span&gt;&lt;/code&gt;&lt;br /&gt;&lt;code&gt;&lt;span style="background-color: transparent; font-family: Arial; font-size: 11pt; font-style: italic; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"&gt;public class CircularDependencyTest {&lt;span class="Apple-tab-span" style="white-space: pre;"&gt; &lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;br /&gt;&lt;code&gt;&lt;span style="background-color: transparent; font-family: Arial; font-size: 11pt; font-style: italic; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"&gt;public static void main(String[] args){&lt;/span&gt;&lt;/code&gt;&lt;br /&gt;&lt;code&gt;&lt;span style="background-color: transparent; font-family: Arial; font-size: 11pt; font-style: italic; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"&gt;&lt;span class="Apple-tab-span" style="white-space: pre;"&gt; &lt;/span&gt;Building b = new Building();&lt;/span&gt;&lt;/code&gt;&lt;br /&gt;&lt;code&gt;&lt;span style="background-color: transparent; font-family: Arial; font-size: 11pt; font-style: italic; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"&gt;&lt;span class="Apple-tab-span" style="white-space: pre;"&gt; &lt;/span&gt;Lift l = new Lift(b);&lt;/span&gt;&lt;/code&gt;&lt;br /&gt;&lt;code&gt;&lt;span style="background-color: transparent; font-family: Arial; font-size: 11pt; font-style: italic; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"&gt;}&lt;/span&gt;&lt;/code&gt;&lt;br /&gt;&lt;code&gt;&lt;span style="background-color: transparent; font-family: Arial; font-size: 11pt; font-style: italic; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"&gt;}&lt;/span&gt;&lt;/code&gt;&lt;br /&gt;&lt;code&gt;&lt;span style="background-color: transparent; font-family: Arial; font-size: 11pt; font-style: italic; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"&gt;&lt;/span&gt;&lt;/code&gt;&lt;br /&gt;&lt;span style="background-color: transparent; font-family: Arial; font-size: 11pt; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"&gt;So whats the principle behind such work around... It will be clear soon...&lt;/span&gt;&lt;br /&gt;&lt;span style="background-color: transparent; font-family: Arial; font-size: 11pt; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"&gt; &lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="font-family: Arial;"&gt;&lt;span class="Apple-style-span" style="font-size: 15px; white-space: pre-wrap;"&gt;As it becomes clear from the code that Building &lt;b&gt;HAS &lt;/b&gt;Lift... That is not a problem... Now when it comes to solve the part that Lift &lt;b&gt;HAS &lt;/b&gt;Building, instead of the Building object, we have created an IBuildingProxy interface and we pass it to the Lift class... what it essentially means, that the building class knows the memory requirement to initialize the Lift object, and as the Lift class &lt;b&gt;HAS &lt;/b&gt;just a proxy interface of the Building, it does not have to care for the Building's memory requirement... and that solves the problem...&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="font-family: Arial;"&gt;&lt;span class="Apple-style-span" style="font-size: 15px; white-space: pre-wrap;"&gt; &lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="background-color: transparent; font-family: Arial; font-size: 11pt; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"&gt;Hope this discussion becomes helpful for Java learners...&lt;/span&gt;&lt;br /&gt;&lt;span style="background-color: transparent; color: black; font-family: Arial; font-size: 11pt; font-style: italic; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"&gt;&lt;/span&gt;&lt;span style="background-color: transparent; color: black; font-family: Arial; font-size: 11pt; font-style: italic; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"&gt;&lt;/span&gt;&lt;span style="background-color: transparent; color: black; font-family: Arial; font-size: 11pt; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"&gt;&lt;/span&gt;&lt;span style="background-color: transparent; color: black; font-family: Arial; font-size: 11pt; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"&gt;&lt;/span&gt;&lt;span style="background-color: transparent; color: black; font-family: Arial; font-size: 11pt; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"&gt;&lt;/span&gt;&lt;span style="background-color: transparent; color: black; font-family: Arial; font-size: 11pt; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"&gt;&lt;/span&gt;&lt;span style="background-color: transparent; color: black; font-family: Arial; font-size: 11pt; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"&gt;&lt;/span&gt;&lt;span style="background-color: transparent; color: black; font-family: Arial; font-size: 11pt; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"&gt;&lt;/span&gt;&lt;/div&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3946478681282550454-6324188549818408093?l=som-itsolutions.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://som-itsolutions.blogspot.com/feeds/6324188549818408093/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=3946478681282550454&amp;postID=6324188549818408093' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3946478681282550454/posts/default/6324188549818408093'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3946478681282550454/posts/default/6324188549818408093'/><link rel='alternate' type='text/html' href='http://som-itsolutions.blogspot.com/2011/10/tackling-circular-dependency-in-java.html' title='Tackling the Circular Dependency in Java...'/><author><name>Som</name><uri>http://www.blogger.com/profile/09519633424407534012</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='24' src='http://3.bp.blogspot.com/-XVhL110Tyf8/ThxKF3DBYcI/AAAAAAAAEBo/arVXUPsgtSg/s220/NJ%2B042.JPG'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3946478681282550454.post-6728261593335908417</id><published>2011-10-05T13:23:00.082+05:30</published><updated>2011-10-30T20:05:06.703+05:30</updated><title type='text'>My Android AsyncTask implementation vis-a-vis Command Pattern...</title><content type='html'>&lt;div dir="ltr" style="text-align: left;" trbidi="on"&gt;&lt;span class="Apple-style-span" style="font-family: Arial; font-size: 15px; white-space: pre-wrap;"&gt;As i was developing a sample Android App to showcase the Android AsyncTask, i found it very much similar to the Command design pattern. i would like to share this with you...&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="font-family: Arial; font-size: 15px; white-space: pre-wrap;"&gt; &lt;/span&gt;&lt;br /&gt;&lt;div style="background-color: transparent;"&gt;&lt;span style="background-color: transparent; font-family: Arial; font-size: 11pt; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="background-color: transparent; font-family: Arial; font-size: 11pt; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"&gt;Let me first state about the Command design pattern. The purpose of the command pattern is to associate a command object with its receiver where the receiver knows what to do when this command is called... We have an interface called command, from where we deduce different concrete commend classes... The client creates the concrete command objects passing the information of the receiver for that command... And when the invoker ( which is generally a framework object) calls the execute method of the command, the concrete command actually executes it with the help of the Receiver’s functionalities... &lt;/span&gt;&lt;br /&gt;&lt;span style="background-color: transparent; font-family: Arial; font-size: 11pt; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="background-color: transparent; font-family: Arial; font-size: 11pt; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"&gt; &lt;/span&gt;&lt;br /&gt;&lt;div style="text-align: center;"&gt;&lt;span style="background-color: transparent; font-family: Arial; font-size: 11pt; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"&gt;The class diagram of the command pattern is as follows:&lt;/span&gt;&lt;a href="http://4.bp.blogspot.com/-ixExOG4NM7k/TqoB53pJS3I/AAAAAAAAEEg/QkNE-5ySO8s/s1600/3.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img border="0" height="320" src="http://4.bp.blogspot.com/-ixExOG4NM7k/TqoB53pJS3I/AAAAAAAAEEg/QkNE-5ySO8s/s320/3.png" width="320" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;/div&gt;&lt;span style="background-color: transparent; color: black; font-family: Arial; font-size: 11pt; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="background-color: transparent; font-family: Arial; font-size: 11pt; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"&gt;And the sequence diagram is as follows:&lt;/span&gt;&lt;br /&gt;&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://2.bp.blogspot.com/-Fp3codkChVs/TqoCEs-vM7I/AAAAAAAAEEo/4baQZ4TxlKo/s1600/2.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img border="0" height="320" src="http://2.bp.blogspot.com/-Fp3codkChVs/TqoCEs-vM7I/AAAAAAAAEEo/4baQZ4TxlKo/s320/2.png" width="320" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;span style="background-color: transparent; font-family: Arial; font-size: 11pt; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;/div&gt;&lt;span style="background-color: transparent; color: black; font-family: Arial; font-size: 11pt; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="background-color: transparent; color: black; font-family: Arial; font-size: 11pt; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="background-color: transparent; font-family: Arial; font-size: 11pt; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"&gt;Now let me decipher my App to show how it implements the command pattern... the class diagram of this application looks like the following:&lt;/span&gt;&lt;br /&gt;&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://2.bp.blogspot.com/-gVwuNrckxyM/TqjySYjhYRI/AAAAAAAAEEM/FybR6Ul4s98/s1600/AsyncTaskUML.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img border="0" height="183" src="http://2.bp.blogspot.com/-gVwuNrckxyM/TqjySYjhYRI/AAAAAAAAEEM/FybR6Ul4s98/s320/AsyncTaskUML.png" width="320" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;span style="background-color: transparent; font-family: Arial; font-size: 11pt; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;/div&gt;&lt;span style="background-color: transparent; color: black; font-family: Arial; font-size: 11pt; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="background-color: transparent; font-family: Arial; vertical-align: baseline;"&gt;&lt;span class="Apple-style-span" style="font-size: 11pt; white-space: pre-wrap;"&gt;As it becomes clear from the code, the client (which is the Activity class) creates a concrete command class, the Callback interface through the concept of &lt;/span&gt;&lt;/span&gt;&lt;span style="background-color: transparent; font-family: Arial; vertical-align: baseline;"&gt;&lt;span class="Apple-style-span" style="font-size: 15px; white-space: pre-wrap;"&gt;Anonymous inner class (see the code&amp;nbsp;c = new CallBack() {.....};&lt;/span&gt;&lt;span class="Apple-style-span" style="font-size: 11pt; white-space: pre-wrap;"&gt; it then stores this command in the invoker (the MyAsyncTask class) by passing the reference to the invoker (see the line of code &lt;/span&gt;&lt;/span&gt;aTask = new MyAsyncTask(c))&lt;span class="Apple-style-span" style="font-family: Arial;"&gt;&lt;span class="Apple-style-span" style="font-size: 11pt; white-space: pre-wrap;"&gt;.. . the invoker (the MyAsyncTask class here) stores a reference to this command object... then if something interesting happens, the invoker calls the &lt;/span&gt;&lt;span class="Apple-style-span" style="font-size: 15px; white-space: pre-wrap;"&gt;functionality from the callback interface (the command)... the functionality of the callback interface have been implemented in the Client (the Activity class)...&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="font-family: Arial;"&gt;&lt;span class="Apple-style-span" style="font-size: 15px; white-space: pre-wrap;"&gt; &lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="background-color: transparent; font-family: Arial; font-size: 11pt; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"&gt;hence i think that my implementation of the Asynctask is very similar to the Command design pattern implementation...&lt;/span&gt;&lt;br /&gt;&lt;span style="background-color: transparent; font-family: Arial; font-size: 11pt; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="background-color: transparent; font-family: Arial; font-size: 11pt; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"&gt;Hope this discussion helps the android learners...&lt;/span&gt;&lt;/div&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="font-family: Arial; white-space: pre-wrap;"&gt; &lt;a href="https://docs.google.com/document/d/12J8wxHH2hRJ_JGTTOtQOOKQtSqPnrqyBcvdpDpHTb0s/edit?hl=en_US"&gt;Here &lt;/a&gt;is my AsyncTask implementation.. &lt;/span&gt;&lt;a href="https://docs.google.com/document/d/15R3OAvA292CJCSCszN1gc9SxZPwFeRY8RSNWhH8wmho/edit?hl=en_US"&gt;Here &lt;/a&gt;you can find the callback interface...&lt;span class="Apple-style-span" style="font-family: Arial;"&gt;&lt;span class="Apple-style-span" style="white-space: pre-wrap;"&gt;&amp;nbsp;&lt;/span&gt;&lt;/span&gt;And you can find the main Activity class &lt;a href="https://docs.google.com/document/d/1TD7dqAqE5i9ZuRqsfHtu2EE3wJ0vqEj_tA6bNE96nLw/edit?hl=en_US"&gt;here&lt;/a&gt;.&lt;br /&gt;&lt;div style="background-color: transparent;"&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;"&gt;And &lt;a href="https://docs.google.com/leaf?id=0B8L15NA4lO_UOTk4NzVlNjEtNGQwYS00ZDRkLTkxYTYtNmIyM2EwNmI1NzMx&amp;amp;hl=en_US"&gt;here&lt;/a&gt; goes the apk of the sample app... You can clone the whole source from &lt;a href="https://github.com/sommukhopadhyay/AsyncTask"&gt;here&lt;/a&gt;...&lt;/span&gt;&lt;/div&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3946478681282550454-6728261593335908417?l=som-itsolutions.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://som-itsolutions.blogspot.com/feeds/6728261593335908417/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=3946478681282550454&amp;postID=6728261593335908417' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3946478681282550454/posts/default/6728261593335908417'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3946478681282550454/posts/default/6728261593335908417'/><link rel='alternate' type='text/html' href='http://som-itsolutions.blogspot.com/2011/10/android-asynctask-demistified.html' title='My Android AsyncTask implementation vis-a-vis Command Pattern...'/><author><name>Som</name><uri>http://www.blogger.com/profile/09519633424407534012</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='24' src='http://3.bp.blogspot.com/-XVhL110Tyf8/ThxKF3DBYcI/AAAAAAAAEBo/arVXUPsgtSg/s220/NJ%2B042.JPG'/></author><media:thumbnail xmlns:media='http://search.yahoo.com/mrss/' url='http://4.bp.blogspot.com/-ixExOG4NM7k/TqoB53pJS3I/AAAAAAAAEEg/QkNE-5ySO8s/s72-c/3.png' height='72' width='72'/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3946478681282550454.post-5109829826796696875</id><published>2011-08-05T14:26:00.003+05:30</published><updated>2011-08-06T07:59:00.844+05:30</updated><title type='text'>Observer Pattern in MFC</title><content type='html'>&lt;div dir="ltr" style="text-align: left;" trbidi="on"&gt;&lt;span class="Apple-style-span" style="font-size: 16px;"&gt;&lt;/span&gt;&lt;br /&gt;&lt;div class="western" id="rfqe0" style="margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;"&gt;&lt;div style="margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; text-align: left;"&gt;As I walk through the different design concepts of the Design Pattern book by GoF, I usually try to&amp;nbsp;find from my past experience about any practical implementation of these patterns. This way I found&amp;nbsp;out one practical implementation of the Observer Pattern in microsoft foundation class (MFC) library&amp;nbsp;which I would like to share with you.&lt;/div&gt;&lt;/div&gt;&lt;div class="western" id="rfqe1" style="margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;"&gt;&lt;div style="margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;"&gt;&lt;br id="rfqe2" /&gt;&lt;/div&gt;&lt;/div&gt;&lt;div class="western" id="rfqe3" style="margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;"&gt;&lt;div style="margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;"&gt;Before explaining the application of Observer Pattern in MFC, let me give you a brief introduction of&amp;nbsp;this pattern. Observer pattern helps you in notifying and updating all the dependent objects, if one&amp;nbsp;object changes state. This pattern has two main objects – Subject and Observer. Multiple number of&amp;nbsp;observers can be attached to a particular Subject. All the observers are notified and in turn gotten&amp;nbsp;updated if the Subject changes its state. This is also known as the publish-subscribe. The subject is&amp;nbsp;the publisher of changes, and the Observers are the subscribers to those changes.&lt;/div&gt;&lt;/div&gt;&lt;div class="western" id="rfqe4" style="margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;"&gt;&lt;div style="margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;"&gt;&lt;br id="rfqe5" /&gt;&lt;/div&gt;&lt;/div&gt;&lt;div class="western" id="rfqe6" style="margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;"&gt;&lt;div style="margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;"&gt;The class diagram will look like the following.&lt;/div&gt;&lt;/div&gt;&lt;div class="western" id="rfqe7" style="margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;"&gt;&lt;div style="margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;/div&gt;&lt;div id="odo9" style="margin-bottom: 0px; margin-top: 0px; text-align: left;"&gt;&lt;div style="margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;"&gt;&lt;img id="qb5c0" src="https://docs.google.com/a/som-itsolutions.com/File?id=dcgcp339_243cqq8vgdw_b" style="cursor: move;" /&gt;&lt;/div&gt;&lt;/div&gt;&lt;div class="western" id="r4v90" style="margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;"&gt;&lt;div style="margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;/div&gt;&lt;div id="irot" style="margin-bottom: 0px; margin-top: 0px; text-align: left;"&gt;&lt;div id="yjmg" style="margin-bottom: 0px; margin-top: 0px; text-align: left;"&gt;&lt;div style="margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;"&gt;And the sequence diagram of this pattern is like this.&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;div class="western" id="n2lb0" style="margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;"&gt;&lt;div style="margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;/div&gt;&lt;div id="iygk" style="margin-bottom: 0px; margin-top: 0px; text-align: left;"&gt;&lt;div style="margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;"&gt;&lt;img id="mls60" src="https://docs.google.com/a/som-itsolutions.com/File?id=dcgcp339_24092pb4wgw_b" style="cursor: move;" /&gt;&lt;/div&gt;&lt;/div&gt;&lt;div class="western" id="n:y_2" style="margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;"&gt;&lt;div style="margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;/div&gt;&lt;div class="western" id="n2lb1" style="margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;"&gt;&lt;div style="margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;"&gt;What these two diagrams essentially depict is that in the Observer Pattern, we have a Subject, which&amp;nbsp;can attach one or more Observers through its Attach() function. Whenever it changes its state it&amp;nbsp;Notifies all the attached Observers through its Notify function. The observers in turn synchronize their&amp;nbsp;states with that of the Subject through the GetSubjectState function.&lt;/div&gt;&lt;/div&gt;&lt;div class="western" id="rfqe25" style="margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;"&gt;&lt;div style="margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;"&gt;&lt;br id="rfqe26" /&gt;&lt;/div&gt;&lt;/div&gt;&lt;div class="western" id="rfqe27" style="margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;"&gt;&lt;div style="margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;"&gt;Now let me dissect the MFC's Document-View architecture and explain how the Observer Pattern&amp;nbsp;has been implemented there. In MFC, the Document acts as the Subject and the views attached to it&amp;nbsp;act as the observers. The Document (Subject) has to notify and update the views (observers)&amp;nbsp;whenever it changes its state. This is done through the function UpdateAllViews () of the CDocument&amp;nbsp;class.&lt;/div&gt;&lt;/div&gt;&lt;div class="western" id="rfqe28" style="margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;"&gt;&lt;div style="margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;"&gt;&lt;br id="rfqe29" /&gt;&lt;/div&gt;&lt;/div&gt;&lt;div class="western" id="rfqe30" style="margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;"&gt;&lt;div style="margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;"&gt;Let me show you the actual code of the UpdateAllViews from doccore.cpp under the MFC folder.&amp;nbsp;&lt;/div&gt;&lt;/div&gt;&lt;div class="western" id="rfqe33" style="margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;"&gt;&lt;div style="margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;"&gt;void&lt;/div&gt;&lt;/div&gt;&lt;div class="western" id="v1hk0" style="margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;"&gt;&lt;div style="margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;"&gt;CDocument :: UpdateAllViews(CView* pSender,&lt;/div&gt;&lt;/div&gt;&lt;div class="western" id="v1hk3" style="margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;"&gt;&lt;div style="margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;"&gt;&amp;nbsp;LPARAM lHint,&lt;/div&gt;&lt;/div&gt;&lt;div class="western" id="v1hk7" style="margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;"&gt;&lt;div style="margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;"&gt;&amp;nbsp;CObject* pHint)&lt;/div&gt;&lt;/div&gt;&lt;div class="western" id="rfqe42" style="margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;"&gt;&lt;div style="margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;"&gt;{&lt;/div&gt;&lt;/div&gt;&lt;div class="western" id="rfqe44" style="margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;"&gt;&lt;div style="margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;"&gt;ASSERT(pSender == NULL || !m_viewList.IsEmpty());&lt;/div&gt;&lt;/div&gt;&lt;div class="western" id="rfqe50" style="margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;"&gt;&lt;div style="margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;"&gt;&lt;br id="rfqe51" /&gt;&lt;/div&gt;&lt;/div&gt;&lt;div class="western" id="rfqe52" style="margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;"&gt;&lt;div style="margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;"&gt;POSITION pos = GetFirstViewPosition();&lt;/div&gt;&lt;/div&gt;&lt;div class="western" id="rfqe54" style="margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;"&gt;&lt;div style="margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;"&gt;while (pos != NULL)&lt;/div&gt;&lt;/div&gt;&lt;div class="western" id="rfqe59" style="margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;"&gt;&lt;div style="margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;"&gt;{&lt;/div&gt;&lt;/div&gt;&lt;div class="western" id="rfqe61" style="margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;"&gt;&lt;div style="margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;"&gt;CView* pView = GetNextView(pos);&lt;/div&gt;&lt;/div&gt;&lt;div class="western" id="rfqe63" style="margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;"&gt;&lt;div style="margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;"&gt;ASSERT_VALID(pView);&lt;/div&gt;&lt;/div&gt;&lt;div class="western" id="rfqe65" style="margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;"&gt;&lt;div style="margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;"&gt;if (pView != pSender)&lt;/div&gt;&lt;/div&gt;&lt;div class="western" id="rfqe70" style="margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;"&gt;&lt;div style="margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;"&gt;pView-&amp;gt;OnUpdate(pSender, lHint, pHint);&lt;/div&gt;&lt;/div&gt;&lt;div class="western" id="rfqe72" style="margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;"&gt;&lt;div style="margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;"&gt;}&lt;/div&gt;&lt;/div&gt;&lt;div class="western" id="rfqe74" style="margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;"&gt;&lt;div style="margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;"&gt;}&lt;/div&gt;&lt;/div&gt;&lt;div class="western" id="rfqe76" style="margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;"&gt;&lt;div style="margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;"&gt;As you can see from the code that UpdateAllViews function actually traverses through all the views attached through it and call the view's OnUpdate function. Hence UpdateAllViews acts as the Notify function of the Observer pattern.&lt;/div&gt;&lt;/div&gt;&lt;div class="western" id="rfqe82" style="margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;"&gt;&lt;div style="margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;"&gt;&lt;br id="rfqe83" /&gt;&lt;/div&gt;&lt;/div&gt;&lt;div class="western" id="rfqe84" style="margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;"&gt;&lt;div style="margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;"&gt;Let me show you the actual code of OnUpdate from viewcore.cpp. It goes like this:&lt;/div&gt;&lt;/div&gt;&lt;div class="western" id="rfqe86" style="margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;"&gt;&lt;div style="margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;"&gt;&lt;br id="rfqe87" /&gt;&lt;/div&gt;&lt;/div&gt;&lt;div class="western" id="rfqe88" style="margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;"&gt;&lt;div style="margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;"&gt;void&lt;/div&gt;&lt;/div&gt;&lt;div class="western" id="y.an0" style="margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;"&gt;&lt;div style="margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;"&gt;CView :: OnUpdate(CView* pSender,&lt;/div&gt;&lt;/div&gt;&lt;div class="western" id="y.an3" style="margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;"&gt;&lt;div style="margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;"&gt;LPARAM&lt;/div&gt;&lt;/div&gt;&lt;div class="western" id="y.an7" style="margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;"&gt;&lt;div style="margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;"&gt;CObject*&lt;/div&gt;&lt;/div&gt;&lt;div class="western" id="bag:0" style="margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;"&gt;&lt;div style="margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;"&gt;{&lt;/div&gt;&lt;/div&gt;&lt;div class="western" id="rfqe99" style="margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;"&gt;&lt;div style="margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;"&gt;ASSERT(pSender != this);&lt;/div&gt;&lt;/div&gt;&lt;div class="western" id="rfqe105" style="margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;"&gt;&lt;div style="margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;"&gt;UNUSED(pSender);&amp;nbsp;&lt;/div&gt;&lt;/div&gt;&lt;div class="western" id="rfqe116" style="margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;"&gt;&lt;div style="margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;"&gt;Invalidate(TRUE);&lt;/div&gt;&lt;/div&gt;&lt;div class="western" id="rfqe118" style="margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;"&gt;&lt;div style="margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;"&gt;}&lt;/div&gt;&lt;/div&gt;&lt;div class="western" id="rfqe120" style="margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;"&gt;&lt;div style="margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;"&gt;&lt;br id="rfqe121" /&gt;&lt;/div&gt;&lt;/div&gt;&lt;div class="western" id="rfqe122" style="margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;"&gt;&lt;div style="margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;"&gt;As its is clear from the above code, that the OnUpdate function will actually invalidate the view area,&amp;nbsp;which will force the views to redraw themselves synchronizing their states with the current state of the Document.&lt;/div&gt;&lt;/div&gt;&lt;div class="western" id="rfqe124" style="margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;"&gt;&lt;div style="margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;"&gt;&lt;br id="rfqe125" /&gt;&lt;/div&gt;&lt;/div&gt;&lt;div class="western" id="rfqe126" style="margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;"&gt;&lt;div style="margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;"&gt;This is all about the notification from Document to View. But what about the Attach and Detach&amp;nbsp;function of the Subject. We have similar functions in the Document class which are as follows:&lt;/div&gt;&lt;/div&gt;&lt;div class="western" id="rfqe128" style="margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;"&gt;&lt;div style="margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;"&gt;&lt;br id="rfqe129" /&gt;&lt;/div&gt;&lt;/div&gt;&lt;div class="western" id="rfqe130" style="margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;"&gt;&lt;div style="margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;"&gt;void CDocument :: AddView(CView* pView)&lt;/div&gt;&lt;/div&gt;&lt;div class="western" id="rfqe135" style="margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;"&gt;&lt;div style="margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;"&gt;{&lt;/div&gt;&lt;/div&gt;&lt;div class="western" id="rfqe137" style="margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;"&gt;&lt;div style="margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;"&gt;ASSERT_VALID(pView);&lt;/div&gt;&lt;/div&gt;&lt;div class="western" id="rfqe139" style="margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;"&gt;&lt;div style="margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;"&gt;ASSERT(pView-&amp;gt;m_pDocument == NULL);&lt;/div&gt;&lt;/div&gt;&lt;div class="western" id="oj410" style="margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;"&gt;&lt;div style="margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;"&gt;ASSERT(m_viewList.Find(pView, NULL) == NULL);&amp;nbsp;&lt;/div&gt;&lt;/div&gt;&lt;div class="western" id="rfqe151" style="margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;"&gt;&lt;div style="margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;"&gt;m_viewList.AddTail(pView);&lt;/div&gt;&lt;/div&gt;&lt;div class="western" id="rfqe153" style="margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;"&gt;&lt;div style="margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;"&gt;ASSERT(pView-&amp;gt;m_pDocument == NULL);&lt;/div&gt;&lt;/div&gt;&lt;div class="western" id="rfqe158" style="margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;"&gt;&lt;div style="margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;"&gt;pView-&amp;gt;m_pDocument = this;&lt;/div&gt;&lt;/div&gt;&lt;div class="western" id="rfqe164" style="margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;"&gt;&lt;div style="margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;"&gt;&lt;br id="rfqe165" /&gt;&lt;/div&gt;&lt;/div&gt;&lt;div class="western" id="rfqe166" style="margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;"&gt;&lt;div style="margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;"&gt;OnChangedViewList();&lt;/div&gt;&lt;/div&gt;&lt;div class="western" id="oj412" style="margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;"&gt;&lt;div style="margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;"&gt;}&lt;/div&gt;&lt;/div&gt;&lt;div class="western" id="rfqe173" style="margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;"&gt;&lt;div style="margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;"&gt;&lt;br id="rfqe174" /&gt;&lt;/div&gt;&lt;/div&gt;&lt;div class="western" id="rfqe175" style="margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;"&gt;&lt;div style="margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;"&gt;void CDocument :: RemoveView(CView* pView)&lt;/div&gt;&lt;/div&gt;&lt;div class="western" id="rfqe180" style="margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;"&gt;&lt;div style="margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;"&gt;{&lt;/div&gt;&lt;/div&gt;&lt;div class="western" id="rfqe182" style="margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;"&gt;&lt;div style="margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;"&gt;ASSERT_VALID(pView);&lt;/div&gt;&lt;/div&gt;&lt;div class="western" id="rfqe184" style="margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;"&gt;&lt;div style="margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;"&gt;ASSERT(pView-&amp;gt;m_pDocument == this);&lt;/div&gt;&lt;/div&gt;&lt;div class="western" id="rfqe191" style="margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;"&gt;&lt;div style="margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;"&gt;&lt;br id="rfqe192" /&gt;&lt;/div&gt;&lt;/div&gt;&lt;div class="western" id="rfqe193" style="margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;"&gt;&lt;div style="margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;"&gt;m_viewList.RemoveAt(m_viewList.Find(pView));&lt;/div&gt;&lt;/div&gt;&lt;div class="western" id="rfqe195" style="margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;"&gt;&lt;div style="margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;"&gt;pView-&amp;gt;m_pDocument = NULL;&lt;/div&gt;&lt;/div&gt;&lt;div class="western" id="rfqe197" style="margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;"&gt;&lt;div style="margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;"&gt;&lt;br id="rfqe198" /&gt;&lt;/div&gt;&lt;/div&gt;&lt;div class="western" id="rfqe199" style="margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;"&gt;&lt;div style="margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;"&gt;OnChangedViewList();&lt;/div&gt;&lt;/div&gt;&lt;div class="western" id="rfqe204" style="margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;"&gt;&lt;div style="margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;"&gt;}&lt;/div&gt;&lt;/div&gt;&lt;div class="western" id="rfqe206" style="margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;"&gt;&lt;div style="margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;"&gt;&lt;br id="rfqe207" /&gt;&lt;/div&gt;&lt;/div&gt;&lt;div class="western" id="rfqe208" style="margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;"&gt;&lt;div style="margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;"&gt;As this is clear from the above listings that CDocument :: AddView is similar to the Attach function of&amp;nbsp;the Subject, and RemoveView is like the Detach function as in the Observer Pattern.&lt;/div&gt;&lt;/div&gt;&lt;div class="western" id="rfqe210" style="margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;"&gt;&lt;div style="margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;"&gt;&lt;br id="rfqe211" /&gt;&lt;/div&gt;&lt;/div&gt;&lt;div class="western" id="rfqe212" style="margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;"&gt;&lt;div style="margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;"&gt;Similar to the Observer Pattern, the Document has a list of its attached views through its m_viewList member and each view has a reference to its document through its m_pDocument member.&lt;/div&gt;&lt;/div&gt;&lt;div class="western" id="rfqe214" style="margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;"&gt;&lt;div style="margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;"&gt;&lt;br id="rfqe215" /&gt;&lt;/div&gt;&lt;/div&gt;&lt;div class="western" id="rfqe216" style="margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;"&gt;&lt;div style="margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;"&gt;From the above discussion, it has become clear that the MFC's Document- View architecture is one&amp;nbsp;of the applications of the Observer Pattern.&lt;/div&gt;&lt;/div&gt;&lt;div class="western" id="rfqe216" style="margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;"&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;/div&gt;&lt;div&gt;&lt;/div&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3946478681282550454-5109829826796696875?l=som-itsolutions.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://som-itsolutions.blogspot.com/feeds/5109829826796696875/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=3946478681282550454&amp;postID=5109829826796696875' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3946478681282550454/posts/default/5109829826796696875'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3946478681282550454/posts/default/5109829826796696875'/><link rel='alternate' type='text/html' href='http://som-itsolutions.blogspot.com/2011/08/observer-pattern-in-mfc_05.html' title='Observer Pattern in MFC'/><author><name>Som</name><uri>http://www.blogger.com/profile/09519633424407534012</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='24' src='http://3.bp.blogspot.com/-XVhL110Tyf8/ThxKF3DBYcI/AAAAAAAAEBo/arVXUPsgtSg/s220/NJ%2B042.JPG'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3946478681282550454.post-2305465487960630557</id><published>2011-07-11T05:40:00.002+05:30</published><updated>2011-07-17T07:00:21.598+05:30</updated><title type='text'>SMS Scheduler App for Android...</title><content type='html'>I have developed a rudimentary SMS Scheduler App... &lt;a href="https://docs.google.com/leaf?id=0B8L15NA4lO_UODk3ZmRmOGUtMTMzYy00ODBhLTljNjctMjVhNmZmZWQ2ODA4&amp;amp;hl=en_US"&gt;Here&lt;/a&gt; is the link to download it... i will work on it to give finer touches... hope you enjoy it...&lt;br /&gt;&lt;br /&gt;Here are the screenshots of the App&lt;br /&gt;&lt;br /&gt;&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://4.bp.blogspot.com/-_BsswiOujhg/TiI694OR8jI/AAAAAAAAECE/Z7pJY7Cj37c/s1600/SMS+Scheduler1.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img border="0" height="200" src="http://4.bp.blogspot.com/-_BsswiOujhg/TiI694OR8jI/AAAAAAAAECE/Z7pJY7Cj37c/s320/SMS+Scheduler1.png" width="320" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://1.bp.blogspot.com/-QxhEnz3f8_Q/TiI7FVXiDFI/AAAAAAAAECI/5QpDDB4HPDk/s1600/SMSScheduler+2.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img border="0" height="200" src="http://1.bp.blogspot.com/-QxhEnz3f8_Q/TiI7FVXiDFI/AAAAAAAAECI/5QpDDB4HPDk/s320/SMSScheduler+2.png" width="320" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;i would like to share something more with you guys about what i have learnt while doing this project... i had to run two android emulators on my Ubuntu machine for testing the SMS...i tried but it was giving error messages like data image is used by other... after i Googled it i could not find any satisfactory answer... so i pondered on this subject a little bit and thought if somehow i could create different data image for different emulator, the problem will go... similarly for the cache image...&lt;br /&gt;&lt;br /&gt;so i tried the following two commands to run two different emulators on my Ubuntu machine...&lt;br /&gt;&lt;br /&gt;$ emulator -avd Android2.2 -data ~/workspace/Android/dataimg1 -cache ~/workspace/Android/cacheimage1 -port 5554&lt;br /&gt;&lt;br /&gt;$ emulator -avd Android2.2 -data ~/workspace/Android/dataimg2 -cache ~/workspace/Android/cacheimage2 -port 5556&lt;br /&gt;&lt;br /&gt;So the above two commands are basically responsible for running two emulators on console 5554 and 5556 with different data and cache files namely dataimg1 and cacheimage1 for the first one and dataimg2 and cacheimage2 for the second one... and it was a success!!!&lt;br /&gt;&lt;br /&gt;hope this discussion becomes useful for Android learners...&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3946478681282550454-2305465487960630557?l=som-itsolutions.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://som-itsolutions.blogspot.com/feeds/2305465487960630557/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=3946478681282550454&amp;postID=2305465487960630557' title='3 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3946478681282550454/posts/default/2305465487960630557'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3946478681282550454/posts/default/2305465487960630557'/><link rel='alternate' type='text/html' href='http://som-itsolutions.blogspot.com/2011/07/sms-scheduler-app-for-android.html' title='SMS Scheduler App for Android...'/><author><name>Som</name><uri>http://www.blogger.com/profile/09519633424407534012</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='24' src='http://3.bp.blogspot.com/-XVhL110Tyf8/ThxKF3DBYcI/AAAAAAAAEBo/arVXUPsgtSg/s220/NJ%2B042.JPG'/></author><media:thumbnail xmlns:media='http://search.yahoo.com/mrss/' url='http://4.bp.blogspot.com/-_BsswiOujhg/TiI694OR8jI/AAAAAAAAECE/Z7pJY7Cj37c/s72-c/SMS+Scheduler1.png' height='72' width='72'/><thr:total>3</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3946478681282550454.post-1980179749456537772</id><published>2011-07-08T21:34:00.001+05:30</published><updated>2011-07-09T05:51:35.829+05:30</updated><title type='text'>My good days with Ubuntu...</title><content type='html'>&lt;div style="background-color: transparent; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;"&gt;&lt;span id="internal-source-marker_0.6069688710849732" style="background-color: transparent; font-family: Arial; font-size: 11pt; font-style: normal; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"&gt;i have now almost completely switched over from Windows to Ubuntu... when the google page first comes out in the chrome browser, or the test page prints Ubuntu, the feeling is of sheer joy... i am loving it... no fear of spyware, no fear of virus... no headache for installing spybot or spyware doctor... no worry about how to install malware bytes... hopefully my days with Ubuntu will pass by peacefully...&lt;/span&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3946478681282550454-1980179749456537772?l=som-itsolutions.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://som-itsolutions.blogspot.com/feeds/1980179749456537772/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=3946478681282550454&amp;postID=1980179749456537772' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3946478681282550454/posts/default/1980179749456537772'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3946478681282550454/posts/default/1980179749456537772'/><link rel='alternate' type='text/html' href='http://som-itsolutions.blogspot.com/2011/07/my-good-days-with-ubuntu.html' title='My good days with Ubuntu...'/><author><name>Som</name><uri>http://www.blogger.com/profile/09519633424407534012</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='24' src='http://3.bp.blogspot.com/-XVhL110Tyf8/ThxKF3DBYcI/AAAAAAAAEBo/arVXUPsgtSg/s220/NJ%2B042.JPG'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3946478681282550454.post-991865409133374205</id><published>2011-06-27T08:31:00.001+05:30</published><updated>2011-06-27T09:20:20.696+05:30</updated><title type='text'>CS != Programming</title><content type='html'>&lt;div dir="ltr" style="text-align: left;" trbidi="on"&gt;&lt;span class="Apple-style-span" style="font-family: Arial; font-size: 15px; white-space: pre-wrap;"&gt;While teaching the Computer Science students in an engineering college, i had this strange feelings that CS != Programming... The theoretical aspects of computer science which the students usually learn in the engineering college will never help them become proficient programmers... many people would shun this point of view... some times back&lt;/span&gt;&lt;span class="Apple-style-span" style="font-family: Arial; font-size: 15px; white-space: pre-wrap;"&gt; i interacted with one of my colleagues &lt;/span&gt;&lt;span class="Apple-style-span" style="font-family: Arial; font-size: 15px; white-space: pre-wrap;"&gt;who insisted that programming is only &amp;nbsp;small part of computer science world... however i feel that it is the most important part of the computer science... with the wake of Test Driven Development and other Agile processes, when the long quality process is loosing its significance, its only good efficient programming that remains the most significant factor of the software project development... i believe that one can get a CS degree without even &amp;nbsp;having a computer... but one cannot develop and design software that runs without getting his hands dirty with debugger, breakpoint, issues with memory leaks and so on... &lt;/span&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3946478681282550454-991865409133374205?l=som-itsolutions.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://som-itsolutions.blogspot.com/feeds/991865409133374205/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=3946478681282550454&amp;postID=991865409133374205' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3946478681282550454/posts/default/991865409133374205'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3946478681282550454/posts/default/991865409133374205'/><link rel='alternate' type='text/html' href='http://som-itsolutions.blogspot.com/2011/06/cs-programming_27.html' title='CS != Programming'/><author><name>Som</name><uri>http://www.blogger.com/profile/09519633424407534012</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='24' src='http://3.bp.blogspot.com/-XVhL110Tyf8/ThxKF3DBYcI/AAAAAAAAEBo/arVXUPsgtSg/s220/NJ%2B042.JPG'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3946478681282550454.post-7499491297958595525</id><published>2011-06-08T19:32:00.019+05:30</published><updated>2011-06-25T04:03:25.279+05:30</updated><title type='text'>Patent and Copyright - from my perspective</title><content type='html'>&lt;div dir="ltr" style="text-align: left;" trbidi="on"&gt;&lt;span class="Apple-style-span" style="font-family: Arial; font-size: 15px; white-space: pre-wrap;"&gt;today during our breakfast my wife asked me a question about the difference between patent and copyright... while answering her queries, i reminded her how the way we create patents of software these days has become an hindrance to innovation... if one is not convinced see &lt;a href="http://www.gnu.org/patent-examp/patent-examples.html"&gt;this&lt;/a&gt; or &lt;a href="http://en.swpat.org/wiki/Free_software_projects_harmed_by_software_patents"&gt;this&lt;/a&gt;... think about the situation had all the basic scientific theories (e.g. newton’s law of motion and gravity, Archimedes's principles, Einstein's theory of relativity, the knowledge of periodic table and in-numerous chemical reactions or the basic ideas of zero and decimals) being patented and copyrighted, where would our scientific exploration have gone so far? from another angle had the Almighty patented air, water, earth, fire or so many of His living creatures on whom we do scientific experimentation, where would our mankind and civilization stand today?or even had we have to pay royalty to the community of cows for their milk or to the community of plants and vegetables for their own products, where would&amp;nbsp;&lt;/span&gt;&lt;span class="Apple-style-span" style="font-family: Arial; font-size: 15px; white-space: pre-wrap;"&gt;we &lt;/span&gt;&lt;span class="Apple-style-span" style="font-family: Arial; font-size: 15px; white-space: pre-wrap;"&gt;go for the money?&lt;/span&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3946478681282550454-7499491297958595525?l=som-itsolutions.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://som-itsolutions.blogspot.com/feeds/7499491297958595525/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=3946478681282550454&amp;postID=7499491297958595525' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3946478681282550454/posts/default/7499491297958595525'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3946478681282550454/posts/default/7499491297958595525'/><link rel='alternate' type='text/html' href='http://som-itsolutions.blogspot.com/2011/06/patent-and-copyright-from-my.html' title='Patent and Copyright - from my perspective'/><author><name>Som</name><uri>http://www.blogger.com/profile/09519633424407534012</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='24' src='http://3.bp.blogspot.com/-XVhL110Tyf8/ThxKF3DBYcI/AAAAAAAAEBo/arVXUPsgtSg/s220/NJ%2B042.JPG'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3946478681282550454.post-3325721120240785869</id><published>2011-04-07T18:26:00.002+05:30</published><updated>2011-04-07T18:30:17.113+05:30</updated><title type='text'>Eye opener for educators...</title><content type='html'>&lt;div dir="ltr" style="text-align: left;" trbidi="on"&gt;&lt;span class="Apple-style-span" style="white-space: pre-wrap;"&gt;&lt;span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;"&gt;“Intellect has been cultured with the result that hundreds of sciences have been discovered,&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;div style="background-color: transparent;"&gt;&lt;span style="background-color: transparent; font-family: Arial, Helvetica, sans-serif; font-style: normal; font-weight: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"&gt;and their effect has been that the few have made slaves of the many – that is all the good&lt;/span&gt;&lt;br /&gt;&lt;span style="background-color: transparent; font-family: Arial, Helvetica, sans-serif; font-style: normal; font-weight: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"&gt;that has been done. Artificial wants have been created; and every poor man, whether he&lt;/span&gt;&lt;br /&gt;&lt;span style="background-color: transparent; font-family: Arial, Helvetica, sans-serif; font-style: normal; font-weight: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"&gt;has money or not, desires to have those wants satisfied, and when he cannot, he struggles,&lt;/span&gt;&lt;br /&gt;&lt;span style="background-color: transparent; font-family: Arial, Helvetica, sans-serif; font-style: normal; font-weight: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"&gt;and dies in the struggle” - Swami Vivekananda.&lt;/span&gt;&lt;br /&gt;&lt;span style="background-color: transparent; font-family: Arial, Helvetica, sans-serif; font-style: normal; font-weight: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"&gt;Is the mad rush towards consumerism of the modern day a product of such faulty education system? &lt;/span&gt;&lt;/div&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3946478681282550454-3325721120240785869?l=som-itsolutions.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://som-itsolutions.blogspot.com/feeds/3325721120240785869/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=3946478681282550454&amp;postID=3325721120240785869' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3946478681282550454/posts/default/3325721120240785869'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3946478681282550454/posts/default/3325721120240785869'/><link rel='alternate' type='text/html' href='http://som-itsolutions.blogspot.com/2011/04/eye-opener-for-educators.html' title='Eye opener for educators...'/><author><name>Som</name><uri>http://www.blogger.com/profile/09519633424407534012</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='24' src='http://3.bp.blogspot.com/-XVhL110Tyf8/ThxKF3DBYcI/AAAAAAAAEBo/arVXUPsgtSg/s220/NJ%2B042.JPG'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3946478681282550454.post-7082513610493745359</id><published>2011-03-24T19:24:00.004+05:30</published><updated>2011-07-19T16:56:16.756+05:30</updated><title type='text'>Unit Converter App with Source Code</title><content type='html'>&lt;div dir="ltr" style="text-align: left;" trbidi="on"&gt;&lt;span style="font-size: small;"&gt;For the past few days i was in a dilemma about ethics, openness and honesty... the reason behind this was should i show the whole world the source code of my Android apps? as i don’t have a job, i thought of earning some money for my family by offering training to the people who want to learn how to develop Android apps... but then i thought that as i am using an open source platform to develop the Android App, i should show the source code to the others so that if someone really wants to learn, he can learn it from this source code... being a believer in Swamy Vivekananda, i thought not to do business just by selling knowledge...if i face difficulty in feeding my family in the future, there is definitely another way to earn money, but not by selling the knowledge which i got because of the Almighty.&lt;br /&gt;&lt;br /&gt;So here goes the &lt;a href="https://docs.google.com/leaf?id=0B8L15NA4lO_UMWVkZDY4OWItZTYwNS00NTYwLWI2NDktZTczNTM3NDc4MjRi&amp;amp;hl=en&amp;amp;authkey=CMfF2JUJ"&gt;source code&lt;/a&gt; of an Unit Converter App which i started developing to help some of my students... if somebody can learn from it, i will be the happiest person...&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-size: small;"&gt;Here is a screenshot of this app...&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://1.bp.blogspot.com/-GnAYpds6eN8/TiVpvW3XSEI/AAAAAAAAECM/W4EhfN8FzXU/s1600/UnitConverter.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img border="0" height="200" src="http://1.bp.blogspot.com/-GnAYpds6eN8/TiVpvW3XSEI/AAAAAAAAECM/W4EhfN8FzXU/s320/UnitConverter.png" width="320" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;&lt;span style="font-size: small;"&gt; i have used Strategy Pattern to develop this App.&lt;br /&gt;&lt;br /&gt;Hope this helps others.&lt;/span&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3946478681282550454-7082513610493745359?l=som-itsolutions.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://som-itsolutions.blogspot.com/feeds/7082513610493745359/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=3946478681282550454&amp;postID=7082513610493745359' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3946478681282550454/posts/default/7082513610493745359'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3946478681282550454/posts/default/7082513610493745359'/><link rel='alternate' type='text/html' href='http://som-itsolutions.blogspot.com/2011/03/unit-converter-app-with-source-code.html' title='Unit Converter App with Source Code'/><author><name>Som</name><uri>http://www.blogger.com/profile/09519633424407534012</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='24' src='http://3.bp.blogspot.com/-XVhL110Tyf8/ThxKF3DBYcI/AAAAAAAAEBo/arVXUPsgtSg/s220/NJ%2B042.JPG'/></author><media:thumbnail xmlns:media='http://search.yahoo.com/mrss/' url='http://1.bp.blogspot.com/-GnAYpds6eN8/TiVpvW3XSEI/AAAAAAAAECM/W4EhfN8FzXU/s72-c/UnitConverter.png' height='72' width='72'/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3946478681282550454.post-5163847160822637451</id><published>2011-03-10T04:34:00.001+05:30</published><updated>2011-03-10T04:35:23.594+05:30</updated><title type='text'>Unfolding the mystery...</title><content type='html'>&lt;div dir="ltr" style="text-align: left;" trbidi="on"&gt;&lt;span class="Apple-style-span" style="font-family: Arial; font-size: 15px; white-space: pre-wrap;"&gt;There is an absolute ecstasy in unfolding the mystery...i know it from my own experience... when i first came to the IT industry, i used to wonder how things actually work inside... however, with experience and knowledge, these days i can decipher a fragment of code of a working system...today i know a little bit of why an OOAD system has been designed the way it is....and when this mystery gets unfolded, the joy is no less than that of a scientist’s discovery... probably this is the only reason i love software... &lt;/span&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3946478681282550454-5163847160822637451?l=som-itsolutions.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://som-itsolutions.blogspot.com/feeds/5163847160822637451/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=3946478681282550454&amp;postID=5163847160822637451' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3946478681282550454/posts/default/5163847160822637451'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3946478681282550454/posts/default/5163847160822637451'/><link rel='alternate' type='text/html' href='http://som-itsolutions.blogspot.com/2011/03/unfolding-mystery.html' title='Unfolding the mystery...'/><author><name>Som</name><uri>http://www.blogger.com/profile/09519633424407534012</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='24' src='http://3.bp.blogspot.com/-XVhL110Tyf8/ThxKF3DBYcI/AAAAAAAAEBo/arVXUPsgtSg/s220/NJ%2B042.JPG'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3946478681282550454.post-8180294163313347468</id><published>2011-03-09T13:34:00.018+05:30</published><updated>2011-03-14T05:49:12.426+05:30</updated><title type='text'>How to become a software developer without spending a penny...</title><content type='html'>&lt;div dir="ltr" style="text-align: left;" trbidi="on"&gt;&lt;span class="Apple-style-span" style="font-family: Arial;"&gt;&lt;span class="Apple-style-span" style="font-size: 15px;"&gt;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;div style="background-color: transparent; font-family: 'Times New Roman';"&gt;&lt;span class="Apple-style-span" style="font-family: Arial;"&gt;&lt;span id="internal-source-marker_0.22066517896018922" style="background-color: transparent; font-family: Arial; font-style: normal; font-weight: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"&gt;This post is for all those engineering students of computer science in remote places of India who cannot afford hefty amount to buy licensed software... i faced this dilemma when i first started my software career... i would like to share my experience with you...&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="background-color: transparent;"&gt;&lt;span style="background-color: transparent; font-family: Arial; font-style: normal; font-weight: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"&gt;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="background-color: transparent; font-family: Arial; font-style: normal; font-weight: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"&gt;the best way to learn software is to use Linux. i use Ubuntu. hence i can advise on this. anyone can order an Ubuntu CD from the &lt;/span&gt;&lt;a href="https://shipit.ubuntu.com/"&gt;&lt;span style="background-color: transparent; font-family: Arial; font-style: normal; font-weight: normal; text-decoration: underline; vertical-align: baseline; white-space: pre-wrap;"&gt;https://shipit.ubuntu.com/&lt;/span&gt;&lt;/a&gt;&lt;span style="background-color: transparent; font-family: Arial; font-style: normal; font-weight: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"&gt; . if someone has a braodband connection he can download Ubuntu from &lt;/span&gt;&lt;a href="http://www.ubuntu.com/desktop/get-ubuntu/download"&gt;&lt;span style="background-color: transparent; font-family: Arial; font-style: normal; font-weight: normal; text-decoration: underline; vertical-align: baseline; white-space: pre-wrap;"&gt;http://www.ubuntu.com/desktop/get-ubuntu/download&lt;/span&gt;&lt;/a&gt;&lt;span style="background-color: transparent; font-family: Arial; font-style: normal; font-weight: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"&gt;. however, installing Ubuntu is not the end... one will have to install the necessary package for C/C++ developement. These packages can be installed over the internet through the Synaptic Package Manager in Ubuntu desktop menu. The package for C/C++ is the build essential package... one may like to install the eclipse IDE from the software repository... the next thing is to install the OPEN-JDK package for working using Java... Once these things are done, the basic development environment for a student is done.&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="background-color: transparent;"&gt;&lt;span style="background-color: transparent; font-family: Arial; font-style: normal; font-weight: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"&gt;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="background-color: transparent; font-family: Arial; font-style: normal; font-weight: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"&gt;However, there are still some people who are simply familiar with Windows and do not have the money to buy Visual Studio...many poor students fall in the trap of pirated version of Visual Studio... but that is unethical... right....for those students i would suggest to go for Eclipse as the IDE... For a C/C++ compiler in a Windows machine one may go for Cygwin... this is how i have configured my Windows development environment...&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="background-color: transparent;"&gt;&lt;span style="background-color: transparent; font-family: Arial; font-style: normal; font-weight: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"&gt;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="background-color: transparent; font-family: Arial; font-style: normal; font-weight: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"&gt;however, its not only the development environment a student looks for... he needs a productivity tool... here again i would like to suggest the poor students not to fall in the trap of pirated MS-Office CD...if you want an offline productivity tool, go for free OpenOffice... and if you have a broadband connection, you may opt for Google Docs...&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="background-color: transparent;"&gt;&lt;span style="background-color: transparent; font-family: Arial; font-style: normal; font-weight: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"&gt;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="background-color: transparent; font-family: Arial; font-style: normal; font-weight: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"&gt;i think for a poor student in India, the tug of war between zeal to learn and ethics always plays havoc...i hope i have thrown some lights how to quench the thirst for knowledge without compromising on ethics...&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3946478681282550454-8180294163313347468?l=som-itsolutions.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://som-itsolutions.blogspot.com/feeds/8180294163313347468/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=3946478681282550454&amp;postID=8180294163313347468' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3946478681282550454/posts/default/8180294163313347468'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3946478681282550454/posts/default/8180294163313347468'/><link rel='alternate' type='text/html' href='http://som-itsolutions.blogspot.com/2011/03/how-to-become-software-developer.html' title='How to become a software developer without spending a penny...'/><author><name>Som</name><uri>http://www.blogger.com/profile/09519633424407534012</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='24' src='http://3.bp.blogspot.com/-XVhL110Tyf8/ThxKF3DBYcI/AAAAAAAAEBo/arVXUPsgtSg/s220/NJ%2B042.JPG'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3946478681282550454.post-5885924404060877196</id><published>2011-02-23T19:05:00.002+05:30</published><updated>2011-07-09T06:58:35.621+05:30</updated><title type='text'>Meaning of education to me...</title><content type='html'>&lt;div dir="ltr" style="text-align: left;" trbidi="on"&gt;From the very beginning of my graduation day, i was in a dilemma about  the meaning of education. Education, to me is an enabler, and all other  means to educate people are facilitators. i was baffled by the very  basic question what i will be able to do hands-on after i got a BE  degree. i didn't want to become a theory-mugging Babu like so many  engineering graduates in India. To me if a software engineer is not able  to write good programs of a running application, there is no meaning of  his education. it does not matter how much theory one churns out, the  way to practice that theory should be the motto of education...&lt;br /&gt;&lt;br /&gt;As Swami Vivekananda said, "We may talk and reason all our lives, but we shall not understand a word of truth, until we experience it ourselves. You cannot hope to make a man a surgeon by simply giving him a few books. You cannot satisfy my curiosity to see a country by showing me a map; I must have actual experience. Maps can only create curiosity in us to get more perfect knowledge. Beyond that they have no value whatever... "&lt;br /&gt;&lt;br /&gt;&lt;div&gt;i  am damn sure if someone looks into the IT industry, he will find lot of  middle level managers and senior managers who just can't decipher a  simple programming concept... They can be termed as Babus in the IT  industry.. if an automobile engineer has to call a mechanic every time  his car falters, his engineering degree does not serve the basic  purpose...&lt;/div&gt;&lt;br /&gt;&lt;div&gt;Here in India we give more importance to  marks... A student scoring 90% might not be an effective engineer...i  know there are a number of engineers who would not have become engineers  had they been guaranteed jobs in other industries...i know there are  few people who want others to remain in dark and make profit out of  their ignorance... under any circumstances they cannot be termed as good  human beings...&lt;/div&gt;&lt;br /&gt;&lt;div&gt;thats the only reason probably i have  embraced open source technologies to work on my software passion...  because it gives freedom... i think FOSS is more about freedom than  about free of cost...however, there are some limitations in the open  source technologies as well... the limitation is that one has to  overcome a steep learning curve to contribute a little to the learning  society... and there is no hand-holding for a new comer... so far i have  just used some of the open source technologies like&amp;nbsp;Ubuntu, eclipse, android... but i  have not been able to contribute any thing in terms of bug fixing of an  open source project... however, i try to contribute to the learning  society, in whatever little form it may be, through my technical blog...&lt;/div&gt;&lt;br /&gt;i  know i am an insignificant guy to change the way education is being  practiced here in India...i know its not easy to become Jonathon  Livingstone Seagull... &amp;nbsp;however, i want someone influential to think the  way i have thought about education....&lt;br /&gt;&lt;br /&gt;&lt;div&gt;&lt;/div&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3946478681282550454-5885924404060877196?l=som-itsolutions.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://som-itsolutions.blogspot.com/feeds/5885924404060877196/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=3946478681282550454&amp;postID=5885924404060877196' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3946478681282550454/posts/default/5885924404060877196'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3946478681282550454/posts/default/5885924404060877196'/><link rel='alternate' type='text/html' href='http://som-itsolutions.blogspot.com/2011/02/meaning-of-education-to-me.html' title='Meaning of education to me...'/><author><name>Som</name><uri>http://www.blogger.com/profile/09519633424407534012</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='24' src='http://3.bp.blogspot.com/-XVhL110Tyf8/ThxKF3DBYcI/AAAAAAAAEBo/arVXUPsgtSg/s220/NJ%2B042.JPG'/></author><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3946478681282550454.post-1341497345541404684</id><published>2010-12-27T08:53:00.020+05:30</published><updated>2011-06-02T16:13:06.933+05:30</updated><title type='text'>Freeware Android Paint with source code...</title><content type='html'>&lt;div dir="ltr" style="text-align: left;" trbidi="on"&gt;Here is one of my freeware android apps called AndroidPaint. This can be downloaded from &lt;a href="https://docs.google.com/leaf?id=0B8L15NA4lO_UYWYwMmU4MDgtYTlmNC00MTVhLWJhMWMtMGI2M2JhODJhMGE3&amp;amp;hl=en&amp;amp;authkey=CMKx4zk"&gt;here&lt;/a&gt;. Before running this application one has to install the ColorPicker app which can be downloaded from &lt;a href="https://docs.google.com/leaf?id=0B8L15NA4lO_UMmE5MWY3N2YtODkwMy00NzgxLTgxOWEtM2QxODRhNjZjZDA2&amp;amp;hl=en&amp;amp;authkey=CML93vcB"&gt;here&lt;/a&gt;.&lt;br /&gt;&lt;br /&gt;Using the Android Paint app, one can draw geometrical shapes and free hand drawing on an Android device. In the future version i will refine the app to give the user more drawing options and more regular shapes to draw.&lt;br /&gt;&lt;br /&gt;To start with, one will have to choose from the menu options and then draw.&lt;br /&gt;&lt;br /&gt;The screenshot of this application is as follows:&lt;br /&gt;&lt;br /&gt;&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://2.bp.blogspot.com/_PnYnrngiRvA/TTlqGBWEsGI/AAAAAAAAD7U/CrpElr6Y4zE/s1600/AndroidPaint2.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img border="0" height="200" src="http://2.bp.blogspot.com/_PnYnrngiRvA/TTlqGBWEsGI/AAAAAAAAD7U/CrpElr6Y4zE/s320/AndroidPaint2.png" width="320" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;Here goes the &lt;a href="https://docs.google.com/leaf?id=0B8L15NA4lO_UMWE4MzBjNDUtNzUzOC00N2VmLWFjZjYtODcxNzBlMzE0MmIw&amp;amp;hl=en_US&amp;amp;authkey=CMOI2MMF"&gt;source code&lt;/a&gt; of this application...&lt;br /&gt;&lt;br /&gt;There are lots of scopes to re-factor this application... for example we can introduce a singleton factory class which will be responsible for creating different shapes... i thought of making the source code available to everyone after i did these kinds of refactoring... but i have lost the momentum... it will be really nice if someone works upon these...&lt;br /&gt;&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;/div&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3946478681282550454-1341497345541404684?l=som-itsolutions.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://som-itsolutions.blogspot.com/feeds/1341497345541404684/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=3946478681282550454&amp;postID=1341497345541404684' title='3 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3946478681282550454/posts/default/1341497345541404684'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3946478681282550454/posts/default/1341497345541404684'/><link rel='alternate' type='text/html' href='http://som-itsolutions.blogspot.com/2010/12/freeware-android-paint.html' title='Freeware Android Paint with source code...'/><author><name>Som</name><uri>http://www.blogger.com/profile/09519633424407534012</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='24' src='http://3.bp.blogspot.com/-XVhL110Tyf8/ThxKF3DBYcI/AAAAAAAAEBo/arVXUPsgtSg/s220/NJ%2B042.JPG'/></author><media:thumbnail xmlns:media='http://search.yahoo.com/mrss/' url='http://2.bp.blogspot.com/_PnYnrngiRvA/TTlqGBWEsGI/AAAAAAAAD7U/CrpElr6Y4zE/s72-c/AndroidPaint2.png' height='72' width='72'/><thr:total>3</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3946478681282550454.post-5225549266760158374</id><published>2010-10-04T20:59:00.027+05:30</published><updated>2010-10-21T18:23:18.617+05:30</updated><title type='text'>Structure Alignment - my understanding...</title><content type='html'>&lt;div style="background-color: white; color: black; counter-reset: __goog_page__ 0; font-family: Verdana; font-size: 10pt; line-height: normal; margin-bottom: 6px; margin-left: 6px; margin-right: 6px; margin-top: 6px; min-height: 1100px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;"&gt;The data should be properly aligned for better efficiency. The CPU accesses the memory on WORD (4 byte) boundary...&lt;br /&gt;Thats the reason we add padding bytes in a structure for proper alignment...&lt;br /&gt;&lt;br /&gt;The the result of &amp;nbsp;my research on structure alignment using a gcc compiler is given below... The alignments of the structures are implementation specific... Typically a char will be 1 byte aligned, a short will be 2 byte aligned, an int will be 4 byte aligned and a pointer will be 4 byte aligned... this means that a char can appear at any boundary, a short can appear at any even boundary, and an int can appear at a four byte boundary...&lt;br /&gt;&lt;br /&gt;To test the alignment of a structure and the offset of one of its member, i wrote this &lt;a href="https://docs.google.com/Doc?docid=0AcL15NA4lO_UZGNnY3AzMzlfNDczNHE0a3dwY3g&amp;amp;hl=en&amp;amp;authkey=CO2w7ecO"&gt;code&lt;/a&gt;:&lt;br /&gt;&lt;br /&gt;And the result of alignment was 4.&lt;br /&gt;&lt;br /&gt;The result of offset of the integer was 4.&lt;br /&gt;&lt;br /&gt;If we use gcc, the size of a long double will be 12 bytes whereas its alignment will be 4 for a IA32 machine.&lt;br /&gt;&lt;br /&gt;For different structures, the alignment of its members have influenced the size of them as follows:&lt;br /&gt;&lt;br /&gt;&lt;div style="margin-bottom: 0px; margin-top: 0px;"&gt;typedef struct XYZ&lt;/div&gt;&lt;div style="margin-bottom: 0px; margin-top: 0px;"&gt;{&lt;/div&gt;&lt;div style="margin-bottom: 0px; margin-top: 0px;"&gt;//total 12 bytes&lt;/div&gt;&lt;div style="margin-bottom: 0px; margin-top: 0px;"&gt;/*char c;//1 byte + 3 padding bytes&lt;/div&gt;&lt;div style="margin-bottom: 0px; margin-top: 0px;"&gt;int x;//4 bytes&lt;/div&gt;&lt;div style="margin-bottom: 0px; margin-top: 0px;"&gt;short s;//2 bytes&lt;/div&gt;&lt;div style="margin-bottom: 0px; margin-top: 0px;"&gt;char d;//1 byte + 1 padding byte&lt;/div&gt;}MyStruct1;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;div style="margin-bottom: 0px; margin-top: 0px;"&gt;&lt;div style="margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;"&gt;typedef struct XYZ&lt;/div&gt;&lt;/div&gt;&lt;div style="margin-bottom: 0px; margin-top: 0px;"&gt;&lt;div style="margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;"&gt;{&lt;/div&gt;&lt;/div&gt;&lt;br /&gt;&lt;div style="margin-bottom: 0px; margin-top: 0px;"&gt;//total 8 bytes&lt;/div&gt;&lt;div style="margin-bottom: 0px; margin-top: 0px;"&gt;/*short s;//2 bytes&lt;/div&gt;&lt;div style="margin-bottom: 0px; margin-top: 0px;"&gt;char c;//1 byte + 1 padding bytes&lt;/div&gt;&lt;div style="margin-bottom: 0px; margin-top: 0px;"&gt;int x;//4 bytes*/&lt;/div&gt;}MyStruct2;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;div style="margin-bottom: 0px; margin-top: 0px;"&gt;&lt;div style="margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;"&gt;typedef struct XYZ&lt;/div&gt;&lt;/div&gt;&lt;div style="margin-bottom: 0px; margin-top: 0px;"&gt;&lt;div style="margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;"&gt;{&lt;/div&gt;&lt;/div&gt;&lt;br /&gt;&lt;div style="margin-bottom: 0px; margin-top: 0px;"&gt;//total 12 bytes&lt;/div&gt;&lt;div style="margin-bottom: 0px; margin-top: 0px;"&gt;/*char a;//1 byte&lt;/div&gt;&lt;div style="margin-bottom: 0px; margin-top: 0px;"&gt;char c;//1 byte&lt;/div&gt;&lt;div style="margin-bottom: 0px; margin-top: 0px;"&gt;short s;//2 bytes&lt;/div&gt;&lt;div style="margin-bottom: 0px; margin-top: 0px;"&gt;int x;//4 bytes&lt;/div&gt;&lt;div style="margin-bottom: 0px; margin-top: 0px;"&gt;char d;//1 byte + 1 padding byte&lt;/div&gt;&lt;div style="margin-bottom: 0px; margin-top: 0px;"&gt;short s1;//2 bytes*/&lt;/div&gt;}MyStruct3;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;div style="margin-bottom: 0px; margin-top: 0px;"&gt;&lt;div style="margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;"&gt;typedef struct XYZ&lt;/div&gt;&lt;/div&gt;&lt;div style="margin-bottom: 0px; margin-top: 0px;"&gt;&lt;div style="margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;"&gt;{&lt;/div&gt;&lt;/div&gt;&lt;br /&gt;&lt;div style="margin-bottom: 0px; margin-top: 0px;"&gt;//total 12 bytes&lt;/div&gt;&lt;div style="margin-bottom: 0px; margin-top: 0px;"&gt;/*char a;//1 byte&lt;/div&gt;&lt;div style="margin-bottom: 0px; margin-top: 0px;"&gt;char c;//1 byte&lt;/div&gt;&lt;div style="margin-bottom: 0px; margin-top: 0px;"&gt;short s;//2 bytes&lt;/div&gt;&lt;div style="margin-bottom: 0px; margin-top: 0px;"&gt;int x;//4 bytes&lt;/div&gt;&lt;div style="margin-bottom: 0px; margin-top: 0px;"&gt;char d;//1 byte&amp;nbsp;&lt;/div&gt;&lt;div style="margin-bottom: 0px; margin-top: 0px;"&gt;char e;//1 byte + 2 padding bytes*/&lt;/div&gt;}MyStruct4;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;div style="margin-bottom: 0px; margin-top: 0px;"&gt;&lt;div style="margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;"&gt;typedef struct XYZ&lt;/div&gt;&lt;/div&gt;&lt;div style="margin-bottom: 0px; margin-top: 0px;"&gt;&lt;div style="margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;"&gt;{&lt;/div&gt;&lt;/div&gt;&lt;br /&gt;&lt;div style="margin-bottom: 0px; margin-top: 0px;"&gt;//total 16 bytes&lt;/div&gt;&lt;div style="margin-bottom: 0px; margin-top: 0px;"&gt;char a;//1 byte + 1 padding byte&lt;/div&gt;&lt;div style="margin-bottom: 0px; margin-top: 0px;"&gt;short s1;//2 bytes&lt;/div&gt;&lt;div style="margin-bottom: 0px; margin-top: 0px;"&gt;char c;//1 byte + 1 padding byte&lt;/div&gt;&lt;div style="margin-bottom: 0px; margin-top: 0px;"&gt;short s;//2 bytes&lt;/div&gt;&lt;div style="margin-bottom: 0px; margin-top: 0px;"&gt;int x;//4 bytes&lt;/div&gt;&lt;div style="margin-bottom: 0px; margin-top: 0px;"&gt;char d;//1 byte + 3 padding byte&lt;/div&gt;&lt;div style="margin-bottom: 0px; margin-top: 0px;"&gt;}MyStruct5;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;div style="margin-bottom: 0px; margin-top: 0px;"&gt;&lt;div style="margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;"&gt;&lt;div style="margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;"&gt;typedef struct XYZ&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;div style="margin-bottom: 0px; margin-top: 0px;"&gt;&lt;div style="margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;"&gt;&lt;div style="margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;"&gt;{&lt;/div&gt;&lt;div style="margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;"&gt;//total 20 bytes&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;br /&gt;&lt;br /&gt;char a;//1 byte + 1 padding byte&lt;br /&gt;short s1;//2 bytes&lt;br /&gt;char c;//1 byte + 1 padding byte&lt;br /&gt;short s;//2 bytes&lt;br /&gt;double x;//8 bytes&lt;br /&gt;char d;//1 byte + 3 padding bytes&lt;/div&gt;}MyStruct6;&lt;br /&gt;&lt;br /&gt;&lt;div style="margin-bottom: 0px; margin-top: 0px;"&gt;We can use #pragma pack(1) directive to force the compiler to avoid the padding of the structure elements. Hence with #pragma pack (1) directive, the MyStruct5 will give the size of 11 bytes.&lt;br /&gt;&lt;b&gt;&lt;/b&gt;&lt;br /&gt;&lt;b&gt;&lt;/b&gt;&lt;br /&gt;&lt;b&gt;&lt;/b&gt;&lt;br /&gt;&lt;b&gt;&lt;/b&gt;&lt;br /&gt;&lt;b&gt;&lt;/b&gt;&lt;br /&gt;&lt;b&gt;&lt;ul style="margin-bottom: 0px; margin-top: 0px;"&gt;&lt;/ul&gt;&lt;/b&gt;&lt;br /&gt;&lt;br /&gt;I would like to end this discussion with an example of how the alignments of the structure members affect the size of a structure. &lt;br /&gt;&lt;br /&gt;Consider the following structure MyStruct1.&lt;br /&gt;&lt;br /&gt;&lt;div style="margin-bottom: 0px; margin-top: 0px;"&gt;&lt;div style="margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;"&gt;typedef struct XYZ&lt;/div&gt;&lt;/div&gt;&lt;div style="margin-bottom: 0px; margin-top: 0px;"&gt;&lt;div style="margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;"&gt;{&lt;/div&gt;&lt;/div&gt;&lt;div style="margin-bottom: 0px; margin-top: 0px;"&gt;&lt;div style="margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;"&gt;//total 12 bytes&lt;/div&gt;&lt;/div&gt;&lt;div style="margin-bottom: 0px; margin-top: 0px;"&gt;&lt;div style="margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;"&gt;/*char c;//1 byte + 3 padding bytes&lt;/div&gt;&lt;/div&gt;&lt;div style="margin-bottom: 0px; margin-top: 0px;"&gt;&lt;div style="margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;"&gt;int x;//4 bytes&lt;/div&gt;&lt;/div&gt;&lt;div style="margin-bottom: 0px; margin-top: 0px;"&gt;&lt;div style="margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;"&gt;short s;//2 bytes&lt;/div&gt;&lt;/div&gt;&lt;div style="margin-bottom: 0px; margin-top: 0px;"&gt;&lt;div style="margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;"&gt;char d;//1 byte + 1 padding byte&lt;/div&gt;&lt;/div&gt;&lt;div style="margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;"&gt;}MyStruct1;&lt;/div&gt;&lt;/div&gt;&lt;div&gt;&amp;nbsp;its total size is 12 bytes because of padding.&lt;br /&gt;&lt;br /&gt;Now let us reorder the members of the same structure as follows:&lt;br /&gt;&lt;br /&gt;&lt;div style="margin-bottom: 0px; margin-top: 0px;"&gt;&lt;div style="margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;"&gt;typedef struct XYZ&lt;/div&gt;&lt;/div&gt;&lt;div style="margin-bottom: 0px; margin-top: 0px;"&gt;&lt;div style="margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;"&gt;{&lt;/div&gt;&lt;/div&gt;&lt;div style="margin-bottom: 0px; margin-top: 0px;"&gt;&lt;div style="margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;"&gt;//total 8 bytes&lt;/div&gt;&lt;/div&gt;&lt;div style="margin-bottom: 0px; margin-top: 0px;"&gt;&lt;div style="margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;"&gt;/*char c;//1 byte&amp;nbsp;&lt;/div&gt;&lt;div style="margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;"&gt;char d;//1 byte&lt;/div&gt;&lt;div style="margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;"&gt;short s;//2 bytes&lt;/div&gt;&lt;/div&gt;&lt;div style="margin-bottom: 0px; margin-top: 0px;"&gt;&lt;div style="margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;"&gt;int x;//4 bytes&lt;/div&gt;&lt;/div&gt;&lt;div style="margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;"&gt;}MyStruct1;&lt;/div&gt;&lt;div style="margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;"&gt;The size becomes 8 bytes. So there is a reduction of 4 bytes by just reordering the members of the structure. If we happen to do embedded programming or programming for small devices, we need to take care of this fact because memory is a major constraint in these devices...&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3946478681282550454-5225549266760158374?l=som-itsolutions.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://som-itsolutions.blogspot.com/feeds/5225549266760158374/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=3946478681282550454&amp;postID=5225549266760158374' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3946478681282550454/posts/default/5225549266760158374'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3946478681282550454/posts/default/5225549266760158374'/><link rel='alternate' type='text/html' href='http://som-itsolutions.blogspot.com/2010/10/structure-alignment-my-understanding.html' title='Structure Alignment - my understanding...'/><author><name>Som</name><uri>http://www.blogger.com/profile/09519633424407534012</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='24' src='http://3.bp.blogspot.com/-XVhL110Tyf8/ThxKF3DBYcI/AAAAAAAAEBo/arVXUPsgtSg/s220/NJ%2B042.JPG'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3946478681282550454.post-1221306955917652931</id><published>2010-09-28T13:19:00.005+05:30</published><updated>2010-10-01T22:32:30.100+05:30</updated><title type='text'>Merge Sort - for my students...</title><content type='html'>&lt;span class="Apple-style-span" style="font-family: Verdana; font-size: 13px;"&gt;Using divide-and-conquer policy we can solve a sorting problem. The divide-and-conquer method suggests the sorting algorithm with the following structure.: if n is one, terminate; otherwise partition the collection of elements into two or more sub collections.; sort each; combine the sub collections into a single sorted collection.&lt;/span&gt;&lt;span class="Apple-style-span" style="font-family: Verdana; font-size: 13px;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;span class="Apple-style-span" style="font-family: Verdana; font-size: 13px;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;&lt;div style="font-family: Verdana; font-size: 13px; margin-bottom: 0px; margin-top: 0px;"&gt;It can be depicted as follows:&lt;/div&gt;&lt;span class="Apple-style-span" style="font-family: Verdana; font-size: 13px;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;&lt;div style="font-family: Verdana; font-size: 13px; margin-bottom: 0px; margin-top: 0px;"&gt;void Sort(a[], n)&lt;/div&gt;&lt;div style="font-family: Verdana; font-size: 13px; margin-bottom: 0px; margin-top: 0px;"&gt;{&lt;/div&gt;&lt;div style="font-family: Verdana; font-size: 13px; margin-bottom: 0px; margin-top: 0px;"&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;if(n&amp;gt;= k) { //k is global&lt;/div&gt;&lt;div style="font-family: Verdana; font-size: 13px; margin-bottom: 0px; margin-top: 0px;"&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;i = n/k;&lt;/div&gt;&lt;div style="font-family: Verdana; font-size: 13px; margin-bottom: 0px; margin-top: 0px;"&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;j = n-i;&lt;/div&gt;&lt;div style="font-family: Verdana; font-size: 13px; margin-bottom: 0px; margin-top: 0px;"&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;Let A consist of the first i elements in a[]&lt;/div&gt;&lt;div style="font-family: Verdana; font-size: 13px; margin-bottom: 0px; margin-top: 0px;"&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;Let B consists of the remaining j elements in E&lt;/div&gt;&lt;div style="font-family: Verdana; font-size: 13px; margin-bottom: 0px; margin-top: 0px;"&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;Sort(A,i);&lt;/div&gt;&lt;div style="font-family: Verdana; font-size: 13px; margin-bottom: 0px; margin-top: 0px;"&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;Sort(B,j);&lt;/div&gt;&lt;div style="font-family: Verdana; font-size: 13px; margin-bottom: 0px; margin-top: 0px;"&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;merge(A,B,a,i,j); //merge A and B into a[]&lt;/div&gt;&lt;div style="font-family: Verdana; font-size: 13px; margin-bottom: 0px; margin-top: 0px;"&gt;}&lt;/div&gt;&lt;div style="font-family: Verdana; font-size: 13px; margin-bottom: 0px; margin-top: 0px;"&gt;&amp;nbsp;else sort a[] using insertion sort.&lt;/div&gt;&lt;div style="font-family: Verdana; font-size: 13px; margin-bottom: 0px; margin-top: 0px;"&gt;}&lt;/div&gt;&lt;span class="Apple-style-span" style="font-family: Verdana; font-size: 13px;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;&lt;div style="font-family: Verdana; font-size: 13px; margin-bottom: 0px; margin-top: 0px;"&gt;In the above pseudo code, if we make k = 2, we get merge sort.&lt;/div&gt;&lt;div style="font-family: Verdana; font-size: 13px; margin-bottom: 0px; margin-top: 0px;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="font-family: Verdana; font-size: 13px; margin-bottom: 0px; margin-top: 0px;"&gt;The complete source code of Merge Sort can be found &lt;a href="https://docs.google.com/Doc?docid=0AcL15NA4lO_UZGNnY3AzMzlfNDY3ZmY4emI1Z2o&amp;amp;hl=en&amp;amp;authkey=CJrKrG8"&gt;here&lt;/a&gt;.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;div style="margin-bottom: 0px; margin-top: 0px;"&gt;&lt;b&gt;Analysis of Merge Sort:&lt;/b&gt;&lt;/div&gt;&lt;br /&gt;&lt;div style="margin-bottom: 0px; margin-top: 0px;"&gt;From the following algorithm of Merge Sort, the run time T(n) can be deduced as follows:&lt;/div&gt;&lt;br /&gt;&lt;div style="margin-bottom: 0px; margin-top: 0px;"&gt;void MergeSort(int a[], int low, int high)&lt;/div&gt;&lt;div style="margin-bottom: 0px; margin-top: 0px;"&gt;{&lt;/div&gt;&lt;div style="margin-bottom: 0px; margin-top: 0px;"&gt;int mid;&lt;/div&gt;&lt;div style="margin-bottom: 0px; margin-top: 0px;"&gt;if(low(high))&lt;high)&gt;&lt;high )=""&gt;&lt;/high&gt;&lt;/high)&gt;&lt;/div&gt;&lt;div style="margin-bottom: 0px; margin-top: 0px;"&gt;{&lt;/div&gt;&lt;div style="margin-bottom: 0px; margin-top: 0px;"&gt;mid = (low+high)/2; ==&amp;gt; &lt;b&gt;Θ(1)&lt;/b&gt;&lt;/div&gt;&lt;div style="margin-bottom: 0px; margin-top: 0px;"&gt;MergeSort(a,low,mid); ==&amp;gt;&lt;b&gt;T(n/2)&lt;/b&gt;&lt;/div&gt;&lt;div style="margin-bottom: 0px; margin-top: 0px;"&gt;MergeSort(a,mid+1,high);==&amp;gt;&lt;b&gt;T(n/2)&lt;/b&gt;&lt;/div&gt;&lt;div style="margin-bottom: 0px; margin-top: 0px;"&gt;merge(a,low,mid,high);==&amp;gt;&lt;b&gt;Θ(n)&lt;/b&gt;&lt;/div&gt;&lt;div style="margin-bottom: 0px; margin-top: 0px;"&gt;}&lt;/div&gt;&lt;div style="margin-bottom: 0px; margin-top: 0px;"&gt;}&lt;/div&gt;&lt;br /&gt;&lt;div style="margin-bottom: 0px; margin-top: 0px;"&gt;Therefore we can write &lt;b&gt;T(n) = 2T(n/2) + Θ(n)&lt;/b&gt;&lt;/div&gt;&lt;br /&gt;&lt;div style="margin-bottom: 0px; margin-top: 0px;"&gt;Comparing it with the &lt;a href="https://docs.google.com/Doc?docid=0AcL15NA4lO_UZGNnY3AzMzlfNDcwZnQ4ZjUyZ2Q&amp;amp;hl=en&amp;amp;authkey=CM7p3OEJ"&gt;Master theorem&lt;/a&gt;, we get a = 2, b &amp;nbsp;= 2 and d = 1. Hence a = b&lt;sup&gt;d&lt;/sup&gt;&amp;nbsp;which means it is the second condition of the Master Theorem.&lt;/div&gt;&lt;br /&gt;&lt;div style="margin-bottom: 0px; margin-top: 0px;"&gt;Thus we get &lt;b&gt;T(n) = Θ (n log n)&lt;/b&gt;&lt;/div&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3946478681282550454-1221306955917652931?l=som-itsolutions.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://som-itsolutions.blogspot.com/feeds/1221306955917652931/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=3946478681282550454&amp;postID=1221306955917652931' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3946478681282550454/posts/default/1221306955917652931'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3946478681282550454/posts/default/1221306955917652931'/><link rel='alternate' type='text/html' href='http://som-itsolutions.blogspot.com/2010/09/merge-sort-for-my-students.html' title='Merge Sort - for my students...'/><author><name>Som</name><uri>http://www.blogger.com/profile/09519633424407534012</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='24' src='http://3.bp.blogspot.com/-XVhL110Tyf8/ThxKF3DBYcI/AAAAAAAAEBo/arVXUPsgtSg/s220/NJ%2B042.JPG'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3946478681282550454.post-3020355188485177068</id><published>2010-09-24T16:32:00.003+05:30</published><updated>2010-10-03T09:42:07.136+05:30</updated><title type='text'>Quick Sort - for my students...</title><content type='html'>&lt;div style="background-color: white; color: black; counter-reset: __goog_page__ 0; font-family: Verdana; font-size: 10pt; line-height: normal; margin-bottom: 6px; margin-left: 6px; margin-right: 6px; margin-top: 6px; min-height: 1100px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;"&gt;&lt;b&gt;Quick Sort&lt;/b&gt; is a sorting algorithm where we apply Divide and Conquer policy. In this sorting algorithm, the n elements to be sorted are partitioned into three segments - a left segment, a middle segment and a right segment. The middle segment is called pivot. The middle segment exactly contains one element. The partition is done in such a way so that all the elements in the left segment have key less than the pivot and all the elements in the right segment have keys greater than the pivot. As a result, the left segment and the right segment can be sorted independently.&lt;br /&gt;&lt;br /&gt;&lt;div style="margin-bottom: 0px; margin-top: 0px;"&gt;The basic principle of Quick sort is as follows:&lt;/div&gt;&lt;br /&gt;&lt;ul style="margin-bottom: 0px; margin-top: 0px;"&gt;&lt;li style="margin-bottom: 0px; margin-top: 0px;"&gt;Select an element from a[0:n-1] for middle. This element is called pivot.&lt;/li&gt;&lt;li style="margin-bottom: 0px; margin-top: 0px;"&gt;Partition the remaining element in such a fashion that all elements in the left of the pivot have keys less than the pivot, and all the elements in the right segment have keys greater than the pivot.&lt;/li&gt;&lt;li style="margin-bottom: 0px; margin-top: 0px;"&gt;Sort left segment using quick sort recursively&lt;/li&gt;&lt;li style="margin-bottom: 0px; margin-top: 0px;"&gt;Sort right segment using quick sort recursively&lt;/li&gt;&lt;li style="margin-bottom: 0px; margin-top: 0px;"&gt;The answer will be left followed by middle followed by right.&lt;/li&gt;&lt;/ul&gt;&lt;br /&gt;&lt;div style="margin-bottom: 0px; margin-top: 0px;"&gt;The algorithm of the quick sort can be found &lt;a href="https://docs.google.com/Doc?docid=0AcL15NA4lO_UZGNnY3AzMzlfNDY0ZDVyenQ2ZjY&amp;amp;hl=en&amp;amp;authkey=CLW_z4QI"&gt;here&lt;/a&gt;.&lt;/div&gt;&lt;br /&gt;&lt;div style="margin-bottom: 0px; margin-top: 0px;"&gt;&lt;b&gt;&lt;u&gt;Debugging of the Algorithm of the code:&lt;/u&gt;&lt;/b&gt;&lt;/div&gt;&lt;br /&gt;&lt;div style="margin-bottom: 0px; margin-top: 0px;"&gt;Step I: To begin with we get m = 0, n = 6, hence k = 3. After doing swap(&amp;amp;list[m],&amp;amp;list[k]), we get key = 5. The following two steps make i = 1 and j = 6.&lt;/div&gt;&lt;br /&gt;&lt;div style="margin-bottom: 0px; margin-top: 0px;"&gt;Step II: Now the loop starts.&lt;/div&gt;&lt;br /&gt;&lt;div style="margin-bottom: 0px; margin-top: 0px;"&gt;II while loop fails as list[i] (7) is not less than key (5). Hence i does not increase and it remains 1. The III while loop succeeds (as list[j] &amp;nbsp;&amp;gt; key)and hence j is decremented. So j becomes 5. In the next iteration of the III while loop, the list[j]&amp;gt;k condition fails, hence j remains 5 and we exit the III while loop. So we exchange list[i] and list[j] and the array becomes {5,1,8,3,2,7,9}&lt;/div&gt;&lt;br /&gt;Next the II while loop succeeds and we increment i. Hence i becomes 2. The III while loop also succeeds and hence j becomes 4. So list[i] = list [2] = 8 and list[j] = list[4] = 2. So when we swap between list[i] and list[j], the array becomes list {5,1,2,3 8,7,9}.&lt;br /&gt;&lt;br /&gt;&lt;div style="margin-bottom: 0px; margin-top: 0px;"&gt;Next the II while loop succeeds two times and we get i = 4. The III while loop also succeeds and we get j = 3. As j becomes larger than i, we come out of the I while loop.&lt;/div&gt;&lt;br /&gt;&lt;div style="margin-bottom: 0px; margin-top: 0px;"&gt;Next we do swap(&amp;amp;list[m],&amp;amp;list[j]). And the list becomes list {3,1,2,5,8,7,9}&lt;/div&gt;&lt;br /&gt;&lt;div style="margin-bottom: 0px; margin-top: 0px;"&gt;After that we recursively sort list{3,1,2}, the left segment and list{8,7,9}, the right segment.&lt;br /&gt;&lt;br /&gt;See how all the elements of the left segment are less than 5 and all the elements in the right segment are greater than 5.&lt;/div&gt;&lt;br /&gt;&lt;div style="margin-bottom: 0px; margin-top: 0px;"&gt;This is how we achieve the Quick Sort.&lt;br /&gt;&lt;div style="margin-bottom: 0px; margin-top: 0px;"&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3946478681282550454-3020355188485177068?l=som-itsolutions.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://som-itsolutions.blogspot.com/feeds/3020355188485177068/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=3946478681282550454&amp;postID=3020355188485177068' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3946478681282550454/posts/default/3020355188485177068'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3946478681282550454/posts/default/3020355188485177068'/><link rel='alternate' type='text/html' href='http://som-itsolutions.blogspot.com/2010/09/quick-sort-for-my-students.html' title='Quick Sort - for my students...'/><author><name>Som</name><uri>http://www.blogger.com/profile/09519633424407534012</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='24' src='http://3.bp.blogspot.com/-XVhL110Tyf8/ThxKF3DBYcI/AAAAAAAAEBo/arVXUPsgtSg/s220/NJ%2B042.JPG'/></author><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3946478681282550454.post-4645881141085559760</id><published>2010-09-19T06:47:00.000+05:30</published><updated>2010-09-19T06:47:15.593+05:30</updated><title type='text'>Pointer Semantics Vs Value Semantics</title><content type='html'>&lt;span class="Apple-style-span" style="font-family: Verdana; font-size: 13px;"&gt;Value semantics means we directly deal with the values and we pass copies of that value around. We can say that nobody will change the value.&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;&lt;div style="margin-bottom: 0px; margin-top: 0px;"&gt;However, in pointer semantics we deal with pointer, and anyone can change the value at the pointer location.&lt;/div&gt;&lt;div style="margin-bottom: 0px; margin-top: 0px;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="margin-bottom: 0px; margin-top: 0px;"&gt;Consider the following program.&lt;/div&gt;&lt;div style="margin-bottom: 0px; margin-top: 0px;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="margin-bottom: 0px; margin-top: 0px;"&gt;&lt;div style="margin-bottom: 0px; margin-top: 0px;"&gt;/*&lt;/div&gt;&lt;div style="margin-bottom: 0px; margin-top: 0px;"&gt;&amp;nbsp;* main.c&lt;/div&gt;&lt;div style="margin-bottom: 0px; margin-top: 0px;"&gt;&amp;nbsp;*&lt;/div&gt;&lt;div style="margin-bottom: 0px; margin-top: 0px;"&gt;&amp;nbsp;* &amp;nbsp;Created on: Sep 18, 2010&lt;/div&gt;&lt;div style="margin-bottom: 0px; margin-top: 0px;"&gt;&amp;nbsp;* &amp;nbsp; &amp;nbsp; &amp;nbsp;Author: administrator&lt;/div&gt;&lt;div style="margin-bottom: 0px; margin-top: 0px;"&gt;&amp;nbsp;*/&lt;/div&gt;&lt;br /&gt;&lt;div style="margin-bottom: 0px; margin-top: 0px;"&gt;#include &lt;stdio.h&gt;&lt;/stdio.h&gt;&lt;/div&gt;&lt;br /&gt;&lt;div style="margin-bottom: 0px; margin-top: 0px;"&gt;void f (int * p, int * q) {&lt;/div&gt;&lt;div style="margin-bottom: 0px; margin-top: 0px;"&gt;p = q;&lt;/div&gt;&lt;div style="margin-bottom: 0px; margin-top: 0px;"&gt;*p = 2;&lt;/div&gt;&lt;div style="margin-bottom: 0px; margin-top: 0px;"&gt;}&lt;/div&gt;&lt;br /&gt;&lt;div style="margin-bottom: 0px; margin-top: 0px;"&gt;int i = 0, j = 1;&lt;/div&gt;&lt;br /&gt;&lt;br /&gt;&lt;div style="margin-bottom: 0px; margin-top: 0px;"&gt;int main ( )&lt;/div&gt;&lt;div style="margin-bottom: 0px; margin-top: 0px;"&gt;{&lt;/div&gt;&lt;div style="margin-bottom: 0px; margin-top: 0px;"&gt;f(&amp;amp;i, &amp;amp; j);&lt;/div&gt;&lt;div style="margin-bottom: 0px; margin-top: 0px;"&gt;printf("%d %d\n", i, j) ;&lt;/div&gt;&lt;div style="margin-bottom: 0px; margin-top: 0px;"&gt;return 0;&lt;/div&gt;&lt;div style="margin-bottom: 0px; margin-top: 0px;"&gt;}&lt;/div&gt;&lt;div style="margin-bottom: 0px; margin-top: 0px;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="margin-bottom: 0px; margin-top: 0px;"&gt;The result will be 0 and 2. Why? Let me explain it to you.&lt;/div&gt;&lt;div style="margin-bottom: 0px; margin-top: 0px;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="margin-bottom: 0px; margin-top: 0px;"&gt;&lt;div style="margin-bottom: 0px; margin-top: 0px;"&gt;We have two global variable i and j and we pass the pointer of these two variables to the function f. &amp;nbsp;When we do p = q, we actually loose the reference of i, and we get two pointers namely p and q both pointing to j. then when we do * p = 2, we actually change the value of j to 2.&amp;nbsp;&lt;/div&gt;&lt;div style="margin-bottom: 0px; margin-top: 0px;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="margin-bottom: 0px; margin-top: 0px;"&gt;The whole thing can be depicted by the following diagram...&lt;/div&gt;&lt;div style="margin-bottom: 0px; margin-top: 0px;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;br /&gt;&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://1.bp.blogspot.com/_PnYnrngiRvA/TJVkEFGBjvI/AAAAAAAADyQ/YMRmuUYFwUA/s1600/pointer.jpeg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img border="0" src="http://1.bp.blogspot.com/_PnYnrngiRvA/TJVkEFGBjvI/AAAAAAAADyQ/YMRmuUYFwUA/s320/pointer.jpeg" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="margin-bottom: 0px; margin-top: 0px;"&gt;However, as we lost the reference of i in the step p = q, in the main program, the value of i that gets printed is the global variable that is 0. Hence we get the result as i = 0 and j = 2.&lt;/div&gt;&lt;div style="margin-bottom: 0px; margin-top: 0px;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="margin-bottom: 0px; margin-top: 0px;"&gt;Hope this explains the pointer arithmetic to my students...&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3946478681282550454-4645881141085559760?l=som-itsolutions.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://som-itsolutions.blogspot.com/feeds/4645881141085559760/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=3946478681282550454&amp;postID=4645881141085559760' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3946478681282550454/posts/default/4645881141085559760'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3946478681282550454/posts/default/4645881141085559760'/><link rel='alternate' type='text/html' href='http://som-itsolutions.blogspot.com/2010/09/pointer-semantics-vs-value-semantics.html' title='Pointer Semantics Vs Value Semantics'/><author><name>Som</name><uri>http://www.blogger.com/profile/09519633424407534012</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='24' src='http://3.bp.blogspot.com/-XVhL110Tyf8/ThxKF3DBYcI/AAAAAAAAEBo/arVXUPsgtSg/s220/NJ%2B042.JPG'/></author><media:thumbnail xmlns:media='http://search.yahoo.com/mrss/' url='http://1.bp.blogspot.com/_PnYnrngiRvA/TJVkEFGBjvI/AAAAAAAADyQ/YMRmuUYFwUA/s72-c/pointer.jpeg' height='72' width='72'/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3946478681282550454.post-6583453682840143777</id><published>2010-08-25T16:19:00.007+05:30</published><updated>2010-09-28T21:55:12.077+05:30</updated><title type='text'>Handy Maths to solve Data Structure Problem</title><content type='html'>&lt;div style="background-color: white; color: black; counter-reset: __goog_page__ 0; font-family: Verdana; font-size: 10pt; line-height: normal; margin-bottom: 6px; margin-left: 6px; margin-right: 6px; margin-top: 6px; min-height: 1100px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;"&gt;&lt;div style="background-color: white; color: black; counter-reset: __goog_page__ 0; font-family: Verdana; font-size: 10pt; line-height: normal; margin-bottom: 6px; margin-left: 6px; margin-right: 6px; margin-top: 6px; min-height: 1100px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;"&gt;&lt;div style="background-color: white; color: black; counter-reset: __goog_page__ 0; font-family: Verdana; font-size: 10pt; line-height: normal; margin-bottom: 6px; margin-left: 6px; margin-right: 6px; margin-top: 6px; min-height: 1100px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;"&gt;Let me first define the problem:&lt;br /&gt;&lt;br /&gt;&lt;div style="margin-bottom: 0px; margin-top: 0px;"&gt;Prob: F(n) is a function defined as :&lt;/div&gt;&lt;br /&gt;&lt;div style="margin-bottom: 0px; margin-top: 0px;"&gt;F(n) = 1 ; n = 1&lt;/div&gt;&lt;br /&gt;&lt;div style="margin-bottom: 0px; margin-top: 0px;"&gt;F(n) = F(n-1) + 1/n ; n&amp;gt;1&lt;/div&gt;&lt;br /&gt;&lt;div style="margin-bottom: 0px; margin-top: 0px;"&gt;Prove that Big Oh of F(n) is log n&lt;/div&gt;&lt;br /&gt;Solution:&lt;br /&gt;&lt;br /&gt;&lt;div style="margin-bottom: 0px; margin-top: 0px;"&gt;F(n) = F(n-1) + 1/n&lt;/div&gt;&lt;div style="margin-bottom: 0px; margin-top: 0px;"&gt;= F(n-2) + 1/(n-1) + 1/n&lt;/div&gt;&lt;div style="margin-bottom: 0px; margin-top: 0px;"&gt;=F(n-3) + 1/(n-2) + 1/(n-1) + 1/n&lt;/div&gt;&lt;br /&gt;&lt;div style="margin-bottom: 0px; margin-top: 0px;"&gt;This kind of series is called the Harmonic Series and can be represented as 1 + 1/2 + 1/3 + 1/4 + ......+ 1/n&lt;/div&gt;&lt;br /&gt;Mathematically we can prove that the sum of an Harmonic series is ln n + gamma( a constant). This constant is called Euler's constant and its approx value is 0.57721&lt;br /&gt;&lt;br /&gt;&lt;div style="margin-bottom: 0px; margin-top: 0px;"&gt;Therefore, we can say limit &amp;nbsp; f(n) = limit ln n + gamma&lt;/div&gt;&lt;div style="margin-bottom: 0px; margin-top: 0px;"&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; n-&amp;gt;infinity &amp;nbsp; &amp;nbsp; &amp;nbsp; n-&amp;gt;infinity&lt;/div&gt;&lt;br /&gt;&lt;div style="margin-bottom: 0px; margin-top: 0px;"&gt;Hence &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;limit &amp;nbsp; f(n)/log n&amp;nbsp;&lt;/div&gt;&lt;div style="margin-bottom: 0px; margin-top: 0px;"&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; n-&amp;gt;infinity&amp;nbsp;&lt;/div&gt;&lt;div style="margin-bottom: 0px; margin-top: 0px;"&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;=&amp;nbsp;limit (ln n + gamma)/log n&lt;/div&gt;&lt;div style="margin-bottom: 0px; margin-top: 0px;"&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;n-&amp;gt;infinity&lt;/div&gt;&lt;div style="margin-bottom: 0px; margin-top: 0px;"&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; = limit ln n/log n &amp;nbsp;+ &amp;nbsp;gamma/limit&amp;nbsp;log n&lt;/div&gt;&lt;div style="margin-bottom: 0px; margin-top: 0px;"&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;n-&amp;gt;infinity&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;n-&amp;gt;infinity&lt;/div&gt;&lt;div style="margin-bottom: 0px; margin-top: 0px;"&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; = ln 2 + 0&lt;/div&gt;&lt;div style="margin-bottom: 0px; margin-top: 0px;"&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; = ln 2&lt;/div&gt;&lt;div style="margin-bottom: 0px; margin-top: 0px;"&gt;&lt;br /&gt;&lt;/div&gt;Hence we can say F(n) = O(log n)&lt;br /&gt;&lt;br /&gt;You can find the document &lt;a href="https://docs.google.com/Doc?docid=0AcL15NA4lO_UZGNnY3AzMzlfNDQ5Y3BwZzVoZGo&amp;amp;hl=en&amp;amp;authkey=CITOieUO"&gt;here&lt;/a&gt;.&lt;br /&gt;&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;/div&gt;&lt;br /&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3946478681282550454-6583453682840143777?l=som-itsolutions.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://som-itsolutions.blogspot.com/feeds/6583453682840143777/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=3946478681282550454&amp;postID=6583453682840143777' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3946478681282550454/posts/default/6583453682840143777'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3946478681282550454/posts/default/6583453682840143777'/><link rel='alternate' type='text/html' href='http://som-itsolutions.blogspot.com/2010/08/handy-maths-to-solve-data-structure.html' title='Handy Maths to solve Data Structure Problem'/><author><name>Som</name><uri>http://www.blogger.com/profile/09519633424407534012</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='24' src='http://3.bp.blogspot.com/-XVhL110Tyf8/ThxKF3DBYcI/AAAAAAAAEBo/arVXUPsgtSg/s220/NJ%2B042.JPG'/></author><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3946478681282550454.post-1193773407608285126</id><published>2010-08-19T11:56:00.003+05:30</published><updated>2010-09-16T16:27:17.175+05:30</updated><title type='text'>For my Data Structure Students - Insertion Sort</title><content type='html'>&lt;b&gt;The Algorithm - &lt;/b&gt;&lt;br /&gt;&lt;br /&gt;Lets define a function to insert an integer into a non-decreasing sorted array. See the function void insert(int x[], int&amp;amp; length, int&amp;amp; number_to_be_inserted). What it does, is that it starts scanning the array from the end - the maximum number (as it is a non-decreasing array). Whenever it finds that the number_to_be_inserted is less than than the number in the array, it shifts the position of that number in the array towards right. Otherwise it inserts the new number in that position. This principle can be applied to Sort an array. We will start with an one element array. It is obviously sorted. We will pick up the next element and put it in the right place of the sorted array. Thus we get a two element sorted array. Similarly we can get a sorted array of size n.&lt;br /&gt;&lt;br /&gt;In the following code snippet, the Method I is the Algorithm with a separate Insert Function. The method II is the sorting algorithm with the Insert function inbuilt into it.&lt;br /&gt;&lt;br /&gt;The source code of Method I can be found &lt;a href="https://docs.google.com/View?id=dcgcp339_461ftggtkvb"&gt;here&lt;/a&gt;.&lt;br /&gt;&lt;br /&gt;The output of this program is as given below&lt;br /&gt;&lt;br /&gt;&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://4.bp.blogspot.com/_PnYnrngiRvA/TJH3dy3laTI/AAAAAAAADx0/uIWVPEJ6Q4I/s1600/insertion+1.JPG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img border="0" src="http://4.bp.blogspot.com/_PnYnrngiRvA/TJH3dy3laTI/AAAAAAAADx0/uIWVPEJ6Q4I/s320/insertion+1.JPG" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;The source code of Method II can be found &lt;a href="https://docs.google.com/document/pub?id=1ByL5bZOHj2IbMbHNxI-BuaYrHKHK411_-EdtorDGmIQ"&gt;here&lt;/a&gt;.&lt;br /&gt;&lt;br /&gt;The output of this program is given below&lt;br /&gt;&lt;br /&gt;&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://2.bp.blogspot.com/_PnYnrngiRvA/TJH36_TPQoI/AAAAAAAADx8/hiO7Atf5RDc/s1600/insertion+2.JPG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img border="0" src="http://2.bp.blogspot.com/_PnYnrngiRvA/TJH36_TPQoI/AAAAAAAADx8/hiO7Atf5RDc/s320/insertion+2.JPG" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;Hope you enjoy this study.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3946478681282550454-1193773407608285126?l=som-itsolutions.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://som-itsolutions.blogspot.com/feeds/1193773407608285126/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=3946478681282550454&amp;postID=1193773407608285126' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3946478681282550454/posts/default/1193773407608285126'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3946478681282550454/posts/default/1193773407608285126'/><link rel='alternate' type='text/html' href='http://som-itsolutions.blogspot.com/2010/08/for-my-data-structure-students_7669.html' title='For my Data Structure Students - Insertion Sort'/><author><name>Som</name><uri>http://www.blogger.com/profile/09519633424407534012</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='24' src='http://3.bp.blogspot.com/-XVhL110Tyf8/ThxKF3DBYcI/AAAAAAAAEBo/arVXUPsgtSg/s220/NJ%2B042.JPG'/></author><media:thumbnail xmlns:media='http://search.yahoo.com/mrss/' url='http://4.bp.blogspot.com/_PnYnrngiRvA/TJH3dy3laTI/AAAAAAAADx0/uIWVPEJ6Q4I/s72-c/insertion+1.JPG' height='72' width='72'/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3946478681282550454.post-4554786651762803289</id><published>2010-08-19T10:50:00.006+05:30</published><updated>2010-09-16T16:04:05.584+05:30</updated><title type='text'>For my Data Structure Students - Selection Sort</title><content type='html'>As mentioned earlier, i have started writing code and analyzing of various data structure area of computer science... Here is one such Sorting Algorithm called Selection Sort. In the first pass, it just finds the minimum number and exchanges it with the first place, in the second pass it finds out the second most minimum number and exchanges it with the second position.&lt;br /&gt;&lt;b&gt;&lt;span class="Apple-style-span" style="font-weight: normal;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/b&gt;&lt;br /&gt;&lt;b&gt;&lt;span class="Apple-style-span" style="font-weight: normal;"&gt;Please find the source code of the Selection Sort from &lt;a href="https://docs.google.com/document/edit?id=1vcaG9j-O2pcXuMR5-MAh9AifKD44ZTTSV9BUrQQrqYM&amp;amp;hl=en&amp;amp;authkey=CLGxqcEF"&gt;here&lt;/a&gt;.&lt;/span&gt;&lt;/b&gt;&lt;br /&gt;&lt;b&gt;&lt;span class="Apple-style-span" style="font-weight: normal;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/b&gt;&lt;br /&gt;&lt;b&gt;&lt;span class="Apple-style-span" style="font-weight: normal;"&gt;The result of the code is as shown below. Please look at how at each outer loop pass, the small numbers occupy the places in the beginning of the sorted array...&lt;/span&gt;&lt;/b&gt;&lt;br /&gt;&lt;b&gt;&lt;span class="Apple-style-span" style="font-weight: normal;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/b&gt;&lt;br /&gt;&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://2.bp.blogspot.com/_PnYnrngiRvA/TJHyk6DfxeI/AAAAAAAADxs/5PKVzQK0w1Q/s1600/selection.JPG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img border="0" src="http://2.bp.blogspot.com/_PnYnrngiRvA/TJHyk6DfxeI/AAAAAAAADxs/5PKVzQK0w1Q/s320/selection.JPG" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;b&gt;&lt;span class="Apple-style-span" style="font-weight: normal;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/b&gt;&lt;br /&gt;&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;/div&gt;&lt;b&gt;&lt;span class="Apple-style-span" style="font-weight: normal;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/b&gt;&lt;br /&gt;&lt;b&gt;Analysis:&lt;/b&gt;&lt;br /&gt;&lt;br /&gt;For first outer loop, the inner loop goes for n-1 times, for the second outer loop, the inner loop goes for n-2 times and so on. The outer loop itself goes for n-1 times.&lt;br /&gt;&lt;br /&gt;Hence f(n) = (n-1) + (n-2) + (n-3) + ....+ 2+1 = n*(n-1)/2&lt;br /&gt;&lt;br /&gt;Hence O(n) = n^2&lt;br /&gt;&lt;br /&gt;Hope you enjoy this...&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3946478681282550454-4554786651762803289?l=som-itsolutions.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://som-itsolutions.blogspot.com/feeds/4554786651762803289/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=3946478681282550454&amp;postID=4554786651762803289' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3946478681282550454/posts/default/4554786651762803289'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3946478681282550454/posts/default/4554786651762803289'/><link rel='alternate' type='text/html' href='http://som-itsolutions.blogspot.com/2010/08/for-my-data-structure-students_19.html' title='For my Data Structure Students - Selection Sort'/><author><name>Som</name><uri>http://www.blogger.com/profile/09519633424407534012</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='24' src='http://3.bp.blogspot.com/-XVhL110Tyf8/ThxKF3DBYcI/AAAAAAAAEBo/arVXUPsgtSg/s220/NJ%2B042.JPG'/></author><media:thumbnail xmlns:media='http://search.yahoo.com/mrss/' url='http://2.bp.blogspot.com/_PnYnrngiRvA/TJHyk6DfxeI/AAAAAAAADxs/5PKVzQK0w1Q/s72-c/selection.JPG' height='72' width='72'/><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3946478681282550454.post-4478060492181172773</id><published>2010-08-19T10:22:00.007+05:30</published><updated>2010-10-01T21:54:57.221+05:30</updated><title type='text'>For my Data Structure Students - Bubble Sort...</title><content type='html'>As a professor of computer science i have started recapitulating the basic theoretical computer science. Few days back i have written the code for bubble sort and did its analysis. I would like to share it with the student community...&lt;br /&gt;&lt;br /&gt;You can find the source code from &lt;a href="https://docs.google.com/document/edit?id=1yx7nazdgZrWfVmj90Ebiu88YsXDEYd1Ov1NZyU0lH9I&amp;amp;hl=en&amp;amp;authkey=CLqW25EK"&gt;here&lt;/a&gt;.&lt;br /&gt;&lt;br /&gt;The result of the above program is shown below.&lt;br /&gt;&lt;br /&gt;&lt;b&gt;&lt;/b&gt;&lt;br /&gt;&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://1.bp.blogspot.com/_PnYnrngiRvA/TJHtx8tWuOI/AAAAAAAADxc/viOA_5kCGPc/s1600/bubble.JPG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img border="0" src="http://1.bp.blogspot.com/_PnYnrngiRvA/TJHtx8tWuOI/AAAAAAAADxc/viOA_5kCGPc/s320/bubble.JPG" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;b&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="font-weight: normal;"&gt;Please have a look at how at each pass of the outer loop the large numbers are pushed towards the end.&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="font-weight: normal;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;Analysis:&lt;/b&gt;&lt;br /&gt;&lt;br /&gt;The outer loop of the bubblesort algorithm does n times. For first outer loop the inner loop is for n-1 times, for second outer loop the inner loop is for n-2 times and so on.&lt;br /&gt;&lt;br /&gt;Hence total loop count is (n-1) + (n-2) +........+2+1 = n*(n-1)/2&lt;br /&gt;&lt;br /&gt;Hence O(n) = n^2&lt;br /&gt;&lt;br /&gt;Hope this discussion helps the student community...&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3946478681282550454-4478060492181172773?l=som-itsolutions.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://som-itsolutions.blogspot.com/feeds/4478060492181172773/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=3946478681282550454&amp;postID=4478060492181172773' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3946478681282550454/posts/default/4478060492181172773'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3946478681282550454/posts/default/4478060492181172773'/><link rel='alternate' type='text/html' href='http://som-itsolutions.blogspot.com/2010/08/for-my-data-structure-students.html' title='For my Data Structure Students - Bubble Sort...'/><author><name>Som</name><uri>http://www.blogger.com/profile/09519633424407534012</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='24' src='http://3.bp.blogspot.com/-XVhL110Tyf8/ThxKF3DBYcI/AAAAAAAAEBo/arVXUPsgtSg/s220/NJ%2B042.JPG'/></author><media:thumbnail xmlns:media='http://search.yahoo.com/mrss/' url='http://1.bp.blogspot.com/_PnYnrngiRvA/TJHtx8tWuOI/AAAAAAAADxc/viOA_5kCGPc/s72-c/bubble.JPG' height='72' width='72'/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3946478681282550454.post-576667982575063333</id><published>2010-08-13T13:52:00.011+05:30</published><updated>2010-10-01T22:02:15.403+05:30</updated><title type='text'>For my Microprocessor Students</title><content type='html'>I got this resource by googling. Hope this helps the student community.&lt;br /&gt;&lt;br /&gt;&lt;a href="https://docs.google.com/fileview?id=0B8L15NA4lO_UNGFhYjE1NTMtMzc5MC00YzU0LWJhY2UtZTAzMzg5YjlkNWQy&amp;amp;hl=en"&gt;Microprocessor Training&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;A good simulator for 8085 programming on PC is GNUSIM8085 and it is available at&amp;nbsp;&lt;a href="http://gnusim8085.org/"&gt;http://gnusim8085.org/&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;The interface of GNUSIM8085 looks like the following.&lt;br /&gt;&lt;br /&gt;&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://3.bp.blogspot.com/_PnYnrngiRvA/TG00rpuRbfI/AAAAAAAADv0/xFTElX9Yr4I/s1600/GNUSIM8085.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img border="0" src="http://3.bp.blogspot.com/_PnYnrngiRvA/TG00rpuRbfI/AAAAAAAADv0/xFTElX9Yr4I/s320/GNUSIM8085.png" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3946478681282550454-576667982575063333?l=som-itsolutions.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://som-itsolutions.blogspot.com/feeds/576667982575063333/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=3946478681282550454&amp;postID=576667982575063333' title='4 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3946478681282550454/posts/default/576667982575063333'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3946478681282550454/posts/default/576667982575063333'/><link rel='alternate' type='text/html' href='http://som-itsolutions.blogspot.com/2010/08/for-my-microprocessor-students.html' title='For my Microprocessor Students'/><author><name>Som</name><uri>http://www.blogger.com/profile/09519633424407534012</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='24' src='http://3.bp.blogspot.com/-XVhL110Tyf8/ThxKF3DBYcI/AAAAAAAAEBo/arVXUPsgtSg/s220/NJ%2B042.JPG'/></author><media:thumbnail xmlns:media='http://search.yahoo.com/mrss/' url='http://3.bp.blogspot.com/_PnYnrngiRvA/TG00rpuRbfI/AAAAAAAADv0/xFTElX9Yr4I/s72-c/GNUSIM8085.png' height='72' width='72'/><thr:total>4</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3946478681282550454.post-8455042614197941025</id><published>2010-07-22T07:24:00.001+05:30</published><updated>2010-07-22T07:25:55.220+05:30</updated><title type='text'>How to Import the Bookmarks from Chrome to Firefox</title><content type='html'>From almost the two years I have been using Ubuntu. I have installed Google's chrome browser in Ubuntu and I mostly use this one for browsing. However, yesterday I was thinking how I can import the bookmarks from Chrome to the Firefox, which is the browser that comes pre-installed with Ubuntu...Then I devised the following simple way to do that which I would like to share with you...&lt;br /&gt;&lt;br /&gt;You must be aware that we can do syncing of our own browsing data from Chrome. When we do syncing, one document called Bookmarks is created in the Google Chrome folder of My folders section of Google Docs of the synchronized Google account. Select that Bookmarks folder and go the More Action menu. At the bottom of that menu, there is a menu item called Export. Click that item and export and download the favorites as an HTML file.&lt;br /&gt;&lt;br /&gt;Now open the Firefox browser and go to Organize Bookmarks under the Bookmarks menu. There click Import and Backup and import the HTML file you have just exported and downloaded from Chrome. &lt;br /&gt;&lt;br /&gt;Voila....  All your Bookmarks will be imported to the Firefox browser....&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3946478681282550454-8455042614197941025?l=som-itsolutions.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://som-itsolutions.blogspot.com/feeds/8455042614197941025/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=3946478681282550454&amp;postID=8455042614197941025' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3946478681282550454/posts/default/8455042614197941025'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3946478681282550454/posts/default/8455042614197941025'/><link rel='alternate' type='text/html' href='http://som-itsolutions.blogspot.com/2010/07/how-to-import-bookmarks-from-chrome-to.html' title='How to Import the Bookmarks from Chrome to Firefox'/><author><name>Som</name><uri>http://www.blogger.com/profile/09519633424407534012</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='24' src='http://3.bp.blogspot.com/-XVhL110Tyf8/ThxKF3DBYcI/AAAAAAAAEBo/arVXUPsgtSg/s220/NJ%2B042.JPG'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3946478681282550454.post-5715839003202943322</id><published>2010-07-19T08:14:00.003+05:30</published><updated>2010-07-21T06:31:08.457+05:30</updated><title type='text'>Ubuntu video screen capture - XVidCap</title><content type='html'>I was wondering if i could get any tool for video screen capturing for Ubuntu. With a little bit of googling, i found XVidCap. Here is my first experience with the video screen capture of one of my Android Applications.&lt;br /&gt;&lt;br /&gt;&lt;object width="320" height="266" class="BLOG_video_class" id="BLOG_video-f1e2ce160bdb65f2" classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,40,0"&gt;&lt;param name="movie" value="http://www.youtube.com/get_player"&gt;&lt;param name="bgcolor" value="#FFFFFF"&gt;&lt;param name="allowfullscreen" value="true"&gt;&lt;param name="flashvars" value="flvurl=http://v11.nonxt8.googlevideo.com/videoplayback?id%3Df1e2ce160bdb65f2%26itag%3D5%26app%3Dblogger%26ip%3D0.0.0.0%26ipbits%3D0%26expire%3D1331080861%26sparams%3Did,itag,ip,ipbits,expire%26signature%3D75E4413FE339EB43B94B7EC7C164AA38EBD6DD92.615A0664D6E8CFDE5F4ECC66A2FB2CCD00A4F954%26key%3Dck1&amp;amp;iurl=http://video.google.com/ThumbnailServer2?app%3Dblogger%26contentid%3Df1e2ce160bdb65f2%26offsetms%3D5000%26itag%3Dw160%26sigh%3DDBCv0tcYbUeOeOmMW2Bo117Zpuk&amp;amp;autoplay=0&amp;amp;ps=blogger"&gt;&lt;embed src="http://www.youtube.com/get_player" type="application/x-shockwave-flash"width="320" height="266" bgcolor="#FFFFFF"flashvars="flvurl=http://v11.nonxt8.googlevideo.com/videoplayback?id%3Df1e2ce160bdb65f2%26itag%3D5%26app%3Dblogger%26ip%3D0.0.0.0%26ipbits%3D0%26expire%3D1331080861%26sparams%3Did,itag,ip,ipbits,expire%26signature%3D75E4413FE339EB43B94B7EC7C164AA38EBD6DD92.615A0664D6E8CFDE5F4ECC66A2FB2CCD00A4F954%26key%3Dck1&amp;iurl=http://video.google.com/ThumbnailServer2?app%3Dblogger%26contentid%3Df1e2ce160bdb65f2%26offsetms%3D5000%26itag%3Dw160%26sigh%3DDBCv0tcYbUeOeOmMW2Bo117Zpuk&amp;autoplay=0&amp;ps=blogger"allowFullScreen="true" /&gt;&lt;/object&gt;&lt;br /&gt;&lt;br /&gt;Hope this information helps others...&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3946478681282550454-5715839003202943322?l=som-itsolutions.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://som-itsolutions.blogspot.com/feeds/5715839003202943322/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=3946478681282550454&amp;postID=5715839003202943322' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3946478681282550454/posts/default/5715839003202943322'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3946478681282550454/posts/default/5715839003202943322'/><link rel='alternate' type='text/html' href='http://som-itsolutions.blogspot.com/2010/07/ubuntu-video-screen-capture-xvidcap.html' title='Ubuntu video screen capture - XVidCap'/><author><name>Som</name><uri>http://www.blogger.com/profile/09519633424407534012</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='24' src='http://3.bp.blogspot.com/-XVhL110Tyf8/ThxKF3DBYcI/AAAAAAAAEBo/arVXUPsgtSg/s220/NJ%2B042.JPG'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3946478681282550454.post-8792033132774433062</id><published>2010-03-29T14:45:00.010+05:30</published><updated>2010-08-15T18:16:37.328+05:30</updated><title type='text'>My first experience with OpenCV</title><content type='html'>OpenCV is an opensource library for computer vision. It is available at &lt;a href="http://sourceforge.net/projects/opencvlibrary/"&gt;http://sourceforge.net/projects/opencvlibrary/&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;With the help of some of the internet samples, i tried to play around with OpenCV from past two days. And here is one such application. It actually plays an AVI file. &lt;br /&gt;&lt;br /&gt;&lt;br /&gt;You can find a nice tutorial on OpenCV at &lt;a href="http://www.site.uottawa.ca/~laganier/tutorial/opencv+directshow/cvision.htm"&gt;http://www.site.uottawa.ca/~laganier/tutorial/opencv+directshow/cvision.htm&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;Here is a glimpse of how my application will look like.&lt;br /&gt;&lt;br /&gt;&lt;object width="320" height="266" class="BLOG_video_class" id="BLOG_video-c5499223a9d66c31" classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,40,0"&gt;&lt;param name="movie" value="http://www.youtube.com/get_player"&gt;&lt;param name="bgcolor" value="#FFFFFF"&gt;&lt;param name="allowfullscreen" value="true"&gt;&lt;param name="flashvars" value="flvurl=http://v12.nonxt3.googlevideo.com/videoplayback?id%3Dc5499223a9d66c31%26itag%3D5%26app%3Dblogger%26ip%3D0.0.0.0%26ipbits%3D0%26expire%3D1331080861%26sparams%3Did,itag,ip,ipbits,expire%26signature%3D4D598946DC28176FB72EC7FA19AA6BC9358B6730.824F047380340C9C5FAAAB728C5B1EB1E092CD89%26key%3Dck1&amp;amp;iurl=http://video.google.com/ThumbnailServer2?app%3Dblogger%26contentid%3Dc5499223a9d66c31%26offsetms%3D5000%26itag%3Dw160%26sigh%3DbT8pJjn6CL62TRHq7kOV_PR0Cv8&amp;amp;autoplay=0&amp;amp;ps=blogger"&gt;&lt;embed src="http://www.youtube.com/get_player" type="application/x-shockwave-flash"width="320" height="266" bgcolor="#FFFFFF"flashvars="flvurl=http://v12.nonxt3.googlevideo.com/videoplayback?id%3Dc5499223a9d66c31%26itag%3D5%26app%3Dblogger%26ip%3D0.0.0.0%26ipbits%3D0%26expire%3D1331080861%26sparams%3Did,itag,ip,ipbits,expire%26signature%3D4D598946DC28176FB72EC7FA19AA6BC9358B6730.824F047380340C9C5FAAAB728C5B1EB1E092CD89%26key%3Dck1&amp;iurl=http://video.google.com/ThumbnailServer2?app%3Dblogger%26contentid%3Dc5499223a9d66c31%26offsetms%3D5000%26itag%3Dw160%26sigh%3DbT8pJjn6CL62TRHq7kOV_PR0Cv8&amp;autoplay=0&amp;ps=blogger"allowFullScreen="true" /&gt;&lt;/object&gt;&lt;br /&gt;&lt;br /&gt;Hope it gives some insights to others who are interested in computer vision.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3946478681282550454-8792033132774433062?l=som-itsolutions.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://som-itsolutions.blogspot.com/feeds/8792033132774433062/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=3946478681282550454&amp;postID=8792033132774433062' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3946478681282550454/posts/default/8792033132774433062'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3946478681282550454/posts/default/8792033132774433062'/><link rel='alternate' type='text/html' href='http://som-itsolutions.blogspot.com/2010/03/my-first-experience-with-opencv.html' title='My first experience with OpenCV'/><author><name>Som</name><uri>http://www.blogger.com/profile/09519633424407534012</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='24' src='http://3.bp.blogspot.com/-XVhL110Tyf8/ThxKF3DBYcI/AAAAAAAAEBo/arVXUPsgtSg/s220/NJ%2B042.JPG'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3946478681282550454.post-5512361684410399212</id><published>2010-03-12T16:42:00.002+05:30</published><updated>2010-03-12T21:33:58.715+05:30</updated><title type='text'>Cubicles in Indian IT companies...</title><content type='html'>The way we behave in a crowd or in solitude is totally different from the way we behave in a place surrounded by few known people... In the first case we become carefree and tend to break all sorts of barriers... in the second case we restrict ourselves to some extent... in the first case when we break free, we may create something new, do something highly innovative... however its just not possible in the second case....hence i believe to get some Aha-product from our IT companies, we must first break the cubicle culture that exists now and let the developers become care-free...&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3946478681282550454-5512361684410399212?l=som-itsolutions.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://som-itsolutions.blogspot.com/feeds/5512361684410399212/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=3946478681282550454&amp;postID=5512361684410399212' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3946478681282550454/posts/default/5512361684410399212'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3946478681282550454/posts/default/5512361684410399212'/><link rel='alternate' type='text/html' href='http://som-itsolutions.blogspot.com/2010/03/cubicles-in-indian-it-companies.html' title='Cubicles in Indian IT companies...'/><author><name>Som</name><uri>http://www.blogger.com/profile/09519633424407534012</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='24' src='http://3.bp.blogspot.com/-XVhL110Tyf8/ThxKF3DBYcI/AAAAAAAAEBo/arVXUPsgtSg/s220/NJ%2B042.JPG'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3946478681282550454.post-1307628826278279214</id><published>2010-03-10T07:53:00.000+05:30</published><updated>2010-03-10T07:54:33.749+05:30</updated><title type='text'>Voting in India through mobile phones</title><content type='html'>Yesterday i saw a digged article in which Sam Pitroda was trying to mention about voting in a democracy through mobile phones. And before going to sleep, i thought of this crazy idea about how it may be implemented... Let me share it with you... &lt;br /&gt;&lt;br /&gt;As you know India is going to give a national id card to everyone. I was thinking how about having an ID card which will have an encrypted image on it which will store all sorts of data, be it biological or anything one can imagine... One national team will develop a mobile application which will decrypt the image to extract all the information... The telecom regulatory authority may issue a law that to sell a mobile phone in India, the manufacturer will have to install this application and it will be secured so that no one can uninstall it from the phone.&lt;br /&gt;&lt;br /&gt;Now what this application will do... Once we take a shot of that encrypted image on the ID card with the phone camera, the application will decipher all the data stored on it...&lt;br /&gt;&lt;br /&gt;So we will have a secured voting website...The person who wants to vote will go to that site which will ask the user to launch that application...Once it is launched the user will simply take a shot of the encrypted image on his ID card... And thats it... The application will feed all the data to the server through a secured connection and the website will take the user to the right constituency... And then he can simply choose his candidate...&lt;br /&gt;&lt;br /&gt;As the blog title says its my own world of technology and software, this is my crazy idea...&lt;br /&gt;&lt;br /&gt;Let me know what you think about it...&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3946478681282550454-1307628826278279214?l=som-itsolutions.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://som-itsolutions.blogspot.com/feeds/1307628826278279214/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=3946478681282550454&amp;postID=1307628826278279214' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3946478681282550454/posts/default/1307628826278279214'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3946478681282550454/posts/default/1307628826278279214'/><link rel='alternate' type='text/html' href='http://som-itsolutions.blogspot.com/2010/03/voting-in-india-through-mobile-phones.html' title='Voting in India through mobile phones'/><author><name>Som</name><uri>http://www.blogger.com/profile/09519633424407534012</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='24' src='http://3.bp.blogspot.com/-XVhL110Tyf8/ThxKF3DBYcI/AAAAAAAAEBo/arVXUPsgtSg/s220/NJ%2B042.JPG'/></author><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3946478681282550454.post-605613700964547370</id><published>2010-03-04T22:19:00.006+05:30</published><updated>2010-07-04T08:26:44.241+05:30</updated><title type='text'>Training on C++, Android, UML and Design Pattern</title><content type='html'>I am interested in providing training on subjects like C++, UML, Android, Design Pattern, Java/J2SE etc. Please have a look at my training website &lt;br /&gt;&lt;br /&gt;&lt;a href="http://sites.google.com/a/som-itsolutions.com/som-itsolutions/Home"&gt;http://sites.google.com/a/som-itsolutions.com/som-itsolutions/Home&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;to get an idea.&lt;br /&gt;&lt;br /&gt;If you are interested, please email me.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3946478681282550454-605613700964547370?l=som-itsolutions.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://som-itsolutions.blogspot.com/feeds/605613700964547370/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=3946478681282550454&amp;postID=605613700964547370' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3946478681282550454/posts/default/605613700964547370'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3946478681282550454/posts/default/605613700964547370'/><link rel='alternate' type='text/html' href='http://som-itsolutions.blogspot.com/2010/03/training-on-c-android-uml-and-design.html' title='Training on C++, Android, UML and Design Pattern'/><author><name>Som</name><uri>http://www.blogger.com/profile/09519633424407534012</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='24' src='http://3.bp.blogspot.com/-XVhL110Tyf8/ThxKF3DBYcI/AAAAAAAAEBo/arVXUPsgtSg/s220/NJ%2B042.JPG'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3946478681282550454.post-2084814709805659153</id><published>2010-02-23T06:22:00.004+05:30</published><updated>2010-03-10T08:16:39.428+05:30</updated><title type='text'>The Importance of Google...</title><content type='html'>The usefulness of Google is not very surprising to many...however, for me its one of the greatest democratizing tools...it has democratized the concept that is called knowledge which was once a well guarded property in the hands of a few... &lt;br /&gt;&lt;br /&gt;let me elaborate it a bit...i think whatever little related to technology i have learnt so far, is simply by means of Googling... even these days to remove the programming errors i take the help of mighty Google...to elaborate it more, for example, today i became curious about the way WiFi can be used in the industrial automation domain... so i googled it and got a fair amount of idea which includes ZigBee to Cisco's Wireless Plant Solution...I became curious about whether the data collected by sensors in a plant can be processed via cloud...i am interested in this topic because of its social implication...think about it that if the plant's data can be processed across the continent, then no one will have to do night shift duty... So i googled about that  and got some idea about Helios platform from Eurotech... when i want to know if the 802.11n has been officially released, i just google that...when i want to know if there is anything similar or dissimilar between new(noThrow) of C++ and new(ELeave) of Symbian C++, i simply google that...when i want to know about the smart pointers in boost, i just google that...&lt;br /&gt;&lt;br /&gt;the google doc or the other tools like picasa and google map have come recently... but i am an ardent fan of Google from its inception because i think its only because of google i did not have to depend on anybody to learn about my technological area...&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3946478681282550454-2084814709805659153?l=som-itsolutions.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://som-itsolutions.blogspot.com/feeds/2084814709805659153/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=3946478681282550454&amp;postID=2084814709805659153' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3946478681282550454/posts/default/2084814709805659153'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3946478681282550454/posts/default/2084814709805659153'/><link rel='alternate' type='text/html' href='http://som-itsolutions.blogspot.com/2010/02/importance-of-google.html' title='The Importance of Google...'/><author><name>Som</name><uri>http://www.blogger.com/profile/09519633424407534012</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='24' src='http://3.bp.blogspot.com/-XVhL110Tyf8/ThxKF3DBYcI/AAAAAAAAEBo/arVXUPsgtSg/s220/NJ%2B042.JPG'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3946478681282550454.post-8210437597258389670</id><published>2010-02-18T05:48:00.002+05:30</published><updated>2010-02-19T20:57:38.242+05:30</updated><title type='text'>My First Experience with Ubuntu QT</title><content type='html'>I had installed Ubuntu quite sometimes back. I had also installed QT. However, i got my hands dirty in QT programming in the Ubuntu environment for the first time today. Let me share my experience with you.&lt;br /&gt;&lt;br /&gt;First i opened the QTCreator from the Applications-&gt;Programming menu. Then went to File-&gt;New. And followed the steps as shown in the pictures.&lt;br /&gt;&lt;br /&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://3.bp.blogspot.com/_PnYnrngiRvA/S3yFzWg7AOI/AAAAAAAACog/uGDB5ZLN6YM/s1600-h/1.png"&gt;&lt;img style="display:block; margin:0px auto 10px; text-align:center;cursor:pointer; cursor:hand;width: 320px; height: 200px;" src="http://3.bp.blogspot.com/_PnYnrngiRvA/S3yFzWg7AOI/AAAAAAAACog/uGDB5ZLN6YM/s320/1.png" border="0" alt=""id="BLOGGER_PHOTO_ID_5439369567220203746" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://4.bp.blogspot.com/_PnYnrngiRvA/S3yF9F1RQOI/AAAAAAAACoo/OHqhIspT5jk/s1600-h/2.png"&gt;&lt;img style="display:block; margin:0px auto 10px; text-align:center;cursor:pointer; cursor:hand;width: 320px; height: 200px;" src="http://4.bp.blogspot.com/_PnYnrngiRvA/S3yF9F1RQOI/AAAAAAAACoo/OHqhIspT5jk/s320/2.png" border="0" alt=""id="BLOGGER_PHOTO_ID_5439369734540837090" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://2.bp.blogspot.com/_PnYnrngiRvA/S3yGGtWhWqI/AAAAAAAACow/s5A1vSdmDBQ/s1600-h/3.png"&gt;&lt;img style="display:block; margin:0px auto 10px; text-align:center;cursor:pointer; cursor:hand;width: 320px; height: 200px;" src="http://2.bp.blogspot.com/_PnYnrngiRvA/S3yGGtWhWqI/AAAAAAAACow/s5A1vSdmDBQ/s320/3.png" border="0" alt=""id="BLOGGER_PHOTO_ID_5439369899768109730" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://2.bp.blogspot.com/_PnYnrngiRvA/S3yGO0uAvYI/AAAAAAAACo4/5aDoIAEXEkE/s1600-h/4.png"&gt;&lt;img style="display:block; margin:0px auto 10px; text-align:center;cursor:pointer; cursor:hand;width: 320px; height: 200px;" src="http://2.bp.blogspot.com/_PnYnrngiRvA/S3yGO0uAvYI/AAAAAAAACo4/5aDoIAEXEkE/s320/4.png" border="0" alt=""id="BLOGGER_PHOTO_ID_5439370039184637314" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://4.bp.blogspot.com/_PnYnrngiRvA/S3yGXNM5ixI/AAAAAAAACpA/y8DmJBtMYuU/s1600-h/5.png"&gt;&lt;img style="display:block; margin:0px auto 10px; text-align:center;cursor:pointer; cursor:hand;width: 320px; height: 200px;" src="http://4.bp.blogspot.com/_PnYnrngiRvA/S3yGXNM5ixI/AAAAAAAACpA/y8DmJBtMYuU/s320/5.png" border="0" alt=""id="BLOGGER_PHOTO_ID_5439370183195593490" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;After the project is created, i opened the mainwindow.ui and dragged a PushButton to the center of the main window. From the property, i changed the display text of the button as Hello World.  its name is changed to HelloWorldBtn.&lt;br /&gt;&lt;br /&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://1.bp.blogspot.com/_PnYnrngiRvA/S3yGkw1LmcI/AAAAAAAACpI/atcV-GpUhw4/s1600-h/6.png"&gt;&lt;img style="display:block; margin:0px auto 10px; text-align:center;cursor:pointer; cursor:hand;width: 320px; height: 200px;" src="http://1.bp.blogspot.com/_PnYnrngiRvA/S3yGkw1LmcI/AAAAAAAACpI/atcV-GpUhw4/s320/6.png" border="0" alt=""id="BLOGGER_PHOTO_ID_5439370416098089410" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;Then i added a private slot in the mainwindow.h file as follows:&lt;br /&gt;&lt;br /&gt;private slots:&lt;br /&gt;void on_HelloWorldBtn_clicked();&lt;br /&gt;&lt;br /&gt;It means the signal connection is automatic.&lt;br /&gt;&lt;br /&gt;Then i added the following handler function in the mainwindow.cpp file:&lt;br /&gt;&lt;br /&gt;void MainWindow::on_HelloWorldBtn_clicked()&lt;br /&gt;{&lt;br /&gt;QMessageBox::information(this,"Som", "Hello World");&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;And its done... Of course  to compile this code, i had to do #include (QMessageBox) in the mainwindow.cpp file...&lt;br /&gt;&lt;br /&gt;i ran the application... And when i clicked the button it showed the messagebox as the following picture...&lt;br /&gt;&lt;br /&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://2.bp.blogspot.com/_PnYnrngiRvA/S3yGtjElVxI/AAAAAAAACpQ/lcXGsC_VVBs/s1600-h/7.png"&gt;&lt;img style="display:block; margin:0px auto 10px; text-align:center;cursor:pointer; cursor:hand;width: 320px; height: 200px;" src="http://2.bp.blogspot.com/_PnYnrngiRvA/S3yGtjElVxI/AAAAAAAACpQ/lcXGsC_VVBs/s320/7.png" border="0" alt=""id="BLOGGER_PHOTO_ID_5439370567023417106" /&gt;&lt;/a&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3946478681282550454-8210437597258389670?l=som-itsolutions.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://som-itsolutions.blogspot.com/feeds/8210437597258389670/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=3946478681282550454&amp;postID=8210437597258389670' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3946478681282550454/posts/default/8210437597258389670'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3946478681282550454/posts/default/8210437597258389670'/><link rel='alternate' type='text/html' href='http://som-itsolutions.blogspot.com/2010/02/my-first-experience-with-ubuntu-qt.html' title='My First Experience with Ubuntu QT'/><author><name>Som</name><uri>http://www.blogger.com/profile/09519633424407534012</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='24' src='http://3.bp.blogspot.com/-XVhL110Tyf8/ThxKF3DBYcI/AAAAAAAAEBo/arVXUPsgtSg/s220/NJ%2B042.JPG'/></author><media:thumbnail xmlns:media='http://search.yahoo.com/mrss/' url='http://3.bp.blogspot.com/_PnYnrngiRvA/S3yFzWg7AOI/AAAAAAAACog/uGDB5ZLN6YM/s72-c/1.png' height='72' width='72'/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3946478681282550454.post-6300538081075161100</id><published>2010-01-25T07:28:00.009+05:30</published><updated>2010-02-04T23:43:56.185+05:30</updated><title type='text'>Android Graphics</title><content type='html'>I was curious about the graphical programming in Android... Fortunately i have found the library aChartEngine... As i was trying to play around with it, i came up with few trigonometric graphs... Hope this would give some pointers to the new comers about graphical programming in Android...&lt;br /&gt;&lt;br /&gt;The application looks like the following...&lt;br /&gt;&lt;br /&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://4.bp.blogspot.com/_PnYnrngiRvA/S2rlgjfxERI/AAAAAAAACns/ozaaVgnKNko/s1600-h/33.JPG"&gt;&lt;img style="display:block; margin:0px auto 10px; text-align:center;cursor:pointer; cursor:hand;width: 320px; height: 259px;" src="http://4.bp.blogspot.com/_PnYnrngiRvA/S2rlgjfxERI/AAAAAAAACns/ozaaVgnKNko/s320/33.JPG" border="0" alt=""id="BLOGGER_PHOTO_ID_5434408247822979346" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;And the graphs are like the following:&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight:bold;"&gt;Sin Curve&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://4.bp.blogspot.com/_PnYnrngiRvA/S1z8Gcds6bI/AAAAAAAACLE/zpiV-upYOqg/s1600-h/28.JPG"&gt;&lt;img style="display:block; margin:0px auto 10px; text-align:center;cursor:pointer; cursor:hand;width: 320px; height: 257px;" src="http://4.bp.blogspot.com/_PnYnrngiRvA/S1z8Gcds6bI/AAAAAAAACLE/zpiV-upYOqg/s320/28.JPG" border="0" alt=""id="BLOGGER_PHOTO_ID_5430492438352161202" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight:bold;"&gt;Cosine Curve&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://3.bp.blogspot.com/_PnYnrngiRvA/S1z8VNoAX0I/AAAAAAAACLM/I0uxe1GaRAg/s1600-h/29.JPG"&gt;&lt;img style="display:block; margin:0px auto 10px; text-align:center;cursor:pointer; cursor:hand;width: 320px; height: 258px;" src="http://3.bp.blogspot.com/_PnYnrngiRvA/S1z8VNoAX0I/AAAAAAAACLM/I0uxe1GaRAg/s320/29.JPG" border="0" alt=""id="BLOGGER_PHOTO_ID_5430492692066885442" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight:bold;"&gt;Tangent Curve&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://2.bp.blogspot.com/_PnYnrngiRvA/S1z8j15wQJI/AAAAAAAACLU/ajrhsMMR_r8/s1600-h/30.JPG"&gt;&lt;img style="display:block; margin:0px auto 10px; text-align:center;cursor:pointer; cursor:hand;width: 320px; height: 262px;" src="http://2.bp.blogspot.com/_PnYnrngiRvA/S1z8j15wQJI/AAAAAAAACLU/ajrhsMMR_r8/s320/30.JPG" border="0" alt=""id="BLOGGER_PHOTO_ID_5430492943396913298" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight:bold;"&gt;Sinc Curve&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://1.bp.blogspot.com/_PnYnrngiRvA/S2sOTFKfcpI/AAAAAAAACn8/hCsAWsqRhOY/s1600-h/33.JPG"&gt;&lt;img style="display:block; margin:0px auto 10px; text-align:center;cursor:pointer; cursor:hand;width: 320px; height: 258px;" src="http://1.bp.blogspot.com/_PnYnrngiRvA/S2sOTFKfcpI/AAAAAAAACn8/hCsAWsqRhOY/s320/33.JPG" border="0" alt=""id="BLOGGER_PHOTO_ID_5434453096319120018" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight:bold;"&gt;Damped Sin Curve&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://4.bp.blogspot.com/_PnYnrngiRvA/S2rlw9WUUSI/AAAAAAAACn0/uWclu8XCaHE/s1600-h/32.JPG"&gt;&lt;img style="display:block; margin:0px auto 10px; text-align:center;cursor:pointer; cursor:hand;width: 320px; height: 260px;" src="http://4.bp.blogspot.com/_PnYnrngiRvA/S2rlw9WUUSI/AAAAAAAACn0/uWclu8XCaHE/s320/32.JPG" border="0" alt=""id="BLOGGER_PHOTO_ID_5434408529640575266" /&gt;&lt;/a&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3946478681282550454-6300538081075161100?l=som-itsolutions.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://som-itsolutions.blogspot.com/feeds/6300538081075161100/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=3946478681282550454&amp;postID=6300538081075161100' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3946478681282550454/posts/default/6300538081075161100'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3946478681282550454/posts/default/6300538081075161100'/><link rel='alternate' type='text/html' href='http://som-itsolutions.blogspot.com/2010/01/android-graphics.html' title='Android Graphics'/><author><name>Som</name><uri>http://www.blogger.com/profile/09519633424407534012</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='24' src='http://3.bp.blogspot.com/-XVhL110Tyf8/ThxKF3DBYcI/AAAAAAAAEBo/arVXUPsgtSg/s220/NJ%2B042.JPG'/></author><media:thumbnail xmlns:media='http://search.yahoo.com/mrss/' url='http://4.bp.blogspot.com/_PnYnrngiRvA/S2rlgjfxERI/AAAAAAAACns/ozaaVgnKNko/s72-c/33.JPG' height='72' width='72'/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3946478681282550454.post-2902583988284809473</id><published>2010-01-19T09:46:00.024+05:30</published><updated>2010-11-25T09:57:19.467+05:30</updated><title type='text'>Android HomeScreen Management</title><content type='html'>As i was trying to play around with Android HomeScreen, i came up with this application to add any application to the HomeScreen. I think it can work as a good project for the beginner of Android programming.&lt;br /&gt;&lt;br /&gt;The home screen looks like the following after i added two of the applications to the HomeScreen -one is my own KeyPadDialer and the other is the AlarmClock.&lt;br /&gt;&lt;br /&gt;&lt;a href="http://2.bp.blogspot.com/_PnYnrngiRvA/S1UzbEouKTI/AAAAAAAACKk/oUXlTftKRIo/s1600-h/24.JPG" onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}"&gt;&lt;img alt="" border="0" id="BLOGGER_PHOTO_ID_5428301466059024690" src="http://2.bp.blogspot.com/_PnYnrngiRvA/S1UzbEouKTI/AAAAAAAACKk/oUXlTftKRIo/s320/24.JPG" style="cursor: hand; cursor: pointer; display: block; height: 262px; margin: 0px auto 10px; text-align: center; width: 320px;" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;And the HomeScreen Management Application looks like the following in the beginning:&lt;br /&gt;&lt;br /&gt;&lt;a href="http://2.bp.blogspot.com/_PnYnrngiRvA/S1UzrXMlUQI/AAAAAAAACKs/rnS9cktudYA/s1600-h/25.JPG" onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}"&gt;&lt;img alt="" border="0" id="BLOGGER_PHOTO_ID_5428301745919185154" src="http://2.bp.blogspot.com/_PnYnrngiRvA/S1UzrXMlUQI/AAAAAAAACKs/rnS9cktudYA/s320/25.JPG" style="cursor: hand; cursor: pointer; display: block; height: 262px; margin: 0px auto 10px; text-align: center; width: 320px;" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;And after clicking the Spinner it looks this:&lt;br /&gt;&lt;br /&gt;&lt;a href="http://2.bp.blogspot.com/_PnYnrngiRvA/S1Uz7bnBF6I/AAAAAAAACK0/0cxAp9BNkF8/s1600-h/26.JPG" onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}"&gt;&lt;img alt="" border="0" id="BLOGGER_PHOTO_ID_5428302021981706146" src="http://2.bp.blogspot.com/_PnYnrngiRvA/S1Uz7bnBF6I/AAAAAAAACK0/0cxAp9BNkF8/s320/26.JPG" style="cursor: hand; cursor: pointer; display: block; height: 221px; margin: 0px auto 10px; text-align: center; width: 320px;" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;The complete source code for my application can be found &lt;a href="https://docs.google.com/Doc?docid=0AcL15NA4lO_UZGNnY3AzMzlfNDc5Z3NtcjhnZmo&amp;amp;hl=en&amp;amp;authkey=CNThmdgB"&gt;here&lt;/a&gt;.&lt;br /&gt;&lt;br /&gt;The manifest file for this application can be found &lt;a href="https://docs.google.com/document/d/1farjHCC9YbJBqHfDD2oNJ4rF5ptZseHb1y2qbwBNCnM/edit?hl=en&amp;amp;authkey=CPvGwpwE"&gt;here&lt;/a&gt;.&lt;br /&gt;&lt;br /&gt;And the layout of the application is given &lt;a href="https://docs.google.com/document/d/1gopExX0_hl3ZbS5HaNjpT7mxDshZIXeL1z8AQ1eheXs/edit?hl=en&amp;amp;authkey=CJj1spkM"&gt;here&lt;/a&gt;.&lt;br /&gt;&lt;br /&gt;Hope this idea helps others...&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3946478681282550454-2902583988284809473?l=som-itsolutions.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://som-itsolutions.blogspot.com/feeds/2902583988284809473/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=3946478681282550454&amp;postID=2902583988284809473' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3946478681282550454/posts/default/2902583988284809473'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3946478681282550454/posts/default/2902583988284809473'/><link rel='alternate' type='text/html' href='http://som-itsolutions.blogspot.com/2010/01/playing-with-android-homescreen.html' title='Android HomeScreen Management'/><author><name>Som</name><uri>http://www.blogger.com/profile/09519633424407534012</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='24' src='http://3.bp.blogspot.com/-XVhL110Tyf8/ThxKF3DBYcI/AAAAAAAAEBo/arVXUPsgtSg/s220/NJ%2B042.JPG'/></author><media:thumbnail xmlns:media='http://search.yahoo.com/mrss/' url='http://2.bp.blogspot.com/_PnYnrngiRvA/S1UzbEouKTI/AAAAAAAACKk/oUXlTftKRIo/s72-c/24.JPG' height='72' width='72'/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3946478681282550454.post-1251027958572356647</id><published>2010-01-02T19:47:00.002+05:30</published><updated>2010-01-02T20:06:03.012+05:30</updated><title type='text'>My first experience with Java</title><content type='html'>As most of my experience lies in C++, when i started gaining interest in Java/J2SE i started looking at it from a C++ programmers point of view. Hence the first thing i googled was how to create a canonical class in Java. And i was astonished to find out that the way we do Assignment operator in C++ is not the same in Java. After some more googling i came to know about the clonable interface in Java. And it gave me the right direction...&lt;br /&gt;&lt;br /&gt;Then i googled about the String class in Java and found out that a String object in Java is immutable... i became curious and opened the String class of Java... And voila... no wonder... the character array that holds the contents of the String object is final... hence it is immutable... So i asked myself what happens when we do String newString = oldString in Java. And i got the answer... As the String class is not implementing the Clonable interface, when we do String newString = oldString, the oldString's contents get a new reference in newString... We loose any reference to oldString.&lt;br /&gt;&lt;br /&gt;But then i wondered how String S1 = oldString + "abc" would work. Because as i was googling i found out that Java does not support operator overloading... so how come the + operator is working fine for the String class? my first stumbling block... fortunately i found out the document at &lt;a href="http://java.sun.com/docs/books/jls/third_edition/html/expressions.html#15.18.1"&gt;http://java.sun.com/docs/books/jls/third_edition/html/expressions.html#15.18.1&lt;/a&gt; and my doubts were gone... &lt;br /&gt;&lt;br /&gt;So i wondered if Strings are immutable in Java, are not there any way to change the contents of a String object without creating a new object? i googled a little more and came to know about StringBuffer and StringBuilder classes and their mutable char array which will store that data... i delved into the classes a little more and found out about their append function.&lt;br /&gt;&lt;br /&gt;So far my investigation into the Java source code is fruitful...&lt;br /&gt;&lt;br /&gt;Hopefully i will be able to delve more into it and find out the nitty-gritties about the Java language...&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3946478681282550454-1251027958572356647?l=som-itsolutions.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://som-itsolutions.blogspot.com/feeds/1251027958572356647/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=3946478681282550454&amp;postID=1251027958572356647' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3946478681282550454/posts/default/1251027958572356647'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3946478681282550454/posts/default/1251027958572356647'/><link rel='alternate' type='text/html' href='http://som-itsolutions.blogspot.com/2010/01/my-first-experience-with-java.html' title='My first experience with Java'/><author><name>Som</name><uri>http://www.blogger.com/profile/09519633424407534012</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='24' src='http://3.bp.blogspot.com/-XVhL110Tyf8/ThxKF3DBYcI/AAAAAAAAEBo/arVXUPsgtSg/s220/NJ%2B042.JPG'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3946478681282550454.post-6966451191242041854</id><published>2009-11-17T06:42:00.012+05:30</published><updated>2011-06-12T06:14:38.899+05:30</updated><title type='text'>Experimentation with Design Pattern</title><content type='html'>&lt;div dir="ltr" style="text-align: left;" trbidi="on"&gt;I am yet to study the book Pattern Hatching. However, i tried to accumulate all my knowledge on Design Pattern and solved a problem of Accountancy. i would like to share it with you. Let me, first of all, state the problem.&lt;br /&gt;&lt;br /&gt;The Problem :&lt;br /&gt;&lt;br /&gt;Basic sales tax is applicable at a rate of 10% on all goods, except books, food, and medical products that are exempt. Import duty is an additional sales tax applicable on all imported goods at a rate of 5%, with no exemptions. Also the Sales Tax should be rounded off to the nearest 0.05.&lt;br /&gt;&lt;br /&gt;This being the problem, we need to come out with a solution for this problem.&lt;br /&gt;&lt;br /&gt;Now let me tell you how my thought process went into it to think it at an abstract level.&lt;br /&gt;&lt;br /&gt;First of all, i thought to make two top level classes. One that will define the Items having different benchmarks for Sales Tax and Import Duty; i.e. &lt;br /&gt;&lt;br /&gt;1. Food, Medical and Book items which are not imported and hence exempted from both sales tax and import duty&lt;br /&gt;2. Non Food Book and Medical items which are not imported and hence will have just the Sales Tax&lt;br /&gt;3. Food Book and Medical items which are imported and hence will have only import duty&lt;br /&gt;4. Non food book and medical  items which are imported and hence will have both Sales Tax and Import Duty&lt;br /&gt;&lt;br /&gt;And the other for the Tax Calculation algorithm for different items.&lt;br /&gt;&lt;br /&gt;Then i thought this is a perfect match for Strategy Pattern that i had studied in the GoF book. I thought about that pattern keeping in mind for the future expansion of the Tax Calculation Algorithm. What i mean is that for the present problem, the calculation is simple.  And hence it does not need any other Strategy. However, for the future purpose if the Tax Calculation Algorithm is changed to some complicated one, then we can just Subclass the Tax Calculation class and attach that strategy to the Item Class.&lt;br /&gt;&lt;br /&gt;Next i thought, won't it be nice to get a Factory Class through which the client can create different Items on the fly. Hence i have decided to create an ItemCreator class which is nothing but a parameterized factory class for creating different Items on the fly.&lt;br /&gt;&lt;br /&gt;And i came out with the following solution.     &lt;br /&gt;&lt;br /&gt;The Item class Hierarchy:&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;em&gt;File: Item.h&lt;/em&gt; &lt;br /&gt;#ifndef ITEM_H&lt;br /&gt;#define ITEM_H&lt;br /&gt;&lt;br /&gt;class SalesTax;&lt;br /&gt;&lt;br /&gt;//This represents the Items which don't have an Import duty or any sales tax &lt;br /&gt;class Item&lt;br /&gt;{&lt;br /&gt;public:&lt;br /&gt;&lt;br /&gt;//Constructors&lt;br /&gt;Item();&lt;br /&gt;Item (SalesTax* aSalesTax);&lt;br /&gt;&lt;br /&gt;//Interface Functions for Item&lt;br /&gt;&lt;br /&gt;//To calculate the price after tax and import duty&lt;br /&gt;virtual void CalculateTotalPrice();&lt;br /&gt;&lt;br /&gt;//To calculate the total tax and import duty&lt;br /&gt;virtual void CalculateTotalTax();&lt;br /&gt;&lt;br /&gt;//To set the price of the Items&lt;br /&gt;void SetPrice(double aPrice);&lt;br /&gt;&lt;br /&gt;//To get the price of the Items before tax&lt;br /&gt;double getPrice();&lt;br /&gt;&lt;br /&gt;//To get the price of the items after tax&lt;br /&gt;double getTotalPrice();&lt;br /&gt;&lt;br /&gt;//To get the total tax and import duty of the items&lt;br /&gt;double getTax();&lt;br /&gt;&lt;br /&gt;//Data&lt;br /&gt;protected:&lt;br /&gt;//Works as the Strategy of the Sales Tax problem.&lt;br /&gt;//If in future the tax calculation becomes more complicated for different Items&lt;br /&gt;//we will just have to change this Strategy. We can also subclass this Strategy class&lt;br /&gt;//for future expansion of the tax calculation strategy&lt;br /&gt;SalesTax* iSalesTax;&lt;br /&gt;//Data&lt;br /&gt;protected:&lt;br /&gt;&lt;br /&gt;//These are the basic properties of any Item.&lt;br /&gt;//Hence these are made protected members so that the subclasses of Item can inherit&lt;br /&gt;//these properties&lt;br /&gt;double iPrice;&lt;br /&gt;double iTotalPrice;&lt;br /&gt;double iTotalTax;&lt;br /&gt;};&lt;br /&gt;&lt;br /&gt;//This class represents the Items which have only Import Duty&lt;br /&gt;class ImportedItem : virtual public Item&lt;br /&gt;{&lt;br /&gt;public:&lt;br /&gt;//Constructors&lt;br /&gt;ImportedItem();&lt;br /&gt;&lt;br /&gt;//This constructor helps to create Items having only Import duty&lt;br /&gt;ImportedItem(SalesTax* aSalesTax, double aImportDuty);&lt;br /&gt;&lt;br /&gt;//Override&lt;br /&gt;virtual void CalculateTotalTax();&lt;br /&gt;&lt;br /&gt;protected:&lt;br /&gt;double iImportDuty;&lt;br /&gt;};&lt;br /&gt;&lt;br /&gt;//This class represents the Items which have only Sales Tax but no Import Duty&lt;br /&gt;class NonFoodBookMedicalItem : virtual public Item&lt;br /&gt;{&lt;br /&gt;public:&lt;br /&gt;//Constructors&lt;br /&gt;NonFoodBookMedicalItem();&lt;br /&gt;&lt;br /&gt;//This constructor helps to create Items having only Sales tax&lt;br /&gt;NonFoodBookMedicalItem(SalesTax* aSalesTax, double aRate);&lt;br /&gt;//Override&lt;br /&gt;virtual void CalculateTotalTax();&lt;br /&gt;&lt;br /&gt;protected:&lt;br /&gt;double iRate;&lt;br /&gt;};&lt;br /&gt;&lt;br /&gt;//This class represents the Items which have got both Import Duty as well as sales Tax&lt;br /&gt;class NormalItem: public ImportedItem, public NonFoodBookMedicalItem&lt;br /&gt;{&lt;br /&gt;public:&lt;br /&gt;NormalItem();&lt;br /&gt;//This constructor helps to create Items having both Sales tax and Import duty&lt;br /&gt;NormalItem(SalesTax* aSalesTax, double aRate, double aImportDuty);&lt;br /&gt;&lt;br /&gt;//Override&lt;br /&gt;virtual void CalculateTotalTax();&lt;br /&gt;};&lt;br /&gt;&lt;br /&gt;#endif&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;As you can see the four classes solve the hierarchy for different items having different benchmark for Sales Tax and import Duty.&lt;br /&gt;&lt;br /&gt;The Item.cpp file looks like the following:&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;File: Item.cpp&lt;/strong&gt;&lt;br /&gt;#include "stdafx.h"&lt;br /&gt;&lt;br /&gt;#include "SalesTax.h"&lt;br /&gt;#include "Item.h"&lt;br /&gt;&lt;br /&gt;Item::Item(){}&lt;br /&gt;&lt;br /&gt;Item::Item(SalesTax* aSalesTax):iSalesTax(aSalesTax),iPrice(0),iTotalPrice(0),iTotalTax(0)&lt;br /&gt;{&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;void Item::CalculateTotalPrice()&lt;br /&gt;{&lt;br /&gt;iTotalPrice = iPrice + iTotalTax;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;double Item::getTotalPrice()&lt;br /&gt;{&lt;br /&gt;return iTotalPrice;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;void Item::CalculateTotalTax()&lt;br /&gt;{&lt;br /&gt;iTotalTax = iSalesTax-&amp;gt;ComputeSalesTax(iPrice, 0, 0);&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;void Item::SetPrice(double aPrice)&lt;br /&gt;{&lt;br /&gt;iPrice = aPrice;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;double Item::getPrice()&lt;br /&gt;{&lt;br /&gt;return iPrice;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;double Item::getTax()&lt;br /&gt;{&lt;br /&gt;return iTotalTax;&lt;br /&gt;}&lt;br /&gt;ImportedItem::ImportedItem(){}&lt;br /&gt;&lt;br /&gt;ImportedItem::ImportedItem(SalesTax* aSalesTax, double aImportDuty):Item(aSalesTax)&lt;br /&gt;{&lt;br /&gt;iImportDuty = aImportDuty;&lt;br /&gt;}&lt;br /&gt;void ImportedItem::CalculateTotalTax()&lt;br /&gt;{&lt;br /&gt;iTotalTax = iSalesTax-&amp;gt;ComputeSalesTax(iPrice, 0, iImportDuty);&lt;br /&gt;&lt;br /&gt;}&lt;br /&gt;NonFoodBookMedicalItem::NonFoodBookMedicalItem(){}&lt;br /&gt;&lt;br /&gt;NonFoodBookMedicalItem::NonFoodBookMedicalItem(SalesTax* aSalesTax, double aRate):Item(aSalesTax)&lt;br /&gt;{&lt;br /&gt;iRate = aRate;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;void NonFoodBookMedicalItem::CalculateTotalTax()&lt;br /&gt;{&lt;br /&gt;iTotalTax = iSalesTax-&amp;gt;ComputeSalesTax(iPrice, iRate, 0);&lt;br /&gt;&lt;br /&gt;}&lt;br /&gt;NormalItem::NormalItem() {}&lt;br /&gt;&lt;br /&gt;NormalItem::NormalItem(SalesTax* aSalesTax, double aRate, double aImportDuty):Item(aSalesTax)&lt;br /&gt;{&lt;br /&gt;iRate = aRate;&lt;br /&gt;iImportDuty = aImportDuty;&lt;br /&gt;}&lt;br /&gt;void NormalItem::CalculateTotalTax()&lt;br /&gt;{&lt;br /&gt;iTotalTax = iSalesTax-&amp;gt;ComputeSalesTax(iPrice, iRate, iImportDuty);&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Now let us concentrate on the Sales Tax class&lt;br /&gt;&lt;br /&gt;file: SalesTax.h&lt;br /&gt;&lt;br /&gt;//This class works as the Strategy of the Sales tax problem&lt;br /&gt;class SalesTax&lt;br /&gt;{&lt;br /&gt;public:&lt;br /&gt;&lt;br /&gt;//Default constructor&lt;br /&gt;SalesTax();&lt;br /&gt;&lt;br /&gt;//This function helps to compute the Sales Tax&lt;br /&gt;virtual double ComputeSalesTax(double aPrice, double aRate, double aImportduty);&lt;br /&gt;&lt;br /&gt;private:&lt;br /&gt;//This is an helper function which will round off the sales tax&lt;br /&gt;double RoundOff(double aTax);&lt;br /&gt;};&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;And the implementation of the Sales tax is as follow:&lt;br /&gt;&lt;br /&gt;file: SalesTax.cpp&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;#include "stdafx.h"&lt;br /&gt;#include "SalesTax.h"&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;SalesTax::SalesTax(){}&lt;br /&gt;&lt;br /&gt;double SalesTax::ComputeSalesTax(double aPrice, double aRate, double aImportduty)&lt;br /&gt;{&lt;br /&gt;double tx = (aPrice*aRate/(double(100))) + (aPrice*aImportduty/(double(100)));&lt;br /&gt;return RoundOff(tx);&lt;br /&gt;}&lt;br /&gt;//private:&lt;br /&gt;double SalesTax::RoundOff(double aTax)&lt;br /&gt;{&lt;br /&gt;int taxTemp = (int)aTax;&lt;br /&gt;&lt;br /&gt;double decimaltaxTemp = (double)(aTax - (int)taxTemp);&lt;br /&gt;&lt;br /&gt;int tempy = (int)(1000*decimaltaxTemp)/100;&lt;br /&gt;&lt;br /&gt;int tempz = (int)(1000*decimaltaxTemp - tempy*100);&lt;br /&gt;&lt;br /&gt;int temp = (int)(tempz/10);&lt;br /&gt;&lt;br /&gt;int t = tempz%10;&lt;br /&gt;&lt;br /&gt;if (t &amp;gt;= 5)&lt;br /&gt;temp+=1;&lt;br /&gt;&lt;br /&gt;return (double)(taxTemp + tempy*(0.1) + temp*(0.01));&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;As you can see the the data for calculation are being passed from the Item class.&lt;br /&gt;&lt;br /&gt;Hence we can say this is in abstract form an implementation of the Strategy Pattern where the Item class is working as the Context and the Sales Tax class is acting as the sole Strategy interface.&lt;br /&gt;&lt;br /&gt;Now lets concentrate on the creation of the Items.&lt;br /&gt;&lt;br /&gt;As i have already mentioned, this is done through a Parameterized factory class called ItemCreator.&lt;br /&gt;&lt;br /&gt;This class looks like the following:&lt;br /&gt;&lt;br /&gt;File: ItemCreator.h&lt;br /&gt;&lt;br /&gt;#include "Item.h"&lt;br /&gt;&lt;br /&gt;const int ITEM_WITH_NOSALESTAX_AND_IMPORTDUTY = 1;&lt;br /&gt;const int ITEM_WITH_NOSALESTAX_ONLY_IMPORTDUTY = 2;&lt;br /&gt;const int ITEM_WITH_ONLY_SALESTAX_AND_NOIMPORTDUTY = 3;&lt;br /&gt;const int ITEM_WITH_BOTH_SALESTAX_AND_IMPORTDUTY = 4;&lt;br /&gt;&lt;br /&gt;const double SALES_TAX_RATE = 10;&lt;br /&gt;const double IMPORT_DUTY_RATE = 5;&lt;br /&gt;&lt;br /&gt;class Not_A_Standard_Item_Type_Exception&lt;br /&gt;{&lt;br /&gt;public:&lt;br /&gt;void printerrormsg();&lt;br /&gt;};&lt;br /&gt;class ItemCreator &lt;br /&gt;{&lt;br /&gt;public:&lt;br /&gt;virtual Item* Create(int aItemId);&lt;br /&gt;&lt;br /&gt;};&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;And the implementation of this ItemCreator is as follow:&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;file: ItemCreator.cpp&lt;br /&gt;&lt;br /&gt;#include "stdafx.h"&lt;br /&gt;#include &lt;iostream&gt;&lt;br /&gt;&lt;br /&gt;#include "ItemCreator.h"&lt;br /&gt;#include "Item.h"&lt;br /&gt;#include "SalesTax.h"&lt;br /&gt;&lt;br /&gt;using namespace std;&lt;br /&gt;&lt;br /&gt;void Not_A_Standard_Item_Type_Exception::printerrormsg()&lt;br /&gt;{&lt;br /&gt;cout (("Not the right Item Type..." ((endl;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;Item* ItemCreator::Create(int aItemId)&lt;br /&gt;{&lt;br /&gt;SalesTax* st = new SalesTax();&lt;br /&gt;&lt;br /&gt;switch(aItemId)&lt;br /&gt;{&lt;br /&gt;case ITEM_WITH_NOSALESTAX_AND_IMPORTDUTY:&lt;br /&gt;return new Item(st);&lt;br /&gt;break;&lt;br /&gt;&lt;br /&gt;case ITEM_WITH_NOSALESTAX_ONLY_IMPORTDUTY:&lt;br /&gt;return new ImportedItem(st,IMPORT_DUTY_RATE);&lt;br /&gt;break;&lt;br /&gt;&lt;br /&gt;case ITEM_WITH_ONLY_SALESTAX_AND_NOIMPORTDUTY:&lt;br /&gt;return new NonFoodBookMedicalItem(st,SALES_TAX_RATE);&lt;br /&gt;break;&lt;br /&gt;&lt;br /&gt;case ITEM_WITH_BOTH_SALESTAX_AND_IMPORTDUTY:&lt;br /&gt;return new NormalItem(st,SALES_TAX_RATE,IMPORT_DUTY_RATE);&lt;br /&gt;break;&lt;br /&gt;&lt;br /&gt;default:&lt;br /&gt;throw Not_A_Standard_Item_Type_Exception();&lt;br /&gt;}&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;And the client program will look like the following:&lt;br /&gt;&lt;br /&gt;#include "stdafx.h"&lt;br /&gt;&lt;br /&gt;#include "SalesTax.h"&lt;br /&gt;#include "Item.h"&lt;br /&gt;#include "ItemCreator.h"&lt;br /&gt;&lt;br /&gt;#include (vector)&amp;nbsp;&lt;iostream&gt;&lt;br /&gt;#include &lt;vector&gt;&lt;br /&gt;&lt;br /&gt;using namespace std;&lt;br /&gt;&lt;br /&gt;void main()&lt;br /&gt;{&lt;br /&gt;typedef vector(Item*)&amp;nbsp;&lt;item*&gt; listOfItem; &lt;br /&gt;listOfItem::iterator theIterator;&lt;br /&gt;&lt;br /&gt;listOfItem Basket;&lt;br /&gt;char answer = 'n';&lt;br /&gt;&lt;br /&gt;double totalprice = 0;&lt;br /&gt;double totaltax = 0;&lt;br /&gt;&lt;br /&gt;do&lt;br /&gt;{&lt;br /&gt;int type_of_item;&lt;br /&gt;&lt;br /&gt;cout (("Enter the type of Item...1,2,3,4" ((endl;&lt;br /&gt;&lt;br /&gt;cout (("1 for ITEM_WITH_NOSALESTAX_AND_NOIMPORTDUTY" ((endl;&lt;br /&gt;&lt;br /&gt;cout (("2 for ITEM_WITH_NOSALESTAX_ONLY_IMPORTDUTY" ((endl;&lt;br /&gt;&lt;br /&gt;cout (("3 for ITEM_WITH_ONLY_SALESTAX_AND_NOIMPORTDUTY" ((endl;&lt;br /&gt;&lt;br /&gt;cout (("4 for ITEM_WITH_BOTH_SALESTAX_AND_IMPORTDUTY" ((endl;&lt;br /&gt;&lt;br /&gt;cin ))type_of_item;&lt;br /&gt;&lt;br /&gt;ItemCreator* itemCreator = new ItemCreator();&lt;br /&gt;&lt;br /&gt;try &lt;br /&gt;{&lt;br /&gt;Item* item = itemCreator-&amp;gt;Create(type_of_item);&lt;br /&gt;&lt;br /&gt;cout (("Enter the price of the Item" ((endl;&lt;br /&gt;&lt;br /&gt;double price;&lt;br /&gt;&lt;br /&gt;cin ))price;&lt;br /&gt;&lt;br /&gt;item-&amp;gt;SetPrice(price);&lt;br /&gt;&lt;br /&gt;Basket.push_back(item);&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;catch(Not_A_Standard_Item_Type_Exception&amp;amp; e)&lt;br /&gt;{&lt;br /&gt;e.printerrormsg();&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;cout (("Do you want to continue... Y/N" ((endl;&lt;br /&gt;cin ))answer;&lt;br /&gt;}&lt;br /&gt;while (answer =='y');&lt;br /&gt;&lt;br /&gt;theIterator = Basket.begin();&lt;br /&gt;&lt;br /&gt;int pos = 0;&lt;br /&gt;while (theIterator != Basket.end())&lt;br /&gt;{&lt;br /&gt;Basket.at(pos)-&amp;gt;CalculateTotalTax();&lt;br /&gt;totaltax+=Basket.at(pos)-&amp;gt;getTax();&lt;br /&gt;&lt;br /&gt;Basket.at(pos)-&amp;gt;CalculateTotalPrice();&lt;br /&gt;&lt;br /&gt;double price = Basket.at(pos)-&amp;gt;getPrice();&lt;br /&gt;&lt;br /&gt;double price_after_tax = Basket.at(pos)-&amp;gt;getTotalPrice();&lt;br /&gt;&lt;br /&gt;totalprice+=price_after_tax;&lt;br /&gt;&lt;br /&gt;cout (("Item" ((pos+1 ((" price " ((price ((endl;&lt;br /&gt;theIterator++;&lt;br /&gt;pos++; &lt;br /&gt;}&lt;br /&gt;cout (("------------" ((endl;&lt;br /&gt;cout (("Toal tax " ((totaltax ((endl;&lt;br /&gt;cout (("Total price " ((totalprice ((endl;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Thus the problem is solved using two common design pattern concepts - Strategy Pattern and Parameterized Factory Pattern.&lt;br /&gt;&lt;br /&gt;This is the way i am trying to move from the problem domain to the solution domain using design pattern concepts.&lt;br /&gt;&lt;br /&gt;Hope this helps others who are studying Design Pattern.&lt;/item*&gt;&lt;/vector&gt;&lt;/iostream&gt;&lt;/iostream&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3946478681282550454-6966451191242041854?l=som-itsolutions.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://som-itsolutions.blogspot.com/feeds/6966451191242041854/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=3946478681282550454&amp;postID=6966451191242041854' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3946478681282550454/posts/default/6966451191242041854'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3946478681282550454/posts/default/6966451191242041854'/><link rel='alternate' type='text/html' href='http://som-itsolutions.blogspot.com/2009/11/experimentation-with-design-pattern.html' title='Experimentation with Design Pattern'/><author><name>Som</name><uri>http://www.blogger.com/profile/09519633424407534012</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='24' src='http://3.bp.blogspot.com/-XVhL110Tyf8/ThxKF3DBYcI/AAAAAAAAEBo/arVXUPsgtSg/s220/NJ%2B042.JPG'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3946478681282550454.post-4191076337349676619</id><published>2009-11-09T08:27:00.007+05:30</published><updated>2010-06-05T04:42:24.716+05:30</updated><title type='text'>My first experience with Ubuntu Karmic kola</title><content type='html'>I felt very excited after i read the review comments about Ubuntu 9.1, the Karmic Kola distribution of Ubuntu... However with over enthusiasm i could not wait for the official release... I downloaded the release candidate few days before the official release of Ubuntu 9.1...&lt;br /&gt;&lt;br /&gt;As i have used only Windows so far, i was a bit worried about my transition to Ubuntu... However, so far it was smooth...&lt;br /&gt;&lt;br /&gt;After downloading the release candidate of the Ubuntu 9.1, i had to burn the CD... I used ImgBurn to do that... What one needs is a blank 700 MB writable CD... The burning process did not take much time...&lt;br /&gt;&lt;br /&gt;Then with caution i inserted the CD for the installation... The installation got started... And it hardly took 20 minutes to completely install it...&lt;br /&gt;&lt;br /&gt;I restarted my computer... There were two options to boot up - one for my old Windows XP and the other was Ubuntu... I chose the second one... The log in screen came in no time... i entered my password... And voila... The system came up within a flash... I thought i need to do lot of configuration for my internet connection... To test it i just clicked the firefox menu on the top of the desktop... And no wonder, the Ubuntu Google came up in a flash...&lt;br /&gt;&lt;br /&gt;I was delighted...&lt;br /&gt;&lt;br /&gt;With a little help through googling, i found that for a developer, the build essential package is a must... After that i did a research and found the Synaptic Package Manager Under System.. i opened it... Searched for build essential... Marked it... And installed it...&lt;br /&gt;&lt;br /&gt;Then i installed Git... And Eclipse... And yesterday i installed QTCreator IDE... And the development environment is ready...&lt;br /&gt;&lt;br /&gt;I started gaining interest in Linux because i wanted to compile the Android source code... so far my experience with Ubuntu is very good... its update manager is working for me...The synaptic package manager is fantastic...&lt;br /&gt;&lt;br /&gt;I installed HPLIP... However i could not set up my HP 656C printer... Its saying the driver is different... I hope even that will be sorted out within a couple of weeks...&lt;br /&gt;&lt;br /&gt;I can say that for me its been a smooth transition to Ubuntu...And the best part is that neither i  had to install SpyBot... nor do i have to scan with SpyWare doctor every time i start my PC...and of course i don't have to care about Malwarebytes to fight against virtumunde...&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3946478681282550454-4191076337349676619?l=som-itsolutions.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://som-itsolutions.blogspot.com/feeds/4191076337349676619/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=3946478681282550454&amp;postID=4191076337349676619' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3946478681282550454/posts/default/4191076337349676619'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3946478681282550454/posts/default/4191076337349676619'/><link rel='alternate' type='text/html' href='http://som-itsolutions.blogspot.com/2009/11/my-first-time-experience-with-ubuntu.html' title='My first experience with Ubuntu Karmic kola'/><author><name>Som</name><uri>http://www.blogger.com/profile/09519633424407534012</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='24' src='http://3.bp.blogspot.com/-XVhL110Tyf8/ThxKF3DBYcI/AAAAAAAAEBo/arVXUPsgtSg/s220/NJ%2B042.JPG'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3946478681282550454.post-5061525624057450503</id><published>2009-10-10T06:06:00.000+05:30</published><updated>2009-10-20T20:10:01.120+05:30</updated><title type='text'>WiFi Subsystem in Android</title><content type='html'>As i was trying to understand the WiFi subsystem of Android i came out with a diagram to depict the flow of events between different functional blocks of it. I would like to share it with you.&lt;br /&gt;&lt;br /&gt;It goes like this:&lt;br /&gt;&lt;br /&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://3.bp.blogspot.com/_PnYnrngiRvA/Ss_X1CbZMHI/AAAAAAAACB8/0HMKOyEc5dQ/s1600-h/2.JPG"&gt;&lt;img style="display:block; margin:0px auto 10px; text-align:center;cursor:pointer; cursor:hand;width: 320px; height: 197px;" src="http://3.bp.blogspot.com/_PnYnrngiRvA/Ss_X1CbZMHI/AAAAAAAACB8/0HMKOyEc5dQ/s320/2.JPG" border="0" alt=""id="BLOGGER_PHOTO_ID_5390764585170579570" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;Hope it will help the Android developers' community.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3946478681282550454-5061525624057450503?l=som-itsolutions.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://som-itsolutions.blogspot.com/feeds/5061525624057450503/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=3946478681282550454&amp;postID=5061525624057450503' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3946478681282550454/posts/default/5061525624057450503'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3946478681282550454/posts/default/5061525624057450503'/><link rel='alternate' type='text/html' href='http://som-itsolutions.blogspot.com/2009/10/wifi-subsystem-in-android.html' title='WiFi Subsystem in Android'/><author><name>Som</name><uri>http://www.blogger.com/profile/09519633424407534012</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='24' src='http://3.bp.blogspot.com/-XVhL110Tyf8/ThxKF3DBYcI/AAAAAAAAEBo/arVXUPsgtSg/s220/NJ%2B042.JPG'/></author><media:thumbnail xmlns:media='http://search.yahoo.com/mrss/' url='http://3.bp.blogspot.com/_PnYnrngiRvA/Ss_X1CbZMHI/AAAAAAAACB8/0HMKOyEc5dQ/s72-c/2.JPG' height='72' width='72'/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3946478681282550454.post-6538175902088656574</id><published>2009-10-08T17:07:00.000+05:30</published><updated>2009-10-08T17:11:15.632+05:30</updated><title type='text'>Tabs in Android - through an example</title><content type='html'>As i was trying to experiment with the different widgets of Android, i developed this example to show how Tab works in Android.&lt;br /&gt;&lt;br /&gt;And the application looks like the following:&lt;br /&gt;&lt;br /&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://3.bp.blogspot.com/_PnYnrngiRvA/Ss3PcDn36xI/AAAAAAAACBs/nDhF_gZfbnw/s1600-h/1.JPG"&gt;&lt;img style="display:block; margin:0px auto 10px; text-align:center;cursor:pointer; cursor:hand;width: 320px; height: 261px;" src="http://3.bp.blogspot.com/_PnYnrngiRvA/Ss3PcDn36xI/AAAAAAAACBs/nDhF_gZfbnw/s320/1.JPG" border="0" alt=""id="BLOGGER_PHOTO_ID_5390192409948187410" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;And the next tab looks like:&lt;br /&gt;&lt;br /&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://3.bp.blogspot.com/_PnYnrngiRvA/Ss3PlprFstI/AAAAAAAACB0/-f_CsRsMx_8/s1600-h/2.JPG"&gt;&lt;img style="display:block; margin:0px auto 10px; text-align:center;cursor:pointer; cursor:hand;width: 320px; height: 261px;" src="http://3.bp.blogspot.com/_PnYnrngiRvA/Ss3PlprFstI/AAAAAAAACB0/-f_CsRsMx_8/s320/2.JPG" border="0" alt=""id="BLOGGER_PHOTO_ID_5390192574781043410" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;The first thing we need to to do is working on the XML layout.&lt;br /&gt;&lt;br /&gt;The XML code of the layout my example is as follows:&lt;br /&gt;&lt;br /&gt;(?xml version="1.0" encoding="utf-8"?)&lt;br /&gt;(LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"&lt;br /&gt;    android:orientation="vertical"&lt;br /&gt;    android:layout_width="fill_parent"&lt;br /&gt;    android:layout_height="fill_parent"&lt;br /&gt;    )&lt;br /&gt;&lt;br /&gt;(TabHost android:id="@+id/TabHost01" android:layout_width="wrap_content" android:layout_height="wrap_content")&lt;br /&gt;(TabWidget android:id="@android:id/tabs" android:layout_width="wrap_content" android:layout_height="wrap_content" /)&lt;br /&gt;(FrameLayout android:id="@android:id/tabcontent" android:layout_width="wrap_content" android:layout_height="wrap_content" android:paddingTop="65px")&lt;br /&gt;(AnalogClock android:id="@+id/AnalogClock01" android:layout_width="wrap_content" android:layout_height="wrap_content")(/AnalogClock)&lt;br /&gt;(DigitalClock android:text="DigitalClock01" android:id="@+id/DigitalClock01" android:layout_width="wrap_content" android:layout_height="wrap_content")(/DigitalClock)&lt;br /&gt;(/FrameLayout)&lt;br /&gt;(/TabHost)&lt;br /&gt;(/LinearLayout)&lt;br /&gt;&lt;br /&gt;And the Java code for this example is as follws:&lt;br /&gt;&lt;br /&gt;import android.app.Activity;&lt;br /&gt;import android.os.Bundle;&lt;br /&gt;import android.widget.TabHost;&lt;br /&gt;&lt;br /&gt;public class tabexample extends Activity {&lt;br /&gt;    /** Called when the activity is first created. */&lt;br /&gt;    @Override&lt;br /&gt;    public void onCreate(Bundle savedInstanceState) {&lt;br /&gt;        super.onCreate(savedInstanceState);&lt;br /&gt;        setContentView(R.layout.main);&lt;br /&gt;        &lt;br /&gt;        TabHost tabs = (TabHost)findViewById(R.id.TabHost01);&lt;br /&gt;        &lt;br /&gt;        tabs.setup();&lt;br /&gt;        &lt;br /&gt;        TabHost.TabSpec spec1 = tabs.newTabSpec("tag1");&lt;br /&gt;        &lt;br /&gt;        spec1.setContent(R.id.AnalogClock01);&lt;br /&gt;        spec1.setIndicator("Analog Clock");&lt;br /&gt;        &lt;br /&gt;        tabs.addTab(spec1);&lt;br /&gt;        &lt;br /&gt;        TabHost.TabSpec spec2 = tabs.newTabSpec("tag2");&lt;br /&gt;        spec2.setContent(R.id.DigitalClock01);&lt;br /&gt;        spec2.setIndicator("Digital Clock");&lt;br /&gt;        &lt;br /&gt;        tabs.addTab(spec2);&lt;br /&gt;    }&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;Hope this helps the newcomers of Android...&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3946478681282550454-6538175902088656574?l=som-itsolutions.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://som-itsolutions.blogspot.com/feeds/6538175902088656574/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=3946478681282550454&amp;postID=6538175902088656574' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3946478681282550454/posts/default/6538175902088656574'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3946478681282550454/posts/default/6538175902088656574'/><link rel='alternate' type='text/html' href='http://som-itsolutions.blogspot.com/2009/10/tabs-in-android-through-example.html' title='Tabs in Android - through an example'/><author><name>Som</name><uri>http://www.blogger.com/profile/09519633424407534012</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='24' src='http://3.bp.blogspot.com/-XVhL110Tyf8/ThxKF3DBYcI/AAAAAAAAEBo/arVXUPsgtSg/s220/NJ%2B042.JPG'/></author><media:thumbnail xmlns:media='http://search.yahoo.com/mrss/' url='http://3.bp.blogspot.com/_PnYnrngiRvA/Ss3PcDn36xI/AAAAAAAACBs/nDhF_gZfbnw/s72-c/1.JPG' height='72' width='72'/><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3946478681282550454.post-7985956929839043977</id><published>2009-08-15T23:34:00.000+05:30</published><updated>2009-10-08T05:38:49.504+05:30</updated><title type='text'>Inter Process Communication in Android through Intent</title><content type='html'>In Android, one of the nice ways for passing data between different processes is through the help of Intent. In the following example i have tried to explain it by two different applications. One application is called the IntentSupplier. This is started from another application called IntentExample. The application IntentSupplier passes some string data to the IntentExample app through the help of an Intent object which the IntentSupplier application displays in a message box.&lt;br /&gt;&lt;br /&gt;The IntentSupplier application looks like the following.&lt;br /&gt;&lt;br /&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://2.bp.blogspot.com/_PnYnrngiRvA/Sob5LICBsPI/AAAAAAAACBE/rz4XuObPavU/s1600-h/1.JPG"&gt;&lt;img style="display:block; margin:0px auto 10px; text-align:center;cursor:pointer; cursor:hand;width: 320px; height: 263px;" src="http://2.bp.blogspot.com/_PnYnrngiRvA/Sob5LICBsPI/AAAAAAAACBE/rz4XuObPavU/s320/1.JPG" border="0" alt=""id="BLOGGER_PHOTO_ID_5370253575215755506" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;When we click one of the buttons it passes its string data to the IntentExample which looks like the following.&lt;br /&gt;&lt;br /&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://2.bp.blogspot.com/_PnYnrngiRvA/Sob5ZCcB9uI/AAAAAAAACBM/Uo_86j-3FT0/s1600-h/2.JPG"&gt;&lt;img style="display:block; margin:0px auto 10px; text-align:center;cursor:pointer; cursor:hand;width: 320px; height: 262px;" src="http://2.bp.blogspot.com/_PnYnrngiRvA/Sob5ZCcB9uI/AAAAAAAACBM/Uo_86j-3FT0/s320/2.JPG" border="0" alt=""id="BLOGGER_PHOTO_ID_5370253814232381154" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;The source code for IntentSupplier is as follows:&lt;br /&gt;&lt;br /&gt;package android.training.intentsupplier;&lt;br /&gt;&lt;br /&gt;import android.app.Activity;&lt;br /&gt;import android.content.Intent;&lt;br /&gt;import android.os.Bundle;&lt;br /&gt;import android.view.View;&lt;br /&gt;import android.view.View.OnClickListener;&lt;br /&gt;import android.widget.Button;&lt;br /&gt;&lt;br /&gt;public class IntentSupplier extends Activity {&lt;br /&gt;    &lt;br /&gt;&lt;br /&gt;/** Called when the activity is first created. */&lt;br /&gt;    @Override&lt;br /&gt;    public void onCreate(Bundle savedInstanceState) {&lt;br /&gt;        super.onCreate(savedInstanceState);&lt;br /&gt;        setContentView(R.layout.main);&lt;br /&gt;        &lt;br /&gt;        Button button1 = (Button)findViewById(R.id.Button01);&lt;br /&gt;        &lt;br /&gt;        Button button2 = (Button)findViewById(R.id.Button02);&lt;br /&gt;        &lt;br /&gt;        button1.setOnClickListener(onClickButton1);&lt;br /&gt;        button2.setOnClickListener(onClickButton2);&lt;br /&gt;        &lt;br /&gt;    }&lt;br /&gt;   &lt;br /&gt;    private OnClickListener onClickButton1 = new OnClickListener() {&lt;br /&gt;    &lt;br /&gt;     public void onClick(View v){&lt;br /&gt;    &lt;br /&gt;      if (v.getId() == R.id.Button01){&lt;br /&gt;    &lt;br /&gt;      returnResult("Message1 coming from IntentSupplier");&lt;br /&gt;      }&lt;br /&gt;     }&lt;br /&gt;    };&lt;br /&gt;    &lt;br /&gt;private OnClickListener onClickButton2 = new OnClickListener() {&lt;br /&gt;    &lt;br /&gt;     public void onClick(View v){&lt;br /&gt;    &lt;br /&gt;      if (v.getId() == R.id.Button02){&lt;br /&gt;    &lt;br /&gt;      returnResult("Message2 coming from IntentSupplier");&lt;br /&gt;      }&lt;br /&gt;     }&lt;br /&gt;    };&lt;br /&gt;    &lt;br /&gt;    void returnResult(String msg) {&lt;br /&gt;    &lt;br /&gt;     Intent i = new Intent();&lt;br /&gt;    &lt;br /&gt;     i.putExtra("android.training.intentsupplier.resultfromintentsupplier", msg);&lt;br /&gt;    &lt;br /&gt;     setResult(RESULT_OK, i);&lt;br /&gt;    &lt;br /&gt;     finish();&lt;br /&gt;    }&lt;br /&gt;    &lt;br /&gt;}  &lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Look at the function&lt;br /&gt;&lt;br /&gt;void returnResult(String msg).&lt;br /&gt;&lt;br /&gt;Here at the line  i.putExtra("android.training.intentsupplier.resultfromintentsupplier", msg), we are basically parceling the data (msg) and giving it a label called resultfromintentsupplier. Please see how the package info is prefixed with this label.&lt;br /&gt;&lt;br /&gt;The source code for the IntentExample is as follows:&lt;br /&gt;&lt;br /&gt;package android.training.intentexample;&lt;br /&gt;&lt;br /&gt;import android.app.Activity;&lt;br /&gt;import android.app.AlertDialog;&lt;br /&gt;import android.content.ActivityNotFoundException;&lt;br /&gt;import android.content.DialogInterface;&lt;br /&gt;import android.content.Intent;&lt;br /&gt;import android.os.Bundle;&lt;br /&gt;import android.util.Log;&lt;br /&gt;&lt;br /&gt;public class IntentExample extends Activity {&lt;br /&gt;    &lt;br /&gt;static final int REQUEST_CODE = 1001;&lt;br /&gt;&lt;br /&gt;/** Called when the activity is first created. */&lt;br /&gt;    @Override&lt;br /&gt;    public void onCreate(Bundle savedInstanceState) {&lt;br /&gt;        super.onCreate(savedInstanceState);&lt;br /&gt;        &lt;br /&gt;        setContentView(R.layout.main);&lt;br /&gt;        &lt;br /&gt;        Intent getMessageFromIntentSupplier = new Intent();&lt;br /&gt;        &lt;br /&gt;        getMessageFromIntentSupplier.setClassName("android.training.intentsupplier", "android.training.intentsupplier.IntentSupplier");&lt;br /&gt;        &lt;br /&gt;        getMessageFromIntentSupplier.setAction("android.training.intentsupplier.android.intent.action.INTENTSUPPLIERTEST");&lt;br /&gt;        &lt;br /&gt;        getMessageFromIntentSupplier.addCategory("CATEGORY_DEFAULT");&lt;br /&gt;        &lt;br /&gt;        getMessageFromIntentSupplier.setType("vnd.example.greeting/vnd.example.greeting-text");&lt;br /&gt;        &lt;br /&gt;        try {&lt;br /&gt;         startActivityForResult(getMessageFromIntentSupplier,REQUEST_CODE);&lt;br /&gt;        &lt;br /&gt;        }&lt;br /&gt;        &lt;br /&gt;        catch(ActivityNotFoundException e) {&lt;br /&gt;         Log.e("IntentExample", "Activity could not be started...");&lt;br /&gt;        } &lt;br /&gt;        &lt;br /&gt;        }     &lt;br /&gt;    }&lt;br /&gt;    &lt;br /&gt;    public void onActivityResult(int requestcode, int resultcode, Intent result ) {&lt;br /&gt;    &lt;br /&gt;     if(requestcode == REQUEST_CODE){&lt;br /&gt;    if(resultcode == RESULT_OK){&lt;br /&gt;     message = result.getStringExtra("android.training.intentsupplier.resultfromintentsupplier");&lt;br /&gt;   &lt;br /&gt;     new AlertDialog.Builder(this)&lt;br /&gt;     .setTitle("Msg from Intent Supplier")&lt;br /&gt;     .setMessage(message)&lt;br /&gt;     .setNeutralButton("Close", new DialogInterface.OnClickListener() {&lt;br /&gt;     public void onClick(DialogInterface dlg, int sumthin) {&lt;br /&gt;     // do nothing – it will close on its own&lt;br /&gt;     }&lt;br /&gt;     })&lt;br /&gt;     .show(); &lt;br /&gt;    }&lt;br /&gt;     }&lt;br /&gt;    }&lt;br /&gt;    &lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;The AndroidManifest.xml file of the IntentSupplier application looks like the following:&lt;br /&gt;&lt;br /&gt;(** Please replace the "(" &amp; ")" brackets with the angular brackets to xmlize the file contents) &lt;br /&gt;&lt;br /&gt;(?xml version="1.0" encoding="utf-8"?)&lt;br /&gt;(manifest xmlns:android="http://schemas.android.com/apk/res/android"&lt;br /&gt;      package="android.training.intentsupplier"&lt;br /&gt;      android:versionCode="1"&lt;br /&gt;      android:versionName="1.0")&lt;br /&gt;    (application android:icon="@drawable/icon" android:label="@string/app_name")&lt;br /&gt;        (activity android:name=".IntentSupplier"&lt;br /&gt;                  android:label="@string/app_name")&lt;br /&gt;           &lt;br /&gt;           (intent-filter)&lt;br /&gt;                (action android:name="android.intent.action.MAIN" /)&lt;br /&gt;                (category android:name="android.intent.category.LAUNCHER" /)&lt;br /&gt;            (/intent-filter)&lt;br /&gt;            &lt;br /&gt;            (intent-filter)&lt;br /&gt;                (action android:name="android.intent.action.INTENTSUPPLIERTEST" /)&lt;br /&gt;                (category android:name="android.intent.category.DEFAULT" /)&lt;br /&gt;                (data android:mimeType="vnd.example.greeting/vnd.example.greeting-text" /)&lt;br /&gt;            (/intent-filter)&lt;br /&gt;        (/activity)&lt;br /&gt;    (/application)&lt;br /&gt;    (uses-sdk android:minSdkVersion="3" /)&lt;br /&gt;(/manifest) &lt;br /&gt;&lt;br /&gt;The main.xml file of the IntentSupplier application looks like the following:&lt;br /&gt;&lt;br /&gt;(?xml version="1.0" encoding="utf-8"?)&lt;br /&gt;(LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"&lt;br /&gt;    android:orientation="vertical"&lt;br /&gt;    android:layout_width="fill_parent"&lt;br /&gt;    android:layout_height="fill_parent"&lt;br /&gt;    )&lt;br /&gt;(TextView  &lt;br /&gt;    android:layout_width="fill_parent" &lt;br /&gt;    android:layout_height="wrap_content" &lt;br /&gt;    android:text="@string/hello"&lt;br /&gt;    /)&lt;br /&gt;(Button android:text="Message1" android:id="@+id/Button01" android:layout_width="fill_parent" android:layout_height="wrap_content")(/Button)&lt;br /&gt;(Button android:text="Message2" android:id="@+id/Button02" android:layout_width="fill_parent" android:layout_height="wrap_content")(/Button)&lt;br /&gt;(/LinearLayout)&lt;br /&gt;&lt;br /&gt;In this example we have started the IntentSupplier app through the function startActivityForResult. It then waits for the result from the child activity, and once the result arrives, the callback function onActivityResult is called. in this function we extract the data sent from the child activity (by using the function getStringExtra) and show it in a message box.&lt;br /&gt;&lt;br /&gt;To run this application we need to run once the IntentSupplier application first.&lt;br /&gt;&lt;br /&gt;Hope this discussion becomes helpful for the newbies of Android.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3946478681282550454-7985956929839043977?l=som-itsolutions.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://som-itsolutions.blogspot.com/feeds/7985956929839043977/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=3946478681282550454&amp;postID=7985956929839043977' title='2 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3946478681282550454/posts/default/7985956929839043977'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3946478681282550454/posts/default/7985956929839043977'/><link rel='alternate' type='text/html' href='http://som-itsolutions.blogspot.com/2009/08/in-android-one-of-nice-ways-for-passing.html' title='Inter Process Communication in Android through Intent'/><author><name>Som</name><uri>http://www.blogger.com/profile/09519633424407534012</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='24' src='http://3.bp.blogspot.com/-XVhL110Tyf8/ThxKF3DBYcI/AAAAAAAAEBo/arVXUPsgtSg/s220/NJ%2B042.JPG'/></author><media:thumbnail xmlns:media='http://search.yahoo.com/mrss/' url='http://2.bp.blogspot.com/_PnYnrngiRvA/Sob5LICBsPI/AAAAAAAACBE/rz4XuObPavU/s72-c/1.JPG' height='72' width='72'/><thr:total>2</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3946478681282550454.post-8381607602336989427</id><published>2009-07-05T21:28:00.000+05:30</published><updated>2009-07-06T19:40:50.752+05:30</updated><title type='text'>My first time experience with Android Webkit</title><content type='html'>As I was trying to play around with WebKit, I tried to load an web page through it in Android. A good starting point for WebKit may be found at &lt;br /&gt;&lt;br /&gt;&lt;a href="http://developer.apple.com/documentation/Cocoa/Conceptual/DisplayWebContent/DisplayWebContent.html"&gt;http://developer.apple.com/documentation/Cocoa/Conceptual/DisplayWebContent/DisplayWebContent.html&lt;/a&gt; . &lt;br /&gt;&lt;br /&gt;The source code of my android application is pretty straight forward.&lt;br /&gt;&lt;br /&gt;It goes like this:&lt;br /&gt;&lt;br /&gt;  public class WebKitExample extends Activity {&lt;br /&gt;    /** Called when the activity is first created. */&lt;br /&gt;    @Override&lt;br /&gt;    public void onCreate(Bundle savedInstanceState) {&lt;br /&gt;        super.onCreate(savedInstanceState);&lt;br /&gt;        &lt;br /&gt;        WebView webView;&lt;br /&gt;    &lt;br /&gt;        setContentView(R.layout.main);&lt;br /&gt;        &lt;br /&gt;        webView = (WebView)findViewById(R.id.appView);&lt;br /&gt;        &lt;br /&gt;        webView.getSettings().setJavaScriptEnabled(true);&lt;br /&gt;&lt;br /&gt;        webView.loadUrl("http://www.google.com");&lt;br /&gt;    }&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;We need to add the XML resource in the main.layout as the following:&lt;br /&gt;&lt;br /&gt;(WebView android:id="@+id/appView"&lt;br /&gt;            android:layout_height="wrap_content"&lt;br /&gt;            android:layout_width="fill_parent" /)&lt;br /&gt;&lt;br /&gt;We also need to add the permission to the manifest file as the following:&lt;br /&gt;&lt;br /&gt;(uses-permission android:name = "android.permission.INTERNET" /)&lt;br /&gt;&lt;br /&gt;And the application will look like the following in the emulator.&lt;br /&gt;&lt;br /&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://3.bp.blogspot.com/_PnYnrngiRvA/SlDOL-ttekI/AAAAAAAACAg/81nWvdOShKk/s1600-h/1.JPG"&gt;&lt;img style="display:block; margin:0px auto 10px; text-align:center;cursor:pointer; cursor:hand;width: 181px; height: 320px;" src="http://3.bp.blogspot.com/_PnYnrngiRvA/SlDOL-ttekI/AAAAAAAACAg/81nWvdOShKk/s320/1.JPG" border="0" alt=""id="BLOGGER_PHOTO_ID_5355006662152124994" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;Although the example shown here is pretty simple but it can be a starting point in  learning Webkit in Android. Hope this helps the newbies of Android.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3946478681282550454-8381607602336989427?l=som-itsolutions.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://som-itsolutions.blogspot.com/feeds/8381607602336989427/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=3946478681282550454&amp;postID=8381607602336989427' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3946478681282550454/posts/default/8381607602336989427'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3946478681282550454/posts/default/8381607602336989427'/><link rel='alternate' type='text/html' href='http://som-itsolutions.blogspot.com/2009/07/my-first-time-experience-with-webkit.html' title='My first time experience with Android Webkit'/><author><name>Som</name><uri>http://www.blogger.com/profile/09519633424407534012</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='24' src='http://3.bp.blogspot.com/-XVhL110Tyf8/ThxKF3DBYcI/AAAAAAAAEBo/arVXUPsgtSg/s220/NJ%2B042.JPG'/></author><media:thumbnail xmlns:media='http://search.yahoo.com/mrss/' url='http://3.bp.blogspot.com/_PnYnrngiRvA/SlDOL-ttekI/AAAAAAAACAg/81nWvdOShKk/s72-c/1.JPG' height='72' width='72'/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3946478681282550454.post-1790319830907903206</id><published>2009-06-20T10:32:00.000+05:30</published><updated>2009-06-23T06:03:48.735+05:30</updated><title type='text'>The flow of events during the Media Player Creation in Android Framework</title><content type='html'>The flow of events of the Android media player is complex. Moreover as i don't have a Linux machine, i have to depend on the careful study of the framework source code. i think i have got a strong enough reason to buy an Ubuntu machine.&lt;br /&gt;&lt;br /&gt;Lets come to the fact findings. There are two sides of the Android Media Framework. What we as an user see is the Java interface which is called the Mediaplayer.java. However, this java interface interacts with a native mediaplayer object through Java Native Interface (JNI) mechanism. This interaction is done through the functionalities defined in &lt;span style="font-weight:bold;"&gt;Android_media_Mediaplayer.cpp&lt;/span&gt;. In this file the framework engineers have kept all the necessary JNI functions.&lt;br /&gt;&lt;br /&gt;Now when we are about to start the MediaPlayer, the JNI function that is called is the &lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight:bold;"&gt;private native final void native_setup&lt;/span&gt;.&lt;br /&gt;&lt;br /&gt;This function is actually responsible for creating a C++ mediaplayer object in the native side and storing an opaque reference to it in the Java client side. So when we interact with the client side Java mediaplayer object, we internally interact with this native C++ object.&lt;br /&gt;&lt;br /&gt;The JNI layer actually delegates its task to a Mediaplayer object. The functionalities of this C++ class are defined in the file &lt;span style="font-weight:bold;"&gt;Mediaplayer.cpp&lt;/span&gt;.&lt;br /&gt;&lt;br /&gt;Now the next step is that we set a data source in the Java side using the function setDataSource function in which the URI of the data source is passed. This in turn calls the native function  &lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight:bold;"&gt;android_media_MediaPlayer_setDataSource(JNIEnv *env, jobject thiz, jstring path)&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;In the native source, this function is defined as &lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight:bold;"&gt;android_media_MediaPlayer_setDataSource(JNIEnv *env, jobject thiz, jstring path)&lt;/span&gt;&lt;br /&gt; {&lt;br /&gt;    sp(MediaPlayer) mp = getMediaPlayer(env, thiz);&lt;br /&gt;    ........&lt;br /&gt;    ........&lt;br /&gt;&lt;br /&gt;    ........&lt;br /&gt;    ........&lt;br /&gt;    status_t opStatus = mp-&gt;setDataSource(pathStr);&lt;br /&gt;&lt;br /&gt;    process_media_player_call( env, thiz, opStatus, "java/io/IOException",   "setDataSource failed." );&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;Look at the line :&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight:bold;"&gt;status_t opStatus = mp-&gt;setDataSource(pathStr);&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;This function is defined as&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight:bold;"&gt;status_t MediaPlayer::setDataSource(const char *url)&lt;/span&gt;&lt;br /&gt;{&lt;br /&gt;    ......&lt;br /&gt;    ......&lt;br /&gt;&lt;br /&gt;    if (url != NULL) {&lt;br /&gt;        const sp(IMediaPlayerService)&amp; service(getMediaPlayerService());&lt;br /&gt;        if (service != 0) {&lt;br /&gt;            sp(IMediaPlayer) player(service-&gt;create(getpid(), this, url));&lt;br /&gt;            err = setDataSource(player);&lt;br /&gt;        }&lt;br /&gt;    }&lt;br /&gt;    return err;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;Look at the line :&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight:bold;"&gt;sp(IMediaPlayer) player(service-&gt;create(getpid(), this, url));&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;It actually takes the help of the IMediaPlayerservice layer and calls the create function on this. This function can be found in &lt;span style="font-weight:bold;"&gt;\\base\media\libmedia\IMediaPlayerService.cpp&lt;/span&gt; file.&lt;br /&gt;&lt;br /&gt;The create function of the MediaPlayerService looks like the following. &lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight:bold;"&gt;sp&lt;IMediaPlayer&gt; MediaPlayerService::create(pid_t pid, const sp(IMediaPlayerClient)&amp; client, const char* url)&lt;/span&gt;&lt;br /&gt;{&lt;br /&gt;    .....&lt;br /&gt;&lt;br /&gt;    sp(Client) c = new Client(this, pid, connId, client);&lt;br /&gt;&lt;br /&gt;    .....&lt;br /&gt;   &lt;br /&gt;    .....&lt;br /&gt;&lt;br /&gt;    if (NO_ERROR != c-&gt;setDataSource(url))&lt;br /&gt;    {&lt;br /&gt;        c.clear();&lt;br /&gt;        return c;&lt;br /&gt;    }&lt;br /&gt;    wp(Client) w = c;&lt;br /&gt;&lt;br /&gt;    Mutex::Autolock lock(mLock);&lt;br /&gt;&lt;br /&gt;    mClients.add(w);&lt;br /&gt;&lt;br /&gt;    return c;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;Now look at the following line of sp(IMediaPlayer) MediaPlayerService::create(pid_t pid, const sp(IMediaPlayerClient)&amp; client, const char* url)&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight:bold;"&gt;if (NO_ERROR != c-&gt;setDataSource(url))&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;So we are basically calling the setDataSource on the Client.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;This function is like the following:&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight:bold;"&gt;status_t MediaPlayerService::Client::setDataSource(const char *url)&lt;/span&gt;&lt;br /&gt;{&lt;br /&gt;    .....&lt;br /&gt;&lt;br /&gt;    .....&lt;br /&gt;&lt;br /&gt;    if (strncmp(url, "content://", 10) == 0) {&lt;br /&gt;        &lt;br /&gt;        // get a filedescriptor for the content Uri and&lt;br /&gt;        // pass it to the setDataSource(fd) method&lt;br /&gt;&lt;br /&gt;        String16 url16(url);&lt;br /&gt;        int fd = android::openContentProviderFile(url16); &lt;br /&gt;        if (fd &lt; 0)&lt;br /&gt;        {&lt;br /&gt;            LOGE("Couldn't open fd for %s", url);&lt;br /&gt;            return UNKNOWN_ERROR;&lt;br /&gt;        }&lt;br /&gt;        setDataSource(fd, 0, 0x7fffffffffLL); // this sets mStatus&lt;br /&gt;        close(fd);&lt;br /&gt;        return mStatus;&lt;br /&gt;    } else {&lt;br /&gt;        player_type playerType = getPlayerType(url);&lt;br /&gt;       &lt;br /&gt;        .....&lt;br /&gt;&lt;br /&gt;        .....&lt;br /&gt;&lt;br /&gt;        // create the right type of player&lt;br /&gt;        sp(MediaPlayerBase) p = createPlayer(playerType);&lt;br /&gt;        ......&lt;br /&gt;&lt;br /&gt;        ......&lt;br /&gt;        mStatus = p-&gt;setDataSource(url);&lt;br /&gt;&lt;br /&gt;        if (mStatus == NO_ERROR) mPlayer = p;&lt;br /&gt;&lt;br /&gt;        return mStatus;&lt;br /&gt;    }&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;From the above code snippet it becomes clear that we do&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight:bold;"&gt;either:&lt;/span&gt;&lt;br /&gt; &lt;br /&gt; if (strncmp(url, "content://", 10) == 0) {&lt;br /&gt;        &lt;br /&gt;        // get a filedescriptor for the content Uri and&lt;br /&gt;        // pass it to the setDataSource(fd) method&lt;br /&gt;&lt;br /&gt;        String16 url16(url);&lt;br /&gt;        int fd = android::openContentProviderFile(url16);&lt;br /&gt;        if (fd &lt; 0)&lt;br /&gt;        {&lt;br /&gt;            LOGE("Couldn't open fd for %s", url);&lt;br /&gt;            return UNKNOWN_ERROR;&lt;br /&gt;        }&lt;br /&gt;        setDataSource(fd, 0, 0x7fffffffffLL); // this sets mStatus&lt;br /&gt;        close(fd);&lt;br /&gt;        return mStatus;&lt;br /&gt; &lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight:bold;"&gt;or:&lt;/span&gt; &lt;br /&gt;&lt;br /&gt;else {&lt;br /&gt;        player_type playerType = getPlayerType(url); //here it extracts the Player Type from the URL.&lt;br /&gt;        LOGV("player type = %d", playerType);&lt;br /&gt;&lt;br /&gt;        // create the right type of player&lt;br /&gt;        sp(MediaPlayerBase) p = createPlayer(playerType); &lt;br /&gt;&lt;br /&gt;       ..............&lt;br /&gt;       ..............&lt;br /&gt;&lt;br /&gt; }&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;In the first case the setDataSource function looks like the following:&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight:bold;"&gt;status_t MediaPlayerService::Client::setDataSource(int fd, int64_t offset, int64_t length)&lt;/span&gt;&lt;br /&gt;{&lt;br /&gt;    .......&lt;br /&gt; &lt;br /&gt;    .......&lt;br /&gt;&lt;br /&gt;    //here it gets the file type from the File descriptor&lt;br /&gt;    player_type playerType = getPlayerType(fd, offset, length); &lt;br /&gt;    &lt;br /&gt;&lt;br /&gt;    // create the right type of player&lt;br /&gt;    sp(MediaPlayerBase) p = createPlayer(playerType);&lt;br /&gt;    ........&lt;br /&gt;&lt;br /&gt;    .........&lt;br /&gt;    &lt;br /&gt;    .........&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;Look at the line :&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight:bold;"&gt;sp(MediaPlayerBase) p = createPlayer(playerType)&lt;/span&gt;. &lt;br /&gt;&lt;br /&gt;It becomes clear that we create the player here.&lt;br /&gt;&lt;br /&gt;The sp(MediaPlayerBase) p = createPlayer (playerType) actually creates the right player. And we get the playertype from the file descriptor.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;In the second case (the else part) we call &lt;span style="font-weight:bold;"&gt;sp&lt;MediaPlayerBase&gt; p = createPlayer(playerType)&lt;/span&gt;. We extract the file type from the URL. This helps us in creating the right player object.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;The createPlayer function looks like the following:&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight:bold;"&gt;sp(MediaPlayerBase) MediaPlayerService::Client::createPlayer(player_type playerType)&lt;/span&gt;&lt;br /&gt;{&lt;br /&gt;    ......&lt;br /&gt;    &lt;br /&gt;    ......&lt;br /&gt;&lt;br /&gt;    if (p == NULL) {&lt;br /&gt;        p = android::createPlayer(playerType, this, notify);&lt;br /&gt;    }&lt;br /&gt;    return p;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Hence it actually delegates the task to &lt;span style="font-weight:bold;"&gt;p = android::createPlayer(playerType, this, notify);&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;The above function is as follows;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight:bold;"&gt;static sp(MediaPlayerBase) createPlayer(player_type playerType, void* cookie,&lt;br /&gt;        notify_callback_f notifyFunc)&lt;/span&gt;&lt;br /&gt;{&lt;br /&gt;    .....&lt;br /&gt;&lt;br /&gt;    switch (playerType) {&lt;br /&gt;#ifndef NO_OPENCORE&lt;br /&gt;        case PV_PLAYER:&lt;br /&gt;            &lt;br /&gt;            p = new PVPlayer();&lt;br /&gt;&lt;br /&gt;            break;&lt;br /&gt;#endif&lt;br /&gt;        case SONIVOX_PLAYER:&lt;br /&gt;&lt;br /&gt;           p = new MidiFile();&lt;br /&gt;&lt;br /&gt;            break;&lt;br /&gt;       &lt;br /&gt;        case VORBIS_PLAYER:&lt;br /&gt;            &lt;br /&gt;            p = new VorbisPlayer();&lt;br /&gt;&lt;br /&gt;            break;&lt;br /&gt;    }&lt;br /&gt;    ......&lt;br /&gt;    &lt;br /&gt;    ......&lt;br /&gt;&lt;br /&gt;    return p;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;Thus we find that the right player is created through the &lt;span style="font-weight:bold;"&gt;parameterized factory function&lt;/span&gt; createPlayer. &lt;br /&gt;&lt;br /&gt;i hope this explains how the right mediaplayer is created from the Uri that we pass in the client side java interface of the Mediaplyer.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3946478681282550454-1790319830907903206?l=som-itsolutions.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://som-itsolutions.blogspot.com/feeds/1790319830907903206/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=3946478681282550454&amp;postID=1790319830907903206' title='4 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3946478681282550454/posts/default/1790319830907903206'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3946478681282550454/posts/default/1790319830907903206'/><link rel='alternate' type='text/html' href='http://som-itsolutions.blogspot.com/2009/06/flow-of-events-during-media-player.html' title='The flow of events during the Media Player Creation in Android Framework'/><author><name>Som</name><uri>http://www.blogger.com/profile/09519633424407534012</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='24' src='http://3.bp.blogspot.com/-XVhL110Tyf8/ThxKF3DBYcI/AAAAAAAAEBo/arVXUPsgtSg/s220/NJ%2B042.JPG'/></author><thr:total>4</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3946478681282550454.post-3342449240346418147</id><published>2009-06-14T06:36:00.000+05:30</published><updated>2009-06-14T12:28:24.798+05:30</updated><title type='text'>Parameterized factory design pattern in Android Media Service Framework</title><content type='html'>As i was going through the Media framework of Android, i have found the implementation of a parameterized factory pattern in the way &lt;span style="font-weight:bold;"&gt;MediaPlayerService &lt;/span&gt;class creates the concrete media players.&lt;br /&gt;&lt;br /&gt;Let me give an idea of the parameterized factory implementation as discussed in the GoF book. It goes like this.&lt;br /&gt;&lt;br /&gt;class Creator {&lt;br /&gt;&lt;br /&gt;public:&lt;br /&gt;&lt;br /&gt;virtual Product* CreateProduct( ProductId id);&lt;br /&gt;&lt;br /&gt;};&lt;br /&gt;&lt;br /&gt;And the implementation will look like the following:&lt;br /&gt;&lt;br /&gt;Product* Creator :: CreateProduct (ProductId id)&lt;br /&gt;{&lt;br /&gt;&lt;br /&gt;if (id == Product1) return new Product1;&lt;br /&gt;&lt;br /&gt;if (id == Product2) return new Product2;&lt;br /&gt;&lt;br /&gt;//repeat for the other products&lt;br /&gt;&lt;br /&gt;return 0;&lt;br /&gt;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;Product1, Product2 etc are all derived from the base class Product.&lt;br /&gt;&lt;br /&gt;Now let us dissect the Media Framework of Android to see how this design pattern has been implemented to create the different Media players.&lt;br /&gt;&lt;br /&gt;The base class of all the players are &lt;span style="font-weight:bold;"&gt;MediaPlayerInterface &lt;/span&gt;which is again derived from &lt;span style="font-weight:bold;"&gt;MediaPlayerBase&lt;/span&gt;.&lt;br /&gt;&lt;br /&gt;MediaPlayerService has got a static function called &lt;br /&gt;&lt;br /&gt;"static sp&lt;MediaPlayerBase&gt; createPlayer(player_type playerType, void* cookie, notify_callback_f notifyFunc)"&lt;br /&gt;&lt;br /&gt;which actually takes care of the creation of the concrete players namely &lt;span style="font-weight:bold;"&gt;PVPlayer&lt;/span&gt;, &lt;span style="font-weight:bold;"&gt;MidiFile &lt;/span&gt;and &lt;span style="font-weight:bold;"&gt;VorbisPlayer&lt;/span&gt;.&lt;br /&gt;&lt;br /&gt;Hence the class MediaPlayerService  works as the Factory class for creating the Concrete Players besides handling other responsibilities.&lt;br /&gt;&lt;br /&gt;The class MediaPlayerService can be found at &lt;span style="font-weight:bold;"&gt;\base\media\libmediaplayerservice &lt;/span&gt;of the Android source code.&lt;br /&gt;&lt;br /&gt;The createPlayer function goes like the following :&lt;br /&gt;&lt;br /&gt;static sp(MediaPlayerBase) createPlayer(player_type playerType, void* cookie,&lt;br /&gt;        notify_callback_f notifyFunc)&lt;br /&gt;{&lt;br /&gt;    sp(MediaPlayerBase) p;&lt;br /&gt;    switch (playerType) {&lt;br /&gt;#ifndef NO_OPENCORE&lt;br /&gt;        case PV_PLAYER:&lt;br /&gt;            LOGV(" create PVPlayer");&lt;br /&gt;            p = new PVPlayer();&lt;br /&gt;            break;&lt;br /&gt;#endif&lt;br /&gt;        case SONIVOX_PLAYER:&lt;br /&gt;            LOGV(" create MidiFile");&lt;br /&gt;            p = new MidiFile();&lt;br /&gt;            break;&lt;br /&gt;        &lt;br /&gt;        case VORBIS_PLAYER:&lt;br /&gt;            LOGV(" create VorbisPlayer");&lt;br /&gt;            p = new VorbisPlayer();&lt;br /&gt;            break;&lt;br /&gt;    }&lt;br /&gt;    if (p != NULL) {&lt;br /&gt;        if (p-&gt;initCheck() == NO_ERROR) {&lt;br /&gt;            p-&gt;setNotifyCallback(cookie, notifyFunc);&lt;br /&gt;        } else {&lt;br /&gt;            p.clear();&lt;br /&gt;        }&lt;br /&gt;    }&lt;br /&gt;   if (p == NULL) {&lt;br /&gt;        LOGE("Failed to create player object");&lt;br /&gt;    }&lt;br /&gt;    return p;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;As we can see from the above code that MediaPlayerBase here works as the base class Product. And we create different products (different concrete media players) through the function createPlayer which works as the CreateProduct function in the example at the beginning.&lt;br /&gt;&lt;br /&gt;The above similarity shows how a Parameterized Factory Pattern has been implemented in the Android Media Framework by MediaService layer to create different Media Players.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3946478681282550454-3342449240346418147?l=som-itsolutions.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://som-itsolutions.blogspot.com/feeds/3342449240346418147/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=3946478681282550454&amp;postID=3342449240346418147' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3946478681282550454/posts/default/3342449240346418147'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3946478681282550454/posts/default/3342449240346418147'/><link rel='alternate' type='text/html' href='http://som-itsolutions.blogspot.com/2009/06/parameterized-factory-pattern-in.html' title='Parameterized factory design pattern in Android Media Service Framework'/><author><name>Som</name><uri>http://www.blogger.com/profile/09519633424407534012</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='24' src='http://3.bp.blogspot.com/-XVhL110Tyf8/ThxKF3DBYcI/AAAAAAAAEBo/arVXUPsgtSg/s220/NJ%2B042.JPG'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3946478681282550454.post-2898873906665487337</id><published>2009-06-03T16:43:00.000+05:30</published><updated>2009-06-11T20:20:02.756+05:30</updated><title type='text'>Composite Design Pattern in Android View and Widget</title><content type='html'>The Intent of this design pattern is stated in the GoF book as "Compose Objects into tree structures to represent part-whole hierarchies. Composite lets clients treat individual objects and compositions of objects uniformly".&lt;br /&gt;&lt;br /&gt;To explain it in a simpler fashion, let me give the same example as given in the GoF book. Suppose there is an object called Picture, a graphics object. This picture may consist of other pictures recursively as well as primitive objects like line, rectangle objects etc. All of these part objects which make the whole picture conform to the same Graphic interface. Hence to the client, a part object appears same as the whole picture consisted of other part objects. To draw a whole object, the client simply traverses through the whole picture and draws different parts.&lt;br /&gt;&lt;br /&gt;The class diagram of the composite design pattern will look like the following:&lt;br /&gt;&lt;br /&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://1.bp.blogspot.com/_PnYnrngiRvA/SiZbUyp1ozI/AAAAAAAAB_w/3PqTj6zmAsg/s1600-h/1.JPG"&gt;&lt;img style="float:left; margin:0 10px 10px 0;cursor:pointer; cursor:hand;width: 400px; height: 201px;" src="http://1.bp.blogspot.com/_PnYnrngiRvA/SiZbUyp1ozI/AAAAAAAAB_w/3PqTj6zmAsg/s400/1.JPG" border="0" alt=""id="BLOGGER_PHOTO_ID_5343058420674437938" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;The following participants take part in this design pattern:&lt;br /&gt;&lt;br /&gt;Component - &lt;br /&gt;&lt;br /&gt;it declares the interface for the objects ( part as well as whole)&lt;br /&gt;helps in managing the objects (adding, removing)&lt;br /&gt;&lt;br /&gt;Leaf -&lt;br /&gt;&lt;br /&gt;represents leaf objects which don't have any children&lt;br /&gt;these are the primitive objects&lt;br /&gt;&lt;br /&gt;Composite - &lt;br /&gt;&lt;br /&gt;defines behavior for components having children&lt;br /&gt;stores the children&lt;br /&gt;&lt;br /&gt;Client -&lt;br /&gt;&lt;br /&gt;takes help of the Component interface to manipulate different objects&lt;br /&gt;&lt;br /&gt;Its all about the theoretical side of the Composite Design Pattern. Now let us try to dissect the Android View and the Widget folders (which are available at \\base\core\java\android) to see how this design pattern has been implemented there.&lt;br /&gt;&lt;br /&gt;In Android, the View class works as the Component class. However, the child management part (add component, remove component) has been moved to the Composite class which is the ViewGroup class. Actually the Add and Remove of a component has been declared in an interface called ViewManager and the ViewGroup implements that interface. Also the interface for a Composite object is declared as ViewParent interface and the ViewGroup (the Composite object) implements that as well.&lt;br /&gt;&lt;br /&gt;The leaf classes like Button, ImageView etc are deduced either by directly subclassing the View (Component) or from the subclasses of the View (for example, the Button class is derived from TextView class which in turn is directly derived fron the View class). The Composite Class (ViewGroup) is deduced by directly subclassing the View and by implementing the two interfaces namely ViewParent (which defines the interface of a composite object) and ViewManager (which defines the interface from adding and removing components). &lt;br /&gt;&lt;br /&gt;As expected the getParent function which is needed to get the Parent of a component is put in the View class (the Component).&lt;br /&gt;&lt;br /&gt;The Composite object (ViewGroup) has an array to hold its children.&lt;br /&gt;&lt;br /&gt;The simplified version of the class diagram of the Android View and Widgets are as follows:&lt;br /&gt;&lt;br /&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://1.bp.blogspot.com/_PnYnrngiRvA/SiiBYcbBHtI/AAAAAAAACAI/eS6q7FeNLas/s1600-h/2.JPG"&gt;&lt;img style="display:block; margin:0px auto 10px; text-align:center;cursor:pointer; cursor:hand;width: 400px; height: 185px;" src="http://1.bp.blogspot.com/_PnYnrngiRvA/SiiBYcbBHtI/AAAAAAAACAI/eS6q7FeNLas/s400/2.JPG" border="0" alt=""id="BLOGGER_PHOTO_ID_5343663214821449426" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;For simplicity i have not shown the two interfaces namely ViewManager and ViewParent.&lt;br /&gt;&lt;br /&gt;Now let us consider the class diagram as presented in the beginning of this discussion. There is a function called Operation. In Android implementation, the onDraw function in the Component (View) plays this role. The &lt;span style="font-weight:bold;"&gt;DispatchDraw&lt;/span&gt; function (which is called when the children are to be drawn) in the composite (ViewGroup) object actually traverses through the list of the objects and calls draw on each of the child object. For simplicity, in the class diagram it is shown that the dispatchDraw function is directly calling the onDraw function. However it actually takes help of another function called &lt;span style="font-weight:bold;"&gt;drawChild&lt;/span&gt; which is called on each child object of the ViewGroup object.&lt;br /&gt;&lt;br /&gt;This way we can say that Android View and Widgets are some sort of implementation of the Composite Design Pattern.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3946478681282550454-2898873906665487337?l=som-itsolutions.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://som-itsolutions.blogspot.com/feeds/2898873906665487337/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=3946478681282550454&amp;postID=2898873906665487337' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3946478681282550454/posts/default/2898873906665487337'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3946478681282550454/posts/default/2898873906665487337'/><link rel='alternate' type='text/html' href='http://som-itsolutions.blogspot.com/2009/06/composite-design-pattern-in-android.html' title='Composite Design Pattern in Android View and Widget'/><author><name>Som</name><uri>http://www.blogger.com/profile/09519633424407534012</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='24' src='http://3.bp.blogspot.com/-XVhL110Tyf8/ThxKF3DBYcI/AAAAAAAAEBo/arVXUPsgtSg/s220/NJ%2B042.JPG'/></author><media:thumbnail xmlns:media='http://search.yahoo.com/mrss/' url='http://1.bp.blogspot.com/_PnYnrngiRvA/SiZbUyp1ozI/AAAAAAAAB_w/3PqTj6zmAsg/s72-c/1.JPG' height='72' width='72'/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3946478681282550454.post-4916652360955133174</id><published>2009-05-31T21:34:00.004+05:30</published><updated>2011-11-17T16:44:59.494+05:30</updated><title type='text'>Observer Pattern in Java</title><content type='html'>&lt;div dir="ltr" style="text-align: left;" trbidi="on"&gt;As i was going through the different source code files of the Java Util package, i found the implementation of the Observer Pattern ( see the GoF book for more information on this pattern) in the two classes - namely Observer.java and Observable.java. i would like to throw some lights on these two classes. These two classes can be found in the Java\j2se\src\share\classes\java\util folder of the JDK source code.&lt;br /&gt;&lt;br /&gt;Before explaining the application of Observer Pattern in Java, let me give you a brief introduction of this pattern. Observer pattern helps you in notifying and updating all the dependent objects, if one object changes state. This pattern has two main objects – Subject and Observer. Multiple number of observers can be attached to a particular Subject. All the observers are notified and in turn gotten updated if the Subject changes its state. This is also known as the publish-subscribe. The subject is the publisher of changes, and the Observers are the subscribers to those changes.&lt;br /&gt;&lt;br /&gt;The class diagram will look like the following.&lt;br /&gt;&lt;br /&gt;&lt;a href="http://4.bp.blogspot.com/_PnYnrngiRvA/Sjd3Yx5r-RI/AAAAAAAACAQ/TUglyLGm29c/s1600-h/1.JPG"&gt;&lt;img alt="" border="0" id="BLOGGER_PHOTO_ID_5347874350121613586" src="http://4.bp.blogspot.com/_PnYnrngiRvA/Sjd3Yx5r-RI/AAAAAAAACAQ/TUglyLGm29c/s400/1.JPG" style="cursor: hand; cursor: pointer; display: block; height: 155px; margin: 0px auto 10px; text-align: center; width: 399px;" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;And the sequence diagram of this pattern is like this.&lt;br /&gt;&lt;br /&gt;&lt;a href="http://4.bp.blogspot.com/_PnYnrngiRvA/Sjd3rit4-zI/AAAAAAAACAY/6XMez0c4c5g/s1600-h/2.JPG"&gt;&lt;img alt="" border="0" id="BLOGGER_PHOTO_ID_5347874672463117106" src="http://4.bp.blogspot.com/_PnYnrngiRvA/Sjd3rit4-zI/AAAAAAAACAY/6XMez0c4c5g/s400/2.JPG" style="cursor: hand; cursor: pointer; display: block; height: 275px; margin: 0px auto 10px; text-align: center; width: 295px;" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;What these two diagrams essentially depict is that in the Observer Pattern, we have a Subject, which can attach one or more Observers through its Attach() function. Whenever it changes its state it Notifies all the attached Observers through its Notify function. The observers in turn synchronize their states with that of the Subject through the GetSubjectState function.&lt;br /&gt;&lt;br /&gt;Now let me try to dissect the Java observer pattern.&lt;br /&gt;&lt;br /&gt;Let us first start with the Observable.java class. As the name suggests it is the class which will implemented functionalities for being observed. Or in other words it is the class which helps in designing the Subject class of the Observer pattern discussion of the GoF book. We need to extend this class to get the Subject class.&lt;br /&gt;&lt;br /&gt;Let us try to dissect this class. The following functions are there in this class:&lt;br /&gt;&lt;br /&gt;Data Members: It has a vector to hold all the observers that are interested in observing this observable class. It has another boolean data member called "changed" to indicate if anything has changed in the Subject class ( which will be derived from this Observable class).&lt;br /&gt;&lt;br /&gt;Constructor : This class has a no argument constructor to construct an empty vector of Observers. &lt;br /&gt;&lt;br /&gt;Member Functions :&lt;br /&gt;addObserver : To add an observer to its list of Observers.&lt;br /&gt;&lt;br /&gt;deleteObserver : To delete a particular observer from the list of the observers&lt;br /&gt;&lt;br /&gt;notifyObservers : there are two overloaded versions of this function. One takes an Object parameter as an argument and the other does not take any argument. The task of this function is to notify all the attached observers when any data of the subject gets changed. To check whether the data is changed it evaluates the boolean "changed" data member. This function also calls the update function of each observer objects to ask them to get in sync with the subject's changed state. The overloaded version that takes an one argument parameter is used to let the observers know about which attribute is changed. And the other version of this function which does not take any argument does not let the observer know about which attribute is changed.&lt;br /&gt;&lt;br /&gt;deleteObservers : This function removes all the observers attached to this subject.&lt;br /&gt;&lt;br /&gt;setChanged : This function sets the boolean data member "changed".&lt;br /&gt;&lt;br /&gt;clearChanged : This function resets the boolean data member "changed".&lt;br /&gt;&lt;br /&gt;hasChanged : This function helps us to know whether the data of the subject has been changed or not. &lt;br /&gt;&lt;br /&gt;countObservers : This function returns the number of observers attached to this subject.&lt;br /&gt;&lt;br /&gt;This is all about the Observable class which helps us to define to Subject class.&lt;br /&gt;&lt;br /&gt;The Observer.java defines an interface called Observer having just one abstract function called update (Observable o, Object arg). As the name suggests, the Observer class that will implement this interface will override the update function to set the attribute passed as an argument (arg) from the Subject class. This method is called whenever any attribute in the Subject class gets changed.&lt;br /&gt;&lt;br /&gt;Now let us try to see an example to understand how this Observer Pattern is used.&lt;br /&gt;&lt;br /&gt;Let us first extend the Observable class to create the Subject class.&lt;br /&gt;&lt;br /&gt;import java.util.Observable;&lt;br /&gt;&lt;br /&gt;public class Subject extends Observable {&lt;br /&gt;private String name;&lt;br /&gt;private float price;&lt;br /&gt;&lt;br /&gt;public Subject(String name, float price) {&lt;br /&gt;this.name = name;&lt;br /&gt;this.price = price;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;public String getName() {return name;}&lt;br /&gt;&lt;br /&gt;public float getPrice() {return price;}&lt;br /&gt;&lt;br /&gt;public void setName(String name) {&lt;br /&gt;this.name = name;&lt;br /&gt;setChanged();&lt;br /&gt;notifyObservers(name);&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;public void setPrice(float price) {&lt;br /&gt;this.price = price;&lt;br /&gt;setChanged();&lt;br /&gt;notifyObservers(new Float(price));&lt;br /&gt;}&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;As this is clear from the implementation of the Subject class, that whenever we call the setter function to change the attributes of the Subject's object, we call the notifyObservers and pass that attribute as a parameter.&lt;br /&gt;&lt;br /&gt;Now let us see how we create two different observers namely NameObserver and PriceObserver to observe these two attributes of the Subject class.&lt;br /&gt;&lt;br /&gt;// An observer of name changes.&lt;br /&gt;&lt;br /&gt;import java.util.Observable;&lt;br /&gt;import java.util.Observer;&lt;br /&gt;&lt;br /&gt;public class NameObserver implements Observer {&lt;br /&gt;private String name;&lt;br /&gt;&lt;br /&gt;public NameObserver() {&lt;br /&gt;name = null;&lt;br /&gt;System.out.println("NameObserver created: Name is " + name);&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;public void update(Observable obj, Object arg) {&lt;br /&gt;&lt;br /&gt;if (arg instanceof String) {&lt;br /&gt;name = (String)arg;&lt;br /&gt;System.out.println("NameObserver: Name changed to " + name);&lt;br /&gt;} &lt;br /&gt;}&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;// An observer of price changes.&lt;br /&gt;&lt;br /&gt;import java.util.Observable;&lt;br /&gt;import java.util.Observer;&lt;br /&gt;&lt;br /&gt;public class PriceObserver implements Observer {&lt;br /&gt;private float price;&lt;br /&gt;public PriceObserver() {&lt;br /&gt;price = 0;&lt;br /&gt;System.out.println("PriceObserver created: Price is " + price);&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;public void update(Observable obj, Object arg) {&lt;br /&gt;if (arg instanceof Float) {&lt;br /&gt;price = ((Float)arg).floatValue();&lt;br /&gt;System.out.println("PriceObserver: Price changed to " +&lt;br /&gt;price);&lt;br /&gt;} &lt;br /&gt;}&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;As it has become clear from the above two implementations that the update function actually helps in synchronizing the state of the concrete observers with that of the Subject.&lt;br /&gt;&lt;br /&gt;Now the client of the Observer framework will look like the following :&lt;br /&gt;&lt;br /&gt;// Test program for Subject, NameObserver and PriceObserver&lt;br /&gt;public class TestObservers {&lt;br /&gt;&lt;br /&gt;public static void main(String args[]) {&lt;br /&gt;&lt;br /&gt;// Create the Subject and Observers.&lt;br /&gt;Subject s = new Subject("Corn Pops", 20.5f);&lt;br /&gt;NameObserver nameObs = new NameObserver();&lt;br /&gt;PriceObserver priceObs = new PriceObserver();&lt;br /&gt;&lt;br /&gt;// Add those Observers!&lt;br /&gt;s.addObserver(nameObs);&lt;br /&gt;s.addObserver(priceObs);&lt;br /&gt;&lt;br /&gt;// Make changes to the Subject.&lt;br /&gt;s.setName("Frosted Flakes"); // It prints NameObserver: Name changed to Frosted Flakes&lt;br /&gt;&lt;br /&gt;s.setPrice(30.6f); //It prints PriceObserver: Price changed to 30.6&lt;br /&gt;&lt;br /&gt;s.setPrice(50.8f); //It prints PriceObserver: Price changed to 50.8&lt;br /&gt;&lt;br /&gt;s.setName("Sugar Crispies"); // It prints NameObserver: Name changed to Sugar Crispies&lt;br /&gt;}&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;Hope the above discussion will help people understand of how the Java supports implementing the Observer pattern.&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3946478681282550454-4916652360955133174?l=som-itsolutions.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://som-itsolutions.blogspot.com/feeds/4916652360955133174/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=3946478681282550454&amp;postID=4916652360955133174' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3946478681282550454/posts/default/4916652360955133174'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3946478681282550454/posts/default/4916652360955133174'/><link rel='alternate' type='text/html' href='http://som-itsolutions.blogspot.com/2009/05/observer-pattern-in-java.html' title='Observer Pattern in Java'/><author><name>Som</name><uri>http://www.blogger.com/profile/09519633424407534012</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='24' src='http://3.bp.blogspot.com/-XVhL110Tyf8/ThxKF3DBYcI/AAAAAAAAEBo/arVXUPsgtSg/s220/NJ%2B042.JPG'/></author><media:thumbnail xmlns:media='http://search.yahoo.com/mrss/' url='http://4.bp.blogspot.com/_PnYnrngiRvA/Sjd3Yx5r-RI/AAAAAAAACAQ/TUglyLGm29c/s72-c/1.JPG' height='72' width='72'/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3946478681282550454.post-8642732373097546935</id><published>2009-03-12T17:38:00.000+05:30</published><updated>2009-03-12T17:39:00.565+05:30</updated><title type='text'>Bridge Pattern</title><content type='html'>&lt;iframe src='http://docs.google.com/EmbedSlideshow?docid=dcgcp339_304c4b6pvgj' frameborder='0' width='410' height='342'&gt;&lt;/iframe&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3946478681282550454-8642732373097546935?l=som-itsolutions.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://som-itsolutions.blogspot.com/feeds/8642732373097546935/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=3946478681282550454&amp;postID=8642732373097546935' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3946478681282550454/posts/default/8642732373097546935'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3946478681282550454/posts/default/8642732373097546935'/><link rel='alternate' type='text/html' href='http://som-itsolutions.blogspot.com/2009/03/bridge-pattern_12.html' title='Bridge Pattern'/><author><name>Som</name><uri>http://www.blogger.com/profile/09519633424407534012</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='24' src='http://3.bp.blogspot.com/-XVhL110Tyf8/ThxKF3DBYcI/AAAAAAAAEBo/arVXUPsgtSg/s220/NJ%2B042.JPG'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3946478681282550454.post-8690461483733515609</id><published>2009-01-25T16:12:00.000+05:30</published><updated>2009-10-01T16:17:59.897+05:30</updated><title type='text'>Android Widget - through Java Code</title><content type='html'>There are two ways to create android resources/view - either through the XML layout or through pure java code. In this article I have tried to implement the android view through the second method - i.e. through Java code. I have implemented a Table Layout and few widgets like static text, edit box and slider bar. There are three sets of all these widgets - namely Red, Green and Blue. These three are the percentage of the RGB color code. For example if we make Red as 100, and Green and Blue as 0, it will paint the background of the device with Red. It has also shown how to create a prompt dialog when you enter a value more than 100 in any of the edit boxes.&lt;br /&gt;&lt;br /&gt;The application will look like the following:&lt;br /&gt;&lt;br /&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://3.bp.blogspot.com/_PnYnrngiRvA/SqRG2jTunbI/AAAAAAAACBU/1Bz3BGx-mWs/s1600-h/1.JPG"&gt;&lt;img style="display:block; margin:0px auto 10px; text-align:center;cursor:pointer; cursor:hand;width: 320px; height: 261px;" src="http://3.bp.blogspot.com/_PnYnrngiRvA/SqRG2jTunbI/AAAAAAAACBU/1Bz3BGx-mWs/s320/1.JPG" border="0" alt=""id="BLOGGER_PHOTO_ID_5378501757992082866" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;The code for this application is as follow -&lt;br /&gt; &lt;br /&gt;import android.app.Activity;&lt;br /&gt;import android.app.AlertDialog;&lt;br /&gt;import android.content.DialogInterface;&lt;br /&gt;import android.content.pm.ActivityInfo;&lt;br /&gt;import android.graphics.Color;&lt;br /&gt;import android.os.Bundle;&lt;br /&gt;import android.view.View;&lt;br /&gt;import android.view.ViewGroup.LayoutParams;&lt;br /&gt;import android.widget.Button;&lt;br /&gt;import android.widget.EditText;&lt;br /&gt;import android.widget.LinearLayout;&lt;br /&gt;import android.widget.SeekBar;&lt;br /&gt;import android.widget.TableLayout;&lt;br /&gt;import android.widget.TextView;&lt;br /&gt;import android.widget.SeekBar.OnSeekBarChangeListener;&lt;br /&gt;&lt;br /&gt;public class Widget extends Activity implements  View.OnClickListener /*, View.OnKeyListener */{&lt;br /&gt;    /** Called when the activity is first created. */&lt;br /&gt;   &lt;br /&gt; private final static int idLayout = 1;&lt;br /&gt; private final static int idTitle = 2;&lt;br /&gt;    &lt;br /&gt; private final static int idTextRed = 3;&lt;br /&gt;    private final static int idTextGreen = 4;&lt;br /&gt;    private final static int idTextBlue = 5;&lt;br /&gt;    &lt;br /&gt;    private final static int idEditRedText = 6;&lt;br /&gt;    private final static int idEditGreenText = 7;&lt;br /&gt;    private final static int idEditBlueText = 8;&lt;br /&gt;    &lt;br /&gt;    private final static int idSeekBarRed = 9;&lt;br /&gt;    private final static int idSeekBarGreen = 10;&lt;br /&gt;    private final static int idSeekBarBlue =11;&lt;br /&gt;    &lt;br /&gt;    private final static int idButtonOK = 12;&lt;br /&gt;    &lt;br /&gt;    private final static int MaxColorValue = 255;&lt;br /&gt;    &lt;br /&gt;    private int RedProgress = 0;&lt;br /&gt;    private int GreenProgress = 0;&lt;br /&gt;    private int BlueProgress = 0;&lt;br /&gt;&lt;br /&gt;    private int RedValue = 0;&lt;br /&gt;    private int GreenValue = 0;&lt;br /&gt;    private int BlueValue = 0;&lt;br /&gt;    &lt;br /&gt;        &lt;br /&gt; @Override&lt;br /&gt;    public void onCreate(Bundle savedInstanceState) {&lt;br /&gt;        super.onCreate(savedInstanceState);&lt;br /&gt;        &lt;br /&gt;        &lt;br /&gt;        setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);&lt;br /&gt;&lt;br /&gt;        TableLayout layout = new TableLayout(this);&lt;br /&gt;        layout.setId(idLayout);&lt;br /&gt;        layout.setLayoutParams(&lt;br /&gt;          new LayoutParams(LayoutParams.FILL_PARENT,android.view.ViewGroup.LayoutParams.FILL_PARENT));&lt;br /&gt;        layout.setFocusable(true);&lt;br /&gt;        &lt;br /&gt;        TextView title = new TextView(this);&lt;br /&gt;        title.setText(R.string.title);&lt;br /&gt;        title.setLayoutParams(&lt;br /&gt;                new LinearLayout.LayoutParams(&lt;br /&gt;                LinearLayout.LayoutParams.FILL_PARENT,&lt;br /&gt;                LayoutParams.WRAP_CONTENT));&lt;br /&gt;        //title.s(Alignment.ALIGN_CENTER);&lt;br /&gt;        title.setId(idTitle);&lt;br /&gt;        layout.addView(title,0);&lt;br /&gt;        &lt;br /&gt;        &lt;br /&gt;        //For Item 1&lt;br /&gt;        TextView ItemRed = new TextView(this);&lt;br /&gt;        ItemRed.setFocusable(true);&lt;br /&gt;        ItemRed.setText("% RED");&lt;br /&gt;        ItemRed.setTextColor(Color.LTGRAY);&lt;br /&gt;        ItemRed.setLayoutParams(&lt;br /&gt;        new TableLayout.LayoutParams(&lt;br /&gt;        TableLayout.LayoutParams.FILL_PARENT, TableLayout.LayoutParams.WRAP_CONTENT));&lt;br /&gt;&lt;br /&gt;        //Give the menu item an ID for tracking reasons.&lt;br /&gt;        //The ID is a static int defined locally to the class&lt;br /&gt;        ItemRed.setId(idTextRed);&lt;br /&gt;        //Add it to our linear layout&lt;br /&gt;        layout.addView(ItemRed, 1);&lt;br /&gt;        &lt;br /&gt;        EditText EditTextRed = new EditText(this);&lt;br /&gt;        EditTextRed.setFocusable(true);&lt;br /&gt;        EditTextRed.setLayoutParams(&lt;br /&gt;          new TableLayout.LayoutParams(TableLayout.LayoutParams.FILL_PARENT, TableLayout.LayoutParams.WRAP_CONTENT));&lt;br /&gt;        EditTextRed.setId(idEditRedText);&lt;br /&gt;        &lt;br /&gt;        layout.addView(EditTextRed, 2);&lt;br /&gt;        &lt;br /&gt;        SeekBar SeekBarRed = new SeekBar(this);&lt;br /&gt;        SeekBarRed.setFocusable(true);&lt;br /&gt;        SeekBarRed.setLayoutParams(&lt;br /&gt;          new TableLayout.LayoutParams(TableLayout.LayoutParams.FILL_PARENT, TableLayout.LayoutParams.WRAP_CONTENT));&lt;br /&gt;        SeekBarRed.setMax(MaxColorValue);&lt;br /&gt;        SeekBarRed.setId(idSeekBarRed);&lt;br /&gt;        &lt;br /&gt;        &lt;br /&gt;        layout.addView(SeekBarRed, 3);&lt;br /&gt;        &lt;br /&gt;        &lt;br /&gt;        //For item 2&lt;br /&gt;        TextView ItemGreen = new TextView(this);&lt;br /&gt;        ItemGreen.setFocusable(true);&lt;br /&gt;        ItemGreen.setText("% GREEN");&lt;br /&gt;        ItemGreen.setTextColor(Color.LTGRAY);&lt;br /&gt;        ItemGreen.setLayoutParams(&lt;br /&gt;                new TableLayout.LayoutParams(&lt;br /&gt;                TableLayout.LayoutParams.FILL_PARENT, TableLayout.LayoutParams.WRAP_CONTENT));&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;        //Give the menu item an ID for tracking reasons.&lt;br /&gt;        //The ID is a static int defined locally to the class&lt;br /&gt;        ItemGreen.setId(idTextGreen);&lt;br /&gt;        //Add it to our linear layout&lt;br /&gt;        layout.addView(ItemGreen, 4);&lt;br /&gt;        &lt;br /&gt;        EditText EditTextGreen = new EditText(this);&lt;br /&gt;        EditTextGreen.setFocusable(true);&lt;br /&gt;        EditTextGreen.setLayoutParams(&lt;br /&gt;          new TableLayout.LayoutParams(TableLayout.LayoutParams.FILL_PARENT, TableLayout.LayoutParams.WRAP_CONTENT));&lt;br /&gt;        EditTextRed.setId(idEditGreenText);&lt;br /&gt;        &lt;br /&gt;        layout.addView(EditTextGreen, 5);&lt;br /&gt;        &lt;br /&gt;        SeekBar SeekBarGreen = new SeekBar(this);&lt;br /&gt;        SeekBarGreen.setFocusable(true);&lt;br /&gt;        SeekBarGreen.setLayoutParams(&lt;br /&gt;          new TableLayout.LayoutParams(TableLayout.LayoutParams.FILL_PARENT, TableLayout.LayoutParams.WRAP_CONTENT));&lt;br /&gt;        SeekBarGreen.setMax(MaxColorValue);&lt;br /&gt;        SeekBarGreen.setId(idSeekBarGreen);&lt;br /&gt;        layout.addView(SeekBarGreen, 6);&lt;br /&gt;        &lt;br /&gt;        &lt;br /&gt;        TextView ItemBlue = new TextView(this);&lt;br /&gt;        ItemBlue.setFocusable(true);&lt;br /&gt;        ItemBlue.setText("% BLUE");&lt;br /&gt;        ItemBlue.setTextColor(Color.LTGRAY);&lt;br /&gt;        ItemBlue.setLayoutParams(&lt;br /&gt;                new TableLayout.LayoutParams(&lt;br /&gt;                TableLayout.LayoutParams.FILL_PARENT, TableLayout.LayoutParams.WRAP_CONTENT));&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;        //Give the menu item an ID for tracking reasons.&lt;br /&gt;        //The ID is a static int defined locally to the class&lt;br /&gt;        ItemBlue.setId(idTextBlue);&lt;br /&gt;        //Add it to our linear layout&lt;br /&gt;        layout.addView(ItemBlue, 7);&lt;br /&gt;        &lt;br /&gt;        &lt;br /&gt;        EditText EditTextBlue = new EditText(this);&lt;br /&gt;        EditTextBlue.setFocusable(true);&lt;br /&gt;        EditTextBlue.setLayoutParams(&lt;br /&gt;          new TableLayout.LayoutParams(TableLayout.LayoutParams.FILL_PARENT, TableLayout.LayoutParams.WRAP_CONTENT));&lt;br /&gt;        EditTextBlue.setId(idEditBlueText);&lt;br /&gt;        &lt;br /&gt;        layout.addView(EditTextBlue, 8);&lt;br /&gt;        &lt;br /&gt;        SeekBar SeekBarBlue = new SeekBar(this);&lt;br /&gt;        SeekBarBlue.setFocusable(true);&lt;br /&gt;        SeekBarBlue.setLayoutParams(&lt;br /&gt;          new TableLayout.LayoutParams(TableLayout.LayoutParams.FILL_PARENT, TableLayout.LayoutParams.WRAP_CONTENT));&lt;br /&gt;        SeekBarBlue.setMax(MaxColorValue);&lt;br /&gt;        SeekBarBlue.setId(idSeekBarBlue);&lt;br /&gt;        layout.addView(SeekBarBlue, 9);&lt;br /&gt;        &lt;br /&gt;        Button OKBtn = new Button(this);&lt;br /&gt;        OKBtn.setFocusable(true);&lt;br /&gt;        OKBtn.setLayoutParams(&lt;br /&gt;          new TableLayout.LayoutParams(TableLayout.LayoutParams.FILL_PARENT, TableLayout.LayoutParams.WRAP_CONTENT));&lt;br /&gt;        OKBtn.setId(idButtonOK);&lt;br /&gt;        OKBtn.setText("OK");&lt;br /&gt;        layout.addView(OKBtn,10);&lt;br /&gt;        &lt;br /&gt;        &lt;br /&gt;        setContentView(layout);&lt;br /&gt;     &lt;br /&gt;        OKBtn.setOnClickListener(this);&lt;br /&gt;        &lt;br /&gt;     SeekBarRed.setOnSeekBarChangeListener(OnSeekBarProgress);&lt;br /&gt;     SeekBarGreen.setOnSeekBarChangeListener(OnSeekBarProgress);&lt;br /&gt;     SeekBarBlue.setOnSeekBarChangeListener(OnSeekBarProgress);&lt;br /&gt;    }&lt;br /&gt; &lt;br /&gt; OnSeekBarChangeListener OnSeekBarProgress =&lt;br /&gt; new OnSeekBarChangeListener() {&lt;br /&gt; &lt;br /&gt; public void onProgressChanged(SeekBar s, int progress, boolean touch){&lt;br /&gt;  &lt;br /&gt;  if(touch){&lt;br /&gt;   TableLayout layout = (TableLayout)s.getParent();&lt;br /&gt;   &lt;br /&gt;   EditText Red = (EditText)layout.getChildAt(2);&lt;br /&gt;   EditText Green = (EditText)layout.getChildAt(5);&lt;br /&gt;   EditText Blue = (EditText)layout.getChildAt(8);&lt;br /&gt;   &lt;br /&gt;    if(s.getId()== idSeekBarRed ){&lt;br /&gt;     RedProgress = progress;&lt;br /&gt;     Red.setText(Integer.toString(RedProgress*100/254));&lt;br /&gt;    }&lt;br /&gt;   &lt;br /&gt;    if(s.getId()== idSeekBarGreen  ){&lt;br /&gt;     &lt;br /&gt;     GreenProgress = progress;&lt;br /&gt;     Green.setText(Integer.toString(GreenProgress*100/254));&lt;br /&gt;    }&lt;br /&gt;   &lt;br /&gt;   &lt;br /&gt;    if(s.getId()== idSeekBarBlue ){&lt;br /&gt;     &lt;br /&gt;     BlueProgress = progress;&lt;br /&gt;     Blue.setText(Integer.toString(BlueProgress*100/254));&lt;br /&gt;    }&lt;br /&gt;   &lt;br /&gt;   int color = Color.rgb(RedProgress, GreenProgress, BlueProgress);&lt;br /&gt;   layout.setBackgroundColor(color);&lt;br /&gt;   &lt;br /&gt;   }&lt;br /&gt; }&lt;br /&gt; &lt;br /&gt; public void onStartTrackingTouch(SeekBar s){&lt;br /&gt;  &lt;br /&gt; }&lt;br /&gt; &lt;br /&gt; public void onStopTrackingTouch(SeekBar s){&lt;br /&gt;  &lt;br /&gt; }&lt;br /&gt; };&lt;br /&gt;&lt;br /&gt;  &lt;br /&gt;  public void onClick(View v){&lt;br /&gt;   &lt;br /&gt;   Button b = (Button)v;&lt;br /&gt;   &lt;br /&gt;   if(b.getId() == idButtonOK){&lt;br /&gt;   &lt;br /&gt;   TableLayout layout = (TableLayout)(v.getParent());&lt;br /&gt;   &lt;br /&gt;   EditText Red = (EditText)layout.getChildAt(2);&lt;br /&gt;   EditText Green = (EditText)layout.getChildAt(5);&lt;br /&gt;   EditText Blue = (EditText)layout.getChildAt(8);&lt;br /&gt;   &lt;br /&gt;   SeekBar SeekBarRed  = (SeekBar)layout.getChildAt(3);&lt;br /&gt;   SeekBar SeekBarGreen  = (SeekBar)layout.getChildAt(6);&lt;br /&gt;   SeekBar SeekBarBlue  = (SeekBar)layout.getChildAt(9);&lt;br /&gt;   &lt;br /&gt;   &lt;br /&gt;   String RedText = Red.getText().toString();&lt;br /&gt;   String GreenText = Green.getText().toString();&lt;br /&gt;   String BlueText = Blue.getText().toString();&lt;br /&gt;   &lt;br /&gt;   &lt;br /&gt;   if(!("".equals(RedText))) {&lt;br /&gt;       try {    &lt;br /&gt;            RedValue = Integer.parseInt(RedText);&lt;br /&gt;           }&lt;br /&gt;       catch (NumberFormatException e) {&lt;br /&gt;          }&lt;br /&gt;        }&lt;br /&gt;   else&lt;br /&gt;        RedValue = 0;&lt;br /&gt;   &lt;br /&gt;&lt;br /&gt;    if(!("".equals(GreenText))) {&lt;br /&gt;       try {    &lt;br /&gt;            GreenValue = Integer.parseInt(GreenText);&lt;br /&gt;           }&lt;br /&gt;       catch (NumberFormatException e) {&lt;br /&gt;          }&lt;br /&gt;        }&lt;br /&gt;   else&lt;br /&gt;        GreenValue = 0;&lt;br /&gt;   &lt;br /&gt;   if(!("".equals(BlueText))) {&lt;br /&gt;       try {    &lt;br /&gt;            BlueValue = Integer.parseInt(BlueText);&lt;br /&gt;           }&lt;br /&gt;       catch (NumberFormatException e) {&lt;br /&gt;          }&lt;br /&gt;        }&lt;br /&gt;   else&lt;br /&gt;        BlueValue = 0;&lt;br /&gt;   &lt;br /&gt;    &lt;br /&gt;    if( RedValue&gt;=0 &amp;&amp; RedValue&lt;=100) {&lt;br /&gt;      RedProgress = 254*RedValue/100;&lt;br /&gt;      SeekBarRed.setProgress(RedProgress);&lt;br /&gt;    }&lt;br /&gt;    &lt;br /&gt;    else {&lt;br /&gt;    new AlertDialog.Builder(this)&lt;br /&gt;    .setTitle("Alert!")&lt;br /&gt;    .setMessage("Please enter a value between 0 and 100 for RED...")&lt;br /&gt;    .setNeutralButton("Close", new DialogInterface.OnClickListener() {&lt;br /&gt;    public void onClick(DialogInterface dlg, int sumthin) {&lt;br /&gt;    // do nothing – it will close on its own&lt;br /&gt;    }&lt;br /&gt;    })&lt;br /&gt;    .show(); &lt;br /&gt;   }&lt;br /&gt;    &lt;br /&gt;if( GreenValue&gt;=0 &amp;&amp; GreenValue&lt;=100) {&lt;br /&gt;     GreenProgress = 254*GreenValue/100;&lt;br /&gt;     SeekBarGreen.setProgress(GreenProgress);&lt;br /&gt;    }&lt;br /&gt;    &lt;br /&gt;    else {&lt;br /&gt;    new AlertDialog.Builder(this)&lt;br /&gt;    .setTitle("Alert!")&lt;br /&gt;    .setMessage("Please enter a value between 0 and 100 for GREEN...")&lt;br /&gt;    .setNeutralButton("Close", new DialogInterface.OnClickListener() {&lt;br /&gt;    public void onClick(DialogInterface dlg, int sumthin) {&lt;br /&gt;    // do nothing – it will close on its own&lt;br /&gt;    }&lt;br /&gt;    })&lt;br /&gt;    .show(); &lt;br /&gt;   }&lt;br /&gt;     &lt;br /&gt;    if(BlueValue&gt;=0 &amp;&amp; BlueValue&lt;=100) {&lt;br /&gt;     BlueProgress = 254*BlueValue/100;&lt;br /&gt;     SeekBarBlue.setProgress(BlueProgress);&lt;br /&gt;    }&lt;br /&gt;    &lt;br /&gt;   else {&lt;br /&gt;    new AlertDialog.Builder(this)&lt;br /&gt;    .setTitle("Alert!")&lt;br /&gt;    .setMessage("Please enter a value between 0 and 100 for BLUE...")&lt;br /&gt;    .setNeutralButton("Close", new DialogInterface.OnClickListener() {&lt;br /&gt;    public void onClick(DialogInterface dlg, int sumthin) {&lt;br /&gt;    // do nothing – it will close on its own&lt;br /&gt;    }&lt;br /&gt;    })&lt;br /&gt;    .show(); &lt;br /&gt;   }&lt;br /&gt;       &lt;br /&gt;    int color = Color.rgb(RedProgress, GreenProgress, BlueProgress);&lt;br /&gt;    layout.setBackgroundColor(color);&lt;br /&gt;    &lt;br /&gt;   }&lt;br /&gt;     &lt;br /&gt;};&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Play around with it.&lt;br /&gt;&lt;br /&gt;Feel happy to work in Android...&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3946478681282550454-8690461483733515609?l=som-itsolutions.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://som-itsolutions.blogspot.com/feeds/8690461483733515609/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=3946478681282550454&amp;postID=8690461483733515609' title='5 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3946478681282550454/posts/default/8690461483733515609'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3946478681282550454/posts/default/8690461483733515609'/><link rel='alternate' type='text/html' href='http://som-itsolutions.blogspot.com/2009/01/android-widget-through-java-code.html' title='Android Widget - through Java Code'/><author><name>Som</name><uri>http://www.blogger.com/profile/09519633424407534012</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='24' src='http://3.bp.blogspot.com/-XVhL110Tyf8/ThxKF3DBYcI/AAAAAAAAEBo/arVXUPsgtSg/s220/NJ%2B042.JPG'/></author><media:thumbnail xmlns:media='http://search.yahoo.com/mrss/' url='http://3.bp.blogspot.com/_PnYnrngiRvA/SqRG2jTunbI/AAAAAAAACBU/1Bz3BGx-mWs/s72-c/1.JPG' height='72' width='72'/><thr:total>5</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3946478681282550454.post-526997876541241625</id><published>2008-12-04T06:52:00.002+05:30</published><updated>2010-08-06T11:11:16.105+05:30</updated><title type='text'>Composite Design Pattern</title><content type='html'>Composite design pattern is a structural pattern in which we compose the whole-part relationship in a symmetric hierarchy. The client of the composite treats all the objects in the same fashion.&lt;br /&gt;The whole concept of this design pattern lies in the fact that we can treat a composite object which consists of several other objects the same way as a leaf object. The client never knows that it is working on an object which has many other objects inside it.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Let us try to understand the composite pattern with an example. Here we have defined a class namely Shape, which is acting as the root of all the objects in the example. We have put all the basic functionalities of a graphical object in this class. These functions are Add (for adding a component), Remove (for removing a component), GetChild (for getting a pointer to a child), GetParentOfComponent (which will return the parent of a component) and Draw (to draw a component).&lt;br /&gt;&lt;br /&gt;#include (iostream)&lt;br /&gt;#include (vector)&lt;br /&gt;#include (map)&lt;br /&gt;&lt;br /&gt;using namespace std;&lt;br /&gt;&lt;br /&gt;class Shape&lt;br /&gt;{&lt;br /&gt;public:&lt;br /&gt;Shape(){}&lt;br /&gt;virtual void Add(unsigned int id)&lt;br /&gt;{&lt;br /&gt;throw LeafClassTypeException();&lt;br /&gt;};&lt;br /&gt;virtual void Remove(unsigned int id){};&lt;br /&gt;&lt;br /&gt;//leaf classes will not override it..however, it will be overridden by the composite class.&lt;br /&gt;virtual Shape* GetChild(unsigned int id)&lt;br /&gt;{&lt;br /&gt;throw LeafClassTypeException();&lt;br /&gt;};&lt;br /&gt;&lt;br /&gt;//Using this reference the "Chain of Responsibility" can be implemented&lt;br /&gt;virtual Shape* GetParentOfComponent()&lt;br /&gt;{&lt;br /&gt;return ParentOfComponent;&lt;br /&gt;};&lt;br /&gt;&lt;br /&gt;virtual void SetParentOfComponent(Shape* s)&lt;br /&gt;{&lt;br /&gt;ParentOfComponent = s;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;virtual void Display(){};&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;virtual Shape* FindItem(unsigned int id); //implementation afterwards&lt;br /&gt;&lt;br /&gt;virtual ~Shape(){};&lt;br /&gt;&lt;br /&gt;protected:    &lt;br /&gt;Shape* ParentOfComponent;&lt;br /&gt;unsigned int resource_id;&lt;br /&gt;};&lt;br /&gt;&lt;br /&gt;typedef map (unsigned int, Shape*, less(unsigned int) ) theMap;&lt;br /&gt;&lt;br /&gt;theMap Resource_Map;&lt;br /&gt;theMap::iterator theIterator;&lt;br /&gt;&lt;br /&gt;Shape* Shape::FindItem(unsigned int id)&lt;br /&gt;{&lt;br /&gt;theIterator = Resource_Map.begin();&lt;br /&gt;while (theIterator != Resource_Map.end())&lt;br /&gt;{&lt;br /&gt;theIterator = Resource_Map.find(id);&lt;br /&gt;Shape* s = (*theIterator).second;&lt;br /&gt;theIterator++;&lt;br /&gt;return s;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;return NULL;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;Now from the Shape class, we have derived other graphic classes, like Point, Line and Rectangle. Among these classes, class Point is working as an helper class to define classes like Line and Rectangle. We have deduced another class called Picture which is composed of these component classes.&lt;br /&gt;&lt;br /&gt;class Point : public Shape&lt;br /&gt;{&lt;br /&gt;public:&lt;br /&gt;Point():x_Coord(0),y_Coord(0){}&lt;br /&gt;Point(int x, int y):x_Coord(x), y_Coord(y){}&lt;br /&gt;Point(const Point&amp; p)&lt;br /&gt;{&lt;br /&gt;x_Coord = p.x_Coord;&lt;br /&gt;y_Coord = p.y_Coord;&lt;br /&gt;}&lt;br /&gt;Point&amp; operator = (const Point&amp; p)&lt;br /&gt;{&lt;br /&gt;x_Coord = p.x_Coord;&lt;br /&gt;y_Coord = p.y_Coord;&lt;br /&gt;&lt;br /&gt;return *this;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;virtual void Display()&lt;br /&gt;{&lt;br /&gt;cout(("X Coordinate is:"((x_Coord((endl;&lt;br /&gt;cout(("Y Coordinate is:"((y_Coord((endl;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;int X_COORD() &lt;br /&gt;{&lt;br /&gt;return x_Coord;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;int Y_COORD()&lt;br /&gt;{&lt;br /&gt;return y_Coord;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;virtual ~Point(){}&lt;br /&gt;private:&lt;br /&gt;int x_Coord;&lt;br /&gt;int y_Coord;&lt;br /&gt;};&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;class Line : public Shape&lt;br /&gt;{&lt;br /&gt;private:&lt;br /&gt;Line(unsigned int id):begin(0,0),end(0,0)&lt;br /&gt;{&lt;br /&gt;resource_id = id;&lt;br /&gt;Resource_Map.insert(theMap::value_type(resource_id,(Shape*)this));&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;Line(unsigned int id, Point a, Point b):begin(a),end(b)&lt;br /&gt;{&lt;br /&gt;resource_id = id;&lt;br /&gt;Resource_Map.insert(theMap::value_type(resource_id,(Shape*)this));&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;public:&lt;br /&gt;virtual void Display()&lt;br /&gt;{&lt;br /&gt;cout(("Begining point is:";&lt;br /&gt;begin.Display();&lt;br /&gt;cout(("End Point is:";&lt;br /&gt;end.Display();&lt;br /&gt;}&lt;br /&gt;static Line* CreateLine(unsigned int id, Point a, Point b)&lt;br /&gt;{&lt;br /&gt;return new Line(id,a,b);&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;virtual ~Line(){}&lt;br /&gt;private:&lt;br /&gt;Point begin;&lt;br /&gt;Point end;&lt;br /&gt;};&lt;br /&gt;&lt;br /&gt;class Rectangle : public Shape&lt;br /&gt;{&lt;br /&gt;private:&lt;br /&gt;Rectangle(unsigned int id, Point&amp; p, int width, int height)&lt;br /&gt;{&lt;br /&gt;top_left = p;&lt;br /&gt;top_right = Point(p.X_COORD() + width, p.Y_COORD());&lt;br /&gt;bottom_left = Point(p.X_COORD() , p.Y_COORD() + height); &lt;br /&gt;bottom_right = Point(p.X_COORD() + width, p.Y_COORD() + height);&lt;br /&gt;resource_id = id;&lt;br /&gt;Resource_Map.insert(theMap::value_type(resource_id,(Shape*)this));&lt;br /&gt;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;public:&lt;br /&gt;static Rectangle* CreateRectange(unsigned int id, Point&amp; p, int width, int height)&lt;br /&gt;{&lt;br /&gt;return new Rectangle(id, p, width, height);&lt;br /&gt;&lt;br /&gt;}&lt;br /&gt;virtual ~Rectangle(){}&lt;br /&gt;virtual void Display()&lt;br /&gt;{&lt;br /&gt;cout(("The four vertices are:"((endl;&lt;br /&gt;cout(("Top Left :" ;&lt;br /&gt;top_left.Display();&lt;br /&gt;cout (("Top Right :";&lt;br /&gt;top_right.Display();&lt;br /&gt;cout(("Bottom Left :";&lt;br /&gt;bottom_left.Display();&lt;br /&gt;cout(("Bottom Right :";&lt;br /&gt;bottom_right.Display();&lt;br /&gt;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;//Attributes&lt;br /&gt;private:&lt;br /&gt;Point top_left;&lt;br /&gt;Point top_right;&lt;br /&gt;Point bottom_left;&lt;br /&gt;Point bottom_right;&lt;br /&gt;};&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;The interesting point here is that, we have tried to implement the leaf classes, namely Line and Rectangle as final classes by making their constructors private and providing static member functions to create them.&lt;br /&gt;&lt;br /&gt;The Picture class is composed of these leaf objects (Line and Rectangle).&lt;br /&gt;&lt;br /&gt;class Picture : public Shape&lt;br /&gt;{&lt;br /&gt;public:&lt;br /&gt;Picture(unsigned int id)&lt;br /&gt;{&lt;br /&gt;resource_id = id;&lt;br /&gt;Resource_Map.insert(theMap::value_type(resource_id,(Shape*)this));&lt;br /&gt;}&lt;br /&gt;virtual void Display()&lt;br /&gt;{&lt;br /&gt;vector(Shape*)::iterator p = Components.begin();&lt;br /&gt;while (p != Components.end())&lt;br /&gt;{&lt;br /&gt;(*p)-)Display();&lt;br /&gt;p++;&lt;br /&gt;}&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;//Adds the component with the resource id equal to the passed parameter&lt;br /&gt;virtual void Add (unsigned int id)&lt;br /&gt;{&lt;br /&gt;Shape* s = FindItem(id);&lt;br /&gt;&lt;br /&gt;Components.push_back(s);&lt;br /&gt;&lt;br /&gt;s-)SetParentOfComponent(this);&lt;br /&gt;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;//removes the  component from the list with the resource_id equal to the parameter passed&lt;br /&gt;virtual void Remove(unsigned int id)&lt;br /&gt;{&lt;br /&gt;Shape* s = FindItem(id);&lt;br /&gt;vector(Shape*)::iterator p = Components.begin();&lt;br /&gt;int pos = 0;&lt;br /&gt;while (p != Components.end())&lt;br /&gt;{&lt;br /&gt;if(Components.at(pos) == s)&lt;br /&gt;break;&lt;br /&gt;pos++;&lt;br /&gt;p++;&lt;br /&gt;}&lt;br /&gt;Components.erase(p);&lt;br /&gt;s-)SetParentOfComponent(NULL);&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;//will return the chile having the id equal to the passed value.&lt;br /&gt;virtual Shape* GetChild (unsigned int id)&lt;br /&gt;{&lt;br /&gt;return FindItem(id);&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;virtual ~Picture()&lt;br /&gt;{&lt;br /&gt;vector(Shape*)::iterator p = Components.begin();&lt;br /&gt;&lt;br /&gt;int pos = 0;&lt;br /&gt;while (p != Components.end())&lt;br /&gt;{&lt;br /&gt;delete(Components.at(pos));&lt;br /&gt;p++;&lt;br /&gt;pos++;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Components.clear();&lt;br /&gt;}&lt;br /&gt;private:&lt;br /&gt;vector(Shape*) Components;&lt;br /&gt;};&lt;br /&gt;&lt;br /&gt;The Shape class is called as the Component class, the Line and Rectangle classes are called the Leaf classes and the Picture class is called the Composite class.&lt;br /&gt;&lt;br /&gt;Another interesting part of the example is that here every component is identifiable through its resource id. Whenever we create an object (leaf or composite object), it creates a key pair of the id and the pointer to that object and pushes this key into a MAP, from which we can easily search for that component in later times through its resource id.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;There are many issues to consider when implementing the composite pattern.&lt;br /&gt;&lt;br /&gt;We have defined one function called GetParentOfComponent. This can be useful to traverse the whole hierarchy of parent-child relationship. We have to make sure that any child can have only a composite object as its parent. We have ensured it by defining an Exception class which will be thrown the moment we want to add a component to a leaf object. The exception class can be defined as follows: &lt;br /&gt;class LeafClassTypeException&lt;br /&gt;{&lt;br /&gt;public:&lt;br /&gt;void printerrormsg()&lt;br /&gt;{&lt;br /&gt;cout(("This is a leaf class"((endl;&lt;br /&gt;}&lt;br /&gt;};  &lt;br /&gt;It should be noted that the functions like Add and Remove have been defined in the root class. Although for leaf classes, it does not do any meaningful things except throwing an exception, but it gives us transparency, because we can treat all components uniformly.&lt;br /&gt;If we define these functions at the composite class level, then it would give the safety, because any attempt to Add or Remove from the leaf classes would give compile time error, but we would loose the transparency. The composite and the leaf classes will have different interfaces in this case.&lt;br /&gt;&lt;br /&gt;The main participants in this design pattern are&lt;br /&gt;Component (Shape) : It basically works as an abstract class which provides a common interface which will be used by the client to treat different classes uniformly. The common functionalities (e.g. Display) have been defined here. Other functionalities like Add, Remove, etc have been put in this class to maximize the role of this interface. The default behavior for Add and Remove has been implemented in such a fashion that for a leaf class, these functions will throw exceptions.&lt;br /&gt;Leaf (Line, Rectangle, etc) : It represents a leaf objects in the composition. Leaf objects cannot have any children.&lt;br /&gt;Composite (Picture) : It stores child components.&lt;br /&gt;Client: It manipulates the objects through the common interface exposed by the Component class.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3946478681282550454-526997876541241625?l=som-itsolutions.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://som-itsolutions.blogspot.com/feeds/526997876541241625/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=3946478681282550454&amp;postID=526997876541241625' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3946478681282550454/posts/default/526997876541241625'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3946478681282550454/posts/default/526997876541241625'/><link rel='alternate' type='text/html' href='http://som-itsolutions.blogspot.com/2008/12/composite-design-pattern-is-structural.html' title='Composite Design Pattern'/><author><name>Som</name><uri>http://www.blogger.com/profile/09519633424407534012</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='24' src='http://3.bp.blogspot.com/-XVhL110Tyf8/ThxKF3DBYcI/AAAAAAAAEBo/arVXUPsgtSg/s220/NJ%2B042.JPG'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3946478681282550454.post-9129294747574637070</id><published>2008-11-14T05:00:00.001+05:30</published><updated>2008-11-14T05:00:58.775+05:30</updated><title type='text'>Test Driven Development</title><content type='html'>&lt;iframe src='http://docs.google.com/EmbedSlideshow?docid=dcgcp339_300f9ktxvgq' frameborder='0' width='410' height='342'&gt;&lt;/iframe&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3946478681282550454-9129294747574637070?l=som-itsolutions.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://som-itsolutions.blogspot.com/feeds/9129294747574637070/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=3946478681282550454&amp;postID=9129294747574637070' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3946478681282550454/posts/default/9129294747574637070'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3946478681282550454/posts/default/9129294747574637070'/><link rel='alternate' type='text/html' href='http://som-itsolutions.blogspot.com/2008/11/test-driven-development_6785.html' title='Test Driven Development'/><author><name>Som</name><uri>http://www.blogger.com/profile/09519633424407534012</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='24' src='http://3.bp.blogspot.com/-XVhL110Tyf8/ThxKF3DBYcI/AAAAAAAAEBo/arVXUPsgtSg/s220/NJ%2B042.JPG'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3946478681282550454.post-4197446721098385816</id><published>2008-09-10T04:00:00.003+05:30</published><updated>2011-05-14T09:58:59.111+05:30</updated><title type='text'>Active Objects of Symbian - in the lights of Client-Server Architecture</title><content type='html'>&lt;div dir="ltr" style="text-align: left;" trbidi="on"&gt;&lt;br /&gt;When I started understanding Active Object framework in Symbian, it was difficult for me to grasp the idea how the front end UI is not frozen, in the event of long running task, even when we don't use multiple threads. But when i started understanding the active object framework in conjunction with the client-server architecture of symbian, I got the idea. I would like to share it with you.&lt;br /&gt;&lt;br /&gt;Before we start, i want to throw some lights on the definition of Asynchronous Service Provider and Asynchronous functions in Symbian Active Object and Client-Server architecture. Asynchronous Service Providers are the functions which are fired from a client and returns immediately in that client. However, this function causes another function in the server to run. This server function may be blocking in server side. So we get two sides of a function. We get a non-blocking function in the client-side which initiates another function in the server side, which may be blocking, in the server side. Once the function in the server side finishes, it notifies the client side (which actually initiates the whole chain) about this. These asynchronous functions have TRequestStatus as one of the parameters which is passed as a reference from the client to the server.&lt;br /&gt;&lt;br /&gt;These are all theoretical aspects of the Active object and Client-Server framework. Let me give you one practical scenario where this can be used. In this context i would also like to share what actually happens in a normal multi threaded application.&lt;br /&gt;&lt;br /&gt;Suppose, we have a communication port which is continuously receiving data from an external source. Suppose we need to develop an application which will read the data and at the same time will render that data in some short of graphical form. So how is it possible?&lt;br /&gt;&lt;br /&gt;In symbian environment, we can realize this scenario by employing the Active object framework in conjunction with the client-server architecture. Let me explain it in more details. We may delegate the task of reading the data from the communication port to a server application which will run as a different process than the front end UI application. Of course there are such functionalities already developed in the Symbian and related frameworks. But just for the sake of explanation, we will have to create an asynchronous function in the server which will actually read the data from the communication port. So in the server this function will be blocking. However, we may create an UI application using the active object framework, which will initiate this call to the server and will immediately return in the UI application (non-blocking). The moment, the server finishes reading certain amount of data (say 1024 Kb) and copying it to the UI application's memory area, (remember the UI application and the server are across the process boundary), it will notify the front end UI about this and again start reading the data from the port in the background. On the other hand, the UI application will render the data in the graphical format.&lt;br /&gt;&lt;br /&gt;Now let me tell you how this is possible in an Windows application. Once I had developed one such application using the Windows asynchronous I/O pattern and windows event mechanism. There the task of reading of the data&amp;nbsp; from the communication port was delegated to a background thread. The background thread used to read the data and when it finishes some specific amount it used to fire an event to the front end UI, which then rendered the data in the front end UI.&lt;br /&gt;&lt;br /&gt;This is all about theories and scenarios. Now, let me give you a real life symbian code which has got two applications. One is an UI application which has got an engine. This engine is working as an active object for this UI application. Then we have a Symbian Client-Server application. This application has got a client side interface which is a DLL and a Server side implementation which is developed as an EXE. The server has an Asynchronous function which will eventually be called from the UI application.The UI application is linked with the dynamic link library (DLL) of the client-server application.&lt;br /&gt;&lt;br /&gt;Let us start from the client-server application. The client has just three exported functions. One is an Asynchronous function and the other if we cancel that function. And the third one is to connect to the server. It looks like the following:&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;span id="msfc" style="color: yellow;"&gt;//client.h&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span id="msfc0" style="color: yellow;"&gt;class RClient : public RSessionBase&lt;/span&gt;&lt;br /&gt;&lt;span id="msfc1" style="color: yellow;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;/span&gt;&lt;br /&gt;&lt;span id="msfc2" style="color: yellow;"&gt;public:&lt;/span&gt;&lt;br /&gt;&lt;span id="msfc3" style="color: yellow;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; IMPORT_C TInt Connect();&lt;/span&gt;&lt;br /&gt;&lt;span id="msfc4" style="color: yellow;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; IMPORT_C void GetNotifiedWhenEventCompleted(TInt aCount, TDes&amp;amp; aData, TRequestStatus&amp;amp; aStatus);&lt;/span&gt;&lt;br /&gt;&lt;span id="msfc5" style="color: yellow;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; IMPORT_C void CancelGetNotifiedWhenEventCompleted();&lt;/span&gt;&lt;br /&gt;&lt;span id="msfc6" style="color: yellow;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; };&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;The implementation of the client looks like the following:&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;span id="oj5r" style="color: yellow;"&gt;// client.cpp&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span id="oj5r0" style="color: yellow;"&gt;#include "client.h"&lt;/span&gt;&lt;br /&gt;&lt;span id="oj5r1" style="color: yellow;"&gt;#include "client-server.h"&lt;/span&gt;&lt;br /&gt;&lt;span id="oj5r2" style="color: yellow;"&gt;#include &amp;lt;e32math.h&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span id="oj5r3" style="color: yellow;"&gt;// Runs client-side and starts the separate server process&lt;/span&gt;&lt;br /&gt;&lt;span id="oj5r4" style="color: yellow;"&gt;static TInt StartTheServer()&lt;/span&gt;&lt;br /&gt;&lt;span id="oj5r5" style="color: yellow;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;/span&gt;&lt;br /&gt;&lt;span id="oj5r6" style="color: yellow;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; RProcess server;&lt;/span&gt;&lt;br /&gt;&lt;span id="oj5r7" style="color: yellow;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; TInt r=server.Create(KServerBinaryName, KNullDesC);&lt;/span&gt;&lt;br /&gt;&lt;span id="oj5r8" style="color: yellow;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; if (r!=KErrNone)&lt;/span&gt;&lt;br /&gt;&lt;span id="oj5r9" style="color: yellow;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; return r;&lt;/span&gt;&lt;br /&gt;&lt;span id="oj5r10" style="color: yellow;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;br /&gt;&lt;span id="oj5r11" style="color: yellow;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; TRequestStatus stat;&lt;/span&gt;&lt;br /&gt;&lt;span id="oj5r12" style="color: yellow;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; server.Rendezvous(stat);&lt;/span&gt;&lt;br /&gt;&lt;span id="oj5r13" style="color: yellow;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; if (stat!=KRequestPending)&lt;/span&gt;&lt;br /&gt;&lt;span id="oj5r14" style="color: yellow;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; server.Kill(0);&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; // abort startup&lt;/span&gt;&lt;br /&gt;&lt;span id="oj5r15" style="color: yellow;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; else&lt;/span&gt;&lt;br /&gt;&lt;span id="oj5r16" style="color: yellow;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; server.Resume();&amp;nbsp;&amp;nbsp;&amp;nbsp; // logon OK - start the server&lt;/span&gt;&lt;br /&gt;&lt;span id="oj5r17" style="color: yellow;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;br /&gt;&lt;span id="oj5r18" style="color: yellow;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; User::WaitForRequest(stat);&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; // wait for start or death&lt;/span&gt;&lt;br /&gt;&lt;span id="oj5r19" style="color: yellow;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;br /&gt;&lt;span id="oj5r20" style="color: yellow;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; // Check the exit type.&lt;/span&gt;&lt;br /&gt;&lt;span id="oj5r21" style="color: yellow;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; // We can't use the 'exit reason' because if the server panicked this&lt;/span&gt;&lt;br /&gt;&lt;span id="oj5r22" style="color: yellow;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; // is set to the panic 'reason' (which may be '0' and cannot thus be distinguished&lt;/span&gt;&lt;br /&gt;&lt;span id="oj5r23" style="color: yellow;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; // from KErrNone)&lt;/span&gt;&lt;br /&gt;&lt;span id="oj5r24" style="color: yellow;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; r = server.ExitType();&lt;/span&gt;&lt;br /&gt;&lt;span id="oj5r25" style="color: yellow;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; if (EExitPanic==r)&lt;/span&gt;&lt;br /&gt;&lt;span id="oj5r26" style="color: yellow;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; r = KErrGeneral; &lt;/span&gt;&lt;br /&gt;&lt;span id="oj5r27" style="color: yellow;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; else&lt;/span&gt;&lt;br /&gt;&lt;span id="oj5r28" style="color: yellow;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; r = stat.Int();&lt;/span&gt;&lt;br /&gt;&lt;span id="oj5r29" style="color: yellow;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;br /&gt;&lt;span id="oj5r30" style="color: yellow;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; server.Close(); // This is no longer needed&lt;/span&gt;&lt;br /&gt;&lt;span id="oj5r31" style="color: yellow;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; return r;&lt;/span&gt;&lt;br /&gt;&lt;span id="oj5r32" style="color: yellow;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;span id="oj5r33" style="color: yellow;"&gt;EXPORT_C TInt RClient::Connect()&lt;/span&gt;&lt;br /&gt;&lt;span id="oj5r34" style="color: yellow;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;/span&gt;&lt;br /&gt;&lt;span id="oj5r35" style="color: yellow;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; TInt retry=2;&lt;/span&gt;&lt;br /&gt;&lt;span id="oj5r36" style="color: yellow;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; for (;;)&lt;/span&gt;&lt;br /&gt;&lt;span id="oj5r37" style="color: yellow;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; {// Uses system-pool message slots&lt;/span&gt;&lt;br /&gt;&lt;span id="oj5r38" style="color: yellow;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; TInt r=CreateSession(KServerName,TVersion(1,0,0));&lt;/span&gt;&lt;br /&gt;&lt;span id="oj5r39" style="color: yellow;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; if ( (KErrNotFound!=r) &amp;amp;&amp;amp; (KErrServerTerminated!=r) )&lt;/span&gt;&lt;br /&gt;&lt;span id="oj5r40" style="color: yellow;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; return (r);&lt;/span&gt;&lt;br /&gt;&lt;span id="oj5r41" style="color: yellow;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; if (--retry==0)&lt;/span&gt;&lt;br /&gt;&lt;span id="oj5r42" style="color: yellow;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; return (r);&lt;/span&gt;&lt;br /&gt;&lt;span id="oj5r43" style="color: yellow;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; r=StartTheServer();&lt;/span&gt;&lt;br /&gt;&lt;span id="oj5r44" style="color: yellow;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; if ( (KErrNone!=r) &amp;amp;&amp;amp; (KErrAlreadyExists!=r) )&lt;/span&gt;&lt;br /&gt;&lt;span id="oj5r45" style="color: yellow;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; return (r);&lt;/span&gt;&lt;br /&gt;&lt;span id="oj5r46" style="color: yellow;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;/span&gt;&lt;br /&gt;&lt;span id="oj5r47" style="color: yellow;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span id="oj5r48" style="color: yellow;"&gt;EXPORT_C void RClient::GetNotifiedWhenEventCompleted(TInt aCount, TDes&amp;amp; aData, TRequestStatus&amp;amp; aStatus)&lt;/span&gt;&lt;br /&gt;&lt;span id="oj5r49" style="color: yellow;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;/span&gt;&lt;br /&gt;&lt;span id="oj5r50" style="color: yellow;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; TIpcArgs args(aCount,&amp;amp;aData);&lt;/span&gt;&lt;br /&gt;&lt;span id="oj5r51" style="color: yellow;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; SendReceive(EGetNotifiedWhenEventCompleted, args, aStatus);&lt;/span&gt;&lt;br /&gt;&lt;span id="oj5r52" style="color: yellow;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;/span&gt;&lt;br /&gt;&lt;span id="oj5r53" style="color: yellow;"&gt;EXPORT_C void RClient::CancelGetNotifiedWhenEventCompleted()&lt;/span&gt;&lt;br /&gt;&lt;span id="oj5r54" style="color: yellow;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;/span&gt;&lt;br /&gt;&lt;span id="oj5r55" style="color: yellow;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; SendReceive(ECancelGetNotifiedWhenEventCompleted, TIpcArgs());&lt;/span&gt;&lt;br /&gt;&lt;span id="oj5r56" style="color: yellow;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;These are pretty staright forward. I am not going in details about the client server architecture of a symbian application. I am more interested in explaining you about how an asynchrounous function is handled in the client-server and active object framework.&lt;br /&gt;&lt;br /&gt;Now let me focus on the server side implementation of this application.&lt;br /&gt;&lt;br /&gt;The server header file looks like the following:&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;span id="q1wr" style="color: yellow;"&gt;// server.h&lt;/span&gt;&lt;br /&gt;&lt;span id="q1wr0" style="color: yellow;"&gt;#ifndef __SERVER_H__&lt;/span&gt;&lt;br /&gt;&lt;span id="q1wr1" style="color: yellow;"&gt;#define __SERVER_H__&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span id="q1wr2" style="color: yellow;"&gt;#include &amp;lt;e32base.h&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;span id="q1wr3" style="color: yellow;"&gt;#include "client-server.h"&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span id="q1wr4" style="color: yellow;"&gt;enum TServerPanic&lt;/span&gt;&lt;br /&gt;&lt;span id="q1wr5" style="color: yellow;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;/span&gt;&lt;br /&gt;&lt;span id="q1wr6" style="color: yellow;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; EPanicBadDescriptor,&lt;/span&gt;&lt;br /&gt;&lt;span id="q1wr7" style="color: yellow;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; EPanicNotSupported&lt;/span&gt;&lt;br /&gt;&lt;span id="q1wr8" style="color: yellow;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; };&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span id="q1wr9" style="color: yellow;"&gt;void PanicClient(const RMessage2&amp;amp; aMessage,TServerPanic TMyPanic);&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span id="q1wr10" style="color: yellow;"&gt;const TInt KShutdownDelay=200000; // approx 2 seconds&lt;/span&gt;&lt;br /&gt;&lt;span id="q1wr11" style="color: yellow;"&gt;class CShutdown : public CTimer&lt;/span&gt;&lt;br /&gt;&lt;span id="q1wr12" style="color: yellow;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;/span&gt;&lt;br /&gt;&lt;span id="q1wr13" style="color: yellow;"&gt;public:&lt;/span&gt;&lt;br /&gt;&lt;span id="q1wr14" style="color: yellow;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; inline CShutdown();&lt;/span&gt;&lt;br /&gt;&lt;span id="q1wr15" style="color: yellow;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; inline void ConstructL();&lt;/span&gt;&lt;br /&gt;&lt;span id="q1wr16" style="color: yellow;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; inline void Start();&lt;/span&gt;&lt;br /&gt;&lt;span id="q1wr17" style="color: yellow;"&gt;private:&lt;/span&gt;&lt;br /&gt;&lt;span id="q1wr18" style="color: yellow;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; void RunL();&lt;/span&gt;&lt;br /&gt;&lt;span id="q1wr19" style="color: yellow;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; };&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;span id="q1wr20" style="color: yellow;"&gt;inline CShutdown::CShutdown()&lt;/span&gt;&lt;br /&gt;&lt;span id="q1wr21" style="color: yellow;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; :CTimer(-1)&lt;/span&gt;&lt;br /&gt;&lt;span id="q1wr22" style="color: yellow;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; {CActiveScheduler::Add(this);}&lt;/span&gt;&lt;br /&gt;&lt;span id="q1wr23" style="color: yellow;"&gt;inline void CShutdown::ConstructL()&lt;/span&gt;&lt;br /&gt;&lt;span id="q1wr24" style="color: yellow;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; {CTimer::ConstructL();}&lt;/span&gt;&lt;br /&gt;&lt;span id="q1wr25" style="color: yellow;"&gt;inline void CShutdown::Start()&lt;/span&gt;&lt;br /&gt;&lt;span id="q1wr26" style="color: yellow;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; {After(KShutdownDelay);}&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;span id="q1wr27" style="color: yellow;"&gt;class CMyServer : public CServer2&lt;/span&gt;&lt;br /&gt;&lt;span id="q1wr28" style="color: yellow;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;/span&gt;&lt;br /&gt;&lt;span id="q1wr29" style="color: yellow;"&gt;public:&lt;/span&gt;&lt;br /&gt;&lt;span id="q1wr30" style="color: yellow;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; static CServer2* NewLC();&lt;/span&gt;&lt;br /&gt;&lt;span id="q1wr31" style="color: yellow;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; void AddSession();&lt;/span&gt;&lt;br /&gt;&lt;span id="q1wr32" style="color: yellow;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; void RemoveSession();&lt;/span&gt;&lt;br /&gt;&lt;span id="q1wr33" style="color: yellow;"&gt;private:&lt;/span&gt;&lt;br /&gt;&lt;span id="q1wr34" style="color: yellow;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; CMyServer();&lt;/span&gt;&lt;br /&gt;&lt;span id="q1wr35" style="color: yellow;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; void ConstructL();&lt;/span&gt;&lt;br /&gt;&lt;span id="q1wr36" style="color: yellow;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; // From CServer2&lt;/span&gt;&lt;br /&gt;&lt;span id="q1wr37" style="color: yellow;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; virtual CSession2* NewSessionL(const TVersion&amp;amp; aVersion,const RMessage2&amp;amp; aMessage) const; &lt;/span&gt;&lt;br /&gt;&lt;span id="q1wr38" style="color: yellow;"&gt;private:&lt;/span&gt;&lt;br /&gt;&lt;span id="q1wr39" style="color: yellow;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; TInt iSessionCount;&lt;/span&gt;&lt;br /&gt;&lt;span id="q1wr40" style="color: yellow;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; CShutdown iShutdown;&lt;/span&gt;&lt;br /&gt;&lt;span id="q1wr41" style="color: yellow;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; };&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;span id="q1wr42" style="color: yellow;"&gt;inline CMyServer::CMyServer()&lt;/span&gt;&lt;br /&gt;&lt;span id="q1wr43" style="color: yellow;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; :CServer2(CActive::EPriorityStandard)&lt;/span&gt;&lt;br /&gt;&lt;span id="q1wr44" style="color: yellow;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; {}&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;span id="q1wr45" style="color: yellow;"&gt;class CAsyncHandler; // Active object class for asynchronous requests&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span id="q1wr46" style="color: yellow;"&gt;class CMyServerSession : public CSession2&lt;/span&gt;&lt;br /&gt;&lt;span id="q1wr47" style="color: yellow;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;/span&gt;&lt;br /&gt;&lt;span id="q1wr48" style="color: yellow;"&gt;public:&lt;/span&gt;&lt;br /&gt;&lt;span id="q1wr49" style="color: yellow;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; CMyServerSession();&lt;/span&gt;&lt;br /&gt;&lt;span id="q1wr50" style="color: yellow;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; void CreateL();&lt;/span&gt;&lt;br /&gt;&lt;span id="q1wr51" style="color: yellow;"&gt;public:&lt;/span&gt;&lt;br /&gt;&lt;span id="q1wr52" style="color: yellow;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; virtual void ServiceL(const RMessage2&amp;amp; aMessage); // From CSession2&lt;/span&gt;&lt;br /&gt;&lt;span id="q1wr53" style="color: yellow;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; virtual void ServiceError(const RMessage2&amp;amp; aMessage, TInt aError); // From CSession2&lt;/span&gt;&lt;br /&gt;&lt;span id="q1wr54" style="color: yellow;"&gt;private:&lt;/span&gt;&lt;br /&gt;&lt;span id="q1wr55" style="color: yellow;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; void GetNotifiedWhenEventCompletedL(const RMessage2&amp;amp; aMessage);&lt;/span&gt;&lt;br /&gt;&lt;span id="q1wr56" style="color: yellow;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; void CancelGetNotifiedWhenEventCompletedL(const RMessage2&amp;amp; aMessage);&lt;/span&gt;&lt;br /&gt;&lt;span id="q1wr57" style="color: yellow;"&gt;private:&lt;/span&gt;&lt;br /&gt;&lt;span id="q1wr58" style="color: yellow;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; ~CMyServerSession();&lt;/span&gt;&lt;br /&gt;&lt;span id="q1wr59" style="color: yellow;"&gt;private:&lt;/span&gt;&lt;br /&gt;&lt;span id="q1wr60" style="color: yellow;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; CAsyncHandler* iAsyncRequestHandler;&lt;/span&gt;&lt;br /&gt;&lt;span id="q1wr61" style="color: yellow;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; HBufC8* iClientBuf;&lt;/span&gt;&lt;br /&gt;&lt;span id="q1wr62" style="color: yellow;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; };&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span id="q1wr63" style="color: yellow;"&gt;inline CMyServerSession::CMyServerSession()&lt;/span&gt;&lt;br /&gt;&lt;span id="q1wr64" style="color: yellow;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; {}&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;span id="q1wr65" style="color: yellow;"&gt;// Skeleton active object, for asynchronous server requests&lt;/span&gt;&lt;br /&gt;&lt;span id="q1wr66" style="color: yellow;"&gt;// Uses a very basic timer for asynchronicity&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span id="q1wr67" style="color: yellow;"&gt;class CAsyncHandler : public CActive&lt;/span&gt;&lt;br /&gt;&lt;span id="q1wr68" style="color: yellow;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;/span&gt;&lt;br /&gt;&lt;span id="q1wr69" style="color: yellow;"&gt;public:&lt;/span&gt;&lt;br /&gt;&lt;span id="q1wr70" style="color: yellow;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; static CAsyncHandler* NewL();&lt;/span&gt;&lt;br /&gt;&lt;span id="q1wr71" style="color: yellow;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; static CAsyncHandler* NewLC();&lt;/span&gt;&lt;br /&gt;&lt;span id="q1wr72" style="color: yellow;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; ~CAsyncHandler();&lt;/span&gt;&lt;br /&gt;&lt;span id="q1wr73" style="color: yellow;"&gt;public:&lt;/span&gt;&lt;br /&gt;&lt;span id="q1wr74" style="color: yellow;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; void ServiceAsyncRequest(const RMessage2&amp;amp; aMessage);&lt;/span&gt;&lt;br /&gt;&lt;span id="q1wr75" style="color: yellow;"&gt;protected:&lt;/span&gt;&lt;br /&gt;&lt;span id="q1wr76" style="color: yellow;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; CAsyncHandler();&lt;/span&gt;&lt;br /&gt;&lt;span id="q1wr77" style="color: yellow;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; void ConstructL();&lt;/span&gt;&lt;br /&gt;&lt;span id="q1wr78" style="color: yellow;"&gt;private:&lt;/span&gt;&lt;br /&gt;&lt;span id="q1wr79" style="color: yellow;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; void DoCancel();&lt;/span&gt;&lt;br /&gt;&lt;span id="q1wr80" style="color: yellow;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; void RunL();&lt;/span&gt;&lt;br /&gt;&lt;span id="q1wr81" style="color: yellow;"&gt;private:&lt;/span&gt;&lt;br /&gt;&lt;span id="q1wr82" style="color: yellow;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; RTimer iTimer;&lt;/span&gt;&lt;br /&gt;&lt;span id="q1wr83" style="color: yellow;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; RMessage2 iMessage;&lt;/span&gt;&lt;br /&gt;&lt;span id="q1wr84" style="color: yellow;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; };&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;span id="q1wr85" style="color: yellow;"&gt;#endif //__SERVER_H__&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;And the server implementation file looks like the following:&lt;br /&gt;&lt;br /&gt;&lt;span id="wu99" style="color: yellow;"&gt;// server.cpp&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span id="wu990" style="color: yellow;"&gt;#include "server.h"&lt;/span&gt;&lt;br /&gt;&lt;span id="wu991" style="color: yellow;"&gt;#include &amp;lt;e32base.h&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span id="wu992" style="color: yellow;"&gt;_LIT(KDesMsgToServer, "To Server;");&lt;/span&gt;&lt;br /&gt;&lt;span id="wu993" style="color: yellow;"&gt;// Called by the CServer framework&lt;/span&gt;&lt;br /&gt;&lt;span id="wu994" style="color: yellow;"&gt;void CMyServerSession::CreateL()&lt;/span&gt;&lt;br /&gt;&lt;span id="wu995" style="color: yellow;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;/span&gt;&lt;br /&gt;&lt;span id="wu996" style="color: yellow;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; CMyServer* server = static_cast&amp;lt;CMyServer*&amp;gt;(const_cast&amp;lt;CServer2*&amp;gt;(Server()));&lt;/span&gt;&lt;br /&gt;&lt;span id="wu997" style="color: yellow;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; ASSERT(server);&lt;/span&gt;&lt;br /&gt;&lt;span id="wu998" style="color: yellow;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; server-&amp;gt;AddSession();&lt;/span&gt;&lt;br /&gt;&lt;span id="wu999" style="color: yellow;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; iAsyncRequestHandler = CAsyncHandler::NewL();&lt;/span&gt;&lt;br /&gt;&lt;span id="wu9910" style="color: yellow;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span id="wu9911" style="color: yellow;"&gt;CMyServerSession::~CMyServerSession()&lt;/span&gt;&lt;br /&gt;&lt;span id="wu9912" style="color: yellow;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;/span&gt;&lt;br /&gt;&lt;span id="wu9913" style="color: yellow;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; CMyServer* server = static_cast&amp;lt;CMyServer*&amp;gt;(const_cast&amp;lt;CServer2*&amp;gt;(Server()));&lt;/span&gt;&lt;br /&gt;&lt;span id="wu9914" style="color: yellow;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; ASSERT(server);&lt;/span&gt;&lt;br /&gt;&lt;span id="wu9915" style="color: yellow;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; server-&amp;gt;RemoveSession();&lt;/span&gt;&lt;br /&gt;&lt;span id="wu9916" style="color: yellow;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; delete iAsyncRequestHandler;&lt;/span&gt;&lt;br /&gt;&lt;span id="wu9917" style="color: yellow;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; delete iClientBuf;&lt;/span&gt;&lt;br /&gt;&lt;span id="wu9918" style="color: yellow;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span id="wu9919" style="color: yellow;"&gt;// A bad descriptor error implies a badly programmed client, so panic it&lt;/span&gt;&lt;br /&gt;&lt;span id="wu9920" style="color: yellow;"&gt;// Report other errors to the client by completing the outstanding request with the error&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span id="wu9921" style="color: yellow;"&gt;void CMyServerSession::ServiceError(const RMessage2&amp;amp; aMessage, TInt aError)&lt;/span&gt;&lt;br /&gt;&lt;span id="wu9922" style="color: yellow;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;/span&gt;&lt;br /&gt;&lt;span id="wu9923" style="color: yellow;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; if (KErrBadDescriptor==aError)&lt;/span&gt;&lt;br /&gt;&lt;span id="wu9924" style="color: yellow;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; PanicClient(aMessage,EPanicBadDescriptor);&lt;/span&gt;&lt;br /&gt;&lt;span id="wu9925" style="color: yellow;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; else&lt;/span&gt;&lt;br /&gt;&lt;span id="wu9926" style="color: yellow;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; aMessage.Complete(aError);&lt;/span&gt;&lt;br /&gt;&lt;span id="wu9927" style="color: yellow;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span id="wu9928" style="color: yellow;"&gt;// Handle a client request&lt;/span&gt;&lt;br /&gt;&lt;span id="wu9929" style="color: yellow;"&gt;void CMyServerSession::ServiceL(const RMessage2&amp;amp; aMessage)&lt;/span&gt;&lt;br /&gt;&lt;span id="wu9930" style="color: yellow;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;/span&gt;&lt;br /&gt;&lt;span id="wu9931" style="color: yellow;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; switch (aMessage.Function())&lt;/span&gt;&lt;br /&gt;&lt;span id="wu9932" style="color: yellow;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;/span&gt;&lt;br /&gt;&lt;span id="wu9933" style="color: yellow;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; case EGetNotifiedWhenEventCompleted:&lt;/span&gt;&lt;br /&gt;&lt;span id="wu9934" style="color: yellow;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; GetNotifiedWhenEventCompletedL(aMessage);&lt;/span&gt;&lt;br /&gt;&lt;span id="wu9935" style="color: yellow;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; break;&lt;/span&gt;&lt;br /&gt;&lt;span id="wu9936" style="color: yellow;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;br /&gt;&lt;span id="wu9937" style="color: yellow;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; case ECancelGetNotifiedWhenEventCompleted:&lt;/span&gt;&lt;br /&gt;&lt;span id="wu9938" style="color: yellow;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; CancelGetNotifiedWhenEventCompletedL(aMessage);&lt;/span&gt;&lt;br /&gt;&lt;span id="wu9939" style="color: yellow;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; break;&lt;/span&gt;&lt;br /&gt;&lt;span id="wu9940" style="color: yellow;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; default:&lt;/span&gt;&lt;br /&gt;&lt;span id="wu9941" style="color: yellow;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; PanicClient(aMessage,EPanicNotSupported);&lt;/span&gt;&lt;br /&gt;&lt;span id="wu9942" style="color: yellow;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; break;&lt;/span&gt;&lt;br /&gt;&lt;span id="wu9943" style="color: yellow;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;/span&gt;&lt;br /&gt;&lt;span id="wu9944" style="color: yellow;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span id="wu9945" style="color: yellow;"&gt;// Asynchronous method&lt;/span&gt;&lt;br /&gt;&lt;span id="wu9946" style="color: yellow;"&gt;// message slot 0 contains TInt&lt;/span&gt;&lt;br /&gt;&lt;span id="wu9947" style="color: yellow;"&gt;// message slot 1 contains TDes8&amp;amp;&lt;/span&gt;&lt;br /&gt;&lt;span id="wu9948" style="color: yellow;"&gt;void CMyServerSession::GetNotifiedWhenEventCompletedL(const RMessage2&amp;amp; aMessage)&lt;/span&gt;&lt;br /&gt;&lt;span id="wu9949" style="color: yellow;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;/span&gt;&lt;br /&gt;&lt;span id="wu9950" style="color: yellow;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; TInt val0 = aMessage.Int0();&lt;/span&gt;&lt;br /&gt;&lt;span id="wu9951" style="color: yellow;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; if (val0!=10)&lt;/span&gt;&lt;br /&gt;&lt;span id="wu9952" style="color: yellow;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; aMessage.Complete(KErrGeneral);&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span id="wu9953" style="color: yellow;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; // Determine the length of the client descriptor passed to the server&lt;/span&gt;&lt;br /&gt;&lt;span id="wu9954" style="color: yellow;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; TInt clientDesMaxLen = aMessage.GetDesMaxLength(1);&lt;/span&gt;&lt;br /&gt;&lt;span id="wu9955" style="color: yellow;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; if (iClientBuf)&lt;/span&gt;&lt;br /&gt;&lt;span id="wu9956" style="color: yellow;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;/span&gt;&lt;br /&gt;&lt;span id="wu9957" style="color: yellow;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; delete iClientBuf;&lt;/span&gt;&lt;br /&gt;&lt;span id="wu9958" style="color: yellow;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; iClientBuf = NULL;&lt;/span&gt;&lt;br /&gt;&lt;span id="wu9959" style="color: yellow;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;/span&gt;&lt;br /&gt;&lt;span id="wu9960" style="color: yellow;"&gt;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;br /&gt;&lt;span id="wu9961" style="color: yellow;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; //&amp;nbsp;&amp;nbsp;&amp;nbsp; Make an asynchronous request&lt;/span&gt;&lt;br /&gt;&lt;span id="wu9962" style="color: yellow;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; //&amp;nbsp;&amp;nbsp;&amp;nbsp; for the purpose of example here don't worry about passing the&lt;/span&gt;&lt;br /&gt;&lt;span id="wu9963" style="color: yellow;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; //&amp;nbsp;&amp;nbsp;&amp;nbsp; descriptor retrieved above or modifying it&lt;/span&gt;&lt;br /&gt;&lt;span id="wu9964" style="color: yellow;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; iAsyncRequestHandler-&amp;gt;ServiceAsyncRequest(aMessage);&lt;/span&gt;&lt;br /&gt;&lt;span id="wu9965" style="color: yellow;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; //&amp;nbsp;&amp;nbsp;&amp;nbsp; iClientBuf is destroyed by later call to this method or destructor&lt;/span&gt;&lt;br /&gt;&lt;span id="wu9966" style="color: yellow;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span id="wu9967" style="color: yellow;"&gt;void CMyServerSession::CancelGetNotifiedWhenEventCompletedL(const RMessage2&amp;amp; aMessage)&lt;/span&gt;&lt;br /&gt;&lt;span id="wu9968" style="color: yellow;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;/span&gt;&lt;br /&gt;&lt;span id="wu9969" style="color: yellow;"&gt;//&amp;nbsp;&amp;nbsp;&amp;nbsp; Calls Cancel() on the CAsyncHandler active object&lt;/span&gt;&lt;br /&gt;&lt;span id="wu9970" style="color: yellow;"&gt;//&amp;nbsp;&amp;nbsp;&amp;nbsp; which must complete the outstanding async activity and complete &lt;/span&gt;&lt;br /&gt;&lt;span id="wu9971" style="color: yellow;"&gt;//&amp;nbsp;&amp;nbsp;&amp;nbsp; the original client-server request&lt;/span&gt;&lt;br /&gt;&lt;span id="wu9972" style="color: yellow;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; iAsyncRequestHandler-&amp;gt;Cancel();&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;br /&gt;&lt;span id="wu9973" style="color: yellow;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; aMessage.Complete(KErrNone);&lt;/span&gt;&lt;br /&gt;&lt;span id="wu9974" style="color: yellow;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span id="wu9975" style="color: yellow;"&gt;CServer2* CMyServer::NewLC()&lt;/span&gt;&lt;br /&gt;&lt;span id="wu9976" style="color: yellow;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;/span&gt;&lt;br /&gt;&lt;span id="wu9977" style="color: yellow;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; CMyServer* self=new(ELeave) CMyServer;&lt;/span&gt;&lt;br /&gt;&lt;span id="wu9978" style="color: yellow;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; CleanupStack::PushL(self);&lt;/span&gt;&lt;br /&gt;&lt;span id="wu9979" style="color: yellow;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; self-&amp;gt;ConstructL();&lt;/span&gt;&lt;br /&gt;&lt;span id="wu9980" style="color: yellow;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; return self;&lt;/span&gt;&lt;br /&gt;&lt;span id="wu9981" style="color: yellow;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span id="wu9982" style="color: yellow;"&gt;// Starts the server and constructs the shutdown object, starting the timer to ensure that&lt;/span&gt;&lt;br /&gt;&lt;span id="wu9983" style="color: yellow;"&gt;// the server will exit even if the starting client connection fails&lt;/span&gt;&lt;br /&gt;&lt;span id="wu9984" style="color: yellow;"&gt;void CMyServer::ConstructL()&lt;/span&gt;&lt;br /&gt;&lt;span id="wu9985" style="color: yellow;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;/span&gt;&lt;br /&gt;&lt;span id="wu9986" style="color: yellow;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; StartL(KServerName);&lt;/span&gt;&lt;br /&gt;&lt;span id="wu9987" style="color: yellow;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; iShutdown.ConstructL();&lt;/span&gt;&lt;br /&gt;&lt;span id="wu9988" style="color: yellow;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; iShutdown.Start();&lt;/span&gt;&lt;br /&gt;&lt;span id="wu9989" style="color: yellow;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span id="wu9990" style="color: yellow;"&gt;// Example doesn't bother checking the version&lt;/span&gt;&lt;br /&gt;&lt;span id="wu9991" style="color: yellow;"&gt;CSession2* CMyServer::NewSessionL(const TVersion&amp;amp; /*aVersion*/,const RMessage2&amp;amp; /*aMessage*/) const&lt;/span&gt;&lt;br /&gt;&lt;span id="wu9992" style="color: yellow;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;/span&gt;&lt;br /&gt;&lt;span id="wu9993" style="color: yellow;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; return new(ELeave) CMyServerSession();&lt;/span&gt;&lt;br /&gt;&lt;span id="wu9994" style="color: yellow;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span id="wu9995" style="color: yellow;"&gt;// Cancel the shutdown timer now, the new session is connected&lt;/span&gt;&lt;br /&gt;&lt;span id="wu9996" style="color: yellow;"&gt;void CMyServer::AddSession()&lt;/span&gt;&lt;br /&gt;&lt;span id="wu9997" style="color: yellow;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;/span&gt;&lt;br /&gt;&lt;span id="wu9998" style="color: yellow;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; ++iSessionCount;&lt;/span&gt;&lt;br /&gt;&lt;span id="wu9999" style="color: yellow;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; iShutdown.Cancel();&amp;nbsp; // Cancel any outstanding shutdown timer&lt;/span&gt;&lt;br /&gt;&lt;span id="wu99100" style="color: yellow;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span id="wu99101" style="color: yellow;"&gt;// Decrement the session counter and start the shutdown timer if the last client has disconnected&lt;/span&gt;&lt;br /&gt;&lt;span id="wu99102" style="color: yellow;"&gt;void CMyServer::RemoveSession()&lt;/span&gt;&lt;br /&gt;&lt;span id="wu99103" style="color: yellow;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;/span&gt;&lt;br /&gt;&lt;span id="wu99104" style="color: yellow;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; if (--iSessionCount==0)&lt;/span&gt;&lt;br /&gt;&lt;span id="wu99105" style="color: yellow;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; iShutdown.Start();&lt;/span&gt;&lt;br /&gt;&lt;span id="wu99106" style="color: yellow;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;span id="wu99107" style="color: yellow;"&gt;// Initiates server exit when the timer expires&lt;/span&gt;&lt;br /&gt;&lt;span id="wu99108" style="color: yellow;"&gt;void CShutdown::RunL()&lt;/span&gt;&lt;br /&gt;&lt;span id="wu99109" style="color: yellow;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;/span&gt;&lt;br /&gt;&lt;span id="wu99110" style="color: yellow;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; CActiveScheduler::Stop();&lt;/span&gt;&lt;br /&gt;&lt;span id="wu99111" style="color: yellow;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span id="wu99112" style="color: yellow;"&gt;void PanicClient(const RMessage2&amp;amp; aMessage,TServerPanic aPanic)&lt;/span&gt;&lt;br /&gt;&lt;span id="wu99113" style="color: yellow;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;/span&gt;&lt;br /&gt;&lt;span id="wu99114" style="color: yellow;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; _LIT(KPanic,"MyServer");&lt;/span&gt;&lt;br /&gt;&lt;span id="wu99115" style="color: yellow;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; aMessage.Panic(KPanic,aPanic);&lt;/span&gt;&lt;br /&gt;&lt;span id="wu99116" style="color: yellow;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span id="wu99117" style="color: yellow;"&gt;// Initialize and run the server&lt;/span&gt;&lt;br /&gt;&lt;span id="wu99118" style="color: yellow;"&gt;static void RunTheServerL()&lt;/span&gt;&lt;br /&gt;&lt;span id="wu99119" style="color: yellow;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; {// First create and install the active scheduler&lt;/span&gt;&lt;br /&gt;&lt;span id="wu99120" style="color: yellow;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; CActiveScheduler* scheduler = new (ELeave) CActiveScheduler;&lt;/span&gt;&lt;br /&gt;&lt;span id="wu99121" style="color: yellow;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; CleanupStack::PushL(scheduler);&lt;/span&gt;&lt;br /&gt;&lt;span id="wu99122" style="color: yellow;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; CActiveScheduler::Install(scheduler);&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span id="wu99123" style="color: yellow;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; // create the server&lt;/span&gt;&lt;br /&gt;&lt;span id="wu99124" style="color: yellow;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; CMyServer::NewLC();&lt;/span&gt;&lt;br /&gt;&lt;span id="wu99125" style="color: yellow;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;br /&gt;&lt;span id="wu99126" style="color: yellow;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; // Naming the server thread after the server helps to debug panics&lt;/span&gt;&lt;br /&gt;&lt;span id="wu99127" style="color: yellow;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; User::LeaveIfError(User::RenameThread(KServerName));&lt;/span&gt;&lt;br /&gt;&lt;span id="wu99128" style="color: yellow;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;br /&gt;&lt;span id="wu99129" style="color: yellow;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; RProcess::Rendezvous(KErrNone);&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span id="wu99130" style="color: yellow;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; // Enter the wait loop&lt;/span&gt;&lt;br /&gt;&lt;span id="wu99131" style="color: yellow;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; CActiveScheduler::Start();&lt;/span&gt;&lt;br /&gt;&lt;span id="wu99132" style="color: yellow;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;br /&gt;&lt;span id="wu99133" style="color: yellow;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; // Exited - cleanup the server and scheduler&lt;/span&gt;&lt;br /&gt;&lt;span id="wu99134" style="color: yellow;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; CleanupStack::PopAndDestroy(2, scheduler);&lt;/span&gt;&lt;br /&gt;&lt;span id="wu99135" style="color: yellow;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span id="wu99136" style="color: yellow;"&gt;// Server process entry-point&lt;/span&gt;&lt;br /&gt;&lt;span id="wu99137" style="color: yellow;"&gt;TInt E32Main()&lt;/span&gt;&lt;br /&gt;&lt;span id="wu99138" style="color: yellow;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;/span&gt;&lt;br /&gt;&lt;span id="wu99139" style="color: yellow;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; __UHEAP_MARK; // Heap checking&lt;/span&gt;&lt;br /&gt;&lt;span id="wu99140" style="color: yellow;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;br /&gt;&lt;span id="wu99141" style="color: yellow;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; CTrapCleanup* cleanup=CTrapCleanup::New();&lt;/span&gt;&lt;br /&gt;&lt;span id="wu99142" style="color: yellow;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; TInt r=KErrNoMemory;&lt;/span&gt;&lt;br /&gt;&lt;span id="wu99143" style="color: yellow;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; if (cleanup)&lt;/span&gt;&lt;br /&gt;&lt;span id="wu99144" style="color: yellow;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;/span&gt;&lt;br /&gt;&lt;span id="wu99145" style="color: yellow;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; TRAP(r,RunTheServerL());&lt;/span&gt;&lt;br /&gt;&lt;span id="wu99146" style="color: yellow;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; delete cleanup;&lt;/span&gt;&lt;br /&gt;&lt;span id="wu99147" style="color: yellow;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;/span&gt;&lt;br /&gt;&lt;span id="wu99148" style="color: yellow;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; __UHEAP_MARKEND;&lt;/span&gt;&lt;br /&gt;&lt;span id="wu99149" style="color: yellow;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; return r;&lt;/span&gt;&lt;br /&gt;&lt;span id="wu99150" style="color: yellow;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;The class CAsyncHandler has been implemented as the following:&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;span id="kva5" style="color: yellow;"&gt;// asynchandler.cpp&lt;br id="mu.p" /&gt;&lt;br id="usqh1" /&gt;// Skeleton active object, for asynchronous server requests&lt;br id="usqh2" /&gt;&lt;br id="usqh3" /&gt;#include &amp;lt;e32base.h&amp;gt;&lt;br id="usqh4" /&gt;#include "server.h"&lt;br id="usqh5" /&gt;&lt;br id="usqh6" /&gt;CAsyncHandler* CAsyncHandler::NewL()&lt;br id="usqh7" /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;br id="usqh8" /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; CAsyncHandler* me = CAsyncHandler::NewLC();&lt;br id="usqh9" /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; CleanupStack::Pop(me);&lt;br id="usqh10" /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; return (me);&lt;br id="usqh11" /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;br id="usqh12" /&gt;&lt;br id="usqh13" /&gt;CAsyncHandler* CAsyncHandler::NewLC()&lt;br id="usqh14" /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;br id="usqh15" /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; CAsyncHandler* me = new (ELeave) CAsyncHandler();&lt;br id="usqh16" /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; CleanupStack::PushL(me);&lt;br id="usqh17" /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; me-&amp;gt;ConstructL();&lt;br id="usqh18" /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; return (me);&lt;br id="usqh19" /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;br id="usqh20" /&gt;&lt;br id="usqh21" /&gt;CAsyncHandler::~CAsyncHandler()&lt;br id="usqh22" /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;br id="usqh23" /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; Cancel();&lt;br id="usqh24" /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; iTimer.Close();&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;br id="usqh25" /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;br id="usqh26" /&gt;&lt;br id="usqh27" /&gt;CAsyncHandler::CAsyncHandler()&lt;br id="usqh28" /&gt;: CActive(EPriorityStandard) &lt;br id="usqh29" /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; { &lt;br id="usqh30" /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; CActiveScheduler::Add(this); &lt;br id="usqh31" /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;br id="usqh32" /&gt;&lt;br id="usqh33" /&gt;void CAsyncHandler::ConstructL()&lt;br id="usqh34" /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;br id="usqh35" /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; User::LeaveIfError(iTimer.CreateLocal());&lt;br id="usqh36" /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;br id="usqh37" /&gt;&lt;br id="usqh38" /&gt;void CAsyncHandler::ServiceAsyncRequest(const RMessage2&amp;amp; aMessage)&lt;br id="usqh39" /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; {// Only allow one request to be submitted at a time&lt;br id="usqh40" /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; _LIT(KOutstandingRequestPanic, "InUse");&lt;br id="usqh41" /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; __ASSERT_ALWAYS(!IsActive(), User::Panic(KOutstandingRequestPanic, KErrInUse));&lt;br id="usqh42" /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; iMessage = aMessage;&lt;br id="usqh43" /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; iTimer.After(iStatus, 2000000); // Set the RTimer to expire in 2 seconds&lt;br id="usqh44" /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; SetActive(); // Mark this object active&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;br id="usqh45" /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;br id="usqh46" /&gt;&lt;br id="usqh47" /&gt;void CAsyncHandler::DoCancel()&lt;br id="usqh48" /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;br id="usqh49" /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; iTimer.Cancel();&lt;br id="usqh50" /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; iMessage.Complete(KErrCancel);&lt;br id="usqh51" /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;br id="usqh52" /&gt;&lt;br id="usqh53" /&gt;void CAsyncHandler::RunL()&lt;br id="usqh54" /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;br id="usqh55" /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; iMessage.Complete(iStatus.Int());&lt;br id="usqh56" /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;The client-server.h file looks like the following:&lt;br /&gt;&lt;br /&gt;&lt;span id="bn6l" style="color: yellow;"&gt;// client-server.h&lt;br id="aw_e" /&gt;#ifndef CLIENTSERVER_H__&lt;br id="aw_e0" /&gt;#define CLIENTSERVER_H__&lt;br id="aw_e1" /&gt;&lt;br id="aw_e2" /&gt;#include &amp;lt;e32std.h&amp;gt;&lt;br id="aw_e3" /&gt;#include &amp;lt;s32std.h&amp;gt;&lt;br id="aw_e4" /&gt;&lt;br id="aw_e5" /&gt;_LIT(KServerName,"TestServer");// The server's identity within the client-server framework&lt;br id="aw_e6" /&gt;_LIT(KServerBinaryName,"server"); // The name of the server binary (dll or exe) &lt;br id="aw_e7" /&gt;&lt;br id="aw_e8" /&gt;#ifdef __WINS__&lt;br id="aw_e9" /&gt;const TInt KMinServerHeapSize=0x1000;&lt;br id="aw_e10" /&gt;const TInt KMaxServerHeapSize=0x1000000;&lt;br id="aw_e11" /&gt;#endif&lt;br id="aw_e12" /&gt;&lt;br id="aw_e13" /&gt;enum TClientServerCommands&lt;br id="aw_e14" /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;br id="aw_e15" /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; EGetNotifiedWhenEventCompleted,&lt;br id="aw_e16" /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; ECancelGetNotifiedWhenEventCompleted&lt;br id="aw_e17" /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; };&lt;br id="aw_e18" /&gt;&lt;br id="aw_e19" /&gt;#endif // CLIENTSERVER_H__&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;So this is all about the client-server application of the example. This client-server application will provide the basis of the Asynchronous signal handling in the Active Object framework.&lt;br /&gt;&lt;br /&gt;Please see the function void CMyServerSession::GetNotifiedWhenEventCompletedL(const RMessage2&amp;amp; aMessage).&lt;br /&gt;&lt;br /&gt;Towards the end of this function we are calling iAsyncRequestHandler-&amp;gt;ServiceAsyncRequest(aMessage). Please remember I am not interested what the server is doing with the data that the client passes to it. I am more interested in explaining to you how the Asynchronous function is be
