<?xml version='1.0' encoding='UTF-8'?><?xml-stylesheet href="http://www.blogger.com/styles/atom.css" type="text/css"?><feed xmlns='http://www.w3.org/2005/Atom' xmlns:openSearch='http://a9.com/-/spec/opensearchrss/1.0/' xmlns:blogger='http://schemas.google.com/blogger/2008' xmlns:georss='http://www.georss.org/georss' xmlns:gd="http://schemas.google.com/g/2005" xmlns:thr='http://purl.org/syndication/thread/1.0'><id>tag:blogger.com,1999:blog-7356812311849332117</id><updated>2024-09-19T13:41:43.035-07:00</updated><category term="Avro"/><category term="Linked list"/><category term="Linked list problems"/><category term="Protocol Buffers"/><category term="amazon"/><category term="choose java collection"/><category term="collection hierarhcy"/><category term="commerce"/><category term="e-commerce"/><category term="ebay"/><category term="f-commerce"/><category term="facebook app"/><category term="facebook connect"/><category term="foreign language sorting in java"/><category term="fork and join framework"/><category term="integer reverse"/><category term="java collections"/><category term="java hashset"/><category term="java list"/><category term="java map"/><category term="java parallel processing"/><category term="java set"/><category term="java treemap"/><category term="linked list reversal"/><category term="locale character sorting in java"/><category term="locale characters"/><category term="locale sorting"/><category term="multi-processor java coding"/><category term="online shopping"/><category term="parallel processing"/><category term="reverse"/><category term="reverse logic"/><category term="reverse the linkedlist"/><category term="social commerce"/><category term="sorting"/><category term="string reverse"/><category term="treemap locale sorting"/><title type='text'>Thinking in java</title><subtitle type='html'></subtitle><link rel='http://schemas.google.com/g/2005#feed' type='application/atom+xml' href='http://saraven.blogspot.com/feeds/posts/default'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7356812311849332117/posts/default?redirect=false'/><link rel='alternate' type='text/html' href='http://saraven.blogspot.com/'/><link rel='hub' href='http://pubsubhubbub.appspot.com/'/><author><name>Sarav</name><uri>http://www.blogger.com/profile/11797223671802998157</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='25' height='32' src='//blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi5bcV8nSfWmwz5OJYLhZqz2_UpNBNAGgllMP6ZDDtfW_ON3CsRscFrIsA9ToJ0BJzzU5NSI-NiIJEIuYoAINUB98Y3Bh5kyPFhs2dD887uugninF4frU6dKKElQMMXJA/s220/me.jpg'/></author><generator version='7.00' uri='http://www.blogger.com'>Blogger</generator><openSearch:totalResults>13</openSearch:totalResults><openSearch:startIndex>1</openSearch:startIndex><openSearch:itemsPerPage>25</openSearch:itemsPerPage><entry><id>tag:blogger.com,1999:blog-7356812311849332117.post-1220419221231740633</id><published>2013-09-22T15:30:00.000-07:00</published><updated>2013-09-22T15:34:11.135-07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="choose java collection"/><category scheme="http://www.blogger.com/atom/ns#" term="collection hierarhcy"/><category scheme="http://www.blogger.com/atom/ns#" term="java collections"/><category scheme="http://www.blogger.com/atom/ns#" term="java hashset"/><category scheme="http://www.blogger.com/atom/ns#" term="java list"/><category scheme="http://www.blogger.com/atom/ns#" term="java map"/><category scheme="http://www.blogger.com/atom/ns#" term="java set"/><category scheme="http://www.blogger.com/atom/ns#" term="java treemap"/><title type='text'>Java Collections hierarchy</title><content type='html'>&lt;div align=&quot;right&quot; id=&quot;fb_2&quot;&gt;
&lt;iframe frameborder=&quot;0&quot; height=&quot;30&quot; src=&quot;http://www.facebook.com/plugins/like.php?href=http://saraven.blogspot.in/2013/09/java-collections-hierarchy.html&amp;amp;layout=button_count&amp;amp;action=like&amp;amp;colorscheme=light&quot; width=&quot;90&quot;&gt;&lt;/iframe&gt;&lt;/div&gt;
Collection Hierarchy


&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiuBofvqwoDfIt0SMHDJZZJJJ5C8JxRM3h8Ro-j8V-C2ZLwRpMaoNfhikjZa7f96ecsZXwVszGkQdKpjAHqP725FQUruphlqrVa2HTIhuv4htM1SAjvXoIlo1nmHyb9vj1z6fRuZkKmHhEc/s1600/collections-hirearchy.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiuBofvqwoDfIt0SMHDJZZJJJ5C8JxRM3h8Ro-j8V-C2ZLwRpMaoNfhikjZa7f96ecsZXwVszGkQdKpjAHqP725FQUruphlqrVa2HTIhuv4htM1SAjvXoIlo1nmHyb9vj1z6fRuZkKmHhEc/s400/collections-hirearchy.png&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;br /&gt;
&lt;br /&gt;
How to choose collection for my use case?

