tag:blogger.com,1999:blog-90376179021385670122024-02-20T08:54:04.156-08:00Sachin ThapaFun Drive with TechnologySachin Thapahttp://www.blogger.com/profile/06690382541886114339noreply@blogger.comBlogger34125tag:blogger.com,1999:blog-9037617902138567012.post-49270210337513869132017-10-22T20:22:00.001-07:002017-10-25T19:36:54.095-07:00Java 9 Collection Changes Overview<div style="height: 0px;">
</div>
<span style="font-size: small;"><b>Introduction</b></span><br />
Java 9 finally brings the convenience of creating small unmodifiable Collection instances using just one line code. New APIs make it convenient to create instances of collections and maps with small number of elements.<br />
<br />
<b>Driving Factor</b><br />
Too much code is required to be written to create a small, unmodifiable collection, which involves constructing it, then storing it in a local variable, and calling methods e.g.<br />
<pre style="background: #181818; color: #f8f8f8;"><span style="color: #f9ee98;">Set<<span style="color: #f9ee98;">String</span>></span> set <span style="color: #cda869;">=</span> <span style="color: #cda869;">new</span> <span style="color: #f9ee98;">HashSet<></span>();
set<span style="color: #cda869;">.</span>add(<span style="color: #8f9d6a;">"first"</span>);
set<span style="color: #cda869;">.</span>add(<span style="color: #8f9d6a;">"second"</span>);
set<span style="color: #cda869;">.</span>add(<span style="color: #8f9d6a;">"third"</span>);
set <span style="color: #cda869;">=</span> <span style="color: #f9ee98;">Collections</span><span style="color: #cda869;">.</span>unmodifiableSet(set);
</pre>
<br />
Alternatively one can create same using constructor method.<br />
<pre style="background: #181818; color: #f8f8f8;"><span style="color: #f9ee98;">Set<<span style="color: #f9ee98;">String</span>></span> set <span style="color: #cda869;">=</span> <span style="color: #f9ee98;">Collections</span><span style="color: #cda869;">.</span>unmodifiableSet
(<span style="color: #cda869;">new</span> <span style="color: #f9ee98;">HashSet<></span>(<span style="color: #f9ee98;">Arrays</span><span style="color: #cda869;">.</span>asList(<span style="color: #8f9d6a;">"first"</span>, <span style="color: #8f9d6a;">"second"</span>, <span style="color: #8f9d6a;">"third"</span>)));
</pre>
<br />
Or using Double brace method<br />
<pre style="background: #181818; color: #f8f8f8;"><span style="color: #f9ee98;">Set<<span style="color: #f9ee98;">String</span>></span> set <span style="color: #cda869;">=</span> <span style="color: #f9ee98;">Collections</span><span style="color: #cda869;">.</span>unmodifiableSet
(<span style="color: #cda869;">new</span> <span style="color: #f9ee98;">HashSet<<span style="color: #f9ee98;">String</span>></span>() {{
add(<span style="color: #8f9d6a;">"first"</span>);
add(<span style="color: #8f9d6a;">"second"</span>);
add(<span style="color: #8f9d6a;">"third"</span>);}});
</pre>
<br />
or using Java 8 Streams<br />
<pre style="background: #181818; color: #f8f8f8;"><span style="color: #f9ee98;">Stream</span><span style="color: #cda869;">.</span>of(<span style="color: #8f9d6a;">"first"</span>, <span style="color: #8f9d6a;">"second"</span>, <span style="color: #8f9d6a;">"third"</span>)
.collect(collectingAndThen(toSet(),
<span style="color: #f9ee98;">Collections</span><span style="color: #cda869;">:</span><span style="color: #cda869;">:</span>unmodifiableSet));
</pre>
<br />
<span style="font-size: small;"><b>New Methods </b></span><br />
<span style="font-size: small;">Java 9 provides static methods for List, Set, and Map interfaces which take the elements as arguments</span><br />
<pre style="background: #181818; color: #f8f8f8;"><span style="color: #f9ee98;">List<<span style="color: #f9ee98;">String</span>></span> list <span style="color: #cda869;">=</span> <span style="color: #f9ee98;">List</span><span style="color: #cda869;">.</span>of(<span style="color: #8f9d6a;">"first"</span>, <span style="color: #8f9d6a;">"second"</span>, <span style="color: #8f9d6a;">"third"</span>);
<span style="color: #f9ee98;">Set<<span style="color: #f9ee98;">String</span>></span> set <span style="color: #cda869;">=</span> <span style="color: #f9ee98;">Set</span><span style="color: #cda869;">.</span>of(<span style="color: #8f9d6a;">"first"</span>, <span style="color: #8f9d6a;">"second"</span>, <span style="color: #8f9d6a;">"third"</span>);
<span style="color: #f9ee98;">Map<<span style="color: #f9ee98;">Integer</span>, <span style="color: #f9ee98;">String</span>></span> map <span style="color: #cda869;">=</span> <span style="color: #f9ee98;">Map</span><span style="color: #cda869;">.</span>of(<span style="color: #cf6a4c;">1</span>, <span style="color: #8f9d6a;">"first"</span>, <span style="color: #cf6a4c;">2</span>, <span style="color: #8f9d6a;">"second"</span>);
</pre>
<br />
For maps this method is overloaded to have 0 to 10 key-value pairs, e.g.<br />
<br />
<!-- HTML generated using hilite.me --><br />
<div style="background: #202020; border-width: 0.1em 0.1em 0.1em 0.8em; border: solid gray; overflow: auto; padding: 0.2em 0.6em; width: auto;">
<pre style="line-height: 125%; margin: 0;"><span style="color: #d0d0d0;">Map<String,</span> <span style="color: #d0d0d0;">String></span> <span style="color: #24909d;">map</span> <span style="color: #d0d0d0;">=</span> <span style="color: #d0d0d0;">Map.of(</span><span style="color: #ed9d13;">"1"</span><span style="color: #d0d0d0;">,</span> <span style="color: #ed9d13;">"first"</span><span style="color: #d0d0d0;">);</span>
<span style="color: #d0d0d0;">Map<String,</span> <span style="color: #d0d0d0;">String></span> <span style="color: #24909d;">map</span> <span style="color: #d0d0d0;">=</span> <span style="color: #d0d0d0;">Map.of(</span><span style="color: #ed9d13;">"1"</span><span style="color: #d0d0d0;">,</span> <span style="color: #ed9d13;">"first"</span><span style="color: #d0d0d0;">,</span> <span style="color: #ed9d13;">"2"</span><span style="color: #d0d0d0;">,</span> <span style="color: #ed9d13;">"second"</span><span style="color: #d0d0d0;">);</span>
<span style="color: #d0d0d0;">Map<String,</span> <span style="color: #d0d0d0;">String></span> <span style="color: #24909d;">map</span> <span style="color: #d0d0d0;">=</span> <span style="color: #d0d0d0;">Map.of(</span><span style="color: #ed9d13;">"1"</span><span style="color: #d0d0d0;">,</span> <span style="color: #ed9d13;">"first"</span><span style="color: #d0d0d0;">,</span> <span style="color: #ed9d13;">"2"</span><span style="color: #d0d0d0;">,</span> <span style="color: #ed9d13;">"second"</span><span style="color: #d0d0d0;">,</span> <span style="color: #ed9d13;">"3"</span><span style="color: #d0d0d0;">,</span> <span style="color: #ed9d13;">"third"</span><span style="color: #d0d0d0;">);</span>
</pre>
</div>
<br />
Similarly you can have up to ten entries.<br />
<br />
For a case where we have more than 10 key-value pairs, there is a different method:<br />
<!-- HTML generated using hilite.me --><br />
<div style="background: #202020; border-width: 0.1em 0.1em 0.1em 0.8em; border: solid gray; overflow: auto; padding: 0.2em 0.6em; width: auto;">
<pre style="line-height: 125%; margin: 0;"><span style="color: #d0d0d0;">static</span> <span style="color: #d0d0d0;"><K,V></span> <span style="color: #d0d0d0;">Map<K,V></span> <span style="color: #d0d0d0;">ofEntries(Map.Entry<</span><span style="background-color: #e3d2d2; color: #a61717;">?</span> <span style="color: #d0d0d0;">extends</span> <span style="color: #d0d0d0;">K,</span><span style="background-color: #e3d2d2; color: #a61717;">?</span> <span style="color: #d0d0d0;">extends</span> <span style="color: #d0d0d0;">V>...</span> <span style="color: #d0d0d0;">entries)</span>
</pre>
</div>
<br />
Java 9 has definitely made creating collection so easy.<br />
<br />
<br />Sachin Thapahttp://www.blogger.com/profile/06690382541886114339noreply@blogger.com0tag:blogger.com,1999:blog-9037617902138567012.post-86283443377268923862017-05-03T20:24:00.002-07:002017-10-22T20:34:18.262-07:00Java 8 streams performance on mathematical calculations Java 8 Streams API supports many parallel operations to process the data, it abstracts low level multithreading logic. To test performance did following simple test to calculate factorial of first X number starting with N.<br />
<div>
<br /></div>
Following program calculates factorial of first 1000 numbers.<br />
<br />
<pre style="background:#002240;color:#fff"><span style="color:#ff9d00">package</span> <span style="color:#ffee80">com.java.examples</span>;
<span style="color:#ff9d00">import</span> <span style="color:#ffee80">java.math.BigInteger</span>;
<span style="color:#ff9d00">import</span> <span style="color:#ffee80">java.time.Duration</span>;
<span style="color:#ff9d00">import</span> <span style="color:#ffee80">java.time.Instant</span>;
<span style="color:#ff9d00">import</span> <span style="color:#ffee80">java.util.ArrayList</span>;
<span style="color:#ff9d00">import</span> <span style="color:#ffee80">java.util.List</span>;
<span style="color:#ffee80">public</span> <span style="color:#ffee80">class</span> <span style="color:#fd0">MathCalculation</span> {
<span style="color:#ffee80">public</span> <span style="color:#ffee80">static</span> <span style="color:#ffee80">void</span> <span style="color:#fd0">main</span>(<span style="color:#ffee80">String</span>[] <span style="color:#ccc">args</span>) {
<span style="color:#ffee80">List</span> <span style="color:#ff9d00"><</span> <span style="color:#ffee80">Runnable</span> <span style="color:#ff9d00">></span> runnables <span style="color:#ff9d00">=</span> generateRunnables<span style="color:#e1efff">(</span><span style="color:#ff628c">1</span><span style="color:#e1efff">,</span> <span style="color:#ff628c">1000</span><span style="color:#e1efff">)</span><span style="color:#e1efff">;</span>
<span style="color:#ffee80">Instant</span> start <span style="color:#ff9d00">=</span> <span style="color:#ffee80">Instant</span><span style="color:#ff9d00">.</span>now<span style="color:#e1efff">(</span><span style="color:#e1efff">)</span><span style="color:#e1efff">;</span>
<span style="color:#08f;font-style:italic"><span style="color:#e1efff">//</span> Comment one of the lines below to test parallel or sequential streams</span>
runnables<span style="color:#ff9d00">.</span>parallelStream<span style="color:#e1efff">(</span><span style="color:#e1efff">)</span><span style="color:#ff9d00">.</span>forEach<span style="color:#e1efff">(</span>r <span style="color:#ff9d00">-</span><span style="color:#ff9d00">></span> r<span style="color:#ff9d00">.</span>run<span style="color:#e1efff">(</span><span style="color:#e1efff">)</span><span style="color:#e1efff">)</span><span style="color:#e1efff">;</span>
<span style="color:#08f;font-style:italic"><span style="color:#e1efff">//</span> runnables.stream().forEach(r -> r.run());</span>
<span style="color:#ffee80">Instant</span> end <span style="color:#ff9d00">=</span> <span style="color:#ffee80">Instant</span><span style="color:#ff9d00">.</span>now<span style="color:#e1efff">(</span><span style="color:#e1efff">)</span><span style="color:#e1efff">;</span>
<span style="color:#ffee80">System</span><span style="color:#ff9d00">.</span>out<span style="color:#ff9d00">.</span>println<span style="color:#e1efff">(</span><span style="color:#3ad900">"</span>Calculated in <span style="color:#3ad900">"</span> <span style="color:#ff9d00">+</span> <span style="color:#ffee80">Duration</span><span style="color:#ff9d00">.</span>between<span style="color:#e1efff">(</span>start<span style="color:#e1efff">,</span> end<span style="color:#e1efff">)</span><span style="color:#e1efff">)</span><span style="color:#e1efff">;</span>
}
<span style="color:#ffee80">private</span> <span style="color:#ffee80">static</span> <span style="color:#ffee80">void</span> <span style="color:#fd0">factorial</span>(<span style="color:#ffee80">int</span> <span style="color:#ccc">number</span>) {
<span style="color:#ffee80">int</span> i<span style="color:#e1efff">;</span>
<span style="color:#ffee80">BigInteger</span> fact <span style="color:#ff9d00">=</span> <span style="color:#ffee80">BigInteger</span><span style="color:#ff9d00">.</span>valueOf<span style="color:#e1efff">(</span><span style="color:#ff628c">1</span><span style="color:#e1efff">)</span><span style="color:#e1efff">;</span>
<span style="color:#ff9d00">for</span> (i <span style="color:#ff9d00">=</span> <span style="color:#ff628c">1</span><span style="color:#e1efff">;</span> i <span style="color:#ff9d00"><=</span> number<span style="color:#e1efff">;</span> i<span style="color:#ff9d00">++</span>) {
fact <span style="color:#ff9d00">=</span> fact<span style="color:#ff9d00">.</span>multiply<span style="color:#e1efff">(</span><span style="color:#ffee80">BigInteger</span><span style="color:#ff9d00">.</span>valueOf<span style="color:#e1efff">(</span>i<span style="color:#e1efff">)</span><span style="color:#e1efff">)</span><span style="color:#e1efff">;</span>
}
<span style="color:#ffee80">System</span><span style="color:#ff9d00">.</span>out<span style="color:#ff9d00">.</span>println<span style="color:#e1efff">(</span><span style="color:#3ad900">"</span>Factorial of <span style="color:#3ad900">"</span> <span style="color:#ff9d00">+</span> number <span style="color:#ff9d00">+</span> <span style="color:#3ad900">"</span> is: <span style="color:#3ad900">"</span> <span style="color:#ff9d00">+</span> fact<span style="color:#e1efff">)</span><span style="color:#e1efff">;</span>
}
<span style="color:#ffee80">private</span> <span style="color:#ffee80">static</span> <span style="color:#ffee80">List</span> < <span style="color:#ffee80">Runnable</span> > <span style="color:#fd0">generateRunnables</span>(<span style="color:#ffee80">Integer</span> <span style="color:#ccc">num</span>, <span style="color:#ffee80">int</span> <span style="color:#ccc">count</span>) {
<span style="color:#ffee80">List</span> <span style="color:#ff9d00"><</span> <span style="color:#ffee80">Runnable</span> <span style="color:#ff9d00">></span> l <span style="color:#ff9d00">=</span> <span style="color:#ff9d00">new</span> <span style="color:#ffee80">ArrayList</span> < <span style="color:#ffee80">Runnable</span> > ()<span style="color:#e1efff">;</span>
<span style="color:#ff9d00">for</span> (<span style="color:#ffee80">int</span> i <span style="color:#ff9d00">=</span> <span style="color:#ff628c">0</span><span style="color:#e1efff">;</span> i <span style="color:#ff9d00"><</span> count<span style="color:#e1efff">;</span> i<span style="color:#ff9d00">++</span>) {
<span style="color:#ffee80">int</span> n <span style="color:#ff9d00">=</span> num <span style="color:#ff9d00">+</span> i<span style="color:#e1efff">;</span>
<span style="color:#ffee80">Runnable</span> r <span style="color:#ff9d00">=</span> () <span style="color:#ff9d00">-</span><span style="color:#ff9d00">></span> {
factorial<span style="color:#e1efff">(</span>n<span style="color:#e1efff">)</span><span style="color:#e1efff">;</span>
}<span style="color:#e1efff">;</span>
l<span style="color:#ff9d00">.</span>add<span style="color:#e1efff">(</span>r<span style="color:#e1efff">)</span><span style="color:#e1efff">;</span>
}
<span style="color:#ff9d00">return</span> l<span style="color:#e1efff">;</span>
}
<span style="color:#e1efff">}</span>
</pre>
<br />
<br />
Results:<br />
<div>
<br />
Parallel stream -> 0.765S </div>
<div>
Sequential stream -> 0.849S<br />
<span style="font-family: "monaco"; font-size: 11px;"><br /></span>
This is just one example to demonstrate how Streams can improve performance, there are several use cases. Also notice how Java 8 changes the way we use to write programs before this version was released.<br />
<span style="font-family: "monaco"; font-size: 11px;"><br /></span>
<span style="font-family: "monaco"; font-size: 11px;"><br /></span>
<style type="text/css">
p.p1 {margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Monaco}
</style>
<br />
<br /></div>
Sachin Thapahttp://www.blogger.com/profile/06690382541886114339noreply@blogger.com0tag:blogger.com,1999:blog-9037617902138567012.post-75005108128232042952017-04-27T18:36:00.001-07:002017-04-27T19:55:10.202-07:00Mobile TestingMobile application testing falls into broadly two types:<br />
<div>
<br /></div>
<div>
<b>Hardware Testing</b></div>
<div>
This includes testing internal hardware, screen size, resolution, space, camera, Bluetooth, WIFI etc.</div>
<div>
<br /></div>
<div>
<b>Software or Application Testing</b></div>
<div>
This includes testing the application that are running on device. Because of types of apps this can be divided into following categories:</div>
<div>
<ul>
<li>Native apps</li>
<li>Mobile web apps</li>
<li>Hybrid apps</li>
</ul>
</div>
<div>
There are some key things to be considered when testing mobile apps:</div>
<div>
<ul>
<li>Native apps have single platform</li>
<li>Native apps are written in platforms like SDKs while Mobile web are written in html, css</li>
<li>Native/Hybrid apps may or may not require internet connection</li>
<li>Mobile web apps require internet connection</li>
<li>Native/Hybrid apps are downloaded from playstore</li>
<li>Mobile web apps are accessible from internet</li>
</ul>
</div>
<div>
<b>Mobile Testing complexity in comparison web applications</b></div>
<div>
<ul>
<li>Different range of mobile devices, screen sizes etc.</li>
<li>Various manufactures customizations</li>
<li>OS types iOS, Android, Windows etc.</li>
<li>Different versions of OS e.g. Android 4.x, 5.x, 6.x, 7.x</li>
<li>Spectrum of mobile networks GSM, CDMA 3G/4G</li>
<li>Frequent updates (security patches)</li>
</ul>
</div>
<div>
<b>Manual or Automation ?</b></div>
<div>
Both have advantages and disadvantages similar to web application testing</div>
<div>
<u>Manual Testing </u>: Usability, Ad-hoc test cases</div>
<div>
<u>Automation Testing</u> : Regression testing, Repeated Execution of use cases</div>
<div>
<br /></div>
<div>
<b>Top open source Mobile Testing Frameworks</b><br />
<style type="text/css"><!--td {border: 1px solid #ccc;}br {mso-data-placement:same-cell;}--></style>
<br />
<table border="1" cellpadding="0" cellspacing="0" dir="ltr" style="border-collapse: collapse; border: none; font-family: arial,sans,sans-serif; font-size: 13px; table-layout: fixed;"><colgroup><col width="113"></col><col width="64"></col><col width="48"></col><col width="81"></col><col width="81"></col><col width="135"></col><col width="100"></col></colgroup><tbody>
<tr style="height: 21px;"><td data-sheets-value="{"1":2,"2":"Testing Tool"}" style="background-color: #76a5af; border-color: rgb(0, 0, 0); padding: 2px 3px; vertical-align: bottom;">Testing Tool</td><td data-sheets-value="{"1":2,"2":"Android"}" style="background-color: #76a5af; border-bottom-color: rgb(0, 0, 0); border-right-color: rgb(0, 0, 0); border-top-color: rgb(0, 0, 0); padding: 2px 3px; vertical-align: bottom;">Android</td><td data-sheets-value="{"1":2,"2":"IOS"}" style="background-color: #76a5af; border-bottom-color: rgb(0, 0, 0); border-right-color: rgb(0, 0, 0); border-top-color: rgb(0, 0, 0); padding: 2px 3px; vertical-align: bottom;">IOS</td><td data-sheets-value="{"1":2,"2":"Native Apps"}" style="background-color: #76a5af; border-bottom-color: rgb(0, 0, 0); border-right-color: rgb(0, 0, 0); border-top-color: rgb(0, 0, 0); padding: 2px 3px; vertical-align: bottom;">Native Apps</td><td data-sheets-value="{"1":2,"2":"Hybrid Apps"}" style="background-color: #76a5af; border-bottom-color: rgb(0, 0, 0); border-right-color: rgb(0, 0, 0); border-top-color: rgb(0, 0, 0); padding: 2px 3px; vertical-align: bottom;">Hybrid Apps</td><td data-sheets-value="{"1":2,"2":"Scripting Language"}" style="background-color: #76a5af; border-bottom-color: rgb(0, 0, 0); border-right-color: rgb(0, 0, 0); border-top-color: rgb(0, 0, 0); padding: 2px 3px; vertical-align: bottom;">Scripting Language</td><td data-sheets-value="{"1":2,"2":"Test same app"}" style="background-color: #76a5af; border-bottom-color: rgb(0, 0, 0); padding: 2px 3px; vertical-align: bottom;">Test same app</td></tr>
<tr style="height: 21px;"><td data-sheets-value="{"1":2,"2":"Appium"}" style="background-color: #fff2cc; border-bottom-color: rgb(0, 0, 0); border-left-color: rgb(0, 0, 0); border-right-color: rgb(0, 0, 0); padding: 2px 3px; vertical-align: bottom;">Appium</td><td data-sheets-value="{"1":2,"2":"Y"}" style="border-bottom-color: rgb(0, 0, 0); border-right-color: rgb(0, 0, 0); padding: 2px 3px; vertical-align: bottom;">Y</td><td data-sheets-value="{"1":2,"2":"Y"}" style="border-bottom-color: rgb(0, 0, 0); border-right-color: rgb(0, 0, 0); padding: 2px 3px; vertical-align: bottom;">Y</td><td data-sheets-value="{"1":2,"2":"Y"}" style="border-bottom-color: rgb(0, 0, 0); border-right-color: rgb(0, 0, 0); padding: 2px 3px; vertical-align: bottom;">Y</td><td data-sheets-value="{"1":2,"2":"Y"}" style="border-bottom-color: rgb(0, 0, 0); border-right-color: rgb(0, 0, 0); padding: 2px 3px; vertical-align: bottom;">Y</td><td data-sheets-value="{"1":2,"2":"Almost any"}" style="border-bottom-color: rgb(0, 0, 0); border-right-color: rgb(0, 0, 0); padding: 2px 3px; vertical-align: bottom;">Almost any</td><td data-sheets-value="{"1":2,"2":"Y"}" style="border-bottom-color: rgb(0, 0, 0); border-right-color: rgb(0, 0, 0); padding: 2px 3px; vertical-align: bottom;">Y</td></tr>
<tr style="height: 21px;"><td data-sheets-value="{"1":2,"2":"Robotium"}" style="background-color: #fff2cc; border-bottom-color: rgb(0, 0, 0); border-left-color: rgb(0, 0, 0); border-right-color: rgb(0, 0, 0); padding: 2px 3px; vertical-align: bottom;">Robotium</td><td data-sheets-value="{"1":2,"2":"Y"}" style="border-bottom-color: rgb(0, 0, 0); border-right-color: rgb(0, 0, 0); padding: 2px 3px; vertical-align: bottom;">Y</td><td data-sheets-value="{"1":2,"2":"N"}" style="border-bottom-color: rgb(0, 0, 0); border-right-color: rgb(0, 0, 0); padding: 2px 3px; vertical-align: bottom;">N</td><td data-sheets-value="{"1":2,"2":"Y"}" style="border-bottom-color: rgb(0, 0, 0); border-right-color: rgb(0, 0, 0); padding: 2px 3px; vertical-align: bottom;">Y</td><td data-sheets-value="{"1":2,"2":"Y"}" style="border-bottom-color: rgb(0, 0, 0); border-right-color: rgb(0, 0, 0); padding: 2px 3px; vertical-align: bottom;">Y</td><td data-sheets-value="{"1":2,"2":"Java"}" style="border-bottom-color: rgb(0, 0, 0); border-right-color: rgb(0, 0, 0); padding: 2px 3px; vertical-align: bottom;">Java</td><td data-sheets-value="{"1":2,"2":"N"}" style="border-bottom-color: rgb(0, 0, 0); border-right-color: rgb(0, 0, 0); padding: 2px 3px; vertical-align: bottom;">N</td></tr>
<tr style="height: 21px;"><td data-sheets-value="{"1":2,"2":"Selendroid"}" style="background-color: #fff2cc; border-bottom-color: rgb(0, 0, 0); border-left-color: rgb(0, 0, 0); border-right-color: rgb(0, 0, 0); padding: 2px 3px; vertical-align: bottom;">Selendroid</td><td data-sheets-value="{"1":2,"2":"Y"}" style="border-bottom-color: rgb(0, 0, 0); border-right-color: rgb(0, 0, 0); padding: 2px 3px; vertical-align: bottom;">Y</td><td data-sheets-value="{"1":2,"2":"N"}" style="border-bottom-color: rgb(0, 0, 0); border-right-color: rgb(0, 0, 0); padding: 2px 3px; vertical-align: bottom;">N</td><td data-sheets-value="{"1":2,"2":"Y"}" style="border-bottom-color: rgb(0, 0, 0); border-right-color: rgb(0, 0, 0); padding: 2px 3px; vertical-align: bottom;">Y</td><td data-sheets-value="{"1":2,"2":"Y"}" style="border-bottom-color: rgb(0, 0, 0); border-right-color: rgb(0, 0, 0); padding: 2px 3px; vertical-align: bottom;">Y</td><td data-sheets-value="{"1":2,"2":"Selenium 2 API"}" style="border-bottom-color: rgb(0, 0, 0); border-right-color: rgb(0, 0, 0); padding: 2px 3px; vertical-align: bottom;">Selenium 2 API</td><td data-sheets-value="{"1":2,"2":"N"}" style="border-bottom-color: rgb(0, 0, 0); border-right-color: rgb(0, 0, 0); padding: 2px 3px; vertical-align: bottom;">N</td></tr>
<tr style="height: 21px;"><td data-sheets-value="{"1":2,"2":"Keep it Functional"}" style="background-color: #fff2cc; border-bottom-color: rgb(0, 0, 0); border-left-color: rgb(0, 0, 0); border-right-color: rgb(0, 0, 0); padding: 2px 3px; vertical-align: bottom;">Keep it Functional</td><td data-sheets-value="{"1":2,"2":"N"}" style="border-bottom-color: rgb(0, 0, 0); border-right-color: rgb(0, 0, 0); padding: 2px 3px; vertical-align: bottom;">N</td><td data-sheets-value="{"1":2,"2":"Y"}" style="border-bottom-color: rgb(0, 0, 0); border-right-color: rgb(0, 0, 0); padding: 2px 3px; vertical-align: bottom;">Y</td><td data-sheets-value="{"1":2,"2":"Y"}" style="border-bottom-color: rgb(0, 0, 0); border-right-color: rgb(0, 0, 0); padding: 2px 3px; vertical-align: bottom;">Y</td><td data-sheets-value="{"1":2,"2":"Y"}" style="border-bottom-color: rgb(0, 0, 0); border-right-color: rgb(0, 0, 0); padding: 2px 3px; vertical-align: bottom;">Y</td><td data-sheets-value="{"1":2,"2":"Objection C"}" style="border-bottom-color: rgb(0, 0, 0); border-right-color: rgb(0, 0, 0); padding: 2px 3px; vertical-align: bottom;">Objection C</td><td data-sheets-value="{"1":2,"2":"Y"}" style="border-bottom-color: rgb(0, 0, 0); border-right-color: rgb(0, 0, 0); padding: 2px 3px; vertical-align: bottom;">Y</td></tr>
<tr style="height: 21px;"><td data-sheets-value="{"1":2,"2":"Monkey Talk"}" style="background-color: #fff2cc; border-bottom-color: rgb(0, 0, 0); border-left-color: rgb(0, 0, 0); border-right-color: rgb(0, 0, 0); padding: 2px 3px; vertical-align: bottom;">Monkey Talk</td><td data-sheets-value="{"1":2,"2":"Y"}" style="border-bottom-color: rgb(0, 0, 0); border-right-color: rgb(0, 0, 0); padding: 2px 3px; vertical-align: bottom;">Y</td><td data-sheets-value="{"1":2,"2":"Y"}" style="border-bottom-color: rgb(0, 0, 0); border-right-color: rgb(0, 0, 0); padding: 2px 3px; vertical-align: bottom;">Y</td><td data-sheets-value="{"1":2,"2":"Y"}" style="border-bottom-color: rgb(0, 0, 0); border-right-color: rgb(0, 0, 0); padding: 2px 3px; vertical-align: bottom;">Y</td><td data-sheets-value="{"1":2,"2":"Y"}" style="border-bottom-color: rgb(0, 0, 0); border-right-color: rgb(0, 0, 0); padding: 2px 3px; vertical-align: bottom;">Y</td><td data-sheets-value="{"1":2,"2":"Monkey Talk Script/JS"}" style="border-bottom-color: rgb(0, 0, 0); border-right-color: rgb(0, 0, 0); padding: 2px 3px; vertical-align: bottom;">Monkey Talk Script/JS</td><td data-sheets-value="{"1":2,"2":"N"}" style="border-bottom-color: rgb(0, 0, 0); border-right-color: rgb(0, 0, 0); padding: 2px 3px; vertical-align: bottom;">N</td></tr>
</tbody></table>
<b><br /></b></div>
<div>
<b>Recommended - Appium</b></div>
<div>
<ul>
<li>Test the same app you submit to the marketplace. </li>
<li>Write your tests in any framework, using any language. </li>
<li>Standard automation specification and API. </li>
<li>Large open-source community effort. </li>
</ul>
</div>
<div>
<b>Cloud based mobile testing solutions</b><br />
<ul>
<li>Perfecto Mobile</li>
<li>DeviceAnywhere</li>
</ul>
</div>
<div>
<br /></div>
<style type="text/css"><!--td {border: 1px solid #ccc;}br {mso-data-placement:same-cell;}--></style>Sachin Thapahttp://www.blogger.com/profile/06690382541886114339noreply@blogger.com0tag:blogger.com,1999:blog-9037617902138567012.post-57922702112368438972017-03-30T19:53:00.001-07:002017-03-30T19:55:17.574-07:00Java keytool to create keypairUse following command to create a public/private keypair using java keytool command.<br />
<br />
<i>keytool -genkey -keyalg RSA -alias mykeystore -keystore keystore.jks -validity 30 -keysize 2048</i><br />
<br />
Once you run the command follow the steps to complete generation of keypair, make sure you remember the password that you provide during generation.<br />
<br />Sachin Thapahttp://www.blogger.com/profile/06690382541886114339noreply@blogger.com0tag:blogger.com,1999:blog-9037617902138567012.post-13714225873045997352017-03-30T19:04:00.000-07:002017-05-02T11:42:52.144-07:00Windows to Mac cheatsheetFor any user who moves from windows to Mac here are some frequently used shortcuts that we commonly use on windows<br />
<br />
<b>Task Manager</b><br />
<span style="background-color: white; color: #222222; font-family: , ".sfnsdisplay-regular" , "open sans" , sans-serif;"><span style="font-size: x-small;">Command+Option+Esc</span></span><br />
<span style="background-color: white; color: #222222; font-family: , ".sfnsdisplay-regular" , "open sans" , sans-serif; font-size: 16px;"><br /></span><span style="background-color: white; color: #222222; font-family: , ".sfnsdisplay-regular" , "open sans" , sans-serif; font-size: 16px;"><b>Screenshot</b></span><br />
<span style="background-color: white; color: #222222; font-family: , ".sfnsdisplay-regular" , "open sans" , sans-serif; font-size: x-small;">Shift+Command+4</span><br />
<div>
<span style="background-color: white; color: #222222; font-family: , ".sfnsdisplay-regular" , "open sans" , sans-serif; font-size: 16px;"><br /></span>
<span style="background-color: white; color: #222222; font-family: , ".sfnsdisplay-regular" , "open sans" , sans-serif; font-size: 16px;"><b>Eclipse Preferences</b></span><br />
<span style="background-color: white; color: #222222; font-family: , ".sfnsdisplay-regular" , "open sans" , sans-serif; font-size: 16px;">Unlike Windows where they are under Window -> preferences, on mac they are under eclipse -> preferences</span></div>
Sachin Thapahttp://www.blogger.com/profile/06690382541886114339noreply@blogger.com0tag:blogger.com,1999:blog-9037617902138567012.post-33631576459357975052016-08-22T19:30:00.000-07:002016-08-22T19:30:05.407-07:00Gulp command not found on Mac OSXWas getting following error after installing gulp on mac.<br />
<br />
<div class="p1">
<span class="s1" style="background-color: #eeeeee;">Sachins-MBP:MyApp sachin$ gulp</span></div>
<br />
<div class="p1">
<span class="s1" style="background-color: #eeeeee;">-bash: gulp: command not found</span></div>
<div class="p1">
<span class="s1"><br /></span></div>
After fighting for hours and searching on internet, tuned out to be a very simple fix. While installing gulp missed the parameter to install globally.<br />
<br />
<span style="background-color: #eeeeee;">Sachins-MBP:MyApp sachin$ npm install -g gulp</span><br />
<br />
Yay !!!! Its working, thought to write to save time for somebody else.Sachin Thapahttp://www.blogger.com/profile/06690382541886114339noreply@blogger.com0tag:blogger.com,1999:blog-9037617902138567012.post-53729533648118402392016-08-15T14:03:00.003-07:002017-10-22T20:40:41.541-07:00MQTT : Android step by step guide using Eclipse Paho<div dir="ltr" style="text-align: left;" trbidi="on">
For MQTT integration, recently explored Paho Android project, very simple to use, here are the steps:<br />
<br />
Intialize a client, set required options and connect.<br />
<br />
MqttAndroidClient mqttClient = new MqttAndroidClient(BaseApplication.getAppContext(), broker, MQTT_CLIENT_ID);<br />
//Set call back class<br />
mqttClient.setCallback(new MqttCallbackHandler(BaseApplication.getAppContext()));<br />
MqttConnectOptions connOpts = new MqttConnectOptions();<br />
IMqttToken token = mqttClient.connect(connOpts);<br />
<br />
Subscribe to a topic.<br />
<br />
token.setActionCallback(new IMqttActionListener() {<br />
@Override<br />
public void onSuccess(IMqttToken arg0) {<br />
mqttClient.subscribe("TOPIC_NAME" + userId, 2, null, new IMqttActionListener() {<br />
@Override<br />
public void onSuccess(IMqttToken asyncActionToken) {<br />
Log.d(LOG_TAG, "Successfully subscribed to topic.");<br />
}<br />
<br />
@Override<br />
public void onFailure(IMqttToken asyncActionToken, Throwable exception) {<br />
Log.d(LOG_TAG, "Failed to subscribed to topic.");<br />
}<br />
});<br />
}<br />
<br />
@Override<br />
public void onFailure(IMqttToken arg0, Throwable arg1) {<br />
Log.d(LOG_TAG, errorMsg);<br />
}<br />
});<br />
<br />
Define your callback handler class.<br />
<br />
public class MqttCallbackHandler implements MqttCallbackExtended {<br />
@Override<br />
public void connectComplete(boolean b, String s) {<br />
Log.w("mqtt", s);<br />
}<br />
<br />
@Override<br />
public void connectionLost(Throwable throwable) {<br />
<br />
}<br />
<br />
@Override<br />
public void messageArrived(String topic, MqttMessage mqttMessage) throws Exception {<br />
Log.w("Anjing", mqttMessage.toString());<br />
}<br />
<br />
@Override<br />
public void deliveryComplete(IMqttDeliveryToken iMqttDeliveryToken) {<br />
<br />
}<br />
}<br />
<br />
Also set following in manifest file.<br />
<br />
<service android:name="org.eclipse.paho.android.service.MqttService" ><br />
</service><br />
<br />
Would recommend visiting their project on GitHub and going through samples online.<br />
<br />
<a href="https://github.com/eclipse/paho.mqtt.android">https://github.com/eclipse/paho.mqtt.android</a><br />
<br />
Hoping this helps.<br />
<br />
Cheers !<br />
<br />
<br /></div>
Sachin Thapahttp://www.blogger.com/profile/06690382541886114339noreply@blogger.com0tag:blogger.com,1999:blog-9037617902138567012.post-32559622779872419532014-11-03T21:29:00.001-08:002014-11-03T21:47:58.470-08:00Parsing mailing address in JavaRecently came across a problem to parse postal address String using Java, did some research here are some findings.<br />
<br />
Given<br />
<blockquote class="tr_bq">
String s = "60 Strawberry Hill Ave Stamford CT 06901"</blockquote>
Required Result<br />
<blockquote class="tr_bq">
Street = Strawberry Hill Ave<br />
City = Stamford<br />
Number = 60<br />
zip = 06901<br />
state = CT</blockquote>
You can use <a href="http://jgeocoder.sourceforge.net/parser.html">JGeocoder</a><br />
<br />
<b>public static void main(String[] args) {</b><br />
<blockquote class="tr_bq">
<b>Map<AddressComponent, String> parsedAddr = AddressParser.parseAddress("Google Inc, 1600 Amphitheatre Parkway, Mountain View, CA 94043");<br />System.out.println(parsedAddr);<br /> <br />Map<AddressComponent, String> normalizedAddr = AddressStandardizer.normalizeParsedAddress(parsedAddr);<br /> System.out.println(normalizedAddr);</b></blockquote>
<blockquote class="tr_bq">
<b>}</b></blockquote>
Output will be:<br />
<br />
<blockquote class="tr_bq">
<b>{street=Amphitheatre, city=Mountain View, number=1600, zip=94043, state=CA, name=Google Inc, type=Parkway}<br />{street=AMPHITHEATRE, city=MOUNTAIN VIEW, number=1600, zip=94043, state=CA, name=GOOGLE INC, type=PKWY}</b></blockquote>
<br />
There is another library <a href="http://address-parser.net/documentation/documentation.php#samplecode">International Address Parser</a> , it provides a trial version. It supports country as well.<br />
<br />
<br />
<div>
AddressParser addressParser = AddressParser.getInstance();<br />
AddressStandardizer standardizer = AddressStandardizer.getInstance(); <br />
AddressFormater formater = AddressFormater.getInstance();<br />
String rawAddress = "101 Avenue des Champs-Elysées 75008 Paris";<br />
<br />
//you can try to detect the country<br />
CountryDetector detector = CountryDetector.getInstance();<br />
String countryCode = detector.getCountryCode("7580 Commerce Center Dr ALABAMA");<br />
System.out.println("detected country=" + countryCode);<br />
<br /></div>
Also, please check <a href="http://address-parser.net/documentation/documentation.php#implemetedcountries">Implemented Countries</a><br />
<br />
Hope you find this helpful<br />
<br />
Cheers !!<br />
<br />
<br />
<br />
<blockquote class="tr_bq">
</blockquote>
<blockquote class="tr_bq">
</blockquote>
Sachin Thapahttp://www.blogger.com/profile/06690382541886114339noreply@blogger.com0tag:blogger.com,1999:blog-9037617902138567012.post-24383548986813218552013-07-30T20:28:00.003-07:002013-07-30T20:28:44.133-07:00Clean and Simple Email Sender Design<div dir="ltr" style="text-align: left;" trbidi="on">
<span style="font-family: Arial, 'Liberation Sans', 'DejaVu Sans', sans-serif; font-size: 14px; line-height: 18px;">Recently review design for an email sender with following requirements:</span><br />
<br />
<ol style="background-color: white; border: 0px; font-family: Arial, 'Liberation Sans', 'DejaVu Sans', sans-serif; font-size: 14px; line-height: 18px; list-style-image: initial; list-style-position: initial; margin: 0px 0px 1em 30px; padding: 0px; vertical-align: baseline;">
<li style="background-color: transparent; border: 0px; margin: 0px; padding: 0px; vertical-align: baseline; word-wrap: break-word;">Build a service to send email</li>
<li style="background-color: transparent; border: 0px; margin: 0px; padding: 0px; vertical-align: baseline; word-wrap: break-word;">Service must have failover recovery, in youcase if system goes down and comes back up it should still send out pending email reminders</li>
<li style="background-color: transparent; border: 0px; margin: 0px; padding: 0px; vertical-align: baseline; word-wrap: break-word;">You are not expecting any acknowledgements for the messages sent.</li>
</ol>
<div>
<span style="font-family: Arial, Liberation Sans, DejaVu Sans, sans-serif;"><span style="font-size: 14px; line-height: 18px;">The design proposal in place was to use a funky framework with persistence store etc etc. </span></span></div>
<div>
<span style="font-family: Arial, Liberation Sans, DejaVu Sans, sans-serif;"><span style="font-size: 14px; line-height: 18px;"><br /></span></span></div>
<div>
<span style="font-family: Arial, Liberation Sans, DejaVu Sans, sans-serif;"><span style="font-size: 14px; line-height: 18px;">After going through the simple requirements stated above, used following clean and simple design and I am happy to say we made right decision:</span></span></div>
<div>
<span style="font-family: Arial, Liberation Sans, DejaVu Sans, sans-serif;"><span style="font-size: 14px; line-height: 18px;"><br /></span></span></div>
<div>
<ol style="background-color: white; border: 0px; font-family: Arial, 'Liberation Sans', 'DejaVu Sans', sans-serif; font-size: 14px; line-height: 18px; list-style-image: initial; list-style-position: initial; margin: 0px 0px 1em 30px; padding: 0px; vertical-align: baseline;">
<li style="background-color: transparent; border: 0px; margin: 0px; padding: 0px; vertical-align: baseline; word-wrap: break-word;">Use Java Mail API to send email reminders</li>
<li style="background-color: transparent; border: 0px; margin: 0px; padding: 0px; vertical-align: baseline; word-wrap: break-word;">Create a table which stores reminders to be sent and update a flag after email reminder is sent</li>
<li style="background-color: transparent; border: 0px; margin: 0px; padding: 0px; vertical-align: baseline; word-wrap: break-word;">In case system goes down, you can resend all reminders for which flag was not set.</li>
</ol>
<div>
<span style="font-family: Arial, Liberation Sans, DejaVu Sans, sans-serif;"><span style="font-size: 14px; line-height: 18px;">It was so simple and easy to implement and we have all control in our hand and there was no RAMP up time to learn new frameworks.</span></span></div>
</div>
<div>
<span style="font-family: Arial, Liberation Sans, DejaVu Sans, sans-serif;"><span style="font-size: 14px; line-height: 18px;"><br /></span></span></div>
<div>
<span style="font-family: Arial, Liberation Sans, DejaVu Sans, sans-serif;"><span style="font-size: 14px; line-height: 18px;">So, if you are confused with n number of ideas available out there using x number of frameworks, you can use the simple design explained above.</span></span></div>
</div>
Unknownnoreply@blogger.com0tag:blogger.com,1999:blog-9037617902138567012.post-403745795865021072013-02-11T08:01:00.000-08:002013-07-24T20:34:19.914-07:00Map Reduce Simplified<div dir="ltr" style="text-align: left;" trbidi="on">
Yes it is about parallel and distributed computing, there are tonnes of web pages, books articles, diagrams etc. etc with nice buzz words to talk about Map Reduce, here is the most simplified explanation.<br />
<br />
Lets take a real life example.<br />
<br />
1. Company CEO called all Program Manager's "I need total effort spent this month by noon". Program Manager's no problem sir. Why are Program Manager's not worried because they are going to distribute task :-)<br />
<br />
2. Each Program Manager called their project manager asking for effort spent so far.<br />
<br />
3. Each Project Manager pulled up effort sheet and provided it to their Program Managers.<br />
<br />
4. Program Managers complied received sheet into one file and sent it to CEO.<br />
<br />
5. Company CEO collated all the sheets and calculated total effort spent.<br />
<br />
Each individually broke its task to smaller tasks (Mapped its input task to smaller tasks), Program Manager was required to provide effort spent, he mapped his task to smaller tasks, this is MAP.<br />
<br />
Program Manager's on receiving data from their project managers compiled it back to single output, this is REDUCE.<br />
<br />
Now lets zoom out and summarize how Map Reduce applies to distributed and parallel computing. Each node distributes its task to smaller tasks(Maps its given task). Each node receive results, combine them(REDUCE) to generate required output.<br />
<br />
<br /></div>
Unknownnoreply@blogger.com0tag:blogger.com,1999:blog-9037617902138567012.post-79356624343700558592013-01-27T21:46:00.000-08:002013-07-22T20:40:37.660-07:00Apache Roller Getting Started<div dir="ltr" style="text-align: left;" trbidi="on">
If you are thinking to setup a blog website then apache roller is the quickest and simplest thing to do so, below are steps for getting started, though these instructions are present in documentation provided by apache, but hopefully following steps will make it very easy for you.<br />
<br />
Here you Go !!<br />
<br />
1. Download apache roller<br />
<br />
<a href="http://roller.apache.org/download.cgi#roller50">http://roller.apache.org/download.cgi#roller50</a><br />
<br />
2. Install Tomcat <br />
<br />
<a href="http://tomcat.apache.org/download-70.cgi">http://tomcat.apache.org/download-70.cgi</a><br />
<br />
3. Download mysql <br />
<br />
<a href="http://dev.mysql.com/downloads/">http://dev.mysql.com/downloads/</a><br />
<br />
4. Unzip apache roller zip file and copy roller-5.0.1-tomcat.war from <br />
\roller-weblogger-5.0.1-for-tomcat.zip\roller-weblogger-5.0.1-tomcat\webapp to tomcat webapps folder<br />
<br />
5. Create mysql database, dont worry about schema, that will be automatically created later.<br />
<br />
<span style="font-family: CourierNewPSMT;"></span><br />
<div align="LEFT">
<span style="font-family: CourierNewPSMT;">mysql -u root -p</span></div>
<span style="font-family: CourierNewPSMT;">password: *****<br /> <br /><div align="LEFT">
mysql> create database rollerdb;</div>
mysql> grant all on rollerdb.* to scott@'%' identified by 'tiger';<br /> mysql> grant all on rollerdb.* to scott@localhost identified by 'tiger';<br /><br />Otherwise you will get following error on webpage:<br /><br />[com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: Unknown database 'rollerdb'</span><br />
<br />
6. Create a file roller-custom.properties in tomcat lib folder, here is default content:<br />
<br />
installation.type=auto<br />
mediafiles.storage.dir=/usr/local/rollerdata/mediafiles<br />
search.index.dir=/usr/local/rollerdata/searchindex<br />
log4j.appender.roller.File=/usr/local/rollerdata/roller.log<br />
database.configurationType=jdbc<br />
database.jdbc.driverClass=com.mysql.jdbc.Driver<br />
database.jdbc.connectionURL=jdbc:mysql://localhost:3306/rollerdb?<br />
autoReconnect=true&useUnicode=true&characterEncoding=utf-8&mysqlEncoding=utf8<br />
database.jdbc.username=scott<br />
database.jdbc.password=tiger<br />
mail.configurationType=properties<br />
mail.hostname=smtp-server.example.com<br />
mail.username=scott<br />
mail.password=tiger<br />
<br />
If you dont add this file then you will get following error on startup:<br />
<br />
Roller Weblogger: No customer properties found in classpath<br />
<br />
7. Please download and copy jars for mail api and mysql jdbc drivers to lib directory of tomcat<br />
<br />
mail.jar<br />
mysql-connector-java-5.1.22-bin.jar<br />
<br />
I came across following error and copying mail.jar to lib directory fixed it.<br />
<br />
SEVERE: Error listenerStart<br />
Jan 28, 2013 11:03:29 AM org.apache.catalina.core.StandardContext startInternal<br />
SEVERE: Context [/roller-5.0.1-tomcat] startup failed due to previous errors<br />
Jan 28, 2013 11:03:29 AM org.apache.catalina.loader.WebappClassLoader clearRefer<br />
encesThreads<br />
SEVERE: The web application [/roller-5.0.1-tomcat] appears to have started a thr<br />
ead named [Abandoned connection cleanup thread] but has failed to stop it. This<br />
is very likely to create a memory leak.<br />
<br />
8. Start tomcat and open following url<br />
<br />
<a href="http://localhost:8080/roller-5.0.1-tomcat/">http://localhost:8080/roller-5.0.1-tomcat/</a><br />
<br />
9. If you have followed all the steps, you should see following screen:<br />
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjdHdzU9QUwbaM8xvonzWY3VsCYnMQDvwE3mwIdo6-91jbVdNoaugOJ32oXLRH1Nd-hMiR1-A0HXxPfhpRBARl6dkZhYjdf55x-JRfJmOh-MKL7Q6YlT8vQRoFI7To443WuCuANjBDzjgmE/s1600/roller+startup.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="113" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjdHdzU9QUwbaM8xvonzWY3VsCYnMQDvwE3mwIdo6-91jbVdNoaugOJ32oXLRH1Nd-hMiR1-A0HXxPfhpRBARl6dkZhYjdf55x-JRfJmOh-MKL7Q6YlT8vQRoFI7To443WuCuANjBDzjgmE/s320/roller+startup.jpg" width="320" /></a></div>
<div align="left" class="separator" style="clear: both; text-align: center;">
</div>
10. Click on "Yes - create tables now", once the tables are created you will see following confirmation message.<br />
<br />
Database tables were created successfully as you can see below. <br />
Database tables are present and up-to-date. Click <a href="http://localhost:8080/roller-5.0.1-tomcat/roller-ui/install/install!bootstrap.rol">here</a> to complete the installation process and start using Roller.<br />
<br />
Click on "Here"<br />
<br />
11. You should now see welcome message<br />
<br />
"Welcome to Roller"<br />
<br />
12. Follow on screen steps to create a user and blog.<br />
<br />
Hopefully you will find it very simple to setup and have fun setting up your blog site in few minutes.</div>
Unknownnoreply@blogger.com0tag:blogger.com,1999:blog-9037617902138567012.post-8608579509036143532011-08-13T20:02:00.000-07:002013-07-22T20:32:00.896-07:00HTML5 Cool FeaturesHTML5 has come up with lot of features but coolest of them are MathML and SVG support. Tried few quick examples, they make web designing more fun:<br /><br /><br /><br /><svg><circle r="50" cx="50" cy="50" fill="green"/></svg><br /><br /><svg><rect width="300" height="100" fill="red" /></svg><br /><br /><svg><line x1="20" y1="20" x2="200" y2="100" style="stroke:blue;stroke-width:2"/</svg><br /><br />If you don't see a green circle, red rectangle and a blue line then your browser does not support HTML5, visit following URL to check your browser:<br /><br /><br /><br />http://html5test.com/<br /><br /><br /><br />Good luck for rich GUI's.<br /><br /><br /><br /><br /><br /><br /><br />Unknownnoreply@blogger.com0tag:blogger.com,1999:blog-9037617902138567012.post-88357410982140010702011-07-12T21:04:00.000-07:002011-07-12T21:19:55.580-07:00Best way to visit Statue of LibertyWell it actually depends on how much time you have and for how long you are in New york. If you are in states for shorter time then probably you would take a ferry from battery park.<br /><br />Going from battery park you may have to be in long queues for tickets then ferry and same when you take the ferry back from Ellis island and statue of liberty.<br /><br />But if you are around new york for a longer time and you are traveling with kids then the best way is to rent a car and go to liberty state park in Jersey City. And if you are coming from Connecticut then I would suggest that you take Tappan Zee bridge and Garden state parkway. From Stamford, CT we found this route most convenient and traffic free.<br /><br />From the Jersey side the queues are much much shorter, no waiting. Would strongly recommend especially if you are traveling with kids. We felt so relieved when we went there last weekend with nine month old baby, it would have been so hard to stand in long queues. Also the time that you save from standing in queues you can enjoy more on island.<br /><br />The ferry from Jersey first take you to Ellis island and then to statue of liberty. Ellis island you will like if you love to learn history. You will enjoy more time at Statue of liberty, very good views of New York, if you can take a sheet would be good to sit on grass and feel the breeze coming from shore.<br /><br />Have fun !!Unknownnoreply@blogger.com1tag:blogger.com,1999:blog-9037617902138567012.post-79861170732644793172011-06-17T17:24:00.000-07:002014-11-03T21:46:10.443-08:00Watch Youtube HD on PS3Last few weeks i spent a lot of time searching on internet to watch Youtube HD videos on PS3, there were a few solutions available, but the following worked for me and is the simplest.<br /><br />1. Open browser on ps3<br />2. Goto Ps3Youtube.com<br />3. There is a search box on top, enter your keywords (you may add word HD in your search criteria)<br />4. From the search list click on a video and play it, thats it !!<br /><br />I know there are some other instructions on website in green colored text but playing the video on same site worked for me.<br /><br />I hope this helps, searching through internet i found lot of people feeling this pain of unable to watch youtube HD videos and low quality that is provided by Youtube XL.<br /><br />Good luck !Unknownnoreply@blogger.com0tag:blogger.com,1999:blog-9037617902138567012.post-22808137520284097052011-06-16T20:20:00.000-07:002013-07-24T20:36:14.762-07:00View Drools Generated Code<div dir="ltr" style="text-align: left;" trbidi="on">
When we execute rules, behind the scene java code is generated which is actually getting executed, to see this java code you need to set configuration path where you want java code generated by drools to be stored.<br />
<br />
PackageBuilderConfiguration configuration = new PackageBuilderConfiguration();<br />
configuration.setDumpDir(new File("XYZ"));<br />
<br />
final KnowledgeBuilder kbuilder = KnowledgeBuilderFactory<br />
.newKnowledgeBuilder(configuration);<br />
<br />
Set XYZ as a directory path where you would like drools to store generated code. e.g. XYZ = "c:/drools/codegen"<br />
<br />
When you run your program the java classes generated for the .drl files are stored at the path XYZ.<br />
<br />
This generated code is really helpful to understand the behavior in lot of situations.</div>
Unknownnoreply@blogger.com1tag:blogger.com,1999:blog-9037617902138567012.post-40621647042505303742011-06-11T15:58:00.001-07:002014-11-03T21:46:28.599-08:00Listen Hindi Internet Radio Channels on PS3PS3 is the best gadget i have ever used and its true "It only do everything".<br /><br />Having used it to play games, watch netflix, youtube and see my collection of pictures and listen to songs. I was searching for a way to play radio on PS3 and specifically "Hindi Internet Radio Channels"<br /><br />After spending couple of days, finally I have it working in few easy steps:<br /><br />1. Download PS3 Media server on you laptop or PC: http://ps3mediaserver.blogspot.com/<br /><br />2. Open WEB.conf file of PS3 and add following lines:<br /><br />audiostream.Web,Radio=Desi Radio - www.desi-radio.com,http://76.73.90.27:80/<br />audiostream.Web,Radio=Desi-Radio - www.desi-radio.com,http://76.73.126.218:80/<br /><br />3. Restart PS3 Media Server<br /><br />4. In your PS3, you should see PS3 Media server, open following path:<br /><br />Web -> Radio <br /><br />You should see "Desi Radio" in list.<br /><br />5. Click on Desi Radio and you have live hindi songs streaming on your Ps3.<br /><br />I am searching more hindi internet radio channels, will update this blog when i find more channels.<br /><br />Enjoy !!<br /><br />------------------<br />More channels:<br /><br />audiostream.Web,Radio,India=Dhak Dhak Radio - www.dhakdhakradio.com,http://173.192.48.97:8404<br />audiostream.Web,Radio,India=Filmy Radio - www.dealsgeni.com,http://173.192.224.123:8270<br />audiostream.Web,Radio,India=Hamara Sangeet - www.hamara-sangeet.com,http://213.175.221.132:9001/<br />audiostream.Web,Radio,India=Humsafar Montreal - www.indianmedia.com,http://usa7-vn.mixstream.net:8210/Unknownnoreply@blogger.com7tag:blogger.com,1999:blog-9037617902138567012.post-80194517124963742472010-10-27T21:26:00.000-07:002013-07-24T20:37:03.412-07:00JSON Optimizing for Faster Rendering<div dir="ltr" style="text-align: left;" trbidi="on">
All web applications have fast rendering as one of the primary goals, JSON is a preferred choice in most of AJAX based applications because it is lightweight data interchange format.<br />
<br />
Consider a scenario where you have to read data from database and render it on UI, typically the steps which will be followed are:<br />
<br />
a. Send request data to server using AJAX calls<br />
b. At server end invoke the Business layer<br />
c. Business layer calls the database layer<br />
d. Data returned from database layer is populated into business objects<br />
e. From business objects build JSON objects, send them back to client<br />
f. Client use Javascript libraries to render data on UI.<br />
<br />
If everything works fine for you, you can stop reading right now, because you are achieving the required goal in the best way.<br />
<br />
But in real world this might not be working for you because of performance issues at one or the other step mentioned above. Here are few performance tips, they might suite in some of the scenarios and might be the worst suggestion in other cases:<br />
<br />
1. Store JSON objects in database, read them send them to UI. It will be the fastest Way but how to query, we need to build JSON object from our business objects before sending them to UI.<br />
<br />
2. Store JSON objects in one of the columns in database, query on other columns and return the column containing the JSON Object.<br />
<br />
These tips might be useful in some of the scenario's, also use JSON API's to add methods to generate JSON objects out of Java Objects.<br />
<br />
Hope they might help you, might not help some of you.<br />
<br />
Good Luck for faster UI's</div>
Unknownnoreply@blogger.com0tag:blogger.com,1999:blog-9037617902138567012.post-71283948441564799142010-10-22T19:58:00.000-07:002013-07-24T20:37:21.712-07:00Drools - An overview<div dir="ltr" style="text-align: left;" trbidi="on">
For Java based applications the most challenging part has always been the business logic maintenance, and pick any applications which you find complex and if we ask ourself how complex it would be moving forward, the answer will always be nX times.<br />
<br />
What do we do ? Drools comes for Rescue as a Rule Engine.<br />
<br />
Drools provides mechanism:<br />
<br />
a. To write business logic in simple english language<br />
b. Easy to maintain and very simple to extend<br />
c. Reusability of logic by defining keywords in a DSL file and using them in DSLR file.<br />
<br />
But be careful nothing comes free, everything takes cost in terms of memory and time space.<br />
<br />
Use Drools if you really have :<br />
<br />
a. Business logic which you think is getting cluttered with multiple if conditions because of variety of scenarios<br />
b. You will have growing demand of increase in the complexity<br />
c. The business logic changes would be frequent (1 - 2 times a year would also be frequent)<br />
d. Your server's have enough of memory as it is a memory hungary tool, it provides performance at cost of memory<br />
<br />
Choosing a technology stack is a big decision for the lifecycle of an application, so evaluate both pros and cons and if they fits in your application requirements go for it because it is one of the easiest to use and plug in Java based Rule Engine.<br />
<br />
Some programmers might find it cumbersome as we are used to looking at the code which is being executed and loves to debug it and understand it and see what is actually happening, latest version of Drools 5.0 address this by providing JMX support and functionality to see the generated Java Code.<br />
<br />
Good Luck with your Rule Engine !!</div>
Unknownnoreply@blogger.com0tag:blogger.com,1999:blog-9037617902138567012.post-50369949594192551952010-01-31T07:06:00.000-08:002010-01-31T07:12:50.428-08:00Give Me Some Sunshine Keyboard NotesNo doubt about the movie of this song that was one of the best movies but I liked this song and thought to play it, was able to work on some of the begining lines, here are few song notes.<br /><br />Sa Re Umar Hum <br /><br />Ga Ga Re Sa Re<br /><br />Mar mar ke jee liye<br /><br />Ga Ga Re Sa Re<br /><br />Loved playing this song, will work on chords next weekend.Unknownnoreply@blogger.com0tag:blogger.com,1999:blog-9037617902138567012.post-68780838790343413912009-02-20T10:16:00.000-08:002013-07-22T20:31:50.446-07:00Class Data SharingClass data sharing (CDS) a feature introduced in J2SE 5.0 reduces the startup time for Java <br />programming language applications.<br /><br />When the JRE is installed on 32-bit platforms using the Sun provided installer, the installer loads a set of <br />classes from the system jar file into a private internal representation, and dumps that representation to a file, <br />called a "shared archive".Class data sharing is not supported in Microsoft Windows 95/98/ME.<br /><br />During subsequent JVM invocations, the shared archive is memory-mapped in, saving the cost of loading those <br />classes and allowing much of the JVM's metadata for these classes to be shared among multiple JVM processes.<br /><br />The primary motivation for including CDS in the 5.0 release is the decrease in startup time it provides. <br />CDS produces better results for smaller applications because it eliminates a fixed cost: that of loading <br />certain core classes. The smaller the application relative to the number of core classes it uses, the <br />larger the saved fraction of startup time. <br /><br /><br />The footprint cost of new JVM instances has been reduced in two ways. First, a portion of the shared archive, <br />currently between five and six megabytes, is mapped read-only and therefore shared among multiple JVM processes. <br />Previously this data was replicated in each JVM instance. Second, since the shared archive contains class data <br />in the form in which the Java Hotspot VM uses it, the memory which would otherwise be required to access the <br />original class information in rt.jar is not needed. These savings allow more applications to be run concurrently <br />on the same machine.<br /><br />Regenerating Shared Archive<br /><br />To regenerate the share archive use the following command:<br /><br />java -Xshare:dump <br /><br />Diagnostic information will be printed as the archive is generated. <br /><br />Manually Controlling Class Data Sharing<br /><br />The class data sharing feature is automatically enabled when conditions allow it to be used. The following command <br />line options are present primarily for diagnostic and debugging purposes and may change or be removed in future <br />releases. <br /><br />-Xshare:off <br />Disable class data sharing. <br /><br />-Xshare:on <br />Require class data sharing to be enabled. If it could not be enabled for various reasons, print an error message and exit. <br /><br />-Xshare:auto <br />The default; enable class data sharing whenever possible.Unknownnoreply@blogger.com0tag:blogger.com,1999:blog-9037617902138567012.post-71358115395973182432009-01-20T22:58:00.000-08:002013-07-24T20:38:04.479-07:00XML Naming Conventions (Best Practices)<div dir="ltr" style="text-align: left;" trbidi="on">
XML is the base of Web 2.0 development. While writing a web service to integrate products, I learned some best practices with XML naming conventions.<br />
<br />
An XML element is everything from (including) the element's start tag to (including) the element's end tag.<br />
<br />
An element can contain other elements, simple text or a mixture of both. Elements can also have attributes.<br />
<br />
<bookstore><br />
<book category="CHILDREN"><br />
<author>J K. Rowling</author><br />
<year>2005</year><br />
<price>29.99</price><br />
</book><br />
<book category="WEB"><br />
<author>Erik T. Ray</author>><br />
<year>2003</year><br />
<price>39.95</price> <br />
</book><br />
</bookstore>><br />
<br />
In the example above, <bookstore> and <book> have element contents, because they contain other elements. <author> has text content because it contains text.<br /><br />In the example above only <book> has an attribute (category="CHILDREN"). <br /><br /><strong>XML Naming Rules</strong><br /><br />XML elements must follow these naming rules:<br /><br />1. Names can contain letters, numbers, and other characters <br />2. Names cannot start with a number or punctuation character <br />3. Names cannot start with the letters xml (or XML, or Xml, etc) <br />4. Names cannot contain spaces <br /><br />Any name can be used, no words are reserved.<br /><br /><strong>Best Naming Practices</strong><br /><br />1. Make names descriptive. Names with an underscore separator are nice: <first_name>, <last_name>.<br />2. Names should be short and simple, like this: <book_title> not like this: <the_title_of_the_book>. <br />3. Avoid "-" characters. If you name something "first-name," some software may think you want to subtract name from first.<br />4. Avoid "." characters. If you name something "first.name," some software may think that "name" is a property of the object "first."<br />5. Avoid ":" characters. Colons are reserved to be used for something called namespaces (more later).<br />6. XML documents often have a corresponding database. A good practice is to use the naming rules of your database for the elements in the XML documents.<br />7. Non-English letters like éòá are perfectly legal in XML, but watch out for problems if your software vendor doesn't support them.<br /><br />Reference : http://www.w3schools.com/xml/xml_elements.asp</the_title_of_the_book></book_title></last_name></first_name></book></author></book></bookstore></div>
Unknownnoreply@blogger.com0tag:blogger.com,1999:blog-9037617902138567012.post-61413229220452530032009-01-15T01:43:00.000-08:002013-07-24T20:38:48.246-07:00Apache AXIS2 Web Service Client<div dir="ltr" style="text-align: left;" trbidi="on">
This article covers details about writing a web service client using Apache AXIS2 API. The article explains the various API using code snippets and covers parameters require by various methods of web service client API.<br />
<br />
Apache AXIS2 web service API mainly consists of two type of objects ServiceClient and OperationClient. ServiceClient provides basic APIs to send and receive SOAP messages, for advanced methods you require Operation Client.<br />
<br />
To provide target URL you need to define a EndPointReference type of object.<br />
<br />
EndpointReference targetEPR = new EndpointReference(http://localhost:8080/axis2/services/helloworld);<br />
<br />
Various options can be given to web service client by creating an Options object. The reference point defined is set into the options along with the Transport protocol.<br />
<br />
Options options = new <br />
<br />
Options();<br />
<br />
options.setTo(targetEPR);<br />
<br />
options.setTransportInProtocol(Constants.TRANSPORT_HTTP);<br />
<br />
Now create a service client and pass these options to service client using setOptions API of service client.<br />
<br />
ServiceClient sender = new ServiceClient();<br />
<br />
sender.setOptions(options);<br />
<br />
So, till now we have created a service client and provided the various options to it, next step is creating the payload of SOAP message that will be send in the web service call. AXIS2 provides AXIOM (AXIS Object model) to create XML Structure. Following code snippet creates the payload message.<br />
<br />
OMFactory fac = OMAbstractFactory.getOMFactory();<br />
<br />
OMNamespace omNs = fac.createOMNamespace("http://ws.apache.org/axis2", "");<br />
<br />
OMElement method = fac.createOMElement("sayHello", omNs); //Method to be invoked.<br />
<br />
OMElement value = fac.createOMElement("parameter1", omNs);<br />
<br />
value.addChild(fac.createOMText(value, "Sachin" ));<br />
<br />
method.addChild(value);<br />
<br />
value = fac.createOMElement("parameter2", omNs);<br />
<br />
value.addChild(fac.createOMText(value, "Thapa" ));<br />
<br />
method.addChild(value);<br />
<br />
Finally use the sendReceive API of ServiceClient to send SOAP request and receive response.<br />
<br />
OMElement result = sender.sendReceive(method);<br />
<br />
System.out.println(result);<br />
<br />
The result object contains the response received from the server.</div>
Unknownnoreply@blogger.com0tag:blogger.com,1999:blog-9037617902138567012.post-39544129404905507892008-12-29T04:00:00.000-08:002013-07-24T20:38:27.818-07:00Deploying Web Service in Apache AXIS2<div dir="ltr" style="text-align: left;" trbidi="on">
The purpose of this article is to talk about how to write web service and deploy it in Apache AXIS2.<br />
<br />
First step is downloading and installing apache axis2. There are two ways to use Apache AXIS2.<br />
<br />
1. Install AXIS2 as a standalone server using the Standard Binary Distribution.<br />
2. Deploy axis2.war and deploy it in a servlet container.<br />
<br />
We will be using the 2nd method in the article. To check the installation open the url http://localhost:8080/axis2 and you should be able to see the home page of apache axis2.<br />
<br />
Please locate the folder axis2\WEB-INF\services in exploded war file of axis2. This is the folder where you will copy the code of your service and it will get deployed in apache axis2.<br />
<br />
Lets us take a simple example. Write your service class.<br />
<br />
public class HelloWorld<br />
{<br />
public String sayHello(String firstName, String lastName)<br />
{<br />
System.out.println("Hello World Invoked");<br />
MessageContext incomingContext = MessageContext.getCurrentMessageContext();<br />
FileDataSource dataSource = new FileDataSource("c:/YServer.txt");<br />
DataHandler dataHandler = new DataHandler(dataSource);<br />
incomingContext.addAttachment("contentID", dataHandler);<br />
<br />
String data = DataProvider.getData();<br />
return "Hello " + firstName + " " + lastName + " " + data;<br />
}<br />
public String getServiceName()<br />
{<br />
return "test service";<br />
}<br />
}<br />
<br />
Write a services.xml file.<br />
<br />
<service><br />
<description><br />
This is my first service, which says hello<br />
</description><br />
<parameter name="ServiceClass">HelloWorld</parameter><br />
<operation name="sayHello"><br />
<messageReceiver class="org.apache.axis2.rpc.receivers.RPCMessageReceiver"/><br />
</operation><br />
<operation name="getServiceName"><br />
<messageReceiver class="org.apache.axis2.rpc.receivers.RPCMessageReceiver"/><br />
</operation><br />
</service><br />
<br />
In case you want to receive the SOAP payload as XML Message in the service you need to specify XML Message receiver instead of RPCMessageReceiver in services.xml file. To specify XML Message receiver put the following line as child of <operation> tag in your services.xml.<br />
<br />
<messageReceiver <br />
<br />
class="org.apache.axis2.receivers.RawXMLINOutMessageReceiver"/><br />
<br />
Also, since the service will receive XML Message as input parameter you need to change the signature of the method of service.<br />
<br />
public OMElement sayHello(OMElement element) <br />
<br />
OMElement object contains the XML Message, OMElement Object is provided by AXIOM. AXIOM stands for AXis Object Model (also known as OM - Object Model) and refers to the XML infoset model that was initially developed for Apache Axis2.<br />
<br />
<br />
Bundle your class file, services.xml in the hierarchy as shown in the figure below. See helloworld folder in image below.<br />
<br />
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgGiH7KUpsuqQQKi-im5cAvqp8rrNPUM96wQYoWl9OK3srZjDX_YMgM4qk-tmk54gLY4YtKTstz7MHQDZbI8lv3KsLFK-4wsJIaQYJwjorGiOpgupXfnwRyIQMgXjxgEICwbQIq0nBuzQc3/s1600-h/untitled.JPG"><img alt="" border="0" id="BLOGGER_PHOTO_ID_5285181179777294114" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgGiH7KUpsuqQQKi-im5cAvqp8rrNPUM96wQYoWl9OK3srZjDX_YMgM4qk-tmk54gLY4YtKTstz7MHQDZbI8lv3KsLFK-4wsJIaQYJwjorGiOpgupXfnwRyIQMgXjxgEICwbQIq0nBuzQc3/s320/untitled.JPG" style="cursor: pointer; display: block; height: 300px; margin: 0px auto 10px; text-align: center; width: 270px;" /></a><br />
<br />
Copy your service into the services folder of axis2 as shown in figure, start web server. Open the URL http://localhost:8080/axis2.<br />
<br />
On the displayed page Click on services, you should be able to see the name of service you specified in services.xml in the list of web services.</div>
Unknownnoreply@blogger.com0tag:blogger.com,1999:blog-9037617902138567012.post-10511702521598173252008-12-02T06:20:00.000-08:002008-12-02T06:22:19.044-08:00Happy Singh @Big 92.7 FMHappy Singh is telecasted daily and I hear it mostly when I am driving back to home from office @7 PM, I am a big fan of Happy Singh's sense of humour. Listen it you will surely like it.Unknownnoreply@blogger.com0tag:blogger.com,1999:blog-9037617902138567012.post-21419816346996763412008-12-01T01:55:00.000-08:002013-07-24T20:39:24.636-07:00Getting Started with Apache Lucene<div dir="ltr" style="text-align: left;" trbidi="on">
Apache Lucene is a high-performance, full-featured text search engine library.<br />
<br />
The API of lucene is very simple to use. Here is overview of some of the objects required to start using Apache Lucene.<br />
<br />
<strong>Document and Fields</strong><br />
<br />
The class "org.apache.lucene.document.Document" is necessary container for the index. Lucene requires all indexed objects to provide an instance of Document. Each document defines one or several fields ( (org.apache.lucene.document.Field). Fields contain classified information about the document or metadata related to document. A sample classification is for example the creation date of a file, author of the document etc. These fields allow you to search later for a specific information in this classification. <br />
<br />
<br />
<strong>IndexWriter</strong><br />
<br />
The class org.apache.lucene.index.IndexWriter creates the index. Via the method addDocument you can add an existing Document to the index. The constructor for IndexWriter expects the directory to store the index, and the analyzer for the content of the files. In addition a boolean flag is handed over which indicates if the index should be created new or if an existing index should be extended. <br />
<br />
<strong>Analyser</strong><br />
<br />
The class org.apache.lucene.analysis.standard.StandardAnalyzer provides a standard analyzer. This part is responsible to analyse the text and to filter out certain fill-words, e.g. "and". <br />
<br />
<strong>Searcher and Query</strong><br />
<br />
The class org.apache.lucene.search.Searcher provides the search functionality. org.apache.lucene.search.IndexSearcher searches over an index. What is to be searched is provided via the query (org.apache.lucene.search.Query) class. The search allows wildcard search, e.g. *, ?, logical operations (AND, OR, NOT) and much more, e.g. fussy. <br />
<br />
Here's a simple example how to use Lucene for indexing and searching.<br />
<br />
public class TestMyLucene<br />
{<br />
public static void main(String[] args) throws Exception<br />
{<br />
Analyzer analyzer = new StandardAnalyzer();<br />
<br />
// Store the index in memory:<br />
Directory directory = new RAMDirectory();<br />
<br />
// To store an index on disk, use this instead (note that the <br />
// parameter true will overwrite the index in that directory<br />
// if one exists):<br />
//Directory directory = FSDirectory.getDirectory("/tmp/testindex", true);<br />
IndexWriter iwriter = new IndexWriter(directory, analyzer, true);<br />
iwriter.setMaxFieldLength(25000);<br />
<br />
Document doc = new Document();<br />
String text = "This is the text to be indexed.";<br />
doc.add(new Field("fieldname", text, Field.Store.YES, Field.Index.TOKENIZED));<br />
iwriter.addDocument(doc);<br />
iwriter.close();<br />
<br />
// Now search the index:<br />
IndexSearcher isearcher = new IndexSearcher(directory);<br />
<br />
// Parse a simple query that searches for "text":<br />
Query query = QueryParser.parse("text", "fieldname", analyzer);<br />
Hits hits = isearcher.search(query);<br />
System.out.println(hits.length());<br />
<br />
// Iterate through the results:<br />
for (int i = 0; i < hits.length(); i++) <br />
{<br />
Document hitDoc = hits.doc(i);<br />
System.out.println(hitDoc.get("fieldname"));<br />
}<br />
<br />
isearcher.close();<br />
directory.close(); <br />
}<br />
}<br />
<br />
In the above example, hits return the matching documents for the query provided.</div>
Unknownnoreply@blogger.com0