<?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-683958699864453873</id><updated>2012-01-06T10:30:21.286-08:00</updated><category term='tetris'/><category term='logging'/><category term='priority-queue'/><category term='device_drivers'/><category term='windows programming'/><category term='hashcode'/><category term='creating projects'/><category term='JDT'/><category term='ps'/><category term='analytics'/><category term='ranking'/><category term='mixins'/><category term='XNA'/><category term='immutable-objects'/><category term='c#'/><category term='daemon'/><category term='set'/><category term='heaps'/><category term='commands'/><category term='opengl'/><category term='shell'/><category term='trees'/><category term='unicode'/><category term='freebsd'/><category term='eclipse'/><category term='c++'/><category term='cross domain'/><category term='stl'/><category term='bruteforce'/><category term='const'/><category term='linux'/><category term='eclipse-plugin-development'/><category term='threads'/><category term='subset-sum'/><category term='bigoh'/><category term='java'/><category term='heap'/><category term='refactoring'/><category term='patterns'/><category term='little sugar'/><category term='security'/><category term='programming'/><category term='views'/><category term='formatting'/><category term='similarity'/><category term='algorithm'/><category term='bash'/><category term='marker-resolution'/><category term='XHR'/><category term='game programming'/><category term='cosine similarity'/><category term='unix'/><category term='kernel'/><category term='markers'/><category term='. linux'/><category term='mergesort'/><category term='statistics'/><category term='references'/><category term='collections'/><category term='machine learning'/><category term='numbers'/><category term='equals'/><title type='text'>TechJude</title><subtitle type='html'></subtitle><link rel='http://schemas.google.com/g/2005#feed' type='application/atom+xml' href='http://techjude.blogspot.com/feeds/posts/default'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/683958699864453873/posts/default?max-results=100'/><link rel='alternate' type='text/html' href='http://techjude.blogspot.com/'/><link rel='hub' href='http://pubsubhubbub.appspot.com/'/><link rel='next' type='application/atom+xml' href='http://www.blogger.com/feeds/683958699864453873/posts/default?start-index=101&amp;max-results=100'/><author><name>KaranJude</name><uri>http://www.blogger.com/profile/08859421733871339100</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><generator version='7.00' uri='http://www.blogger.com'>Blogger</generator><openSearch:totalResults>122</openSearch:totalResults><openSearch:startIndex>1</openSearch:startIndex><openSearch:itemsPerPage>100</openSearch:itemsPerPage><entry><id>tag:blogger.com,1999:blog-683958699864453873.post-8819959687376796009</id><published>2010-11-23T00:45:00.000-08:00</published><updated>2010-11-23T00:51:25.586-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='bash'/><category scheme='http://www.blogger.com/atom/ns#' term='little sugar'/><title type='text'>Running commands on multiple boxes via ssh</title><content type='html'>ssh -jobs 1 -continue_on_error -h mybox[1-2].box.com -- 'hostname;ls -l ~/'&lt;br /&gt;&lt;br /&gt;This will run the 'hostname;ls -l ~/'&lt;br /&gt;&lt;br /&gt;command on all boxes with names mybox1.box.com and mybox2.box.com&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/683958699864453873-8819959687376796009?l=techjude.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://techjude.blogspot.com/feeds/8819959687376796009/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=683958699864453873&amp;postID=8819959687376796009' title='8 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/683958699864453873/posts/default/8819959687376796009'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/683958699864453873/posts/default/8819959687376796009'/><link rel='alternate' type='text/html' href='http://techjude.blogspot.com/2010/11/running-commands-on-multiple-boxes-via.html' title='Running commands on multiple boxes via ssh'/><author><name>KaranJude</name><uri>http://www.blogger.com/profile/08859421733871339100</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>8</thr:total></entry><entry><id>tag:blogger.com,1999:blog-683958699864453873.post-5658096585383325268</id><published>2010-03-01T01:07:00.000-08:00</published><updated>2010-03-01T01:10:01.134-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='bash'/><category scheme='http://www.blogger.com/atom/ns#' term='little sugar'/><title type='text'>LIttle Sugar: Bash :: Finding the N largest or smallest files under a folder</title><content type='html'>Finding the N largest files under a folder&lt;br /&gt;&lt;br /&gt;find . -type f -print|xargs ls -l|sort -r -n -k 5,5 | tail -N&lt;br /&gt;&lt;br /&gt;Finding the N smallest files under a folder&lt;br /&gt;&lt;br /&gt;find . -type f -print|xargs ls -l|sort -r -n -k 5,5 | head -N&lt;br /&gt;&lt;br /&gt;here replace N by the number of largest files you want in the output&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/683958699864453873-5658096585383325268?l=techjude.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://techjude.blogspot.com/feeds/5658096585383325268/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=683958699864453873&amp;postID=5658096585383325268' title='78 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/683958699864453873/posts/default/5658096585383325268'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/683958699864453873/posts/default/5658096585383325268'/><link rel='alternate' type='text/html' href='http://techjude.blogspot.com/2010/03/little-sugar-bash-finding-n-largest-or.html' title='LIttle Sugar: Bash :: Finding the N largest or smallest files under a folder'/><author><name>KaranJude</name><uri>http://www.blogger.com/profile/08859421733871339100</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>78</thr:total></entry><entry><id>tag:blogger.com,1999:blog-683958699864453873.post-4369233979067035304</id><published>2010-02-16T06:01:00.000-08:00</published><updated>2010-02-16T06:02:12.669-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='bash'/><title type='text'>Little Sugar: Bash</title><content type='html'>removing files older than 30 days&lt;br /&gt;&lt;br /&gt;/home/user_dir/app_name/logs -ctime +30d  -exec rm {} ';'&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/683958699864453873-4369233979067035304?l=techjude.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://techjude.blogspot.com/feeds/4369233979067035304/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=683958699864453873&amp;postID=4369233979067035304' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/683958699864453873/posts/default/4369233979067035304'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/683958699864453873/posts/default/4369233979067035304'/><link rel='alternate' type='text/html' href='http://techjude.blogspot.com/2010/02/little-sugar-bash.html' title='Little Sugar: Bash'/><author><name>KaranJude</name><uri>http://www.blogger.com/profile/08859421733871339100</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-683958699864453873.post-333003509680162715</id><published>2010-01-30T07:22:00.000-08:00</published><updated>2010-03-07T09:55:21.604-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='cosine similarity'/><category scheme='http://www.blogger.com/atom/ns#' term='machine learning'/><title type='text'>Similarity in application features - Cosine Similarity</title><content type='html'>Lets say you are planning to write a rating system for music songs.&lt;br /&gt;&lt;br /&gt;and you are interested in the following queries:&lt;br /&gt;- average rating of a given song&lt;br /&gt;- average rating a user gives to a song&lt;br /&gt;- which songs are most similar&lt;br /&gt;- which users rate similar songs&lt;br /&gt;- which users have similar tastes &lt;br /&gt;&lt;br /&gt;here are we gave 2 dimensions user and song rating. We can use cosine similarity to answer the above mentioned queries. Lets do this in a step by step manner&lt;br /&gt;&lt;br /&gt;&lt;b&gt;Step 1&lt;/b&gt;&lt;br /&gt;Create a 2 dimensional matrix of song_rating vs user&lt;br /&gt;&lt;br /&gt;&lt;table&gt;&lt;br /&gt;&lt;tr&gt;&lt;th&gt;&amp;nbsp;&lt;/th&gt;&lt;th&gt;A&lt;/th&gt;&lt;th&gt;B&lt;/th&gt;&lt;th&gt;C&lt;/th&gt;&lt;th&gt;Avg&lt;/th&gt;&lt;/tr&gt;&lt;br /&gt;&lt;tr&gt;&lt;td&gt;song1&lt;/td&gt;&lt;td&gt;3&lt;/td&gt;&lt;td&gt;2&lt;/td&gt;&lt;td&gt;1&lt;/td&gt;&lt;td&gt;2&lt;/td&gt;&lt;/tr&gt;&lt;br /&gt;&lt;tr&gt;&lt;td&gt;song2&lt;/td&gt;&lt;td&gt;4&lt;/td&gt;&lt;td&gt;2&lt;/td&gt;&lt;td&gt;3&lt;/td&gt;&lt;td&gt;3&lt;/td&gt;&lt;/tr&gt;&lt;br /&gt;&lt;tr&gt;&lt;td&gt;song3&lt;/td&gt;&lt;td&gt;2&lt;/td&gt;&lt;td&gt;4&lt;/td&gt;&lt;td&gt;5&lt;/td&gt;&lt;td&gt;11/3&lt;/td&gt;&lt;/tr&gt;&lt;br /&gt;&lt;tr&gt;&lt;td&gt;average&lt;/td&gt;&lt;td&gt;3&lt;/td&gt;&lt;td&gt;8/3&lt;/td&gt;&lt;td&gt;3&lt;/td&gt;&lt;td&gt;26/3&lt;/td&gt;&lt;/tr&gt;&lt;br /&gt;&lt;/table&gt;&lt;br /&gt;&lt;br /&gt;Here the column represent the ratings given by users A, B, C&lt;br /&gt;The last column represents the avg rating of a given song.&lt;br /&gt;The rows represents a song and the ratings given by different users for that song.&lt;br /&gt;&lt;br /&gt;&lt;b&gt;Step 2&lt;/b&gt;&lt;br /&gt;Normalize the values in the matrix so that they lie between 0 and 1.&lt;br /&gt;&lt;br /&gt;divide each column value by square root of the sum of the squares of all the columns in a given row. e.g to normalize column with value 3 divide 3 by &lt;br /&gt;sqrt(3^2 + 2^2 + 1^2)&lt;br /&gt;&lt;br /&gt;&lt;table&gt;&lt;br /&gt;&lt;tr&gt;&lt;th&gt;&amp;nbsp;&lt;/th&gt;&lt;th&gt;A&lt;/th&gt;&lt;th&gt;B&lt;/th&gt;&lt;th&gt;C&lt;/th&gt;&lt;/tr&gt;&lt;br /&gt;&lt;tr&gt;&lt;td&gt;song1&lt;/td&gt;&lt;td&gt;3&lt;/td&gt;&lt;td&gt;2&lt;/td&gt;&lt;td&gt;1&lt;/td&gt;&lt;/tr&gt;&lt;br /&gt;&lt;tr&gt;&lt;td&gt;song2&lt;/td&gt;&lt;td&gt;4&lt;/td&gt;&lt;td&gt;2&lt;/td&gt;&lt;td&gt;3&lt;/td&gt;&lt;/tr&gt;&lt;br /&gt;&lt;tr&gt;&lt;td&gt;song3&lt;/td&gt;&lt;td&gt;2&lt;/td&gt;&lt;td&gt;4&lt;/td&gt;&lt;td&gt;5&lt;/td&gt;&lt;/tr&gt;&lt;br /&gt;&lt;/table&gt;&lt;br /&gt;&lt;br /&gt;&lt;b&gt;Step 3&lt;/b&gt;&lt;br /&gt;Normalize the values in the matrix so that they lie between 0 and 1.&lt;br /&gt;&lt;br /&gt;divide each column value by square root of the sum of the squares of all the columns in a given row. e.g to normalize column with value 3 divide 3 by &lt;br /&gt;sqrt(3^2 + 2^2 + 1^2)&lt;br /&gt;&lt;br /&gt;&lt;table&gt;&lt;br /&gt;&lt;tr&gt;&lt;th&gt;&amp;nbsp;&lt;/th&gt;&lt;th&gt;A&lt;/th&gt;&lt;th&gt;B&lt;/th&gt;&lt;th&gt;C&lt;/th&gt;&lt;/tr&gt;&lt;br /&gt;&lt;tr&gt;&lt;td&gt;song1&lt;/td&gt;&lt;td&gt;3&lt;/td&gt;&lt;td&gt;2&lt;/td&gt;&lt;td&gt;1&lt;/td&gt;&lt;/tr&gt;&lt;br /&gt;&lt;tr&gt;&lt;td&gt;song2&lt;/td&gt;&lt;td&gt;4&lt;/td&gt;&lt;td&gt;2&lt;/td&gt;&lt;td&gt;3&lt;/td&gt;&lt;/tr&gt;&lt;br /&gt;&lt;tr&gt;&lt;td&gt;song3&lt;/td&gt;&lt;td&gt;2&lt;/td&gt;&lt;td&gt;4&lt;/td&gt;&lt;td&gt;5&lt;/td&gt;&lt;/tr&gt;&lt;br /&gt;&lt;/table&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;b&gt;Step 4&lt;/b&gt;&lt;br /&gt;obtain a new table after applying normalization rule&lt;br /&gt;&lt;br /&gt;&lt;table&gt;&lt;br /&gt;&lt;tr&gt;&lt;th&gt;&amp;nbsp;&lt;/th&gt;&lt;th&gt;A&lt;/th&gt;&lt;th&gt;B&lt;/th&gt;&lt;th&gt;C&lt;/th&gt;&lt;/tr&gt;&lt;br /&gt;&lt;tr&gt;&lt;td&gt;song1&lt;/td&gt;&lt;td&gt;.8018&lt;/td&gt;&lt;td&gt;.5345&lt;/td&gt;&lt;td&gt;.2673&lt;/td&gt;&lt;/tr&gt;&lt;br /&gt;&lt;tr&gt;&lt;td&gt;song2&lt;/td&gt;&lt;td&gt;.7428&lt;/td&gt;&lt;td&gt;.3714&lt;/td&gt;&lt;td&gt;.557&lt;/td&gt;&lt;/tr&gt;&lt;br /&gt;&lt;tr&gt;&lt;td&gt;song3&lt;/td&gt;&lt;td&gt;.2981&lt;/td&gt;&lt;td&gt;.5963&lt;/td&gt;&lt;td&gt;.7454&lt;/td&gt;&lt;/tr&gt;&lt;br /&gt;&lt;/table&gt;&lt;br /&gt;&lt;br /&gt;Now each row with every other row to obtain a similarity matrix.&lt;br /&gt;The multiplication should be a dot product of the 2 rows&lt;br /&gt;&lt;br /&gt;for example the song1 and song2 dot product yields in &lt;br /&gt;.8018*.7428 + .5345*.3714 + .2673*.557 = .943&lt;br /&gt;&lt;br /&gt;&lt;b&gt;Step 5&lt;/b&gt;&lt;br /&gt;Use the dot product rule to obtain the similarity rule&lt;br /&gt;&lt;br /&gt;&lt;table&gt;&lt;br /&gt;&lt;tr&gt;&lt;th&gt;&amp;nbsp;&lt;/th&gt;&lt;th&gt;Song1&lt;/th&gt;&lt;th&gt;Song2&lt;/th&gt;&lt;th&gt;Song3&lt;/th&gt;&lt;/tr&gt;&lt;br /&gt;&lt;tr&gt;&lt;td&gt;song1&lt;/td&gt;&lt;td&gt;1&lt;/td&gt;&lt;td&gt;.943&lt;/td&gt;&lt;td&gt;.757&lt;/td&gt;&lt;/tr&gt;&lt;br /&gt;&lt;tr&gt;&lt;td&gt;song2&lt;/td&gt;&lt;td&gt;.943&lt;/td&gt;&lt;td&gt;1&lt;/td&gt;&lt;td&gt;.858&lt;/td&gt;&lt;/tr&gt;&lt;br /&gt;&lt;tr&gt;&lt;td&gt;song3&lt;/td&gt;&lt;td&gt;.757&lt;/td&gt;&lt;td&gt;.858&lt;/td&gt;&lt;td&gt;1&lt;/td&gt;&lt;/tr&gt;&lt;br /&gt;&lt;/table&gt;&lt;br /&gt;&lt;br /&gt;From this matrix its easy to figure out that song1 is more likely to be similar to song2 than song3&lt;br /&gt;&lt;br /&gt;&lt;b&gt;Step 6&lt;/b&gt;&lt;br /&gt;Finding similar users is similar to finding similar songs, just align the &lt;br /&gt;users as rows of the initial matrix and song rating as the columns of the initialization matrix.&lt;br /&gt;&lt;br /&gt;Then apply Step 2 - Step 5 in order and you can obtain the similarity matrix for users also&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/683958699864453873-333003509680162715?l=techjude.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://techjude.blogspot.com/feeds/333003509680162715/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=683958699864453873&amp;postID=333003509680162715' title='2 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/683958699864453873/posts/default/333003509680162715'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/683958699864453873/posts/default/333003509680162715'/><link rel='alternate' type='text/html' href='http://techjude.blogspot.com/2010/01/similarity-in-application-features.html' title='Similarity in application features - Cosine Similarity'/><author><name>KaranJude</name><uri>http://www.blogger.com/profile/08859421733871339100</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>2</thr:total></entry><entry><id>tag:blogger.com,1999:blog-683958699864453873.post-6837957706830058473</id><published>2010-01-26T01:38:00.000-08:00</published><updated>2010-01-26T02:11:47.917-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='statistics'/><category scheme='http://www.blogger.com/atom/ns#' term='analytics'/><title type='text'>Adding feedback loop to your applications</title><content type='html'>These days everyone is talking about smart applications. &lt;br /&gt;&lt;br /&gt;One very simple feature that smart applications have is measuring user interactions.&lt;br /&gt;Learning from user interactions and acting in a more personalized manner towards the user.&lt;br /&gt;&lt;br /&gt;User interaction can mean different things for different applications. Here i am going to talk about one popular user interaction metric.&lt;br /&gt;&lt;br /&gt;"Time spent by a user on a given feature"&lt;br /&gt;&lt;br /&gt;Assuming you have some way of measuring the time spent by a user on a given feature. You can calculate the average time spent by a user and compare it with the time spent by other realistic users by using some statistics.&lt;br /&gt;&lt;br /&gt;Assuming you have a list of users and their corresponding time's spent on the feature.&lt;br /&gt;You can calculate the mean time for the list.&lt;br /&gt;&lt;br /&gt;Lets call this mean_time.&lt;br /&gt;&lt;br /&gt;You can also calculate the standard deviation for the list.&lt;br /&gt;&lt;br /&gt;Lets call this time_range_delta&lt;br /&gt;&lt;br /&gt;you actual time_range interval is then (mean_time - (time_range_delta * range_factor), mean_time + (time_range_delta * range_factor))&lt;br /&gt;&lt;br /&gt;where range factor is the amount spurious information you are will to tolerate a range of [1-3] for this factor is generally considered good.&lt;br /&gt;&lt;br /&gt;once you have this range interval, you can ignore all times that fall outside this range interval.&lt;br /&gt;&lt;br /&gt;this will give a new list, from which you can calculate the mean and standard deviation again. &lt;br /&gt;&lt;br /&gt;By following this process iteratively you can get the actual list of genuine users and their corresponding times. &lt;br /&gt;&lt;br /&gt;Calculating the mean of this list will give the average time spent by the user.&lt;br /&gt;&lt;br /&gt;You can then classify any user by using this average time.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/683958699864453873-6837957706830058473?l=techjude.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://techjude.blogspot.com/feeds/6837957706830058473/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=683958699864453873&amp;postID=6837957706830058473' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/683958699864453873/posts/default/6837957706830058473'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/683958699864453873/posts/default/6837957706830058473'/><link rel='alternate' type='text/html' href='http://techjude.blogspot.com/2010/01/adding-feedback-loop-to-your.html' title='Adding feedback loop to your applications'/><author><name>KaranJude</name><uri>http://www.blogger.com/profile/08859421733871339100</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-683958699864453873.post-2433408200614683745</id><published>2009-09-14T06:18:00.000-07:00</published><updated>2010-03-07T09:58:26.954-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='device_drivers'/><category scheme='http://www.blogger.com/atom/ns#' term='linux'/><title type='text'>Little Sugar: Creating a device node</title><content type='html'>To create a device node use mknod&lt;br /&gt;&lt;br /&gt;mknod /dev/mem c 1 1&lt;br /&gt;&lt;br /&gt;here the device name is /dev/mem&lt;br /&gt;&lt;br /&gt;c represents character device this can be block device also&lt;br /&gt;&lt;br /&gt;the first 1 represents the major number&lt;br /&gt;the second 1 represents the minor number&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/683958699864453873-2433408200614683745?l=techjude.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/683958699864453873/posts/default/2433408200614683745'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/683958699864453873/posts/default/2433408200614683745'/><link rel='alternate' type='text/html' href='http://techjude.blogspot.com/2009/09/little-sugar-creating-device-node.html' title='Little Sugar: Creating a device node'/><author><name>KaranJude</name><uri>http://www.blogger.com/profile/08859421733871339100</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author></entry><entry><id>tag:blogger.com,1999:blog-683958699864453873.post-309618798048836821</id><published>2009-09-13T23:31:00.000-07:00</published><updated>2009-09-13T23:34:55.676-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='freebsd'/><category scheme='http://www.blogger.com/atom/ns#' term='commands'/><title type='text'>Little Sugar: FreeBSD total RAM</title><content type='html'>to find out the total RAM installed on your FreeBSD box use something like this&lt;br /&gt;&lt;br /&gt;sysctl hw.physmem&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/683958699864453873-309618798048836821?l=techjude.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://techjude.blogspot.com/feeds/309618798048836821/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=683958699864453873&amp;postID=309618798048836821' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/683958699864453873/posts/default/309618798048836821'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/683958699864453873/posts/default/309618798048836821'/><link rel='alternate' type='text/html' href='http://techjude.blogspot.com/2009/09/little-sugar-freebsd-total-ram.html' title='Little Sugar: FreeBSD total RAM'/><author><name>KaranJude</name><uri>http://www.blogger.com/profile/08859421733871339100</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-683958699864453873.post-8705637860511203829</id><published>2009-09-10T06:44:00.000-07:00</published><updated>2009-09-10T06:47:08.678-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='linux'/><category scheme='http://www.blogger.com/atom/ns#' term='kernel'/><title type='text'>Little Sugar: insmod</title><content type='html'>Linux kernel extensions have a .ko extension are inserted directly into the kernel&lt;br /&gt;using insmod command.&lt;br /&gt;&lt;br /&gt;The kernel modules are removed using rmmod.&lt;br /&gt;&lt;br /&gt;Kernel modules are generally placed at /lib/modules.&lt;br /&gt;&lt;br /&gt;To update kernel dependencies run depmod&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/683958699864453873-8705637860511203829?l=techjude.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://techjude.blogspot.com/feeds/8705637860511203829/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=683958699864453873&amp;postID=8705637860511203829' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/683958699864453873/posts/default/8705637860511203829'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/683958699864453873/posts/default/8705637860511203829'/><link rel='alternate' type='text/html' href='http://techjude.blogspot.com/2009/09/little-sugar-insmod.html' title='Little Sugar: insmod'/><author><name>KaranJude</name><uri>http://www.blogger.com/profile/08859421733871339100</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-683958699864453873.post-1634870405013553328</id><published>2009-09-09T02:44:00.000-07:00</published><updated>2009-09-09T02:49:37.516-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='algorithm'/><title type='text'>Finding Document Similarity</title><content type='html'>If you need to find how similar a document is we can use vector algebra to our advantage. If we have 2 document d1 and d2 then &lt;br /&gt;&lt;br /&gt;Let D1 be a vector of the word-frequency of the document d1&lt;br /&gt;Let D2 be a vector of the word-frequency of the document d2&lt;br /&gt;&lt;br /&gt;then the deviation of the 2 documents can be calculated by &lt;br /&gt;&lt;br /&gt;using the fact that &lt;br /&gt;&lt;br /&gt;cos(theta) = (D1 * D2)/(N(D1) * N(D2))&lt;br /&gt;&lt;br /&gt;where N(D) is the normalized vector represented by &lt;br /&gt;&lt;br /&gt;N(D) = sqrt(D * D)&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/683958699864453873-1634870405013553328?l=techjude.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://techjude.blogspot.com/feeds/1634870405013553328/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=683958699864453873&amp;postID=1634870405013553328' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/683958699864453873/posts/default/1634870405013553328'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/683958699864453873/posts/default/1634870405013553328'/><link rel='alternate' type='text/html' href='http://techjude.blogspot.com/2009/09/finding-document-similarity.html' title='Finding Document Similarity'/><author><name>KaranJude</name><uri>http://www.blogger.com/profile/08859421733871339100</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-683958699864453873.post-4508978285296123771</id><published>2009-09-02T00:44:00.000-07:00</published><updated>2009-09-02T00:58:31.416-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='opengl'/><title type='text'>OpenGL: Diffuse, Specular, Ambient, Emissive lights</title><content type='html'>In the OpenGL world there are different types of light types&lt;br /&gt;&lt;br /&gt;Diffuse&lt;br /&gt;--------&lt;br /&gt;These type come from one direction bu are scattered equally in all directions.&lt;br /&gt;&lt;br /&gt;Specular&lt;br /&gt;--------&lt;br /&gt;This type of light comes in one directions and is also bounced off in one direction&lt;br /&gt;&lt;br /&gt;Ambient&lt;br /&gt;--------&lt;br /&gt;This type of light source comes from different light sources and is also scattered in different directions&lt;br /&gt;&lt;br /&gt;Emissive&lt;br /&gt;---------&lt;br /&gt;This represents light originating from the object&lt;br /&gt;&lt;br /&gt;So in general A light source has two types of properties associated with it &lt;br /&gt;LR,LG,LB =&gt; the RGB components that make up the light and&lt;br /&gt;MR,MG,MB =&gt; the RGB components that are reflected away&lt;br /&gt;Hence the net effect of the RGB is given by a vector&lt;br /&gt;&lt;br /&gt;(LR.MR, LG.MG, LB.MB)&lt;br /&gt;&lt;br /&gt;if light is coming from two or more sources the light is added and next effect is&lt;br /&gt;of the form&lt;br /&gt;&lt;br /&gt;(R1 + R2, G1 + G2, B1 + B2)&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/683958699864453873-4508978285296123771?l=techjude.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://techjude.blogspot.com/feeds/4508978285296123771/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=683958699864453873&amp;postID=4508978285296123771' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/683958699864453873/posts/default/4508978285296123771'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/683958699864453873/posts/default/4508978285296123771'/><link rel='alternate' type='text/html' href='http://techjude.blogspot.com/2009/09/opengl-diffuse-specular-ambient.html' title='OpenGL: Diffuse, Specular, Ambient, Emissive lights'/><author><name>KaranJude</name><uri>http://www.blogger.com/profile/08859421733871339100</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-683958699864453873.post-8454651403845768587</id><published>2009-09-01T23:16:00.000-07:00</published><updated>2009-09-01T23:40:17.072-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='opengl'/><title type='text'>Opengl : Hidden Surface Removal and LIghting</title><content type='html'>Hidden surface removal is a common technique in the graphics world. The technique says&lt;br /&gt;we should draw only parts of objects that are visible to the user.&lt;br /&gt;&lt;br /&gt;What support does OpenGL have for hidden surface removal.OpenGL supports hidden surface removal through a combination of DEPTH BUFFER and COLOR BUFFER.&lt;br /&gt;&lt;br /&gt;Depth Buffer and Color Buffer&lt;br /&gt;------------------------------&lt;br /&gt;Our screen is flat basically we see a flat 2D rectangular screen made up of pixels. Associated with these pixels we have a corresponding value in the Depth Buffer and&lt;br /&gt;Color Buffer. So what pixel appears forward or backward depends on its value in the depth buffer. The color value it shows depends on its value in the color buffer.&lt;br /&gt;&lt;br /&gt;to enable the depth buffer we need use something like the following:&lt;br /&gt;&lt;br /&gt;glClear(GL_COLOR_BUFFER_BIT GL_DEPTH_BUFFER_BIT);&lt;br /&gt;&lt;br /&gt;Material And Ambient Light&lt;br /&gt;---------------------------&lt;br /&gt;OpenGL understands RGB. A material quality decides the amount of RGB that is reflected or absorbed. An area can be lit by many light sources.Say in a room the bulb can the primary source of light.But there might be light reflected from walls which can be called secondory sources, the light contributed by such sources is called ambient light.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/683958699864453873-8454651403845768587?l=techjude.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://techjude.blogspot.com/feeds/8454651403845768587/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=683958699864453873&amp;postID=8454651403845768587' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/683958699864453873/posts/default/8454651403845768587'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/683958699864453873/posts/default/8454651403845768587'/><link rel='alternate' type='text/html' href='http://techjude.blogspot.com/2009/09/opengl-hidden-surface-removal-and.html' title='Opengl : Hidden Surface Removal and LIghting'/><author><name>KaranJude</name><uri>http://www.blogger.com/profile/08859421733871339100</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-683958699864453873.post-962044702633211216</id><published>2009-09-01T06:08:00.000-07:00</published><updated>2009-09-01T06:11:34.915-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='linux'/><category scheme='http://www.blogger.com/atom/ns#' term='ps'/><category scheme='http://www.blogger.com/atom/ns#' term='shell'/><title type='text'>ps options</title><content type='html'>If you invoke the ps command like this&lt;br /&gt;&lt;br /&gt;ps -C &lt;command_name&gt; -o etime,pid,pri,cmd&lt;br /&gt;&lt;br /&gt;this will show processes that match the command name and show output using the &lt;br /&gt;fields followed after -o i.e&lt;br /&gt; &lt;br /&gt;etime - how long the process is running&lt;br /&gt;pid - the pid of the process&lt;br /&gt;pri - priority of the process&lt;br /&gt;cmd - the full command line of the command&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/683958699864453873-962044702633211216?l=techjude.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://techjude.blogspot.com/feeds/962044702633211216/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=683958699864453873&amp;postID=962044702633211216' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/683958699864453873/posts/default/962044702633211216'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/683958699864453873/posts/default/962044702633211216'/><link rel='alternate' type='text/html' href='http://techjude.blogspot.com/2009/09/ps-options.html' title='ps options'/><author><name>KaranJude</name><uri>http://www.blogger.com/profile/08859421733871339100</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-683958699864453873.post-7405876787871447552</id><published>2009-08-30T10:24:00.000-07:00</published><updated>2009-08-30T10:29:44.642-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='algorithm'/><category scheme='http://www.blogger.com/atom/ns#' term='mergesort'/><title type='text'>Looking back at mergesort</title><content type='html'>For mergesort the recurrence relation is&lt;br /&gt;&lt;br /&gt;T(N) = 1 if N == 1&lt;br /&gt;T(N) = cn + 2T(N/2) if N != 1&lt;br /&gt;&lt;br /&gt;so if we draw the recursion tree for such a recurrence relation we get&lt;br /&gt;Height of tree = lg N&lt;br /&gt;Number of leaves = N&lt;br /&gt;--------------&lt;br /&gt;Leaves at level 0 -&gt; 1&lt;br /&gt;Leaves at level 1 -&gt; 2&lt;br /&gt;Leaves at level 2 -&gt; 4&lt;br /&gt;Leaves at level 3 -&gt; 8&lt;br /&gt;...&lt;br /&gt;Leaves at level lg N -&gt; N&lt;br /&gt;&lt;br /&gt;Total Work Done&lt;br /&gt;----------------&lt;br /&gt;Work done at level 0 -&gt; cn&lt;br /&gt;Work done at level 1 -&gt; cn&lt;br /&gt;Work done at level 2 -&gt; cn&lt;br /&gt;....&lt;br /&gt;Work done at level lg N -&gt; cn&lt;br /&gt;&lt;br /&gt;So total work done =&gt; cn * lg N =&gt; O(n lg n)&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/683958699864453873-7405876787871447552?l=techjude.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://techjude.blogspot.com/feeds/7405876787871447552/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=683958699864453873&amp;postID=7405876787871447552' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/683958699864453873/posts/default/7405876787871447552'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/683958699864453873/posts/default/7405876787871447552'/><link rel='alternate' type='text/html' href='http://techjude.blogspot.com/2009/08/looking-back-at-mergesort.html' title='Looking back at mergesort'/><author><name>KaranJude</name><uri>http://www.blogger.com/profile/08859421733871339100</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-683958699864453873.post-2175352880090609166</id><published>2009-08-30T06:37:00.000-07:00</published><updated>2009-08-30T07:10:50.303-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='similarity'/><category scheme='http://www.blogger.com/atom/ns#' term='algorithm'/><category scheme='http://www.blogger.com/atom/ns#' term='ranking'/><title type='text'>Similarity between objects</title><content type='html'>Lets say we need to find the similarity between people based on how they rank different items. Based on the that collected data we need to recommend some new&lt;br /&gt;items to the users.People who are similar to each other have a higher likelihood of &lt;br /&gt;liking things that we recommend them.&lt;br /&gt;&lt;br /&gt;Now lets consider a Set of Users.A Set of Items and a set of Rankings which users give to these Items.&lt;br /&gt;&lt;br /&gt;Given this information how can we find the similarity between 2 Users.&lt;br /&gt;&lt;br /&gt;Approach 1)&lt;br /&gt;------------&lt;br /&gt;Take user A and user B&lt;br /&gt;Calculate union of items chosen by user A &amp; B , call it A_UNION_B&lt;br /&gt;Calculate the intersection of the items chosen between A &amp; b, call it A_INT_B&lt;br /&gt;then the value A_INT_B/A_UNION_B represents the similarity of the 2 users A and B&lt;br /&gt;&lt;br /&gt;Approach 2)&lt;br /&gt;------------&lt;br /&gt;For every item that is common between A &amp; B we can calculate the Euclidean distance between the rankings of the 2 items. &lt;br /&gt;D = RA (ranking A gave to an item) - RB (ranking B gave to an item)&lt;br /&gt;Sum = Sum + D^2&lt;br /&gt;&lt;br /&gt;The once we have the sum we can call it Similarity Sum and use a formula&lt;br /&gt;like&lt;br /&gt;&lt;br /&gt;Similarity = 1/(1 + Sum)&lt;br /&gt;&lt;br /&gt;The 1 is added to prevent the 1/0 off case, where our magic factor factor is 1&lt;br /&gt;we can choose an arbitrary magic factor say N&lt;br /&gt;&lt;br /&gt;Then Similarity = N/(N + Sum)&lt;br /&gt;&lt;br /&gt;Approach 3)&lt;br /&gt;-----------&lt;br /&gt;Use the Sum that we got in Approach 2 above &lt;br /&gt;Similarity = Sum / N where N is the number of items common between A and B that have the same rating&lt;br /&gt;Similarity = Sqrt(Similarity)&lt;br /&gt;then to make Similarity fall between the range 0 and 1&lt;br /&gt;&lt;br /&gt;Similarity = 1 - tanh(Similarity)&lt;br /&gt;&lt;br /&gt;Approach 4)&lt;br /&gt;-----------&lt;br /&gt;Use the Similarity that we calculated in Approach 3&lt;br /&gt;NN = Number of items common between A and B&lt;br /&gt;Similarity = Similarity * (N / NN)&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/683958699864453873-2175352880090609166?l=techjude.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://techjude.blogspot.com/feeds/2175352880090609166/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=683958699864453873&amp;postID=2175352880090609166' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/683958699864453873/posts/default/2175352880090609166'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/683958699864453873/posts/default/2175352880090609166'/><link rel='alternate' type='text/html' href='http://techjude.blogspot.com/2009/08/similarity-between-objects.html' title='Similarity between objects'/><author><name>KaranJude</name><uri>http://www.blogger.com/profile/08859421733871339100</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-683958699864453873.post-9169941915498955051</id><published>2009-06-17T03:17:00.000-07:00</published><updated>2009-06-17T03:20:43.827-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='algorithm'/><category scheme='http://www.blogger.com/atom/ns#' term='little sugar'/><title type='text'>Little Sugar: Writing an oscillator function</title><content type='html'>Say you need to transform values v1, v2 in such a way that they lie between lowerlimit L and upper limit U&lt;br /&gt;&lt;br /&gt;then u can use an oscillator function&lt;br /&gt;&lt;br /&gt;new value = U - (L + (U * (1 / (1 + value))))&lt;br /&gt;&lt;br /&gt;this new value will be between L and U, if u omit L then new value &lt;br /&gt;would be between 0 - U&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/683958699864453873-9169941915498955051?l=techjude.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://techjude.blogspot.com/feeds/9169941915498955051/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=683958699864453873&amp;postID=9169941915498955051' title='7 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/683958699864453873/posts/default/9169941915498955051'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/683958699864453873/posts/default/9169941915498955051'/><link rel='alternate' type='text/html' href='http://techjude.blogspot.com/2009/06/little-sugar-writing-oscillator.html' title='Little Sugar: Writing an oscillator function'/><author><name>KaranJude</name><uri>http://www.blogger.com/profile/08859421733871339100</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>7</thr:total></entry><entry><id>tag:blogger.com,1999:blog-683958699864453873.post-1442304402686194520</id><published>2009-06-11T06:32:00.000-07:00</published><updated>2009-06-11T06:39:29.130-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='unix'/><category scheme='http://www.blogger.com/atom/ns#' term='commands'/><category scheme='http://www.blogger.com/atom/ns#' term='little sugar'/><title type='text'>Little Sugar: Useful commands while programming on Unix Systems</title><content type='html'>Here are a list of commands that re use file while programming on unix systems&lt;br /&gt;&lt;br /&gt;pid = process id&lt;br /&gt;&lt;br /&gt;ps aux | grep process_name &lt;br /&gt;- to search for a given process name , generally use this to fetch pid of process&lt;br /&gt;&lt;br /&gt;lsof -p pid&lt;br /&gt;- to get all the files or file descriptors being used by the process having pid&lt;br /&gt;&lt;br /&gt;lsof | grep file_name&lt;br /&gt;- to get the list processes using a given file&lt;br /&gt;&lt;br /&gt;sockstat | grep process_name&lt;br /&gt;- to see the socket connections between a host and desinations &lt;br /&gt;&lt;br /&gt;strace -p pid&lt;br /&gt;- to see what the process is doing in general&lt;br /&gt;&lt;br /&gt;nc hostname port&lt;br /&gt;- to see data flowing from the hostname at the given portu&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/683958699864453873-1442304402686194520?l=techjude.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://techjude.blogspot.com/feeds/1442304402686194520/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=683958699864453873&amp;postID=1442304402686194520' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/683958699864453873/posts/default/1442304402686194520'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/683958699864453873/posts/default/1442304402686194520'/><link rel='alternate' type='text/html' href='http://techjude.blogspot.com/2009/06/little-sugar-useful-commands-while.html' title='Little Sugar: Useful commands while programming on Unix Systems'/><author><name>KaranJude</name><uri>http://www.blogger.com/profile/08859421733871339100</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-683958699864453873.post-8386075995330413593</id><published>2009-06-09T02:55:00.000-07:00</published><updated>2009-06-09T02:59:25.907-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='. linux'/><category scheme='http://www.blogger.com/atom/ns#' term='daemon'/><category scheme='http://www.blogger.com/atom/ns#' term='unix'/><title type='text'>Little Sugar: Things to remember while creating a daemon</title><content type='html'>While writing a daemon on unix systems. The daemon should not be attached to any &lt;br /&gt;terminals. So make sure the following things hold valid.&lt;br /&gt;&lt;br /&gt;chdir '/'&lt;br /&gt;&lt;br /&gt;umask 0 &lt;br /&gt;&lt;br /&gt;Map STDIN to /dev/null&lt;br /&gt;Map STDOUT to your logging system&lt;br /&gt;MAP STRERR to STDOUT&lt;br /&gt;&lt;br /&gt;setsid  # Make the daemon a session leader&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/683958699864453873-8386075995330413593?l=techjude.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://techjude.blogspot.com/feeds/8386075995330413593/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=683958699864453873&amp;postID=8386075995330413593' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/683958699864453873/posts/default/8386075995330413593'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/683958699864453873/posts/default/8386075995330413593'/><link rel='alternate' type='text/html' href='http://techjude.blogspot.com/2009/06/little-sugar-things-to-remember-while.html' title='Little Sugar: Things to remember while creating a daemon'/><author><name>KaranJude</name><uri>http://www.blogger.com/profile/08859421733871339100</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-683958699864453873.post-5494826602002833315</id><published>2008-10-15T07:04:00.000-07:00</published><updated>2008-10-15T07:07:03.161-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='linux'/><category scheme='http://www.blogger.com/atom/ns#' term='programming'/><title type='text'>use find magic to create etags</title><content type='html'>To create a TAGS file so that you can work with emacs / vim use the following command&lt;br /&gt;&lt;br /&gt;find . -ipath '*.p*' -print | etags -&lt;br /&gt;&lt;br /&gt;the above command for example will create etags for all the pl , pm files in the current directory&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/683958699864453873-5494826602002833315?l=techjude.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://techjude.blogspot.com/feeds/5494826602002833315/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=683958699864453873&amp;postID=5494826602002833315' title='3 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/683958699864453873/posts/default/5494826602002833315'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/683958699864453873/posts/default/5494826602002833315'/><link rel='alternate' type='text/html' href='http://techjude.blogspot.com/2008/10/use-find-magic-to-create-etags.html' title='use find magic to create etags'/><author><name>KaranJude</name><uri>http://www.blogger.com/profile/08859421733871339100</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>3</thr:total></entry><entry><id>tag:blogger.com,1999:blog-683958699864453873.post-7894298531112153580</id><published>2008-09-27T13:06:00.000-07:00</published><updated>2008-09-27T13:12:46.070-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='c++'/><category scheme='http://www.blogger.com/atom/ns#' term='programming'/><category scheme='http://www.blogger.com/atom/ns#' term='little sugar'/><title type='text'>Little Sugar:Decreasing capacity in C++</title><content type='html'>When you use vector,string class in C++, the problem that happens is that the capacity just increases and does not decrease, causing the data structure to hog lot of memory.&lt;br /&gt;For example, say in the vector 10 elements were added , then to the same vector 1000000 elements were added. Then 900000 were deleted. This will not cause the capacity to decrease. This might result in the vector still holding on to a lot of memory.&lt;br /&gt;&lt;br /&gt;One way to fix this is the sap trick.&lt;br /&gt;&lt;br /&gt;vector &lt; int &gt; elements;  // the original vector&lt;br /&gt;&lt;br /&gt;vector &lt; int &gt; (elements.begin(), elements.end() ).swap(elements)&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/683958699864453873-7894298531112153580?l=techjude.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://techjude.blogspot.com/feeds/7894298531112153580/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=683958699864453873&amp;postID=7894298531112153580' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/683958699864453873/posts/default/7894298531112153580'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/683958699864453873/posts/default/7894298531112153580'/><link rel='alternate' type='text/html' href='http://techjude.blogspot.com/2008/09/little-sugardecreasing-capacity-in-c.html' title='Little Sugar:Decreasing capacity in C++'/><author><name>KaranJude</name><uri>http://www.blogger.com/profile/08859421733871339100</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-683958699864453873.post-2275138828025201925</id><published>2008-08-13T07:57:00.000-07:00</published><updated>2008-08-13T08:09:08.026-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='c++'/><category scheme='http://www.blogger.com/atom/ns#' term='programming'/><category scheme='http://www.blogger.com/atom/ns#' term='stl'/><title type='text'>vector::assign</title><content type='html'>"assign" is a method in STL for the vector class. When ever you need to erase the contents of the vector and replace it with totally new contents use the assign member function .You should use the operator= then all elements of the right hand side container would be copied to the container on the left hand side.  &lt;br /&gt;&lt;br /&gt;e.g &lt;br /&gt;&lt;br /&gt;v1.assign(v2.begin() + v2.size()/2 , v2.end())&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/683958699864453873-2275138828025201925?l=techjude.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://techjude.blogspot.com/feeds/2275138828025201925/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=683958699864453873&amp;postID=2275138828025201925' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/683958699864453873/posts/default/2275138828025201925'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/683958699864453873/posts/default/2275138828025201925'/><link rel='alternate' type='text/html' href='http://techjude.blogspot.com/2008/08/vectorassign.html' title='vector::assign'/><author><name>KaranJude</name><uri>http://www.blogger.com/profile/08859421733871339100</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-683958699864453873.post-6080216047999525224</id><published>2008-06-05T02:29:00.000-07:00</published><updated>2008-06-05T02:34:12.154-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='c++'/><category scheme='http://www.blogger.com/atom/ns#' term='programming'/><title type='text'>C++ : std::swap and template specialization</title><content type='html'>say you want to use the swap method provided in std namespace for your own class . Then  instead of using the std::swap option blindly , that would involve making use that your class has at least a copy constructor and that the assignment operator is overridden.&lt;br /&gt;&lt;br /&gt;It makes more sense to use template specialization for std::swap &lt;br /&gt;&lt;br /&gt;class MyClass {&lt;br /&gt;public:&lt;br /&gt; void Swap(MyClass &amp;) ;&lt;br /&gt;};&lt;br /&gt;&lt;br /&gt;namespace std {&lt;br /&gt; template&lt;&gt; swap&lt;MyClass&gt;(MyClass&amp; a, MyClass&amp; b){&lt;br /&gt;  a.Swap(b);&lt;br /&gt; }&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;so that way we just tune the default swap to use our class specific Swap and things become fast and simple for us .&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/683958699864453873-6080216047999525224?l=techjude.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://techjude.blogspot.com/feeds/6080216047999525224/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=683958699864453873&amp;postID=6080216047999525224' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/683958699864453873/posts/default/6080216047999525224'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/683958699864453873/posts/default/6080216047999525224'/><link rel='alternate' type='text/html' href='http://techjude.blogspot.com/2008/06/c-stdswap-and-template-specialization.html' title='C++ : std::swap and template specialization'/><author><name>KaranJude</name><uri>http://www.blogger.com/profile/08859421733871339100</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-683958699864453873.post-6808459197444823787</id><published>2008-06-04T06:43:00.000-07:00</published><updated>2008-06-04T06:49:46.756-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='c++'/><category scheme='http://www.blogger.com/atom/ns#' term='programming'/><title type='text'>C++ : std::mem_fun</title><content type='html'>Say you have a class &lt;br /&gt;&lt;br /&gt;class MyClass {&lt;br /&gt;public:&lt;br /&gt; int DoSomething(){&lt;br /&gt; }&lt;br /&gt;};&lt;br /&gt;&lt;br /&gt;now say you have &lt;br /&gt;&lt;br /&gt;std::vector&lt;MyClass&gt; classes;&lt;br /&gt;&lt;br /&gt;you can use something like this &lt;br /&gt;&lt;br /&gt;for_each(classes.begin(), classes.end(), &amp;DoSomething);&lt;br /&gt;&lt;br /&gt;where DoSomething is &lt;br /&gt;&lt;br /&gt;int DoSomething(MyClass&amp; e){&lt;br /&gt; d.DoSomething();&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;to call the member function DoSomething rather than the wrapper function use function calls like these&lt;br /&gt;&lt;br /&gt;for_each(classes.begin(), classes.end(), mem_fun_ref(&amp;MyClass::DoSomething));&lt;br /&gt;&lt;br /&gt;if the classes vector was defined something like this&lt;br /&gt;&lt;br /&gt;vector&lt;MyClass*&gt; classes&lt;br /&gt;&lt;br /&gt;then you would use something like this&lt;br /&gt;&lt;br /&gt;for_each(classes.begin(), classes.end(), mem_fun(&amp;MyClass::DoSomething));&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/683958699864453873-6808459197444823787?l=techjude.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://techjude.blogspot.com/feeds/6808459197444823787/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=683958699864453873&amp;postID=6808459197444823787' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/683958699864453873/posts/default/6808459197444823787'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/683958699864453873/posts/default/6808459197444823787'/><link rel='alternate' type='text/html' href='http://techjude.blogspot.com/2008/06/c-stdmemfun.html' title='C++ : std::mem_fun'/><author><name>KaranJude</name><uri>http://www.blogger.com/profile/08859421733871339100</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-683958699864453873.post-1818114315629876738</id><published>2008-06-04T05:04:00.000-07:00</published><updated>2008-06-04T05:08:21.925-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='c++'/><category scheme='http://www.blogger.com/atom/ns#' term='programming'/><title type='text'>C++ : Template specializations</title><content type='html'>Assuming you have a piece of code that is templatized and looks like this &lt;br /&gt;&lt;br /&gt;template&lt;typename T&gt;&lt;br /&gt;void prettyPrint(T value, char* buf);&lt;br /&gt;&lt;br /&gt;now assume that you are using sprintf for formatting the input . &lt;br /&gt;&lt;br /&gt;that being the case you can use template specializations like this :&lt;br /&gt;&lt;br /&gt;template&lt;&gt; void prettyPrint&lt;int&gt;(int value, char* buf){&lt;br /&gt; sprintf(buf, "%d", value);&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;template&lt;&gt; void prettyPrint&lt;char&gt;(char value, char* buf){&lt;br /&gt; sprintf(buf, "%c", value);&lt;br /&gt;}&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/683958699864453873-1818114315629876738?l=techjude.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://techjude.blogspot.com/feeds/1818114315629876738/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=683958699864453873&amp;postID=1818114315629876738' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/683958699864453873/posts/default/1818114315629876738'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/683958699864453873/posts/default/1818114315629876738'/><link rel='alternate' type='text/html' href='http://techjude.blogspot.com/2008/06/c-template-specializations.html' title='C++ : Template specializations'/><author><name>KaranJude</name><uri>http://www.blogger.com/profile/08859421733871339100</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-683958699864453873.post-6504767560133068473</id><published>2008-06-03T13:11:00.000-07:00</published><updated>2008-06-03T13:17:55.079-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='c++'/><category scheme='http://www.blogger.com/atom/ns#' term='programming'/><title type='text'>C++: copy magic</title><content type='html'>Say if you have a vector and you want to print it . Then instead of the normal for loop and cout call inside the loop you can do the following :&lt;br /&gt;&lt;br /&gt;if you have a vector "v"&lt;br /&gt;&lt;br /&gt;copy(v.begin(), v.end(), ostream_iterator&lt;int&gt;(cout, "\n"));&lt;br /&gt;&lt;br /&gt;this will print the entire vector . &lt;br /&gt;&lt;br /&gt;To generalize this you could use something like this :&lt;br /&gt;&lt;br /&gt;template&lt;class Container , class OutputIterator&gt;&lt;br /&gt;OutputIterator copy(const Container&amp; c, OutputIterator result){&lt;br /&gt; return std::copy(c.begin(), c.end(), result);&lt;br /&gt;}&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/683958699864453873-6504767560133068473?l=techjude.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://techjude.blogspot.com/feeds/6504767560133068473/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=683958699864453873&amp;postID=6504767560133068473' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/683958699864453873/posts/default/6504767560133068473'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/683958699864453873/posts/default/6504767560133068473'/><link rel='alternate' type='text/html' href='http://techjude.blogspot.com/2008/06/c-copy-magic.html' title='C++: copy magic'/><author><name>KaranJude</name><uri>http://www.blogger.com/profile/08859421733871339100</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-683958699864453873.post-4298910445156333993</id><published>2008-06-03T12:52:00.000-07:00</published><updated>2008-06-03T12:58:40.128-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='c++'/><title type='text'>C++ : pragma warning</title><content type='html'>if there is a header file after including which you start getting warnings , and especially if that header file is a third party header file , its better to wrap the header file with your own custom wrapper . &lt;br /&gt;&lt;br /&gt;#pragma warning(push)&lt;br /&gt;#pragma warning(disable:line_number_causing_warning)&lt;br /&gt;#include &lt;third_party_header_file.h&gt;&lt;br /&gt;#pragma warning(pop)&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/683958699864453873-4298910445156333993?l=techjude.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://techjude.blogspot.com/feeds/4298910445156333993/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=683958699864453873&amp;postID=4298910445156333993' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/683958699864453873/posts/default/4298910445156333993'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/683958699864453873/posts/default/4298910445156333993'/><link rel='alternate' type='text/html' href='http://techjude.blogspot.com/2008/06/c-pragma-warning.html' title='C++ : pragma warning'/><author><name>KaranJude</name><uri>http://www.blogger.com/profile/08859421733871339100</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-683958699864453873.post-3558966197648656898</id><published>2008-05-22T09:31:00.000-07:00</published><updated>2008-05-22T09:35:35.324-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='c++'/><category scheme='http://www.blogger.com/atom/ns#' term='little sugar'/><title type='text'>C++ : Little Sugar</title><content type='html'>In C++ when ever you see a function that accepts a const reference than its a valid candidate for temporaries . Temporaries are objects that are created and destroyed whenever there is mismatch in function arguments and a constructor exists that takes the passed argument and converts it to a destination entity via the constructor .&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/683958699864453873-3558966197648656898?l=techjude.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://techjude.blogspot.com/feeds/3558966197648656898/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=683958699864453873&amp;postID=3558966197648656898' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/683958699864453873/posts/default/3558966197648656898'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/683958699864453873/posts/default/3558966197648656898'/><link rel='alternate' type='text/html' href='http://techjude.blogspot.com/2008/05/c-little-sugar_679.html' title='C++ : Little Sugar'/><author><name>KaranJude</name><uri>http://www.blogger.com/profile/08859421733871339100</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-683958699864453873.post-217182291049791579</id><published>2008-05-22T07:24:00.000-07:00</published><updated>2008-05-22T07:32:03.033-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='c++'/><category scheme='http://www.blogger.com/atom/ns#' term='little sugar'/><title type='text'>C++ : Little Sugar</title><content type='html'>mutable keyword is useful in C++ , when you  are changing a member variable in side a constant function . A simple way to remove constantness of the "this" pointer is to use  code like this &lt;br /&gt;&lt;br /&gt;const_cast&lt;Class_Type *&gt;(this)&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/683958699864453873-217182291049791579?l=techjude.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://techjude.blogspot.com/feeds/217182291049791579/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=683958699864453873&amp;postID=217182291049791579' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/683958699864453873/posts/default/217182291049791579'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/683958699864453873/posts/default/217182291049791579'/><link rel='alternate' type='text/html' href='http://techjude.blogspot.com/2008/05/c-little-sugar_22.html' title='C++ : Little Sugar'/><author><name>KaranJude</name><uri>http://www.blogger.com/profile/08859421733871339100</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-683958699864453873.post-4600336375831761995</id><published>2008-05-22T06:47:00.000-07:00</published><updated>2008-05-22T07:15:04.793-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='c++'/><category scheme='http://www.blogger.com/atom/ns#' term='programming'/><title type='text'>C++ : new operator and operator new</title><content type='html'>The new operator in C++ is something that cannot be changed . For example &lt;br /&gt;when you use code something like this , &lt;br /&gt;&lt;br /&gt;string *ps = new string("Memory Management");&lt;br /&gt;&lt;br /&gt;the new operator is used . Its sole purpose is to allocate memory and initialize it.&lt;br /&gt;&lt;br /&gt;The new operator in turn uses the operator new to allocate memory which can be overloaded.&lt;br /&gt;&lt;br /&gt;its prototype looks like this :&lt;br /&gt;&lt;br /&gt;void * operator new(size_t size);&lt;br /&gt;&lt;br /&gt;there is another version of new operator called the placement new , that is used to create objects in pre initialized memory. example usage for it looks like this :&lt;br /&gt;&lt;br /&gt;string *ps = new(memory) string("Memory Management");&lt;br /&gt;&lt;br /&gt;same is the case for delete operator and operator delete&lt;br /&gt;&lt;br /&gt;operator new[] is another type of operator that can be used to allocate new arrays&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/683958699864453873-4600336375831761995?l=techjude.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://techjude.blogspot.com/feeds/4600336375831761995/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=683958699864453873&amp;postID=4600336375831761995' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/683958699864453873/posts/default/4600336375831761995'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/683958699864453873/posts/default/4600336375831761995'/><link rel='alternate' type='text/html' href='http://techjude.blogspot.com/2008/05/c-new-operator-and-operator-new.html' title='C++ : new operator and operator new'/><author><name>KaranJude</name><uri>http://www.blogger.com/profile/08859421733871339100</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-683958699864453873.post-55426230011437557</id><published>2008-05-20T23:06:00.000-07:00</published><updated>2008-05-20T23:11:33.686-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='c++'/><category scheme='http://www.blogger.com/atom/ns#' term='little sugar'/><title type='text'>C++ : Little Sugar</title><content type='html'>While creating objects in C++ , in order to initialize objects use the member initialization list. When initialization of a class starts , initialization of its members happens . If the member initialization list is not used the default constructor  of all the class members is called even before entering the constructor . Once inside the constructor the copy constructor or operator = is  called to initialize the member objects . &lt;br /&gt;&lt;br /&gt;On the other hand if member initialization list is used only the copy constructor is called once and hence you prevent the over head of an extra call.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/683958699864453873-55426230011437557?l=techjude.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://techjude.blogspot.com/feeds/55426230011437557/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=683958699864453873&amp;postID=55426230011437557' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/683958699864453873/posts/default/55426230011437557'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/683958699864453873/posts/default/55426230011437557'/><link rel='alternate' type='text/html' href='http://techjude.blogspot.com/2008/05/c-little-sugar.html' title='C++ : Little Sugar'/><author><name>KaranJude</name><uri>http://www.blogger.com/profile/08859421733871339100</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-683958699864453873.post-6891113650552212418</id><published>2008-05-19T07:05:00.000-07:00</published><updated>2008-05-19T07:19:27.500-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='c++'/><category scheme='http://www.blogger.com/atom/ns#' term='programming'/><title type='text'>C++ : Creating Objects</title><content type='html'>Here are 2 simple rules to allocating and deleting objects.&lt;br /&gt;&lt;br /&gt;MyObject * myPointer;&lt;br /&gt;&lt;br /&gt;while updating object memory always use code like this:&lt;br /&gt;&lt;br /&gt;MyObject::update(){&lt;br /&gt; delete myPointer;&lt;br /&gt; myPointer = NULL;&lt;br /&gt; myPointer = MyObject::CreateNew();&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;while deallocating always use code like this:&lt;br /&gt;&lt;br /&gt;MyObject::~MyObject(){&lt;br /&gt; delete myPointer;&lt;br /&gt; myPointer = NULL;&lt;br /&gt;}&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/683958699864453873-6891113650552212418?l=techjude.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://techjude.blogspot.com/feeds/6891113650552212418/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=683958699864453873&amp;postID=6891113650552212418' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/683958699864453873/posts/default/6891113650552212418'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/683958699864453873/posts/default/6891113650552212418'/><link rel='alternate' type='text/html' href='http://techjude.blogspot.com/2008/05/c-creating-objects.html' title='C++ : Creating Objects'/><author><name>KaranJude</name><uri>http://www.blogger.com/profile/08859421733871339100</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-683958699864453873.post-7562139661263691257</id><published>2008-04-29T03:58:00.000-07:00</published><updated>2008-04-29T03:59:30.757-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='refactoring'/><title type='text'>Refactoring Large Methods: Refactoring</title><content type='html'>Refactoring Large Methods:&lt;br /&gt;&lt;br /&gt;"The object programs that live best and longest &lt;br /&gt;&lt;br /&gt;are those with short methods. Programmers new to &lt;br /&gt;&lt;br /&gt;objects often feel that no computation ever takes &lt;br /&gt;&lt;br /&gt;place, that object programs are endless sequences &lt;br /&gt;&lt;br /&gt;of delegation. When you have lived with such a &lt;br /&gt;&lt;br /&gt;program for a few years, however, you learn just &lt;br /&gt;&lt;br /&gt;how valuable all those little methods are. All of &lt;br /&gt;&lt;br /&gt;the payoffs of indirection—explanation, sharing, &lt;br /&gt;&lt;br /&gt;and choosing—are supported by little methods" - &lt;br /&gt;&lt;br /&gt;Refactoring Book - Martin Fowler&lt;br /&gt;&lt;br /&gt;Large Methods are code smells.To refactor large &lt;br /&gt;&lt;br /&gt;methods follow the following methods :&lt;br /&gt;&lt;br /&gt;-&gt; Use extract method refactoring to extract a &lt;br /&gt;&lt;br /&gt;lot of small methods&lt;br /&gt;&lt;br /&gt;-&gt; In case of a method having a number of &lt;br /&gt;&lt;br /&gt;temporary variables , temporary variables can be &lt;br /&gt;&lt;br /&gt;replaced by query methods&lt;br /&gt;&lt;br /&gt;-&gt; A query method is a small method that is &lt;br /&gt;&lt;br /&gt;intended to replace variables .&lt;br /&gt;&lt;br /&gt;e.g int myVariable = oldValue1 * oldValue2&lt;br /&gt;&lt;br /&gt;create a new method like&lt;br /&gt;&lt;br /&gt;int getValue(){&lt;br /&gt; return oldValue1 * oldValue2; &lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;now replace all usages to myVariable by the &lt;br /&gt;method getValue()&lt;br /&gt;&lt;br /&gt;-&gt; Then try introduce Parameter Object &lt;br /&gt;&lt;br /&gt;refactoring to take care of huge number &lt;br /&gt;&lt;br /&gt;parameters in the extracted method&lt;br /&gt;&lt;br /&gt;-&gt; Use Preserve Whole Object Refactoring in case &lt;br /&gt;&lt;br /&gt;lot of parameters are passed to methods , and &lt;br /&gt;&lt;br /&gt;each of these parameters are local values.&lt;br /&gt;&lt;br /&gt;-&gt; If still extract method refactoring becomes &lt;br /&gt;&lt;br /&gt;difficult use "Replace method with Method Object" &lt;br /&gt;&lt;br /&gt;refactoring&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/683958699864453873-7562139661263691257?l=techjude.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://techjude.blogspot.com/feeds/7562139661263691257/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=683958699864453873&amp;postID=7562139661263691257' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/683958699864453873/posts/default/7562139661263691257'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/683958699864453873/posts/default/7562139661263691257'/><link rel='alternate' type='text/html' href='http://techjude.blogspot.com/2008/04/refactoring-large-methods-refactoring.html' title='Refactoring Large Methods: Refactoring'/><author><name>KaranJude</name><uri>http://www.blogger.com/profile/08859421733871339100</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-683958699864453873.post-5329242702247869854</id><published>2008-04-27T11:49:00.000-07:00</published><updated>2008-04-27T12:03:22.560-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='c++'/><category scheme='http://www.blogger.com/atom/ns#' term='algorithm'/><title type='text'>QuickSort : C++</title><content type='html'>i was having a re look at quick sort.&lt;br /&gt;&lt;br /&gt;Here is the code in c++ :&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;&lt;br /&gt;template&amp;lt; class T &amp;gt;&lt;br /&gt;int partition(T a[], int p, int r){&lt;br /&gt; T x = a[r];&lt;br /&gt; int i = p - 1;&lt;br /&gt; for(int j = p;j &lt; r;j++){&lt;br /&gt;  if(a[j] &lt;= x){&lt;br /&gt;   i++;&lt;br /&gt;   swap(a[i],a[j]);&lt;br /&gt;  }&lt;br /&gt; }&lt;br /&gt; swap(a[i+1] , a[r]);&lt;br /&gt; return i + 1;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;template&amp;lt; class T &amp;gt;&lt;br /&gt;void quickSort(T a[], int p, int r){&lt;br /&gt; if(p &lt; r){&lt;br /&gt;  int q = partition(a, p , r);&lt;br /&gt;  quickSort(a, p , q-1);&lt;br /&gt;  quickSort(a, q+1 , r);&lt;br /&gt; }&lt;br /&gt;}&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;The idea of quicksort is to take an array and divide it into partitions . &lt;br /&gt;First a key is chosen . That is called the pivot . Here 'x' is the pivot . &lt;br /&gt;Based on the value of 'x' other values in an array are put in 2 partitions .&lt;br /&gt;One partition that contains values less than 'x' and other partition contains values greater than x . &lt;br /&gt;&lt;br /&gt;Here i and j are used to mark the extent of these 2 partitions . &lt;br /&gt;&lt;br /&gt;The beauty of the algorithm lies in the fact , how integers are used to manipulate partitions . 'i' is initially set to value that precedes a real boundary . 'j' is set to the first location in the array . Now as values are compared with 'x' ( the key)&lt;br /&gt;if value is less than 'x' the partition extent marked by 'i' are increased , else the partition extent marked by 'j' is increased . In the first case where values of 'i' is less than 'x' and since 'i' now occupies what 'j' occupied the values at those indices are swapped . &lt;br /&gt;&lt;br /&gt;the partition method does in place sorting of the array and the quickSort method is responsible for choosing partitons .&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/683958699864453873-5329242702247869854?l=techjude.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://techjude.blogspot.com/feeds/5329242702247869854/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=683958699864453873&amp;postID=5329242702247869854' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/683958699864453873/posts/default/5329242702247869854'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/683958699864453873/posts/default/5329242702247869854'/><link rel='alternate' type='text/html' href='http://techjude.blogspot.com/2008/04/quicksort-c.html' title='QuickSort : C++'/><author><name>KaranJude</name><uri>http://www.blogger.com/profile/08859421733871339100</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-683958699864453873.post-8663588092099583143</id><published>2008-04-13T14:11:00.000-07:00</published><updated>2008-04-13T14:19:04.924-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='c++'/><category scheme='http://www.blogger.com/atom/ns#' term='programming'/><title type='text'>C++ : template specialization</title><content type='html'>template &lt;&gt;&lt;br /&gt;char* Add&amp;lt;char*&amp;gt;(char* a , char* b){&lt;br /&gt;   return strcat(a,b);&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;char * res = Add&amp;lt;char*&amp;gt;("foo","bar");&lt;br /&gt;&lt;br /&gt;This code refers to a new type of syntax for templates called template specialization syntax.&lt;br /&gt;Generally when you write code for templates .&lt;br /&gt;&lt;br /&gt;you end up using stuff like&lt;br /&gt;&lt;br /&gt;template&amp;lt;class&amp;gt;&lt;br /&gt;&lt;br /&gt;but say you want the same generic code for many cases . In the above mentioned code for example if the add function used the "+" operator to add two types it would have not worked for char* pointers , because the "+" operator does not work with them .&lt;br /&gt;&lt;br /&gt;by using the syntax as mentioned above its possible to tell the compiler that there are exceptions to your generic code and that for special cases these new methods should be called.&lt;/class&gt;&lt;/char*&gt;&lt;/char*&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/683958699864453873-8663588092099583143?l=techjude.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://techjude.blogspot.com/feeds/8663588092099583143/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=683958699864453873&amp;postID=8663588092099583143' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/683958699864453873/posts/default/8663588092099583143'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/683958699864453873/posts/default/8663588092099583143'/><link rel='alternate' type='text/html' href='http://techjude.blogspot.com/2008/04/c-template-specialization.html' title='C++ : template specialization'/><author><name>KaranJude</name><uri>http://www.blogger.com/profile/08859421733871339100</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-683958699864453873.post-8308012912885398467</id><published>2008-04-13T13:41:00.000-07:00</published><updated>2008-04-13T13:58:35.266-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='c++'/><category scheme='http://www.blogger.com/atom/ns#' term='programming'/><title type='text'>C++ : The need for virtual destructors</title><content type='html'>With the advent of object oriented languages the use of polymophism became very common .&lt;br /&gt;In C++ when you have a derived Class and a base class .&lt;br /&gt;&lt;br /&gt;when you have code like this :&lt;br /&gt;&lt;br /&gt;class Base {&lt;br /&gt;};&lt;br /&gt;&lt;br /&gt;class Derived : public Base{&lt;br /&gt;};&lt;br /&gt;&lt;br /&gt;Base * p = new Derived();&lt;br /&gt;&lt;br /&gt;delete p;&lt;br /&gt;&lt;br /&gt;what's wrong with it .&lt;br /&gt;&lt;br /&gt;Since this piece of code is based on polymorphism , the base pointer will refer to an instance of a derived class object .&lt;br /&gt;&lt;br /&gt;when delete on the pointer p is called , due to  static typing in c++ , destructor of Base is called , instead of Derived . To correct this&lt;br /&gt;&lt;br /&gt;virtual ~Base(){&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;should be added . By making the destructor virtual the destructor of the derived class would be called now .&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/683958699864453873-8308012912885398467?l=techjude.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://techjude.blogspot.com/feeds/8308012912885398467/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=683958699864453873&amp;postID=8308012912885398467' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/683958699864453873/posts/default/8308012912885398467'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/683958699864453873/posts/default/8308012912885398467'/><link rel='alternate' type='text/html' href='http://techjude.blogspot.com/2008/04/c-need-for-virtual-destructors.html' title='C++ : The need for virtual destructors'/><author><name>KaranJude</name><uri>http://www.blogger.com/profile/08859421733871339100</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-683958699864453873.post-1290444769088697896</id><published>2008-04-12T02:45:00.000-07:00</published><updated>2008-04-12T02:49:43.412-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='programming'/><category scheme='http://www.blogger.com/atom/ns#' term='refactoring'/><title type='text'>Refactoring : Self Encapsulate Field</title><content type='html'>Some times in a code base , especially inside a class , a field is referenced from many places.&lt;br /&gt;Say you decide to move this field to another class .&lt;br /&gt;&lt;br /&gt;A clean way of doing this is to first extract a getter method for that field within the same class .&lt;br /&gt;Now with all occurances replaced by the getter method , move this getter method to the new class .&lt;br /&gt;Similarly replace the code where the field is being set by the appropriate setter code and then move the setter code to another class .&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/683958699864453873-1290444769088697896?l=techjude.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://techjude.blogspot.com/feeds/1290444769088697896/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=683958699864453873&amp;postID=1290444769088697896' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/683958699864453873/posts/default/1290444769088697896'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/683958699864453873/posts/default/1290444769088697896'/><link rel='alternate' type='text/html' href='http://techjude.blogspot.com/2008/04/refactoring-self-encapsulate-field.html' title='Refactoring : Self Encapsulate Field'/><author><name>KaranJude</name><uri>http://www.blogger.com/profile/08859421733871339100</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-683958699864453873.post-5917890558720096165</id><published>2008-04-12T02:23:00.000-07:00</published><updated>2008-04-12T02:43:54.643-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='programming'/><category scheme='http://www.blogger.com/atom/ns#' term='refactoring'/><title type='text'>Refactroing : Handling Duplicate Code</title><content type='html'>In legacy code bases we see lot of duplicate code . so how do we handle it ?&lt;br /&gt;&lt;br /&gt;I am assuming you are using a tool that supports refactoring . In that case ,&lt;br /&gt;&lt;br /&gt;Case 1:&lt;br /&gt;&lt;br /&gt;If in a class you have lot of repeated code , use extract method refactoring to move the repeated code into a common method inside the class . Now replace if not automatically all occurance s of the repeated code with the call to the newly created method.&lt;br /&gt;&lt;br /&gt;Case 2:&lt;br /&gt;&lt;br /&gt;You have 2 sibling classes that have same piece of code .&lt;br /&gt;&lt;br /&gt;Use extract method to create method with the same name in the 2 classes . Then use pull up refactoring to pull up the common method now in a super class . If the super class does not exist create it now .&lt;br /&gt;&lt;br /&gt;Case 3:&lt;br /&gt;&lt;br /&gt;You have 2 sibling classes that have almost the same piece of code , but some different bits here and there .&lt;br /&gt;&lt;br /&gt;Use extract method to create method with the same signature in both the classes . Then identify the parts that are different , extract these different parts into methods of their own . Make sure that the names of these different parts is same in both sibling classes.&lt;br /&gt;&lt;br /&gt;Now use template method design pattern , to create a common method in a super class of these 2 siblings . Using polymorph ism and inheritance to implement the different methods in the sibling classes.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/683958699864453873-5917890558720096165?l=techjude.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://techjude.blogspot.com/feeds/5917890558720096165/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=683958699864453873&amp;postID=5917890558720096165' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/683958699864453873/posts/default/5917890558720096165'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/683958699864453873/posts/default/5917890558720096165'/><link rel='alternate' type='text/html' href='http://techjude.blogspot.com/2008/04/refactroing-handling-duplicate-code.html' title='Refactroing : Handling Duplicate Code'/><author><name>KaranJude</name><uri>http://www.blogger.com/profile/08859421733871339100</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-683958699864453873.post-433682420794402428</id><published>2008-04-08T12:32:00.000-07:00</published><updated>2008-04-08T12:40:13.517-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='c++'/><category scheme='http://www.blogger.com/atom/ns#' term='programming'/><title type='text'>C++: Object slicing and pass by value</title><content type='html'>In C++ , when a object is passed by value to a function that accepts a parameter then object slicing might happen. Consider the following class&lt;br /&gt;&lt;br /&gt;class Base {&lt;br /&gt;public:&lt;br /&gt; virtual const char * toString() throw();&lt;br /&gt;&lt;br /&gt;};&lt;br /&gt;&lt;br /&gt;class Derived : public Base {&lt;br /&gt;public:&lt;br /&gt; virtual const char* toString() throw();&lt;br /&gt;};&lt;br /&gt;&lt;br /&gt;Derived derived;&lt;br /&gt;Base base;&lt;br /&gt;&lt;br /&gt;void doSomething(Base base){&lt;br /&gt;....&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;doSomething(base);&lt;br /&gt;doSomething(derived);&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;now we have 2 classes Base and Derived with a common virtual function that have been overridden in the derived class . We create 2 objects "derived" and "base".&lt;br /&gt;&lt;br /&gt;Both of them are passed to the function doSomething . What happens in this case .&lt;br /&gt;&lt;br /&gt;In the first case , it works the way its supposed to . In the second case , object slicing takes place and the members that are just of derived class are chopped off and the virtual function of the base class is called.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/683958699864453873-433682420794402428?l=techjude.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://techjude.blogspot.com/feeds/433682420794402428/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=683958699864453873&amp;postID=433682420794402428' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/683958699864453873/posts/default/433682420794402428'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/683958699864453873/posts/default/433682420794402428'/><link rel='alternate' type='text/html' href='http://techjude.blogspot.com/2008/04/c-object-slicing-and-pass-by-value.html' title='C++: Object slicing and pass by value'/><author><name>KaranJude</name><uri>http://www.blogger.com/profile/08859421733871339100</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-683958699864453873.post-3562236880750827678</id><published>2008-04-07T11:51:00.000-07:00</published><updated>2008-04-07T12:00:10.037-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='c++'/><category scheme='http://www.blogger.com/atom/ns#' term='programming'/><title type='text'>C++ : pointer to member function</title><content type='html'>class Foo{&lt;br /&gt;public:&lt;br /&gt; int iVal;&lt;br /&gt; int Bar(int);&lt;br /&gt;};&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;int Foo::* pm;&lt;br /&gt;&lt;br /&gt;is a pointer to a member variable that is an integer.&lt;br /&gt;&lt;br /&gt;pm = &amp;amp;Foo::iVal;&lt;br /&gt;&lt;br /&gt;is used to initailize a pointer to a member variable&lt;br /&gt;&lt;br /&gt;Foo foo;&lt;br /&gt;&lt;br /&gt;int i = foo.*pm&lt;br /&gt;&lt;br /&gt;is used to retrieve values of the pointer to member variable&lt;br /&gt;&lt;br /&gt;int (Foo::*pmf) (int) = &amp;amp;Foo::Bar;&lt;br /&gt;&lt;br /&gt;is a pointer to member function that is initialized by the address of member function Bar&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/683958699864453873-3562236880750827678?l=techjude.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://techjude.blogspot.com/feeds/3562236880750827678/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=683958699864453873&amp;postID=3562236880750827678' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/683958699864453873/posts/default/3562236880750827678'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/683958699864453873/posts/default/3562236880750827678'/><link rel='alternate' type='text/html' href='http://techjude.blogspot.com/2008/04/c-pointer-to-member-function.html' title='C++ : pointer to member function'/><author><name>KaranJude</name><uri>http://www.blogger.com/profile/08859421733871339100</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-683958699864453873.post-1555837239454842216</id><published>2008-04-07T04:53:00.000-07:00</published><updated>2008-04-07T04:58:51.275-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='c++'/><category scheme='http://www.blogger.com/atom/ns#' term='programming'/><title type='text'>C++ : Preventing implicit type conversion</title><content type='html'>class Foo{&lt;br /&gt;public:&lt;br /&gt;&lt;br /&gt;Foo(int n ){&lt;br /&gt; ...&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;};&lt;br /&gt;&lt;br /&gt;Foo foo(42);&lt;br /&gt;Foo boo = 42;&lt;br /&gt;&lt;br /&gt;In the above mentioned snippet , the first constructor is matched and called. In the second case , for the assignment operator since the right hand side is 42 and since we have a constructor that takes integer as an argument . The corresponding constructor is called . This is syntactic sugar that can lead to lots of problems . To prevent something like this .&lt;br /&gt;&lt;br /&gt;the &lt;span style="font-weight: bold;"&gt;explicit &lt;/span&gt;&lt;span&gt;keyword should be used in front of constructors .&lt;br /&gt;&lt;/span&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/683958699864453873-1555837239454842216?l=techjude.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://techjude.blogspot.com/feeds/1555837239454842216/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=683958699864453873&amp;postID=1555837239454842216' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/683958699864453873/posts/default/1555837239454842216'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/683958699864453873/posts/default/1555837239454842216'/><link rel='alternate' type='text/html' href='http://techjude.blogspot.com/2008/04/c-preventing-implicit-type-conversion.html' title='C++ : Preventing implicit type conversion'/><author><name>KaranJude</name><uri>http://www.blogger.com/profile/08859421733871339100</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-683958699864453873.post-5023673559544838538</id><published>2008-04-02T01:50:00.000-07:00</published><updated>2008-04-02T01:53:31.103-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='c++'/><category scheme='http://www.blogger.com/atom/ns#' term='programming'/><title type='text'>C++: Rethrowing exceptions</title><content type='html'>Consider the following piece of code &lt;br /&gt;&lt;br /&gt;catch (Base&amp; w)                 &lt;br /&gt;{&lt;br /&gt;  ...                             &lt;br /&gt;  throw;                          &lt;br /&gt;}                                 &lt;br /&gt;catch (Base&amp; w)                 &lt;br /&gt;{&lt;br /&gt;  ...                             &lt;br /&gt;  throw w;                        &lt;br /&gt;}                                 &lt;br /&gt;&lt;br /&gt;What do you think is the difference between the 2 approaches above .&lt;br /&gt;&lt;br /&gt;In the first case , the exception is re thrown . In the second case a copy is made and a new exception is thrown . Also the copy is based on the static type i.e &lt;br /&gt;Base (copy constructor is called )&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/683958699864453873-5023673559544838538?l=techjude.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://techjude.blogspot.com/feeds/5023673559544838538/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=683958699864453873&amp;postID=5023673559544838538' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/683958699864453873/posts/default/5023673559544838538'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/683958699864453873/posts/default/5023673559544838538'/><link rel='alternate' type='text/html' href='http://techjude.blogspot.com/2008/04/c-rethrowing-exceptions.html' title='C++: Rethrowing exceptions'/><author><name>KaranJude</name><uri>http://www.blogger.com/profile/08859421733871339100</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-683958699864453873.post-5645212889893236545</id><published>2008-04-02T01:37:00.000-07:00</published><updated>2008-04-02T01:41:43.947-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='c++'/><category scheme='http://www.blogger.com/atom/ns#' term='programming'/><title type='text'>C++ : Object Copies in C++ are based on Object's Static Type Not Dynamic Type</title><content type='html'>Consider the following piece of code&lt;br /&gt;&lt;br /&gt;class Base { ... };&lt;br /&gt;class Derived: public Base { ... };&lt;br /&gt;&lt;br /&gt;void passAndThrowDerived()&lt;br /&gt;{&lt;br /&gt;  Derived local;&lt;br /&gt;  ...&lt;br /&gt;  Base&amp; rw = local;      &lt;br /&gt;                                        &lt;br /&gt;  throw rw;                             &lt;br /&gt;                                        &lt;br /&gt;}                                       &lt;br /&gt;&lt;br /&gt;&lt;br /&gt;In the above mentioned case . When a copy of rw is made while throwing it . &lt;br /&gt;The copy constructor for the type is called . In this case the since rw is a reference to Base there fore the copy constructor of Base is called rather than the &lt;br /&gt;Copy Constructor of Derived class.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/683958699864453873-5645212889893236545?l=techjude.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://techjude.blogspot.com/feeds/5645212889893236545/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=683958699864453873&amp;postID=5645212889893236545' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/683958699864453873/posts/default/5645212889893236545'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/683958699864453873/posts/default/5645212889893236545'/><link rel='alternate' type='text/html' href='http://techjude.blogspot.com/2008/04/c-object-copies-in-c-are-based-on.html' title='C++ : Object Copies in C++ are based on Object&apos;s Static Type Not Dynamic Type'/><author><name>KaranJude</name><uri>http://www.blogger.com/profile/08859421733871339100</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-683958699864453873.post-8631721255975145848</id><published>2008-04-02T01:00:00.000-07:00</published><updated>2008-04-02T01:05:30.083-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='c++'/><category scheme='http://www.blogger.com/atom/ns#' term='programming'/><title type='text'>C++ : Why are objects thrown as exception always copied</title><content type='html'>When an exception is thrown , the objects are generally copied. To explain this consider the following :&lt;br /&gt;&lt;br /&gt;{&lt;br /&gt; MyObject myObject;&lt;br /&gt; cin &gt;&gt; myObject;          &lt;br /&gt; throw myObject; &lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;if the object myObject was passed by reference then the same myObject would be thrown out . If the same object is thrown out then as soon as it goes out of scope , its destructor would get called and as a result of which some garbage would finally reach the exceptional handling code . &lt;br /&gt;&lt;br /&gt;It is for this reason that copies of myObject are thrown rather than the original one .&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/683958699864453873-8631721255975145848?l=techjude.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://techjude.blogspot.com/feeds/8631721255975145848/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=683958699864453873&amp;postID=8631721255975145848' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/683958699864453873/posts/default/8631721255975145848'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/683958699864453873/posts/default/8631721255975145848'/><link rel='alternate' type='text/html' href='http://techjude.blogspot.com/2008/04/c-why-are-objects-thrown-as-exception.html' title='C++ : Why are objects thrown as exception always copied'/><author><name>KaranJude</name><uri>http://www.blogger.com/profile/08859421733871339100</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-683958699864453873.post-6147007272978002403</id><published>2008-03-24T11:01:00.000-07:00</published><updated>2008-03-24T11:58:24.687-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='c++'/><category scheme='http://www.blogger.com/atom/ns#' term='programming'/><category scheme='http://www.blogger.com/atom/ns#' term='little sugar'/><title type='text'>Little Sugar : C++</title><content type='html'>In C++ have you imagined what would happen if the destructor of your class throws an exception . For starters , the object would not get destroyed properly . Actually in reality the control would go back to the callee from the current point directly.&lt;br /&gt;&lt;br /&gt;Alright , now think what would happen if the destructor got called as a part of some exception handling code and this destructor threw an exception .&lt;br /&gt;&lt;br /&gt;Since the active callee is calling the destructor due to some raised exception . &lt;br /&gt;it would result in the terminate() function getting called and though would terminate the program immediately&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/683958699864453873-6147007272978002403?l=techjude.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://techjude.blogspot.com/feeds/6147007272978002403/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=683958699864453873&amp;postID=6147007272978002403' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/683958699864453873/posts/default/6147007272978002403'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/683958699864453873/posts/default/6147007272978002403'/><link rel='alternate' type='text/html' href='http://techjude.blogspot.com/2008/03/little-sugar-c_24.html' title='Little Sugar : C++'/><author><name>KaranJude</name><uri>http://www.blogger.com/profile/08859421733871339100</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-683958699864453873.post-2931985280678466135</id><published>2008-03-23T04:02:00.000-07:00</published><updated>2008-03-23T04:48:06.062-07:00</updated><title type='text'>ThoughtWorks: Why it should be your first Software Company ??</title><content type='html'>&lt;a href="http://www.thoughtworks.com/"&gt;ThoughtWorks&lt;/a&gt; , should be your first software company because:&lt;br /&gt;&lt;br /&gt;You will learn..&lt;br /&gt;&lt;br /&gt;&lt;ul&gt;&lt;li&gt;&lt;span style="font-style: italic;"&gt;What good software design is all about. You will hone the skills that will enable you  to write good solid beautiful code .&lt;/span&gt; &lt;/li&gt;&lt;/ul&gt;&lt;ul style="font-style: italic;"&gt;&lt;li&gt;Good coding  practices e.g ( Test Driven Development .. )&lt;/li&gt;&lt;/ul&gt;&lt;ul style="font-style: italic;"&gt;&lt;li&gt;To re factor code properly and effectively .&lt;/li&gt;&lt;/ul&gt;&lt;ul&gt;&lt;li&gt;&lt;span style="font-style: italic;"&gt;How to test your code like crazy&lt;/span&gt;&lt;br /&gt;&lt;/li&gt;&lt;/ul&gt;Other reasons why you will love Thoughtworks..&lt;br /&gt;&lt;br /&gt;&lt;ul&gt;&lt;li&gt;&lt;span style="font-style: italic;"&gt; People adore Ruby and Python ;) and use them for their project work&lt;/span&gt;&lt;br /&gt;&lt;/li&gt;&lt;/ul&gt;&lt;ul style="font-style: italic;"&gt;&lt;li&gt; Fellow developers try  out cool  and technologies like Erlang and haskell and incite you to try something or do something different.&lt;/li&gt;&lt;/ul&gt;&lt;ul&gt;&lt;li&gt;&lt;span style="font-style: italic;"&gt;Free Food&lt;/span&gt;&lt;br /&gt;&lt;/li&gt;&lt;/ul&gt;&lt;ul&gt;&lt;li&gt;&lt;span style="font-style: italic;"&gt;XBox , PlayStation&lt;/span&gt; &lt;/li&gt;&lt;/ul&gt;&lt;ul style="font-style: italic;"&gt;&lt;li&gt;Table Tennis and other games .&lt;/li&gt;&lt;/ul&gt;&lt;ul style="font-style: italic;"&gt;&lt;li&gt;Cool outings and free booze ;)&lt;/li&gt;&lt;/ul&gt;&lt;ul style="font-style: italic;"&gt;&lt;li&gt; Amazing people from whom you 'll learn like crazy almost everyday , till the next 1.5 yrs&lt;/li&gt;&lt;/ul&gt;&lt;ul style="font-style: italic;"&gt;&lt;li&gt;You can play pranks on the CEO and he wont fire you .&lt;/li&gt;&lt;/ul&gt;&lt;span style="font-weight: bold;"&gt;And finally an average ThoughtWorker with 1.5 yrs of work experience =  most of the  Software Engineers with  3.5 yrs of experience .&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;So if you want a head start , &lt;a href="http://www.thoughtworks.com/"&gt;ThoughtWorks&lt;/a&gt; is the place to be ;)&lt;br /&gt;&lt;br /&gt;&lt;script type="text/javascript" src="http://reddit.com/button.js?t=1"&gt;&lt;/script&gt;&lt;br /&gt;&lt;script language="javascript" src="http://widgets.dzone.com/widgets/zoneit.js"&gt;&lt;/script&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/683958699864453873-2931985280678466135?l=techjude.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://techjude.blogspot.com/feeds/2931985280678466135/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=683958699864453873&amp;postID=2931985280678466135' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/683958699864453873/posts/default/2931985280678466135'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/683958699864453873/posts/default/2931985280678466135'/><link rel='alternate' type='text/html' href='http://techjude.blogspot.com/2008/03/thoughtworks-why-it-should-be-your.html' title='ThoughtWorks: Why it should be your first Software Company ??'/><author><name>KaranJude</name><uri>http://www.blogger.com/profile/08859421733871339100</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-683958699864453873.post-3569762056044488940</id><published>2008-03-20T06:11:00.000-07:00</published><updated>2008-03-20T06:17:34.762-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='java'/><category scheme='http://www.blogger.com/atom/ns#' term='programming'/><title type='text'>Java Thread Programming : Using Semaphores</title><content type='html'>The java concurrent framework provides Semaphore . Semaphores are useful when the end user wants to implement some kind of resource pool.&lt;br /&gt;&lt;br /&gt;In a semaphore permits can be acquired and released . A semaphore when created can be initialized with the number of entries it can contain at any point of time .&lt;br /&gt;&lt;br /&gt;Semaphore s = new Semaphore(N);&lt;br /&gt;&lt;br /&gt;// acquire a permit&lt;br /&gt;&lt;br /&gt;s.acquire();&lt;br /&gt;&lt;br /&gt;// release a permit&lt;br /&gt;&lt;br /&gt;s.release();&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/683958699864453873-3569762056044488940?l=techjude.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://techjude.blogspot.com/feeds/3569762056044488940/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=683958699864453873&amp;postID=3569762056044488940' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/683958699864453873/posts/default/3569762056044488940'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/683958699864453873/posts/default/3569762056044488940'/><link rel='alternate' type='text/html' href='http://techjude.blogspot.com/2008/03/java-thread-programming-using.html' title='Java Thread Programming : Using Semaphores'/><author><name>KaranJude</name><uri>http://www.blogger.com/profile/08859421733871339100</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-683958699864453873.post-8702196087631057577</id><published>2008-03-20T04:30:00.000-07:00</published><updated>2008-03-20T04:42:06.513-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='java'/><category scheme='http://www.blogger.com/atom/ns#' term='programming'/><title type='text'>Java Concurrent Programming : CountDownLatch</title><content type='html'>CountDownLatch in the concurrent programming framework provided by java is pretty cool.&lt;br /&gt;In principle it works like a binary latch . (Once set it remain in that state for ever )&lt;br /&gt;&lt;br /&gt;So when would something like a countdownlatch be useful for thread programming .&lt;br /&gt;&lt;br /&gt;Consider a scenario , you have a  big task T to be done by  N threads .&lt;br /&gt;&lt;br /&gt;1) Now you want all the threads to be started at the same time so that they get equal opportunity&lt;br /&gt;to participate in the completion of the task .&lt;br /&gt;&lt;br /&gt;2) You want your main thread to do something when all the threads finish .&lt;br /&gt;&lt;br /&gt;You can create two CountDownLatch objects.&lt;br /&gt;&lt;br /&gt;CountDownLatch startLatch = new CountDownLatch(1);&lt;br /&gt;CountDownLatch endLatch = new CountDownLatch(N);&lt;br /&gt;&lt;br /&gt;Then you can construct all the threads like this&lt;br /&gt;&lt;br /&gt;Thread thread = new Thread(){&lt;br /&gt; public void run(){&lt;br /&gt;  try{&lt;br /&gt;   startLatch.await();&lt;br /&gt;   // do the task&lt;br /&gt;   endLatch.countDown();    &lt;br /&gt;  }catch(InterruptedException e){&lt;br /&gt;    Thread.currentThread.interrupt();&lt;br /&gt; }&lt;br /&gt;&lt;br /&gt; }&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;thread.start();&lt;br /&gt;&lt;br /&gt;so when the thread starts it will block cause of the CountDownLatch (await method call)&lt;br /&gt;&lt;br /&gt;when startLatch.countDown() is called the latch opens and all the threads can flow now and start working .&lt;br /&gt;&lt;br /&gt;similarly the main thread that is waiting for all threads to finish .&lt;br /&gt;&lt;br /&gt;will continue when all the threads have  called endLatch.countDown()&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/683958699864453873-8702196087631057577?l=techjude.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://techjude.blogspot.com/feeds/8702196087631057577/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=683958699864453873&amp;postID=8702196087631057577' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/683958699864453873/posts/default/8702196087631057577'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/683958699864453873/posts/default/8702196087631057577'/><link rel='alternate' type='text/html' href='http://techjude.blogspot.com/2008/03/java-concurrent-programming.html' title='Java Concurrent Programming : CountDownLatch'/><author><name>KaranJude</name><uri>http://www.blogger.com/profile/08859421733871339100</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-683958699864453873.post-7466516367024672067</id><published>2008-03-17T06:45:00.000-07:00</published><updated>2008-03-17T06:59:30.090-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='programming'/><category scheme='http://www.blogger.com/atom/ns#' term='eclipse-plugin-development'/><title type='text'>Eclipse Plugin Development : Small nuggets</title><content type='html'>Small snuggets for eclipse plugin development are small snippets of code useful in eclipse plugin development.&lt;br /&gt;&lt;br /&gt;In eclipse windows that you see contains pages . Each of this page hosts a view or an editor .&lt;br /&gt;Generally these editors are not hosted directly but indirectly via references ( aka proxies to the actual editor / views )&lt;br /&gt;&lt;br /&gt;So &lt;span style="font-weight: bold;"&gt;to get reference to the actual editors / views from the pages use code like this &lt;/span&gt;:&lt;br /&gt;&lt;br /&gt;IWorkbenchPage page = getPage();&lt;br /&gt;IEditorReference[] editors = page.getEditorReferences();&lt;br /&gt;&lt;br /&gt;Once you have the references you can get the actual hosted editor / view.&lt;br /&gt;&lt;br /&gt;Editors in eclipse implement IEditorPart , so to get an editor some thing like this would work:&lt;br /&gt;&lt;br /&gt;IEditorPart editor = editor.getEditor(true);&lt;br /&gt;&lt;br /&gt;To reveal IJavaElement in the editor  ( basically any java method , entity )  using JDT ( eclipse for java development is based on it )&lt;br /&gt;&lt;br /&gt;JavaUI.revealInEditor(part , javaElement);&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;To add an action (aka tool bar item ) in the toolbar for your view something like this would work&lt;/span&gt; :&lt;br /&gt;&lt;br /&gt;IActionBars actionBars = view.getViewSite().getActionBars();&lt;br /&gt;IToolBarManager manager = actionBars.getToolBarManager();&lt;br /&gt;manager.add(new MyToolBarItem());&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/683958699864453873-7466516367024672067?l=techjude.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://techjude.blogspot.com/feeds/7466516367024672067/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=683958699864453873&amp;postID=7466516367024672067' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/683958699864453873/posts/default/7466516367024672067'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/683958699864453873/posts/default/7466516367024672067'/><link rel='alternate' type='text/html' href='http://techjude.blogspot.com/2008/03/eclipse-plugin-development-small.html' title='Eclipse Plugin Development : Small nuggets'/><author><name>KaranJude</name><uri>http://www.blogger.com/profile/08859421733871339100</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-683958699864453873.post-4816249849432158717</id><published>2008-03-13T06:34:00.000-07:00</published><updated>2008-03-13T06:37:43.492-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='programming'/><category scheme='http://www.blogger.com/atom/ns#' term='eclipse-plugin-development'/><title type='text'>Eclipse Plugin Development : Programatically saving all open editors</title><content type='html'>In Eclipse editors are contained in &lt;span style="font-weight: bold;"&gt;WorkbenchWindow &lt;/span&gt;. To save all open editors one can call code like this&lt;br /&gt;&lt;br /&gt;IWorkbench workbench = PlatformUI.getWorkbench();&lt;br /&gt;return workbench.saveAllEditors(false);&lt;br /&gt;&lt;br /&gt;This will get the current workbench and save all open editors.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/683958699864453873-4816249849432158717?l=techjude.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://techjude.blogspot.com/feeds/4816249849432158717/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=683958699864453873&amp;postID=4816249849432158717' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/683958699864453873/posts/default/4816249849432158717'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/683958699864453873/posts/default/4816249849432158717'/><link rel='alternate' type='text/html' href='http://techjude.blogspot.com/2008/03/eclipse-plugin-development.html' title='Eclipse Plugin Development : Programatically saving all open editors'/><author><name>KaranJude</name><uri>http://www.blogger.com/profile/08859421733871339100</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-683958699864453873.post-2346043978771186409</id><published>2008-03-09T13:14:00.000-07:00</published><updated>2008-03-09T13:27:29.274-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='java'/><category scheme='http://www.blogger.com/atom/ns#' term='threads'/><category scheme='http://www.blogger.com/atom/ns#' term='programming'/><title type='text'>Java : Inner Classes and Parent Reference Escaping</title><content type='html'>When an inner class is created inside a class in java, it transparently contains a reference to its parent class. If by chance this reference leaks out , it compromises the thread safety of the parent class. To avoid these kind of issues , factory methods should be used to create inner classes .&lt;br /&gt;&lt;br /&gt;Another thing that should be best avoided is : starting of a thread inside the constructor of a class.&lt;br /&gt;Since the thread object also shares the reference to its parent class, this reference might be in an inconsistent state when the thread is started .&lt;br /&gt;&lt;br /&gt;To prevent these type of scenarios factory methods are best.&lt;br /&gt;&lt;br /&gt;e.g&lt;br /&gt;&lt;br /&gt;public class Prent {&lt;br /&gt;&lt;br /&gt;private childThread;&lt;br /&gt;&lt;br /&gt; private Parent(){&lt;br /&gt;   childThread = new Thread();&lt;br /&gt; }&lt;br /&gt;&lt;br /&gt; public static Parent newInstance(){&lt;br /&gt;  Parent parent = new Parent();&lt;br /&gt;  childThread.start();&lt;br /&gt;  return parent&lt;br /&gt; }&lt;br /&gt;&lt;br /&gt;}&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/683958699864453873-2346043978771186409?l=techjude.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://techjude.blogspot.com/feeds/2346043978771186409/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=683958699864453873&amp;postID=2346043978771186409' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/683958699864453873/posts/default/2346043978771186409'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/683958699864453873/posts/default/2346043978771186409'/><link rel='alternate' type='text/html' href='http://techjude.blogspot.com/2008/03/java-inner-classes-and-parent-reference.html' title='Java : Inner Classes and Parent Reference Escaping'/><author><name>KaranJude</name><uri>http://www.blogger.com/profile/08859421733871339100</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-683958699864453873.post-3838047818087410718</id><published>2008-03-03T22:41:00.000-08:00</published><updated>2008-03-04T00:12:32.206-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='eclipse-plugin-development'/><title type='text'>Eclipse : Adding nature to a project</title><content type='html'>In Eclipse plugin development terminology adding a nature to a project is like tagging the project with a specific tag . Generally natures are used to install various builders for the project. I will talk about builders in a later post . Lets look at some code and see how how natures are added to projects:&lt;br /&gt;&lt;br /&gt;IProjectDescription projectDescription = project.getDescription();&lt;br /&gt;&lt;br /&gt; description is a description of the project . It gives a lot of information including the entire list of&lt;br /&gt;nature ids and build commands.&lt;br /&gt;&lt;br /&gt;String[]  ids = projectDescription.getNatureIds();&lt;br /&gt;String[] newIds = new String[ids.length + 1];&lt;br /&gt;System.arraycopy(ids,0,newIds,0,ids.length);&lt;br /&gt;newIds[ids.length] = YOUR_NATURE_ID;&lt;br /&gt;projectDescription.setNatureIds(newIds);&lt;br /&gt;project.setDescription(projectDescription,null);&lt;br /&gt;&lt;br /&gt;the remove nature id code is kind of similar .&lt;br /&gt;&lt;br /&gt;To actually implement your nature , you need to contribute to the extension point&lt;br /&gt;org.eclipse.core.resources.natures&lt;br /&gt;&lt;br /&gt;Basically that boils down to adding something like this in your plugin.xml&lt;br /&gt;&lt;br /&gt;&lt;extension point="org.eclipse.core.resources.natures"&lt;br /&gt;id="yourNatureID"&lt;br /&gt;name="Your Nature Name"&gt;&lt;br /&gt;&lt;runtime&gt;&lt;br /&gt;&lt;run class="your.package.name.YourNatureClass"&gt;&lt;br /&gt;&lt;/runtime&gt;&lt;br /&gt;&lt;requires-nature id="org.eclipse.jdt.core.javanature"&gt;&lt;br /&gt;&lt;builder id="your.package.yourBuilder"&gt;&lt;br /&gt;&lt;/extension&gt;&lt;br /&gt;&lt;br /&gt;"id" here represents the id of the nature .&lt;br /&gt;"name" represents the name of the nature .&lt;br /&gt;"class" represents the class implements the IProjectNature .&lt;br /&gt;&lt;br /&gt;the requires-nature here represents the nature id that is required for this nature to be successfully installed .&lt;br /&gt;&lt;br /&gt;Next , finally the class that implements the IProjectNature interface.&lt;br /&gt;&lt;br /&gt;public class YourProjectNature implements IProjectNature {&lt;br /&gt; IProject project;&lt;br /&gt; public YourProjectTestNature() {&lt;br /&gt; }&lt;br /&gt; public IProject getProject() {&lt;br /&gt;  return project;&lt;br /&gt; }&lt;br /&gt; public void setProject(IProject project) {&lt;br /&gt; this.project= project;&lt;br /&gt; }&lt;br /&gt;}&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/683958699864453873-3838047818087410718?l=techjude.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://techjude.blogspot.com/feeds/3838047818087410718/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=683958699864453873&amp;postID=3838047818087410718' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/683958699864453873/posts/default/3838047818087410718'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/683958699864453873/posts/default/3838047818087410718'/><link rel='alternate' type='text/html' href='http://techjude.blogspot.com/2008/03/eclipse-adding-nature-to-project.html' title='Eclipse : Adding nature to a project'/><author><name>KaranJude</name><uri>http://www.blogger.com/profile/08859421733871339100</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-683958699864453873.post-5509107239430420357</id><published>2008-03-02T13:42:00.000-08:00</published><updated>2008-03-02T13:46:03.080-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='c++'/><category scheme='http://www.blogger.com/atom/ns#' term='little sugar'/><title type='text'>Little Sugar : C++</title><content type='html'>The only to initialize const pointers in c++ within a class , is via member initialization list.&lt;br /&gt;&lt;br /&gt;class MyClass{&lt;br /&gt;&lt;br /&gt; Data * const data_ptr;&lt;br /&gt;&lt;br /&gt; MyClass(Data * const value) : data_ptr(value)&lt;br /&gt; {}&lt;br /&gt;};&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/683958699864453873-5509107239430420357?l=techjude.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://techjude.blogspot.com/feeds/5509107239430420357/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=683958699864453873&amp;postID=5509107239430420357' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/683958699864453873/posts/default/5509107239430420357'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/683958699864453873/posts/default/5509107239430420357'/><link rel='alternate' type='text/html' href='http://techjude.blogspot.com/2008/03/little-sugar-c.html' title='Little Sugar : C++'/><author><name>KaranJude</name><uri>http://www.blogger.com/profile/08859421733871339100</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-683958699864453873.post-1851389459854374292</id><published>2008-02-05T10:34:00.000-08:00</published><updated>2008-02-23T05:37:49.666-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='java'/><category scheme='http://www.blogger.com/atom/ns#' term='algorithm'/><title type='text'>Remove from Array : Java Quickie</title><content type='html'>lets say you have a problem . You have an array of N numbers . You want to remove the i th number . Then you need a new array not containing the j th number . You are using java . How can you do it ??&lt;br /&gt;&lt;br /&gt;Here 's a quickie:&lt;br /&gt;&lt;br /&gt;int[] result = null;&lt;br /&gt;&lt;br /&gt;result =  new int[n-1];&lt;br /&gt;  if(i &gt; 0 ) System.arraycopy(array,0,result,0,i);&lt;br /&gt;  if(i+1 &lt; n ) System.arraycopy(array,i+1,result,i,n-1-i);&lt;br /&gt;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;This is quick way of removing the element you need and getting a new array devoid of the removed number .&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/683958699864453873-1851389459854374292?l=techjude.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://techjude.blogspot.com/feeds/1851389459854374292/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=683958699864453873&amp;postID=1851389459854374292' title='3 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/683958699864453873/posts/default/1851389459854374292'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/683958699864453873/posts/default/1851389459854374292'/><link rel='alternate' type='text/html' href='http://techjude.blogspot.com/2008/02/remove-from-array-java-quickie.html' title='Remove from Array : Java Quickie'/><author><name>KaranJude</name><uri>http://www.blogger.com/profile/08859421733871339100</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>3</thr:total></entry><entry><id>tag:blogger.com,1999:blog-683958699864453873.post-6230873802604066226</id><published>2008-01-31T09:57:00.000-08:00</published><updated>2008-01-31T09:58:42.234-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='algorithm'/><category scheme='http://www.blogger.com/atom/ns#' term='heaps'/><title type='text'>Thnking in Heaps : Algorithms</title><content type='html'>An interative version of max-Heap :&lt;br /&gt;&lt;br /&gt;void iter_maxHeapify(int * a,int rootIndex,int heapLength){&lt;br /&gt;    int largest = rootIndex;&lt;br /&gt;    int leftIndex = left(rootIndex);&lt;br /&gt;    int rightIndex = left(rootIndex);&lt;br /&gt;   &lt;br /&gt;    for(int largest = rootIndex;&lt;br /&gt;        (leftIndex &lt; heapLength) || (rightIndex &lt; heapLength);&lt;br /&gt;        leftIndex = left(rootIndex),rightIndex = right(rootIndex)){&lt;br /&gt;&lt;br /&gt;        if(leftIndex &lt; heapLength &amp;amp;&amp;amp; a[rootIndex] &lt; a[leftIndex]){&lt;br /&gt;            largest = leftIndex;&lt;br /&gt;        }&lt;br /&gt;        if(rightIndex &lt; heapLength &amp;amp;&amp;amp; a[largest] &lt; a[rightIndex]){&lt;br /&gt;            largest = rightIndex;&lt;br /&gt;        }&lt;br /&gt;        if(rootIndex != largest){&lt;br /&gt;            swap(a[largest],a[rootIndex]);&lt;br /&gt;            rootIndex = largest;&lt;br /&gt;        }&lt;br /&gt;    }&lt;br /&gt;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;Building the Heap:&lt;br /&gt;&lt;br /&gt;void buildMaxHeap(int * a,int heapLength){&lt;br /&gt;    for(int i = heapLength/2;i &gt;=0;i--){&lt;br /&gt;        maxHeapify(a,i,heapLength);&lt;br /&gt;    }&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Sorting a heap:&lt;br /&gt;&lt;br /&gt;void heapSort(int * a ,int heapLength){&lt;br /&gt;    buildMaxHeap(a,heapLength);&lt;br /&gt;    for(int i = 0;i &lt; heapLength;i++){&lt;br /&gt;        swap(a[i],a[heapLength-1]);&lt;br /&gt;        maxHeapify(a,1,heapLength-i-1);&lt;br /&gt;    }&lt;br /&gt;}&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/683958699864453873-6230873802604066226?l=techjude.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://techjude.blogspot.com/feeds/6230873802604066226/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=683958699864453873&amp;postID=6230873802604066226' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/683958699864453873/posts/default/6230873802604066226'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/683958699864453873/posts/default/6230873802604066226'/><link rel='alternate' type='text/html' href='http://techjude.blogspot.com/2008/01/thnking-in-heaps-algorithms.html' title='Thnking in Heaps : Algorithms'/><author><name>KaranJude</name><uri>http://www.blogger.com/profile/08859421733871339100</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-683958699864453873.post-6564340949747382294</id><published>2008-01-31T04:43:00.000-08:00</published><updated>2008-01-31T04:57:21.837-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='JDT'/><category scheme='http://www.blogger.com/atom/ns#' term='eclipse-plugin-development'/><title type='text'>Tweaking JDT : eclipse</title><content type='html'>To create a new Java Class/Interface using JDT you can use the following code :&lt;br /&gt;&lt;br /&gt;IJavaproject prj;&lt;br /&gt;IPackage package;&lt;br /&gt;&lt;br /&gt;prj.createType(package, "your class body");&lt;br /&gt;&lt;br /&gt;To find subclasses of a given type using JDT use :&lt;br /&gt;&lt;br /&gt;IType type = prj.findType("class name");&lt;br /&gt;ITypeHierarchy typeHierarchy = type.newTypeHierarchy(prj,new NullProgressMonitor());&lt;br /&gt;IType[] subclasses = typeHierarchy.getAllSubtypes(prj);&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;To check if the given class aka IType is part of this project&lt;br /&gt;&lt;br /&gt;IType type;&lt;br /&gt;&lt;br /&gt;IResource resource = type.getUnderlyingResource();&lt;br /&gt;&lt;br /&gt;boolean isPartOfClass = resource.getProject().equals(project.getProject());&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/683958699864453873-6564340949747382294?l=techjude.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://techjude.blogspot.com/feeds/6564340949747382294/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=683958699864453873&amp;postID=6564340949747382294' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/683958699864453873/posts/default/6564340949747382294'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/683958699864453873/posts/default/6564340949747382294'/><link rel='alternate' type='text/html' href='http://techjude.blogspot.com/2008/01/tweaking-jdt-eclipse.html' title='Tweaking JDT : eclipse'/><author><name>KaranJude</name><uri>http://www.blogger.com/profile/08859421733871339100</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-683958699864453873.post-2692558448266892880</id><published>2008-01-31T03:57:00.000-08:00</published><updated>2008-01-31T04:05:34.596-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='marker-resolution'/><category scheme='http://www.blogger.com/atom/ns#' term='eclipse-plugin-development'/><title type='text'>Marker Resolutions for markers : Eclipse</title><content type='html'>In Eclipse it is possible to associate marker resolutions with markers . This is more commonly known as Quick Fixes also evoked by using the key combination Ctrl + 1.&lt;br /&gt;&lt;br /&gt;You need to implement the extension point with id :&lt;br /&gt;&lt;br /&gt;"org.eclipse.ui.markerResolution"&lt;br /&gt;&lt;br /&gt;for the markerType attribute under that extension point specify the marker id&lt;br /&gt;you want to associate this resolution with .&lt;br /&gt;&lt;br /&gt;Then in the "class" attribute specify the class that implements the MarkerResolutionGenerator&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/683958699864453873-2692558448266892880?l=techjude.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://techjude.blogspot.com/feeds/2692558448266892880/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=683958699864453873&amp;postID=2692558448266892880' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/683958699864453873/posts/default/2692558448266892880'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/683958699864453873/posts/default/2692558448266892880'/><link rel='alternate' type='text/html' href='http://techjude.blogspot.com/2008/01/marker-resolutions-for-markers-eclipse.html' title='Marker Resolutions for markers : Eclipse'/><author><name>KaranJude</name><uri>http://www.blogger.com/profile/08859421733871339100</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-683958699864453873.post-2160416710973724270</id><published>2008-01-31T02:04:00.000-08:00</published><updated>2008-01-31T02:10:50.649-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='unicode'/><category scheme='http://www.blogger.com/atom/ns#' term='windows programming'/><title type='text'>The world of wide characters aka Unicode</title><content type='html'>Wide characters aka unicode characters are characters that occupy 16 bits per character .&lt;br /&gt;In C we have a header file specifically for that .&lt;br /&gt;&lt;br /&gt;&lt;whar.h&gt;&lt;br /&gt;&lt;br /&gt;that contains special data type for that&lt;br /&gt;&lt;br /&gt;wchar_t&lt;br /&gt;&lt;br /&gt;wchar_t * text = L"Hello";&lt;br /&gt;&lt;br /&gt;is used to tell the compiler that it should use 16 bit aka wide variants of characters.&lt;br /&gt;&lt;br /&gt;strlen for wide characters becomes wcslen .&lt;br /&gt;&lt;br /&gt;To  take care of these problems windows provides TCHAR.H&lt;br /&gt;&lt;br /&gt;it contains many functions starting with _t , like. ..&lt;br /&gt;&lt;br /&gt;_tprintf&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;by defining _UNICODE&lt;br /&gt;&lt;br /&gt;like&lt;br /&gt;&lt;br /&gt;#define _UNICODE&lt;br /&gt;&lt;br /&gt;its possible to use 16 bit / 8 bit versions of functions without much verbosity .&lt;br /&gt;&lt;br /&gt;the same _t functions then correctly map on to their 8 bit and 16 bit counter parts.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/683958699864453873-2160416710973724270?l=techjude.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://techjude.blogspot.com/feeds/2160416710973724270/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=683958699864453873&amp;postID=2160416710973724270' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/683958699864453873/posts/default/2160416710973724270'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/683958699864453873/posts/default/2160416710973724270'/><link rel='alternate' type='text/html' href='http://techjude.blogspot.com/2008/01/world-of-wide-characters-aka-unicode.html' title='The world of wide characters aka Unicode'/><author><name>KaranJude</name><uri>http://www.blogger.com/profile/08859421733871339100</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-683958699864453873.post-2789207705247634778</id><published>2008-01-28T09:36:00.000-08:00</published><updated>2008-01-28T09:57:57.278-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='markers'/><category scheme='http://www.blogger.com/atom/ns#' term='eclipse-plugin-development'/><title type='text'>Fnding markers in a workspace : eclipse</title><content type='html'>If you have a marker or you know a marker id :&lt;br /&gt;&lt;br /&gt;let the id be : org.my.marker&lt;br /&gt;&lt;br /&gt;then all markers of that type can be easily found . The way to found those markers is :&lt;br /&gt;&lt;br /&gt;IWorkspaceRoot root = ResourcePlugin.getWorkspace().getRoot();&lt;br /&gt;root.findMarkers("org.my.marker",false,IResource.DEPTH_INFINITE);&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;To create a marker :&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;getProject().createMarker("org.my.marker",false,IResource.DEPTH_INFINITE);&lt;br /&gt;&lt;br /&gt;generally since workspace changes are expensive , an IWorkspaceRunnable should be used&lt;br /&gt;to batch many workspace operations together .&lt;br /&gt;&lt;br /&gt;IWorkspaceRunnable runnable = new IWorkspaceRunnable(){&lt;br /&gt; public void run(IProgressMonitor monitor) {&lt;br /&gt; IMarker marker = resource.createMarker(markerId);&lt;br /&gt; setAttributes(marker); &lt;br /&gt;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;};&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;the setAttributes method sets the marker . This generally boild down to populating a hashtable&lt;br /&gt;and setting it .&lt;br /&gt;&lt;br /&gt;resource.getWorkspace().run(runnable , null);&lt;br /&gt;&lt;br /&gt;An imageProvider can be specified in the marker definition to define an image for the marker .&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/683958699864453873-2789207705247634778?l=techjude.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://techjude.blogspot.com/feeds/2789207705247634778/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=683958699864453873&amp;postID=2789207705247634778' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/683958699864453873/posts/default/2789207705247634778'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/683958699864453873/posts/default/2789207705247634778'/><link rel='alternate' type='text/html' href='http://techjude.blogspot.com/2008/01/fnding-markers-in-workspace-eclipse.html' title='Fnding markers in a workspace : eclipse'/><author><name>KaranJude</name><uri>http://www.blogger.com/profile/08859421733871339100</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-683958699864453873.post-7482112119832804682</id><published>2008-01-27T05:50:00.000-08:00</published><updated>2008-01-27T05:55:17.747-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='c++'/><title type='text'>Overloading the &amp;&amp; , || , " , " operators : C++</title><content type='html'>&amp;amp;&amp;amp; , || and comma operator in C++ are very useful . &amp;amp;&amp;amp; and || are useful in short circuiting code .&lt;br /&gt;Now when you overload these operator at the global level or at the member level . Then at that case&lt;br /&gt;&lt;br /&gt;an expression like&lt;br /&gt;&lt;br /&gt;(exp1 &amp;amp;&amp;amp; exp2)&lt;br /&gt;&lt;br /&gt;gets transformed into something like&lt;br /&gt;&lt;br /&gt;(exp1.operator&amp;amp;&amp;amp;(exp2))&lt;br /&gt;&lt;br /&gt;that being the case , both the arguments exp1 and exp2 are evaluated . Hence since we are not&lt;br /&gt;sure in which order the arguments are evaluated , short circuiting is thrown out of the window.&lt;br /&gt;&lt;br /&gt;So commonsense says it makes sense not to overload the &amp;amp;&amp;amp; , || and the comma operator .&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/683958699864453873-7482112119832804682?l=techjude.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://techjude.blogspot.com/feeds/7482112119832804682/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=683958699864453873&amp;postID=7482112119832804682' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/683958699864453873/posts/default/7482112119832804682'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/683958699864453873/posts/default/7482112119832804682'/><link rel='alternate' type='text/html' href='http://techjude.blogspot.com/2008/01/overloading-operators-c.html' title='Overloading the &amp;&amp; , || , &quot; , &quot; operators : C++'/><author><name>KaranJude</name><uri>http://www.blogger.com/profile/08859421733871339100</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-683958699864453873.post-7337753806783552400</id><published>2008-01-25T09:07:00.001-08:00</published><updated>2008-01-25T09:46:23.162-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='trees'/><category scheme='http://www.blogger.com/atom/ns#' term='algorithm'/><category scheme='http://www.blogger.com/atom/ns#' term='little sugar'/><title type='text'>Little Sugar (Trees : relations)</title><content type='html'>A complete binary tree has odd number of nodes .&lt;br /&gt;&lt;br /&gt;Number of leaves + number of internal nodes ( both even) +&lt;br /&gt;1 = number of nodes in a tree&lt;br /&gt;&lt;br /&gt;The number of internal nodes + 1 = number of leaves&lt;br /&gt;&lt;br /&gt;number of internal nodes  =  number of leaves - 1&lt;br /&gt;&lt;br /&gt;n = number of nodes&lt;br /&gt;&lt;br /&gt;n = number of leaves + number of internal nodes&lt;br /&gt;&lt;br /&gt;n +1 = 2 * number of leaves&lt;br /&gt;&lt;br /&gt;number of leaves = (n+1)/2&lt;br /&gt;&lt;br /&gt;The number of total nodes upto height h :&lt;br /&gt;&lt;br /&gt;= pow(2,h+1) - 1&lt;br /&gt;&lt;br /&gt;The number of nodes for any binary tree at height  (h) :&lt;br /&gt;&lt;br /&gt;= ceil(n / pow(2,h+1))&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/683958699864453873-7337753806783552400?l=techjude.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://techjude.blogspot.com/feeds/7337753806783552400/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=683958699864453873&amp;postID=7337753806783552400' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/683958699864453873/posts/default/7337753806783552400'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/683958699864453873/posts/default/7337753806783552400'/><link rel='alternate' type='text/html' href='http://techjude.blogspot.com/2008/01/little-sugar-trees-relations_25.html' title='Little Sugar (Trees : relations)'/><author><name>KaranJude</name><uri>http://www.blogger.com/profile/08859421733871339100</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-683958699864453873.post-1643112766086346242</id><published>2008-01-25T09:07:00.000-08:00</published><updated>2008-01-25T09:17:38.209-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='trees'/><category scheme='http://www.blogger.com/atom/ns#' term='algorithm'/><category scheme='http://www.blogger.com/atom/ns#' term='little sugar'/><title type='text'>Little Sugar (Trees : relations)</title><content type='html'>A complete binary tree has odd number of nodes .&lt;br /&gt;&lt;br /&gt;Number of leaves + number of internal nodes ( both even) +&lt;br /&gt;1 = number of nodes in a tree&lt;br /&gt;&lt;br /&gt;The number of internal nodes + 1 = number of leaves&lt;br /&gt;&lt;br /&gt;number of internal nodes  =  number of leaves - 1&lt;br /&gt;&lt;br /&gt;n = number of nodes&lt;br /&gt;&lt;br /&gt;n = number of leaves + number of internal nodes&lt;br /&gt;&lt;br /&gt;n +1 = 2 * number of leaves&lt;br /&gt;&lt;br /&gt;number of leaves = (n+1)/2&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/683958699864453873-1643112766086346242?l=techjude.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://techjude.blogspot.com/feeds/1643112766086346242/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=683958699864453873&amp;postID=1643112766086346242' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/683958699864453873/posts/default/1643112766086346242'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/683958699864453873/posts/default/1643112766086346242'/><link rel='alternate' type='text/html' href='http://techjude.blogspot.com/2008/01/little-sugar-trees-relations.html' title='Little Sugar (Trees : relations)'/><author><name>KaranJude</name><uri>http://www.blogger.com/profile/08859421733871339100</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-683958699864453873.post-1722614946066091760</id><published>2008-01-20T03:14:00.000-08:00</published><updated>2008-01-20T03:26:07.242-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='c++'/><category scheme='http://www.blogger.com/atom/ns#' term='programming'/><title type='text'>type conversions : C++</title><content type='html'>Implicit type conversions in C++ can be quite problematic . To take care of type conversion issues , C++ provides us with a simple mechanism .&lt;br /&gt;&lt;br /&gt;use the &lt;span style="font-weight: bold;"&gt;explicit &lt;/span&gt;keyword .&lt;br /&gt;&lt;br /&gt;so for a class like Array&lt;br /&gt;&lt;br /&gt;class Array{&lt;br /&gt;&lt;br /&gt;public:&lt;br /&gt; explicit Array(int size){&lt;br /&gt; ...&lt;br /&gt; }&lt;br /&gt;&lt;br /&gt;};&lt;br /&gt;&lt;br /&gt;so by using the explicit keyword in this manner , you tell the compiler to use the constructor only&lt;br /&gt;when explicit object construction is taking place.&lt;br /&gt;&lt;br /&gt;another way around the explicit keyword is :&lt;br /&gt;&lt;br /&gt;class Array{&lt;br /&gt;public:&lt;br /&gt; class ArraySize{&lt;br /&gt; public:&lt;br /&gt;  ArraySize(int size)&lt;br /&gt;   this-&gt;size =  size;&lt;br /&gt;  }&lt;br /&gt;  &lt;br /&gt;  private:&lt;br /&gt;  int size;&lt;br /&gt; };&lt;br /&gt;&lt;br /&gt; Array(ArraySize size){&lt;br /&gt;  ...&lt;br /&gt; }&lt;br /&gt;};&lt;br /&gt;&lt;br /&gt;So by using the nested public ArraySize class in this manner  , you 'll see that even if the compiler makes implicit type conversions for cases like&lt;br /&gt;&lt;br /&gt;Array a(10);&lt;br /&gt;&lt;br /&gt;the integer 10 is correctly transformed to ArraySize and the constructor having ArraySize as a parameter is called .&lt;br /&gt;&lt;br /&gt;The beauty of this last technique is that it works in many cases , cause the compiler is allowed to make 1 implicit type conversion but now two.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/683958699864453873-1722614946066091760?l=techjude.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://techjude.blogspot.com/feeds/1722614946066091760/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=683958699864453873&amp;postID=1722614946066091760' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/683958699864453873/posts/default/1722614946066091760'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/683958699864453873/posts/default/1722614946066091760'/><link rel='alternate' type='text/html' href='http://techjude.blogspot.com/2008/01/type-conversions-c.html' title='type conversions : C++'/><author><name>KaranJude</name><uri>http://www.blogger.com/profile/08859421733871339100</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-683958699864453873.post-8499829080506474106</id><published>2008-01-15T11:03:00.000-08:00</published><updated>2008-01-15T11:23:52.923-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='c++'/><category scheme='http://www.blogger.com/atom/ns#' term='programming'/><title type='text'>Default Constructors : C++</title><content type='html'>Just imagine if your class does not have a default constructor and infact has one that accepts a parameter . In that case few things might not be possible . To illustrate&lt;br /&gt;&lt;br /&gt;class Piece{&lt;br /&gt;public:&lt;br /&gt;Piece(int n);&lt;br /&gt;&lt;br /&gt;};&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Things like these will not work&lt;br /&gt;&lt;br /&gt;Piece pieces[10];&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;Why??  &lt;/span&gt;-&gt; cause u don t have a  default constructor and trying to create an array of 10 piece instances just tries to call exactly that for every one of them .&lt;br /&gt;&lt;br /&gt;Piece * pieces = new Piece[10];&lt;br /&gt;&lt;br /&gt;wont work.&lt;br /&gt;&lt;br /&gt;How to get it working :&lt;br /&gt;&lt;br /&gt;Piece pieces[] = {&lt;br /&gt;Piece(1),&lt;br /&gt;Piece(2),&lt;br /&gt;Piece(3)&lt;br /&gt;};&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Another way to get it working would be :&lt;br /&gt;&lt;br /&gt;Piece * pieces[10];&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;: &lt;/span&gt;here you are just declaring an array of 10 Piece pointers;&lt;br /&gt;&lt;br /&gt;Or Piece* *pieces = new Piece*[10];&lt;br /&gt;&lt;br /&gt;But you still need to initialize all the pointers like this :&lt;br /&gt;&lt;br /&gt;for(int i = 0;i &lt; 10;i++){  pieces[i] = new Piece(i); }  &lt;br /&gt;&lt;br /&gt;Another way of initializing accomplishing this would be : &lt;br /&gt;&lt;br /&gt;void * memory = operator new[](10 * sizeof(Piece)); &lt;br /&gt;&lt;br /&gt;this will create memory for 10 piece objects . Now we can go an and make the memory more  specific to Piece : &lt;br /&gt;&lt;br /&gt;Piece * pieces = static_cast&amp;lt;piece*&amp;gt;(memory);&lt;br /&gt;&lt;br /&gt;Now that pieces points to memory for Piece , lets initialize the pieces with code like&lt;br /&gt;&lt;br /&gt;for(int i = 0;i &lt; 10;i++){  new(&amp;amp;pieces[i]) Pieces(i); } &lt;br /&gt;&lt;br /&gt;Though this arcane technique will get the job done . It seriously is arcane . Not only that it also has the disadvantage of boilerplate code like this :&lt;br /&gt;&lt;br /&gt; for(int i = 9;i &gt;= 0;i--){&lt;br /&gt;pieces[i].~Piece();&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;operator delete[] memory;&lt;br /&gt;&lt;br /&gt;If we do not follow the 1st approach , we see that what problems we can face . A small hack to get around this problem would be :&lt;br /&gt;&lt;br /&gt;class Piece{&lt;br /&gt;public:&lt;br /&gt;Piece(int n = Piece::UNDEFINED);&lt;br /&gt;private:&lt;br /&gt;static const int UNDEFINED;&lt;br /&gt;};&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;const int Piece::UNDEFINED = -1;&lt;/piece*&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/683958699864453873-8499829080506474106?l=techjude.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://techjude.blogspot.com/feeds/8499829080506474106/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=683958699864453873&amp;postID=8499829080506474106' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/683958699864453873/posts/default/8499829080506474106'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/683958699864453873/posts/default/8499829080506474106'/><link rel='alternate' type='text/html' href='http://techjude.blogspot.com/2008/01/default-constructors-c.html' title='Default Constructors : C++'/><author><name>KaranJude</name><uri>http://www.blogger.com/profile/08859421733871339100</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-683958699864453873.post-6039926289870319653</id><published>2008-01-15T09:38:00.000-08:00</published><updated>2008-01-15T09:43:07.583-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='windows programming'/><title type='text'>Hello Windows Facts</title><content type='html'>windows.h is the mother of all other header files in windows . It includes other header files .&lt;br /&gt;&lt;br /&gt;Windef.h =&gt; basic type defintions&lt;br /&gt;&lt;br /&gt;winnt.h =&gt; type definitions for unicode support.&lt;br /&gt;&lt;br /&gt;winbase.h =&gt; kernel functions.&lt;br /&gt;&lt;br /&gt;winusr.h =&gt; user interface functions&lt;br /&gt;&lt;br /&gt;wingdi.h =&gt; graphics device interface functions.&lt;br /&gt;&lt;br /&gt;WINAPI =&gt; is a naming convention like __stdcall .&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/683958699864453873-6039926289870319653?l=techjude.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://techjude.blogspot.com/feeds/6039926289870319653/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=683958699864453873&amp;postID=6039926289870319653' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/683958699864453873/posts/default/6039926289870319653'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/683958699864453873/posts/default/6039926289870319653'/><link rel='alternate' type='text/html' href='http://techjude.blogspot.com/2008/01/hello-windows-facts.html' title='Hello Windows Facts'/><author><name>KaranJude</name><uri>http://www.blogger.com/profile/08859421733871339100</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-683958699864453873.post-8173513952224860354</id><published>2008-01-15T04:35:00.000-08:00</published><updated>2008-01-15T04:53:49.743-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='patterns'/><title type='text'>Moving Patterns</title><content type='html'>If you have a layer of objects and each object in that layer shares a certain set of methods . Those methods can be moved in a common super type . This super type that is common for a whole layer is called a &lt;span style="font-weight: bold;"&gt;layer super type&lt;/span&gt; .&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;Remote Facade&lt;/span&gt; is a facade for objects that are not part of a given process address space , in other words whenever you need to access objects that line in other processes you should use a remote facade to encapsulate and operate on remote objects via the facade . The facade make a number of operation invisible and may also cache the most commonly use objects.&lt;br /&gt;&lt;br /&gt;When ever data has to marshaled across processes boundaries and lot of data needs to sent . A &lt;span style="font-weight: bold;"&gt;Data Transfer Object&lt;/span&gt; can be used . The parameters are packed into a simple POJO  called a DTO and marshaled . On the server side , the server used some sort of assembler to break the DTO and set the corresponding properties on domain objects.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/683958699864453873-8173513952224860354?l=techjude.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://techjude.blogspot.com/feeds/8173513952224860354/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=683958699864453873&amp;postID=8173513952224860354' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/683958699864453873/posts/default/8173513952224860354'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/683958699864453873/posts/default/8173513952224860354'/><link rel='alternate' type='text/html' href='http://techjude.blogspot.com/2008/01/moving-patterns.html' title='Moving Patterns'/><author><name>KaranJude</name><uri>http://www.blogger.com/profile/08859421733871339100</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-683958699864453873.post-6991378340680340813</id><published>2008-01-11T10:08:00.000-08:00</published><updated>2008-01-13T10:08:01.369-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='priority-queue'/><category scheme='http://www.blogger.com/atom/ns#' term='algorithm'/><title type='text'>Floating in a Tree</title><content type='html'>If you have a priority queue setup of many nodes. Lets say we want to bring the node with the highest value to the top . IN orther words if i have given a heap than how do i modify the heap so that the biggest element is always present at the root.&lt;br /&gt;&lt;br /&gt;One simple logic can be . Given a root node of a subtree .&lt;br /&gt;&lt;br /&gt;&lt;ul&gt;&lt;li&gt;Assume the root node is the largest node .&lt;br /&gt;&lt;/li&gt;&lt;li&gt;Now compare the value of root node with left child and mark the one with the bigger value as biggest&lt;/li&gt;&lt;li&gt;Then compare biggest with the right child now and make the bigger of the two as the new biggest.&lt;/li&gt;&lt;li&gt;now repeat the above mentioned steps with the new largest node&lt;/li&gt;&lt;/ul&gt;In terms of code this looks like :&lt;br /&gt;&lt;br /&gt;void maxHeapify(int * a,int rootIndex, int heapLength){&lt;br /&gt;int largest = rootIndex;&lt;br /&gt;int leftIndex = left(rootIndex);&lt;br /&gt;int rightIndex = right(rootIndex);&lt;br /&gt;&lt;br /&gt;if(leftIndex &lt; heapLength &amp;amp;&amp;amp; a[rootIndex] &lt; a[leftIndex]){&lt;br /&gt; largest =  leftIndex;&lt;br /&gt;}&lt;br /&gt;if(rightIndex &lt; heapLength &amp;amp;&amp;amp; a[largest] &lt; a[rightIndex]){&lt;br /&gt; largest = rightIndex;&lt;br /&gt;}&lt;br /&gt;if(largest  != rootIndex){&lt;br /&gt; swap(a[largest],a[rootIndex]);&lt;br /&gt; maxHeapify(a,largest,heapLength);&lt;br /&gt;}&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;The worst case time for floating a node to any another node depending on your optimization  would be approximately equal to the height of the tree , which would generally result in something like ~ lg(N) . To give a counter example for a max Heap operating in a heap . lets give a value of 0 to the root , and let all the other nodes be 1 . In that case the program would go all the way down the heap till the last leaf .&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/683958699864453873-6991378340680340813?l=techjude.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://techjude.blogspot.com/feeds/6991378340680340813/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=683958699864453873&amp;postID=6991378340680340813' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/683958699864453873/posts/default/6991378340680340813'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/683958699864453873/posts/default/6991378340680340813'/><link rel='alternate' type='text/html' href='http://techjude.blogspot.com/2008/01/floating-in-tree.html' title='Floating in a Tree'/><author><name>KaranJude</name><uri>http://www.blogger.com/profile/08859421733871339100</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-683958699864453873.post-3357323313635344459</id><published>2008-01-10T09:52:00.000-08:00</published><updated>2008-01-10T11:03:21.724-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='c++'/><category scheme='http://www.blogger.com/atom/ns#' term='programming'/><title type='text'>casts in C++</title><content type='html'>C++ provides us with 4 types of casting mechanisms . Namely:&lt;br /&gt;&lt;ol&gt;&lt;li&gt;static_cast&lt;/li&gt;&lt;li&gt;const_cast&lt;/li&gt;&lt;li&gt;dynamic_cast&lt;/li&gt;&lt;li&gt;reinterpret_cast&lt;/li&gt;&lt;/ol&gt;&lt;span style="font-weight: bold;"&gt;static_cast&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;In C casting is done via () operator&lt;br /&gt;&lt;br /&gt;int i = 7;&lt;br /&gt;e.g double d = (double) i;&lt;br /&gt;&lt;br /&gt;in c++ to do something like this one should use &lt;span style="font-style: italic;"&gt;static_cast &lt;/span&gt;.&lt;br /&gt;e.g double d = static_cast&amp;lt;double&amp;gt;(i);&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;const_cast&lt;span style="font-weight: bold;"&gt; &lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;const_cast is used to remove constness of an object .&lt;br /&gt;&lt;br /&gt;jump(Person * person);&lt;br /&gt;&lt;br /&gt;Person p;&lt;br /&gt;const Person&amp;amp; constPerson = p;&lt;br /&gt;&lt;br /&gt;then some thing like this wont work.&lt;br /&gt;jump(&amp;amp;constPerson) , cause jump expects a non const object . To fix this you would have to use something like this.&lt;br /&gt;&lt;br /&gt;jump(const_cast&amp;lt;person*&amp;gt;(&amp;amp;constPerson));&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;dynamic_cast &lt;/span&gt;&lt;br /&gt;&lt;br /&gt;This cast is used with inheritance hierarchies . Say to cast a between pointers or references of base classes to references or pointers of derived classes.&lt;br /&gt;&lt;br /&gt;e.g&lt;br /&gt;&lt;br /&gt;Mammal * mammal;&lt;br /&gt;&lt;br /&gt;jump(dynamic_cast&amp;lt;person*&amp;gt;(mammal));&lt;br /&gt;&lt;br /&gt;if there was a function like&lt;br /&gt;&lt;br /&gt;jump(Person&amp;amp; person); then&lt;br /&gt;&lt;br /&gt;we would have something like&lt;br /&gt;&lt;br /&gt;jump(dynamic_cast&amp;lt;person&amp;amp;&amp;gt;(*mammal));&lt;br /&gt;&lt;br /&gt;if the casting is not possible , the dynamic_cast mechaism throws an excetion or the result is null (This is implementation specific)&lt;span style="font-weight: bold;"&gt;&lt;span style="font-weight: bold;"&gt;&lt;/span&gt;&lt;br /&gt;&lt;/span&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/683958699864453873-3357323313635344459?l=techjude.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://techjude.blogspot.com/feeds/3357323313635344459/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=683958699864453873&amp;postID=3357323313635344459' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/683958699864453873/posts/default/3357323313635344459'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/683958699864453873/posts/default/3357323313635344459'/><link rel='alternate' type='text/html' href='http://techjude.blogspot.com/2008/01/casts-in-c.html' title='casts in C++'/><author><name>KaranJude</name><uri>http://www.blogger.com/profile/08859421733871339100</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-683958699864453873.post-4436164445791354000</id><published>2008-01-09T06:17:00.000-08:00</published><updated>2008-01-09T06:21:25.690-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='c++'/><category scheme='http://www.blogger.com/atom/ns#' term='references'/><category scheme='http://www.blogger.com/atom/ns#' term='little sugar'/><title type='text'>Little Sugar: C++ references</title><content type='html'>C++ references are a variant of const pointers that always point to something .&lt;br /&gt;&lt;br /&gt;Now consider&lt;br /&gt;&lt;br /&gt;string s1("abc");&lt;br /&gt;&lt;br /&gt;string s2("def");&lt;br /&gt;&lt;br /&gt;string &amp;amp; refTos1 = s1;&lt;br /&gt;&lt;br /&gt;Now refTosi points to s1.&lt;br /&gt;&lt;br /&gt;Even after refTos1 = s2. Its still points to s1 . But the value of s1 is now changed from "abc" to "def"&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/683958699864453873-4436164445791354000?l=techjude.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://techjude.blogspot.com/feeds/4436164445791354000/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=683958699864453873&amp;postID=4436164445791354000' title='2 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/683958699864453873/posts/default/4436164445791354000'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/683958699864453873/posts/default/4436164445791354000'/><link rel='alternate' type='text/html' href='http://techjude.blogspot.com/2008/01/little-sugar-c-references.html' title='Little Sugar: C++ references'/><author><name>KaranJude</name><uri>http://www.blogger.com/profile/08859421733871339100</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>2</thr:total></entry><entry><id>tag:blogger.com,1999:blog-683958699864453873.post-988145852560579348</id><published>2008-01-08T13:09:00.000-08:00</published><updated>2008-01-08T13:16:02.170-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='bigoh'/><category scheme='http://www.blogger.com/atom/ns#' term='little sugar'/><title type='text'>Little Sugar : Big Oh</title><content type='html'>Consider a scenario where you had a list of N numbers . Now say you have an algorithm that finds the does some sort of comparison . If comparison strategy used compares every element with all the succeeding elements . Then on an average the number of comparisons possible in different cases would be something like this :&lt;br /&gt;&lt;br /&gt;(n) + (n-1) + (n-2) .... 1&lt;br /&gt;&lt;br /&gt;for the 1 st case we have n comparisons&lt;br /&gt;for the 1 st element we have n-1 comparisons&lt;br /&gt;for the 2 nd element we have n-2 comparison .. and so on.&lt;br /&gt;&lt;br /&gt;the sum is = ((n)*(n+1))/2 = O(n^2)&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/683958699864453873-988145852560579348?l=techjude.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://techjude.blogspot.com/feeds/988145852560579348/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=683958699864453873&amp;postID=988145852560579348' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/683958699864453873/posts/default/988145852560579348'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/683958699864453873/posts/default/988145852560579348'/><link rel='alternate' type='text/html' href='http://techjude.blogspot.com/2008/01/little-sugar-big-oh.html' title='Little Sugar : Big Oh'/><author><name>KaranJude</name><uri>http://www.blogger.com/profile/08859421733871339100</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-683958699864453873.post-3196957132824763433</id><published>2007-12-29T04:25:00.000-08:00</published><updated>2007-12-29T04:45:32.933-08:00</updated><title type='text'>Java + meta programming framework == EMF</title><content type='html'>Meta programming is a popular buzz word these days . There is a framework for java , called EMF (Eclipse Modeling Framework ) that tries to add that support to java . The framework makes meta programming look like total crap .  It overly complicates stuff to such a large extent that you just feel like just removing it from your project code.&lt;br /&gt;&lt;br /&gt;So in short meta-programming in EMF + java = night mare :(&lt;br /&gt;&lt;br /&gt;But on the other hand if you are building your domain layer . EMF is a pretty decent choice . It has in build support for a notification mechanism that allows you to listen to various model changes . So your GUI can become lightly couple to the domain layer and can become very responsive .&lt;br /&gt;&lt;br /&gt;If other people have tried EMF , i would love to hear their experiences.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/683958699864453873-3196957132824763433?l=techjude.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://techjude.blogspot.com/feeds/3196957132824763433/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=683958699864453873&amp;postID=3196957132824763433' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/683958699864453873/posts/default/3196957132824763433'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/683958699864453873/posts/default/3196957132824763433'/><link rel='alternate' type='text/html' href='http://techjude.blogspot.com/2007/12/java-meta-programming-framework-emf.html' title='Java + meta programming framework == EMF'/><author><name>KaranJude</name><uri>http://www.blogger.com/profile/08859421733871339100</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-683958699864453873.post-9048279651065972915</id><published>2007-12-17T09:07:00.000-08:00</published><updated>2007-12-17T09:12:16.544-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='algorithm'/><category scheme='http://www.blogger.com/atom/ns#' term='programming'/><title type='text'>Little Sugar : Sequences</title><content type='html'>Given a sequence , the sum of elements from the i th position to the j th position can be easily found by adding the elements from the i th location to the j th location . A better optimization over this is generally to do a cumulative sum of all the elements upto the j th element . Then the&lt;br /&gt;sum of any sub sequence can be found by taking the starting i th location and the ending j th location and subtracting the result of the element at the i th place from the element at the j th place .&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/683958699864453873-9048279651065972915?l=techjude.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://techjude.blogspot.com/feeds/9048279651065972915/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=683958699864453873&amp;postID=9048279651065972915' title='2 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/683958699864453873/posts/default/9048279651065972915'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/683958699864453873/posts/default/9048279651065972915'/><link rel='alternate' type='text/html' href='http://techjude.blogspot.com/2007/12/little-sugar-sequences.html' title='Little Sugar : Sequences'/><author><name>KaranJude</name><uri>http://www.blogger.com/profile/08859421733871339100</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>2</thr:total></entry><entry><id>tag:blogger.com,1999:blog-683958699864453873.post-2965174150683729192</id><published>2007-12-15T13:06:00.000-08:00</published><updated>2007-12-15T13:42:26.310-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='algorithm'/><category scheme='http://www.blogger.com/atom/ns#' term='programming'/><title type='text'>All About Heap Sort -- Part 1</title><content type='html'>HeapSort is a sorting algorithm . It performs in place sorting . Its complexity it O(n lg n).&lt;br /&gt;It makes use of a data structure called heap. The heap data structure is like an array which looks like a complete binary tree.If you imagine the heap array as a tree then each node in the tree will have left and right children . Each of the nodes in the tree map on to elements in the array . Every parent at index (i) will have a left child at index (2 * i ) and a right child at index (2 *i +1 )  in the array . Nodes in the heap follow the heap property . Heaps can be a max heap or a min heap.&lt;br /&gt;In a max heap every Parent will have a higher value than any of its children . Its the opposite in the case of min heap. For the heap sort algorithm a max heap is used , generally a min heap is used for a priority queue.&lt;br /&gt;&lt;br /&gt;Since a heap of (n) elements is like a complete binary tree its height is (lg n )  and all basic operations run in a time proportional to the height of the tree . Heap is a complete binary tree filled with elements at all levels except the last one . So the max number of elements in a heap of height (h) is (pow(2,h+1) - 1) . The minimum number of elements is equal to the number of elements in a heap of height (h-1) + 1 element. We add the extra one element because in the actual heap  there would be at least one element on the last row containing leaves.&lt;br /&gt;So the minimum number of elements = (pow(2,h) -1 ) + 1&lt;br /&gt;&lt;br /&gt;The height of a heap is actually = floor(lg n ) . Since , a heap with height h will have elements (n) = pow(2,h) &lt;= n &lt;=  pow(2,h+1)-1  &lt;  pow(2,h-1) and hence&lt;br /&gt;h &lt;= lg n &lt; 1 =""&gt; height = floor ( lg n )&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/683958699864453873-2965174150683729192?l=techjude.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://techjude.blogspot.com/feeds/2965174150683729192/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=683958699864453873&amp;postID=2965174150683729192' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/683958699864453873/posts/default/2965174150683729192'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/683958699864453873/posts/default/2965174150683729192'/><link rel='alternate' type='text/html' href='http://techjude.blogspot.com/2007/12/all-about-heap-sort-part-1.html' title='All About Heap Sort -- Part 1'/><author><name>KaranJude</name><uri>http://www.blogger.com/profile/08859421733871339100</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-683958699864453873.post-7695966488783814457</id><published>2007-12-04T11:52:00.000-08:00</published><updated>2007-12-04T11:52:39.771-08:00</updated><title type='text'>Ctrl-Shift-B: Interactive Application Architecture Patterns</title><content type='html'>&lt;a href="http://ctrl-shift-b.blogspot.com/2007/08/interactive-application-architecture.html"&gt;Ctrl-Shift-B: Interactive Application Architecture Patterns&lt;/a&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/683958699864453873-7695966488783814457?l=techjude.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='related' href='http://ctrl-shift-b.blogspot.com/2007/08/interactive-application-architecture.html' title='Ctrl-Shift-B: Interactive Application Architecture Patterns'/><link rel='replies' type='application/atom+xml' href='http://techjude.blogspot.com/feeds/7695966488783814457/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=683958699864453873&amp;postID=7695966488783814457' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/683958699864453873/posts/default/7695966488783814457'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/683958699864453873/posts/default/7695966488783814457'/><link rel='alternate' type='text/html' href='http://techjude.blogspot.com/2007/12/ctrl-shift-b-interactive-application.html' title='Ctrl-Shift-B: Interactive Application Architecture Patterns'/><author><name>KaranJude</name><uri>http://www.blogger.com/profile/08859421733871339100</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-683958699864453873.post-2871344015422620582</id><published>2007-11-26T12:35:00.000-08:00</published><updated>2007-11-26T12:43:44.693-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='java'/><category scheme='http://www.blogger.com/atom/ns#' term='programming'/><title type='text'>What would happen if locks in Java were non re-entrant</title><content type='html'>Locks in java are re-entrant , that aids locking to work effectively with Object Oriented Programming . Why ??&lt;br /&gt;&lt;br /&gt;Just consider , if you have a base class&lt;br /&gt;&lt;br /&gt;class Mybase{&lt;br /&gt; public synchronized doStuff(){&lt;br /&gt; }&lt;br /&gt;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;Now If you have a child class extending the base class then,&lt;br /&gt;&lt;br /&gt;public class MyChild extends MyBase{&lt;br /&gt; public synchronized doStuff(){&lt;br /&gt;  super.doStuff();&lt;br /&gt; }&lt;br /&gt;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;This would cause a deadlock . Why ??&lt;br /&gt;&lt;br /&gt;When on the child doStuff is called a lock on the MyBase object is obtained . Now in MyChild::doStuff when super.doStuff() is called the code would again try to get a new lock on&lt;br /&gt;Mybase and if locks were non re-entrant then the thread would block and hence would cause a deadlock.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/683958699864453873-2871344015422620582?l=techjude.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://techjude.blogspot.com/feeds/2871344015422620582/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=683958699864453873&amp;postID=2871344015422620582' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/683958699864453873/posts/default/2871344015422620582'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/683958699864453873/posts/default/2871344015422620582'/><link rel='alternate' type='text/html' href='http://techjude.blogspot.com/2007/11/what-would-happen-if-locks-in-java-were.html' title='What would happen if locks in Java were non re-entrant'/><author><name>KaranJude</name><uri>http://www.blogger.com/profile/08859421733871339100</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-683958699864453873.post-6175009613999097006</id><published>2007-11-22T05:06:00.000-08:00</published><updated>2007-11-22T05:13:16.590-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='eclipse'/><category scheme='http://www.blogger.com/atom/ns#' term='views'/><category scheme='http://www.blogger.com/atom/ns#' term='programming'/><title type='text'>Little Sugar : Showing an Eclipse view</title><content type='html'>You can use an IWorkbenchPage.showView(viewId)  to programatically show a view .&lt;br /&gt;&lt;br /&gt;To access the current active page you can use the following code&lt;br /&gt;&lt;br /&gt;IWorkbench workbench = PlatformUI.getWorkbench();&lt;br /&gt;IWorkbenchWindow workbenchWindow = workbench.getActiveWorkbenchWindow();&lt;br /&gt;IWorkbenchPage activePage = workbenchWindow.getActivePage();&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/683958699864453873-6175009613999097006?l=techjude.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://techjude.blogspot.com/feeds/6175009613999097006/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=683958699864453873&amp;postID=6175009613999097006' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/683958699864453873/posts/default/6175009613999097006'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/683958699864453873/posts/default/6175009613999097006'/><link rel='alternate' type='text/html' href='http://techjude.blogspot.com/2007/11/little-sugar-showing-eclipse-view.html' title='Little Sugar : Showing an Eclipse view'/><author><name>KaranJude</name><uri>http://www.blogger.com/profile/08859421733871339100</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-683958699864453873.post-488725165015280762</id><published>2007-11-22T02:55:00.000-08:00</published><updated>2007-11-22T03:07:30.791-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='eclipse'/><category scheme='http://www.blogger.com/atom/ns#' term='programming'/><title type='text'>Little Sugar : Eclipse Views live in pages</title><content type='html'>In eclipse we have a workbench window in which different types of pages exist .&lt;br /&gt;&lt;br /&gt;thats is WorkbenchWindow &gt;  Pages&lt;br /&gt;                                                 &gt;   ActivePage&lt;br /&gt;&lt;br /&gt;a workbench window also contains the currently active page .&lt;br /&gt;&lt;br /&gt;Each page is a IWorkbenchPage. A WorkbenchPage contains many views .&lt;br /&gt;Each view is a IViewPart.&lt;br /&gt;&lt;br /&gt;So Views live in pages and pages live in workbench window&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/683958699864453873-488725165015280762?l=techjude.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://techjude.blogspot.com/feeds/488725165015280762/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=683958699864453873&amp;postID=488725165015280762' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/683958699864453873/posts/default/488725165015280762'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/683958699864453873/posts/default/488725165015280762'/><link rel='alternate' type='text/html' href='http://techjude.blogspot.com/2007/11/little-sugar-eclipse-views-live-in.html' title='Little Sugar : Eclipse Views live in pages'/><author><name>KaranJude</name><uri>http://www.blogger.com/profile/08859421733871339100</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-683958699864453873.post-2632137721451483188</id><published>2007-11-21T01:14:00.000-08:00</published><updated>2007-11-21T01:18:15.363-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='c++'/><category scheme='http://www.blogger.com/atom/ns#' term='programming'/><title type='text'>Little Sugar : Why constantness helps</title><content type='html'>&lt;pre&gt;Say u have a method like this :&lt;br /&gt;&lt;br /&gt;const Rational operator*(const Rational&amp;amp; lhs,&lt;br /&gt;                        const Rational&amp;amp; rhs);&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Now consider this (a * b ) = c&lt;br /&gt;&lt;br /&gt;If the above method returned a non const object then the above mentioned&lt;br /&gt;assignment would make sense , ideally it should not as it would be violating the&lt;br /&gt;api contract for built ins.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;/pre&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/683958699864453873-2632137721451483188?l=techjude.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://techjude.blogspot.com/feeds/2632137721451483188/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=683958699864453873&amp;postID=2632137721451483188' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/683958699864453873/posts/default/2632137721451483188'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/683958699864453873/posts/default/2632137721451483188'/><link rel='alternate' type='text/html' href='http://techjude.blogspot.com/2007/11/little-sugar-why-constantness-helps.html' title='Little Sugar : Why constantness helps'/><author><name>KaranJude</name><uri>http://www.blogger.com/profile/08859421733871339100</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-683958699864453873.post-962988670191652634</id><published>2007-11-20T21:36:00.000-08:00</published><updated>2007-11-20T22:18:02.955-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='c++'/><category scheme='http://www.blogger.com/atom/ns#' term='programming'/><title type='text'>Little Sugar : Pointers to Member Functions</title><content type='html'>Pointers to member functions is a feature that not many people use but its good to know .&lt;br /&gt;So lets have a look at it . Lets assume you have a class&lt;br /&gt;&lt;br /&gt;class Person ;&lt;br /&gt;&lt;br /&gt;typedef void (Person::*PPMF)();&lt;br /&gt;&lt;br /&gt;class Person{&lt;br /&gt;public :&lt;br /&gt; static PPMF blahFunction(){&lt;br /&gt;  return &amp;amp;(Person::processAddress);&lt;br /&gt; }&lt;br /&gt;&lt;br /&gt;private :&lt;br /&gt;Address address;&lt;br /&gt;void processAddress();&lt;br /&gt;&lt;br /&gt;};&lt;br /&gt;&lt;br /&gt;Here blah function returns a pointer to the member function processAddress .&lt;br /&gt;Now you have the pointer to the member address , even if it private ( its evil to to access private member function like this)  you can invoke this member function now on an instance of a person&lt;br /&gt;class.&lt;br /&gt;&lt;br /&gt;Person boo;&lt;br /&gt;&lt;br /&gt;eg. PPMF  pmf = boo.blahFunction();&lt;br /&gt;&lt;br /&gt;invoke the member function like this :&lt;br /&gt;&lt;br /&gt;(boo.*pmf)();&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/683958699864453873-962988670191652634?l=techjude.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://techjude.blogspot.com/feeds/962988670191652634/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=683958699864453873&amp;postID=962988670191652634' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/683958699864453873/posts/default/962988670191652634'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/683958699864453873/posts/default/962988670191652634'/><link rel='alternate' type='text/html' href='http://techjude.blogspot.com/2007/11/little-sugar-pointers-to-member.html' title='Little Sugar : Pointers to Member Functions'/><author><name>KaranJude</name><uri>http://www.blogger.com/profile/08859421733871339100</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-683958699864453873.post-4043195362818545578</id><published>2007-11-13T13:38:00.000-08:00</published><updated>2007-11-13T13:40:50.775-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='c++'/><category scheme='http://www.blogger.com/atom/ns#' term='programming'/><category scheme='http://www.blogger.com/atom/ns#' term='little sugar'/><title type='text'>Little Sugar : Casting away constant ness</title><content type='html'>In C++ if you create a constant object , say&lt;br /&gt;&lt;br /&gt;const String A("Hello World");&lt;br /&gt;&lt;br /&gt;String&amp;amp; B = const_cast&lt;string&amp;amp;&gt;(A);&lt;br /&gt;&lt;br /&gt;can be used to create a non constant reference to the so called constant object and hence&lt;br /&gt;manipulate it .&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/683958699864453873-4043195362818545578?l=techjude.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://techjude.blogspot.com/feeds/4043195362818545578/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=683958699864453873&amp;postID=4043195362818545578' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/683958699864453873/posts/default/4043195362818545578'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/683958699864453873/posts/default/4043195362818545578'/><link rel='alternate' type='text/html' href='http://techjude.blogspot.com/2007/11/little-sugar-casting-away-constant-ness.html' title='Little Sugar : Casting away constant ness'/><author><name>KaranJude</name><uri>http://www.blogger.com/profile/08859421733871339100</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-683958699864453873.post-3243145679569569276</id><published>2007-11-12T04:12:00.000-08:00</published><updated>2007-11-12T04:28:06.305-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='c++'/><category scheme='http://www.blogger.com/atom/ns#' term='programming'/><category scheme='http://www.blogger.com/atom/ns#' term='little sugar'/><title type='text'>Little Sugar :const function pointers and references</title><content type='html'>The syntax in c++ for constant function pointers is like this&lt;br /&gt;&lt;br /&gt;Handle&amp;amp; (*const getHandle) = handle;&lt;br /&gt;&lt;br /&gt;where handle is a function returning a reference to the handle.&lt;br /&gt;&lt;br /&gt;The syntax for reference function pointers is like this:&lt;br /&gt;&lt;br /&gt;Handle&amp;amp; (&amp;amp;getHandle) = handle;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/683958699864453873-3243145679569569276?l=techjude.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://techjude.blogspot.com/feeds/3243145679569569276/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=683958699864453873&amp;postID=3243145679569569276' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/683958699864453873/posts/default/3243145679569569276'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/683958699864453873/posts/default/3243145679569569276'/><link rel='alternate' type='text/html' href='http://techjude.blogspot.com/2007/11/little-sugar-const-function-pointers.html' title='Little Sugar :const function pointers and references'/><author><name>KaranJude</name><uri>http://www.blogger.com/profile/08859421733871339100</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-683958699864453873.post-6805863753822029242</id><published>2007-11-01T11:55:00.000-07:00</published><updated>2007-11-01T12:04:13.681-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='c++'/><category scheme='http://www.blogger.com/atom/ns#' term='programming'/><category scheme='http://www.blogger.com/atom/ns#' term='little sugar'/><title type='text'>Little Sugar : What does virtual in C++ mean</title><content type='html'>In c++ if a function is declared virtual for any class, then that class has an associated&lt;br /&gt;&lt;span style="font-style: italic;"&gt;virtual table &lt;/span&gt;. With each of those virtual functions a special type of &lt;span style="font-style: italic;"&gt;virtual table pointer is associated&lt;/span&gt; , which has an entry in the virtual table associated with the corresponding class.&lt;br /&gt;&lt;br /&gt;These virtual pointers are used at runtime to figure out which virtual function to invoke at runtime.&lt;br /&gt;&lt;br /&gt;Making virtual functions inline does not make sense ?? why ...&lt;br /&gt;&lt;br /&gt;Inline functions are meant to be made inline , so that means they don't have an explicit address but then if it does not have an address and its virtual then how will it have an entry in the virtual table ??&lt;br /&gt;&lt;br /&gt;It will have an entry , cause our friend compiler will generate a function body for us and embed the address somewhere for it .&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/683958699864453873-6805863753822029242?l=techjude.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://techjude.blogspot.com/feeds/6805863753822029242/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=683958699864453873&amp;postID=6805863753822029242' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/683958699864453873/posts/default/6805863753822029242'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/683958699864453873/posts/default/6805863753822029242'/><link rel='alternate' type='text/html' href='http://techjude.blogspot.com/2007/11/little-sugar-what-does-virtual-in-c.html' title='Little Sugar : What does virtual in C++ mean'/><author><name>KaranJude</name><uri>http://www.blogger.com/profile/08859421733871339100</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-683958699864453873.post-876853338341416138</id><published>2007-10-30T14:37:00.000-07:00</published><updated>2007-10-30T14:40:41.141-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='java'/><category scheme='http://www.blogger.com/atom/ns#' term='programming'/><title type='text'>Private lock Object Idiom</title><content type='html'>The private lock object idiom is generally used in making a class Thread Safe.&lt;br /&gt;Instead of using the instance of the object as a lock object an internal private object is used&lt;br /&gt;as a lock object.&lt;br /&gt;&lt;br /&gt;private Object lock = new Object();&lt;br /&gt;&lt;br /&gt;so the method need to acquire a lock should use the &lt;span style="font-style: italic;"&gt;lock&lt;/span&gt; object instead of &lt;span style="font-style: italic;"&gt;this&lt;/span&gt; object.&lt;br /&gt;e.g.&lt;br /&gt;&lt;br /&gt;public void foo(){&lt;br /&gt; synchronized(lock){&lt;br /&gt; ....&lt;br /&gt;}&lt;br /&gt;}&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/683958699864453873-876853338341416138?l=techjude.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://techjude.blogspot.com/feeds/876853338341416138/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=683958699864453873&amp;postID=876853338341416138' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/683958699864453873/posts/default/876853338341416138'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/683958699864453873/posts/default/876853338341416138'/><link rel='alternate' type='text/html' href='http://techjude.blogspot.com/2007/10/private-lock-object-idiom.html' title='Private lock Object Idiom'/><author><name>KaranJude</name><uri>http://www.blogger.com/profile/08859421733871339100</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-683958699864453873.post-1935697839180920210</id><published>2007-10-21T10:50:00.000-07:00</published><updated>2007-10-21T10:52:36.398-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='java'/><category scheme='http://www.blogger.com/atom/ns#' term='programming'/><title type='text'>Lazy Initailization Idioms</title><content type='html'>Double check idiom is supposedly the best lazy initialization technique&lt;br /&gt;&lt;br /&gt;&lt;span style="font-style: italic;"&gt;private static Foo foo = null;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-style: italic;"&gt;public static void getFoo(){&lt;/span&gt;&lt;br /&gt;&lt;span style="font-style: italic;"&gt; if (null == foo){&lt;/span&gt;&lt;br /&gt;&lt;span style="font-style: italic;"&gt;  synchronized (Foo.class){&lt;/span&gt;&lt;br /&gt;&lt;span style="font-style: italic;"&gt;   if ( null == foo){&lt;/span&gt;&lt;br /&gt;&lt;span style="font-style: italic;"&gt;    foo = new Foo();&lt;/span&gt;&lt;br /&gt;&lt;span style="font-style: italic;"&gt;   }&lt;/span&gt;&lt;br /&gt;&lt;span style="font-style: italic;"&gt;  }&lt;/span&gt;&lt;br /&gt;&lt;span style="font-style: italic;"&gt; }&lt;/span&gt;&lt;br /&gt;&lt;span style="font-style: italic;"&gt; return foo;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-style: italic;"&gt;}&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;This is the double check idiom , it works great with primitives but is flawed when it&lt;br /&gt;comes to object references cause the behaviour of object references after synchronized is&lt;br /&gt;undefined.&lt;br /&gt;&lt;br /&gt;Solution 1:&lt;br /&gt;&lt;br /&gt;&lt;span style="font-style: italic;"&gt;private static Foo foo = new Foo();&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-style: italic;"&gt;public static void getFoo(){&lt;/span&gt;&lt;br /&gt;&lt;span style="font-style: italic;"&gt; return foo;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-style: italic;"&gt;}&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;Solution 2:&lt;br /&gt;&lt;br /&gt;&lt;span style="font-style: italic;"&gt;private static Foo foo = null;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-style: italic;"&gt;public synchronized Foo getFoo(){&lt;/span&gt;&lt;br /&gt;&lt;span style="font-style: italic;"&gt; if (null == Foo)&lt;/span&gt;&lt;br /&gt;&lt;span style="font-style: italic;"&gt;    foo = new Foo();&lt;/span&gt;&lt;br /&gt;&lt;span style="font-style: italic;"&gt; return foo;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-style: italic;"&gt;}&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;Solution 3:&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;Initialize on demand - holder class Idiom&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-style: italic;"&gt;private static class Holder{&lt;/span&gt;&lt;br /&gt;&lt;span style="font-style: italic;"&gt; static Foo foo = new Foo();&lt;/span&gt;&lt;br /&gt;&lt;span style="font-style: italic;"&gt;}&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-style: italic;"&gt;public static Foo getFoo(){&lt;/span&gt;&lt;br /&gt;&lt;span style="font-style: italic;"&gt; return Holder.foo;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-style: italic;"&gt;}&lt;/span&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/683958699864453873-1935697839180920210?l=techjude.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://techjude.blogspot.com/feeds/1935697839180920210/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=683958699864453873&amp;postID=1935697839180920210' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/683958699864453873/posts/default/1935697839180920210'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/683958699864453873/posts/default/1935697839180920210'/><link rel='alternate' type='text/html' href='http://techjude.blogspot.com/2007/10/lazy-initailization-idioms.html' title='Lazy Initailization Idioms'/><author><name>KaranJude</name><uri>http://www.blogger.com/profile/08859421733871339100</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-683958699864453873.post-2103924960053608424</id><published>2007-10-21T10:44:00.000-07:00</published><updated>2007-10-21T10:48:48.304-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='c++'/><category scheme='http://www.blogger.com/atom/ns#' term='programming'/><title type='text'>set_new_handler in </title><content type='html'>&lt;span style="font-style: italic;"&gt;&lt;span style="font-style: italic;"&gt;&lt;/span&gt;The &lt;/span&gt;correct way of overriding the new operator can be something. Here i try to highlight  how one can go about doing so .&lt;br /&gt;&lt;span style="font-style: italic;"&gt;&lt;br /&gt;typedef void (*new_handler)();&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;In the new header file , a typedef new handler is defined . This typedef basically refers to&lt;br /&gt;the function that the new operator will call if it is not able to allocate memory properly.&lt;br /&gt;Generally the new operator specification looks for the new_handler to allocate more or release&lt;br /&gt;memory so that the new operator can call it properly.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-style: italic;"&gt;new_handler set_new_handler(new_handler handler);&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;is a function also found in &lt;new&gt; that installs the new handler . A typical implementation&lt;br /&gt;of this should return the old_handler that was replaced.&lt;br /&gt;&lt;br /&gt;The new operator throws std::bad_alloc exception when it is not able to allocate memory.&lt;br /&gt;&lt;br /&gt;Class specific handlers can be installed for class specific new operator .&lt;br /&gt;The code for managing the operator and the handler can go in one templatised base class.&lt;br /&gt;Derived classes can then inherit from this class . The base class is very specialized class&lt;br /&gt;as it only provides only one type of functionality.Such type of classes are called mixins.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-style: italic;"&gt;template&lt;t&gt;&lt;class&gt;&lt;/class&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-style: italic;"&gt;class NewHandler{&lt;/span&gt;&lt;br /&gt;&lt;span style="font-style: italic;"&gt;public:&lt;/span&gt;&lt;br /&gt;&lt;span style="font-style: italic;"&gt; static new_handler set_new_handler(new_handler handler);&lt;/span&gt;&lt;br /&gt;&lt;span style="font-style: italic;"&gt; static void* operator new(size_t size);&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-style: italic;"&gt;private:&lt;/span&gt;&lt;br /&gt;&lt;span style="font-style: italic;"&gt; static new_handler currentHandler;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-style: italic;"&gt;};&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-style: italic;"&gt;template&lt;class&gt;&lt;/class&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-style: italic;"&gt;new_handler NewHandler&lt;t&gt;::currentHandler;&lt;/t&gt;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-style: italic;"&gt;template&lt;class&gt;&lt;/class&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-style: italic;"&gt;new_handler NewHandler&lt;t&gt;::set_new_handler(new_handler handler){&lt;/t&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-style: italic;"&gt; new_handler oldHandler = currentHandler;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-style: italic;"&gt; currentHandler = handler;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-style: italic;"&gt; return oldHandler;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-style: italic;"&gt;}&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-style: italic;"&gt;template&lt;class&gt;&lt;/class&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-style: italic;"&gt;void* NewHandler&lt;t&gt;::operator new(size_t size){&lt;/t&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-style: italic;"&gt; new_handler globalHandler = std::set_new_handler(NewHandler&lt;t&gt;::currentHandler):&lt;/t&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-style: italic;"&gt; void * memory;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-style: italic;"&gt; try{&lt;/span&gt;&lt;br /&gt;&lt;span style="font-style: italic;"&gt;  // try to allocate memory using global new operator&lt;/span&gt;&lt;br /&gt;&lt;span style="font-style: italic;"&gt;  memory = ::operator new(size);&lt;/span&gt;&lt;br /&gt;&lt;span style="font-style: italic;"&gt; }catch(std::bad_alloc &amp;amp;){&lt;/span&gt;&lt;br /&gt;&lt;span style="font-style: italic;"&gt;  std::set_new_handler(globalHandler);&lt;/span&gt;&lt;br /&gt;&lt;span style="font-style: italic;"&gt;  // propogate all the exceptions&lt;/span&gt;&lt;br /&gt;&lt;span style="font-style: italic;"&gt;  throw;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-style: italic;"&gt; }&lt;/span&gt;&lt;br /&gt;&lt;span style="font-style: italic;"&gt; // reinstall the saved gloabal handler&lt;/span&gt;&lt;br /&gt;&lt;span style="font-style: italic;"&gt; std::set_new_handler(globalHandler);&lt;/span&gt;&lt;br /&gt;&lt;span style="font-style: italic;"&gt; return memory;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-style: italic;"&gt;}&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;Now any class X can use NewHandler like this :&lt;br /&gt;&lt;br /&gt;&lt;span style="font-style: italic;"&gt;class X : public NewHandler&lt;x&gt; {&lt;/x&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-style: italic;"&gt;};&lt;/span&gt;&lt;/new&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/683958699864453873-2103924960053608424?l=techjude.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://techjude.blogspot.com/feeds/2103924960053608424/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=683958699864453873&amp;postID=2103924960053608424' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/683958699864453873/posts/default/2103924960053608424'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/683958699864453873/posts/default/2103924960053608424'/><link rel='alternate' type='text/html' href='http://techjude.blogspot.com/2007/10/setnewhandler-in.html' title='set_new_handler in &lt;new&gt;'/><author><name>KaranJude</name><uri>http://www.blogger.com/profile/08859421733871339100</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-683958699864453873.post-4372616897798576356</id><published>2007-10-18T05:10:00.000-07:00</published><updated>2007-10-18T05:15:31.711-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='java'/><category scheme='http://www.blogger.com/atom/ns#' term='programming'/><title type='text'>Finalizer guardian Idiom</title><content type='html'>Finalizer Guardian idiom is nothing but an anonymous class assigned to a private final instance  variable within a class that wants to override the finalize method .&lt;br /&gt;&lt;br /&gt;The anonymous class takes the responsibility of calling the finalize method of the enclosing class.&lt;br /&gt;All this in code looks like :&lt;br /&gt;&lt;br /&gt;&lt;span style="font-style: italic;"&gt;public class A{&lt;/span&gt;&lt;br /&gt;&lt;span style="font-style: italic;"&gt; private final Object b = new Object(){&lt;/span&gt;&lt;br /&gt;&lt;span style="font-style: italic;"&gt;  protected void finalize() throws Throwable {&lt;/span&gt;&lt;br /&gt;&lt;span style="font-style: italic;"&gt;    // finalize the outer A here &lt;/span&gt;&lt;br /&gt;&lt;span style="font-style: italic;"&gt;  }&lt;/span&gt;&lt;br /&gt;&lt;span style="font-style: italic;"&gt; };&lt;/span&gt;&lt;br /&gt;&lt;span style="font-style: italic;"&gt;}&lt;/span&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/683958699864453873-4372616897798576356?l=techjude.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://techjude.blogspot.com/feeds/4372616897798576356/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=683958699864453873&amp;postID=4372616897798576356' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/683958699864453873/posts/default/4372616897798576356'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/683958699864453873/posts/default/4372616897798576356'/><link rel='alternate' type='text/html' href='http://techjude.blogspot.com/2007/10/finalizer-guardian-idion.html' title='Finalizer guardian Idiom'/><author><name>KaranJude</name><uri>http://www.blogger.com/profile/08859421733871339100</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-683958699864453873.post-5827696985721108616</id><published>2007-10-18T04:51:00.000-07:00</published><updated>2007-10-18T05:03:01.943-07:00</updated><title type='text'>Little Sugar (Handling Exceptions in Finalize )</title><content type='html'>Lets consider a scenario where you have a class A and a subclass of that class called B.&lt;br /&gt;Now say you override the finalize method in class B then you need to explicitly invoke the&lt;br /&gt;finalize method of the parent.&lt;br /&gt;&lt;br /&gt;So your implementation should look like this :&lt;br /&gt;&lt;br /&gt;&lt;span style="font-style: italic;"&gt;protected void finalize() throws Throwable {&lt;/span&gt;&lt;br /&gt;&lt;span style="font-style: italic;"&gt; try{&lt;/span&gt;&lt;br /&gt;&lt;span style="font-style: italic;"&gt; }finally{&lt;/span&gt;&lt;br /&gt;&lt;span style="font-style: italic;"&gt;  super.finalize();    &lt;/span&gt;&lt;br /&gt;&lt;span style="font-style: italic;"&gt; }&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-style: italic;"&gt;}&lt;br /&gt;&lt;span style="font-style: italic;"&gt;&lt;br /&gt;&lt;span style="font-style: italic;"&gt;That way ,&lt;/span&gt;&lt;/span&gt;&lt;/span&gt; any exceptions thrown in the finalize method would not cause the finalize method to terminate and leave the object in a corrupt state.&lt;span style="font-style: italic;"&gt;&lt;span style="font-style: italic;"&gt;&lt;span style="font-style: italic;"&gt;&lt;/span&gt;&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/683958699864453873-5827696985721108616?l=techjude.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://techjude.blogspot.com/feeds/5827696985721108616/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=683958699864453873&amp;postID=5827696985721108616' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/683958699864453873/posts/default/5827696985721108616'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/683958699864453873/posts/default/5827696985721108616'/><link rel='alternate' type='text/html' href='http://techjude.blogspot.com/2007/10/little-sugar-handling-exceptions-in.html' title='Little Sugar (Handling Exceptions in Finalize )'/><author><name>KaranJude</name><uri>http://www.blogger.com/profile/08859421733871339100</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-683958699864453873.post-2529707851353944059</id><published>2007-10-18T04:42:00.000-07:00</published><updated>2007-10-18T04:51:00.103-07:00</updated><title type='text'>Little Sugar (Java Finalization )</title><content type='html'>Uncaught exceptions thrown  in the finalize method of an object are not caught . Infact they cause the finalization process to terminate and leave the object in a corrupt state . Now that's weird ...&lt;br /&gt;&lt;br /&gt;So the best of the rule of thumb would be to avoid finalizers. Instead explicit termination methods should be called that can be invoked in the finally block .&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/683958699864453873-2529707851353944059?l=techjude.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://techjude.blogspot.com/feeds/2529707851353944059/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=683958699864453873&amp;postID=2529707851353944059' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/683958699864453873/posts/default/2529707851353944059'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/683958699864453873/posts/default/2529707851353944059'/><link rel='alternate' type='text/html' href='http://techjude.blogspot.com/2007/10/little-sugar-java-finalization.html' title='Little Sugar (Java Finalization )'/><author><name>KaranJude</name><uri>http://www.blogger.com/profile/08859421733871339100</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-683958699864453873.post-2071154816191755733</id><published>2007-10-08T05:29:00.000-07:00</published><updated>2007-10-08T06:27:40.109-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='eclipse-plugin-development'/><title type='text'>Contributing to the Eclipse Cool Bar</title><content type='html'>To add stuff to the eclipse cool bar , u need to&lt;br /&gt;1)  implement the extension point &lt;span style="font-weight: bold;"&gt;org.eclipse.ui.editor&lt;/span&gt; .&lt;br /&gt;2) Specify a &lt;span style="font-weight: bold;"&gt;contributorClass&lt;/span&gt; for the above mentioned extension point.&lt;br /&gt;&lt;br /&gt;This contributor class will provide actions that would be contributed to the&lt;br /&gt;coolbar.&lt;br /&gt;Lets call this calls &lt;span style="font-weight: bold;"&gt;MyContributorClass&lt;/span&gt;.&lt;br /&gt;&lt;br /&gt;3) Have this class extend &lt;span style="font-weight: bold;"&gt;BaseEditorContributor , &lt;span style="font-weight: bold;"&gt;It &lt;/span&gt;&lt;/span&gt;should override &lt;span style="font-style: italic;"&gt;contributeToParentCoolbar &lt;/span&gt;.&lt;br /&gt;&lt;br /&gt;4) In the given method create a ContributionItem that would be contributed to the coolbar.&lt;br /&gt;&lt;br /&gt;Lets call this &lt;span style="font-style: italic;"&gt;myContributionItem&lt;/span&gt;.&lt;br /&gt;&lt;br /&gt;5)  Use the &lt;span style="font-style: italic;"&gt;parentCoolBarManager &lt;/span&gt;to add create a &lt;span style="font-style: italic;"&gt;ToolBarManager&lt;/span&gt;.&lt;br /&gt;&lt;br /&gt;IToolBarManager toolbar = new ToolBarManager(parentCoolBarManager.getStyle())&lt;br /&gt;&lt;br /&gt;6) Add &lt;span style="font-style: italic;"&gt;myContributionItem &lt;/span&gt;to toolbar.&lt;br /&gt;&lt;br /&gt;toolbar.add(myContributionItem);&lt;br /&gt;&lt;br /&gt;7) Create a &lt;span style="font-style: italic;"&gt;ToolBarContributionItem&lt;/span&gt; and add it to the parent cool bar.&lt;br /&gt;&lt;br /&gt;ToolBarContributionItem toolBarItem = new ToolBarContributionItem(toolbar,myContributionItem.getId())&lt;br /&gt;&lt;br /&gt;parentCoolBarManager.add(toolBarItem);&lt;br /&gt;&lt;br /&gt;and finally&lt;br /&gt;&lt;br /&gt;coolBarItems.add(toolBarItem);&lt;br /&gt;&lt;br /&gt;&lt;span style="font-style: italic;"&gt;parentCoolBarManager&lt;/span&gt; and &lt;span style="font-style: italic;"&gt;coolBarItem &lt;/span&gt;are protected members and are available from the base class .&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/683958699864453873-2071154816191755733?l=techjude.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://techjude.blogspot.com/feeds/2071154816191755733/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=683958699864453873&amp;postID=2071154816191755733' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/683958699864453873/posts/default/2071154816191755733'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/683958699864453873/posts/default/2071154816191755733'/><link rel='alternate' type='text/html' href='http://techjude.blogspot.com/2007/10/contributing-to-eclipse-cool-bar.html' title='Contributing to the Eclipse Cool Bar'/><author><name>KaranJude</name><uri>http://www.blogger.com/profile/08859421733871339100</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-683958699864453873.post-935380628930062267</id><published>2007-09-23T22:58:00.000-07:00</published><updated>2007-09-23T23:06:42.923-07:00</updated><title type='text'>what is e raised to i * Pi</title><content type='html'>The other day i was seeing some presentation . During the presentation i came across a mathematical puzzle . The puzzle asked about what is the value of&lt;br /&gt;&lt;br /&gt;value = e ^ (i * Pi) ??&lt;br /&gt;&lt;br /&gt;now this would have been really really easy if i was in 12 th grade . But Since its a been long time since 12 th grade and few yrs since by B.S degree . It took some thinking ..&lt;br /&gt;&lt;br /&gt;So the solution is :&lt;br /&gt;&lt;br /&gt;well if you remember complex numbers then then you can say&lt;br /&gt;&lt;br /&gt;e ^ (i * x ) = cos (x) + i sin(x)&lt;br /&gt;&lt;br /&gt;so e ^ ( i * Pi ) = cos (Pi) + i sin (Pi)&lt;br /&gt;&lt;br /&gt;since cos (pi)  = -1&lt;br /&gt;sin (pi ) = 0&lt;br /&gt;&lt;br /&gt;e ^ (i * pi) = -1&lt;br /&gt;&lt;br /&gt;Duh .. so much for my memory :( ..&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/683958699864453873-935380628930062267?l=techjude.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://techjude.blogspot.com/feeds/935380628930062267/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=683958699864453873&amp;postID=935380628930062267' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/683958699864453873/posts/default/935380628930062267'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/683958699864453873/posts/default/935380628930062267'/><link rel='alternate' type='text/html' href='http://techjude.blogspot.com/2007/09/what-is-e-raised-to-i-pi.html' title='what is e raised to i * Pi'/><author><name>KaranJude</name><uri>http://www.blogger.com/profile/08859421733871339100</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-683958699864453873.post-1770276511513505613</id><published>2007-08-21T06:21:00.000-07:00</published><updated>2007-08-21T06:37:31.445-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='java'/><category scheme='http://www.blogger.com/atom/ns#' term='eclipse'/><category scheme='http://www.blogger.com/atom/ns#' term='views'/><title type='text'>Showing an Eclipse View Programatically</title><content type='html'>In eclipse non savable containers are called views . It pretty easy to create a view , all you need to do is to implement an extension - point (org.eclipse.ui.views)  and add features to a class . If you want to implement your own view , you can google it you 'll find a number of articles about it .&lt;br /&gt;&lt;br /&gt;In this blog entry i tell you how to show/hide an existing view programatically .&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;&lt;br /&gt;Scenario1 &lt;/span&gt;: Assuming you have created a view whose view ID is "my.view" and you want to show this view .&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;Scenario2:&lt;/span&gt; You know the view id of some view and you want to show that view programatically.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-style: italic;"&gt;IWorkbench workbench = PLatformUI.getWorkbench();&lt;br /&gt;IWorkbenchWindow workbenchWindow = workbench.getActiveWorkbenchWindow();&lt;br /&gt;&lt;/span&gt;&lt;span style="font-style: italic;"&gt;workbenchWindow.getActivePage().showView("my.view");&lt;br /&gt;&lt;br /&gt;// to hide a view&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="font-style: italic;"&gt;workbenchWindow.getActivePage().hideView("my.view");&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;PlatformUI is a plugin that can give information about currently active windows and objects in an eclipse session . Its available to us so we use it to get the current workbench window . In eclipse workbench window is the main window . Each window has one or more pages . We get the active page . In the active page we either show or hide the view we are interested in .&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/683958699864453873-1770276511513505613?l=techjude.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://techjude.blogspot.com/feeds/1770276511513505613/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=683958699864453873&amp;postID=1770276511513505613' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/683958699864453873/posts/default/1770276511513505613'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/683958699864453873/posts/default/1770276511513505613'/><link rel='alternate' type='text/html' href='http://techjude.blogspot.com/2007/08/showing-eclipse-view-programatically.html' title='Showing an Eclipse View Programatically'/><author><name>KaranJude</name><uri>http://www.blogger.com/profile/08859421733871339100</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-683958699864453873.post-7831169392532374211</id><published>2007-08-13T12:56:00.000-07:00</published><updated>2007-08-22T10:21:49.121-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='algorithm'/><category scheme='http://www.blogger.com/atom/ns#' term='little sugar'/><category scheme='http://www.blogger.com/atom/ns#' term='heap'/><title type='text'>Little Sugar (Heaps)</title><content type='html'>&lt;ul&gt;&lt;li&gt;Heap is a  data structure whcih satisfies the MAX-HEAP or MIN-HEAP property&lt;/li&gt;&lt;li&gt;All basic operations on a heap run in a time proportional to the height of the heap (lg n ) where n being the total number of nodes in a heap&lt;/li&gt;&lt;li&gt;A heap is generally a complete tree&lt;/li&gt;&lt;li&gt;IN an array represenation of an N-element heap the leaves nodes are indexed by n/2+1 , n/2 + 2 ... n&lt;/li&gt;&lt;li&gt;In an N element heap , the number of nodes of height H are n/pow(2,h+1)&lt;br /&gt;&lt;/li&gt;&lt;/ul&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/683958699864453873-7831169392532374211?l=techjude.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://techjude.blogspot.com/feeds/7831169392532374211/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=683958699864453873&amp;postID=7831169392532374211' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/683958699864453873/posts/default/7831169392532374211'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/683958699864453873/posts/default/7831169392532374211'/><link rel='alternate' type='text/html' href='http://techjude.blogspot.com/2007/08/little-sugar-heaps.html' title='Little Sugar (Heaps)'/><author><name>KaranJude</name><uri>http://www.blogger.com/profile/08859421733871339100</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-683958699864453873.post-903049715413758793</id><published>2007-07-29T11:08:00.000-07:00</published><updated>2007-07-29T11:28:39.436-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='eclipse'/><category scheme='http://www.blogger.com/atom/ns#' term='programming'/><category scheme='http://www.blogger.com/atom/ns#' term='eclipse-plugin-development'/><title type='text'>Programatically Creating a java package in Eclipse</title><content type='html'>In my last &lt;a href="http://techjude.blogspot.com/2007/07/creating-new-project-in-eclipse.html"&gt;post&lt;/a&gt; we saw how we can create a java project programatically in eclipse. In this post we will see how to create a package in this java project.&lt;br /&gt;&lt;br /&gt;The steps needed to do this are :&lt;br /&gt;&lt;br /&gt;1. Create a source folder under the java project created earlier  .&lt;br /&gt;&lt;br /&gt;      IFolder src = javaProject.getFolder("src");&lt;br /&gt;      folder.create(force , local , nullProgressMonitor);&lt;br /&gt;      IPackageFragmentRoot packageRoot = javaProject.getPackageFragmentRoot(folder);&lt;br /&gt;      IClasspathEntry[] classPath = javaProject.getRawClasspath();&lt;br /&gt;      List&lt;iclasspathentry&gt; entries = new ArrayList&lt;iclasspathentry&gt;(Arrays.asList(classpath));&lt;br /&gt;      entries.add(JavaCore.newSourceEntry(root.getPath()));&lt;br /&gt;    &lt;br /&gt;     javaProject.setRawClasspath(entries.toArray(new IClasspathEntry[0]) , null ProgressMonitor);&lt;br /&gt;&lt;br /&gt;The code becomes pretty clear if you had followed my previous &lt;a href="http://techjude.blogspot.com/2007/07/creating-new-project-in-eclipse.html"&gt;post&lt;/a&gt;.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;2. Create the actual package .&lt;br /&gt;   &lt;br /&gt;    src.createPackageFragment(packageName, force , nullProgressMonitor);&lt;br /&gt;&lt;br /&gt;Yeah thats done , in the next post well see how to create a class programatically&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/683958699864453873-903049715413758793?l=techjude.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://techjude.blogspot.com/feeds/903049715413758793/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=683958699864453873&amp;postID=903049715413758793' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/683958699864453873/posts/default/903049715413758793'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/683958699864453873/posts/default/903049715413758793'/><link rel='alternate' type='text/html' href='http://techjude.blogspot.com/2007/07/programatically-creating-java-package.html' title='Programatically Creating a java package in Eclipse'/><author><name>KaranJude</name><uri>http://www.blogger.com/profile/08859421733871339100</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-683958699864453873.post-8780979599549687764</id><published>2007-07-25T10:54:00.000-07:00</published><updated>2007-07-25T12:17:17.911-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='creating projects'/><category scheme='http://www.blogger.com/atom/ns#' term='eclipse-plugin-development'/><title type='text'>Creating a new project in Eclipse Programatically</title><content type='html'>If you have done Eclipse plugin development you would know that any non trivial task is not obvious , unless you have gone and dug into the eclipse source code. Going through the eclipse source code is not easy cause its a massive rhino . Finding the right code requires tons of patience for a newbie .&lt;br /&gt;&lt;br /&gt;Here i am presenting a small snippet that creates a java project programatically&lt;br /&gt;This code can also be found in the eclipse source tree , i am presenting here just for handy reference .&lt;br /&gt;&lt;br /&gt;&lt;ol&gt;&lt;li&gt;Create an IProject with a name       &lt;br /&gt;&lt;/li&gt;&lt;/ol&gt;          IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot();&lt;br /&gt;         IProject project = root.getProject("dummyProject");&lt;br /&gt;         IProgressMonitor nullProgressMonitor = null;&lt;br /&gt;         project.create(nullProgressMonitor);&lt;br /&gt;&lt;br /&gt;ResourcesPlugin is the plugin that gives us access to all the resources in eclipse including the workspace . When eclipse creates a project it shows a progress bar , we are passing null for that.&lt;br /&gt;  &lt;br /&gt;   2.  Open the above created java Project&lt;br /&gt;&lt;br /&gt;        IJavaProject javaProject = JavaCore.create(project)&lt;br /&gt;&lt;br /&gt;'create' is a misonomer . This creates a decorated Java version of an eclipse project.&lt;br /&gt;&lt;br /&gt;   3.  Add the java nature to the project&lt;br /&gt;&lt;br /&gt;       IProjectDescription description = project.getDescription();&lt;br /&gt;       description.setNatureIds(new String[]{JavaCore.NATURE_ID});&lt;br /&gt;       project.setDescription(description,null);&lt;br /&gt;&lt;br /&gt;Eclipse has the concept of natures , its kinda tagging a project with java label.&lt;br /&gt;&lt;br /&gt;   4.  Set the class path for the java project&lt;br /&gt;     &lt;br /&gt;        IClasspathEntry[] rawClassPath = javaProject.getRawClassPath();&lt;br /&gt;        List&lt;iclasspathentry&gt; classPath = new ArrayList&lt;iclasspathentry&gt;(&lt;br /&gt;                             Arrays.asList(rawClassPath));&lt;br /&gt;        classPath.add(JavaRuntime.getDefaultJREContainerEntry());&lt;br /&gt;        javaProject.setRawClasspath(classPath, nullProgressMonitor);&lt;br /&gt;&lt;br /&gt;Since java and class paths are closely tied . We need to add the different class libraries to the project class path . In Eclipse every plugin has its own class loader . By adding add class libraries to the project class path we make class libraries accessible to the class loader .&lt;br /&gt;&lt;br /&gt;   5. Create the bin folder and mark it as output folder&lt;br /&gt;   &lt;br /&gt;       boolean force = true;&lt;br /&gt;       boolean local = true;&lt;br /&gt;       IFolder binFolder = project.getFolder("bin");&lt;br /&gt;       binFolder.create(force,local,nullProgressMonitor);&lt;br /&gt;       IPath fullPath = binFolder.getFullPath();&lt;br /&gt;       javaProject.setOutputLocation(fullPath,nullProgressMonitor);&lt;br /&gt;&lt;br /&gt;This code will create a  project in the Runtime Eclipse Workbench that appears when you launch a new eclipse instance from your eclipse instance.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/683958699864453873-8780979599549687764?l=techjude.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://techjude.blogspot.com/feeds/8780979599549687764/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=683958699864453873&amp;postID=8780979599549687764' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/683958699864453873/posts/default/8780979599549687764'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/683958699864453873/posts/default/8780979599549687764'/><link rel='alternate' type='text/html' href='http://techjude.blogspot.com/2007/07/creating-new-project-in-eclipse.html' title='Creating a new project in Eclipse Programatically'/><author><name>KaranJude</name><uri>http://www.blogger.com/profile/08859421733871339100</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-683958699864453873.post-8248726975315363408</id><published>2007-07-09T02:20:00.000-07:00</published><updated>2007-07-09T03:16:12.576-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='java'/><category scheme='http://www.blogger.com/atom/ns#' term='patterns'/><category scheme='http://www.blogger.com/atom/ns#' term='eclipse'/><title type='text'>Extension Object Pattern : an Eclipse Example</title><content type='html'>In short an Extension Object pattern is a nice way of extending an interface of class by 3 rd party classes without polluting the base interface of the class.&lt;br /&gt;&lt;br /&gt;I am going to take eclipse as an example to explaing this pattern . For those of you , who have done eclipse plugin development . You would have come across ed the interface &lt;span style="font-style: italic;"&gt;IAdaptable.&lt;/span&gt; This interface is at heart of the Extension Object Pattern implemented by Eclipse .&lt;br /&gt;&lt;br /&gt;So what is the &lt;span style="font-weight: bold;"&gt;Extension Object Pattern ???&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;Say you have an interface &lt;span style="font-style: italic;"&gt;IFile . &lt;/span&gt;This interface represents an abstraction of a file . Apart from being a basic file this IFile interface could offer many services . So the question is how do you offer those services .&lt;br /&gt;&lt;br /&gt;One simple way would be to extend the IFile interface . Add the extra functionality to the new new interface and have come class implement that new interface . e.g you could have a &lt;span style="font-style: italic;"&gt;IUIFile &lt;/span&gt;interface . Once you have that interface , you could implement that interface .&lt;br /&gt;&lt;br /&gt;But the problem with that approach is that , you end up polluting the base beautiful interface and have a bloated class ( implementor) . Well the above mentioned approach would work if you are fine with extending the object every time you want to implement a new service , but as the number of services increase the class becomes super duper bloated monster .&lt;br /&gt;&lt;br /&gt;So how does the extension object pattern help us in solving this evolution problem ??&lt;br /&gt;&lt;br /&gt;I ll continue with the IFile interface from eclipse to explain how can we go about using the interface to implement the extension pattern .&lt;br /&gt;&lt;br /&gt;We know that IFile might have to support a number of services at some point of time in future . So rather than have IFile implement all the new interfaces , we just implement the IAdaptable interface . This interface is a place holder , saying that the class implementing IFile is now ready to be extended by 3 rd party classes without polluting the base interface IFile.&lt;br /&gt;&lt;br /&gt;This Adaptable interface can contain a simple method that does the job of resolving the service to the correct service provider .&lt;br /&gt;&lt;br /&gt;&lt;span style="font-style: italic;"&gt;public interface IFile extends IAdaptable , .... {&lt;br /&gt;.....&lt;br /&gt;&lt;br /&gt; public Object getAdapter(Class adapter);&lt;br /&gt; ...&lt;br /&gt; }&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;Now lets say that we want to check if IFile supports ServiceA , or ServiceB.&lt;br /&gt;We can do that now passing ServiceA.class to the getAdpater method .&lt;br /&gt;This method would return a valid object if the service is supported or on the other hand it would return a null object .&lt;br /&gt;&lt;br /&gt;Instead of having a number of if conditions in the getAdapter method  what eclipse does is that for each interface supported by the type , eclipse creates an adapter factory . The different factories are then registered with an AdapterManager . The getAdapter method then returns&lt;br /&gt;the appropriate AdapterFactory via the AdpaterManager. e.g&lt;br /&gt;&lt;span style="font-style: italic;"&gt;&lt;br /&gt;public Object getAdapter(Class adapter);&lt;br /&gt;return Platform.getAdapterManager.getAdpater(this,adapter);&lt;br /&gt;}&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;Something like this can later be used to return the right adapter for intended service.&lt;br /&gt;&lt;span style="font-style: italic;"&gt;&lt;br /&gt;public interface  IAdapterfactory {&lt;br /&gt;public Object getAdapter(Object adaptableObject, Class adapterType);&lt;br /&gt;....&lt;br /&gt;}&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;The adapter manager uses different adapter factories to resolve the reference for the  asked interface , for the given type .&lt;br /&gt;&lt;br /&gt;So in this manner multiple behaviors can be added to a single type . This is a nice way to support class extensions.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/683958699864453873-8248726975315363408?l=techjude.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://techjude.blogspot.com/feeds/8248726975315363408/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=683958699864453873&amp;postID=8248726975315363408' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/683958699864453873/posts/default/8248726975315363408'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/683958699864453873/posts/default/8248726975315363408'/><link rel='alternate' type='text/html' href='http://techjude.blogspot.com/2007/07/extension-object-pattern-eclipse.html' title='Extension Object Pattern : an Eclipse Example'/><author><name>KaranJude</name><uri>http://www.blogger.com/profile/08859421733871339100</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-683958699864453873.post-4773420441059126723</id><published>2007-06-29T02:05:00.000-07:00</published><updated>2007-06-29T02:14:15.841-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='java'/><category scheme='http://www.blogger.com/atom/ns#' term='eclipse'/><category scheme='http://www.blogger.com/atom/ns#' term='logging'/><title type='text'>Logging using the Eclipse Logging Framework</title><content type='html'>if you are using eclipse in your day to day work and you want to log activities using the in built eclipse logging frame work .&lt;br /&gt;&lt;br /&gt;Here is a small example to do the same ,&lt;br /&gt;&lt;br /&gt;if u have a plugin class then say MyPlugin that extends AbstrarctUIPlugin then u can a have method in that class that does the logging for you .&lt;br /&gt;&lt;br /&gt;&lt;span style="font-style: italic;"&gt;public static void log(String message , int status ){&lt;/span&gt;&lt;br /&gt;&lt;span style="font-style: italic;"&gt; getDefault().getLog().log(new Status(status,  getPluginID( ), message,null) );&lt;/span&gt;&lt;br /&gt;&lt;span style="font-style: italic;"&gt;}&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;the values , status can take are like :&lt;br /&gt;&lt;br /&gt;&lt;blockquote&gt;&lt;ul&gt;&lt;li style="font-style: italic;"&gt;IStatus.ERROR&lt;/li&gt;&lt;li style="font-style: italic;"&gt;IStatus.WARNING&lt;/li&gt;&lt;/ul&gt;&lt;br /&gt;&lt;/blockquote&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/683958699864453873-4773420441059126723?l=techjude.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://techjude.blogspot.com/feeds/4773420441059126723/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=683958699864453873&amp;postID=4773420441059126723' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/683958699864453873/posts/default/4773420441059126723'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/683958699864453873/posts/default/4773420441059126723'/><link rel='alternate' type='text/html' href='http://techjude.blogspot.com/2007/06/logging-using-eclipse-logging-framework.html' title='Logging using the Eclipse Logging Framework'/><author><name>KaranJude</name><uri>http://www.blogger.com/profile/08859421733871339100</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-683958699864453873.post-159987080045439840</id><published>2007-06-28T13:27:00.000-07:00</published><updated>2007-06-28T14:01:26.526-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='java'/><category scheme='http://www.blogger.com/atom/ns#' term='immutable-objects'/><title type='text'>Immutable Objects In Java</title><content type='html'>What is an Immutable Object ?&lt;br /&gt;&lt;br /&gt;An immutable object is an object that does not change its state once its created .Java has a number of inbuilt classes that provide that functionality e.g String , Integer etc..&lt;br /&gt;&lt;br /&gt;So how do you create an immutable object  :&lt;br /&gt;&lt;ul&gt;&lt;li&gt;Remove or make setters less accessible.&lt;br /&gt;&lt;/li&gt;&lt;li&gt;Preveting methods from getting overriden.&lt;/li&gt;&lt;li&gt;Make all fields final.&lt;/li&gt;&lt;li&gt;Make &lt;span style="font-weight: bold;"&gt;defensive&lt;/span&gt; copies of mutable objects.&lt;/li&gt;&lt;li&gt;Do not provide a clone method&lt;/li&gt;&lt;li&gt;Do not provide a copy constructor&lt;/li&gt;&lt;li&gt;return a fuctional object&lt;/li&gt;&lt;/ul&gt;Returning a functional object means applyting a function on the parameters of a method and returning the function rather than calculating the function and returning the value . e.g&lt;br /&gt;&lt;br /&gt;public class Complex {&lt;br /&gt; public Complex(int real, int imaginery){&lt;br /&gt;   this.real = real;&lt;br /&gt;  this.imaginery = imaginery;&lt;br /&gt; }&lt;br /&gt;&lt;br /&gt; public Complex add(Complex left , Complex right) {&lt;br /&gt;&lt;br /&gt;  // fuctional return&lt;br /&gt;  return new Complex(left.real + right.real , left.imaginery + right.imaginery); &lt;br /&gt;}&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;The advantage of having an immutable class is that its thread safe.&lt;br /&gt;The disadvantage being creating many new objects for different operations can lead to memory bloat&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/683958699864453873-159987080045439840?l=techjude.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://techjude.blogspot.com/feeds/159987080045439840/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=683958699864453873&amp;postID=159987080045439840' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/683958699864453873/posts/default/159987080045439840'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/683958699864453873/posts/default/159987080045439840'/><link rel='alternate' type='text/html' href='http://techjude.blogspot.com/2007/06/immutable-objects-in-java.html' title='Immutable Objects In Java'/><author><name>KaranJude</name><uri>http://www.blogger.com/profile/08859421733871339100</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-683958699864453873.post-9005309127288778129</id><published>2007-06-28T13:16:00.000-07:00</published><updated>2007-06-28T13:25:30.397-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='java'/><category scheme='http://www.blogger.com/atom/ns#' term='mixins'/><category scheme='http://www.blogger.com/atom/ns#' term='little sugar'/><title type='text'>Little Sugar ( Mixins in Java)</title><content type='html'>Mixin ?? what is a mixin ...&lt;br /&gt;&lt;br /&gt;Thats what i wondered when i cam accross the phrase . A Mixin is a way of adding  features to the core functionlaity of a class . It is different from extending the class , cause it generally pertains to adding features not related to the core or default behaviour of a class .&lt;br /&gt;&lt;br /&gt;A little example will make things clear . Say you have a small class &lt;span style="font-weight: bold;"&gt;&lt;span style="font-weight: bold;"&gt;Person&lt;/span&gt;&lt;/span&gt; that represents a person wholly . Not if you want to compare 2 instances of Person , you could implement the &lt;span style="font-weight: bold;"&gt;Comparable&lt;/span&gt; interface . By implementing the Comparable interface you add a functionlity that is not directly related to a Person object but is a help ful feature .&lt;br /&gt;&lt;br /&gt;So a simple way to implement a Mixin is to implement an interface .. so much for &lt;span style="font-weight: bold;"&gt;buzz words...&lt;/span&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/683958699864453873-9005309127288778129?l=techjude.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://techjude.blogspot.com/feeds/9005309127288778129/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=683958699864453873&amp;postID=9005309127288778129' title='2 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/683958699864453873/posts/default/9005309127288778129'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/683958699864453873/posts/default/9005309127288778129'/><link rel='alternate' type='text/html' href='http://techjude.blogspot.com/2007/06/little-sugar-mixins-in-java.html' title='Little Sugar ( Mixins in Java)'/><author><name>KaranJude</name><uri>http://www.blogger.com/profile/08859421733871339100</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>2</thr:total></entry><entry><id>tag:blogger.com,1999:blog-683958699864453873.post-2522515735125286494</id><published>2007-06-27T11:16:00.000-07:00</published><updated>2007-06-27T11:34:54.650-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='java'/><category scheme='http://www.blogger.com/atom/ns#' term='security'/><category scheme='http://www.blogger.com/atom/ns#' term='little sugar'/><title type='text'>Little Sugar (Security Manager , Java)</title><content type='html'>Today i ll gloss over a few small things worth remembering about security&lt;br /&gt;in java . So lets get started :&lt;br /&gt;&lt;br /&gt;In Java , we hava a Java API . The java API provides us with a lot methods to accomplish different type of tasks . Now if for some reason we want to enforce security on these tasks so that only selected operation can be performed and that to by selected users . In that case we need to create a &lt;span style="font-weight: bold;"&gt;security policy file&lt;/span&gt;.&lt;br /&gt;&lt;br /&gt;In the security policy file , we specifiy how permissions are applied to different code sources . We specify differnt permissions in terms of &lt;span style="font-weight: bold;"&gt;Permission&lt;/span&gt; objects that are applied to&lt;span style="font-weight: bold;"&gt; CodeSource  &lt;/span&gt;objects .&lt;br /&gt;&lt;br /&gt;At runtime a policy object is created corresponding to the policy file .&lt;br /&gt;&lt;br /&gt;For the policies to take effect a &lt;span style="font-weight: bold;"&gt;SecurityManager&lt;/span&gt; needs to be installed . Once the security manager is installed it uses the &lt;span style="font-weight: bold;"&gt;AccessController&lt;/span&gt; ,which inturn checks the different permissions based on different permission objects .&lt;br /&gt;&lt;br /&gt;When the class loader loads a type in the JVM . It places the type in a protection domain , which encapsulates the permissions . At runtime , when methods on the type instance are invoked the security manger is checked to see if the method can be invoked .&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/683958699864453873-2522515735125286494?l=techjude.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://techjude.blogspot.com/feeds/2522515735125286494/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=683958699864453873&amp;postID=2522515735125286494' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/683958699864453873/posts/default/2522515735125286494'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/683958699864453873/posts/default/2522515735125286494'/><link rel='alternate' type='text/html' href='http://techjude.blogspot.com/2007/06/little-sugar-security-manager-java.html' title='Little Sugar (Security Manager , Java)'/><author><name>KaranJude</name><uri>http://www.blogger.com/profile/08859421733871339100</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-683958699864453873.post-4056227682732042784</id><published>2007-06-19T07:07:00.000-07:00</published><updated>2007-06-19T07:18:33.384-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='java'/><category scheme='http://www.blogger.com/atom/ns#' term='collections'/><category scheme='http://www.blogger.com/atom/ns#' term='set'/><category scheme='http://www.blogger.com/atom/ns#' term='little sugar'/><title type='text'>Litttle Sugar (Java Collections)</title><content type='html'>The other day I was reading about java collections . I came accross this trivial point about Sets in java that is worth remembering . In java there are 3 different implementations of the Set interface , namely :&lt;br /&gt;&lt;ol&gt;&lt;li&gt;HashSet&lt;/li&gt;&lt;li&gt;TreeSet&lt;/li&gt;&lt;li&gt;LinkedHashSet&lt;span style="font-weight: bold;"&gt;&lt;/span&gt;&lt;/li&gt;&lt;/ol&gt;&lt;span style="font-weight: bold;"&gt;HashSet:&lt;/span&gt;&lt;br /&gt;The fastest among the 3 implementations , but does not maintain ordering.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;TreeSet:&lt;/span&gt;&lt;br /&gt;The slowest among the 3 implementations , uses &lt;span style="font-weight: bold;"&gt;red black tree &lt;/span&gt;to internally store items and orders the items by value.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;LinkedHashSet:&lt;/span&gt;&lt;br /&gt;Its performance comes in between the 1st two but maintain the ordering in which items are&lt;br /&gt;inserted . Uses hashtable with linked list to store items.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/683958699864453873-4056227682732042784?l=techjude.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://techjude.blogspot.com/feeds/4056227682732042784/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=683958699864453873&amp;postID=4056227682732042784' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/683958699864453873/posts/default/4056227682732042784'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/683958699864453873/posts/default/4056227682732042784'/><link rel='alternate' type='text/html' href='http://techjude.blogspot.com/2007/06/litttle-sugar-java-collections.html' title='Litttle Sugar (Java Collections)'/><author><name>KaranJude</name><uri>http://www.blogger.com/profile/08859421733871339100</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-683958699864453873.post-7672590748868659134</id><published>2007-06-16T15:38:00.001-07:00</published><updated>2007-06-16T15:42:03.847-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='c++'/><category scheme='http://www.blogger.com/atom/ns#' term='formatting'/><category scheme='http://www.blogger.com/atom/ns#' term='programming'/><title type='text'>String formatting using C++</title><content type='html'>Say you need to create a special string that does shows floating point numbers.&lt;br /&gt;Lets put another constraint , say you need to show upto K decimal places.&lt;br /&gt;&lt;br /&gt;e.g u need an output like this&lt;br /&gt;123.45 &lt;--- 2 decimal places&lt;br /&gt;&lt;br /&gt;say double d = 123.456&lt;br /&gt;&lt;br /&gt;then u can create a string which shows upto 2 decimal places like this.&lt;br /&gt;&lt;br /&gt;ostringstream o;&lt;br /&gt;o.setf(ios::fixed);&lt;br /&gt;o.precision(2);&lt;br /&gt;o &lt;&lt; d;&lt;br /&gt;cout &lt;&lt; o.str();&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/683958699864453873-7672590748868659134?l=techjude.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://techjude.blogspot.com/feeds/7672590748868659134/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=683958699864453873&amp;postID=7672590748868659134' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/683958699864453873/posts/default/7672590748868659134'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/683958699864453873/posts/default/7672590748868659134'/><link rel='alternate' type='text/html' href='http://techjude.blogspot.com/2007/06/string-formatting-using-c.html' title='String formatting using C++'/><author><name>KaranJude</name><uri>http://www.blogger.com/profile/08859421733871339100</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-683958699864453873.post-7037349250497086593</id><published>2007-06-16T08:08:00.000-07:00</published><updated>2007-06-16T08:39:55.073-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='subset-sum'/><category scheme='http://www.blogger.com/atom/ns#' term='c++'/><category scheme='http://www.blogger.com/atom/ns#' term='programming'/><category scheme='http://www.blogger.com/atom/ns#' term='bruteforce'/><title type='text'>Maximum Subset sum of a sequence</title><content type='html'>Given a sequence say 1,1,2,.....N . If this sequence has N elements . It has 2^N subsets .&lt;br /&gt;These subsets are of different sizes &lt;span style="font-weight: bold;"&gt;k &lt;/span&gt;, where k varies from 1 ... N&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;&lt;br /&gt;for(int subset = 0;subset &lt; (1&amp;lt;&amp;lt;N) ; subset++){&lt;br /&gt; if(cardinality(subset) == k){&lt;br /&gt;  sum = sum(subset)&lt;br /&gt;  if(sum &gt; maxSum)&lt;br /&gt;     maxSum = sum&lt;br /&gt; }&lt;br /&gt;}&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;a simple way to calculate subsets is to use the power of binary numbers . Bits of a number represent the different subsets as we go from 0 to 2^N i.e 1&lt;&lt;12&gt;&lt;br /&gt;&lt;br /&gt;Cardinality,is defined as the number of ones in the given number or the number of&lt;br /&gt;bits set to 1 in the given number . If cardinality is K m or the subset size we are&lt;br /&gt;are interested in , we calculate the sum of the subset .&lt;br /&gt;&lt;br /&gt;int cardinality(int N){&lt;br /&gt;return N == 0 ? 0 : (N&amp;1) + cardinality(N&gt;&gt;1);&lt;br /&gt;}&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/683958699864453873-7037349250497086593?l=techjude.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://techjude.blogspot.com/feeds/7037349250497086593/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=683958699864453873&amp;postID=7037349250497086593' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/683958699864453873/posts/default/7037349250497086593'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/683958699864453873/posts/default/7037349250497086593'/><link rel='alternate' type='text/html' href='http://techjude.blogspot.com/2007/06/maximum-subset-sum-of-sequence.html' title='Maximum Subset sum of a sequence'/><author><name>KaranJude</name><uri>http://www.blogger.com/profile/08859421733871339100</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry></feed>