&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhz7Nxd1jenxRIjYVTHyMPvczaQOnpDSVcnVk8qARbnt5kSSfN8bN240LDmjfbAZ1s3N-iuyNYTR7eORAk8xZgEBhMWBLQjOfe51gIp_Yic9hoE-XtU3xZ4bj8BLpOtaREU0FlOYB_NujsF/s1600/collection-to-choose.gif&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhz7Nxd1jenxRIjYVTHyMPvczaQOnpDSVcnVk8qARbnt5kSSfN8bN240LDmjfbAZ1s3N-iuyNYTR7eORAk8xZgEBhMWBLQjOfe51gIp_Yic9hoE-XtU3xZ4bj8BLpOtaREU0FlOYB_NujsF/s400/collection-to-choose.gif&quot; /&gt;&lt;/a&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://saraven.blogspot.com/feeds/1220419221231740633/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment/fullpage/post/7356812311849332117/1220419221231740633' title='2 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7356812311849332117/posts/default/1220419221231740633'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7356812311849332117/posts/default/1220419221231740633'/><link rel='alternate' type='text/html' href='http://saraven.blogspot.com/2013/09/java-collections-hierarchy.html' title='Java Collections hierarchy'/><author><name>Sarav</name><uri>http://www.blogger.com/profile/11797223671802998157</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='25' height='32' src='//blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi5bcV8nSfWmwz5OJYLhZqz2_UpNBNAGgllMP6ZDDtfW_ON3CsRscFrIsA9ToJ0BJzzU5NSI-NiIJEIuYoAINUB98Y3Bh5kyPFhs2dD887uugninF4frU6dKKElQMMXJA/s220/me.jpg'/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiuBofvqwoDfIt0SMHDJZZJJJ5C8JxRM3h8Ro-j8V-C2ZLwRpMaoNfhikjZa7f96ecsZXwVszGkQdKpjAHqP725FQUruphlqrVa2HTIhuv4htM1SAjvXoIlo1nmHyb9vj1z6fRuZkKmHhEc/s72-c/collections-hirearchy.png" height="72" width="72"/><thr:total>2</thr:total></entry><entry><id>tag:blogger.com,1999:blog-7356812311849332117.post-105633932512566910</id><published>2013-09-19T14:27:00.002-07:00</published><updated>2013-09-19T14:42:15.828-07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="foreign language sorting in java"/><category scheme="http://www.blogger.com/atom/ns#" term="locale character sorting in java"/><category scheme="http://www.blogger.com/atom/ns#" term="locale characters"/><category scheme="http://www.blogger.com/atom/ns#" term="locale sorting"/><category scheme="http://www.blogger.com/atom/ns#" term="sorting"/><category scheme="http://www.blogger.com/atom/ns#" term="treemap locale sorting"/><title type='text'>Locale character sorting - java</title><content type='html'>&lt;div align=&quot;right&quot; id=&quot;fb_2&quot;&gt;
&lt;iframe frameborder=&quot;0&quot; height=&quot;30&quot; src=&quot;http://www.facebook.com/plugins/like.php?href=http://saraven.blogspot.com/2013/09/locale-character-sorting-java.html&amp;amp;layout=button_count&amp;amp;action=like&amp;amp;colorscheme=light&quot; width=&quot;90&quot;&gt;&lt;/iframe&gt;&lt;/div&gt;
I am currently working on multilingual site development. Yesterday I faced an interesting requirement to sort the locale characters.&lt;br /&gt;
&lt;br /&gt;
Assuming the english text sorting, we have written the code as Treemap based sorting.&lt;br /&gt;
&lt;blockquote class=&quot;tr_bq&quot;&gt;
&lt;blockquote class=&quot;tr_bq&quot;&gt;
Map&lt;String, String&gt; data = new TreeMap&lt;String, String&gt;(); &amp;nbsp;&lt;/string&gt;&lt;/string&gt;&lt;/blockquote&gt;
&lt;blockquote class=&quot;tr_bq&quot;&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp;data&amp;nbsp;.put(&quot;sarav&quot;, &quot;000&quot;); &amp;nbsp;&lt;/blockquote&gt;
&lt;blockquote class=&quot;tr_bq&quot;&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp;data&amp;nbsp;.put(&quot;rohit&quot;, &quot;002&quot;);&amp;nbsp;&lt;/blockquote&gt;
&lt;/blockquote&gt;
As i18n involved, what happens all locale based text got the last position in the sorting.&lt;br /&gt;
&lt;blockquote class=&quot;tr_bq&quot;&gt;
data&amp;nbsp;.put(&quot;ärav&quot;, &quot;003&quot;);&amp;nbsp;&lt;/blockquote&gt;
&lt;br /&gt;
Interestingly Treemap has a constructor with Compartor&lt;br /&gt;
&lt;br /&gt;
TreeMap(Collator.getInstance(Locale.GERMAN))&lt;br /&gt;
&lt;br /&gt;
The Collator class performs locale-sensitive String comparison. By using this Collator, we will be able to build searching and sorting routines for natural language text.&lt;br /&gt;
&lt;br /&gt;
Collator is an abstract base class. Subclasses implement specific collation strategies. One subclass, RuleBasedCollator, is currently provided with the Java 2 platform and is applicable to a wide set of languages.&lt;br /&gt;
&lt;br /&gt;
Like other locale-sensitive classes, you can use the static factory method, getInstance, to obtain the appropriate Collator object for a given locale, as I used above.&lt;br /&gt;
&lt;br /&gt;
We can set a Collator&#39;s strength property to determine the level of difference considered significant in comparisons. Four strengths are provided: PRIMARY, SECONDARY, TERTIARY, and IDENTICAL. The exact assignment of strengths to language features is locale dependant. For example, in Czech, &quot;e&quot; and &quot;f&quot; are considered primary differences, while &quot;e&quot; and &quot;ê&quot; are secondary differences, &quot;e&quot; and &quot;E&quot; are tertiary differences and &quot;e&quot; and &quot;e&quot; are identical.&lt;br /&gt;
&lt;br /&gt;
I didn&#39;t set any strength for my requirement, it worked as-is. I found a sample for this in the below URL&lt;br /&gt;
&lt;br /&gt;
&lt;a href=&quot;http://stackoverflow.com/questions/7502642/sort-a-list-of-hungarian-strings-in-the-hungarian-alphabetical-order&quot;&gt;http://stackoverflow.com/questions/7502642/sort-a-list-of-hungarian-strings-in-the-hungarian-alphabetical-order&lt;/a&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;</content><link rel='replies' type='application/atom+xml' href='http://saraven.blogspot.com/feeds/105633932512566910/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment/fullpage/post/7356812311849332117/105633932512566910' title='2 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7356812311849332117/posts/default/105633932512566910'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7356812311849332117/posts/default/105633932512566910'/><link rel='alternate' type='text/html' href='http://saraven.blogspot.com/2013/09/locale-character-sorting-java.html' title='Locale character sorting - java'/><author><name>Sarav</name><uri>http://www.blogger.com/profile/11797223671802998157</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='25' height='32' src='//blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi5bcV8nSfWmwz5OJYLhZqz2_UpNBNAGgllMP6ZDDtfW_ON3CsRscFrIsA9ToJ0BJzzU5NSI-NiIJEIuYoAINUB98Y3Bh5kyPFhs2dD887uugninF4frU6dKKElQMMXJA/s220/me.jpg'/></author><thr:total>2</thr:total></entry><entry><id>tag:blogger.com,1999:blog-7356812311849332117.post-2612784980580111112</id><published>2011-12-10T05:59:00.000-08:00</published><updated>2013-09-19T14:36:48.515-07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="fork and join framework"/><category scheme="http://www.blogger.com/atom/ns#" term="java parallel processing"/><category scheme="http://www.blogger.com/atom/ns#" term="multi-processor java coding"/><category scheme="http://www.blogger.com/atom/ns#" term="parallel processing"/><title type='text'>How to do parallel processing in java?</title><content type='html'>&lt;div align=&quot;right&quot; id=&quot;fb_2&quot;&gt;&lt;iframe frameborder=&quot;0&quot; height=&quot;30&quot; src=&quot;http://www.facebook.com/plugins/like.php?href=http://saraven.blogspot.com/2011/12/how-to-do-parallel-processing-in-java.html&amp;amp;layout=button_count&amp;amp;action=like&amp;amp;colorscheme=light&quot; width=&quot;90&quot;&gt;&lt;/iframe&gt;&lt;/div&gt;I have this question in my mind for long time. We have dual processor/multi processor whether we are using the full power of those. How JVM itself can split the task across the processor and make the instruction set execution more&amp;nbsp;efficient?&lt;br /&gt;
&lt;br /&gt;
As usual before I move 5 steps in my thought process, industry will move 50 steps. No wonder, we have solve for this in Java 7.&lt;br /&gt;
&lt;br /&gt;
It&#39;s&amp;nbsp;the fork/join framework is an implementation of the&amp;nbsp;&lt;code&gt;ExecutorService&lt;/code&gt;&amp;nbsp;interface that helps you take advantage of multiple processors.&amp;nbsp;As with any&amp;nbsp;&lt;code&gt;ExecutorService&lt;/code&gt;, the fork/join framework distributes tasks to worker threads in a thread pool. The fork/join framework is distinct because it uses a&amp;nbsp;&lt;i&gt;work-stealing&lt;/i&gt;&amp;nbsp;algorithm. Worker threads that run out of things to do can steal tasks from other threads that are still busy.&lt;br /&gt;
&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;background-color: white; font-family: arial, sans-serif; font-size: 16px; line-height: 24px;&quot;&gt;&amp;nbsp;If you are not using Java 7 you also need to have &quot;jsr166y.jar&quot; in the classpath.&lt;/span&gt;&lt;br /&gt;
&lt;pre class=&quot;programlisting&quot; style=&quot;background-color: white; border-bottom-color: rgb(187, 187, 187); border-bottom-style: solid; border-bottom-width: 1px; border-left-color: rgb(187, 187, 187); border-left-style: solid; border-left-width: 1px; border-right-color: rgb(187, 187, 187); border-right-style: solid; border-right-width: 1px; border-top-color: rgb(187, 187, 187); border-top-style: solid; border-top-width: 1px; font-family: &#39;Droid Sans Mono&#39;, Monaco, &#39;Bitstream Vera Sans Mono&#39;, &#39;Lucida Console&#39;, Terminal, monospace; font-size: 13px; line-height: 16px; margin-top: 1em; overflow-x: auto; overflow-y: auto; padding-left: 0.8em; word-wrap: break-word;&quot;&gt;&lt;span class=&quot;hl-keyword&quot; style=&quot;color: #7f0055; font-weight: bold;&quot;&gt;package&lt;/span&gt; com.sarav.forkjoin;

&lt;span class=&quot;hl-keyword&quot; style=&quot;color: #7f0055; font-weight: bold;&quot;&gt;import&lt;/span&gt; java.util.Random;

