<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" media="screen" href="/~d/styles/atom10full.xsl"?><?xml-stylesheet type="text/css" media="screen" href="http://feeds.feedburner.com/~d/styles/itemcontent.css"?><feed xmlns="http://www.w3.org/2005/Atom" xmlns:openSearch="http://a9.com/-/spec/opensearch/1.1/" xmlns:georss="http://www.georss.org/georss" xmlns:gd="http://schemas.google.com/g/2005" xmlns:thr="http://purl.org/syndication/thread/1.0" xmlns:feedburner="http://rssnamespace.org/feedburner/ext/1.0" gd:etag="W/&quot;CU8FSHw4cSp7ImA9WhRVFEo.&quot;"><id>tag:blogger.com,1999:blog-3102468434043486639</id><updated>2012-01-13T08:56:59.239-08:00</updated><category term="ruby" /><category term="Python" /><category term="Unix" /><category term="EasyMock" /><category term="WTP" /><category term="Java SE 6" /><category term="Cygwin" /><category term="JNA" /><category term="Regular Expressions" /><category term="VirtualBox" /><category term="Performance Tuning" /><category term="Hibernate" /><category term="OpenSSL" /><category term="irb" /><category term="Common Knowledge" /><category term="Kernel" /><category term="Tutorial" /><category term="Windows" /><category term="Security" /><category term="Oracle" /><category term="xterm" /><category term="Lisp" /><category term="Ethereal" /><category term="3G" /><category term="Programming" /><category term="C++" /><category term="Fantom" /><category term="CPU" /><category term="PuTTY" /><category term="Web Technologies" /><category term="Vulnerability" /><category term="Puzzles" /><category term="Solaris" /><category term="InfoSec" /><category term="XWindows" /><category term="Debugging" /><category term="PC Assembling" /><category term="Lua" /><category term="SLF4J" /><category term="SSL" /><category term="vim" /><category term="JUnit" /><category term="Spring" /><category term="Build your PC" /><category term="Quartz" /><category term="Threading" /><category term="JNI" /><category term="VMWare" /><category term="Entrepreneur" /><category term="Java EE" /><category term="TCP/IP Networking" /><category term="Cool Hacks" /><category term="SFTP" /><category term="Matplotlib" /><category term="C/C++" /><category term="CVS" /><category term="Logging" /><category term="ssh" /><category term="XML" /><category term="FreeBSD" /><category term="Perl" /><category term="Java" /><category term="Cool Tools" /><category term="bash" /><category term="Algorithms" /><category term="Groovy" /><category term="Commons DBCP" /><category term="LDAP" /><category term="JDBC" /><category term="Tomcat" /><category term="Firefox" /><category term="xVM" /><category term="WYSIWYG Editor" /><category term="TipsAndTricks" /><category term="Django" /><category term="Linux" /><category term="Eclipse" /><category term="HTML" /><category term="Reference" /><category term="Emacs" /><category term="Ubuntu" /><category term="PlotKit" /><category term="JavaScript" /><category term="Intel" /><category term="JDBC-pool" /><title>Roy's musings</title><subtitle type="html">On Java and other bits.</subtitle><link rel="http://schemas.google.com/g/2005#feed" type="application/atom+xml" href="http://royontechnology.blogspot.com/feeds/posts/default" /><link rel="alternate" type="text/html" href="http://royontechnology.blogspot.com/" /><link rel="next" type="application/atom+xml" href="http://www.blogger.com/feeds/3102468434043486639/posts/default?start-index=26&amp;max-results=25&amp;redirect=false&amp;v=2" /><author><name>Roy</name><uri>http://www.blogger.com/profile/00633074227808113222</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>158</openSearch:totalResults><openSearch:startIndex>1</openSearch:startIndex><openSearch:itemsPerPage>25</openSearch:itemsPerPage><atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="self" type="application/atom+xml" href="http://feeds.feedburner.com/RoysMusings" /><feedburner:info uri="roysmusings" /><atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="hub" href="http://pubsubhubbub.appspot.com/" /><entry gd:etag="W/&quot;CkUAQXg_fip7ImA9WhRTGU0.&quot;"><id>tag:blogger.com,1999:blog-3102468434043486639.post-2148419366782351223</id><published>2011-11-09T20:43:00.000-08:00</published><updated>2011-11-09T20:44:00.646-08:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2011-11-09T20:44:00.646-08:00</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="Algorithms" /><category scheme="http://www.blogger.com/atom/ns#" term="Puzzles" /><title>Puzzle: Finding if a linked list has a loop</title><content type="html">&lt;div dir="ltr" style="text-align: left;" trbidi="on"&gt;
Puzzle statement:&lt;br /&gt;
&lt;blockquote class="tr_bq"&gt;
You are given the reference to the head of a singly linked list. Come up with an algorithm to find out if the linked list has a loop.&amp;nbsp;&lt;/blockquote&gt;
Credit: &amp;nbsp;I believe I read this problem in Sedgewick's Algorithms in C book first.&lt;br /&gt;
&lt;br /&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3102468434043486639-2148419366782351223?l=royontechnology.blogspot.com' alt='' /&gt;&lt;/div&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/M5LgQoIEjpGOczwq5h6sabgTsFE/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/M5LgQoIEjpGOczwq5h6sabgTsFE/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/M5LgQoIEjpGOczwq5h6sabgTsFE/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/M5LgQoIEjpGOczwq5h6sabgTsFE/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/RoysMusings/~4/lUgb99Xtv4A" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://royontechnology.blogspot.com/feeds/2148419366782351223/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://www.blogger.com/comment.g?blogID=3102468434043486639&amp;postID=2148419366782351223" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/3102468434043486639/posts/default/2148419366782351223?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/3102468434043486639/posts/default/2148419366782351223?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/RoysMusings/~3/lUgb99Xtv4A/puzzle-finding-if-linked-list-has-loop.html" title="Puzzle: Finding if a linked list has a loop" /><author><name>Roy</name><uri>http://www.blogger.com/profile/00633074227808113222</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><feedburner:origLink>http://royontechnology.blogspot.com/2011/11/puzzle-finding-if-linked-list-has-loop.html</feedburner:origLink></entry><entry gd:etag="W/&quot;A0AMQX0yeip7ImA9WhRTGEQ.&quot;"><id>tag:blogger.com,1999:blog-3102468434043486639.post-5258366198448664239</id><published>2011-11-09T20:36:00.000-08:00</published><updated>2011-11-09T20:36:20.392-08:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2011-11-09T20:36:20.392-08:00</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="Algorithms" /><category scheme="http://www.blogger.com/atom/ns#" term="Puzzles" /><title>Puzzle: First common parent</title><content type="html">&lt;div dir="ltr" style="text-align: left;" trbidi="on"&gt;
I love to come up with elegant and simple algorithms for hard problems. Recently one thought came to my mind: why don't I create a catalog of interesting puzzles that I come across. I am sure it will be useful to some people. At least to those who are preparing for an interview. So here is my first in the series.&lt;br /&gt;
&lt;br /&gt;
Disclaimer: I do not claim ownership of any of these puzzles that you will see in this series, unless explicitly noted. If I know the source, I give credit to the source. If I don't know the source and you do, please drop a comment pointing me to the original source of the puzzle.&lt;br /&gt;
&lt;br /&gt;
Here is the problem:&lt;br /&gt;
&lt;blockquote class="tr_bq"&gt;
You are given a binary search tree. For the sake of simplicity, assume that each node in the binary search tree holds an integer value and all the values are unique. Each node in the binary search tree has a reference to its right child and left child, but not to its parent. Given root, and two random nodes, find the first common parent of these two nodes. In case one of them is the ancestor of the other, return the ancestor node as the common parent.&lt;/blockquote&gt;
Please note that you can only perform downward traversal, as none of the nodes have a reference to its parent.&lt;br /&gt;
&lt;br /&gt;
&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3102468434043486639-5258366198448664239?l=royontechnology.blogspot.com' alt='' /&gt;&lt;/div&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/JK4GqBdxGVaWG_4Bp0z9PP5mNho/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/JK4GqBdxGVaWG_4Bp0z9PP5mNho/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/JK4GqBdxGVaWG_4Bp0z9PP5mNho/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/JK4GqBdxGVaWG_4Bp0z9PP5mNho/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/RoysMusings/~4/BNVuaYYH0Ew" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://royontechnology.blogspot.com/feeds/5258366198448664239/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://www.blogger.com/comment.g?blogID=3102468434043486639&amp;postID=5258366198448664239" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/3102468434043486639/posts/default/5258366198448664239?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/3102468434043486639/posts/default/5258366198448664239?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/RoysMusings/~3/BNVuaYYH0Ew/puzzle-first-common-parent.html" title="Puzzle: First common parent" /><author><name>Roy</name><uri>http://www.blogger.com/profile/00633074227808113222</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><feedburner:origLink>http://royontechnology.blogspot.com/2011/11/puzzle-first-common-parent.html</feedburner:origLink></entry><entry gd:etag="W/&quot;A04BSXo-eip7ImA9WhdaEks.&quot;"><id>tag:blogger.com,1999:blog-3102468434043486639.post-5538146709110372445</id><published>2011-10-22T00:20:00.000-07:00</published><updated>2011-10-22T00:52:38.452-07:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2011-10-22T00:52:38.452-07:00</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="Lisp" /><category scheme="http://www.blogger.com/atom/ns#" term="Emacs" /><title>Loading Lisp file from URL in Emacs</title><content type="html">&lt;div dir="ltr" style="text-align: left;" trbidi="on"&gt;
On a given day, I have to login and work from multiple Linux boxes. One thing I find annoying is that every time I make a change to my .emacs file, I have to copy the changes to all the hosts.&lt;br /&gt;
&lt;br /&gt;
There are multiple ways to circumvent this issue. One way I find useful is to maintain my custom file as a gist in github (or any where you can host your .emacs file) and use the following code snippet in the .emacs to load the file from the URL.&lt;br /&gt;
&lt;br /&gt;
&lt;blockquote&gt;
(with-temp-buffer&lt;br /&gt;
&amp;nbsp; (shell-command "curl -Ls https://gist.github.com/raw/372f5e3e8aca632d9b82/hello-world.el" (current-buffer))&lt;br /&gt;
&amp;nbsp; (eval-buffer))&lt;/blockquote&gt;
&lt;div&gt;
Let me explain what this code snippet does:&lt;/div&gt;
&lt;div&gt;
&lt;div&gt;
&lt;ol style="text-align: left;"&gt;
&lt;li&gt;It creates a temporary buffer.&lt;/li&gt;
&lt;li&gt;With the temporary buffer as the current buffer, it fetches the contents of the URL into the current buffer.&lt;/li&gt;
&lt;li&gt;It evaluates the current buffer.&lt;/li&gt;
&lt;li&gt;Remove the temporary buffer.&lt;/li&gt;
&lt;/ol&gt;
&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
If the sample code above works for you, if you eval the "(hello-world)", it will say "hello world" in the mini buffer.&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3102468434043486639-5538146709110372445?l=royontechnology.blogspot.com' alt='' /&gt;&lt;/div&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/fcHap4xzHuOZ0re-xxeeOElxkbY/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/fcHap4xzHuOZ0re-xxeeOElxkbY/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/fcHap4xzHuOZ0re-xxeeOElxkbY/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/fcHap4xzHuOZ0re-xxeeOElxkbY/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/RoysMusings/~4/I6xr2-0YzEk" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://royontechnology.blogspot.com/feeds/5538146709110372445/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://www.blogger.com/comment.g?blogID=3102468434043486639&amp;postID=5538146709110372445" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/3102468434043486639/posts/default/5538146709110372445?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/3102468434043486639/posts/default/5538146709110372445?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/RoysMusings/~3/I6xr2-0YzEk/loading-lisp-file-from-url-in-emacs.html" title="Loading Lisp file from URL in Emacs" /><author><name>Roy</name><uri>http://www.blogger.com/profile/00633074227808113222</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><feedburner:origLink>http://royontechnology.blogspot.com/2011/10/loading-lisp-file-from-url-in-emacs.html</feedburner:origLink></entry><entry gd:etag="W/&quot;DEEDSX0-eCp7ImA9WhdbGEk.&quot;"><id>tag:blogger.com,1999:blog-3102468434043486639.post-1453804831200426096</id><published>2011-10-17T03:17:00.000-07:00</published><updated>2011-10-17T03:17:58.350-07:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2011-10-17T03:17:58.350-07:00</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="Emacs" /><title>Fastest way to switch between buffers in Emacs</title><content type="html">&lt;div dir="ltr" style="text-align: left;" trbidi="on"&gt;
In any given Emacs session, I have at least 5 buffers open. One of the pains of using C-x b to switch between buffers is that after typing every few characters, you have to type tab to perform completion. It is a waste of time.&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;iswitchb&lt;/b&gt; is a much more efficient alternative to the default switch-to-buffer that is invoked while you type C-x b. It is time saving in two ways: (1) there is no need to type tab for completion and (2) you can give any part of the buffer name in the minibuffer prompt and jump to that buffer.&lt;br /&gt;
&lt;br /&gt;
To enable this mode, add the following line in your .emacs file.&lt;br /&gt;
&lt;blockquote&gt;
&lt;span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;"&gt;(iswitchb-mode 1)&amp;nbsp;&lt;/span&gt;&lt;/blockquote&gt;
Thats it. You are ready to rock-n-roll.&lt;br /&gt;
&lt;br /&gt;
More info at:&amp;nbsp;&lt;a href="http://www.emacswiki.org/emacs/IswitchBuffers"&gt;http://www.emacswiki.org/emacs/IswitchBuffers&lt;/a&gt;.&lt;br /&gt;
&lt;br /&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3102468434043486639-1453804831200426096?l=royontechnology.blogspot.com' alt='' /&gt;&lt;/div&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/qBNcHw5GfkdJshEOppGnsAtX5kc/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/qBNcHw5GfkdJshEOppGnsAtX5kc/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/qBNcHw5GfkdJshEOppGnsAtX5kc/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/qBNcHw5GfkdJshEOppGnsAtX5kc/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/RoysMusings/~4/NxGwTX69Vds" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://royontechnology.blogspot.com/feeds/1453804831200426096/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://www.blogger.com/comment.g?blogID=3102468434043486639&amp;postID=1453804831200426096" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/3102468434043486639/posts/default/1453804831200426096?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/3102468434043486639/posts/default/1453804831200426096?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/RoysMusings/~3/NxGwTX69Vds/fastest-way-to-switch-between-buffers.html" title="Fastest way to switch between buffers in Emacs" /><author><name>Roy</name><uri>http://www.blogger.com/profile/00633074227808113222</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><feedburner:origLink>http://royontechnology.blogspot.com/2011/10/fastest-way-to-switch-between-buffers.html</feedburner:origLink></entry><entry gd:etag="W/&quot;Dk4FQngyfip7ImA9WhdbGEk.&quot;"><id>tag:blogger.com,1999:blog-3102468434043486639.post-2179714592324480878</id><published>2011-10-17T02:46:00.000-07:00</published><updated>2011-10-17T02:48:33.696-07:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2011-10-17T02:48:33.696-07:00</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="Emacs" /><title>Font face customization in Emacs - an easy way</title><content type="html">&lt;div dir="ltr" style="text-align: left;" trbidi="on"&gt;
I usually edit source code using Emacs running inside a PuTTY session. One of the struggles I often run into is how to customize different elements I see on the screen. For e.g. the prompt in the shell-mode, previously executed command line, shell input, etc.&lt;br /&gt;
&lt;br /&gt;
While I googled around a bit, I came across this incredibly useful key binding: &lt;b&gt;C-u C-x =&lt;/b&gt;. It runs the command "what-cursor-position". Here is how you can use this:&amp;nbsp;You position the cursor on the element you would like to customize, and type C-u C-x =. You will be presented with the properties of the character at point, including links to customize the character.&lt;br /&gt;
&lt;br /&gt;
I find this extremely useful and hope sharing this information will help others as well.&lt;br /&gt;
&lt;br /&gt;
Credit:&amp;nbsp;&lt;a href="http://stackoverflow.com/questions/1242352/get-font-face-under-cursor-in-emacs"&gt;http://stackoverflow.com/questions/1242352/get-font-face-under-cursor-in-emacs&lt;/a&gt;&lt;br /&gt;
&lt;br /&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3102468434043486639-2179714592324480878?l=royontechnology.blogspot.com' alt='' /&gt;&lt;/div&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/UeMMM-76iraXWGxltvoCtM8Zthg/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/UeMMM-76iraXWGxltvoCtM8Zthg/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/UeMMM-76iraXWGxltvoCtM8Zthg/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/UeMMM-76iraXWGxltvoCtM8Zthg/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/RoysMusings/~4/OYJuzEnRUjI" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://royontechnology.blogspot.com/feeds/2179714592324480878/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://www.blogger.com/comment.g?blogID=3102468434043486639&amp;postID=2179714592324480878" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/3102468434043486639/posts/default/2179714592324480878?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/3102468434043486639/posts/default/2179714592324480878?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/RoysMusings/~3/OYJuzEnRUjI/font-face-customization-in-emacs-easy.html" title="Font face customization in Emacs - an easy way" /><author><name>Roy</name><uri>http://www.blogger.com/profile/00633074227808113222</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><feedburner:origLink>http://royontechnology.blogspot.com/2011/10/font-face-customization-in-emacs-easy.html</feedburner:origLink></entry><entry gd:etag="W/&quot;C0EHR349fCp7ImA9WhdbFkk.&quot;"><id>tag:blogger.com,1999:blog-3102468434043486639.post-7256685238725337147</id><published>2011-10-14T18:20:00.000-07:00</published><updated>2011-10-14T18:20:36.064-07:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2011-10-14T18:20:36.064-07:00</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="Perl" /><title>Perlbrew saved the day</title><content type="html">&lt;div dir="ltr" style="text-align: left;" trbidi="on"&gt;
After an insanely long period of silence, I am writing another blog entry. I couldn't contain my excitement with what I learnt today and hence this post.&lt;br /&gt;
&lt;br /&gt;
I had to upgrade Perl installation in my Linux host and I visited Perl.org to download and install Perl. It was suggested to make use of the &lt;a href="http://search.cpan.org/dist/App-perlbrew/lib/App/perlbrew.pm"&gt;perlbrew &lt;/a&gt;to install and manage different versions of Perl under your home directory. I gave it a try and it was incredibly simple to upgrade the Perl installation in my box, without screwing up the old installation (which I still need for some of the old scripts I have).&lt;br /&gt;
&lt;br /&gt;
If you haven't tried it yet, I would strongly recommend.&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3102468434043486639-7256685238725337147?l=royontechnology.blogspot.com' alt='' /&gt;&lt;/div&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/OU8n31FnXnBDASIEPxCB9-cFmlM/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/OU8n31FnXnBDASIEPxCB9-cFmlM/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/OU8n31FnXnBDASIEPxCB9-cFmlM/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/OU8n31FnXnBDASIEPxCB9-cFmlM/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/RoysMusings/~4/-7SQxLpq4XQ" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://royontechnology.blogspot.com/feeds/7256685238725337147/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://www.blogger.com/comment.g?blogID=3102468434043486639&amp;postID=7256685238725337147" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/3102468434043486639/posts/default/7256685238725337147?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/3102468434043486639/posts/default/7256685238725337147?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/RoysMusings/~3/-7SQxLpq4XQ/perlbrew-saved-day.html" title="Perlbrew saved the day" /><author><name>Roy</name><uri>http://www.blogger.com/profile/00633074227808113222</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><feedburner:origLink>http://royontechnology.blogspot.com/2011/10/perlbrew-saved-day.html</feedburner:origLink></entry><entry gd:etag="W/&quot;D08GRHkyeCp7ImA9Wx9bEko.&quot;"><id>tag:blogger.com,1999:blog-3102468434043486639.post-3769618678534789257</id><published>2011-02-21T00:10:00.000-08:00</published><updated>2011-02-21T00:10:25.790-08:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2011-02-21T00:10:25.790-08:00</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="Security" /><title>Two cookie attributes you MUST be aware to secure your web app</title><content type="html">&lt;div dir="ltr" style="text-align: left;" trbidi="on"&gt;There are two attributes of cookies that every web developer must be aware of to secure your web application. These two attributes doesn't save your application from all attacks, but at least they reduce the vulnerability to a great extent. These two attributes are:&lt;br /&gt;
&lt;br /&gt;
&lt;ul style="text-align: left;"&gt;&lt;li&gt;HttpOnly&lt;/li&gt;
&lt;li&gt;Secure&lt;/li&gt;
&lt;/ul&gt;&lt;div&gt;The first attribute HttpOnly says that the cookie is intended to be passed only as a part of HTTP communication. Hence it must not be available to the application (like JavaScripts running in the browser). So once you load a page, if you type "javascript:alert(document.cookie)" in the URL bar, you will not those cookies that have the HttpOnly flag set.&lt;/div&gt;&lt;div&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div&gt;The second attribute Secure tells that the cookie should be sent as a part of the request if and only if the communication happens over a HTTPS channel. Typically login requests are sent over HTTPS channels. (If you are using a web app that is using HTTP for login page, its time you stop using it!). Typically, as a part of the login response, there will be two sets of cookies set. One that can be sent over both HTTP and HTTPS and another set that can be sent only over HTTPS. It is the cookies that are to be sent over HTTPS that serious parts of your web application should depend on. For e.g. check out of your shopping cart.&lt;/div&gt;&lt;div&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div&gt;You can learn more about &lt;a href="http://www.owasp.org/index.php/HttpOnly"&gt;HttpOnly flag here&lt;/a&gt;&amp;nbsp;and &lt;a href="http://www.codinghorror.com/blog/2008/08/protecting-your-cookies-httponly.html"&gt;here&lt;/a&gt;.Also you can learn more about Secure flag in the &lt;a href="http://en.wikipedia.org/wiki/HTTP_cookie"&gt;wiki page&lt;/a&gt;.&lt;/div&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3102468434043486639-3769618678534789257?l=royontechnology.blogspot.com' alt='' /&gt;&lt;/div&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/1c9a_ZWzIQsXohm1DRdEhYZFcgE/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/1c9a_ZWzIQsXohm1DRdEhYZFcgE/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/1c9a_ZWzIQsXohm1DRdEhYZFcgE/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/1c9a_ZWzIQsXohm1DRdEhYZFcgE/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/RoysMusings/~4/tcYywrDx290" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://royontechnology.blogspot.com/feeds/3769618678534789257/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://www.blogger.com/comment.g?blogID=3102468434043486639&amp;postID=3769618678534789257" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/3102468434043486639/posts/default/3769618678534789257?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/3102468434043486639/posts/default/3769618678534789257?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/RoysMusings/~3/tcYywrDx290/two-cookie-attributes-you-must-be-aware.html" title="Two cookie attributes you MUST be aware to secure your web app" /><author><name>Roy</name><uri>http://www.blogger.com/profile/00633074227808113222</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><feedburner:origLink>http://royontechnology.blogspot.com/2011/02/two-cookie-attributes-you-must-be-aware.html</feedburner:origLink></entry><entry gd:etag="W/&quot;CkQAQn0zcSp7ImA9Wx9bEUU.&quot;"><id>tag:blogger.com,1999:blog-3102468434043486639.post-8210813726925710884</id><published>2011-02-19T21:33:00.000-08:00</published><updated>2011-02-19T21:39:03.389-08:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2011-02-19T21:39:03.389-08:00</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="ruby" /><category scheme="http://www.blogger.com/atom/ns#" term="irb" /><title>Cygwin and irb</title><content type="html">&lt;div dir="ltr" style="text-align: left;" trbidi="on"&gt;If you had tried to start irb in Windows that has cygwin installed, you might have got the following exception trace:&lt;br /&gt;
&lt;br /&gt;
&lt;pre&gt;C:/Ruby192/lib/ruby/site_ruby/1.9.1/rbreadline.rb:2095:in `expand_path': non-absolute home (ArgumentError)
        from C:/Ruby192/lib/ruby/site_ruby/1.9.1/rbreadline.rb:2095:in `_rl_read_init_file'
        from C:/Ruby192/lib/ruby/site_ruby/1.9.1/rbreadline.rb:2078:in `rl_read_init_file'
        from C:/Ruby192/lib/ruby/site_ruby/1.9.1/rbreadline.rb:2499:in `readline_initialize_everything'
        from C:/Ruby192/lib/ruby/site_ruby/1.9.1/rbreadline.rb:3730:in `rl_initialize'
        from C:/Ruby192/lib/ruby/site_ruby/1.9.1/rbreadline.rb:4737:in `readline'
        from C:/Ruby192/lib/ruby/site_ruby/1.9.1/readline.rb:40:in `readline'
        from C:/Ruby192/lib/ruby/1.9.1/irb/input-method.rb:115:in `gets'
        from C:/Ruby192/lib/ruby/1.9.1/irb.rb:139:in `block (2 levels) in eval_input'
        from C:/Ruby192/lib/ruby/1.9.1/irb.rb:273:in `signal_status'
        from C:/Ruby192/lib/ruby/1.9.1/irb.rb:138:in `block in eval_input'
        from C:/Ruby192/lib/ruby/1.9.1/irb/ruby-lex.rb:188:in `call'
        from C:/Ruby192/lib/ruby/1.9.1/irb/ruby-lex.rb:188:in `buf_input'
        from C:/Ruby192/lib/ruby/1.9.1/irb/ruby-lex.rb:103:in `getc'
        from C:/Ruby192/lib/ruby/1.9.1/irb/slex.rb:205:in `match_io'
        from C:/Ruby192/lib/ruby/1.9.1/irb/slex.rb:75:in `match'
        from C:/Ruby192/lib/ruby/1.9.1/irb/ruby-lex.rb:286:in `token'
        from C:/Ruby192/lib/ruby/1.9.1/irb/ruby-lex.rb:262:in `lex'
        from C:/Ruby192/lib/ruby/1.9.1/irb/ruby-lex.rb:233:in `block (2 levels) in each_top_level_statement'
        from C:/Ruby192/lib/ruby/1.9.1/irb/ruby-lex.rb:229:in `loop'
        from C:/Ruby192/lib/ruby/1.9.1/irb/ruby-lex.rb:229:in `block in each_top_level_statement'
        from C:/Ruby192/lib/ruby/1.9.1/irb/ruby-lex.rb:228:in `catch'
        from C:/Ruby192/lib/ruby/1.9.1/irb/ruby-lex.rb:228:in `each_top_level_statement'
        from C:/Ruby192/lib/ruby/1.9.1/irb.rb:155:in `eval_input'
        from C:/Ruby192/lib/ruby/1.9.1/irb.rb:70:in `block in start'
        from C:/Ruby192/lib/ruby/1.9.1/irb.rb:69:in `catch'
        from C:/Ruby192/lib/ruby/1.9.1/irb.rb:69:in `start'
        from C:/Ruby192/bin/irb:12:in `&lt;main&gt;'