&lt;div class=&quot;hl-tag&quot; style=&quot;color: #008800;&quot;&gt;&lt;span class=&quot;hl-keyword&quot; style=&quot;color: #7f0055; font-weight: bold;&quot;&gt;public&lt;/span&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: black;&quot;&gt; &lt;/span&gt;&lt;span class=&quot;hl-keyword&quot; style=&quot;color: #7f0055; font-weight: bold;&quot;&gt;class&lt;/span&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: black;&quot;&gt; Problem {&lt;/span&gt;&lt;/div&gt;&lt;span class=&quot;hl-keyword&quot; style=&quot;color: #7f0055; font-weight: bold;&quot;&gt;private&lt;/span&gt; &lt;span class=&quot;hl-keyword&quot; style=&quot;color: #7f0055; font-weight: bold;&quot;&gt;final&lt;/span&gt; &lt;span class=&quot;hl-keyword&quot; style=&quot;color: #7f0055; font-weight: bold;&quot;&gt;int&lt;/span&gt;[] list = &lt;span class=&quot;hl-keyword&quot; style=&quot;color: #7f0055; font-weight: bold;&quot;&gt;new&lt;/span&gt; &lt;span class=&quot;hl-keyword&quot; style=&quot;color: #7f0055; font-weight: bold;&quot;&gt;int&lt;/span&gt;[&lt;span class=&quot;hl-number&quot;&gt;2000000&lt;/span&gt;];

 &lt;span class=&quot;hl-keyword&quot; style=&quot;color: #7f0055; font-weight: bold;&quot;&gt;public&lt;/span&gt; Problem() {
  Random generator = &lt;span class=&quot;hl-keyword&quot; style=&quot;color: #7f0055; font-weight: bold;&quot;&gt;new&lt;/span&gt; Random(&lt;span class=&quot;hl-number&quot;&gt;19580427&lt;/span&gt;);
  &lt;span class=&quot;hl-keyword&quot; style=&quot;color: #7f0055; font-weight: bold;&quot;&gt;for&lt;/span&gt; (&lt;span class=&quot;hl-keyword&quot; style=&quot;color: #7f0055; font-weight: bold;&quot;&gt;int&lt;/span&gt; i = &lt;span class=&quot;hl-number&quot;&gt;0&lt;/span&gt;; i &amp;lt; list.length; i++) {
   list[i] = generator.nextInt(&lt;span class=&quot;hl-number&quot;&gt;500000&lt;/span&gt;);
  }
 }

 &lt;span class=&quot;hl-keyword&quot; style=&quot;color: #7f0055; font-weight: bold;&quot;&gt;public&lt;/span&gt; &lt;span class=&quot;hl-keyword&quot; style=&quot;color: #7f0055; font-weight: bold;&quot;&gt;int&lt;/span&gt;[] getList() {
  &lt;span class=&quot;hl-keyword&quot; style=&quot;color: #7f0055; font-weight: bold;&quot;&gt;return&lt;/span&gt; list;
 }

}&lt;/pre&gt;RecrusiveAction implementation&lt;br /&gt;
&lt;pre class=&quot;programlisting&quot; style=&quot;background-color: white; border-bottom-color: rgb(187, 187, 187); border-bottom-style: solid; border-bottom-width: 1px; border-left-color: rgb(187, 187, 187); border-left-style: solid; border-left-width: 1px; border-right-color: rgb(187, 187, 187); border-right-style: solid; border-right-width: 1px; border-top-color: rgb(187, 187, 187); border-top-style: solid; border-top-width: 1px; font-family: &#39;Droid Sans Mono&#39;, Monaco, &#39;Bitstream Vera Sans Mono&#39;, &#39;Lucida Console&#39;, Terminal, monospace; font-size: 13px; line-height: 16px; margin-top: 1em; overflow-x: auto; overflow-y: auto; padding-left: 0.8em; word-wrap: break-word;&quot;&gt;&lt;span class=&quot;hl-keyword&quot; style=&quot;color: #7f0055; font-weight: bold;&quot;&gt;package&lt;/span&gt; com.sarav.forkjoin;

&lt;span class=&quot;hl-keyword&quot; style=&quot;color: #7f0055; font-weight: bold;&quot;&gt;import&lt;/span&gt; java.util.Arrays;

&lt;span class=&quot;hl-keyword&quot; style=&quot;color: #7f0055; font-weight: bold;&quot;&gt;import&lt;/span&gt; jsr166y.forkjoin.RecursiveAction;

&lt;span class=&quot;hl-keyword&quot; style=&quot;color: #7f0055; font-weight: bold;&quot;&gt;public&lt;/span&gt; &lt;span class=&quot;hl-keyword&quot; style=&quot;color: #7f0055; font-weight: bold;&quot;&gt;class&lt;/span&gt; Solver &lt;span class=&quot;hl-keyword&quot; style=&quot;color: #7f0055; font-weight: bold;&quot;&gt;extends&lt;/span&gt; RecursiveAction {
 &lt;span class=&quot;hl-keyword&quot; style=&quot;color: #7f0055; font-weight: bold;&quot;&gt;private&lt;/span&gt; &lt;span class=&quot;hl-keyword&quot; style=&quot;color: #7f0055; font-weight: bold;&quot;&gt;int&lt;/span&gt;[] list;
 &lt;span class=&quot;hl-keyword&quot; style=&quot;color: #7f0055; font-weight: bold;&quot;&gt;public&lt;/span&gt; &lt;span class=&quot;hl-keyword&quot; style=&quot;color: #7f0055; font-weight: bold;&quot;&gt;long&lt;/span&gt; result;

 &lt;span class=&quot;hl-keyword&quot; style=&quot;color: #7f0055; font-weight: bold;&quot;&gt;public&lt;/span&gt; Solver(&lt;span class=&quot;hl-keyword&quot; style=&quot;color: #7f0055; font-weight: bold;&quot;&gt;int&lt;/span&gt;[] array) {
  &lt;span class=&quot;hl-keyword&quot; style=&quot;color: #7f0055; font-weight: bold;&quot;&gt;this&lt;/span&gt;.list = array;
 }

 &lt;em&gt;&lt;span class=&quot;hl-annotation&quot; style=&quot;color: grey;&quot;&gt;@Override&lt;/span&gt;&lt;/em&gt;
 &lt;span class=&quot;hl-keyword&quot; style=&quot;color: #7f0055; font-weight: bold;&quot;&gt;protected&lt;/span&gt; &lt;span class=&quot;hl-keyword&quot; style=&quot;color: #7f0055; font-weight: bold;&quot;&gt;void&lt;/span&gt; compute() {
  &lt;span class=&quot;hl-keyword&quot; style=&quot;color: #7f0055; font-weight: bold;&quot;&gt;if&lt;/span&gt; (list.length == &lt;span class=&quot;hl-number&quot;&gt;1&lt;/span&gt;) {
   result = list[&lt;span class=&quot;hl-number&quot;&gt;0&lt;/span&gt;];
  } &lt;span class=&quot;hl-keyword&quot; style=&quot;color: #7f0055; font-weight: bold;&quot;&gt;else&lt;/span&gt; {
   &lt;span class=&quot;hl-keyword&quot; style=&quot;color: #7f0055; font-weight: bold;&quot;&gt;int&lt;/span&gt; midpoint = list.length / &lt;span class=&quot;hl-number&quot;&gt;2&lt;/span&gt;;
   &lt;span class=&quot;hl-keyword&quot; style=&quot;color: #7f0055; font-weight: bold;&quot;&gt;int&lt;/span&gt;[] l1 = Arrays.copyOfRange(list, &lt;span class=&quot;hl-number&quot;&gt;0&lt;/span&gt;, midpoint);
   &lt;span class=&quot;hl-keyword&quot; style=&quot;color: #7f0055; font-weight: bold;&quot;&gt;int&lt;/span&gt;[] l2 = Arrays.copyOfRange(list, midpoint, list.length);
   Solver s1 = &lt;span class=&quot;hl-keyword&quot; style=&quot;color: #7f0055; font-weight: bold;&quot;&gt;new&lt;/span&gt; Solver(l1);
   Solver s2 = &lt;span class=&quot;hl-keyword&quot; style=&quot;color: #7f0055; font-weight: bold;&quot;&gt;new&lt;/span&gt; Solver(l2);
   forkJoin(s1, s2);
   result = s1.result + s2.result;
  }
 }
}&lt;/pre&gt;Test to verify my understanding&lt;br /&gt;
&lt;pre class=&quot;programlisting&quot; style=&quot;background-color: white; border-bottom-color: rgb(187, 187, 187); border-bottom-style: solid; border-bottom-width: 1px; border-left-color: rgb(187, 187, 187); border-left-style: solid; border-left-width: 1px; border-right-color: rgb(187, 187, 187); border-right-style: solid; border-right-width: 1px; border-top-color: rgb(187, 187, 187); border-top-style: solid; border-top-width: 1px; font-family: &#39;Droid Sans Mono&#39;, Monaco, &#39;Bitstream Vera Sans Mono&#39;, &#39;Lucida Console&#39;, Terminal, monospace; font-size: 13px; line-height: 16px; margin-top: 1em; overflow-x: auto; overflow-y: auto; padding-left: 0.8em; word-wrap: break-word;&quot;&gt;&lt;span class=&quot;hl-keyword&quot; style=&quot;color: #7f0055; font-weight: bold;&quot;&gt;package&lt;/span&gt; com.sarav.forkjoin.testing;