&lt;/pre&gt;The solution to this problem is very simple. Just unset the HOME environment variable and start irb again.&lt;br /&gt;
&lt;pre&gt;set HOME=
set HOMEDRIVE=
set HOMEPATH=
set HOMESHARE=
&lt;/pre&gt;Some of them are not directly related to Cygwin. But resetting will help you in avoiding issues while running gems.&lt;br /&gt;
&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3102468434043486639-8210813726925710884?l=royontechnology.blogspot.com' alt='' /&gt;&lt;/div&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/A8FiAE_x9dyaihq_fQw18YgrpfQ/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/A8FiAE_x9dyaihq_fQw18YgrpfQ/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/A8FiAE_x9dyaihq_fQw18YgrpfQ/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/A8FiAE_x9dyaihq_fQw18YgrpfQ/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/RoysMusings/~4/zRfT77RywOI" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://royontechnology.blogspot.com/feeds/8210813726925710884/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://www.blogger.com/comment.g?blogID=3102468434043486639&amp;postID=8210813726925710884" title="1 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/3102468434043486639/posts/default/8210813726925710884?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/3102468434043486639/posts/default/8210813726925710884?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/RoysMusings/~3/zRfT77RywOI/cygwin-and-irb.html" title="Cygwin and irb" /><author><name>Roy</name><uri>http://www.blogger.com/profile/00633074227808113222</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><feedburner:origLink>http://royontechnology.blogspot.com/2011/02/cygwin-and-irb.html</feedburner:origLink></entry><entry gd:etag="W/&quot;DUMFQHs-eCp7ImA9Wx5aFkw.&quot;"><id>tag:blogger.com,1999:blog-3102468434043486639.post-2171061202013984165</id><published>2010-11-12T19:01:00.000-08:00</published><updated>2010-11-12T19:03:31.550-08:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2010-11-12T19:03:31.550-08:00</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="Fantom" /><title>Pattern: How to start a thread of execution in Fantom</title><content type="html">In Fantom, how do you start a new thread of execution? The pattern below is very simple and nice.&lt;br /&gt;
&lt;br /&gt;
&lt;pre style="font-family: Andale Mono, Lucida Console, Monaco, fixed, monospace; color: #000000; background-color: #eee;font-size: 12px;border: 1px dashed #999999;line-height: 14px;padding: 5px; overflow: auto; width: 100%"&gt;&lt;code&gt;    const class Main {
        Void main() {
            svc := Actor(ActorPool()) { doSomething }.send(null)
        }

        Obj? doSomething() {
            // Do something like binding to a port and listening for requests.
            // Or you can call another method that does that.

            return null
        }
    }
&lt;/code&gt;&lt;/pre&gt;&lt;br /&gt;
The code above might seem a little odd at first. All that it does is to create an Actor with a code block that will execute the doSomething method. By sending a dummy message (".send(null)"), the Actor instance is started.&lt;br /&gt;
&lt;br /&gt;
The key here is that sending a dummy message to an Actor starts the Actor. This same trick may be applicable to other Actor based languages as well.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3102468434043486639-2171061202013984165?l=royontechnology.blogspot.com' alt='' /&gt;&lt;/div&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/rjXAU_PFcFy7ATpy-SWRuEr2PvM/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/rjXAU_PFcFy7ATpy-SWRuEr2PvM/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/rjXAU_PFcFy7ATpy-SWRuEr2PvM/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/rjXAU_PFcFy7ATpy-SWRuEr2PvM/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/RoysMusings/~4/EH8bfRGHkVs" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://royontechnology.blogspot.com/feeds/2171061202013984165/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://www.blogger.com/comment.g?blogID=3102468434043486639&amp;postID=2171061202013984165" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/3102468434043486639/posts/default/2171061202013984165?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/3102468434043486639/posts/default/2171061202013984165?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/RoysMusings/~3/EH8bfRGHkVs/pattern-how-to-start-thread-of.html" title="Pattern: How to start a thread of execution in Fantom" /><author><name>Roy</name><uri>http://www.blogger.com/profile/00633074227808113222</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><feedburner:origLink>http://royontechnology.blogspot.com/2010/11/pattern-how-to-start-thread-of.html</feedburner:origLink></entry><entry gd:etag="W/&quot;DUQBRXo7cSp7ImA9Wx5bGE8.&quot;"><id>tag:blogger.com,1999:blog-3102468434043486639.post-3988948392851369754</id><published>2010-11-03T16:35:00.000-07:00</published><updated>2010-11-03T16:35:54.409-07:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2010-11-03T16:35:54.409-07:00</app:edited><title>Funny error message in YouTube</title><content type="html">Today I got this funny error message in YouTube.&lt;br /&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;/div&gt;&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;/div&gt;&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;/div&gt;&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;/div&gt;&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://2.bp.blogspot.com/_BmzDYiOyneE/TNHxhd6DFDI/AAAAAAAABTc/GhT2UyZwlvs/s1600/funny-youtube-message.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img border="0" height="187" src="http://2.bp.blogspot.com/_BmzDYiOyneE/TNHxhd6DFDI/AAAAAAAABTc/GhT2UyZwlvs/s320/funny-youtube-message.jpg" width="320" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3102468434043486639-3988948392851369754?l=royontechnology.blogspot.com' alt='' /&gt;&lt;/div&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/ULfg2cUDvBi3Tn01VHXcJRXDnCU/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/ULfg2cUDvBi3Tn01VHXcJRXDnCU/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/ULfg2cUDvBi3Tn01VHXcJRXDnCU/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/ULfg2cUDvBi3Tn01VHXcJRXDnCU/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/RoysMusings/~4/pTvH91AuVk0" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://royontechnology.blogspot.com/feeds/3988948392851369754/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://www.blogger.com/comment.g?blogID=3102468434043486639&amp;postID=3988948392851369754" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/3102468434043486639/posts/default/3988948392851369754?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/3102468434043486639/posts/default/3988948392851369754?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/RoysMusings/~3/pTvH91AuVk0/funny-error-message-in-youtube.html" title="Funny error message in YouTube" /><author><name>Roy</name><uri>http://www.blogger.com/profile/00633074227808113222</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><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="http://2.bp.blogspot.com/_BmzDYiOyneE/TNHxhd6DFDI/AAAAAAAABTc/GhT2UyZwlvs/s72-c/funny-youtube-message.jpg" height="72" width="72" /><thr:total>0</thr:total><feedburner:origLink>http://royontechnology.blogspot.com/2010/11/funny-error-message-in-youtube.html</feedburner:origLink></entry><entry gd:etag="W/&quot;DE8GQXo_cSp7ImA9Wx5bF04.&quot;"><id>tag:blogger.com,1999:blog-3102468434043486639.post-8546003716103706938</id><published>2010-11-02T15:26:00.000-07:00</published><updated>2010-11-02T15:27:00.449-07:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2010-11-02T15:27:00.449-07:00</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="Fantom" /><title>Lazy initializing default values</title><content type="html">One of the tasks you will come across often is to look up a value in a map, while providing a default value for the looked up value. For e.g. &lt;br /&gt;
&lt;br /&gt;
&lt;pre style="font-family: Andale Mono, Lucida Console, Monaco, fixed, monospace; color: #000000; background-color: #eee;font-size: 12px;border: 1px dashed #999999;line-height: 14px;padding: 5px; overflow: auto; width: 100%"&gt;&lt;code&gt;Properties prop = ...
Object value = prop.get(&amp;quot;key&amp;quot;, &amp;quot;defaultValue&amp;quot;)
&lt;/code&gt;&lt;/pre&gt;&lt;br /&gt;
The issue with this pattern is that, what if arriving at default value is a costly operation. Even worse, there may be no need to compute the default value at all, may be because the get operation will always find a value in the properties.&lt;br /&gt;
&lt;br /&gt;
During such times "lazy evaluation" comes to the rescue. This is not a new pattern, it has been around for long time. Just that some APIs are written with lazy evaluation in mind, and some not. In the example above, instead of taking the value itself, if the get method takes an argument that is callable or a lambda function, then it can use that function only under the situation that the value is not present.&lt;br /&gt;
&lt;br /&gt;
The example below is from Fantom language when you attempt to get a value from a map.&lt;br /&gt;
&lt;pre style="font-family: Andale Mono, Lucida Console, Monaco, fixed, monospace; color: #000000; background-color: #eee;font-size: 12px;border: 1px dashed #999999;line-height: 14px;padding: 5px; overflow: auto; width: 100%"&gt;&lt;code&gt;    class Main {
        Void main() {
            myMap := [Str:Str][&amp;quot;k1&amp;quot;:&amp;quot;v1&amp;quot;, &amp;quot;k2&amp;quot;:&amp;quot;v2&amp;quot;]
            echo(myMap.getOrAdd(&amp;quot;k3&amp;quot;, &amp;#124;Str k-&amp;gt;Str&amp;#124; {return &amp;quot;v3&amp;quot;}))
        }
    }
&lt;/code&gt;&lt;/pre&gt;&lt;br /&gt;
What the piece of code above does is to compute the value of the key only when it is not present in the map. In the example above when you look up "k3" which is not found in the map, the lambda function is invoked to compute the value once.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3102468434043486639-8546003716103706938?l=royontechnology.blogspot.com' alt='' /&gt;&lt;/div&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/2P6pvlipobriK8u_G0fKr6ptaFM/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/2P6pvlipobriK8u_G0fKr6ptaFM/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/2P6pvlipobriK8u_G0fKr6ptaFM/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/2P6pvlipobriK8u_G0fKr6ptaFM/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/RoysMusings/~4/wkp1GTWCMHg" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://royontechnology.blogspot.com/feeds/8546003716103706938/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://www.blogger.com/comment.g?blogID=3102468434043486639&amp;postID=8546003716103706938" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/3102468434043486639/posts/default/8546003716103706938?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/3102468434043486639/posts/default/8546003716103706938?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/RoysMusings/~3/wkp1GTWCMHg/pattern-for-lazy-initializing-default.html" title="Lazy initializing default values" /><author><name>Roy</name><uri>http://www.blogger.com/profile/00633074227808113222</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><feedburner:origLink>http://royontechnology.blogspot.com/2010/11/pattern-for-lazy-initializing-default.html</feedburner:origLink></entry><entry gd:etag="W/&quot;D0ACR3Y4eCp7ImA9Wx5bE08.&quot;"><id>tag:blogger.com,1999:blog-3102468434043486639.post-9147113955946680118</id><published>2010-10-28T20:25:00.000-07:00</published><updated>2010-10-28T21:16:06.830-07:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2010-10-28T21:16:06.830-07:00</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="Fantom" /><title>Initial thoughts on Fantom</title><content type="html">Recently I started playing with &lt;a href="http://fantom.org/"&gt;Fantom language&lt;/a&gt;. So far my reaction is "Wow!". Its a beautiful language with a lot of cool things. I also ran into a few gotchas, but none that falls in the category of "ugly!".  &lt;br/&gt;&lt;br /&gt;
&lt;br /&gt;
Here are the things I really liked about the language (not necessarily in any order):&lt;br /&gt;
&lt;ol&gt;&lt;li&gt; Before any technical merits, the first thing I liked is the documentation. Most of the time, when I look for some documentation for a open source project, they notoriously suck. Fantom is the second project whose documentation I really liked and found my way around most of the time. (The first one is SLF4J.) &lt;/li&gt;
&lt;li&gt; The language is statically typed, with room for dynamically invoking methods on objects using a mechanism called "trap". &lt;/li&gt;
&lt;li&gt; One central theme I observed in the language is being able to reliably create an immutable objects ("const" classes). This simplifies a lot of analysis when it comes to concurrent programming. Also the language supports creating immutable Lists and Maps.&lt;/li&gt;
&lt;li&gt; The language has a few forms of literal expressions that the compiler understands and creates objects for you. For e.g. Map, List, Uri and Duration have equivalent literal forms. One of the places where supporting literal forms aces is during serialization. Any object that is serialized is humanly readable (There is provision for overriding this as well!). Likewise you can create objects from string literal forms that can either be read from a file or just constructed by the program on the fly. What that means? One particular case I can think of is ease of creation of test data. &lt;/li&gt;
&lt;li&gt; Any field you specify is automatically accessed through getter and setter generated behind the screen. If you want, you can add more checks and behavior to the getters and setters. &lt;/li&gt;
&lt;li&gt; For concurrency, the language provides Actors framework. This is one level of abstraction above thread. In short: actors respond to messages and these messages are immutable. In a way, it simplifies the thinking about concurrent programming. &lt;/li&gt;
&lt;li&gt; The language supports anonymous function blocks. i.e. functions are objects too! That helps you in having some neat and cool patterns in your code. Like "10.times { ... }" or "aList.each { ... }". That also means the language supports closures. &lt;/li&gt;
&lt;li&gt; The language has mixins support. Its a useful concept when you want to assemble behavior on a type. &lt;/li&gt;
&lt;li&gt; Java Annotations equivalent is called as facets. You can decorate a field, method or a type with facets. BTW, fields and methods are called as slots in Fantom. I guess that term came from Smalltalk.&lt;/li&gt;
&lt;li&gt; You can use any of the Java classes just by adding a "using ..." statement. That gives you enough power and you wouldn't be missing any libraries that you may not find in Fantom. &lt;/li&gt;
&lt;li&gt; The code you write runs in JVM, CLR and (almost in) JavaScript. The work to have full support on JavaScript is actively underway. &lt;/li&gt;
&lt;/ol&gt;&lt;br /&gt;
Okay. Now the gotchas. &lt;br /&gt;
&lt;ol&gt;&lt;li&gt; You cannot control how many actors you want to be simultaneously active. The language takes care of it for you. Sometimes, you may want to have control on this one. &lt;/li&gt;
&lt;li&gt; There is no single queue and multiple consumers paradigm in actors. Either the producer can keep enqueuing the work in the same actor's queue or enqueue work with multiple actors in a round-robin fashion. In a circuitous way, you can implement this. &lt;/li&gt;
&lt;li&gt; The way a a collections member field (a List or a Map) is serialized and deserialized, hmm ... still I am not quite clear. I need to read about that section again. &lt;/li&gt;
&lt;/ol&gt;&lt;br /&gt;
Please understand that these gotchas may not be true, as I am a beginner and may be doing things in a wrong way.&lt;br /&gt;
&lt;br /&gt;
Above everything else, I like the community of Fantom. Those guys are just amazing in terms of responding to my questions and helping to understand the concepts. I hope to write more about my adventures in Fantom-land. Stay tuned.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3102468434043486639-9147113955946680118?l=royontechnology.blogspot.com' alt='' /&gt;&lt;/div&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/q5PBFqptGaCFI3CbATeBqlsQ9-0/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/q5PBFqptGaCFI3CbATeBqlsQ9-0/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/q5PBFqptGaCFI3CbATeBqlsQ9-0/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/q5PBFqptGaCFI3CbATeBqlsQ9-0/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/RoysMusings/~4/tDxl7oZZ8n0" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://royontechnology.blogspot.com/feeds/9147113955946680118/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://www.blogger.com/comment.g?blogID=3102468434043486639&amp;postID=9147113955946680118" title="1 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/3102468434043486639/posts/default/9147113955946680118?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/3102468434043486639/posts/default/9147113955946680118?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/RoysMusings/~3/tDxl7oZZ8n0/initial-thoughts-on-fantom.html" title="Initial thoughts on Fantom" /><author><name>Roy</name><uri>http://www.blogger.com/profile/00633074227808113222</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><feedburner:origLink>http://royontechnology.blogspot.com/2010/10/initial-thoughts-on-fantom.html</feedburner:origLink></entry><entry gd:etag="W/&quot;Ak8MR3g_eyp7ImA9Wx5bEE4.&quot;"><id>tag:blogger.com,1999:blog-3102468434043486639.post-3824249450684557400</id><published>2010-10-19T16:51:00.000-07:00</published><updated>2010-10-25T13:34:46.643-07:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2010-10-25T13:34:46.643-07:00</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="Java" /><category scheme="http://www.blogger.com/atom/ns#" term="Java SE 6" /><title>SecretKeyFactory is broken in JDK 1.6 update 22</title><content type="html">If you upgrade JDK to 1.6 update 22 (build 04), the SecretKeyFactory is broken. As a result you will not be able to load any PKCS12 key stores. You will get NoSuchAlgorithmException thrown. &lt;br /&gt;
&lt;br /&gt;
I have reported this issue in the bug database. You can view &lt;a href="http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=6993338"&gt;the bug here&lt;/a&gt;. I guess it will take upto a day for this bug to be externally visible, if you don't have a SDN account.&lt;br /&gt;
&lt;br /&gt;
Here is the sample program to reproduce the issue:&lt;br /&gt;
&lt;pre style="font-family: Andale Mono, Lucida Console, Monaco, fixed, monospace; color: #000000; background-color: #eee;font-size: 12px;border: 1px dashed #999999;line-height: 14px;padding: 5px; overflow: auto; width: 100%"&gt;&lt;code&gt;public static void main(String[] args) {
        SecretKeyFactory instance = SecretKeyFactory.getInstance(&amp;quot;PBEWithMD5AndDES&amp;quot;);
        System.out.println(&amp;quot;Returned instance: &amp;quot; + instance.getAlgorithm());
}
&lt;/code&gt;&lt;/pre&gt;&lt;br /&gt;
You will get the exception below:&lt;br /&gt;
&lt;pre style="font-family: Andale Mono, Lucida Console, Monaco, fixed, monospace; color: #000000; background-color: #eee;font-size: 12px;border: 1px dashed #999999;line-height: 14px;padding: 5px; overflow: auto; width: 100%"&gt;&lt;code&gt;Exception in thread &amp;quot;main&amp;quot; java.security.NoSuchAlgorithmException: PBEWithSHA1AndRC2_40 SecretKeyFactory not available
    at javax.crypto.SecretKeyFactory.&amp;lt;init&amp;gt;(DashoA13*..)
    at javax.crypto.SecretKeyFactory.getInstance(DashoA13*..)
    at main.TestClient.main(TestClient.java:96)
&lt;/code&gt;&lt;/pre&gt;&lt;br /&gt;
&lt;b&gt;Work around:&lt;/b&gt; Until the issue is fixed, revert back to JDK 1.6 update 21. I will update my blog once if I find any fix or work around.&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;Update on 10/25:&lt;/b&gt; Actually I figured one thing: I had update 21 as the project's default JRE in my Eclipse, but tried to run the application using update 22. When I changed the project's default JRE to update 22, I didn't get the error anymore. I am guessing that could be the problem. I am not having the issue any more.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3102468434043486639-3824249450684557400?l=royontechnology.blogspot.com' alt='' /&gt;&lt;/div&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/ah-FgT1Q6aB4sVwV175ivkeFpsQ/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/ah-FgT1Q6aB4sVwV175ivkeFpsQ/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/ah-FgT1Q6aB4sVwV175ivkeFpsQ/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/ah-FgT1Q6aB4sVwV175ivkeFpsQ/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/RoysMusings/~4/g9izba2U_pU" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://royontechnology.blogspot.com/feeds/3824249450684557400/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://www.blogger.com/comment.g?blogID=3102468434043486639&amp;postID=3824249450684557400" title="1 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/3102468434043486639/posts/default/3824249450684557400?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/3102468434043486639/posts/default/3824249450684557400?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/RoysMusings/~3/g9izba2U_pU/secretkeyfactory-is-broken-in-jdk-16.html" title="SecretKeyFactory is broken in JDK 1.6 update 22" /><author><name>Roy</name><uri>http://www.blogger.com/profile/00633074227808113222</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><feedburner:origLink>http://royontechnology.blogspot.com/2010/10/secretkeyfactory-is-broken-in-jdk-16.html</feedburner:origLink></entry><entry gd:etag="W/&quot;C0QHQn4ycSp7ImA9Wx5UE00.&quot;"><id>tag:blogger.com,1999:blog-3102468434043486639.post-2466651361251180572</id><published>2010-10-16T12:14:00.000-07:00</published><updated>2010-10-17T00:42:13.099-07:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2010-10-17T00:42:13.099-07:00</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="Java" /><category scheme="http://www.blogger.com/atom/ns#" term="Performance Tuning" /><title>Performance of BigInteger.toString(radix)</title><content type="html">&lt;b&gt;Problem:&lt;/b&gt; &lt;br /&gt;
You are given a byte array, that represents a number in big endian format (the most significant byte first). You have to convert the byte array to its equivalent hex string. What is the most efficient way to do it?&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;Solution:&lt;/b&gt;&lt;br /&gt;
There are many ways to do it. But let us start with the easiest and correct one and optimize our solution. BigInteger class provides a constructor to convert the byte array to a BigInteger. We can convert that BigInteger to a hex string using the BigInteger.toString(radix) method. The solution is given below:&lt;br /&gt;
&lt;pre style="font-family: Andale Mono, Lucida Console, Monaco, fixed, monospace; color: #000000; background-color: #eee;font-size: 12px;border: 1px dashed #999999;line-height: 14px;padding: 5px; overflow: auto; width: 100%"&gt;&lt;code&gt;public static final String toHexStringUsingBigInteger(byte[] input) {
        BigInteger bi = new BigInteger(input);
        return bi.toString(16);
    }
&lt;/code&gt;&lt;/pre&gt;&lt;br /&gt;
We can also come up with a hand crafted solution that extract nibble by nibble and convert them into their equivalent hex character and finally forming a string. This solution is given below:&lt;br /&gt;
&lt;pre style="font-family: Andale Mono, Lucida Console, Monaco, fixed, monospace; color: #000000; background-color: #eee;font-size: 12px;border: 1px dashed #999999;line-height: 14px;padding: 5px; overflow: auto; width: 100%"&gt;&lt;code&gt;public static final String toHexStringUsingCharArray(byte input[]) {
        int i = 0;
        if (input == null &amp;#124;&amp;#124; input.length &amp;lt;= 0)
            return null;

        char lookupArray[] = { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f' };
        char[] result = new char[input.length * 2];

        while (i &amp;lt; input.length) {
            result[2*i] = lookupArray[(input[i]&amp;gt;&amp;gt;4) &amp;amp; 0x0F];
            result[2*i+1] = lookupArray[(input[i] &amp;amp; 0x0F)];
            i++;
        }
        return String.valueOf(result);
    }
&lt;/code&gt;&lt;/pre&gt;&lt;br /&gt;
For comparison purposes, let us write a test program and see how much time each implementation takes. The test program is given below:&lt;br /&gt;
&lt;pre style="font-family: Andale Mono, Lucida Console, Monaco, fixed, monospace; color: #000000; background-color: #eee;font-size: 12px;border: 1px dashed #999999;line-height: 14px;padding: 5px; overflow: auto; width: 100%"&gt;&lt;code&gt;public static void main(String[] args) {
        byte[] input = new byte[]{0x7D, 0x7D, 0x7D, 0x7D, 0x7D, 0x7D, 0x7D, 0x7D};
        long start = System.nanoTime();
        for(int i = 0; i &amp;lt; 100000; i++) toHexStringUsingBigInteger(input);
        long end = System.nanoTime();
        
        long start2 = System.nanoTime();
        for(int i = 0; i &amp;lt; 100000; i++) toHexStringUsingCharArray(input);
        long end2 = System.nanoTime();
        
        System.out.println(String.format(&amp;quot;Using BigInteger  : %15d&amp;quot;, (end-start)));
        System.out.println(String.format(&amp;quot;Using char array  : %15d&amp;quot;, (end2-start2)));
    }
&lt;/code&gt;&lt;/pre&gt;&lt;br /&gt;
Here is the output of few runs of the program:&lt;br /&gt;
&lt;pre style="font-family: Andale Mono, Lucida Console, Monaco, fixed, monospace; color: #000000; background-color: #eee;font-size: 12px;border: 1px dashed #999999;line-height: 14px;padding: 5px; overflow: auto; width: 100%"&gt;&lt;code&gt;Using BigInteger  :       702013524
Using char array  :        42074621
Using BigInteger  :       711340129
Using char array  :        41369504
Using BigInteger  :       707484052
Using char array  :        41221440
&lt;/code&gt;&lt;/pre&gt;&lt;br /&gt;
WOW! You see the difference between the BigInteger version and the hand crafted version? &lt;b&gt;Hand crafted version is almost 16 times faster&lt;/b&gt;. Why?&lt;br /&gt;
&lt;br /&gt;
You can take a look at how BigInteger.toString(radix) is implemented in the &lt;a href="http://www.docjar.com/html/api/java/math/BigInteger.java.html"&gt;OpenJDK here&lt;/a&gt;. The most important point is, it is making use of Conversion.bigInteger2String() method. You can view the source code of that &lt;a href="http://www.docjar.com/html/api/java/math/Conversion.java.html"&gt;here&lt;/a&gt;. Ultimately, bigInteger2String() method is written such a way that it can cater to different radices and different locales. Most of the complexity in that function is around this concern. That is the reason why BigInteger.toString(radix) is terrible in performance.&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;Moral of the story:&lt;/b&gt; &lt;br /&gt;
If you are planning to use BigInteger and convert that back and forth to hex string, you are better off writing your own version of toHexString as the one given above, instead of using what you get with the library. You can invoke the BigInteger.toByteArray() and pass the byte array to your toHexString method.&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;Most important caveats:&lt;/b&gt;&lt;br /&gt;
Beware of handling of negative numbers between the two approaches. In case of the second approach, you will not get the sign right. You will always get a hex string for the bytes given as argument, without any special interpretation of the bytes. Where as, the BigInteger approach treats the bytes as &lt;b&gt;a signed integer value&lt;/b&gt;. Consider the following test program:&lt;br /&gt;
&lt;pre style="font-family: Andale Mono, Lucida Console, Monaco, fixed, monospace; color: #000000; background-color: #eee;font-size: 12px;border: 1px dashed #999999;line-height: 14px;padding: 5px; overflow: auto; width: 100%"&gt;&lt;code&gt;public static void main(String[] args) {
        byte[] input = new byte[]{(byte)0x8D};
        System.out.println(&amp;quot;From BigInteger : &amp;quot; + toHexStringUsingBigInteger(input));
        System.out.println(&amp;quot;From char array : &amp;quot; + toHexStringUsingCharArray(input));
    }
&lt;/code&gt;&lt;/pre&gt;&lt;br /&gt;
And the output is:&lt;br /&gt;
&lt;pre style="font-family: Andale Mono, Lucida Console, Monaco, fixed, monospace; color: #000000; background-color: #eee;font-size: 12px;border: 1px dashed #999999;line-height: 14px;padding: 5px; overflow: auto; width: 100%"&gt;&lt;code&gt;From BigInteger : -73
From char array : 8d
&lt;/code&gt;&lt;/pre&gt;&lt;br /&gt;
Depending on your application, you will have to choose one usage over the other.&lt;br /&gt;
&lt;br /&gt;
The other important thing is that the code given above doesn't skip the leading zeroes. You can make a small modification and make it to skip leading zero bytes.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3102468434043486639-2466651361251180572?l=royontechnology.blogspot.com' alt='' /&gt;&lt;/div&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/Nj8yYBXMVfhM6PJQEMXU2GzxTMU/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/Nj8yYBXMVfhM6PJQEMXU2GzxTMU/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/Nj8yYBXMVfhM6PJQEMXU2GzxTMU/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/Nj8yYBXMVfhM6PJQEMXU2GzxTMU/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/RoysMusings/~4/B957xYVr2D0" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://royontechnology.blogspot.com/feeds/2466651361251180572/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://www.blogger.com/comment.g?blogID=3102468434043486639&amp;postID=2466651361251180572" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/3102468434043486639/posts/default/2466651361251180572?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/3102468434043486639/posts/default/2466651361251180572?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/RoysMusings/~3/B957xYVr2D0/performance-of-bigintegertostringradix.html" title="Performance of BigInteger.toString(radix)" /><author><name>Roy</name><uri>http://www.blogger.com/profile/00633074227808113222</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><feedburner:origLink>http://royontechnology.blogspot.com/2010/10/performance-of-bigintegertostringradix.html</feedburner:origLink></entry><entry gd:etag="W/&quot;CkYHQnw8eyp7ImA9Wx5UEEU.&quot;"><id>tag:blogger.com,1999:blog-3102468434043486639.post-5447370285446492548</id><published>2010-10-14T10:33:00.000-07:00</published><updated>2010-10-14T11:15:33.273-07:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2010-10-14T11:15:33.273-07:00</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="Java" /><category scheme="http://www.blogger.com/atom/ns#" term="Java SE 6" /><title>Issue of autoboxing and reflection</title><content type="html">Problem: Consider that you want to have a method called "Object invokeAndGet(Object targetObject, String methodName, Object... args)". This method should be able to invoke the given method on the target object and return the value returned by the invocation. If the method has overloaded forms, then depending on the argument types, the invokeAndGet method should invoke the correct form. &lt;br /&gt;
&lt;br /&gt;
Solution: &lt;br /&gt;
Though this problem looks trivial and seems like it can be solved by using reflections APIs, it gets really tricky when you have to deal with primitive types. This is due to the fact that autoboxing converts the primitives into their corresponding wrapper types. For e.g. an integer value is autoboxed into Integer object, etc. &lt;br /&gt;
&lt;br /&gt;
To begin with let us assume that we have the following implementation of the method:&lt;br /&gt;
&lt;br /&gt;
&lt;pre style="font-family: Andale Mono, Lucida Console, Monaco, fixed, monospace; color: #000000; background-color: #eee;font-size: 12px;border: 1px dashed #999999;line-height: 14px;padding: 5px; overflow: auto; width: 100%"&gt;&lt;code&gt;    public static Object invokeAndGet(Object obj, String methodName, Object... args) {
        try {
            Class&amp;lt;?&amp;gt;[] argsTypes = new Class[args.length];
            for(int i = 0; i &amp;lt; argsTypes.length; i++) {
                argsTypes[i] = args[i].getClass();
            }
            Method m = obj.getClass().getMethod(methodName, argsTypes);
            Object retObj = m.invoke(obj, args);
            return retObj;
        } catch (Exception e) {
            System.out.println(&amp;quot;**** Exception thrown: &amp;quot; + e);
            return null;
        }
    }
&lt;/code&gt;&lt;/pre&gt;&lt;br /&gt;
What this code is straight forward. It gets the types of the arguments. Attempts to find out if the target object's class has any method matching the method name and the argument types. If one is found, then that method is invoked. Otherwise null is returned.&lt;br /&gt;
&lt;br /&gt;
The tricky part is this. Assume that the target object's class has a method "void setX(int x)". If you attempt to do invokeAndGet(targetObject, "setX", 1), it will fail. The reason is because of the fact that the argument 1 is converted to its wrapper type, which is Integer. So when you look up, you are looking up for the method with the signature "setX(Integer)", where as the method that is present in the target object has the signature "setX(int)". &lt;br /&gt;
&lt;br /&gt;
There is no bullet proof solution for this problem. One of the ways you can try to solve this issue is by retrying with primitive types when you get a NoSuchMethodException. The modified version of the code is given below. It works for most of the cases:&lt;br /&gt;
&lt;pre style="font-family: Andale Mono, Lucida Console, Monaco, fixed, monospace; color: #000000; background-color: #eee;font-size: 12px;border: 1px dashed #999999;line-height: 14px;padding: 5px; overflow: auto; width: 100%"&gt;&lt;code&gt;    public static Object invokeAndGet(Object obj, String methodName, Object... args) {
        try {
            Class&amp;lt;?&amp;gt;[] argsTypes = new Class[args.length];
            for(int i = 0; i &amp;lt; argsTypes.length; i++) {
                argsTypes[i] = args[i].getClass();
            }
            Method m = null;
            try {
                m = obj.getClass().getMethod(methodName, argsTypes);
            } catch (NoSuchMethodException nsme) {
                boolean signatureModified = false;
                for(int i = 0; i &amp;lt; argsTypes.length; i++) {
                    Field field;
                    try {
                        field = argsTypes[i].getField(&amp;quot;TYPE&amp;quot;);
                        if(Modifier.isStatic(field.getModifiers())) {
                            argsTypes[i] = (Class&amp;lt;?&amp;gt;) field.get(null);
                            signatureModified = true;
                        }
                    } catch (Exception e) {
                        // Ignore these exceptions. There is nothing we can do by catching them.
                    }
                }
                if(signatureModified)
                    m = obj.getClass().getMethod(methodName, argsTypes);
            }
            Object retObj = null;
            if(m != null)
                retObj = m.invoke(obj, args);
            return retObj;
        } catch (Exception e) {
            System.out.println(&amp;quot;*** Exception thrown: &amp;quot; + e);
            return null;
        }
    }    

&lt;/code&gt;&lt;/pre&gt;&lt;br /&gt;
What I am doing is very simple. Whenever NoSuchMethodException is thrown, I convert all the wrapper classes to their respective primitive classes by accessing the "TYPE" static field in them. For e.g. Integer.TYPE will give me int.class. Then I retry to get the new method, if I the signature had been modified since the last attempt. &lt;br /&gt;
&lt;br /&gt;
I said that almost works. Here are the corner cases:&lt;br /&gt;
1) If your method has mixed type arguments, some of them are primitives and some of them are wrappers, the code given above will not work. For e.g. if you have a method with signature "setXIf(int oldValue, Integer newValue)", then invokeAndGet(targetObject, "setXIf", 1, 2) will fail.&lt;br /&gt;
2) There is a remote case when one of the argument class has a field called TYPE which is of type Class&lt;?&gt;. In such cases also the above code will fail.&lt;br /&gt;
&lt;br /&gt;
Please let me know if you know of a better method than the one given above to reflectively invoke a method on an object. I will appreciate that.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3102468434043486639-5447370285446492548?l=royontechnology.blogspot.com' alt='' /&gt;&lt;/div&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/qOcDX_JNpLLhpHnOFBzXpaaj054/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/qOcDX_JNpLLhpHnOFBzXpaaj054/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/qOcDX_JNpLLhpHnOFBzXpaaj054/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/qOcDX_JNpLLhpHnOFBzXpaaj054/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/RoysMusings/~4/sIBcEmI5QOU" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://royontechnology.blogspot.com/feeds/5447370285446492548/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://www.blogger.com/comment.g?blogID=3102468434043486639&amp;postID=5447370285446492548" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/3102468434043486639/posts/default/5447370285446492548?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/3102468434043486639/posts/default/5447370285446492548?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/RoysMusings/~3/sIBcEmI5QOU/issue-of-autoboxing-and-reflection.html" title="Issue of autoboxing and reflection" /><author><name>Roy</name><uri>http://www.blogger.com/profile/00633074227808113222</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><feedburner:origLink>http://royontechnology.blogspot.com/2010/10/issue-of-autoboxing-and-reflection.html</feedburner:origLink></entry><entry gd:etag="W/&quot;CEQNSXs5cSp7ImA9Wx5VGUg.&quot;"><id>tag:blogger.com,1999:blog-3102468434043486639.post-6344282528208873708</id><published>2010-10-12T23:41:00.000-07:00</published><updated>2010-10-12T23:46:38.529-07:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2010-10-12T23:46:38.529-07:00</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="Java" /><title>Creating a HashMap with entries</title><content type="html">Problem: Create an instance of HashMap in Java with entries in it. I don't want to create a new HashMap instance and keep adding entries to it. I want to have a concise way of creating a HashMap with entries.&lt;br /&gt;
&lt;br /&gt;
Solution: Guava library comes with factory methods that can create a HashMap without using the verbose form of "Map&lt;keytype, vlauetype=""&gt; myMap = new HashMap&lt;keytype, valuetype=""&gt;()". You can simply say "Map&lt;keytype, valuetype=""&gt; myMap = newHashMap()", assuming you have done a static import of the Maps.newHashMap method. But that is not sufficient. It would be better to provide a utility method that looks like this: "Map&lt;keytype, vlauetype=""&gt; myMap = newHashMapWithEntries(firstKey, firstValue, secondKey, secondValue)". That way it is easy to create static-final maps instead of writing a separate method to populate them or to populate them from&amp;nbsp;constructor, as given below:&lt;/keytype,&gt;&lt;/keytype,&gt;&lt;/keytype,&gt;&lt;/keytype,&gt;&lt;br /&gt;
&lt;pre style="background-color: #eeeeee; border: 1px dashed #999999; color: black; font-family: Andale Mono, Lucida Console, Monaco, fixed, monospace; font-size: 12px; line-height: 14px; overflow: auto; padding: 5px; width: 100%;"&gt;&lt;code&gt;public class MyClass { 
&amp;nbsp;&amp;nbsp; private static final Map&amp;lt;String, URL&amp;gt; serviceUrls = createServiceUrlsMap(); 
&amp;nbsp;&amp;nbsp; private static Map&amp;lt;String, String&amp;gt; createServiceUrlsMap() { 
&amp;nbsp;&amp;nbsp; &amp;nbsp;Map&amp;lt;String, URL&amp;gt; retVal = new HashMap&amp;lt;String, URL&amp;gt;(); 
&amp;nbsp;&amp;nbsp; &amp;nbsp;retVal.put("google", new URL("http://www.google.com"); 
&amp;nbsp;&amp;nbsp; &amp;nbsp;retVal.put("yahoo", new URL("http://www.yahoo.com"); 
&amp;nbsp;&amp;nbsp; &amp;nbsp;return retVal; 
&amp;nbsp;&amp;nbsp; } 
&amp;nbsp;}&amp;nbsp;&lt;/code&gt;&lt;/pre&gt;&lt;br /&gt;
&lt;br /&gt;
That is too verbose. What I want is something like:&lt;br /&gt;
&lt;pre style="background-color: #eeeeee; border: 1px dashed #999999; color: black; font-family: Andale Mono, Lucida Console, Monaco, fixed, monospace; font-size: 12px; line-height: 14px; overflow: auto; padding: 5px; width: 100%;"&gt;&lt;code&gt;public class MyClass { 
&amp;nbsp;&amp;nbsp; private static final Map&amp;lt;String, URL&amp;gt; serviceUrls = newHashMapWithEntries( 
&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; "google", new URL("http://www.google.com"), 
&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; "yahoo", new URL("http://www.yahoo.com")); &amp;nbsp;
&amp;nbsp;}&lt;/code&gt;&lt;/pre&gt;&lt;br /&gt;
So here is one possible implementation of newHashMapWithEntries:&lt;br /&gt;
&lt;pre style="background-color: #eeeeee; border: 1px dashed #999999; color: black; font-family: Andale Mono, Lucida Console, Monaco, fixed, monospace; font-size: 12px; line-height: 14px; overflow: auto; padding: 5px; width: 100%;"&gt;&lt;code&gt; &amp;nbsp; &amp;nbsp;@SuppressWarnings("unchecked")
&amp;nbsp;&amp;nbsp; &amp;nbsp;public static &amp;lt;K, V&amp;gt; Map&amp;lt;K, V&amp;gt; newHashMapWithEntries(K firstKey, V firstValue, Object... rest) {
&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;if(rest.length%2 != 0) {
&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;throw new IllegalArgumentException("Expected the number of args to be even.");
&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;}
&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; 
&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Class&amp;lt;? extends Object&amp;gt; keyType = firstKey.getClass();
&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Class&amp;lt;? extends Object&amp;gt; valueType = firstValue.getClass();
&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Map&amp;lt;K, V&amp;gt; retVal = new HashMap&amp;lt;K, V&amp;gt;();
&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;retVal.put(firstKey, firstValue);
&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;for(int i = 0; i &amp;lt; rest.length; i += 2) {
&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;if(!keyType.isAssignableFrom(rest[i].getClass())) {
&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;throw new IllegalArgumentException("Expected all keys to be of type &amp;lt;? extends " +
&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;keyType.getName() + "&amp;gt;, but found " + rest[i].getClass().getName() + ".");
&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;}
&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;if(!valueType.isAssignableFrom(rest[i+1].getClass())) {
&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;throw new IllegalArgumentException("Expected all values to be of type &amp;lt;? extends " +
&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;valueType.getName() + "&amp;gt;, but found " + rest[i+1].getClass().getName() + ".");
&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;}
&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;retVal.put((K)rest[i], (V)rest[i+1]);
&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;}
&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;return retVal;
&amp;nbsp;&amp;nbsp; &amp;nbsp;}&lt;/code&gt;&lt;/pre&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3102468434043486639-6344282528208873708?l=royontechnology.blogspot.com' alt='' /&gt;&lt;/div&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/kIodokNAzFEHNr_E1KXaI8lbNyc/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/kIodokNAzFEHNr_E1KXaI8lbNyc/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/kIodokNAzFEHNr_E1KXaI8lbNyc/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/kIodokNAzFEHNr_E1KXaI8lbNyc/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/RoysMusings/~4/1EbQGTFeb1U" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://royontechnology.blogspot.com/feeds/6344282528208873708/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://www.blogger.com/comment.g?blogID=3102468434043486639&amp;postID=6344282528208873708" title="12 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/3102468434043486639/posts/default/6344282528208873708?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/3102468434043486639/posts/default/6344282528208873708?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/RoysMusings/~3/1EbQGTFeb1U/creating-hashmap-with-entries.html" title="Creating a HashMap with entries" /><author><name>Roy</name><uri>http://www.blogger.com/profile/00633074227808113222</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>12</thr:total><feedburner:origLink>http://royontechnology.blogspot.com/2010/10/creating-hashmap-with-entries.html</feedburner:origLink></entry><entry gd:etag="W/&quot;D0YDQXwyfyp7ImA9Wx5VFks.&quot;"><id>tag:blogger.com,1999:blog-3102468434043486639.post-2915900001225898225</id><published>2010-10-09T15:52:00.001-07:00</published><updated>2010-10-09T15:59:30.297-07:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2010-10-09T15:59:30.297-07:00</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="Python" /><title>Bottle - A simple web framework in Python</title><content type="html">I recently came across the &lt;a href="http://bottle.paws.de/docs/dev/index.html"&gt;Bottle&lt;/a&gt;. It is a web framework written in Python. Its very simple to learn and use. It is ideal for prototyping kind of work or you want to run a web application in no time.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3102468434043486639-2915900001225898225?l=royontechnology.blogspot.com' alt='' /&gt;&lt;/div&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/mvXGzH_urGaI1MYMwAtzmnpR9K8/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/mvXGzH_urGaI1MYMwAtzmnpR9K8/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/mvXGzH_urGaI1MYMwAtzmnpR9K8/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/mvXGzH_urGaI1MYMwAtzmnpR9K8/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/RoysMusings/~4/wCKTiXI2Y7I" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://royontechnology.blogspot.com/feeds/2915900001225898225/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://www.blogger.com/comment.g?blogID=3102468434043486639&amp;postID=2915900001225898225" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/3102468434043486639/posts/default/2915900001225898225?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/3102468434043486639/posts/default/2915900001225898225?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/RoysMusings/~3/wCKTiXI2Y7I/bottle-simple-web-framework-in-python.html" title="Bottle - A simple web framework in Python" /><author><name>Roy</name><uri>http://www.blogger.com/profile/00633074227808113222</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><feedburner:origLink>http://royontechnology.blogspot.com/2010/10/bottle-simple-web-framework-in-python.html</feedburner:origLink></entry><entry gd:etag="W/&quot;CEYBQngzfCp7ImA9Wx5WFU8.&quot;"><id>tag:blogger.com,1999:blog-3102468434043486639.post-8286145848143041257</id><published>2010-09-26T10:29:00.000-07:00</published><updated>2010-09-26T10:29:13.684-07:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2010-09-26T10:29:13.684-07:00</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="Java" /><category scheme="http://www.blogger.com/atom/ns#" term="Linux" /><category scheme="http://www.blogger.com/atom/ns#" term="Kernel" /><title>Understanding Java Memory Model</title><content type="html">I was browsing through the Linux kernel documentation and came across &lt;a href="http://lxr.linux.no/#linux+v2.6.35.5/Documentation/memory-barriers.txt"&gt;this excellent documentation on Memory Barriers&lt;/a&gt;. I was able to relate many of the concepts explained in this document with the issues that used to exist in the older buggy JVMs. I would strongly recommend to anyone to go through &lt;a href="http://lxr.linux.no/#linux+v2.6.35.5/Documentation/memory-barriers.txt"&gt;this kernel document &lt;/a&gt;to easily understand the 1.5+ Java Memory Model, especially the concept of happens-before ordering. The same author has written another excellent paper &lt;a href="http://www.rdrop.com/users/paulmck/scalability/paper/whymb.2009.04.05a.pdf"&gt;"Memory Barriers: a Hardware View for Software Hackers"&lt;/a&gt;, which covers the same topic in a bit more depth.&lt;br /&gt;
&lt;br /&gt;
Paul McKenney and David Howells - thanks a lot for your excellent document that helped me understand the key concepts behind memory barriers.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3102468434043486639-8286145848143041257?l=royontechnology.blogspot.com' alt='' /&gt;&lt;/div&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/SmAqjYwuhmrLMPdFZVIqU3O1SvE/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/SmAqjYwuhmrLMPdFZVIqU3O1SvE/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/SmAqjYwuhmrLMPdFZVIqU3O1SvE/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/SmAqjYwuhmrLMPdFZVIqU3O1SvE/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/RoysMusings/~4/dyaWXc9A6bY" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://royontechnology.blogspot.com/feeds/8286145848143041257/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://www.blogger.com/comment.g?blogID=3102468434043486639&amp;postID=8286145848143041257" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/3102468434043486639/posts/default/8286145848143041257?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/3102468434043486639/posts/default/8286145848143041257?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/RoysMusings/~3/dyaWXc9A6bY/understanding-java-memory-model.html" title="Understanding Java Memory Model" /><author><name>Roy</name><uri>http://www.blogger.com/profile/00633074227808113222</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><feedburner:origLink>http://royontechnology.blogspot.com/2010/09/understanding-java-memory-model.html</feedburner:origLink></entry><entry gd:etag="W/&quot;Dk8FRnc6cSp7ImA9Wx5SFU0.&quot;"><id>tag:blogger.com,1999:blog-3102468434043486639.post-2477322821761499249</id><published>2010-08-10T21:56:00.000-07:00</published><updated>2010-08-10T22:33:37.919-07:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2010-08-10T22:33:37.919-07:00</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="Java" /><category scheme="http://www.blogger.com/atom/ns#" term="C++" /><title>Is Java getting more and more complex</title><content type="html">Recently I read an article in &lt;a href="http://www.artima.com/weblogs/viewpost.jsp?thread=299081"&gt;Artima&lt;/a&gt;, titled "Have Generics Killed Java?". This article is not the first one to complain about the complexities introduced into Java due to Generics. I used to a C++ programmer for around 6 years and been a big fan of the language. When I switched to using Java, during the pre-Generics era, I simply loved the simplicity and lucidness of Java. After reading the section on Generics in Effective Java, and having learnt the IFs and BUTs of the Generics, I realized how many things one has to remember to make effective use of Generics.&lt;br /&gt;
&lt;br /&gt;
I rememberd &lt;a href="http://www2.research.att.com/%7Ebs/bs_faq.html#Java"&gt;an answer given by Bjarne Stroustrup&lt;/a&gt;, the creator of C++, a few years before the introduction of Generics. The gist if his answer was that every language commercially successful and used in large scale follows exactly the same path C++ and (now) Java is following. That is to start simple and eventually getting more and more complex.&lt;br /&gt;
&lt;br /&gt;
After reading the &lt;a href="http://www2.research.att.com/%7Ebs/C++0xFAQ.html"&gt;FAQ for C++0X&lt;/a&gt; and some of the modules in Boost library, I now feel that C++ is conquering complexity, especially concurrent programming, using some elegant abstractions. Despite the attempt to conquer complexity, I personally feel that C++0X has too many things to remember :-(&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3102468434043486639-2477322821761499249?l=royontechnology.blogspot.com' alt='' /&gt;&lt;/div&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/biu8FJwlwdpa5fAHr11j3o4U2A8/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/biu8FJwlwdpa5fAHr11j3o4U2A8/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/biu8FJwlwdpa5fAHr11j3o4U2A8/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/biu8FJwlwdpa5fAHr11j3o4U2A8/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/RoysMusings/~4/A-OybgrQTAs" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://royontechnology.blogspot.com/feeds/2477322821761499249/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://www.blogger.com/comment.g?blogID=3102468434043486639&amp;postID=2477322821761499249" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/3102468434043486639/posts/default/2477322821761499249?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/3102468434043486639/posts/default/2477322821761499249?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/RoysMusings/~3/A-OybgrQTAs/is-java-getting-more-and-more-complex.html" title="Is Java getting more and more complex" /><author><name>Roy</name><uri>http://www.blogger.com/profile/00633074227808113222</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><feedburner:origLink>http://royontechnology.blogspot.com/2010/08/is-java-getting-more-and-more-complex.html</feedburner:origLink></entry><entry gd:etag="W/&quot;DkIAQn05cSp7ImA9Wx5SEk0.&quot;"><id>tag:blogger.com,1999:blog-3102468434043486639.post-7952561366414197120</id><published>2010-08-07T11:09:00.000-07:00</published><updated>2010-08-07T11:09:03.329-07:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2010-08-07T11:09:03.329-07:00</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="EasyMock" /><category scheme="http://www.blogger.com/atom/ns#" term="JUnit" /><title>FEST libraries - a useful set of tools for testing</title><content type="html">I came across &lt;a href="http://piotrjagielski.com/blog/a-cool-technique-for-object-comparison-in-junit/"&gt;an article&lt;/a&gt; in DZone.com that talked about the &lt;a href="http://fest.easytesting.org/wiki/pmwiki.php"&gt;FEST libraries&lt;/a&gt;. I felt I should have known about the FEST libraries a earlier. They are pretty powerful in terms of expressing test cases in a human readable form. In FEST site itself I found a link to&lt;a href="http://www.infoq.com/articles/internal-dsls-java"&gt; internal DSLs in Java &lt;/a&gt;which was quite an interesting reading.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3102468434043486639-7952561366414197120?l=royontechnology.blogspot.com' alt='' /&gt;&lt;/div&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/EqZAdAQgX_eC9doDYt1wigjjYhA/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/EqZAdAQgX_eC9doDYt1wigjjYhA/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/EqZAdAQgX_eC9doDYt1wigjjYhA/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/EqZAdAQgX_eC9doDYt1wigjjYhA/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/RoysMusings/~4/FsFVc1ssR6g" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://royontechnology.blogspot.com/feeds/7952561366414197120/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://www.blogger.com/comment.g?blogID=3102468434043486639&amp;postID=7952561366414197120" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/3102468434043486639/posts/default/7952561366414197120?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/3102468434043486639/posts/default/7952561366414197120?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/RoysMusings/~3/FsFVc1ssR6g/fest-libraries-useful-set-of-tools-for.html" title="FEST libraries - a useful set of tools for testing" /><author><name>Roy</name><uri>http://www.blogger.com/profile/00633074227808113222</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><feedburner:origLink>http://royontechnology.blogspot.com/2010/08/fest-libraries-useful-set-of-tools-for.html</feedburner:origLink></entry><entry gd:etag="W/&quot;C0MCR30zeyp7ImA9Wx5SEU4.&quot;"><id>tag:blogger.com,1999:blog-3102468434043486639.post-5996852881978135061</id><published>2010-08-06T14:51:00.000-07:00</published><updated>2010-08-06T14:51:06.383-07:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2010-08-06T14:51:06.383-07:00</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="Eclipse" /><category scheme="http://www.blogger.com/atom/ns#" term="Tomcat" /><category scheme="http://www.blogger.com/atom/ns#" term="WTP" /><title>Eclipse Helios JEE and Tomcat issue</title><content type="html">I installed the latest Eclipse Helios JEE package. Every time when I try to start my Tomcat instance, I started getting 100% CPU and an non-responsive Eclipse. I figured out that this was an issue with the WTP that comes by default with the Eclipse package (which I think is 3.2.0) and this issue was fixed with WTP version 3.2.1. If you try to update this package by using "Help-&amp;gt;Check For Updates" it won't update. So here is how you can update:&lt;br /&gt;
&lt;ol&gt;&lt;li&gt;Go to "Help-&amp;gt;Install New Software".&lt;/li&gt;
&lt;li&gt;In the "Work with:" input box, give the URL "http://download.eclipse.org/webtools/repository/helios/".&lt;/li&gt;
&lt;li&gt;Wait for all the package information to be downloaded and select "Web Tools Platform (WTP) 3.2.1" option. If you are planning to use any other package, you can select them. But make sure you select the ones from 3.2.1 version distribution.&lt;/li&gt;
&lt;li&gt;Click on Next and follow the prompt to complete installation.&amp;nbsp;&lt;/li&gt;
&lt;/ol&gt;If you restart Eclipse, you should be fine. You should no longer see any 100% CPU issues.&lt;br /&gt;
&lt;br /&gt;
If you are interested in knowing more about the issue, please &lt;a href="https://bugs.eclipse.org/bugs/show_bug.cgi?id=317852"&gt;refer here&lt;/a&gt;.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3102468434043486639-5996852881978135061?l=royontechnology.blogspot.com' alt='' /&gt;&lt;/div&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/YRmsK9PyxaOvd8cZ18ZZVz5GEJk/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/YRmsK9PyxaOvd8cZ18ZZVz5GEJk/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/YRmsK9PyxaOvd8cZ18ZZVz5GEJk/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/YRmsK9PyxaOvd8cZ18ZZVz5GEJk/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/RoysMusings/~4/4sxyASePZ9E" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://royontechnology.blogspot.com/feeds/5996852881978135061/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://www.blogger.com/comment.g?blogID=3102468434043486639&amp;postID=5996852881978135061" title="2 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/3102468434043486639/posts/default/5996852881978135061?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/3102468434043486639/posts/default/5996852881978135061?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/RoysMusings/~3/4sxyASePZ9E/eclipse-helios-jee-and-tomcat-issue.html" title="Eclipse Helios JEE and Tomcat issue" /><author><name>Roy</name><uri>http://www.blogger.com/profile/00633074227808113222</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><feedburner:origLink>http://royontechnology.blogspot.com/2010/08/eclipse-helios-jee-and-tomcat-issue.html</feedburner:origLink></entry><entry gd:etag="W/&quot;C08GRXw9fSp7ImA9Wx5TGEw.&quot;"><id>tag:blogger.com,1999:blog-3102468434043486639.post-1392457584163586038</id><published>2010-08-02T22:03:00.000-07:00</published><updated>2010-08-02T22:03:44.265-07:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2010-08-02T22:03:44.265-07:00</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="Java" /><category scheme="http://www.blogger.com/atom/ns#" term="Spring" /><category scheme="http://www.blogger.com/atom/ns#" term="Java SE 6" /><title>Cobertura and Spring auto proxying</title><content type="html">If you are using Cobertrua to get coverage reports, you may run into the error message shown below (lines folded for clarity):&lt;br /&gt;
&lt;blockquote&gt;&lt;span style="font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;"&gt;Caused by: org.springframework.beans.factory.BeanCreationException: &lt;/span&gt;&lt;br style="font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;" /&gt;&lt;span style="font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;"&gt;Error creating bean with name 'myBean' defined in ServletContext resource [/WEB-INF/applicationContext.xml]: Initialization of bean failed; &lt;/span&gt;&lt;br style="font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;" /&gt;&lt;span style="font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;"&gt;nested exception is org.springframework.beans.ConversionNotSupportedException: Failed to convert property value of type &lt;/span&gt;&lt;br style="font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;" /&gt;&lt;span style="font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;"&gt;'$Proxy28 implementing net.sourceforge.cobertura.coveragedata.HasBeenInstrumented, org.springframework.aop.SpringProxy,&lt;/span&gt; &lt;span style="font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;"&gt;org.springframework.aop.framework.Advised' to required type 'com.mydomain.MyDao' for property 'myDao'; &lt;/span&gt;&lt;br style="font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;" /&gt;&lt;span style="font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;"&gt;nested exception is java.lang.IllegalStateException: Cannot convert value of type &lt;/span&gt;&lt;br style="font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;" /&gt;&lt;span style="font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;"&gt;[$Proxy28 implementing net.sourceforge.cobertura.coveragedata.HasBeenInstrumented, org.springframework.aop.SpringProxy,&lt;/span&gt; &lt;span style="font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;"&gt;org.springframework.aop.framework.Advised] to required type [com.mydomain.MyDao] &lt;/span&gt;&lt;br style="font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;" /&gt;&lt;span style="font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;"&gt;for property 'myDao': no matching editors or conversion strategy found&lt;/span&gt; &lt;/blockquote&gt;&amp;nbsp;Specifically if you are using AspectJ auto proxying, like below:&lt;br /&gt;
&lt;blockquote&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;context:annotation-config/&amp;gt;&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;aop:aspectj-autoproxy/&amp;gt;&lt;/blockquote&gt;&amp;nbsp;To fix the issue, just add the following property:&lt;br /&gt;
&lt;br /&gt;
&lt;blockquote&gt;   &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;context:annotation-config/&amp;gt;&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;aop:aspectj-autoproxy &lt;b&gt;proxy-target-class="true"&lt;/b&gt; /&amp;gt;&lt;/blockquote&gt;That should fix the exception shown above. To know more about this property please refer to &lt;a href="http://static.springsource.org/spring/docs/3.0.x/spring-framework-reference/html/aop.html"&gt;Spring documentation&lt;/a&gt;.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3102468434043486639-1392457584163586038?l=royontechnology.blogspot.com' alt='' /&gt;&lt;/div&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/0pwhJt0hUqUMjl18Lg6YeA7NXYc/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/0pwhJt0hUqUMjl18Lg6YeA7NXYc/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/0pwhJt0hUqUMjl18Lg6YeA7NXYc/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/0pwhJt0hUqUMjl18Lg6YeA7NXYc/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/RoysMusings/~4/8itKL2WRwIk" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://royontechnology.blogspot.com/feeds/1392457584163586038/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://www.blogger.com/comment.g?blogID=3102468434043486639&amp;postID=1392457584163586038" title="4 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/3102468434043486639/posts/default/1392457584163586038?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/3102468434043486639/posts/default/1392457584163586038?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/RoysMusings/~3/8itKL2WRwIk/cobertura-and-spring-auto-proxying.html" title="Cobertura and Spring auto proxying" /><author><name>Roy</name><uri>http://www.blogger.com/profile/00633074227808113222</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>4</thr:total><feedburner:origLink>http://royontechnology.blogspot.com/2010/08/cobertura-and-spring-auto-proxying.html</feedburner:origLink></entry><entry gd:etag="W/&quot;CEMCRn8_eCp7ImA9Wx5TGE0.&quot;"><id>tag:blogger.com,1999:blog-3102468434043486639.post-7164543431268721112</id><published>2010-08-02T19:27:00.000-07:00</published><updated>2010-08-02T19:27:47.140-07:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2010-08-02T19:27:47.140-07:00</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="Java" /><category scheme="http://www.blogger.com/atom/ns#" term="Debugging" /><category scheme="http://www.blogger.com/atom/ns#" term="Java SE 6" /><title>Bean properties printer - a useful debugging tool</title><content type="html">There are many instances when I wanted to just log the properties of a given object (most of the time its a bean). This will be useful in two ways: 1) learn about the concrete type of the object 2) serves as a good learning aid to understand what are all the properties that can be get/set in that object. Of course, if you have the documentation and the source code for the class in question, that would be the ultimate aid.&lt;br /&gt;
&lt;br /&gt;
Nevertheless, the following piece of code would be useful to print the properties of the given object/bean, using the getter methods that are available in the object.&lt;br /&gt;
&lt;blockquote&gt;&lt;span style="font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; public static void printProperties(String msg, Object o) {&lt;/span&gt;&lt;br /&gt;
&lt;span style="font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; String className = o.getClass().getName();&lt;/span&gt;&lt;br /&gt;
&lt;span style="font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; if(msg != null &amp;amp;&amp;amp; msg.length() &amp;gt; 0)&lt;/span&gt;&lt;br /&gt;
&lt;span style="font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; logger.info("{} (type {})", msg, className);&lt;/span&gt;&lt;br /&gt;
&lt;span style="font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; Method[] methods = o.getClass().getMethods();&lt;/span&gt;&lt;br /&gt;
&lt;span style="font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; for(Method m:methods) {&lt;/span&gt;&lt;br /&gt;
&lt;span style="font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; if(m.getName().startsWith("get") &amp;amp;&amp;amp; m.getParameterTypes().length == 0) {&lt;/span&gt;&lt;br /&gt;
&lt;span style="font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; m.setAccessible(true);&lt;/span&gt;&lt;br /&gt;
&lt;span style="font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; try {&lt;/span&gt;&lt;br /&gt;
&lt;span style="font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; Object returnValue = m.invoke(o);&lt;/span&gt;&lt;br /&gt;
&lt;span style="font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; logger.info("&amp;nbsp; {} -&amp;gt; {} (type {})", toObjArr(m.getName(), returnValue, &lt;/span&gt;&lt;br /&gt;
&lt;span style="font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; m.getReturnType().getName()));&lt;/span&gt;&lt;br /&gt;
&lt;span style="font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; } catch (Exception e) {&lt;/span&gt;&lt;br /&gt;
&lt;span style="font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; logger.error("Exception thrown while invoking [{}]: {}", m.getName(), e);&lt;/span&gt;&lt;br /&gt;
&lt;span style="font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;/span&gt;&lt;br /&gt;
&lt;span style="font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;/span&gt;&lt;br /&gt;
&lt;span style="font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;/span&gt;&lt;br /&gt;
&lt;span style="font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;/span&gt;&lt;/blockquote&gt;You can view the source code of &lt;a href="http://royontechnology.blogspot.com/2010/07/logging-three-or-more-arguments-in.html"&gt;toObjArr() here&lt;/a&gt;. This method can be improved a bit. For e.g. methods starting with isXXX are not invoked in the code. Also, a recursive way of printing the properties (with an optional max depth) can be provided. &lt;br /&gt;
&lt;br /&gt;
A sample output could look like this:&lt;br /&gt;
&lt;span style="font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;"&gt;Contents of the SAML request (type org.opensaml.saml2.core.impl.AuthnRequestImpl)&lt;/span&gt;&lt;br /&gt;
&lt;span style="font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;"&gt;&amp;nbsp;&amp;nbsp; getSubject -&amp;gt; null (type org.opensaml.saml2.core.Subject)&lt;/span&gt;&lt;br /&gt;
&lt;span style="font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;"&gt;&amp;nbsp;&amp;nbsp; getOrderedChildren -&amp;gt; [org.opensaml.saml2.core.impl.IssuerImpl@15e14d9, org.opensaml.saml2.core.impl.ScopingImpl@1aacada] (type java.util.List)&lt;/span&gt;&lt;br /&gt;
&lt;span style="font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;"&gt;&amp;nbsp;&amp;nbsp; getConditions -&amp;gt; null (type org.opensaml.saml2.core.Conditions)&lt;/span&gt;&lt;br /&gt;
&lt;span style="font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;"&gt;&amp;nbsp;&amp;nbsp; getRequestedAuthnContext -&amp;gt; null (type org.opensaml.saml2.core.RequestedAuthnContext)&lt;/span&gt;&lt;br /&gt;
&lt;span style="font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;"&gt;&amp;nbsp;&amp;nbsp; getProtocolBinding -&amp;gt; urn:oasis:names:tc:SAML:2.0:bindings:HTTP-POST (type java.lang.String)&lt;/span&gt;&lt;br /&gt;
&lt;span style="font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;"&gt;&amp;nbsp;&amp;nbsp; getAssertionConsumerServiceIndex -&amp;gt; null (type java.lang.Integer)&lt;/span&gt;&lt;br /&gt;
&lt;span style="font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;"&gt;&amp;nbsp;&amp;nbsp; getAssertionConsumerServiceURL -&amp;gt; http://localhost:8080/mySP/resources/saml/SSO (type java.lang.String)&lt;/span&gt;&lt;br /&gt;
&lt;span style="font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;"&gt;&amp;nbsp;&amp;nbsp; getAttributeConsumingServiceIndex -&amp;gt; null (type java.lang.Integer)&lt;/span&gt;&lt;br /&gt;
&lt;span style="font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;"&gt;&amp;nbsp;&amp;nbsp; getProviderName -&amp;gt; null (type java.lang.String)&lt;/span&gt;&lt;br /&gt;
&lt;span style="font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;"&gt;&amp;nbsp;&amp;nbsp; getNameIDPolicy -&amp;gt; null (type org.opensaml.saml2.core.NameIDPolicy)&lt;/span&gt;&lt;br /&gt;
&lt;span style="font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;"&gt;&amp;nbsp;&amp;nbsp; getScoping -&amp;gt; org.opensaml.saml2.core.impl.ScopingImpl@1aacada (type org.opensaml.saml2.core.Scoping)&lt;/span&gt;&lt;br /&gt;
&lt;span style="font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;"&gt;&amp;nbsp;&amp;nbsp; getVersion -&amp;gt; 2.0 (type org.opensaml.common.SAMLVersion)&lt;/span&gt;&lt;br /&gt;
&lt;span style="font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;"&gt;&amp;nbsp;&amp;nbsp; getID -&amp;gt; a3hj688f209c170h433b6eh0h73e0j2 (type java.lang.String)&lt;/span&gt;&lt;br /&gt;
&lt;span style="font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;"&gt;&amp;nbsp;&amp;nbsp; getDestination -&amp;gt; http://localhost:8080/myapp/profile/SAML2/POST/SSO (type java.lang.String)&lt;/span&gt;&lt;br /&gt;
&lt;span style="font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;"&gt;&amp;nbsp;&amp;nbsp; getIssuer -&amp;gt; org.opensaml.saml2.core.impl.IssuerImpl@15e14d9 (type org.opensaml.saml2.core.Issuer)&lt;/span&gt;&lt;br /&gt;
&lt;span style="font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;"&gt;&amp;nbsp;&amp;nbsp; getIssueInstant -&amp;gt; 2010-08-02T18:37:33.528Z (type org.joda.time.DateTime)&lt;/span&gt;&lt;br /&gt;
&lt;span style="font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;"&gt;&amp;nbsp;&amp;nbsp; getSignatureReferenceID -&amp;gt; a3hj688f209c170h433b6eh0h73e0j2 (type java.lang.String)&lt;/span&gt;&lt;br /&gt;
&lt;span style="font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;"&gt;&amp;nbsp;&amp;nbsp; getConsent -&amp;gt; null (type java.lang.String)&lt;/span&gt;&lt;br /&gt;
&lt;span style="font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;"&gt;&amp;nbsp;&amp;nbsp; getExtensions -&amp;gt; null (type org.opensaml.saml2.common.Extensions)&lt;/span&gt;&lt;br /&gt;
&lt;span style="font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;"&gt;&amp;nbsp;&amp;nbsp; getValidators -&amp;gt; null (type java.util.List)&lt;/span&gt;&lt;br /&gt;
&lt;span style="font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;"&gt;&amp;nbsp;&amp;nbsp; getSignature -&amp;gt; null (type org.opensaml.xml.signature.Signature)&lt;/span&gt;&lt;br /&gt;
&lt;span style="font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;"&gt;&amp;nbsp;&amp;nbsp; getParent -&amp;gt; null (type org.opensaml.xml.XMLObject)&lt;/span&gt;&lt;br /&gt;
&lt;span style="font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;"&gt;&amp;nbsp;&amp;nbsp; getDOM -&amp;gt; null (type org.w3c.dom.Element)&lt;/span&gt;&lt;br /&gt;
&lt;span style="font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;"&gt;&amp;nbsp;&amp;nbsp; getSchemaType -&amp;gt; null (type javax.xml.namespace.QName)&lt;/span&gt;&lt;br /&gt;
&lt;span style="font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;"&gt;&amp;nbsp;&amp;nbsp; getElementQName -&amp;gt; {urn:oasis:names:tc:SAML:2.0:protocol}AuthnRequest (type javax.xml.namespace.QName)&lt;/span&gt;&lt;br /&gt;
&lt;span style="font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;"&gt;&amp;nbsp;&amp;nbsp; getIDIndex -&amp;gt; org.opensaml.xml.util.IDIndex@1ab000c (type org.opensaml.xml.util.IDIndex)&lt;/span&gt;&lt;br /&gt;
&lt;span style="font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;"&gt;&amp;nbsp;&amp;nbsp; getNamespaces -&amp;gt; [xmlns:saml2p="urn:oasis:names:tc:SAML:2.0:protocol"] (type java.util.Set)&lt;/span&gt;&lt;br /&gt;
&lt;span style="font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;"&gt;&amp;nbsp;&amp;nbsp; getNoNamespaceSchemaLocation -&amp;gt; null (type java.lang.String)&lt;/span&gt;&lt;br /&gt;
&lt;span style="font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;"&gt;&amp;nbsp;&amp;nbsp; getSchemaLocation -&amp;gt; null (type java.lang.String)&lt;/span&gt;&lt;br /&gt;
&lt;span style="font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;"&gt;&amp;nbsp;&amp;nbsp; getClass -&amp;gt; class org.opensaml.saml2.core.impl.AuthnRequestImpl (type java.lang.Class)&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
Hope this serves as a useful tool in your troubleshooting/debugging.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3102468434043486639-7164543431268721112?l=royontechnology.blogspot.com' alt='' /&gt;&lt;/div&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/L03-Cws5lPFOX3B17nlC7xrg5p4/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/L03-Cws5lPFOX3B17nlC7xrg5p4/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/L03-Cws5lPFOX3B17nlC7xrg5p4/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/L03-Cws5lPFOX3B17nlC7xrg5p4/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/RoysMusings/~4/6HQVdn2DTU0" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://royontechnology.blogspot.com/feeds/7164543431268721112/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://www.blogger.com/comment.g?blogID=3102468434043486639&amp;postID=7164543431268721112" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/3102468434043486639/posts/default/7164543431268721112?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/3102468434043486639/posts/default/7164543431268721112?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/RoysMusings/~3/6HQVdn2DTU0/bean-properties-printer-useful.html" title="Bean properties printer - a useful debugging tool" /><author><name>Roy</name><uri>http://www.blogger.com/profile/00633074227808113222</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><feedburner:origLink>http://royontechnology.blogspot.com/2010/08/bean-properties-printer-useful.html</feedburner:origLink></entry><entry gd:etag="W/&quot;DEUMRXY_eyp7ImA9WxFaE00.&quot;"><id>tag:blogger.com,1999:blog-3102468434043486639.post-3967014137754865171</id><published>2010-07-16T11:51:00.000-07:00</published><updated>2010-07-16T11:51:24.843-07:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2010-07-16T11:51:24.843-07:00</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="SLF4J" /><category scheme="http://www.blogger.com/atom/ns#" term="Java" /><category scheme="http://www.blogger.com/atom/ns#" term="Logging" /><category scheme="http://www.blogger.com/atom/ns#" term="Java SE 6" /><title>Logging three or more arguments in slf4j</title><content type="html">I use slf4j for logging purposes. All the logging methods (Logger.info, Logger.debug, etc.) provide an efficient way of passing one or two argument objects. For e.g.&lt;br /&gt;
&lt;blockquote&gt;logger.info("The response from server is [{}]", serverResp);&lt;/blockquote&gt;&lt;blockquote&gt;logger.debug("Key [{}], Value [{}].", key, value);&lt;/blockquote&gt;&amp;nbsp;But if you want to pass three or more arguments you have to create an object array yourself and pass. Like this:&lt;br /&gt;
&lt;blockquote&gt;logger.info("Status [{}], message [{}], time taken [{} ms].", new Object[]{status, msg, timeTaken});&lt;/blockquote&gt;Doing a new everywhere in the code doesn't seem like an elegant way of doing it. I was thinking about a cool way of doing it, and this is what I came up with. Here is a utility method that makes use of varargs:&lt;br /&gt;
&lt;br /&gt;
&lt;blockquote&gt;public static Object[] toObjArr(Object... args) {&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; return args;&lt;br /&gt;
}&lt;/blockquote&gt;&lt;br /&gt;
In the code we can use this utility function like this.&lt;br /&gt;
&lt;blockquote&gt;import static com.mydomain.Utils.toObjArr;&lt;br /&gt;
...&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; logger.info("Status [{}], message [{}], time taken [{} ms].", toObjArr(status, msg, timeTaken));&lt;/blockquote&gt;A little-bit better readable than before.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3102468434043486639-3967014137754865171?l=royontechnology.blogspot.com' alt='' /&gt;&lt;/div&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/rq08uxd45BgzRKNxRvK71Nb2_TI/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/rq08uxd45BgzRKNxRvK71Nb2_TI/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/rq08uxd45BgzRKNxRvK71Nb2_TI/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/rq08uxd45BgzRKNxRvK71Nb2_TI/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/RoysMusings/~4/VxhC9X3EChI" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://royontechnology.blogspot.com/feeds/3967014137754865171/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://www.blogger.com/comment.g?blogID=3102468434043486639&amp;postID=3967014137754865171" title="1 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/3102468434043486639/posts/default/3967014137754865171?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/3102468434043486639/posts/default/3967014137754865171?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/RoysMusings/~3/VxhC9X3EChI/logging-three-or-more-arguments-in.html" title="Logging three or more arguments in slf4j" /><author><name>Roy</name><uri>http://www.blogger.com/profile/00633074227808113222</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><feedburner:origLink>http://royontechnology.blogspot.com/2010/07/logging-three-or-more-arguments-in.html</feedburner:origLink></entry><entry gd:etag="W/&quot;Ak4ESXg4fip7ImA9WxFUE0w.&quot;"><id>tag:blogger.com,1999:blog-3102468434043486639.post-8299729754012995731</id><published>2010-06-23T11:48:00.000-07:00</published><updated>2010-06-23T11:48:28.636-07:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2010-06-23T11:48:28.636-07:00</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="Java" /><category scheme="http://www.blogger.com/atom/ns#" term="Java SE 6" /><title>Creating a Collection with a single element</title><content type="html">Question: What is the most efficient way of creating a collection (Set, List or Map) with a single element?&lt;br /&gt;
&lt;br /&gt;
Answer: The most efficient way of creating a collection with a single element would be to make use of the Collections.singletonXXX() methods.&lt;br /&gt;
&lt;ul&gt;&lt;li&gt;Collections.singleton - To create a set that has only one element.&lt;/li&gt;
&lt;li&gt;Collections.singletonList - To create a list that has only one element.&lt;/li&gt;
&lt;li&gt;Collections.singletonMap - To crate a map that has only one entry.&lt;/li&gt;
&lt;/ul&gt;The collections returned from these methods are immutable.&lt;br /&gt;
&lt;br /&gt;
Compare these methods with Collections.unmodifiableXXX() methods. The umodifiableXXX methods already accept a collection as an argument.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3102468434043486639-8299729754012995731?l=royontechnology.blogspot.com' alt='' /&gt;&lt;/div&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/hlJF8-0JFM94WIklAt5w_LQy92Q/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/hlJF8-0JFM94WIklAt5w_LQy92Q/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/hlJF8-0JFM94WIklAt5w_LQy92Q/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/hlJF8-0JFM94WIklAt5w_LQy92Q/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/RoysMusings/~4/uAfOm6mrG6A" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://royontechnology.blogspot.com/feeds/8299729754012995731/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://www.blogger.com/comment.g?blogID=3102468434043486639&amp;postID=8299729754012995731" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/3102468434043486639/posts/default/8299729754012995731?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/3102468434043486639/posts/default/8299729754012995731?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/RoysMusings/~3/uAfOm6mrG6A/creating-collection-with-single-element.html" title="Creating a Collection with a single element" /><author><name>Roy</name><uri>http://www.blogger.com/profile/00633074227808113222</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><feedburner:origLink>http://royontechnology.blogspot.com/2010/06/creating-collection-with-single-element.html</feedburner:origLink></entry></feed>