&lt;span class=&quot;hl-keyword&quot; style=&quot;color: #7f0055; font-weight: bold;&quot;&gt;import&lt;/span&gt; jsr166y.forkjoin.ForkJoinExecutor;
&lt;span class=&quot;hl-keyword&quot; style=&quot;color: #7f0055; font-weight: bold;&quot;&gt;import&lt;/span&gt; jsr166y.forkjoin.ForkJoinPool;
&lt;span class=&quot;hl-keyword&quot; style=&quot;color: #7f0055; font-weight: bold;&quot;&gt;import&lt;/span&gt; com.sarav.forkjoin.Problem;
&lt;span class=&quot;hl-keyword&quot; style=&quot;color: #7f0055; font-weight: bold;&quot;&gt;import&lt;/span&gt; com.sarav.forkjoin.Solver;

&lt;span class=&quot;hl-keyword&quot; style=&quot;color: #7f0055; font-weight: bold;&quot;&gt;public&lt;/span&gt; &lt;span class=&quot;hl-keyword&quot; style=&quot;color: #7f0055; font-weight: bold;&quot;&gt;class&lt;/span&gt; Test {

 &lt;span class=&quot;hl-keyword&quot; style=&quot;color: #7f0055; font-weight: bold;&quot;&gt;public&lt;/span&gt; &lt;span class=&quot;hl-keyword&quot; style=&quot;color: #7f0055; font-weight: bold;&quot;&gt;static&lt;/span&gt; &lt;span class=&quot;hl-keyword&quot; style=&quot;color: #7f0055; font-weight: bold;&quot;&gt;void&lt;/span&gt; main(String[] args) {
  Problem test = &lt;span class=&quot;hl-keyword&quot; style=&quot;color: #7f0055; font-weight: bold;&quot;&gt;new&lt;/span&gt; Problem();
  &lt;em class=&quot;hl-comment&quot; style=&quot;color: #008800;&quot;&gt;// Check the number of available processors&lt;/em&gt;
  &lt;span class=&quot;hl-keyword&quot; style=&quot;color: #7f0055; font-weight: bold;&quot;&gt;int&lt;/span&gt; nThreads = Runtime.getRuntime().availableProcessors();
  System.out.println(nThreads);
  Solver mfj = &lt;span class=&quot;hl-keyword&quot; style=&quot;color: #7f0055; font-weight: bold;&quot;&gt;new&lt;/span&gt; Solver(test.getList());
  ForkJoinExecutor pool = &lt;span class=&quot;hl-keyword&quot; style=&quot;color: #7f0055; font-weight: bold;&quot;&gt;new&lt;/span&gt; ForkJoinPool(nThreads);
  pool.invoke(mfj);
  &lt;span class=&quot;hl-keyword&quot; style=&quot;color: #7f0055; font-weight: bold;&quot;&gt;long&lt;/span&gt; result = mfj.getResult();
  System.out.println(&lt;span class=&quot;hl-string&quot; style=&quot;color: blue;&quot;&gt;&quot;Done. Result: &quot;&lt;/span&gt; + result);
  &lt;span class=&quot;hl-keyword&quot; style=&quot;color: #7f0055; font-weight: bold;&quot;&gt;long&lt;/span&gt; sum = &lt;span class=&quot;hl-number&quot;&gt;0&lt;/span&gt;;
  &lt;em class=&quot;hl-comment&quot; style=&quot;color: #008800;&quot;&gt;// Check if the result was ok&lt;/em&gt;
  &lt;span class=&quot;hl-keyword&quot; style=&quot;color: #7f0055; font-weight: bold;&quot;&gt;for&lt;/span&gt; (&lt;span class=&quot;hl-keyword&quot; style=&quot;color: #7f0055; font-weight: bold;&quot;&gt;int&lt;/span&gt; i = &lt;span class=&quot;hl-number&quot;&gt;0&lt;/span&gt;; i &amp;lt; test.getList().length; i++) {
   sum += test.getList()[i];
  }
  System.out.println(&lt;span class=&quot;hl-string&quot; style=&quot;color: blue;&quot;&gt;&quot;Done. Result: &quot;&lt;/span&gt; + sum);
 }
}&lt;/pre&gt;&lt;br /&gt;
&lt;br /&gt;
I didn&#39;t apply this in my real time application to give some performance report. Soon I will :)</content><link rel='replies' type='application/atom+xml' href='http://saraven.blogspot.com/feeds/2612784980580111112/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment/fullpage/post/7356812311849332117/2612784980580111112' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7356812311849332117/posts/default/2612784980580111112'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7356812311849332117/posts/default/2612784980580111112'/><link rel='alternate' type='text/html' href='http://saraven.blogspot.com/2011/12/how-to-do-parallel-processing-in-java.html' title='How to do parallel processing in java?'/><author><name>Sarav</name><uri>http://www.blogger.com/profile/11797223671802998157</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='25' height='32' src='//blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi5bcV8nSfWmwz5OJYLhZqz2_UpNBNAGgllMP6ZDDtfW_ON3CsRscFrIsA9ToJ0BJzzU5NSI-NiIJEIuYoAINUB98Y3Bh5kyPFhs2dD887uugninF4frU6dKKElQMMXJA/s220/me.jpg'/></author><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-7356812311849332117.post-1059566366531776307</id><published>2011-10-28T15:52:00.000-07:00</published><updated>2011-10-29T01:06:50.607-07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="Linked list"/><category scheme="http://www.blogger.com/atom/ns#" term="Linked list problems"/><category scheme="http://www.blogger.com/atom/ns#" term="linked list reversal"/><category scheme="http://www.blogger.com/atom/ns#" term="reverse the linkedlist"/><title type='text'>Linked List - Reverse &amp; identifying the cycle</title><content type='html'>&lt;div align=&quot;right&quot; id=&quot;fb_2&quot;&gt;&lt;iframe frameborder=&quot;0&quot; height=&quot;30&quot; src=&quot;http://www.facebook.com/plugins/like.php?href=http://saraven.blogspot.com/2011/10/linked-list-reverse-identifying-cycle.html&amp;amp;layout=button_count&amp;amp;action=like&amp;amp;colorscheme=light&quot; width=&quot;90&quot;&gt;&lt;/iframe&gt;&lt;/div&gt;Linked List- another interesting and simple data structure. Most of the interviewers ask for reverse and identifying the cycle in linked list.&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;&lt;u&gt;Identifying the cycle&lt;/u&gt;&lt;/b&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #222222; font-family: Tahoma, Verdana, Arial, Helvetica, sans-serif; font-size: 12px; line-height: 19px;&quot;&gt;Traversal of a linked list with a cycle will never end, so there needs to be some method to keep track of what nodes have been encountered.&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;background-color: #f4f7e7; color: #222222; font-family: Tahoma, Verdana, Arial, Helvetica, sans-serif; font-size: 12px; line-height: 19px;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;background-color: #f4f7e7; color: #222222; font-family: Tahoma, Verdana, Arial, Helvetica, sans-serif; font-size: 12px; line-height: 19px;&quot;&gt;One idea is to mark nodes that have been seen, either by adding a flag to the node itself or storing information about the node in a separate data structure. Unfortunately, this method requires modification of the node and/or additional space.&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;background-color: #f4f7e7; color: #222222; font-family: Tahoma, Verdana, Arial, Helvetica, sans-serif; font-size: 12px; line-height: 19px;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;background-color: #f4f7e7; color: #222222; font-family: Tahoma, Verdana, Arial, Helvetica, sans-serif; font-size: 12px; line-height: 19px;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: black; font-family: &#39;Times New Roman&#39;; font-size: small; line-height: normal;&quot;&gt;Interviewers won&#39;t accept this way as they want to understand/see how we traverse across nodes.&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
Another idea is to move the pointers in different speed to identify a cycle as below.&amp;nbsp;&lt;span class=&quot;Apple-style-span&quot; style=&quot;background-color: #f4f7e7; color: #222222; font-family: Tahoma, Verdana, Arial, Helvetica, sans-serif; font-size: 12px; line-height: 19px;&quot;&gt;To make one pointer faster than the other, just advance it two nodes instead of one.&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
public static boolean hasCycle(Node head) {&lt;br /&gt;
&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;Node fast = head;&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;Node slow = head;&lt;br /&gt;
&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;while (true) {&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;   &lt;/span&gt;if (fast == null || fast.next == null)&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;    &lt;/span&gt;return false;&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;   &lt;/span&gt;else if (fast == slow || fast.next == slow)&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;    &lt;/span&gt;return true;&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;   &lt;/span&gt;else {&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;    &lt;/span&gt;fast = fast.next.next;&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;    &lt;/span&gt;slow = slow.next;&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;   &lt;/span&gt;}&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;}&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;}&lt;br /&gt;
&lt;b&gt;&lt;u&gt;Reverse&lt;/u&gt;&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&lt;u&gt;&lt;br /&gt;
&lt;/u&gt;&lt;/b&gt;&lt;br /&gt;
With three pointers, reverse will be pretty straight forward to move on.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Node previous = null;&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;Node current = head;&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;Node forward;&lt;br /&gt;
&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;while (current != null) {&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;   &lt;/span&gt;forward = current.next;&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;   &lt;/span&gt;current.next = previous;&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;   &lt;/span&gt;previous = current;&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;   &lt;/span&gt;current = forward;&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;}&lt;br /&gt;
&lt;br /&gt;
&lt;a href=&quot;http://bigbazee.co.uk/downloads/SaravList.java&quot;&gt;Download&amp;nbsp;the code&lt;/a&gt; (Just copy &amp;amp; paster in your editor)</content><link rel='replies' type='application/atom+xml' href='http://saraven.blogspot.com/feeds/1059566366531776307/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment/fullpage/post/7356812311849332117/1059566366531776307' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7356812311849332117/posts/default/1059566366531776307'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7356812311849332117/posts/default/1059566366531776307'/><link rel='alternate' type='text/html' href='http://saraven.blogspot.com/2011/10/linked-list-reverse-identifying-cycle.html' title='Linked List - Reverse &amp; identifying the cycle'/><author><name>Sarav</name><uri>http://www.blogger.com/profile/11797223671802998157</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='25' height='32' src='//blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi5bcV8nSfWmwz5OJYLhZqz2_UpNBNAGgllMP6ZDDtfW_ON3CsRscFrIsA9ToJ0BJzzU5NSI-NiIJEIuYoAINUB98Y3Bh5kyPFhs2dD887uugninF4frU6dKKElQMMXJA/s220/me.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-7356812311849332117.post-2624093998920102056</id><published>2011-10-22T05:48:00.000-07:00</published><updated>2011-10-22T09:13:50.345-07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="amazon"/><category scheme="http://www.blogger.com/atom/ns#" term="commerce"/><category scheme="http://www.blogger.com/atom/ns#" term="e-commerce"/><category scheme="http://www.blogger.com/atom/ns#" term="ebay"/><category scheme="http://www.blogger.com/atom/ns#" term="f-commerce"/><category scheme="http://www.blogger.com/atom/ns#" term="facebook app"/><category scheme="http://www.blogger.com/atom/ns#" term="facebook connect"/><category scheme="http://www.blogger.com/atom/ns#" term="online shopping"/><category scheme="http://www.blogger.com/atom/ns#" term="social commerce"/><title type='text'>Social Commerce - my view</title><content type='html'>What is Social commerce? &lt;div id=&quot;fb_1&quot; align=&quot;right&quot;&gt;&lt;iframe src=&quot;http://www.facebook.com/plugins/like.php?href=http://saraven.blogspot.com&amp;amp;layout=button_count&amp;amp;action=like&amp;amp;colorscheme=light&quot; frameborder=&quot;0&quot; width=&quot;90&quot; height=&quot;30&quot;&gt;&lt;/iframe&gt;&lt;/div&gt;&lt;br /&gt;Social commerce is a another dimension of e-commerce. With the social media interaction and user contributions in its side, it will promote/drive online user to buy and sell products or services.&lt;br /&gt;&lt;br /&gt;Why it gets big hype in recent timings?&lt;br /&gt;E-commerce sites target the big user bank in social networking sites like Facebook, Twitter etc. E-commerce sites want to drive traffic to their site with these platform which they can convert as a purchase.&lt;br /&gt;&lt;br /&gt;Why Facebook is in the top compared to other sites?&lt;div&gt;It&#39;s because of its user bank - &lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: rgb(51, 51, 51); font-family: &#39;lucida grande&#39;, tahoma, verdana, arial, sans-serif; font-size: 11px; line-height: 14px; background-color: rgb(255, 255, 255); &quot;&gt;&lt;i&gt;More than 800 million active users&lt;/i&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: rgb(51, 51, 51); font-family: &#39;lucida grande&#39;, tahoma, verdana, arial, sans-serif; font-size: 11px; line-height: 14px; background-color: rgb(255, 255, 255); &quot;&gt;&lt;i&gt;Average user has 130 friends&lt;/i&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: rgb(51, 51, 51); font-family: &#39;lucida grande&#39;, tahoma, verdana, arial, sans-serif; font-size: 11px; line-height: 14px; background-color: rgb(255, 255, 255); &quot;&gt;&lt;i&gt;More than 70 languages available on the site&lt;/i&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: rgb(51, 51, 51); font-family: &#39;lucida grande&#39;, tahoma, verdana, arial, sans-serif; font-size: 11px; line-height: 14px; background-color: rgb(255, 255, 255); &quot;&gt;&lt;i&gt;More than 7 million apps and websites are integrated with Facebook&lt;/i&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: rgb(51, 51, 51); font-family: &#39;lucida grande&#39;, tahoma, verdana, arial, sans-serif; font-size: 11px; line-height: 14px; background-color: rgb(255, 255, 255); &quot;&gt;&lt;i&gt;More than 350 million active users currently access Facebook through their mobile devices&lt;/i&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-style-span&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-size: 8px; line-height: 14px;&quot;&gt;Data from &lt;a href=&quot;http://www.facebook.com/press/info.php?statistics&quot;&gt;http://www.facebook.com/press/info.php?statistics&lt;/a&gt;&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;Which industries are getting hot?&lt;br /&gt;&lt;div&gt;Fashion (Clothing &amp;amp; shoes) , Electronics (which includes mobile phones, tech gadets)&lt;br /&gt;&lt;br /&gt;How I see its different from traditional E-commerce?&lt;br /&gt;&lt;ul&gt;&lt;li&gt;Group Buy – With friends and family, I can buy and make them buy.Buying something together.&lt;/li&gt;&lt;li&gt;Advise - I can get friend&#39;s advice on a prospective purchase. Same I can provide too.&lt;/li&gt;&lt;li&gt;Recommend/Review - suggesting a specific item to a friend who is looking for one with some review. &lt;/li&gt;&lt;li&gt;Share - Something like show off, what I own&lt;/li&gt;&lt;li&gt;Trust - Trust will be/can be created not only by item description but from my friends and family.&lt;/li&gt;&lt;/ul&gt;Readymade Solutions:&lt;/div&gt;&lt;div&gt;IBM social commerce, Microsoft Commerce&lt;br /&gt;&lt;br /&gt;Though we can say solutions, but it has to be tied with different departments Marketing, Analytics, PR etc&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;Prediction: $30billion revenue from social commerce market in 2015&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-style-span&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-size: 8px; line-height: 14px;&quot;&gt;Data from&lt;a href=&quot;http://www.digitalbuzzblog.com/infographic-the-value-of-social-commerce/&quot;&gt;http://www.digitalbuzzblog.com/infographic-the-value-of-social-commerce/&lt;/a&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://saraven.blogspot.com/feeds/2624093998920102056/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment/fullpage/post/7356812311849332117/2624093998920102056' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7356812311849332117/posts/default/2624093998920102056'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7356812311849332117/posts/default/2624093998920102056'/><link rel='alternate' type='text/html' href='http://saraven.blogspot.com/2011/10/social-commerce-my-view.html' title='Social Commerce - my view'/><author><name>Sarav</name><uri>http://www.blogger.com/profile/11797223671802998157</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='25' height='32' src='//blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi5bcV8nSfWmwz5OJYLhZqz2_UpNBNAGgllMP6ZDDtfW_ON3CsRscFrIsA9ToJ0BJzzU5NSI-NiIJEIuYoAINUB98Y3Bh5kyPFhs2dD887uugninF4frU6dKKElQMMXJA/s220/me.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-7356812311849332117.post-2687425109813134391</id><published>2011-07-14T15:17:00.000-07:00</published><updated>2011-07-15T16:52:13.505-07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="integer reverse"/><category scheme="http://www.blogger.com/atom/ns#" term="reverse"/><category scheme="http://www.blogger.com/atom/ns#" term="reverse logic"/><category scheme="http://www.blogger.com/atom/ns#" term="string reverse"/><title type='text'>Reverse an Integer and String</title><content type='html'>Just tried out the very basic problem today. How to reverse an integer and string? Please let me know, if i can improve anything on this.&lt;br /&gt;&lt;div id=&quot;fb_1&quot; align=&quot;right&quot;&gt;&lt;iframe src=&quot;http://www.facebook.com/plugins/like.php?href=http://saraven.blogspot.com&amp;amp;layout=button_count&amp;amp;action=like&amp;amp;colorscheme=light&quot; frameborder=&quot;0&quot; width=&quot;90&quot; height=&quot;30&quot;&gt;&lt;/iframe&gt;&lt;/div&gt;&lt;br /&gt;Integer logic  1234 = 4 *10^3+3*10^2+2*10^1+1*10^0&lt;br /&gt;String  logic Sarav= replace the indices value till you reach the middle.&lt;br /&gt;&lt;blockquote&gt;&lt;br /&gt;package com.sarav.util;&lt;br /&gt;/**&lt;br /&gt; * @author sparamasivan&lt;br /&gt; *&lt;br /&gt; */&lt;br /&gt;public class ReverseUtil {&lt;br /&gt;&lt;br /&gt; public static void main(String[] args) {&lt;br /&gt;  System.out.println(reverse(1234));&lt;br /&gt;  System.out.println(reverse(&quot;Sarav&quot;));&lt;br /&gt; }&lt;br /&gt; &lt;br /&gt; public static int reverse(int number){&lt;br /&gt;  int length=String.valueOf(number).length();&lt;br /&gt;  int reverse=0;&lt;br /&gt;  while(length&gt;0){&lt;br /&gt;   //int tens=(int)(Math.pow(10.00,length-1));&lt;br /&gt;   //reverse=reverse + ((number%10)*tens);&lt;br /&gt;   reverse=(reverse*10) + ((number%10));&lt;br /&gt;   number= number/10;&lt;br /&gt;   length--;&lt;br /&gt;  }&lt;br /&gt;  return reverse;&lt;br /&gt; }&lt;br /&gt; &lt;br /&gt; public static String reverse( String s ) {&lt;br /&gt;        int length = s.length(), last = length - 1;&lt;br /&gt;        char[] chars = s.toCharArray();&lt;br /&gt;        for ( int i = 0; i &lt; length/2; i++ ) {&lt;br /&gt;            char c = chars[i];&lt;br /&gt;            chars[i] = chars[last - i];&lt;br /&gt;            chars[last - i] = c;&lt;br /&gt;        }&lt;br /&gt;        return new String(chars);&lt;br /&gt;    }&lt;br /&gt;}&lt;br /&gt;&lt;/blockquote&gt;&lt;br /&gt;&lt;div id=&quot;fb_1&quot; align=&quot;right&quot;&gt;&lt;iframe src=&quot;http://www.facebook.com/plugins/like.php?href=http://saraven.blogspot.com&amp;amp;layout=button_count&amp;amp;action=like&amp;amp;colorscheme=light&quot; frameborder=&quot;0&quot; width=&quot;90&quot; height=&quot;30&quot;&gt;&lt;/iframe&gt;&lt;/div&gt;&lt;br /&gt;</content><link rel='replies' type='application/atom+xml' href='http://saraven.blogspot.com/feeds/2687425109813134391/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment/fullpage/post/7356812311849332117/2687425109813134391' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7356812311849332117/posts/default/2687425109813134391'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7356812311849332117/posts/default/2687425109813134391'/><link rel='alternate' type='text/html' href='http://saraven.blogspot.com/2011/07/reverse-integer-and-string.html' title='Reverse an Integer and String'/><author><name>Sarav</name><uri>http://www.blogger.com/profile/11797223671802998157</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='25' height='32' src='//blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi5bcV8nSfWmwz5OJYLhZqz2_UpNBNAGgllMP6ZDDtfW_ON3CsRscFrIsA9ToJ0BJzzU5NSI-NiIJEIuYoAINUB98Y3Bh5kyPFhs2dD887uugninF4frU6dKKElQMMXJA/s220/me.jpg'/></author><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-7356812311849332117.post-5456429177312127082</id><published>2011-07-05T15:17:00.000-07:00</published><updated>2013-09-23T10:38:43.661-07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="Avro"/><category scheme="http://www.blogger.com/atom/ns#" term="Protocol Buffers"/><title type='text'>Protocol Buffers &amp; Avro</title><content type='html'>&lt;div id=&quot;fb_1&quot; align=&quot;right&quot;&gt;&lt;iframe src=&quot;http://www.facebook.com/plugins/like.php?href=http://saraven.blogspot.com&amp;amp;layout=button_count&amp;amp;action=like&amp;amp;colorscheme=light&quot; frameborder=&quot;0&quot; width=&quot;90&quot; height=&quot;30&quot;&gt;&lt;/iframe&gt;&lt;/div&gt;&lt;br /&gt;I am consuming service from world&#39;s biggest market place for my site inventory. Current SLA for their services - ~200msec. I was stunned on hearing their new SLA for us ~20msec. Heard about their optimization happened on data serialization and digged little bit today to upgrade myself.&lt;br /&gt;&lt;br /&gt;Most server-client platforms use a serialization technique to serialize into a leaner data format, and then de-serialize on the receiving end.Many languages offer native serialization APIs, but when serializing the data using the native API, Metadata about the class is serialized into the output too. is it possible to serialize only data and not with metadata?&lt;br /&gt;&lt;br /&gt;Yes we have - Google Protocal Buffers &amp;amp; Apache Avro&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Google Protocol Buffers&lt;br /&gt;&lt;/strong&gt;Protocol Buffers is a serialization format with an interface description language developed by Google. It is available under free software, open source license. Protocol Buffers design goals are emphasized performance and simplicity. It is a language and platform neutral technology that is an extensible mechanism for serializing structured data.&lt;br /&gt;&lt;br /&gt;It works by you defining how you want your data to be structured via proto files, which are simply structure text files. Once you have decided the structure in your proto file, the proto executable is called on it, and a generated class (Adobe Actionscript 3, Java, C, C++, Python) is produced. The class can be generated into multiple different technologies, which means the class can be generated for the client and server technologies. Thus securing a data contract (which is type safe) between the two. The protocol buffer technology provides the ability to update the data structure without breaking deployed programs that are compiled against the old format.&lt;br /&gt;&lt;br /&gt;Protocol buffers claims it takes between 100 to 200 nanoseconds to parse. As the overhead of the data structure is not needed in protocol buffers, only the object fields’ values is serialized. Protocol buffers will find the most compact serialization technique for a particular data type (always primitives), and only serialize fields that are not null.&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Apache Avro&lt;br /&gt;&lt;/strong&gt;Avro is another very recent serialization system. It provides rich data structures that are compact, and are transported in a binary data format.&lt;br /&gt;&lt;br /&gt;Avro relies on a schema-based system that defines a data contract to be exchanged. When Avro data is read, the schema used when writing it is always present. Similar to Protocol Buffers, it is only the values in the data structure that are serialized and sent. The strategy employed by Avro (and Protocol Buffers), means that a minimal amount of data is generated, enabling fast transport.&lt;br /&gt;&lt;br /&gt;The schemas are equivalent to protocol buffers proto files, but they do not have to be generated. The JSON format is used to declare the data structures.&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Protocol Buffers &amp;amp; Avro&lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;Google’s Protocol buffer provides a much richer API for defining a data contract than Avro. Below is a list of features available to Protocol Buffers and not Avro:&lt;br /&gt;&lt;br /&gt;&lt;ul&gt;&lt;br /&gt;&lt;li&gt;Declare nested types&lt;/li&gt;&lt;br /&gt;&lt;li&gt;Define requires, repeated and optional fields&lt;/li&gt;&lt;br /&gt;&lt;li&gt;Specify default values on fields &lt;/li&gt;&lt;br /&gt;&lt;li&gt;Declare enumerations and set a fields default value from it &lt;/li&gt;&lt;br /&gt;&lt;li&gt;Multiple message types in the same document &lt;/li&gt;&lt;br /&gt;&lt;li&gt;Import other proto files &lt;/li&gt;&lt;br /&gt;&lt;li&gt;Declare a range of field numbers in a message available for third party extensions (Extensions) Nested Extensions &lt;/li&gt;&lt;br /&gt;&lt;li&gt;Define services &lt;/li&gt;&lt;/ul&gt;&lt;br /&gt;&lt;p&gt;Avro is only compatible with C, Java and Python, but Protocol Buffers is compatible with C, C++, Adobe Actionscript 3, Java and Python. &lt;/p&gt;&lt;br /&gt;&lt;p&gt;Now you would have guessed what that company applied for their middleware solution as a push mechanism between server and client.&lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;div id=&quot;fb_1&quot; align=&quot;right&quot;&gt;&lt;iframe src=&quot;http://www.facebook.com/plugins/like.php?href=http://saraven.blogspot.com&amp;amp;layout=button_count&amp;amp;action=like&amp;amp;colorscheme=light&quot; frameborder=&quot;0&quot; width=&quot;90&quot; height=&quot;30&quot;&gt;&lt;/iframe&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://saraven.blogspot.com/feeds/5456429177312127082/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment/fullpage/post/7356812311849332117/5456429177312127082' title='2 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7356812311849332117/posts/default/5456429177312127082'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7356812311849332117/posts/default/5456429177312127082'/><link rel='alternate' type='text/html' href='http://saraven.blogspot.com/2011/07/protocol-buffers-avro.html' title='Protocol Buffers &amp; Avro'/><author><name>Sarav</name><uri>http://www.blogger.com/profile/11797223671802998157</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='25' height='32' src='//blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi5bcV8nSfWmwz5OJYLhZqz2_UpNBNAGgllMP6ZDDtfW_ON3CsRscFrIsA9ToJ0BJzzU5NSI-NiIJEIuYoAINUB98Y3Bh5kyPFhs2dD887uugninF4frU6dKKElQMMXJA/s220/me.jpg'/></author><thr:total>2</thr:total></entry><entry><id>tag:blogger.com,1999:blog-7356812311849332117.post-5232644034087206571</id><published>2011-06-05T16:40:00.000-07:00</published><updated>2011-06-11T12:41:32.191-07:00</updated><title type='text'>How to disable the Enter key while doing form posting?</title><content type='html'>&lt;div id=&quot;fb_1&quot;&gt;&lt;iframe src=&quot;http://www.facebook.com/plugins/like.php?href=http://saraven.blogspot.com&amp;amp;layout=button_count&amp;amp;action=like&amp;amp;colorscheme=light&quot; frameborder=&quot;0&quot; width=&quot;90px&quot; height=&quot;30px&quot;&gt;&lt;/iframe&gt;&lt;/div&gt;&lt;br /&gt;&lt;br /&gt;I got a problem last week in IE browser only which blocked my production roll out. As form fields, i had a quantity field with one form refresh to update the quantity and another form button to submit.&lt;br /&gt;&lt;br /&gt;Order of my fields-  Quantity , Refresh button and submit button.&lt;br /&gt;We didn&#39;t specify any tab order. In all the browsers after entering the quantity,if user click enter button, it went to update the quantity. And only in this crapy IE, it went for form submit.&lt;br /&gt;&lt;br /&gt;Here is my simple javascript which helps to solve this problem&lt;br /&gt;&lt;br /&gt;&lt;!--script type=&quot;text/javascript&quot;--&gt;&lt;br /&gt;function handleEnter(inField, e) {&lt;br /&gt;var charCode;&lt;br /&gt;&lt;br /&gt;if(e &amp;amp;&amp;amp; e.which){&lt;br /&gt;  charCode = e.which;&lt;br /&gt;}else if(window.event){&lt;br /&gt;  e = window.event;&lt;br /&gt;  charCode = e.keyCode;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;if(charCode == 13) {&lt;br /&gt;  alert(&quot;We will update the quantity here what happen today: &quot; + inField.id);&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;&lt;!--/script--&gt;&lt;span style=&quot;font-weight:bold;&quot;&gt;Attaching the event to field&lt;/span&gt;&lt;br /&gt;Quantity: input type=&quot;text&quot; id=&quot;someInput&quot; onkeypress=&quot;handleEnter(this, event)&quot;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Did they not code properly, while writing their user agents or did they handle unwanted usecase in which my case fell down? Why this Crap alone behaving like this?&lt;br /&gt;&lt;br /&gt;&lt;div id=&quot;fb_1&quot;&gt;&lt;iframe src=&quot;http://www.facebook.com/plugins/like.php?href=http://saraven.blogspot.com&amp;amp;layout=button_count&amp;amp;action=like&amp;amp;colorscheme=light&quot; frameborder=&quot;0&quot; width=&quot;90px&quot; height=&quot;30px&quot;&gt;&lt;/iframe&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://saraven.blogspot.com/feeds/5232644034087206571/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment/fullpage/post/7356812311849332117/5232644034087206571' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7356812311849332117/posts/default/5232644034087206571'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7356812311849332117/posts/default/5232644034087206571'/><link rel='alternate' type='text/html' href='http://saraven.blogspot.com/2011/06/how-to-disable-enter-key-while-doing.html' title='How to disable the Enter key while doing form posting?'/><author><name>Sarav</name><uri>http://www.blogger.com/profile/11797223671802998157</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='25' height='32' src='//blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi5bcV8nSfWmwz5OJYLhZqz2_UpNBNAGgllMP6ZDDtfW_ON3CsRscFrIsA9ToJ0BJzzU5NSI-NiIJEIuYoAINUB98Y3Bh5kyPFhs2dD887uugninF4frU6dKKElQMMXJA/s220/me.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-7356812311849332117.post-1496104531697959285</id><published>2009-03-30T10:10:00.000-07:00</published><updated>2009-03-30T10:32:25.884-07:00</updated><title type='text'>Why Set collection has no get method?</title><content type='html'>It&#39;s a interseting question.&lt;br /&gt;&lt;br /&gt;When we are developing a tool (kind of crawler), we had this requirement.&lt;br /&gt;&lt;br /&gt;We used our own object and over ride the equals method. We were abou to use the get method in the set and finally realized set has no get method :)&lt;br /&gt;&lt;br /&gt;Pasted in the sun forum for the experts view&lt;br /&gt;&lt;br /&gt;&lt;a href=&quot;http://forums.sun.com/thread.jspa?threadID=5375529&amp;amp;tstart=0&quot;&gt;http://forums.sun.com/thread.jspa?threadID=5375529&amp;amp;tstart=0&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;Didn&#39;t get the exact answer :(&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;&lt;span style=&quot;color:#ff6666;&quot;&gt;Solution&lt;/span&gt;&lt;/strong&gt;: Set internally has a Map to identify and store the unique objects. In simple whatever objects we wil place in Set, it will go as a key in the internal Map with dummy optimized value.&lt;br /&gt;&lt;br /&gt;Carefully watching the iterator implementation of Set, it is like&lt;br /&gt;return map.keySet.iterator();&lt;br /&gt;Seems to be pretty simple implementation.&lt;br /&gt;&lt;br /&gt;But get method is not such simple implementation, it needs to be iterated the whole map to identify an object.&lt;br /&gt;&lt;br /&gt;I donno how optimized it is to traverse in HashMap, TreeMap whatever map implementation has....&lt;br /&gt;&lt;br /&gt;But still doable, I donno Why it is missing in JDK API ?</content><link rel='replies' type='application/atom+xml' href='http://saraven.blogspot.com/feeds/1496104531697959285/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment/fullpage/post/7356812311849332117/1496104531697959285' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7356812311849332117/posts/default/1496104531697959285'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7356812311849332117/posts/default/1496104531697959285'/><link rel='alternate' type='text/html' href='http://saraven.blogspot.com/2009/03/why-set-collection-has-no-get-method.html' title='Why Set collection has no get method?'/><author><name>Sarav</name><uri>http://www.blogger.com/profile/11797223671802998157</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='25' height='32' src='//blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi5bcV8nSfWmwz5OJYLhZqz2_UpNBNAGgllMP6ZDDtfW_ON3CsRscFrIsA9ToJ0BJzzU5NSI-NiIJEIuYoAINUB98Y3Bh5kyPFhs2dD887uugninF4frU6dKKElQMMXJA/s220/me.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-7356812311849332117.post-281141313626896445</id><published>2007-11-30T21:42:00.000-08:00</published><updated>2007-11-30T23:41:55.149-08:00</updated><title type='text'>Even eclipse has dependency graph.Why it is building all the projects?</title><content type='html'>Scenario:&lt;br /&gt; &lt;br /&gt;   Project A, B and C is dependent on say X.jar. I am updating the X.jar where those files are only related to Project A. But eclipse builds all the three projects,if the jar gets updated.&lt;br /&gt;&lt;br /&gt;Problem: Eclipse has all the dependencies graph(I believe) and why it is behaving like this?&lt;br /&gt;If its build only project A then lot of time will be saved.&lt;br /&gt;&lt;br /&gt;Worst case scenario will be when JDK changes (I am seeing this also as a JAR changes),so only the files which are compatiable with the latest versions and it dependencies shuld be built.&lt;br /&gt;&lt;br /&gt;It should try for the incremental build . Any thoughts guys......</content><link rel='replies' type='application/atom+xml' href='http://saraven.blogspot.com/feeds/281141313626896445/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment/fullpage/post/7356812311849332117/281141313626896445' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7356812311849332117/posts/default/281141313626896445'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7356812311849332117/posts/default/281141313626896445'/><link rel='alternate' type='text/html' href='http://saraven.blogspot.com/2007/11/even-eclipse-has-dependency-graphwhy-it.html' title='Even eclipse has dependency graph.Why it is building all the projects?'/><author><name>Sarav</name><uri>http://www.blogger.com/profile/11797223671802998157</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='25' height='32' src='//blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi5bcV8nSfWmwz5OJYLhZqz2_UpNBNAGgllMP6ZDDtfW_ON3CsRscFrIsA9ToJ0BJzzU5NSI-NiIJEIuYoAINUB98Y3Bh5kyPFhs2dD887uugninF4frU6dKKElQMMXJA/s220/me.jpg'/></author><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-7356812311849332117.post-8031758445570502515</id><published>2007-08-07T01:25:00.001-07:00</published><updated>2007-08-07T01:38:56.229-07:00</updated><title type='text'>Escape Analysis in Mustang (Java SE 6)</title><content type='html'>&lt;strong&gt;&lt;span style=&quot;font-family:verdana;font-size:85%;color:#cc0000;&quot;&gt;Escape analysis&lt;/span&gt;&lt;/strong&gt;&lt;br /&gt;&lt;span style=&quot;font-family:verdana;font-size:85%;&quot;&gt;The Java language does not offer any way to explicitly allocate an object on the stack, but this fact doesn&#39;t prevent JVMs from still using stack allocation where appropriate. JVMs can use a technique called escape analysis, by which they can tell that certain objects remain confined to a single thread for their entire lifetime, and that lifetime is bounded by the lifetime of a given stack frame. Such objects can be safely allocated on the stack instead of the heap. Even better, for small objects, the JVM can optimize away the allocation entirely and simply hoist the object&#39;s fields into registers.&lt;/span&gt;&lt;br /&gt;&lt;strong&gt;&lt;span style=&quot;font-family:verdana;font-size:85%;color:#cc0000;&quot;&gt;Escape analysis in Mustang&lt;/span&gt;&lt;/strong&gt;&lt;br /&gt;&lt;span style=&quot;font-family:verdana;font-size:85%;&quot;&gt;This analysis is an optimization that has been talked about for a long time, and it is finally here -- the current builds of Mustang can do escape analysis and convert heap allocation to stack allocation (or no allocation) where appropriate. The use of escape analysis to eliminate some allocations results in even faster average allocation times, reduced memory footprint, and fewer cache misses. Further, optimizing away some allocations reduces pressure on the garbage collector and allows collection to run less often. Escape analysis can find opportunities for stack allocation even where it might not be practical to do so in the source code, even if the language provided the option, because whether a particular allocation gets optimized away is determined based on how the result of an object-returning method is actually used in a particular code path.&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;font-size:85%;&quot;&gt;&lt;span style=&quot;font-family:verdana;&quot;&gt;&lt;strong&gt;&lt;span style=&quot;color:#ff0000;&quot;&gt;Conclusion&lt;/span&gt;&lt;/strong&gt;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;font-family:verdana;font-size:85%;&quot;&gt;JVMs are surprisingly good at figuring out things that we used to assume only the developer could know. By letting the JVM choose between stack allocation and heap allocation on a case-by-case basis, we can get the performance benefits of stack allocation without making the programmer agonize over whether to allocate on the stack or on the heap.&lt;/span&gt;</content><link rel='replies' type='application/atom+xml' href='http://saraven.blogspot.com/feeds/8031758445570502515/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment/fullpage/post/7356812311849332117/8031758445570502515' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7356812311849332117/posts/default/8031758445570502515'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7356812311849332117/posts/default/8031758445570502515'/><link rel='alternate' type='text/html' href='http://saraven.blogspot.com/2007/08/escape-analysis-in-mustang-java-se-6.html' title='Escape Analysis in Mustang (Java SE 6)'/><author><name>Sarav</name><uri>http://www.blogger.com/profile/11797223671802998157</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='25' height='32' src='//blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi5bcV8nSfWmwz5OJYLhZqz2_UpNBNAGgllMP6ZDDtfW_ON3CsRscFrIsA9ToJ0BJzzU5NSI-NiIJEIuYoAINUB98Y3Bh5kyPFhs2dD887uugninF4frU6dKKElQMMXJA/s220/me.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-7356812311849332117.post-3035660448602116240</id><published>2007-04-26T02:34:00.000-07:00</published><updated>2007-04-26T03:21:31.111-07:00</updated><title type='text'>is all string manipulations requires synchronization?</title><content type='html'>The Java language specification assures us that strings are immutable, so most operations on a string destroy the original object and create a new one. But in reality the compiler can optimize the operation and reuse the same memory as the original string. For instance we have a string ‘String stringSample = &quot;Saravanan&quot;;’ stored in memory at memory location m1. The compiler will store this String in memory as origin location = m1 and offset = 12.&lt;br /&gt;&lt;br /&gt;Now when an operation ‘stringSample = stringSample.substring(4);’ is done, stringSample will contain &quot;vanan&quot;.&lt;br /&gt;&lt;br /&gt;As per the Java specification we would assume that stringSample will be moved to a new location m2 and the old memory location is left for the garbage collector, but compilers can reuse the same memory location and update the offsets. So the new string after the sub string operation would read as origin location = m1+4 and offset = 8. This does not break the Java specification, as the old reference is lost and a new reference is created with a new origin location and a new offset. The problem is when two threads try to access this string at the same time; the second thread might get the wrong starting location.</content><link rel='replies' type='application/atom+xml' href='http://saraven.blogspot.com/feeds/3035660448602116240/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment/fullpage/post/7356812311849332117/3035660448602116240' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7356812311849332117/posts/default/3035660448602116240'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7356812311849332117/posts/default/3035660448602116240'/><link rel='alternate' type='text/html' href='http://saraven.blogspot.com/2007/04/is-all-string-manipulations-requires.html' title='is all string manipulations requires synchronization?'/><author><name>Sarav</name><uri>http://www.blogger.com/profile/11797223671802998157</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='25' height='32' src='//blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi5bcV8nSfWmwz5OJYLhZqz2_UpNBNAGgllMP6ZDDtfW_ON3CsRscFrIsA9ToJ0BJzzU5NSI-NiIJEIuYoAINUB98Y3Bh5kyPFhs2dD887uugninF4frU6dKKElQMMXJA/s220/me.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-7356812311849332117.post-2776603305849509231</id><published>2007-04-10T01:23:00.000-07:00</published><updated>2007-04-10T01:24:23.589-07:00</updated><title type='text'>is this a java bug?</title><content type='html'>class ArrayTest{ &lt;br /&gt; public static void main(String arg[])   {  &lt;br /&gt; int a[]=new int[0];  &lt;br /&gt; a[0]=5; &lt;br /&gt;}&lt;br /&gt;}&lt;br /&gt;It will compile fine,when I run this code,its saying ArrayIndexOutOfBoundException....&lt;br /&gt;As we know array declaration should have one integer value,even if I give -1 also it will compile. But in runtime it is saying NegativeIndex or ArrayIndexOutOfBound for -1 or 0 respectivley.&lt;br /&gt;&lt;br /&gt;Why it is doing like this? While doing compiling itself why don&#39;t the compiler has do that? I accept for the variable initialization since it has clue for the variable in the compilation time,but for straight forward initialization like above should caught by the compiler... is my understanding is wrong?</content><link rel='replies' type='application/atom+xml' href='http://saraven.blogspot.com/feeds/2776603305849509231/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment/fullpage/post/7356812311849332117/2776603305849509231' title='2 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7356812311849332117/posts/default/2776603305849509231'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7356812311849332117/posts/default/2776603305849509231'/><link rel='alternate' type='text/html' href='http://saraven.blogspot.com/2007/04/is-this-java-bug.html' title='is this a java bug?'/><author><name>Sarav</name><uri>http://www.blogger.com/profile/11797223671802998157</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='25' height='32' src='//blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi5bcV8nSfWmwz5OJYLhZqz2_UpNBNAGgllMP6ZDDtfW_ON3CsRscFrIsA9ToJ0BJzzU5NSI-NiIJEIuYoAINUB98Y3Bh5kyPFhs2dD887uugninF4frU6dKKElQMMXJA/s220/me.jpg'/></author><thr:total>2</thr:total></entry></feed>