<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" media="screen" href="/~d/styles/atom10full.xsl"?><?xml-stylesheet type="text/css" media="screen" href="http://feeds.feedburner.com/~d/styles/itemcontent.css"?><feed xmlns="http://www.w3.org/2005/Atom" xmlns:openSearch="http://a9.com/-/spec/opensearch/1.1/" xmlns:georss="http://www.georss.org/georss" xmlns:gd="http://schemas.google.com/g/2005" xmlns:thr="http://purl.org/syndication/thread/1.0" xmlns:feedburner="http://rssnamespace.org/feedburner/ext/1.0" gd:etag="W/&quot;AkACQ3k-eSp7ImA9WhRaFEk.&quot;"><id>tag:blogger.com,1999:blog-4903191105785361362</id><updated>2012-02-16T19:19:22.751-08:00</updated><category term="eclipse" /><category term="collection" /><category term="java" /><title>Sanjib</title><subtitle type="html" /><link rel="http://schemas.google.com/g/2005#feed" type="application/atom+xml" href="http://sanjib-swain.blogspot.com/feeds/posts/default" /><link rel="alternate" type="text/html" href="http://sanjib-swain.blogspot.com/" /><link rel="next" type="application/atom+xml" href="http://www.blogger.com/feeds/4903191105785361362/posts/default?start-index=26&amp;max-results=25&amp;redirect=false&amp;v=2" /><author><name>Sanjib Kumar Swain</name><uri>http://www.blogger.com/profile/11353921866017700402</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="32" height="24" src="http://3.bp.blogspot.com/_nnkYFjJnYR0/SjDB5r7-A4I/AAAAAAAAABg/5LvGBQSMBFM/S220/100_1083.JPG" /></author><generator version="7.00" uri="http://www.blogger.com">Blogger</generator><openSearch:totalResults>51</openSearch:totalResults><openSearch:startIndex>1</openSearch:startIndex><openSearch:itemsPerPage>25</openSearch:itemsPerPage><atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="self" type="application/atom+xml" href="http://feeds.feedburner.com/blogspot/PEHIt" /><feedburner:info uri="blogspot/pehit" /><atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="hub" href="http://pubsubhubbub.appspot.com/" /><entry gd:etag="W/&quot;Dk4ERnoyfSp7ImA9Wx9XEU8.&quot;"><id>tag:blogger.com,1999:blog-4903191105785361362.post-709447593015664452</id><published>2011-01-03T23:02:00.000-08:00</published><updated>2011-01-03T23:08:27.495-08:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2011-01-03T23:08:27.495-08:00</app:edited><title>Java JMX tutorial</title><content type="html">Here is some sample Java source code for some JMX tests that I created recently. &lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight:bold;"&gt;First, here's the source code for a Java MBean interface named HelloMBean:&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;public interface HelloMBean {&lt;br /&gt;&lt;br /&gt; public String helloService(String name);&lt;br /&gt; &lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;A class to implement the JMX MBean interface&lt;br /&gt;Next, here's the source code for a Java class named Hello that implements the HelloMBean interface we just defined:&lt;br /&gt;&lt;br /&gt;public class Hello implements HelloMBean {&lt;br /&gt;&lt;br /&gt; @Override&lt;br /&gt; public String helloService(String name) {&lt;br /&gt;  &lt;br /&gt;  System.out.println(" Called ...");&lt;br /&gt;  return " Hello Mbean :"+name;&lt;br /&gt; }&lt;br /&gt;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;A JMX example class (a JMX service)&lt;br /&gt;Next up, here's the source code for a Java class named SimpleAgent that includes a main method that starts up our JMX service application:&lt;br /&gt;&lt;br /&gt;import java.lang.management.ManagementFactory;&lt;br /&gt;&lt;br /&gt;import javax.management.MBeanServer;&lt;br /&gt;import javax.management.ObjectName;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;public class SimpleAgent {&lt;br /&gt;&lt;br /&gt; &lt;br /&gt; private MBeanServer mbs = null;&lt;br /&gt;&lt;br /&gt;    public SimpleAgent() {&lt;br /&gt;&lt;br /&gt;       // Get the platform MBeanServer&lt;br /&gt;        mbs = ManagementFactory.getPlatformMBeanServer();&lt;br /&gt;&lt;br /&gt;       // Unique identification of MBeans&lt;br /&gt;       Hello helloBean = new Hello();&lt;br /&gt;       ObjectName helloName = null;&lt;br /&gt;&lt;br /&gt;       try {&lt;br /&gt;// Uniquely identify the MBeans and register them with the platform MBeanServer &lt;br /&gt;          helloName = new ObjectName("FOO:name=HelloBean");&lt;br /&gt;          mbs.registerMBean(helloBean, helloName);&lt;br /&gt;       } catch(Exception e) {&lt;br /&gt;          e.printStackTrace();&lt;br /&gt;       }&lt;br /&gt;    }&lt;br /&gt;    // Utility method: so that the application continues to run&lt;br /&gt;    private static void waitForEnterPressed() {&lt;br /&gt;       try {&lt;br /&gt;          System.out.println("Press  to continue...");&lt;br /&gt;          System.in.read();&lt;br /&gt;       } catch (Exception e) {&lt;br /&gt;          e.printStackTrace();&lt;br /&gt;       }&lt;br /&gt;     }&lt;br /&gt;    &lt;br /&gt;    public static void main(String argv[]) {&lt;br /&gt;        SimpleAgent agent = new SimpleAgent();&lt;br /&gt;        System.out.println("SimpleAgent is running...");&lt;br /&gt;        SimpleAgent.waitForEnterPressed();&lt;br /&gt;     }&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;A script to start our JMX service&lt;br /&gt;And finally here's a Unix/Linux shell script named run.bat that I wrote to run this sample JMX application ("JMX service")&lt;br /&gt;&lt;br /&gt;Run.bat&lt;br /&gt;java -Dcom.sun.management.jmxremote -Dcom.sun.management.jmxremote.port=5555  -Dcom.sun.management.jmxremote.authenticate=false  -Dcom.sun.management.jmxremote.ssl=false SimpleAgent&lt;br /&gt;&lt;br /&gt;As you can see from that code, my application will listen on port 5555 of whatever computer system it is run on.&lt;br /&gt;&lt;br /&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://download.oracle.com/javase/6/docs/technotes/guides/management/figures/connectrem.gif"&gt;&lt;img style="float:left; margin:0 10px 10px 0;cursor:pointer; cursor:hand;width: 408px; height: 428px;" src="http://download.oracle.com/javase/6/docs/technotes/guides/management/figures/connectrem.gif" border="0" alt="" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Access our JMX service with JConsole&lt;br /&gt;Once the application is running you can then connect to it with the jconsole application and view its JMX resources.&lt;br /&gt;&lt;br /&gt; &lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://3.bp.blogspot.com/_nnkYFjJnYR0/TSLHFPpWN2I/AAAAAAAAAEY/5WUVQeeMd8E/s1600/jmx.JPG"&gt;&lt;img style="float:left; margin:0 10px 10px 0;cursor:pointer; cursor:hand;width: 320px; height: 192px;" src="http://3.bp.blogspot.com/_nnkYFjJnYR0/TSLHFPpWN2I/AAAAAAAAAEY/5WUVQeeMd8E/s320/jmx.JPG" border="0" alt=""id="BLOGGER_PHOTO_ID_5558223783041840994" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;test your mbean by passing args.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4903191105785361362-709447593015664452?l=sanjib-swain.blogspot.com' alt='' /&gt;&lt;/div&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/hxmk1790wAgrOiRXlgq11raX58o/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/hxmk1790wAgrOiRXlgq11raX58o/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/hxmk1790wAgrOiRXlgq11raX58o/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/hxmk1790wAgrOiRXlgq11raX58o/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/blogspot/PEHIt/~4/TrMQRmLdjTM" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://sanjib-swain.blogspot.com/feeds/709447593015664452/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://www.blogger.com/comment.g?blogID=4903191105785361362&amp;postID=709447593015664452" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/4903191105785361362/posts/default/709447593015664452?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/4903191105785361362/posts/default/709447593015664452?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/blogspot/PEHIt/~3/TrMQRmLdjTM/java-jmx-tutorial.html" title="Java JMX tutorial" /><author><name>Sanjib Kumar Swain</name><uri>http://www.blogger.com/profile/11353921866017700402</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="32" height="24" src="http://3.bp.blogspot.com/_nnkYFjJnYR0/SjDB5r7-A4I/AAAAAAAAABg/5LvGBQSMBFM/S220/100_1083.JPG" /></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="http://3.bp.blogspot.com/_nnkYFjJnYR0/TSLHFPpWN2I/AAAAAAAAAEY/5WUVQeeMd8E/s72-c/jmx.JPG" height="72" width="72" /><thr:total>0</thr:total><feedburner:origLink>http://sanjib-swain.blogspot.com/2011/01/java-jmx-tutorial.html</feedburner:origLink></entry><entry gd:etag="W/&quot;CEUNSXcyeSp7ImA9Wx9QEE0.&quot;"><id>tag:blogger.com,1999:blog-4903191105785361362.post-6662925184647529750</id><published>2010-12-21T23:09:00.000-08:00</published><updated>2010-12-21T23:18:18.991-08:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2010-12-21T23:18:18.991-08:00</app:edited><title>Software Design Principles Part II</title><content type="html">&lt;span class="Apple-style-span" style="font-family: Arial, Tahoma, Helvetica, FreeSans, sans-serif; font-size: 14px; color: rgb(204, 204, 204); line-height: 18px; "&gt;&lt;h3 class="post-title entry-title" style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; position: relative; font: normal normal normal 18px/normal Georgia, Utopia, 'Palatino Linotype', Palatino, serif; "&gt;&lt;div style="mso-element:para-border-div;border:none;border-bottom:solid #777777 1.0pt; mso-border-bottom-alt:solid #777777 .75pt;padding:0in 0in 8.0pt 0in"&gt;  &lt;p class="MsoNormal" style="margin-top:12.0pt;mso-margin-bottom-alt:auto; line-height:normal;mso-outline-level:1;border:none;mso-border-bottom-alt:solid #777777 .75pt; padding:0in;mso-padding-alt:0in 0in 8.0pt 0in"&gt;&lt;span style="font-size:24.0pt; font-family:&amp;quot;Georgia&amp;quot;,&amp;quot;serif&amp;quot;;mso-fareast-font-family:&amp;quot;Times New Roman&amp;quot;; mso-bidi-font-family:&amp;quot;Times New Roman&amp;quot;;color:black;mso-font-kerning:18.0pt"&gt;Open Close Principle&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;/div&gt;  &lt;/h3&gt;&lt;h2&gt;&lt;span style="font-family:&amp;quot;Georgia&amp;quot;,&amp;quot;serif&amp;quot;;color:black;font-weight:normal"&gt;Motivation&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/h2&gt;  &lt;p&gt;&lt;span style="font-size:10.0pt;font-family:&amp;quot;Verdana&amp;quot;,&amp;quot;sans-serif&amp;quot;;color:#222222"&gt;A clever application design and the code writing part should take care of the frequent changes that are done during the development and the maintaining phase of an application. Usually, many changes are involved when a new functionality is added to an application. Those changes in the existing code should be minimized, since it's assumed that the existing code is already unit tested and changes in already written code might affect the existing functionality in an unwanted manner.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p&gt;&lt;span style="font-size:10.0pt;font-family:&amp;quot;Verdana&amp;quot;,&amp;quot;sans-serif&amp;quot;;color:#222222"&gt;The&lt;span class="apple-converted-space"&gt; &lt;/span&gt;&lt;strong&gt;&lt;span style="font-family:&amp;quot;Verdana&amp;quot;,&amp;quot;sans-serif&amp;quot;"&gt;Open Close Principle&lt;/span&gt;&lt;/strong&gt;&lt;span class="apple-converted-space"&gt; &lt;/span&gt;states that the design and writing of the code should be done in a way that new functionality should be added with minimum changes in the existing code. The design should be done in a way to allow the adding of new functionality as new classes, keeping as much as possible existing code unchanged.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;h2&gt;&lt;span style="font-family:&amp;quot;Georgia&amp;quot;,&amp;quot;serif&amp;quot;;color:black;font-weight:normal"&gt;Intent&lt;/span&gt;&lt;span style="font-size:18.0pt;line-height:115%;font-family:&amp;quot;Georgia&amp;quot;,&amp;quot;serif&amp;quot;; color:black;font-weight:normal"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/h2&gt;  &lt;p&gt;&lt;span style="font-size:10.0pt;font-family:&amp;quot;Verdana&amp;quot;,&amp;quot;sans-serif&amp;quot;;color:#222222"&gt;Software entities like classes, modules and functions should be&lt;span class="apple-converted-space"&gt; &lt;/span&gt;&lt;strong&gt;&lt;span style="font-family:&amp;quot;Verdana&amp;quot;,&amp;quot;sans-serif&amp;quot;"&gt;open for extension&lt;/span&gt;&lt;/strong&gt;&lt;span class="apple-converted-space"&gt; &lt;/span&gt;but&lt;span class="apple-converted-space"&gt; &lt;/span&gt;&lt;strong&gt;&lt;span style="font-family:&amp;quot;Verdana&amp;quot;,&amp;quot;sans-serif&amp;quot;"&gt;closed for modifications&lt;/span&gt;&lt;/strong&gt;.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;h2&gt;&lt;span style="font-family:&amp;quot;Georgia&amp;quot;,&amp;quot;serif&amp;quot;;color:black;font-weight:normal"&gt;Example&lt;/span&gt;&lt;span style="font-size:18.0pt;line-height:115%;font-family:&amp;quot;Georgia&amp;quot;,&amp;quot;serif&amp;quot;; color:black;font-weight:normal"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/h2&gt;  &lt;p&gt;&lt;span style="font-size:10.0pt;font-family:&amp;quot;Verdana&amp;quot;,&amp;quot;sans-serif&amp;quot;;color:#222222"&gt;Bellow is an example which violates the Open Close Principle. It implements a graphic editor which handles the drawing of different shapes. It's obviously that it does not follow the Open Close Principle since the GraphicEditor class has to be modified for every new shape class that has to be added. There are several disadvantages:&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto; margin-left:0in;text-indent:-.25in;line-height:11.25pt;mso-list:l0 level1 lfo1; tab-stops:list .5in"&gt;&lt;span style="font-size:10.0pt; font-family:Symbol;mso-fareast-font-family:Symbol;mso-bidi-font-family:Symbol; color:#222222"&gt;&lt;span style="mso-list:Ignore"&gt;·&lt;span style="font:7.0pt &amp;quot;Times New Roman&amp;quot;"&gt;         &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style="font-size:10.0pt;font-family:&amp;quot;Verdana&amp;quot;,&amp;quot;sans-serif&amp;quot;; color:#222222"&gt;for each new shape added the unit testing of the GraphicEditor should be redone.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto; margin-left:0in;text-indent:-.25in;line-height:11.25pt;mso-list:l0 level1 lfo1; tab-stops:list .5in"&gt;&lt;span style="font-size:10.0pt; font-family:Symbol;mso-fareast-font-family:Symbol;mso-bidi-font-family:Symbol; color:#222222"&gt;&lt;span style="mso-list:Ignore"&gt;·&lt;span style="font:7.0pt &amp;quot;Times New Roman&amp;quot;"&gt;         &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style="font-size:10.0pt;font-family:&amp;quot;Verdana&amp;quot;,&amp;quot;sans-serif&amp;quot;; color:#222222"&gt;when a new type of shape is added the time for adding it will be high since the developer who add it should understand the logic of the GraphicEditor.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto; margin-left:0in;text-indent:-.25in;line-height:11.25pt;mso-list:l0 level1 lfo1; tab-stops:list .5in"&gt;&lt;span style="font-size:10.0pt; font-family:Symbol;mso-fareast-font-family:Symbol;mso-bidi-font-family:Symbol; color:#222222"&gt;&lt;span style="mso-list:Ignore"&gt;·&lt;span style="font:7.0pt &amp;quot;Times New Roman&amp;quot;"&gt;         &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style="font-size:10.0pt;font-family:&amp;quot;Verdana&amp;quot;,&amp;quot;sans-serif&amp;quot;; color:#222222"&gt;adding a new shape might affect the existing functionality in an undesired way, even if the new shape works perfectly&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p&gt;&lt;span style="font-size:10.0pt;font-family:&amp;quot;Verdana&amp;quot;,&amp;quot;sans-serif&amp;quot;;color:#222222"&gt; &lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p&gt;&lt;span style="font-size:10.0pt;font-family:&amp;quot;Verdana&amp;quot;,&amp;quot;sans-serif&amp;quot;;color:#222222"&gt;In order to have more dramatic effect, just imagine that the Graphic Editor is a big class, with a lot of functionality inside, written and changed by many developers, while the shape might be a class implemented only by one developer. In this case it would be great improvement to allow the adding of a new shape without changing the GraphicEditor class.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style="margin-bottom:12.0pt"&gt;&lt;span style="font-size:10.0pt; line-height:115%;font-family:&amp;quot;Verdana&amp;quot;,&amp;quot;sans-serif&amp;quot;;color:#222222;mso-no-proof: yes"&gt;&lt;!--[if gte vml 1]&gt;&lt;v:shapetype id="_x0000_t75" coordsize="21600,21600" spt="75" preferrelative="t" path="m@4@5l@4@11@9@11@9@5xe" filled="f" stroked="f"&gt;  &lt;v:stroke joinstyle="miter"&gt;  &lt;v:formulas&gt;   &lt;v:f eqn="if lineDrawn pixelLineWidth 0"&gt;   &lt;v:f eqn="sum @0 1 0"&gt;   &lt;v:f eqn="sum 0 0 @1"&gt;   &lt;v:f eqn="prod @2 1 2"&gt;   &lt;v:f eqn="prod @3 21600 pixelWidth"&gt;   &lt;v:f eqn="prod @3 21600 pixelHeight"&gt;   &lt;v:f eqn="sum @0 0 1"&gt;   &lt;v:f eqn="prod @6 1 2"&gt;   &lt;v:f eqn="prod @7 21600 pixelWidth"&gt;   &lt;v:f eqn="sum @8 21600 0"&gt;   &lt;v:f eqn="prod @7 21600 pixelHeight"&gt;   &lt;v:f eqn="sum @10 21600 0"&gt;  &lt;/v:formulas&gt;  &lt;v:path extrusionok="f" gradientshapeok="t" connecttype="rect"&gt;  &lt;o:lock ext="edit" aspectratio="t"&gt; &lt;/v:shapetype&gt;&lt;v:shape id="Picture_x0020_1" spid="_x0000_i1026" type="#_x0000_t75" alt="Open Close Principle(OCP) - bad" style="'width:327pt;height:176.25pt;"&gt;  &lt;v:imagedata src="file:///C:\DOCUME~1\sanjib.k\LOCALS~1\Temp\msohtmlclip1\01\clip_image001.gif" title="Open Close Principle(OCP) - bad"&gt; &lt;/v:shape&gt;&lt;![endif]--&gt;&lt;img width="436" height="235" src="http://www.oodesign.com/images/stories/ocp.bad.gif" alt="Open Close Principle(OCP) - bad" shapes="Picture_x0020_1" /&gt;&lt;/span&gt;&lt;span class="apple-style-span"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;table class="MsoNormalTable" border="1" cellpadding="0" width="739" style="width:554.25pt;  mso-cellspacing:1.5pt;background:#EEEEEE;border-top:#C7D5C4;border-left:#C8D5C4;  border-bottom:#8F9E8C;border-right:#899686;border-style:solid;border-width:  1.0pt;mso-border-top-alt:#C7D5C4;mso-border-left-alt:#C8D5C4;mso-border-bottom-alt:  #8F9E8C;mso-border-right-alt:#899686;mso-border-style-alt:solid;mso-border-width-alt:  .75pt;mso-yfti-tbllook:1184;background-image:initial;background-attachment:  initial;background-origin: initial;background-clip: initial;background-position:  initial initial;background-repeat:initial initial"&gt;  &lt;tbody&gt;&lt;tr style="mso-yfti-irow:0;mso-yfti-firstrow:yes;mso-yfti-lastrow:yes"&gt;   &lt;td style="border:none;padding:.75pt .75pt .75pt .75pt;background-image:initial;   background-attachment:initial;background-origin: initial;background-clip: initial;   background-position:initial initial;background-repeat:initial initial"&gt;&lt;pre&gt;&lt;span style="color:black"&gt;// Open-Close Principle - Bad example&lt;br /&gt;&lt;span style="mso-spacerun:yes"&gt; &lt;/span&gt;class GraphicEditor {&lt;br /&gt;&lt;span style="mso-spacerun:yes"&gt; &lt;/span&gt;&lt;br /&gt;&lt;span style="mso-spacerun:yes"&gt; &lt;/span&gt;&lt;span style="mso-tab-count:1"&gt;       &lt;/span&gt;public void drawShape(Shape s) {&lt;br /&gt;&lt;span style="mso-spacerun:yes"&gt; &lt;/span&gt;&lt;span style="mso-tab-count:2"&gt;              &lt;/span&gt;if (s.m_type==1)&lt;br /&gt;&lt;span style="mso-spacerun:yes"&gt; &lt;/span&gt;&lt;span style="mso-tab-count:3"&gt;                      &lt;/span&gt;drawRectangle(s);&lt;br /&gt;&lt;span style="mso-spacerun:yes"&gt; &lt;/span&gt;&lt;span style="mso-tab-count:2"&gt;              &lt;/span&gt;else if (s.m_type==2)&lt;br /&gt;&lt;span style="mso-spacerun:yes"&gt; &lt;/span&gt;&lt;span style="mso-tab-count:3"&gt;                      &lt;/span&gt;drawCircle(s);&lt;br /&gt;&lt;span style="mso-spacerun:yes"&gt; &lt;/span&gt;&lt;span style="mso-tab-count:1"&gt;       &lt;/span&gt;}&lt;br /&gt;&lt;span style="mso-spacerun:yes"&gt; &lt;/span&gt;&lt;span style="mso-tab-count:1"&gt;       &lt;/span&gt;public void drawCircle(Circle r) {....}&lt;br /&gt;&lt;span style="mso-spacerun:yes"&gt; &lt;/span&gt;&lt;span style="mso-tab-count:1"&gt;       &lt;/span&gt;public void drawRectangle(Rectangle r) {....}&lt;br /&gt;&lt;span style="mso-spacerun:yes"&gt; &lt;/span&gt;}&lt;br /&gt;&lt;span style="mso-spacerun:yes"&gt; &lt;/span&gt;&lt;br /&gt;&lt;span style="mso-spacerun:yes"&gt; &lt;/span&gt;class Shape {&lt;br /&gt;&lt;span style="mso-spacerun:yes"&gt; &lt;/span&gt;&lt;span style="mso-tab-count:1"&gt;       &lt;/span&gt;int m_type;&lt;br /&gt;&lt;span style="mso-spacerun:yes"&gt; &lt;/span&gt;}&lt;br /&gt;&lt;span style="mso-spacerun:yes"&gt; &lt;/span&gt;&lt;br /&gt;&lt;span style="mso-spacerun:yes"&gt; &lt;/span&gt;class Rectangle extends Shape {&lt;br /&gt;&lt;span style="mso-spacerun:yes"&gt; &lt;/span&gt;&lt;span style="mso-tab-count:1"&gt;       &lt;/span&gt;Rectangle() {&lt;br /&gt;&lt;span style="mso-spacerun:yes"&gt; &lt;/span&gt;&lt;span style="mso-tab-count:2"&gt;              &lt;/span&gt;super.m_type=1;&lt;br /&gt;&lt;span style="mso-spacerun:yes"&gt; &lt;/span&gt;&lt;span style="mso-tab-count:1"&gt;       &lt;/span&gt;}&lt;br /&gt;&lt;span style="mso-spacerun:yes"&gt; &lt;/span&gt;}&lt;br /&gt;&lt;span style="mso-spacerun:yes"&gt; &lt;/span&gt;&lt;br /&gt;&lt;span style="mso-spacerun:yes"&gt; &lt;/span&gt;class Circle extends Shape {&lt;br /&gt;&lt;span style="mso-spacerun:yes"&gt; &lt;/span&gt;&lt;span style="mso-tab-count:1"&gt;       &lt;/span&gt;Circle() {&lt;br /&gt;&lt;span style="mso-spacerun:yes"&gt; &lt;/span&gt;&lt;span style="mso-tab-count:2"&gt;              &lt;/span&gt;super.m_type=2;&lt;br /&gt;&lt;span style="mso-spacerun:yes"&gt; &lt;/span&gt;&lt;span style="mso-tab-count:1"&gt;       &lt;/span&gt;}&lt;br /&gt;&lt;span style="mso-spacerun:yes"&gt; &lt;/span&gt;} &lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/pre&gt;&lt;/td&gt;  &lt;/tr&gt;   &lt;/tbody&gt;&lt;/table&gt;  &lt;p class="MsoNormal" style="margin-bottom:0in;margin-bottom:.0001pt"&gt;&lt;span class="apple-style-span"&gt;&lt;span style="font-size:10.0pt;line-height:115%; font-family:&amp;quot;Verdana&amp;quot;,&amp;quot;sans-serif&amp;quot;;color:#222222"&gt;&lt;o:p&gt; &lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p&gt;&lt;span style="font-size:10.0pt;font-family:&amp;quot;Verdana&amp;quot;,&amp;quot;sans-serif&amp;quot;;color:#222222"&gt;Bellow is a example which supports the Open Close Principle. In the new design we use abstract draw() method in GraphicEditor for drawing objects, while moving the implementation in the concrete shape objects. Using the Open Close Principle the problems from the previous design are avoided, because GraphicEditor is not changed when a new shape class is added:&lt;/span&gt;&lt;span style="mso-fareast-font-family: &amp;quot;Times New Roman&amp;quot;;mso-fareast-theme-font:major-fareast"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto; margin-left:0in;text-indent:-.25in;line-height:11.25pt;mso-list:l1 level1 lfo2; tab-stops:list .5in"&gt;&lt;span style="font-size:10.0pt; font-family:Symbol;mso-fareast-font-family:Symbol;mso-bidi-font-family:Symbol; color:#222222"&gt;&lt;span style="mso-list:Ignore"&gt;·&lt;span style="font:7.0pt &amp;quot;Times New Roman&amp;quot;"&gt;         &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style="font-size:10.0pt;font-family:&amp;quot;Verdana&amp;quot;,&amp;quot;sans-serif&amp;quot;; color:#222222"&gt;no unit testing required.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto; margin-left:0in;text-indent:-.25in;line-height:11.25pt;mso-list:l1 level1 lfo2; tab-stops:list .5in"&gt;&lt;span style="font-size:10.0pt; font-family:Symbol;mso-fareast-font-family:Symbol;mso-bidi-font-family:Symbol; color:#222222"&gt;&lt;span style="mso-list:Ignore"&gt;·&lt;span style="font:7.0pt &amp;quot;Times New Roman&amp;quot;"&gt;         &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style="font-size:10.0pt;font-family:&amp;quot;Verdana&amp;quot;,&amp;quot;sans-serif&amp;quot;; color:#222222"&gt;no need to understand the sourcecode from GraphicEditor.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto; margin-left:0in;text-indent:-.25in;line-height:11.25pt;mso-list:l1 level1 lfo2; tab-stops:list .5in"&gt;&lt;span style="font-size:10.0pt; font-family:Symbol;mso-fareast-font-family:Symbol;mso-bidi-font-family:Symbol; color:#222222"&gt;&lt;span style="mso-list:Ignore"&gt;·&lt;span style="font:7.0pt &amp;quot;Times New Roman&amp;quot;"&gt;         &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style="font-size:10.0pt;font-family:&amp;quot;Verdana&amp;quot;,&amp;quot;sans-serif&amp;quot;; color:#222222"&gt;since the drawing code is moved to the concrete shape classes, it's a reduced risk to affect old functionallity when new functionallity is added.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p&gt;&lt;span style="font-size:10.0pt;font-family:&amp;quot;Verdana&amp;quot;,&amp;quot;sans-serif&amp;quot;;color:#222222"&gt; &lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p class="MsoNormal"&gt;&lt;span style="font-size:10.0pt;line-height:115%;font-family: &amp;quot;Verdana&amp;quot;,&amp;quot;sans-serif&amp;quot;;color:#222222;mso-no-proof:yes"&gt;&lt;!--[if gte vml 1]&gt;&lt;v:shape id="Picture_x0020_2" spid="_x0000_i1025" type="#_x0000_t75" alt="Open Close Principle(OCP) - good" style="'width:339.75pt;height:182.25pt;visibility:visible;mso-wrap-style:square'"&gt;  &lt;v:imagedata src="file:///C:\DOCUME~1\sanjib.k\LOCALS~1\Temp\msohtmlclip1\01\clip_image002.gif" title="Open Close Principle(OCP) - good"&gt; &lt;/v:shape&gt;&lt;![endif]--&gt;&lt;img width="453" height="243" src="http://www.oodesign.com/images/stories/ocp.good.gif" alt="Open Close Principle(OCP) - good" shapes="Picture_x0020_2" /&gt;&lt;/span&gt;&lt;span class="apple-style-span"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;h2&gt;&lt;span style="font-family:&amp;quot;Georgia&amp;quot;,&amp;quot;serif&amp;quot;;color:black;font-weight:normal"&gt;&lt;o:p&gt; &lt;/o:p&gt;&lt;/span&gt;&lt;/h2&gt;  &lt;pre&gt;&lt;span style="color:black"&gt;/ Open-Close Principle - Good example&lt;br /&gt;&lt;span style="mso-spacerun:yes"&gt; &lt;/span&gt;class GraphicEditor {&lt;br /&gt;&lt;span style="mso-spacerun:yes"&gt; &lt;/span&gt;&lt;span style="mso-tab-count:1"&gt;       &lt;/span&gt;public void drawShape(Shape s) {&lt;br /&gt;&lt;span style="mso-spacerun:yes"&gt; &lt;/span&gt;&lt;span style="mso-tab-count:2"&gt;              &lt;/span&gt;s.draw();&lt;br /&gt;&lt;span style="mso-spacerun:yes"&gt; &lt;/span&gt;&lt;span style="mso-tab-count:1"&gt;       &lt;/span&gt;}&lt;br /&gt;&lt;span style="mso-spacerun:yes"&gt; &lt;/span&gt;}&lt;br /&gt;&lt;span style="mso-spacerun:yes"&gt; &lt;/span&gt;&lt;br /&gt;&lt;span style="mso-spacerun:yes"&gt; &lt;/span&gt;class Shape {&lt;br /&gt;&lt;span style="mso-spacerun:yes"&gt; &lt;/span&gt;&lt;span style="mso-tab-count:1"&gt;       &lt;/span&gt;abstract void draw();&lt;br /&gt;&lt;span style="mso-spacerun:yes"&gt; &lt;/span&gt;}&lt;br /&gt;&lt;span style="mso-spacerun:yes"&gt; &lt;/span&gt;&lt;br /&gt;&lt;span style="mso-spacerun:yes"&gt; &lt;/span&gt;class Rectangle extends Shape&lt;span style="mso-spacerun:yes"&gt;  &lt;/span&gt;{&lt;br /&gt;&lt;span style="mso-spacerun:yes"&gt; &lt;/span&gt;&lt;span style="mso-tab-count:1"&gt;       &lt;/span&gt;public void draw() {&lt;br /&gt;&lt;span style="mso-spacerun:yes"&gt; &lt;/span&gt;&lt;span style="mso-tab-count:2"&gt;              &lt;/span&gt;// draw the rectangle&lt;br /&gt;&lt;span style="mso-spacerun:yes"&gt; &lt;/span&gt;&lt;span style="mso-tab-count:1"&gt;       &lt;/span&gt;}&lt;br /&gt;&lt;span style="mso-spacerun:yes"&gt; &lt;/span&gt;} &lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/pre&gt;  &lt;h2&gt;&lt;span style="font-family:&amp;quot;Georgia&amp;quot;,&amp;quot;serif&amp;quot;;color:black;font-weight:normal"&gt;&lt;o:p&gt; &lt;/o:p&gt;&lt;/span&gt;&lt;/h2&gt;    &lt;h2&gt;&lt;span style="font-family:&amp;quot;Georgia&amp;quot;,&amp;quot;serif&amp;quot;;color:black;font-weight:normal"&gt;Conclusion&lt;/span&gt;&lt;span style="font-size:18.0pt;line-height:115%;font-family:&amp;quot;Georgia&amp;quot;,&amp;quot;serif&amp;quot;; color:black;font-weight:normal"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/h2&gt;  &lt;p&gt;&lt;span style="font-size:10.0pt;font-family:&amp;quot;Verdana&amp;quot;,&amp;quot;sans-serif&amp;quot;;color:#222222"&gt;Like every principle OCP is only a principle. Making a flexible design involves additional time and effort spent for it and it introduce new level of abstraction increasing the complexity of the code. So this principle should be applied in those area which are most likely to be changed.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p&gt;&lt;span style="font-size:10.0pt;font-family:&amp;quot;Verdana&amp;quot;,&amp;quot;sans-serif&amp;quot;;color:#222222"&gt;There are many design patterns that help us to extend code without changing it. For instance the Decorator pattern help us to follow Open Close principle. Also the Factory Method or the Observer pattern might be used to design an application easy to change with minimum changes in the existing code.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p class="MsoNormal"&gt;&lt;o:p&gt; &lt;/o:p&gt;&lt;/p&gt;&lt;/span&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4903191105785361362-6662925184647529750?l=sanjib-swain.blogspot.com' alt='' /&gt;&lt;/div&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/VSIA_EIX3jz8TmoT-KbAopE9WKg/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/VSIA_EIX3jz8TmoT-KbAopE9WKg/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/VSIA_EIX3jz8TmoT-KbAopE9WKg/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/VSIA_EIX3jz8TmoT-KbAopE9WKg/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/blogspot/PEHIt/~4/y9s3RyibA3c" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://sanjib-swain.blogspot.com/feeds/6662925184647529750/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://www.blogger.com/comment.g?blogID=4903191105785361362&amp;postID=6662925184647529750" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/4903191105785361362/posts/default/6662925184647529750?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/4903191105785361362/posts/default/6662925184647529750?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/blogspot/PEHIt/~3/y9s3RyibA3c/software-design-principles-part-ii.html" title="Software Design Principles Part II" /><author><name>Sanjib Kumar Swain</name><uri>http://www.blogger.com/profile/11353921866017700402</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="32" height="24" src="http://3.bp.blogspot.com/_nnkYFjJnYR0/SjDB5r7-A4I/AAAAAAAAABg/5LvGBQSMBFM/S220/100_1083.JPG" /></author><thr:total>0</thr:total><feedburner:origLink>http://sanjib-swain.blogspot.com/2010/12/software-design-principles-part-ii.html</feedburner:origLink></entry><entry gd:etag="W/&quot;C0INQ3s5eip7ImA9Wx9QEE0.&quot;"><id>tag:blogger.com,1999:blog-4903191105785361362.post-1215686934167292443</id><published>2010-12-21T22:59:00.001-08:00</published><updated>2010-12-21T23:06:32.522-08:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2010-12-21T23:06:32.522-08:00</app:edited><title>Software Design Principles Part I</title><content type="html">&lt;b&gt;Design Principles&lt;/b&gt;&lt;br /&gt;&lt;br /&gt;&lt;i&gt; &gt; What are Software Design Principles?&lt;/i&gt;&lt;br /&gt;&lt;br /&gt;Software design principles represent a set of guidelines that helps us to avoid having a bad design. The design principles are associated to Robert Martin who gathered them in "Agile Software Development: Principles, Patterns, and Practices". According to Robert Martin there are 3 important characteristics of a bad design that should be avoided:&lt;br /&gt;&lt;br /&gt;&lt;span class="Apple-tab-span" style="white-space:pre"&gt; &lt;/span&gt;Rigidity - It is hard to change because every change affects too many other parts of the &lt;span class="Apple-tab-span" style="white-space:pre"&gt;   &lt;/span&gt;system.&lt;br /&gt;&lt;span class="Apple-tab-span" style="white-space:pre"&gt; &lt;/span&gt;Fragility - When you make a change, unexpected parts of the system break.&lt;br /&gt;&lt;span class="Apple-tab-span" style="white-space:pre"&gt; &lt;/span&gt;Immobility - It is hard to reuse in another application because it cannot be disentangled &lt;span class="Apple-tab-span" style="white-space:pre"&gt;    &lt;/span&gt;from the current application.&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;Open Close Principle&lt;/b&gt;&lt;br /&gt;&lt;br /&gt;Software entities like classes, modules and functions should be open for extension but closed for modifications.&lt;br /&gt;OPC is a generic principle. You can consider it when writing your classes to make sure that when you need to extend their behavior you don’t have to change the class but to extend it. The same principle can be applied for modules, packages, libraries. If you have a library containing a set of classes there are many reasons for which you’ll prefer to extend it without changing the code that was already written (backward compatibility, regression testing, …). This is why we have to make sure our modules follow Open Closed Principle.&lt;br /&gt;&lt;br /&gt;When referring to the classes Open Close Principle can be ensured by use of Abstract Classes and concrete classes for implementing their behavior. This will enforce having Concrete Classes extending Abstract Classes instead of changing them. Some particular cases of this are Template Pattern and Strategy Pattern.&lt;br /&gt;&lt;br /&gt;&lt;b&gt;Dependency Inversion Principle&lt;/b&gt;&lt;br /&gt;&lt;br /&gt;High-level modules should not depend on low-level modules. Both should depend on abstractions.&lt;br /&gt;Abstractions should not depend on details. Details should depend on abstractions.&lt;br /&gt;Dependency Inversion Principle states that we should decouple high level modules from low level modules, introducing an abstraction layer between the high level classes and low level classes. Further more it inverts the dependency: instead of writing our abstractions based on details, the we should write the details based on abstractions.&lt;br /&gt;&lt;br /&gt;Dependency Inversion or Inversion of Control are better know terms referring to the way in which the dependencies are realized. In the classical way when a software module(class, framework, …) need some other module, it initializes and holds a direct reference to it. This will make the 2 modules tight coupled. In order to decouple them the first module will provide a hook(a property, parameter, …) and an external module controlling the dependencies will inject the reference to the second one.&lt;br /&gt;&lt;br /&gt;By applying the Dependency Inversion the modules can be easily changed by other modules just changing the dependency module. Factories and Abstract Factories can be used as dependency frameworks, but there are specialized frameworks for that, known as Inversion of Control Container.&lt;br /&gt;&lt;br /&gt;&lt;b&gt;Interface Segregation Principle&lt;/b&gt;&lt;br /&gt;&lt;br /&gt;Clients should not be forced to depend upon interfaces that they don't use.&lt;br /&gt;This principle teaches us to take care how we write our interfaces. When we write our interfaces we should take care to add only methods that should be there. If we add methods that should not be there the classes implementing the interface will have to implement those methods as well. For example if we create an interface called Worker and add a method lunch break, all the workers will have to implement it. What if the worker is a robot?&lt;br /&gt;&lt;br /&gt;As a conclusion Interfaces containing methods that are not specific to it are called polluted or fat interfaces. We should avoid them.&lt;br /&gt;&lt;br /&gt;&lt;b&gt;Single Responsibility Principle&lt;/b&gt;&lt;br /&gt;&lt;br /&gt;A class should have only one reason to change.&lt;br /&gt;In this context a responsibility is considered to be one reason to change. This principle states that if we have 2 reasons to change for a class, we have to split the functionality in two classes. Each class will handle only one responsibility and on future if we need to make one change we are going to make it in the class which handle it. When we need to make a change in a class having more responsibilities the change might affect the other functionality of the classes.&lt;br /&gt;&lt;br /&gt;Single Responsibility Principle was introduced Tom DeMarco in his book Structured Analysis and Systems Specification, 1979. Robert Martin reinterpreted the concept and defined the responsibility as a reason to change.&lt;br /&gt;&lt;br /&gt;&lt;b&gt;Liskov's Substitution Principle&lt;/b&gt;&lt;br /&gt;&lt;br /&gt;Derived types must be completely substitutable for their base types.&lt;br /&gt;This principle is just an extension of the Open Close Principle in terms of behavior meaning that we must make sure that new derived classes are extending the base classes without changing their behavior. The new derived classes should be able to replace the base classes without any change in the code.&lt;br /&gt;&lt;br /&gt;Liskov's Substitution Principle was introduced by Barbara Liskov in a 1987 Conference on Object Oriented Programming Systems Languages and Applications, in Data abstraction and hierarchy&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4903191105785361362-1215686934167292443?l=sanjib-swain.blogspot.com' alt='' /&gt;&lt;/div&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/1Jwx3poVLJ_Z9hHByKKM7fj1-f8/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/1Jwx3poVLJ_Z9hHByKKM7fj1-f8/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/1Jwx3poVLJ_Z9hHByKKM7fj1-f8/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/1Jwx3poVLJ_Z9hHByKKM7fj1-f8/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/blogspot/PEHIt/~4/gxeuG1oqH98" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://sanjib-swain.blogspot.com/feeds/1215686934167292443/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://www.blogger.com/comment.g?blogID=4903191105785361362&amp;postID=1215686934167292443" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/4903191105785361362/posts/default/1215686934167292443?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/4903191105785361362/posts/default/1215686934167292443?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/blogspot/PEHIt/~3/gxeuG1oqH98/software-design-principles-part-i.html" title="Software Design Principles Part I" /><author><name>Sanjib Kumar Swain</name><uri>http://www.blogger.com/profile/11353921866017700402</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="32" height="24" src="http://3.bp.blogspot.com/_nnkYFjJnYR0/SjDB5r7-A4I/AAAAAAAAABg/5LvGBQSMBFM/S220/100_1083.JPG" /></author><thr:total>0</thr:total><feedburner:origLink>http://sanjib-swain.blogspot.com/2010/12/software-design-principles-part-i.html</feedburner:origLink></entry><entry gd:etag="W/&quot;DUYNQH46eip7ImA9Wx9TEEs.&quot;"><id>tag:blogger.com,1999:blog-4903191105785361362.post-6671248709612268215</id><published>2010-11-17T23:54:00.001-08:00</published><updated>2010-11-17T23:59:51.012-08:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2010-11-17T23:59:51.012-08:00</app:edited><title>Java 5 : Extended</title><content type="html">This page describe the major new features added in Java 5.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight:bold;"&gt;&lt;span class="Apple-style-span" &gt;Annotations (Metadata)&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;avoids need for external configuration files, allowing configuration data to be embedded in source files&lt;br /&gt;avoids duplicated boilerplate code by enabling tools to generate it from annotations in source code&lt;br /&gt;leads to a declarative programming style&lt;br /&gt;an example of a specific annotation added in Java 5 is @Override which marks a method that overrides a superclass method&lt;br /&gt;for more information, see here&lt;br /&gt;&lt;span style="font-weight:bold;"&gt;&lt;span class="Apple-style-span" &gt;Autoboxing/Unboxing&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;avoids need to convert between primitives and their corresponding type wrapper objects&lt;br /&gt;basic example&lt;br /&gt;int i = 19;&lt;br /&gt;Integer iObj = i;&lt;br /&gt;int j = iObj;&lt;br /&gt;// i and j are equal&lt;br /&gt;collections example&lt;br /&gt;List&lt;integer&gt; list = new ArrayList&lt;integer&gt;(); // see "Generics"&lt;br /&gt;int i = 19;&lt;br /&gt;list.add(i);&lt;br /&gt;int j = list.get(0);&lt;br /&gt;// i and j are equal&lt;br /&gt;overuse can result in performance issues&lt;br /&gt;for more information, see here&lt;br /&gt;&lt;span style="font-weight:bold;"&gt;Enhanced For Loop&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;array example&lt;br /&gt; Car[] cars = new Car[](5);&lt;br /&gt; // populate array of Car objects&lt;br /&gt; for (Car car : cars) {&lt;br /&gt;   // Use the variable car inside the loop.&lt;br /&gt; }&lt;br /&gt;list example&lt;br /&gt; List&lt;car&gt; cars = new ArrayList&lt;car&gt;() // see "Generics"&lt;br /&gt; // populate List of Car objects&lt;br /&gt; for (Car car : cars) {&lt;br /&gt;   // Use the variable car inside the loop.&lt;br /&gt; }&lt;br /&gt;for more information, see here&lt;br /&gt;&lt;span style="font-weight:bold;"&gt;&lt;span class="Apple-style-span" &gt;Enums&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;can create enumerated types with arbitrary fields and methods&lt;br /&gt;example&lt;br /&gt; enum Season { WINTER, SPRING, SUMMER, FALL }&lt;br /&gt; Season season = SPRING;&lt;br /&gt; for (Season season : Season.values()) {&lt;br /&gt;   // use season variable&lt;br /&gt; }&lt;br /&gt;to get the integer value of an enumerated value, invoke the ordinal method on it&lt;br /&gt;for more information, see here (includes an example of adding fields and methods to enums)&lt;br /&gt;&lt;span style="font-weight:bold;"&gt;&lt;span class="Apple-style-span" &gt;Generics&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;most often used for type-safe collections&lt;br /&gt;example&lt;br /&gt; List&lt;string&gt; myList = new ArrayList&lt;string&gt;();&lt;br /&gt; // only String objects can be added to myList.&lt;br /&gt;collections of subclass objects can be passed to methods that accept collections of superclass objects (for example, an object of type List&lt;dog&gt; can be passed to a method that accepts List or even List)&lt;br /&gt;for more information, see here&lt;br /&gt;Static Import&lt;br /&gt;&lt;br /&gt;avoids the need to qualify static members of classes or interfaces with the class or interface name&lt;br /&gt;example from JUnit 4&lt;br /&gt; import static org.junit.Assert.*;&lt;br /&gt; // can now use static assert methods from the Assert class&lt;br /&gt; // without prefixing them with "Assert."&lt;br /&gt;note that the ".*" part says to import all the static members from the Assert class (can't omit that!)&lt;br /&gt;for more information, see here&lt;br /&gt;&lt;span style="font-weight:bold;"&gt;&lt;span class="Apple-style-span" &gt;Varargs&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;eliminates the need to put arguments into an array for the purpose of passing a variable number of arguments to a method&lt;br /&gt;example&lt;br /&gt; public void washCars(Car... cars) {&lt;br /&gt;   for (int i = 0; i &lt; cars.length; i++) {&lt;br /&gt;     Car car = cars[i];&lt;br /&gt;     // wash the car&lt;br /&gt;   }&lt;br /&gt; }&lt;br /&gt;&lt;br /&gt; // call like this&lt;br /&gt; washCars(car1, car2, car3);&lt;br /&gt;the type of cars is Car[]&lt;br /&gt;&lt;/dog&gt;&lt;/string&gt;&lt;/string&gt;&lt;/car&gt;&lt;/car&gt;&lt;/integer&gt;&lt;/integer&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4903191105785361362-6671248709612268215?l=sanjib-swain.blogspot.com' alt='' /&gt;&lt;/div&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/-ShlnQYEnWbtyU2asF5l0Hh1tfQ/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/-ShlnQYEnWbtyU2asF5l0Hh1tfQ/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/-ShlnQYEnWbtyU2asF5l0Hh1tfQ/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/-ShlnQYEnWbtyU2asF5l0Hh1tfQ/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/blogspot/PEHIt/~4/inZCIQ4V7bU" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://sanjib-swain.blogspot.com/feeds/6671248709612268215/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://www.blogger.com/comment.g?blogID=4903191105785361362&amp;postID=6671248709612268215" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/4903191105785361362/posts/default/6671248709612268215?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/4903191105785361362/posts/default/6671248709612268215?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/blogspot/PEHIt/~3/inZCIQ4V7bU/java-5-extended.html" title="Java 5 : Extended" /><author><name>Sanjib Kumar Swain</name><uri>http://www.blogger.com/profile/11353921866017700402</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="32" height="24" src="http://3.bp.blogspot.com/_nnkYFjJnYR0/SjDB5r7-A4I/AAAAAAAAABg/5LvGBQSMBFM/S220/100_1083.JPG" /></author><thr:total>0</thr:total><feedburner:origLink>http://sanjib-swain.blogspot.com/2010/11/java-5-extended.html</feedburner:origLink></entry><entry gd:etag="W/&quot;DUcNSH09eSp7ImA9Wx5aE0s.&quot;"><id>tag:blogger.com,1999:blog-4903191105785361362.post-2417603182617027533</id><published>2010-11-09T21:22:00.000-08:00</published><updated>2010-11-09T21:31:39.361-08:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2010-11-09T21:31:39.361-08:00</app:edited><title>LOG4J :Best Practice</title><content type="html">I’ve seen these antipatterns over and over again, and I thought it was time to write about them to help any folks who are new to Log4J out there. Senior developers – please share this with your junior peers and save yourself the pain of refactoring later! I’m interested in common mistakes or points of confusion that you’ve seen as well.&lt;br /&gt;&lt;br /&gt;Read on to get a quick tutorial, or reference to point your developers at…&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight:bold;"&gt;Mistake 1: Not logging exceptions at all&lt;span style="font-weight:bold;"&gt;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;Many times, developers don’t realize that there are overloaded versions of the basic log4j methods. I have seen this more times than I can count:&lt;br /&gt;&lt;br /&gt; catch(SomeMeaningfulException e) {&lt;br /&gt;   LOG.error("Bad things: " + e.getMessage());&lt;br /&gt; }&lt;br /&gt;Why is this bad? Because you just lost the single most valuable piece of information in the exception: the stack trace! Obviously, a well-thought out exception strategy is ideal, but at the very least, do this:&lt;br /&gt;&lt;br /&gt;  LOG.error("Bad things",e);&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight:bold;"&gt;Mistake 2: Not logging exceptions with the correct method&lt;/span&gt;&lt;br /&gt;&lt;br /&gt; catch(SomeMeaningfulException e) {&lt;br /&gt;   LOG.error("Bad things");&lt;br /&gt;   LOG.error(e);&lt;br /&gt; }&lt;br /&gt;This is a tricky one. The single-parameter method signature for log4j will simply call toString on the object passed in. In the case of a Throwable, this means you will get the output of getMessage; thus you have exactly the same result as in #1.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight:bold;"&gt;Mistake 3: Not adding thread name to PatternLayout&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;Many, many sample log4j configuration files to be found on the net (such as this &lt;a href="http://www.java2s.com/Code/Java/Language-Basics/Examplelog4jConfigurationFile.htm"&gt;example&lt;/a&gt;) exclude the crucial thread name property (%t). This is absolutely required when using log4j in any kind of multi-user environment. Without it (and without smart alternative use of something like the MDC/NDC functionality), it’s impossible to trace a series of log statements to a single, consecutive, series of actions — for example, a user request in most modern web frameworks.&lt;br /&gt;&lt;br /&gt;Make sure you include the %t conversion parameter if you’re running in any multi-user environment!&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight:bold;"&gt;Mistake 4: Not making appropriate use of log categories&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;It’s very common to use the typical fully qualified class name as the name of the Category you log to:&lt;br /&gt;&lt;br /&gt; static Logger LOG = Logger.getLogger(ThisClass.getClass());&lt;br /&gt;This is all well and good, but suffers from 2 flaws:&lt;br /&gt;&lt;br /&gt;Developers tend to copy and paste this boilerplate code from one class to another. Since the class names are often hard-coded in the static initializer, this is a pattern that is extremely vulnerable to copy-and-paste errors. Java unfortunately doesn’t allow ‘this’ in a static context, and doesn’t have an alternative way to refer to “the current Class”.&lt;br /&gt;It doesn’t offer logical organization, especially for API providers. One of the brilliant things that the Hibernate team did in their use of logging is that, in addition to FQCN-named loggers, they identified a series of key “logical” logging categories that abstracted common logging use cases into simple categories (most notably logging of all SQL statements, which can happen in many different classes using the same logical category.&lt;br /&gt;There are various tricks to avoid this scenario.&lt;br /&gt;&lt;br /&gt;Checkstyle can look for common log4j antipatterns. You’re using checkstyle anyway, right?&lt;br /&gt;You can create a logger factory which will look on the call stack for the current class name (as shown here).&lt;br /&gt;You can use smart annotations or DI (such as is easily done with Guice) to annotate your Loggers and fill in at runtime.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight:bold;"&gt;Mistake 5: Not understanding how (or where) log4j is configured&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;It’s amazingly common for developers not to know how to configure log4j, or even know where to start to set it up. I personally have answered many, many questions from both co-workers and forum / mailing list folks who can’t figure out how to get started with log4j. Usually this is in conjunction with 3rd party libraries like Spring or Hibernate, running in a web application.&lt;br /&gt;&lt;br /&gt;Admittedly, the log4j documentation is not super clear on this subject, and I will attempt to cover the very common scenarios that I have seen confuse developers.&lt;br /&gt;&lt;br /&gt;If you are running in a web application, generally the log4j configuration file will go in WEB-INF/classes. If you are building in Eclipse, you can explicitly create this directory, or (in some versions of Eclipse) place it in your Java source root directory and it will go to the right place.&lt;br /&gt;If you are running in a console application, the log4j configuration file must be somewhere on your CLASSPATH.&lt;br /&gt;You need to have log4j configuration defined in a file called log4j.xml (using the DOMConfigurator syntax), or log4j.properties (using the PropertyConfigurator syntax).&lt;br /&gt;&lt;br /&gt;Reference: log4j Default Initialization Procedure&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4903191105785361362-2417603182617027533?l=sanjib-swain.blogspot.com' alt='' /&gt;&lt;/div&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/PrwAQfLqDmf72jgFtf4vA9N33pU/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/PrwAQfLqDmf72jgFtf4vA9N33pU/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/PrwAQfLqDmf72jgFtf4vA9N33pU/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/PrwAQfLqDmf72jgFtf4vA9N33pU/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/blogspot/PEHIt/~4/6Efq1V_p70o" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://sanjib-swain.blogspot.com/feeds/2417603182617027533/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://www.blogger.com/comment.g?blogID=4903191105785361362&amp;postID=2417603182617027533" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/4903191105785361362/posts/default/2417603182617027533?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/4903191105785361362/posts/default/2417603182617027533?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/blogspot/PEHIt/~3/6Efq1V_p70o/log4j-best-practice.html" title="LOG4J :Best Practice" /><author><name>Sanjib Kumar Swain</name><uri>http://www.blogger.com/profile/11353921866017700402</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="32" height="24" src="http://3.bp.blogspot.com/_nnkYFjJnYR0/SjDB5r7-A4I/AAAAAAAAABg/5LvGBQSMBFM/S220/100_1083.JPG" /></author><thr:total>0</thr:total><feedburner:origLink>http://sanjib-swain.blogspot.com/2010/11/log4j-best-practice.html</feedburner:origLink></entry><entry gd:etag="W/&quot;DEUDSHwzeyp7ImA9Wx5VEkU.&quot;"><id>tag:blogger.com,1999:blog-4903191105785361362.post-5571190203401128342</id><published>2010-10-05T06:41:00.000-07:00</published><updated>2010-10-05T06:44:39.283-07:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2010-10-05T06:44:39.283-07:00</app:edited><title>Eclipse Java Autocompletion Not Working</title><content type="html">Try restoring the default options in 'Windows &gt; Preferences &gt; Java &gt; Editor &gt; Content Assist &gt; Advanced'&lt;br /&gt;&lt;br /&gt;Select all in the content table .&lt;br /&gt;&lt;br /&gt;now you  have done with code completion.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4903191105785361362-5571190203401128342?l=sanjib-swain.blogspot.com' alt='' /&gt;&lt;/div&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/Din7EY16Dhy1N-X3l8wTp6sLHI8/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/Din7EY16Dhy1N-X3l8wTp6sLHI8/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/Din7EY16Dhy1N-X3l8wTp6sLHI8/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/Din7EY16Dhy1N-X3l8wTp6sLHI8/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/blogspot/PEHIt/~4/N62l0DjqGMs" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://sanjib-swain.blogspot.com/feeds/5571190203401128342/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://www.blogger.com/comment.g?blogID=4903191105785361362&amp;postID=5571190203401128342" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/4903191105785361362/posts/default/5571190203401128342?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/4903191105785361362/posts/default/5571190203401128342?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/blogspot/PEHIt/~3/N62l0DjqGMs/eclipse-java-autocompletion-not-working.html" title="Eclipse Java Autocompletion Not Working" /><author><name>Sanjib Kumar Swain</name><uri>http://www.blogger.com/profile/11353921866017700402</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="32" height="24" src="http://3.bp.blogspot.com/_nnkYFjJnYR0/SjDB5r7-A4I/AAAAAAAAABg/5LvGBQSMBFM/S220/100_1083.JPG" /></author><thr:total>0</thr:total><feedburner:origLink>http://sanjib-swain.blogspot.com/2010/10/eclipse-java-autocompletion-not-working.html</feedburner:origLink></entry><entry gd:etag="W/&quot;CEIBSXgycCp7ImA9Wx5REE8.&quot;"><id>tag:blogger.com,1999:blog-4903191105785361362.post-9094510622156753726</id><published>2010-08-16T22:21:00.000-07:00</published><updated>2010-08-16T22:22:38.698-07:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2010-08-16T22:22:38.698-07:00</app:edited><title>Java Threads  : Volatile vs Synchronized</title><content type="html">This can be best understood by looking at the effects that volatile &amp; synchronized on a method. volatile is a field modifier, while synchronized modifies code blocks and methods. So we can specify three variations of a simple accessor using those two keywords:&lt;br /&gt;&lt;br /&gt;int i1;              int geti1() {return i1;}&lt;br /&gt;&lt;br /&gt;volatile int i2;              int geti2() {return i2;}&lt;br /&gt;&lt;br /&gt;int i3; synchronized int geti3() {return i3;}&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;geti1() accesses the value currently stored in i1 in the current thread. Threads can have local copies of variables, and the data does not have to be the same as the data held in other threads. In particular, another thread may have updated i1 in it’s thread, but the value in the current thread could be different from that updated value. In fact Java has the idea of a “main” memory, and this is the memory that holds the current “correct” value for variables. Threads can have their own copy of data for variables, and the thread copy can be different from the “main” memory. So in fact, it is possible for the “main” memory to have a value of 1 for i1, for thread1 to have a value of 2 for i1 and for thread2 to have a value of 3 for i1 if thread1 and thread2 have both updated i1 but those updated value has not yet been propagated to “main” memory or other threads.&lt;br /&gt;&lt;br /&gt;On the other hand, geti2() effectively accesses the value of i2 from “main” memory. A volatile variable is not allowed to have a local copy of a variable that is different from the value currently held in “main” memory. Effectively, a variable declared volatile must have it’s data synchronized across all threads, so that whenever you access or update the variable in any thread, all other threads immediately see the same value. Of course, it is likely that volatile variables have a higher access and update overhead than “plain” variables, since the reason threads can have their own copy of data is for better efficiency.&lt;br /&gt;&lt;br /&gt;Well if volatile already synchronizes data across threads, what is synchronized for? Well there are two differences. Firstly synchronized obtains and releases locks on monitors which can force only one thread at a time to execute a code block, if both threads use the same monitor (effectively the same object lock). That’s the fairly well known aspect to synchronized. But synchronized also synchronizes memory. In fact synchronized synchronizes the whole of thread memory with “main” memory. So executing geti3() does the following:&lt;br /&gt;&lt;br /&gt;The thread acquires the lock on the monitor for object this (assuming the monitor is unlocked, otherwise the thread waits until the monitor is unlocked).&lt;br /&gt;The thread memory flushes all its variables, i.e. it has all of its variables effectively read from “main” memory (JVMs can use dirty sets to optimize this so that only “dirty” variables are flushed, but conceptually this is the same. See section 17.9 of the Java language specification).&lt;br /&gt;The code block is executed (in this case setting the return value to the current value of i3, which may have just been reset from “main” memory).&lt;br /&gt;(Any changes to variables would normally now be written out to “main” memory, but for geti3() we have no changes.)&lt;br /&gt;The thread releases the lock on the monitor for object this.&lt;br /&gt;So where volatile only synchronizes the value of one variable between thread memory and “main” memory, synchronized synchronizes the value of all variables between thread memory and “main” memory, and locks and releases a monitor to boot. Clearly synchronized is likely to have more overhead than volatile.&lt;br /&gt;&lt;br /&gt;Using the volatile keyword ensures that the variable is never kept in a register. This&lt;br /&gt;&lt;br /&gt;guarantees that the variable is truly shared between threads.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Synchronization boundaries signal to the virtual machine that it must invalidate its registers.&lt;br /&gt;&lt;br /&gt;When the virtual machine enters a synchronized method or block, it must reload data it has cached in its local registers. Before the virtual machine exits a synchronization method or block, it must store its local registers to main memory.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4903191105785361362-9094510622156753726?l=sanjib-swain.blogspot.com' alt='' /&gt;&lt;/div&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/JvmDLLPL1z4ZgaFzpL-GI6PZDPA/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/JvmDLLPL1z4ZgaFzpL-GI6PZDPA/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/JvmDLLPL1z4ZgaFzpL-GI6PZDPA/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/JvmDLLPL1z4ZgaFzpL-GI6PZDPA/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/blogspot/PEHIt/~4/ttA5hq73g_M" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://sanjib-swain.blogspot.com/feeds/9094510622156753726/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://www.blogger.com/comment.g?blogID=4903191105785361362&amp;postID=9094510622156753726" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/4903191105785361362/posts/default/9094510622156753726?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/4903191105785361362/posts/default/9094510622156753726?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/blogspot/PEHIt/~3/ttA5hq73g_M/java-threads-volatile-vs-synchronized.html" title="Java Threads  : Volatile vs Synchronized" /><author><name>Sanjib Kumar Swain</name><uri>http://www.blogger.com/profile/11353921866017700402</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="32" height="24" src="http://3.bp.blogspot.com/_nnkYFjJnYR0/SjDB5r7-A4I/AAAAAAAAABg/5LvGBQSMBFM/S220/100_1083.JPG" /></author><thr:total>0</thr:total><feedburner:origLink>http://sanjib-swain.blogspot.com/2010/08/java-threads-volatile-vs-synchronized.html</feedburner:origLink></entry><entry gd:etag="W/&quot;C0YDSXk-eCp7ImA9WxBQEko.&quot;"><id>tag:blogger.com,1999:blog-4903191105785361362.post-242794734406997953</id><published>2010-01-11T20:37:00.000-08:00</published><updated>2010-01-11T20:39:38.750-08:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2010-01-11T20:39:38.750-08:00</app:edited><title>Lucene: A Tutorial Introduction to Full-Text Indexing in Java</title><content type="html">Lucene is a powerful and elegant library for full-text indexing and searching in Java. In this article, we go through some Lucene basics, by adding simple yet powerful full-text index and search functions to a typical J2EE web application.&lt;br /&gt;NOTE&lt;br /&gt;For your convenience, all of the code for this article’s Lucene demo is included in a source.zip file.&lt;br /&gt;Full-Text Searching&lt;br /&gt;Nowadays, any modern web site worth its salt is considered to need a "Google-like" search function. Complex multi-criteria search screens are often perceived by users as being too complex, and are in fact rarely used. Users want to be able to just type the word(s) they’re seeking and have the computer do the rest. This explains the growing popularity of search engines such as those of Yahoo! and Google and, more recently, tools such as Google Desktop.&lt;br /&gt;If you need to add this sort of rich full-text search functionality to your Java web application, look no further! Lucene is an extremely rich and powerful full-text search API written in Java. You can use Lucene to provide consistent full-text indexing across both database objects and documents in various formats (Microsoft Office documents, PDF, HTML, text, and so on).&lt;br /&gt;In this article, we’ll go through the basics of using Lucene to add full-text search functionality to a fairly typical J2EE application—an online accommodation database. The main business object is the Hotel class. In this tutorial, a Hotel has a unique identifier, a name, a city, and a description.&lt;br /&gt;NOTE&lt;br /&gt;We won’t worry about the underlying storage mechanism (JDBC, Hibernate, EJB 3, or whatever) or the display layer technology (JSP/Struts, JFS, Tapestry, or whatever). We’ll just focus on the business layer and the indexing and search functionalities, which are largely independent of the other architectural layers.&lt;br /&gt;Creating an Index&lt;br /&gt;The first step in implementing full-text searching with Lucene is to build an index. This is easy—you just specify a directory and an analyzer class. The analyzer breaks text fields into indexable tokens; this is a core part of Lucene.&lt;br /&gt;Several types of analyzers are provided out of the box. Table 1 shows some of the more interesting ones.&lt;br /&gt;Table 1 Lucene analyzers.&lt;br /&gt;Analyzer Description&lt;br /&gt;StandardAnalyzer A sophisticated general-purpose analyzer.&lt;br /&gt;WhitespaceAnalyzer A very simple analyzer that just separates tokens using white space.&lt;br /&gt;StopAnalyzer Removes common English words that are not usually useful for indexing.&lt;br /&gt;SnowballAnalyzer An interesting experimental analyzer that works on word roots (a search on rain should also return entries with raining, rained, and so on).&lt;br /&gt;There are even a number of language-specific analyzers, including analyzers for German, Russian, French, Dutch, and others.&lt;br /&gt;It isn’t difficult to implement your own analyzer, though the standard ones often do the job well enough. For the sake of simplicity, we’ll use the StandardAnalyzer in this tutorial.&lt;br /&gt;Next, we need to create an IndexWriter object. The IndexWriter object is used to create the index and to add new index entries to this index. You can create an IndexWriter with the StandardAnalyzer analyzer as follows:&lt;br /&gt;IndexWriter indexWriter = new IndexWriter("index", new StandardAnalyzer(),true);&lt;br /&gt;Indexing an Object&lt;br /&gt;Now you need to index your business objects. To index an object, you use the Lucene Document class, to which you add the fields that you want indexed. A Lucene Document is basically a container for a set of indexed fields. This is best illustrated by an example:&lt;br /&gt;Document doc = new Document();&lt;br /&gt;doc.add(new Field("description", hotel.getDescription(), Field.Store.YES, Field.Index.TOKENIZED));&lt;br /&gt; To add a field to a document, you create a new instance of the Field class. A field is made up of a name and a value (the first two parameters in the class constructor). The value may take the form of a String, or a Reader if the object to be indexed is a file.&lt;br /&gt;The two other parameters are used to determine how the field will be stored and indexed in the Lucene index:&lt;br /&gt;• Storing the value. Does the value need to be stored in the index, or just indexed and discarded? Storing the value is useful if the value should be displayed in the search result list, for example. If the value must be stored, use Field.Store.YES. You can also use Field.Store.COMPRESS for large documents or binary value fields. If you don’t need to store the value, use Field.Store.NO.&lt;br /&gt;• Indexing the value. Does the value need to be indexed? A database identified, for example, may just be stored and used later for object retrieval, but not indexed. In this case, you use Field.Index.NO. In most other cases, you’ll index the value using the token analyzer associated with the index writer. To do this, you use Field.Index.TOKENIZED. The value Field.Index.UN_TOKENIZED can be used if you need to index a value without parsing it with the analyzer; in this case, the value will be used "as is."&lt;br /&gt;For our example, we just want some fairly simple full-text searching. So we add the following fields:&lt;br /&gt;• The hotel identifier, so we can retrieve the object later on from the query result list.&lt;br /&gt;• The hotel name, which we need to display in the query result lists.&lt;br /&gt;• The hotel description, if we need to display this information in the query result lists.&lt;br /&gt;• Composite text containing key fields of the Hotel object: &lt;br /&gt;o Hotel name&lt;br /&gt;o Hotel city&lt;br /&gt;o Hotel description&lt;br /&gt;We want full-text indexing on this field. We don’t need to display the indexed text in the query results, so we use Field.Store.NO to save index space.&lt;br /&gt;Here’s the method that indexes a given hotel:&lt;br /&gt;public static void indexHotel(Hotel hotel) throws IOException {&lt;br /&gt;  IndexWriter writer = (IndexWriter) getIndexWriter(false);&lt;br /&gt;  Document doc = new Document();&lt;br /&gt;  doc.add(new Field("id", hotel.getId(), Field.Store.YES,&lt;br /&gt;                      Field.Index.NO));&lt;br /&gt;  doc.add(new Field("name", hotel.getName(), Field.Store.YES,&lt;br /&gt;                        Field.Index.TOKENIZED));&lt;br /&gt;  doc.add(new Field("city", hotel.getCity(), Field.Store.YES,&lt;br /&gt;                        Field.Index.UN_TOKENIZED));&lt;br /&gt;  doc.add(new Field("description", hotel.getDescription(),&lt;br /&gt;                   Field.Store.YES,&lt;br /&gt;                   Field.Index.TOKENIZED));&lt;br /&gt;  String fullSearchableText&lt;br /&gt;        = hotel.getName()&lt;br /&gt;         + " " + hotel.getCity() + " " + hotel.getDescription();&lt;br /&gt;&lt;br /&gt;  doc.add(new Field("content", fullSearchableText,&lt;br /&gt;                 Field.Store.NO,&lt;br /&gt;                 Field.Index.TOKENIZED));&lt;br /&gt;  writer.addDocument(doc);&lt;br /&gt;}&lt;br /&gt;Once the indexing is finished, you have to close the index writer, which updates and closes the associated files on the disk. Opening and closing the index writer is time-consuming, so it’s not a good idea to do it systematically for each operation in the case of batch updates. For example, here’s a function that rebuilds the whole index:&lt;br /&gt;public void rebuildIndexes() throws IOException {&lt;br /&gt;   //&lt;br /&gt;   // Erase existing index&lt;br /&gt;   //&lt;br /&gt;   getIndexWriter(true);&lt;br /&gt;   //&lt;br /&gt;   // Index all hotel entries&lt;br /&gt;   //&lt;br /&gt;   Hotel[] hotels = HotelDatabase.getHotels();&lt;br /&gt;   for(Hotel hotel: hotels) {&lt;br /&gt;     indexHotel(hotel);&lt;br /&gt;   }&lt;br /&gt;   //&lt;br /&gt;   // Don’t forget to close the index writer when done&lt;br /&gt;   //&lt;br /&gt;   closeIndexWriter();&lt;br /&gt; }&lt;br /&gt;Full-Text Searching&lt;br /&gt;Now that we’ve indexed our database, we can do some searching. Full-text searching is done using the IndexSearcher and QueryParser classes. You provide an analyzer object to the QueryParser; note that this must be the same one used during the indexing. You also specify the field that you want to search, and the (user-provided) full-text query. Here’s the class that handles the search function:&lt;br /&gt;public class SearchEngine {&lt;br /&gt;&lt;br /&gt;  /** Creates a new instance of SearchEngine */&lt;br /&gt;  public SearchEngine() {&lt;br /&gt;  }&lt;br /&gt;&lt;br /&gt;  public Hits performSearch(String queryString)&lt;br /&gt;           throws IOException, ParseException {&lt;br /&gt;&lt;br /&gt;    Analyzer analyzer = new StandardAnalyzer();&lt;br /&gt;    IndexSearcher is = new IndexSearcher("index");&lt;br /&gt;    QueryParser parser = new QueryParser("content", analyzer);&lt;br /&gt;    Query query = parser.parse(queryString);&lt;br /&gt;    Hits hits = is.search(query);&lt;br /&gt;    return hits;&lt;br /&gt;  }&lt;br /&gt;}&lt;br /&gt;The search() function returns a Lucene Hits object. This object contains a list of Lucene Hit objects, in order of relevance. The resulting Document objects can be obtained directly, as shown here:&lt;br /&gt;Hits hits = instance.performSearch("Notre Dame");&lt;br /&gt; for(int i = 0; i &lt; hits.length(); i++) {&lt;br /&gt;   Document doc = hits.doc(i);&lt;br /&gt;   String hotelName = doc.get("name");&lt;br /&gt;  ...&lt;br /&gt; }&lt;br /&gt;As in this example, once you obtain the Document object, you can use the get() method to fetch field values that have been stored during indexing.&lt;br /&gt;Another possible approach is to use an Iterator, as in the following example:&lt;br /&gt;public void testPerformSearch() throws Exception {&lt;br /&gt; System.out.println("performSearch");&lt;br /&gt; SearchEngine instance = new SearchEngine();&lt;br /&gt; Hits hits = instance.performSearch("Notre Dame museum");&lt;br /&gt;&lt;br /&gt; System.out.println("Results found: " + hits.length());&lt;br /&gt; Iterator&lt;Hit&gt; iter = hits.iterator();&lt;br /&gt; while(iter.hasNext()){&lt;br /&gt;   Hit hit = iter.next();&lt;br /&gt;   Document doc = hit.getDocument();&lt;br /&gt;   System.out.println(doc.get("name")&lt;br /&gt;            + " " + doc.get("city")&lt;br /&gt;            + " (" + hit.getScore() + ")");&lt;br /&gt;&lt;br /&gt; }&lt;br /&gt;  System.out.println("performSearch done");&lt;br /&gt;}&lt;br /&gt;In this example, you can see how the Hit object can be used not only to fetch the corresponding document, but also to fetch the relative "score"—getScore()—obtained by this document in the search. The score gives an idea of the relative pertinence of each document in the result set. For example, the unit test above produces the following output:&lt;br /&gt;performSearch&lt;br /&gt;Results found: 9&lt;br /&gt;Hôtel Notre Dame Paris (0.5789772)&lt;br /&gt;Hôtel Odeon Paris (0.40939873)&lt;br /&gt;Hôtel Tonic Paris (0.34116563)&lt;br /&gt;Hôtel Bellevue Paris (0.34116563)&lt;br /&gt;Hôtel Marais Paris (0.34116563)&lt;br /&gt;Hôtel Edouard VII Paris (0.16353565)&lt;br /&gt;Hôtel Rivoli Paris (0.11563717)&lt;br /&gt;Hôtel Trinité Paris (0.11563717)&lt;br /&gt;Clarion Cloitre Saint Louis Hotel Avignon (0.11563717)&lt;br /&gt;performSearch done&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4903191105785361362-242794734406997953?l=sanjib-swain.blogspot.com' alt='' /&gt;&lt;/div&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/BVIOjAyF9SuzqMssy2pnnptDyfQ/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/BVIOjAyF9SuzqMssy2pnnptDyfQ/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/BVIOjAyF9SuzqMssy2pnnptDyfQ/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/BVIOjAyF9SuzqMssy2pnnptDyfQ/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/blogspot/PEHIt/~4/ZQ93pYbqQ0M" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://sanjib-swain.blogspot.com/feeds/242794734406997953/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://www.blogger.com/comment.g?blogID=4903191105785361362&amp;postID=242794734406997953" title="1 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/4903191105785361362/posts/default/242794734406997953?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/4903191105785361362/posts/default/242794734406997953?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/blogspot/PEHIt/~3/ZQ93pYbqQ0M/lucene-tutorial-introduction-to-full.html" title="Lucene: A Tutorial Introduction to Full-Text Indexing in Java" /><author><name>Sanjib Kumar Swain</name><uri>http://www.blogger.com/profile/11353921866017700402</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="32" height="24" src="http://3.bp.blogspot.com/_nnkYFjJnYR0/SjDB5r7-A4I/AAAAAAAAABg/5LvGBQSMBFM/S220/100_1083.JPG" /></author><thr:total>1</thr:total><feedburner:origLink>http://sanjib-swain.blogspot.com/2010/01/lucene-tutorial-introduction-to-full.html</feedburner:origLink></entry><entry gd:etag="W/&quot;CkUER3w6eip7ImA9WxNUGU8.&quot;"><id>tag:blogger.com,1999:blog-4903191105785361362.post-5904621607181585774</id><published>2009-11-10T20:16:00.000-08:00</published><updated>2009-11-10T22:16:46.212-08:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2009-11-10T22:16:46.212-08:00</app:edited><title>Finite State Machine for Decimals</title><content type="html">A Finite State Machine (FSM) is a model of behavior using states and state transitions. A transition is a state change triggered by an input event, i.e. transitions map some state-event pairs to other states. As indicated in the name, the set of states should be finite. Also, it is assumed that there is a finite set of distinct input events or their categories (types, classes). Subsequently, the set of transitions is finite as well.
&lt;br /&gt;
&lt;br /&gt;FSMs are one of the most widely used models in computer programming in general. In particular, FSMs are ubiquitous in programming embedded systems and for describing digital circuits. Modeling by means of FSMs has been so successful that they become adopted as a part of the Unified Modeling Language standard by Object Management Group.
&lt;br /&gt;	  	What
&lt;br /&gt;are
&lt;br /&gt;they?
&lt;br /&gt;
&lt;br /&gt;The origin of FSMs is finite atomata. A Finite Atomaton is a more formal notion than a FSM. It is defined as a quintuple ( A, S, s, T, F ), where:
&lt;br /&gt;
&lt;br /&gt;  * A is a finite non empty set of symbols (input alphabet)
&lt;br /&gt;  * S is a finite non empty set of states
&lt;br /&gt;  * s is an initial state, an element of S
&lt;br /&gt;  * T is the state transition function: T: S x A -&gt; S
&lt;br /&gt;  * F is the set of final states, which is a subset of S
&lt;br /&gt;
&lt;br /&gt;Finite automata are primarily used in parsing for recorgizing languages. Input strings belonging to a given language should turn an automaton to final states and all other input strings should turn this automaton to states that are not final.
&lt;br /&gt;
&lt;br /&gt;Finite automata that additionally generate output are called transducers. In order to define a transducer, an output alphabet and output function should be specified in addition to the five components outlined earlier. The output function can be a function of a state or a function of both state and input symbol. If the output function depends on a state and input symbol, then it is called a Mealy automaton. If the output function depends only on a state, then it called is a Moore automaton.
&lt;br /&gt;
&lt;br /&gt;One of the most important facts about finite automata is that instances of any regular expression can be recognized by a finite automaton. It is well-known how to build the recognizing automaton for a given regular expression. Inversely, it is known how to construct a regular expression defining a language recognized by a given finite automaton.
&lt;br /&gt;
&lt;br /&gt;Automata theory studies properties of automata. For instance, it investigates how to optimize automata. In addition to the finite atomata defined above and which are also called deterministic finite automata, there are non-deterministic finite automata. Automata theory also studies so-called pushdown automata. All these topics are beyond the scope of this tutorial.
&lt;br /&gt;	  	Finite
&lt;br /&gt;automata
&lt;br /&gt;
&lt;br /&gt;The notion of finite automata is mathematically rigorous. The notion of FSMs was introduced as a less rigorous and more suitable for computer science. A FSM is defined by the following:
&lt;br /&gt;
&lt;br /&gt;  * a finite non empty set of states
&lt;br /&gt;  * an initial state
&lt;br /&gt;  * a finite non empty set of distinct input events or their categories
&lt;br /&gt;  * state transitions
&lt;br /&gt;  * actions
&lt;br /&gt;
&lt;br /&gt;As opposed to input symbols for finite automata, any sequence of event can be a FSM input. In other words, any object can be an input entity. The only restriction on input is that all possible inputs should be classified as belonging to one of a finite number of distinct input categories (types, classes). In many simpler cases, only a finite number of distinct input objects are allowed. It is assumed that input events are then processed synchronously, that is, the next event is processed only after the current event is fully consumed and a transition is executed if necessary. This may require queing events before the time comes to process them.
&lt;br /&gt;
&lt;br /&gt;One other important difference between finite automata and FSMs is that actions may be related to FSMs. The role of actions is to generate output. FSMs may also communicate with other processes by means of actions. Presumably, actions do not generate input events. In other words, FSMs consume external events only. Also, actions are stateless, i.e. they cannot carry any information from one invocation to another. Actions may be associated with transitions, and if so, such FSM is called a Mealy machine. The FSMs in which actions are associated with states are called Moore machines. Since actions can be represented by virtually any program (code) and action input can be any object, the functionally of FSMs may be quite rich, going far beyond the limits of finite automata.
&lt;br /&gt;	  	Definition
&lt;br /&gt;
&lt;br /&gt;FSMs are most commonly represented by state diagrams, which are also called state transition diagrams. The state diagram is basically a directed graph where each vertex represents a state and each edge represents a transition between two states.
&lt;br /&gt;
&lt;br /&gt;Another common representation of FSMs is state transition tables. In these tables, every column corresponds to a state, every row corresponds to an event category. Values in the table cells give the states resulting from the respective transitions. Table cells also can be used for specifying actions related to transitions.
&lt;br /&gt;		
&lt;br /&gt;	opened 	closed
&lt;br /&gt;pass 	closed 	
&lt;br /&gt;coin 	  	opened
&lt;br /&gt;	  	Diagrams
&lt;br /&gt;etc.
&lt;br /&gt;
&lt;br /&gt;FSM specifications are pretty simple and 'flat'. Harel introduced hierarchical FSMs (statecharts) in which any state can be another FSM. The aim of this extension is to reduce the size of FSM specifications. In practice, the number of FSM transitions grows rapidly when the number of states grows. This happens because it is necessary to copy existing transitions for newly introduced states. The hierarchical FSMs solve this problem by bringing the possibility to encapsulate newly introduced states within a FSM that corresponds to one state of the next upper level. And the next-level transitions become applicable to the entire FSM of this lower level. Yet another extension of FSMs is introduced by allowing sequences of events to define transitions
&lt;br /&gt;
&lt;br /&gt;&lt;p&gt;This is a &lt;b&gt;finite state machine&lt;/b&gt; that recognizes decimal numbers such as &lt;i&gt;123&lt;/i&gt; and &lt;i&gt;0.123&lt;/i&gt; and &lt;i&gt;.789&lt;/i&gt; &lt;/p&gt;&lt;p&gt;It will not recognize strings such as &lt;i&gt;1.2.3&lt;/i&gt; or &lt;i&gt;1a&lt;/i&gt; &lt;/p&gt;
&lt;br /&gt;
&lt;br /&gt;&lt;img src="http://progzoo.net/w/images/e/ea/Fsm_decimal.png" alt="" /&gt;
&lt;br /&gt;&lt;p&gt;
&lt;br /&gt;public class Hello{
&lt;br /&gt;
&lt;br /&gt;final static int A = 1;
&lt;br /&gt;final static int B = 2;
&lt;br /&gt;
&lt;br /&gt;public static boolean fsm(String s){
&lt;br /&gt;  int state = A;
&lt;br /&gt;  for (int i=0;i&lt;s.length();i++){ int="" char="" switch="" c="s.charAt(i);" case="" if="" newstate="0;" return="" state="newState;" public="" static="" void="" string="" 123="" 789="" 3="" 1a=""&gt;&lt;/s.length();i++){&gt;&lt;/p&gt;
&lt;br /&gt;&lt;h2 style="font-weight: normal;"&gt;&lt;span class="mw-headline"&gt;Finite State Machine for String Literals&lt;/span&gt;&lt;/h2&gt;
&lt;br /&gt;&lt;p&gt;A String Literal is a double quote " followed by any sequence of characters (other than a double quote) followed by a double quote. &lt;/p&gt;&lt;p&gt;Acceptable string literals: &lt;i&gt;"one two" and &lt;/i&gt;"" &lt;/p&gt;&lt;p&gt;Unacceptable strings &lt;i&gt;one&lt;/i&gt; and &lt;i&gt;"one&lt;/i&gt;
&lt;br /&gt;&lt;/p&gt;
&lt;br /&gt;&lt;img src="http://progzoo.net/w/images/8/8c/Fsm_string_literal.png" alt="" /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;public class Hello{
&lt;br /&gt;
&lt;br /&gt;  final static int A = 1;
&lt;br /&gt;  final static int B = 2;
&lt;br /&gt;  final static int C = 3;
&lt;br /&gt;
&lt;br /&gt;  public static boolean fsm(String s){
&lt;br /&gt;    int state = A;
&lt;br /&gt;    for (int i=0;i&lt;s.length();i++){
&lt;br /&gt;      int newState = 0;
&lt;br /&gt;      char c = s.charAt(i);
&lt;br /&gt;      switch (state){
&lt;br /&gt;        case A: if (c=='"') newState = B;
&lt;br /&gt;                break;
&lt;br /&gt;        case B: if (c!='"') newState = B;
&lt;br /&gt;                if (c == '"') newState = C;
&lt;br /&gt;                break;
&lt;br /&gt;      } 
&lt;br /&gt;      state = newState;
&lt;br /&gt;    }
&lt;br /&gt;    return state==C;
&lt;br /&gt;  }
&lt;br /&gt;
&lt;br /&gt;  public static void main(String argv[])
&lt;br /&gt;  {
&lt;br /&gt;    System.out.println(fsm("\"one two\""));
&lt;br /&gt;    System.out.println(fsm("\"\""));
&lt;br /&gt;    System.out.println(fsm("one"));
&lt;br /&gt;    System.out.println(fsm("\"one"));
&lt;br /&gt;  }
&lt;br /&gt;}
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4903191105785361362-5904621607181585774?l=sanjib-swain.blogspot.com' alt='' /&gt;&lt;/div&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/vDLxNbtIzjwmJ0bdc_IgiAkz5ew/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/vDLxNbtIzjwmJ0bdc_IgiAkz5ew/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/vDLxNbtIzjwmJ0bdc_IgiAkz5ew/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/vDLxNbtIzjwmJ0bdc_IgiAkz5ew/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/blogspot/PEHIt/~4/bKCboCYfZsk" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://sanjib-swain.blogspot.com/feeds/5904621607181585774/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://www.blogger.com/comment.g?blogID=4903191105785361362&amp;postID=5904621607181585774" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/4903191105785361362/posts/default/5904621607181585774?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/4903191105785361362/posts/default/5904621607181585774?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/blogspot/PEHIt/~3/bKCboCYfZsk/finite-state-machine-for-decimals.html" title="Finite State Machine for Decimals" /><author><name>Sanjib Kumar Swain</name><uri>http://www.blogger.com/profile/11353921866017700402</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="32" height="24" src="http://3.bp.blogspot.com/_nnkYFjJnYR0/SjDB5r7-A4I/AAAAAAAAABg/5LvGBQSMBFM/S220/100_1083.JPG" /></author><thr:total>0</thr:total><feedburner:origLink>http://sanjib-swain.blogspot.com/2009/11/finite-state-machine-for-decimals.html</feedburner:origLink></entry><entry gd:etag="W/&quot;DU8GRn0_fSp7ImA9WxNRFkk.&quot;"><id>tag:blogger.com,1999:blog-4903191105785361362.post-2290725916243904735</id><published>2009-09-10T22:38:00.000-07:00</published><updated>2009-09-10T22:43:47.345-07:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2009-09-10T22:43:47.345-07:00</app:edited><title>- : Mediator pattern : -</title><content type="html">&lt;!-- -------------------------------------------------------------------- --&gt;  &lt;a style="font-family: times new roman;" name="Introduction"&gt;&lt;/a&gt; &lt;h1 style="font-family: times new roman;"&gt;&lt;span style="font-size:100%;"&gt;Introduction&lt;/span&gt;&lt;/h1&gt; &lt;p style="font-family: times new roman;"&gt;     The Mediator is a behavioral design pattern that provides a central     hub to guide the interactions between many objects.      According to Gamma et al, the intent of the Mediator pattern is to, &lt;/p&gt;&lt;p style="font-family: times new roman;"&gt; &lt;quote&gt;     "Define an object that encapsulates how a set of objects interact.       Mediator promotes loose coupling by keeping objects from referring to      each other explicitly, and it lets you vary their interaction      independently." &lt;cite&gt;(&lt;a href="http://pages.cpsc.ucalgary.ca/%7Eheatond/mediator/#References.gamma1995"&gt;Gamma et al., 1995&lt;/a&gt;)&lt;/cite&gt; &lt;/quote&gt; &lt;/p&gt;&lt;p style="font-family: times new roman;"&gt;     You will find on this page, a detailed, and hopefully useful,     investigation into the various aspects of this relatively simple, yet     powerful design pattern. &lt;/p&gt; &lt;p style="font-family: times new roman;"&gt;     &lt;a href="http://pages.cpsc.ucalgary.ca/%7Eheatond/mediator/#Top"&gt;&lt;br /&gt;&lt;/a&gt; &lt;/p&gt;  &lt;!-- -------------------------------------------------------------------- --&gt;  &lt;a style="font-family: times new roman;" name="AirTrafficControllerExample"&gt;&lt;/a&gt; &lt;h1 style="font-family: times new roman;"&gt;&lt;span style="font-size:85%;"&gt;Air Traffic Controller Example&lt;/span&gt;&lt;/h1&gt; &lt;p style="font-family: times new roman;"&gt;     Before we explore the Mediator pattern in any depth, first consider the     example of an air traffic controller, and the various aircraft it helps      to guide &lt;cite&gt;(&lt;a href="http://pages.cpsc.ucalgary.ca/%7Eheatond/mediator/#References.bains2002"&gt;Bains K., Lau E., 2002&lt;/a&gt;)&lt;/cite&gt;. &lt;/p&gt; &lt;p style="font-family: times new roman;"&gt;     Imagine what would happen if there were no air traffic controllers. Each     and every aircraft would have to know about &lt;em&gt;every&lt;/em&gt; other aircraft      in order to avoid collisions with them. This would certainly be a cause      for disaster, as it would be far too difficult for each plane to keep      track of all other aircraft in the vicinity. &lt;/p&gt; &lt;p style="font-family: times new roman;"&gt;     So, to remedy this, we have the air traffic controller. Instead of      having all aircraft communicating directly with one another, they simply     send the controller their flight data and the controller then decides      what other aircraft need to be informed. This is clearly far more      efficient, and in this case, much safer, than the alternative. This      is a perfect example of the Mediator pattern in the real-world. &lt;/p&gt; &lt;p style="font-family: times new roman;"&gt;     &lt;a href="http://pages.cpsc.ucalgary.ca/%7Eheatond/mediator/#Top"&gt;&lt;br /&gt;&lt;/a&gt; &lt;/p&gt;   &lt;!-- -------------------------------------------------------------------- --&gt;  &lt;a style="font-family: times new roman;" name="Structure"&gt;&lt;/a&gt; &lt;h1 style="font-family: times new roman;"&gt;&lt;span style="font-size:85%;"&gt;Structure&lt;/span&gt;&lt;/h1&gt; &lt;p style="font-family: times new roman;"&gt;     Expressed in &lt;abbr title="Unified Modeling Language"&gt;UML&lt;/abbr&gt;, a      Mediator pattern may be structured with a handful of simple classes     and interfaces &lt;cite&gt;(&lt;a href="http://pages.cpsc.ucalgary.ca/%7Eheatond/mediator/#fig1"&gt;Figure 1.&lt;/a&gt;)&lt;/cite&gt;.  &lt;/p&gt; &lt;p style="font-family: times new roman;"&gt;     &lt;a name="fig1"&gt;&lt;/a&gt;     &lt;img name="fig1" src="http://pages.cpsc.ucalgary.ca/%7Eheatond/mediator/structure.gif" /&gt;     &lt;/p&gt;&lt;div style="font-family: times new roman;"&gt;Figure 1: Mediator Structure&lt;/div&gt;  &lt;p style="font-family: times new roman;"&gt;     So an example implementation, in the context of the air traffic controller     described earlier, could also be structured in UML      &lt;cite&gt;(&lt;a href="http://pages.cpsc.ucalgary.ca/%7Eheatond/mediator/#fig2"&gt;Figure 2.&lt;/a&gt;)&lt;/cite&gt;. &lt;/p&gt; &lt;p style="font-family: times new roman;"&gt;     &lt;a name="fig2"&gt;&lt;/a&gt;     &lt;img name="fig2" src="http://pages.cpsc.ucalgary.ca/%7Eheatond/mediator/structure-atc.gif" /&gt;     &lt;/p&gt;&lt;div style="font-family: times new roman;"&gt;Figure 2: Air Traffic Controller Example Structure&lt;/div&gt;  &lt;p style="font-family: times new roman;"&gt;     The sequence of events that may occur between the objects involved     in our air traffic controller example, can be expressed using a     sequence diagram &lt;cite&gt;(&lt;a href="http://pages.cpsc.ucalgary.ca/%7Eheatond/mediator/#fig3"&gt;Figure 3.&lt;/a&gt;)&lt;/cite&gt;. &lt;/p&gt; &lt;p style="font-family: times new roman;"&gt;     &lt;a name="fig3"&gt;&lt;/a&gt;     &lt;img name="fig3" src="http://pages.cpsc.ucalgary.ca/%7Eheatond/mediator/structure-atc-sequence.gif" /&gt;     &lt;/p&gt;&lt;div style="font-family: times new roman;"&gt;Figure 3: Air Traffic Controller Example Sequence Diagram&lt;/div&gt;  &lt;p style="font-family: times new roman;"&gt;     More or less, this is how the Mediator design pattern works. Colleagues     inform the Mediator of particular events, and the Mediator then decides     what other colleagues should be informed. &lt;/p&gt; &lt;p style="font-family: times new roman;"&gt;     &lt;a href="http://pages.cpsc.ucalgary.ca/%7Eheatond/mediator/#Top"&gt;&lt;br /&gt;&lt;/a&gt; &lt;/p&gt;  &lt;!-- -------------------------------------------------------------------- --&gt;  &lt;a style="font-family: times new roman;" name="Participants"&gt;&lt;/a&gt; &lt;h1 style="font-family: times new roman;"&gt;&lt;span style="font-size:85%;"&gt;Participants&lt;/span&gt;&lt;/h1&gt; &lt;p style="font-family: times new roman;"&gt;     There are three participants in the Mediator pattern      &lt;cite&gt;(&lt;a href="http://pages.cpsc.ucalgary.ca/%7Eheatond/mediator/#fig1"&gt;Figure 1.&lt;/a&gt;)&lt;/cite&gt;: &lt;/p&gt;  &lt;ul style="font-family: times new roman;"&gt;&lt;li&gt;         &lt;b&gt;Mediator:&lt;/b&gt;         defines an interface for communicating with Colleague objects          &lt;cite&gt;(&lt;a href="http://pages.cpsc.ucalgary.ca/%7Eheatond/mediator/#References.gamma1995"&gt;Gamma et al., 1995&lt;/a&gt;)&lt;/cite&gt;.      &lt;/li&gt;&lt;li&gt;         &lt;b&gt;ConcreteMediator:&lt;/b&gt;         is the object that coordinates the Colleague objects and is in charge         of the messages they wish to send to each other. A ConcreteMediator         knows and maintains its Colleagues &lt;cite&gt;(&lt;a href="http://pages.cpsc.ucalgary.ca/%7Eheatond/mediator/#References.gamma1995"&gt;Gamma et al., 1995&lt;/a&gt;)&lt;/cite&gt;.     &lt;/li&gt;&lt;li&gt;         &lt;b&gt;Colleague classes:&lt;/b&gt;         each Colleague class knows its Mediator object, and          communicates with it whenever it would have otherwise communicated          with another Colleague &lt;cite&gt;(&lt;a href="http://pages.cpsc.ucalgary.ca/%7Eheatond/mediator/#References.gamma1995"&gt;Gamma et al., 1995&lt;/a&gt;)&lt;/cite&gt;.     &lt;/li&gt;&lt;/ul&gt; &lt;p style="font-family: times new roman;"&gt;     &lt;a href="http://pages.cpsc.ucalgary.ca/%7Eheatond/mediator/#Top"&gt;&lt;br /&gt;&lt;/a&gt; &lt;/p&gt;   &lt;!-- -------------------------------------------------------------------- --&gt;  &lt;a style="font-family: times new roman;" name="Applicability"&gt;&lt;/a&gt; &lt;h1 style="font-family: times new roman;"&gt;&lt;span style="font-size:85%;"&gt;Applicability&lt;/span&gt;&lt;/h1&gt; &lt;p style="font-family: times new roman;"&gt;     According to Gamma et al, the Mediator pattern should be used when      &lt;cite&gt;(&lt;a href="http://pages.cpsc.ucalgary.ca/%7Eheatond/mediator/#References.gamma1995"&gt;Gamma et al., 1995&lt;/a&gt;)&lt;/cite&gt;: &lt;/p&gt; &lt;ul style="font-family: times new roman;"&gt;&lt;li&gt;         a set of objects communicate in well-defined but complex ways. The          resulting interdependencies are unstructured and difficult to          understand.     &lt;/li&gt;&lt;li&gt;         reusing an object is difficult because it refers to and communicates          with many other objects.     &lt;/li&gt;&lt;li&gt;         a behaviour that's distributed between several classes should be          customizable without a lot of subclassing.     &lt;/li&gt;&lt;/ul&gt; &lt;p style="font-family: times new roman;"&gt;     &lt;a href="http://pages.cpsc.ucalgary.ca/%7Eheatond/mediator/#Top"&gt;&lt;br /&gt;&lt;/a&gt; &lt;/p&gt;  &lt;!-- -------------------------------------------------------------------- --&gt;  &lt;a style="font-family: times new roman;" name="Consequences"&gt;&lt;/a&gt; &lt;h1 style="font-family: times new roman;"&gt;&lt;span style="font-size:85%;"&gt;Consequences&lt;/span&gt;&lt;/h1&gt; &lt;p style="font-family: times new roman;"&gt;     As with most design patterns, there are both advantages and disadvantages     to using the Mediator. The following section will briefly outline a few of     these issues. &lt;/p&gt;  &lt;a style="font-family: times new roman;" name="Consequences.Advantages"&gt;&lt;/a&gt; &lt;h2 style="font-family: times new roman;"&gt;&lt;span style="font-size:85%;"&gt;Advantages&lt;/span&gt;&lt;/h2&gt; &lt;ul style="font-family: times new roman;"&gt;&lt;li&gt;         &lt;b&gt;Comprehension:&lt;/b&gt;         Since the Mediator hides all coordination activities that it          implements, the user is better able to understand the system and         the interactions that that the Colleagues make.     &lt;/li&gt;&lt;li&gt;         &lt;b&gt;Decoupled Colleagues:&lt;/b&gt;         Colleagues can be added/removed/modified easier as they depend         less on each other. This also goes between the Colleague and its         Mediator- they can be used independently.      &lt;/li&gt;&lt;li&gt;         &lt;b&gt;Ease of Protocols:&lt;/b&gt;         The Mediator makes sure that there are only a few centralized          access points. The one-to-many relationship of the Mediator is          much preferred to over the many-to-many relationship among          Colleagues. &lt;cite&gt;(&lt;a href="http://pages.cpsc.ucalgary.ca/%7Eheatond/mediator/#References.black2004"&gt;Black, 2004&lt;/a&gt;)&lt;/cite&gt;     &lt;/li&gt;&lt;li&gt;         &lt;b&gt;Limits Subclassing:&lt;/b&gt;         The Mediator localizes behavior. Only the Mediator needs          subclassing when changing behavior; the Colleagues can remain the         same.     &lt;/li&gt;&lt;/ul&gt;  &lt;a style="font-family: times new roman;" name="Consequences.Disadvantages"&gt;&lt;/a&gt; &lt;h2 style="font-family: times new roman;"&gt;&lt;span style="font-size:85%;"&gt;Disadvantages&lt;/span&gt;&lt;/h2&gt; &lt;ul style="font-family: times new roman;"&gt;&lt;li&gt;         &lt;b&gt;Complexity:&lt;/b&gt;         Because the Mediator may handle a potentially large number of          Colleagues, the contents of the Mediator may be very complex.          Thus, it could be difficult to modify its and understand its          contents.     &lt;/li&gt;&lt;/ul&gt; &lt;p style="font-family: times new roman;"&gt;     &lt;a href="http://pages.cpsc.ucalgary.ca/%7Eheatond/mediator/#Top"&gt;&lt;br /&gt;&lt;/a&gt; &lt;/p&gt;  &lt;!-- -------------------------------------------------------------------- --&gt;  &lt;a style="font-family: times new roman;" name="Examples"&gt;&lt;/a&gt; &lt;h1 style="font-family: times new roman;"&gt;&lt;span style="font-size:85%;"&gt;Examples&lt;/span&gt;&lt;/h1&gt;  &lt;span style="font-size:85%;"&gt;&lt;a style="font-family: times new roman;" name="Examples.Parliament"&gt;&lt;/a&gt;&lt;/span&gt; &lt;h2 style="font-family: times new roman;"&gt;&lt;span style="font-size:85%;"&gt;Parliament&lt;/span&gt;&lt;/h2&gt; &lt;p style="font-family: times new roman;"&gt;     The House of Commons in the Parliaments of Canada, England and many more      countries are also excellent real-life examples of the mediator pattern.       According to protocols established hundreds of years ago, Members of      Parliament (Colleagues) may never address each other directly.  All      comments are instead directed to the Speaker of the House (the Mediator).       Further, it is a breach of protocol to refer to a member by name.       All members are referred to as "The Honourable Member      from [district]" or "My good friend from [district]." This is analogous     to addressing Colleague classes by their "interface" and not by their      actual "implementation".  &lt;/p&gt;  &lt;a style="font-family: times new roman;" name="Examples.Chatroom"&gt;&lt;/a&gt; &lt;h2 style="font-family: times new roman;"&gt;&lt;span style="font-size:85%;"&gt;Chatroom&lt;/span&gt;&lt;/h2&gt; &lt;p style="font-family: times new roman;"&gt;     To illustrate a possible use of the Mediator pattern, we have chosen to     present an &lt;a href="http://pages.cpsc.ucalgary.ca/%7Eheatond/mediator/mediator-example.zip"&gt;example chatroom application&lt;/a&gt; &lt;cite&gt;(&lt;a href="http://pages.cpsc.ucalgary.ca/%7Eheatond/mediator/#References.dofactory2004"&gt;Data &amp;amp; Object Factory, 2004&lt;/a&gt;)&lt;/cite&gt;     in Java. In this particular example, the &lt;code&gt;Forum&lt;/code&gt; acts as the abstract      Mediator, and the &lt;code&gt;PoliticalForum&lt;/code&gt; is the concrete      implementation of it. We then have a couple of &lt;code&gt;Colleague&lt;/code&gt;     implementations: &lt;code&gt;MemberOfParliament&lt;/code&gt;, and      &lt;code&gt;PrimeMinister&lt;/code&gt; (&lt;code&gt;PrimeMinister&lt;/code&gt; is actually a     subclass of &lt;code&gt;MemberOfParliament&lt;/code&gt;, so it too is a     &lt;code&gt;Colleague&lt;/code&gt;). By having each &lt;code&gt;Colleague&lt;/code&gt; aware of     the &lt;code&gt;Forum&lt;/code&gt; they're participating in, they can send messages     without actually referencing one another. &lt;/p&gt; &lt;p style="font-family: times new roman;"&gt;     &lt;a href="http://pages.cpsc.ucalgary.ca/%7Eheatond/mediator/#Top"&gt;&lt;br /&gt;&lt;/a&gt; &lt;/p&gt;  &lt;!-- -------------------------------------------------------------------- --&gt;  &lt;a style="font-family: times new roman;" name="RelatedPatterns"&gt;&lt;/a&gt;&lt;!-- -------------------------------------------------------------------- --&gt;  &lt;a style="font-family: times new roman;" name="KnownUses"&gt;&lt;/a&gt; &lt;h1 style="font-family: times new roman;"&gt;&lt;span style="font-size:85%;"&gt;Known Uses&lt;/span&gt;&lt;/h1&gt; &lt;p style="font-family: times new roman;"&gt;     In the following sections, we'll discuss some real-world uses of the     Mediator pattern. You'll find the Mediator in many situations where there     are many components that must interact with one another in complex     ways. &lt;/p&gt;  &lt;a style="font-family: times new roman;" name="KnownUses.UserInterfaces"&gt;&lt;/a&gt; &lt;h2 style="font-family: times new roman;"&gt;&lt;span style="font-size:85%;"&gt;User Interfaces&lt;/span&gt;&lt;/h2&gt; &lt;p style="font-family: times new roman;"&gt;     Perhaps the most common use for the Mediator pattern we've come across,     is that in graphical user interfaces &lt;cite&gt;(&lt;a href="http://pages.cpsc.ucalgary.ca/%7Eheatond/mediator/#References.gamma1995"&gt;Gamma et al., 1995&lt;/a&gt;)&lt;/cite&gt;,      where a change in one control, may change the state of other controls.      Instead of having the instantiating control know about all other possible     controls that may need to know about changes, we &lt;/p&gt;  &lt;a style="font-family: times new roman;" name="KnownUses.JMS"&gt;&lt;/a&gt; &lt;h2 style="font-family: times new roman;"&gt;&lt;span style="font-size:85%;"&gt;Java Message Service&lt;/span&gt;&lt;/h2&gt; &lt;p style="font-family: times new roman;"&gt;     Another use for the Mediator pattern is in messaging services between     remote applications. For instance, the J2EE Java Message Service      &lt;cite&gt;(&lt;a href="http://pages.cpsc.ucalgary.ca/%7Eheatond/mediator/#References.armstrong2004"&gt;Armstrong et al., 2004&lt;/a&gt;)&lt;/cite&gt;     provides applications with the ability to subscribe, and publish data     to other applications in an asynchronous manner. Clearly, this is      a variation of the Mediator, as it incorporates the Observer pattern     for providing the publish and subscribe functionality, but this is     a very common variation, and is worth mentioning. &lt;/p&gt;  &lt;p style="font-family: times new roman;"&gt;     &lt;a href="http://pages.cpsc.ucalgary.ca/%7Eheatond/mediator/#Top"&gt;&lt;br /&gt;&lt;/a&gt; &lt;/p&gt;  &lt;!-- -------------------------------------------------------------------- --&gt;  &lt;a style="font-family: times new roman;" name="PreviousExperience"&gt;&lt;/a&gt; &lt;h1 style="font-family: times new roman;"&gt;&lt;span style="font-size:85%;"&gt;Previous Experience&lt;/span&gt;&lt;/h1&gt;  &lt;p style="font-family: times new roman;"&gt;     Our most common encounter with the Mediator pattern thus far has surely      been in writing user interfaces; a task that dictates the use of many      objects that often need to communicate with one another. &lt;/p&gt; &lt;p style="font-family: times new roman;"&gt;     As mentioned &lt;a href="http://pages.cpsc.ucalgary.ca/%7Eheatond/mediator/#KnownUses.UserInterfaces"&gt;earlier&lt;/a&gt;, the      Mediator is well suited for coordinating changes between related      controls in graphical user interfaces, and we would tend to agree.     Instead of placing the code that deals with 'notifying' other controls     of changes within the controls themselves, we've often found ourselves     creating 'notification' methods within the container class, such as      &lt;code&gt;notifyFontChange()&lt;/code&gt;, that actually execute the various     methods required to update the appropriate controls. This has helped     us to reduce duplication of code, made changes to the UI far less      painful, and made the code itself far easier to understand.  &lt;/p&gt;  &lt;!-- -------------------------------------------------------------------- --&gt;  &lt;a style="font-family: times new roman;" name="Conclusion"&gt;&lt;/a&gt; &lt;h1 style="font-family: times new roman; font-weight: bold;"&gt;&lt;span style="font-size:100%;"&gt;Conclusion&lt;/span&gt;&lt;/h1&gt;  &lt;p style="font-family: times new roman;"&gt;     It would be difficult for us to deny the sheer simplicity and usefulness      of the Mediator pattern. By providing the loose coupling between Colleague     objects and centralizing the interaction logic in the Mediator, changes     are more easily facilitated, and code clarity is heightened. &lt;/p&gt; &lt;p style="font-family: times new roman;"&gt;     While we haven't encountered this yet ourselves, we can easily     foresee Mediator implementations becoming very large and complex when     it must deal with a very large or unknown set of Colleagues. In such     cases, we feel that using the Observer pattern would actually help a     great deal, by placing the interaction logic &lt;em&gt;back&lt;/em&gt; into the     Colleagues. Colleagues in this case would then publish and subscribe     to events that affect them, and would deal these events themselves.     The Mediator would then only provide the means by which     Colleagues may inform one another of such events. Such a Mediator     is actually provided by the &lt;a href="http://pages.cpsc.ucalgary.ca/%7Eheatond/mediator/#KnownUses.JMS"&gt;Java Message      Service&lt;/a&gt;, as we mentioned earlier. &lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4903191105785361362-2290725916243904735?l=sanjib-swain.blogspot.com' alt='' /&gt;&lt;/div&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/ZXmrboNUTV5l059vv0q-LhU3jB0/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/ZXmrboNUTV5l059vv0q-LhU3jB0/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/ZXmrboNUTV5l059vv0q-LhU3jB0/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/ZXmrboNUTV5l059vv0q-LhU3jB0/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/blogspot/PEHIt/~4/JQNsRYGScVo" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://sanjib-swain.blogspot.com/feeds/2290725916243904735/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://www.blogger.com/comment.g?blogID=4903191105785361362&amp;postID=2290725916243904735" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/4903191105785361362/posts/default/2290725916243904735?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/4903191105785361362/posts/default/2290725916243904735?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/blogspot/PEHIt/~3/JQNsRYGScVo/mediator-pattern.html" title="- : Mediator pattern : -" /><author><name>Sanjib Kumar Swain</name><uri>http://www.blogger.com/profile/11353921866017700402</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="32" height="24" src="http://3.bp.blogspot.com/_nnkYFjJnYR0/SjDB5r7-A4I/AAAAAAAAABg/5LvGBQSMBFM/S220/100_1083.JPG" /></author><thr:total>0</thr:total><feedburner:origLink>http://sanjib-swain.blogspot.com/2009/09/mediator-pattern.html</feedburner:origLink></entry><entry gd:etag="W/&quot;DkMASHgzeCp7ImA9WxJaGUs.&quot;"><id>tag:blogger.com,1999:blog-4903191105785361362.post-5944429313570099835</id><published>2009-08-10T21:18:00.000-07:00</published><updated>2009-08-10T21:20:49.680-07:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2009-08-10T21:20:49.680-07:00</app:edited><title>Java performance guidelines-Part I</title><content type="html">* Use the StringBuffer function instead of string concatenations when doing excessive string manipulations to avoid unnecessarily creating objects that eventually must undergo garbage collection.&lt;br /&gt;&lt;br /&gt;   * Avoid excessive writing to the Java console to reduce the cost of string manipulations, text formatting, and output.&lt;br /&gt;&lt;br /&gt;   * Avoid the costs of object creation and manipulation by using primitive types for variables when necessary.&lt;br /&gt;&lt;br /&gt;   * Cache frequently-used objects to reduce the amount of garbage collection needed, and avoid the need to re-create the objects.&lt;br /&gt;&lt;br /&gt;   * Group native operations to reduce the number of Java Native Interface (JNI) calls when possible.&lt;br /&gt;&lt;br /&gt;   * Use synchronized methods only when necessary to limit the multitasking in the JVM and operating system.&lt;br /&gt;&lt;br /&gt;   * Avoid invoking the garbage collector unless necessary. If you must invoke it, do so only during idle time or some noncritical phase.&lt;br /&gt;&lt;br /&gt;   * Use the int type instead of the long type whenever possible, because 32-bit operations are executed faster than 64-bit operations.&lt;br /&gt;&lt;br /&gt;   * Declare methods as final whenever possible. Final methods are handled better by the JVM.&lt;br /&gt;&lt;br /&gt;   * Use the static final key word when creating constants in order to reduce the number of times the variables need to be initialized.&lt;br /&gt;&lt;br /&gt;   * Avoid unnecessary "casts" and "instanceof" references, because casting in Java is done at run time.&lt;br /&gt;&lt;br /&gt;   * Avoid the use of vectors whenever possible when an array will suffice.&lt;br /&gt;&lt;br /&gt;   * Add and delete items from the end of the vector.&lt;br /&gt;&lt;br /&gt;   * Compile Java files with the -O option.&lt;br /&gt;&lt;br /&gt;   * Avoid allocating objects within loops.&lt;br /&gt;&lt;br /&gt;   * Use buffer I/O and tune the buffer size.&lt;br /&gt;&lt;br /&gt;   * Use connection pools and cached-prepared statements for database access.&lt;br /&gt;&lt;br /&gt;   * Use connection pools to the database and reuse connections rather than repeatedly opening and closing connections.&lt;br /&gt;&lt;br /&gt;   * Maximize and minimize thread creation and destruction cycles.&lt;br /&gt;&lt;br /&gt;   * Minimize the contention for shared resources.&lt;br /&gt;&lt;br /&gt;   * Minimize the creation of short-lived objects.&lt;br /&gt;&lt;br /&gt;   * Avoid remote method calls.&lt;br /&gt;&lt;br /&gt;   * Use callbacks to avoid blocking remote method calls.&lt;br /&gt;&lt;br /&gt;   * Avoid creating an object only used for accessing a method.&lt;br /&gt;&lt;br /&gt;   * Keep synchronized methods out of loops.&lt;br /&gt;&lt;br /&gt;   * Store string and char data as Unicode in the database.&lt;br /&gt;&lt;br /&gt;   * Reorder CLASSPATH so that the most frequently used libraries occur first.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4903191105785361362-5944429313570099835?l=sanjib-swain.blogspot.com' alt='' /&gt;&lt;/div&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/rL2KzwUmcCZJVkagMWWVbe9PoLg/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/rL2KzwUmcCZJVkagMWWVbe9PoLg/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/rL2KzwUmcCZJVkagMWWVbe9PoLg/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/rL2KzwUmcCZJVkagMWWVbe9PoLg/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/blogspot/PEHIt/~4/vKCGSq9q7m4" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://sanjib-swain.blogspot.com/feeds/5944429313570099835/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://www.blogger.com/comment.g?blogID=4903191105785361362&amp;postID=5944429313570099835" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/4903191105785361362/posts/default/5944429313570099835?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/4903191105785361362/posts/default/5944429313570099835?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/blogspot/PEHIt/~3/vKCGSq9q7m4/java-performance-guidelines-part-i.html" title="Java performance guidelines-Part I" /><author><name>Sanjib Kumar Swain</name><uri>http://www.blogger.com/profile/11353921866017700402</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="32" height="24" src="http://3.bp.blogspot.com/_nnkYFjJnYR0/SjDB5r7-A4I/AAAAAAAAABg/5LvGBQSMBFM/S220/100_1083.JPG" /></author><thr:total>0</thr:total><feedburner:origLink>http://sanjib-swain.blogspot.com/2009/08/java-performance-guidelines-part-i.html</feedburner:origLink></entry><entry gd:etag="W/&quot;A0QFSHw9eip7ImA9WxNUF0k.&quot;"><id>tag:blogger.com,1999:blog-4903191105785361362.post-3478794538007181185</id><published>2009-06-29T04:37:00.001-07:00</published><updated>2009-11-08T22:48:39.262-08:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2009-11-08T22:48:39.262-08:00</app:edited><title>A brief explanation of the ISO-8583 protocol</title><content type="html">The objective of this protocol is to transmit information for payment processing through a network, usually using TCP/IP sockets. An ISO8583 message can have up to 63 or 127 fields and is processed in a linear way, that is, the message can be processed as it is being read.&lt;br /&gt;Message format&lt;br /&gt;&lt;br /&gt;A simple ISO8583 is comprised of the following:&lt;br /&gt;&lt;br /&gt;   * Message type: Indicates if the message is a request or a response, and what type of transaction it is.&lt;br /&gt;   * Bitmap: The bitmap indicates the fields contained in the message. It is a binary string of 64 bits, in which every bit corresponds to a field, indicating which fields are included in the message.&lt;br /&gt;   * Fields: Fields are included after the bitmap. There are different field types and the message does not indicate the type of field; this has to be defined previously on a specification (there is a certain standard for some common fields but some implementations do not follow it, so it is very important to always review the specification for the specific implementation you will work on).&lt;br /&gt;&lt;br /&gt;The first field is a special field and contains a secondary bitmap. If the first bit of the primary bitmap is on, then the first field after the bitmap is another bitmap, also 64 bits long, indicating additional fields from 65 to 128.&lt;br /&gt;Field types&lt;br /&gt;&lt;br /&gt;From the second field to the last one, the message contains only "normal" fields, which can have the following datatypes:&lt;br /&gt;&lt;br /&gt;Alpha:&lt;br /&gt;   Can contain a fixed number of characters and digits. The length is previouly established in the spec for the particular implementation. If the contents are shorter than the field length, it must be filled with spaces to the right.&lt;br /&gt;Numeric&lt;br /&gt;   Can contain only digits with a fixed length. The length is previously established in the spec for the particular implementation. If the number is shorter than the field length, it must be zero-filled to the left.&lt;br /&gt;LLVAR&lt;br /&gt;   This is an alphanumeric field of variable length. It has a 2-digit field header at the beginning, indicating the length of the rest of the field, which can be 0 to 99.&lt;br /&gt;LLLVAR&lt;br /&gt;   Also an alphanumeric field of variable length, but the field header is 3 digits long, so the rest of the field can be 0 to 999 characters long.&lt;br /&gt;Date/Time&lt;br /&gt;   There are three different date formats: A 10-digit format MMDDHHmmss, a 4-digit format YYMM (useful for expiration dates on credit cards), another 4-digit format MMDD. The time is specified as 6 digits in format HHmmss.&lt;br /&gt;Amount&lt;br /&gt;   This is a 12-digit numeric field expressing a currency amount in cents. For example $15.00 is expressed as 000000001500.&lt;br /&gt;&lt;br /&gt;Message types&lt;br /&gt;&lt;br /&gt;The most common message types are:&lt;br /&gt;0200  Request for payment, credit card charge, etc.&lt;br /&gt;0210  Response to payment, credit card charge, etc.&lt;br /&gt;0400  Request for reversal of payment, credit card charge, etc.&lt;br /&gt;0410  Response to reversal of payment, credit card charge, etc.&lt;br /&gt;0600  Query&lt;br /&gt;0610  Response to query&lt;br /&gt;0800  Echo request&lt;br /&gt;0810  Echo response&lt;br /&gt;Encoding&lt;br /&gt;&lt;br /&gt;ISO8583 messages can be encoded as ASCII or binary; ASCII is more common. In this format, the message type is 4 bytes long, because the characters for it are sent as text, ie. "0200". In binary encoding, the message type is 2 bytes long, for example message type 0200 is encoded as byte 0x02 and byte 0x00.&lt;br /&gt;&lt;br /&gt;In ASCII encoding, the bitmap is sent using hex encoding, so it's 16 characters long; that is, every 4 bits are a hex digit. For example, if the message includes fields 1 and 3 but not 2 or 4, then the first 4 bits are 1010 which is 0xA. In binary encoding, the bitmap is sent as 8 bytes, without encoding them in any way.&lt;br /&gt;&lt;br /&gt;Numeric and alpha fields in ASCII have the same length in bytes as they do in characters or digits; numeric fields are sent as text, for example "000012".&lt;br /&gt;&lt;br /&gt;In binary encoding, numeric fields are encoded using BCD (Binary Coded Digits), which means taking 2 digits and encoding them as hex, that is, the number 12 is encoded as 0x12; this way, a byte can always contain 2 digits. Numbers with an odd number of digits (such as the length header for a LLLVAR field) will have a zero to the left, for example 128 is encoded as two bytes: 0x1 and 0x28.&lt;br /&gt;&lt;br /&gt;ASCII-encoded LLVAR and LLLVAR fields will have 2 or 3 character headers.&lt;br /&gt;&lt;br /&gt;Binary encoded LLVAR and LLLVAR fields will have 1 or 2 byte headers; LLVAR fields have their header as a 1-byte BCD number, for example if the header is 0x57 it means that the field is 57 bytes long. LLLVAR fields have 2-byte BCD headers but the first digit is always 0; for example if the header is 0x128 it means the field contents are 128 bytes long.&lt;br /&gt;&lt;br /&gt;Date and amount fields, being numeric, are encoded as any other numeric field. For example a full date field will be 10 characters long in ASCII encoding but only 5 bytes long in binary encoding.&lt;br /&gt;ISO header&lt;br /&gt;&lt;br /&gt;In some implementations, messages must include a header before the message type. This is implementation-specific and the headers usually vary only by message type.&lt;br /&gt;&lt;br /&gt;Additionally, it is very common to include a header with the length of the message when sending ISO8583 over a network. The header is usually 2 bytes long and is a binary unsigned integer with the length of the full message, thus making the reading on the other side easier, since the process consists of reading 2 bytes, interpreting them as a length, and then reading that many bytes. The byte order is usually most significant byte first, but it can vary in certain implementations.&lt;br /&gt;&lt;br /&gt;Sometimes there is also a message terminator, which can be included in the length or not, depending on implementation. Message terminators are usually just 1 byte long.&lt;br /&gt;Examples&lt;br /&gt;&lt;br /&gt;Here are some examples of ISO8583 messages, along with the XML definition to parse them with the j8583 framework. ASCII encoding is being used for these.&lt;br /&gt;&lt;j8583-config&gt;&lt;br /&gt;&lt;header type="0200"&gt;ISO015000050&lt;/header&gt;&lt;br /&gt;&lt;header type="0210"&gt;ISO015000055&lt;/header&gt;&lt;br /&gt;&lt;header type="0400"&gt;ISO015000050&lt;/header&gt;&lt;br /&gt;&lt;header type="0410"&gt;ISO015000055&lt;/header&gt;&lt;br /&gt;&lt;header type="0800"&gt;ISO015000015&lt;/header&gt;&lt;br /&gt;&lt;header type="0810"&gt;ISO015000015&lt;/header&gt;&lt;br /&gt;&lt;br /&gt;&lt;!-- The client example uses this to create requests --&gt;&lt;br /&gt;&lt;template type="0200"&gt;&lt;br /&gt;&lt;field num="3" type="NUMERIC" length="6"&gt;650000&lt;/field&gt;&lt;br /&gt;&lt;field num="32" type="LLVAR"&gt;456&lt;/field&gt;&lt;br /&gt;&lt;field num="35" type="LLVAR"&gt;4591700012340000=&lt;/field&gt;&lt;br /&gt;&lt;field num="43" type="ALPHA" length="40"&gt;SOLABTEST             TEST-3       DF MX&lt;br /&gt;&lt;field num="49" type="ALPHA" length="3"&gt;484&lt;/field&gt;&lt;br /&gt;&lt;field num="60" type="LLLVAR"&gt;B456PRO1+000&lt;/field&gt;&lt;br /&gt;&lt;field num="61" type="LLLVAR"&gt;        1234P&lt;/field&gt;&lt;br /&gt;&lt;field num="100" type="LLVAR"&gt;999&lt;/field&gt;&lt;br /&gt;&lt;field num="102" type="LLVAR"&gt;ABCD&lt;/field&gt;&lt;br /&gt;&lt;/field&gt;&lt;template type="0210"&gt;&lt;br /&gt;&lt;field num="60" type="LLLVAR"&gt;Fixed data from template&lt;/field&gt;&lt;br /&gt;&lt;field num="70" type="ALPHA" length="3"&gt;ABC&lt;/field&gt;&lt;br /&gt;&lt;field num="90" type="ALPHA" length="42"&gt;Field of length 42&lt;/field&gt;&lt;br /&gt;&lt;field num="100" type="LLVAR"&gt;Fixed field&lt;/field&gt;&lt;br /&gt;&lt;field num="102" type="LLVAR"&gt;Another fixed field&lt;/field&gt;&lt;br /&gt;&lt;field num="126" type="LLLVAR"&gt;...and yet another fixed field.&lt;/field&gt;&lt;br /&gt;&lt;/template&gt;&lt;br /&gt;&lt;parse type="0200"&gt;&lt;field num="3" type="NUMERIC" length="6"&gt;&lt;field num="4" type="AMOUNT"&gt;&lt;field num="7" type="DATE10"&gt;&lt;field num="11" type="NUMERIC" length="6"&gt;&lt;field num="12" type="TIME"&gt;&lt;field num="13" type="DATE4"&gt;&lt;field num="15" type="DATE4"&gt;&lt;field num="17" type="DATE_EXP"&gt;&lt;field num="32" type="LLVAR"&gt;&lt;field num="35" type="LLVAR"&gt;&lt;field num="37" type="NUMERIC" length="12"&gt;&lt;field num="41" type="ALPHA" length="16"&gt;&lt;field num="43" type="ALPHA" length="40"&gt;&lt;field num="48" type="LLLVAR"&gt;&lt;field num="49" type="ALPHA" length="3"&gt;&lt;field num="60" type="LLLVAR"&gt;&lt;field num="61" type="LLLVAR"&gt;&lt;field num="100" type="LLVAR"&gt;&lt;field num="102" type="LLVAR"&gt;&lt;/field&gt;&lt;parse type="0210"&gt;&lt;field num="3" type="NUMERIC" length="6"&gt;&lt;field num="4" type="AMOUNT"&gt;&lt;field num="7" type="DATE10"&gt;&lt;field num="11" type="NUMERIC" length="6"&gt;&lt;field num="12" type="TIME"&gt;&lt;field num="13" type="DATE4"&gt;&lt;field num="15" type="DATE4"&gt;&lt;field num="17" type="DATE_EXP"&gt;&lt;field num="32" type="LLVAR"&gt;&lt;field num="35" type="LLVAR"&gt;&lt;field num="37" type="NUMERIC" length="12"&gt;&lt;field num="38" type="NUMERIC" length="6"&gt;&lt;field num="39" type="NUMERIC" length="2"&gt;&lt;field num="41" type="ALPHA" length="16"&gt;&lt;field num="43" type="ALPHA" length="40"&gt;&lt;field num="48" type="LLLVAR"&gt;&lt;field num="49" type="ALPHA" length="3"&gt;&lt;field num="60" type="LLLVAR"&gt;&lt;field num="61" type="LLLVAR"&gt;&lt;field num="70" type="ALPHA" length="3"&gt;&lt;field num="90" type="ALPHA" length="42"&gt;&lt;field num="100" type="LLVAR"&gt;&lt;field num="102" type="LLVAR"&gt;&lt;field num="126" type="LLLVAR"&gt;&lt;/field&gt;&lt;/field&gt;Exampl:&lt;br /&gt;&lt;br /&gt;Request:&lt;br /&gt;ISO0150000500200B23A800128A180180000000014000000650000000000002050042813271000057813271004280428042803456174591700012340000=000000230579A1B2C3D4E5 SOLABTEST TEST-3 DF MX010abcdefghij484012B456PRO1+000013 1234P0399904ABCD&lt;br /&gt;Field Value&lt;br /&gt;ISO header ISO015000050&lt;br /&gt;Message type 0200&lt;br /&gt;Primary bitmap B23A800128A18018&lt;br /&gt;Secondary bitmap 0000000014000000&lt;br /&gt;3 (proc code) 650000&lt;br /&gt;4 (amount) 000000002050 ($20.50)&lt;br /&gt;7 (date) 0428132710 (Abril 28 13:27:10)&lt;br /&gt;11 (trace) 000578&lt;br /&gt;12 (time) 132710 (13:27:10)&lt;br /&gt;13 (date issued) 0428 (28 de abril)&lt;br /&gt;15 (limit date) 0428 (28 de abril)&lt;br /&gt;17 (expiration date) 0804 (Abril 2008)&lt;br /&gt;32 456&lt;br /&gt;35 4591700012340000=&lt;br /&gt;37 (reference) 000000230579&lt;br /&gt;41 (term id) A1B2C3D4E5&lt;br /&gt;43 SOLABTEST TEST-3 DF MX&lt;br /&gt;48 abcdefghij&lt;br /&gt;49 (currency) 484&lt;br /&gt;60 B456PRO1+000&lt;br /&gt;61 1234P&lt;br /&gt;100 999&lt;br /&gt;102 ABCD&lt;br /&gt;&lt;br /&gt;Response:&lt;br /&gt;ISO0150000550210B23A80012EA180180400004014000004650000000000002050042813271000057813271004280428060403456174591700012340000=00000023057923104300A1B2C3D4E5 SOLABTEST TEST-3 DF MX010abcdefghij484012B456PRO1+000054Dynamic data generated at Mon Apr 28 13:27:11 CDT 2008ABCField of length 42 0399904ABCD031...and yet another fixed field.&lt;br /&gt;Field Value&lt;br /&gt;ISO header ISO015000055&lt;br /&gt;Message type 0210&lt;br /&gt;Primary bitmap B23A80012EA18018&lt;br /&gt;Secondary bitmap 0400004014000004&lt;br /&gt;3 (proc code) 650000&lt;br /&gt;4 (amount) 000000002050 ($20.50)&lt;br /&gt;7 (transaction date) 0428132710 (Abril 28 13:27:10)&lt;br /&gt;11 (trace) 000578&lt;br /&gt;12 (time) 132710 (13:27:10)&lt;br /&gt;13 (date issued) 0428 (28 de abril)&lt;br /&gt;15 (limit date) 0428 (28 de abril)&lt;br /&gt;17 (expiration date) 0804 (Abril 2008)&lt;br /&gt;32 456&lt;br /&gt;35 4591700012340000=&lt;br /&gt;37 (reference) 000000230579&lt;br /&gt;38 (confirmation number) 231043&lt;br /&gt;39 (result code) 00&lt;br /&gt;41 (term id) A1B2C3D4E5&lt;br /&gt;43 SOLABTEST TEST-3 DF MX&lt;br /&gt;48 abcdefghij&lt;br /&gt;49 (currency) 484&lt;br /&gt;60 B456PRO1+000&lt;br /&gt;61 Dynamic data generated at Mon Apr 28 13:27:11 CDT 2008&lt;br /&gt;70 ABC&lt;br /&gt;90 Field of length 42&lt;br /&gt;100 999&lt;br /&gt;102 ABCD&lt;br /&gt;126 ...and yet another fixed field.&lt;/field&gt;&lt;/field&gt;&lt;/field&gt;&lt;/field&gt;&lt;/field&gt;&lt;/field&gt;&lt;/field&gt;&lt;/field&gt;&lt;/field&gt;&lt;/field&gt;&lt;/field&gt;&lt;/field&gt;&lt;/field&gt;&lt;/field&gt;&lt;/field&gt;&lt;/field&gt;&lt;/field&gt;&lt;/field&gt;&lt;/field&gt;&lt;/field&gt;&lt;/field&gt;&lt;/field&gt;&lt;/parse&gt;&lt;/field&gt;&lt;/field&gt;&lt;/field&gt;&lt;/field&gt;&lt;/field&gt;&lt;/field&gt;&lt;/field&gt;&lt;/field&gt;&lt;/field&gt;&lt;/field&gt;&lt;/field&gt;&lt;/field&gt;&lt;/field&gt;&lt;/field&gt;&lt;/field&gt;&lt;/field&gt;&lt;/field&gt;&lt;/field&gt;&lt;/parse&gt;&lt;/template&gt;&lt;/j8583-config&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4903191105785361362-3478794538007181185?l=sanjib-swain.blogspot.com' alt='' /&gt;&lt;/div&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/R0mA39MyTXK67FxWWu4UnxtxQFM/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/R0mA39MyTXK67FxWWu4UnxtxQFM/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/R0mA39MyTXK67FxWWu4UnxtxQFM/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/R0mA39MyTXK67FxWWu4UnxtxQFM/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/blogspot/PEHIt/~4/LsSkBLaJwaI" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://sanjib-swain.blogspot.com/feeds/3478794538007181185/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://www.blogger.com/comment.g?blogID=4903191105785361362&amp;postID=3478794538007181185" title="11 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/4903191105785361362/posts/default/3478794538007181185?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/4903191105785361362/posts/default/3478794538007181185?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/blogspot/PEHIt/~3/LsSkBLaJwaI/brief-explanation-of-iso-8583-protocol.html" title="A brief explanation of the ISO-8583 protocol" /><author><name>Sanjib Kumar Swain</name><uri>http://www.blogger.com/profile/11353921866017700402</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="32" height="24" src="http://3.bp.blogspot.com/_nnkYFjJnYR0/SjDB5r7-A4I/AAAAAAAAABg/5LvGBQSMBFM/S220/100_1083.JPG" /></author><thr:total>11</thr:total><feedburner:origLink>http://sanjib-swain.blogspot.com/2009/06/brief-explanation-of-iso-8583-protocol.html</feedburner:origLink></entry><entry gd:etag="W/&quot;C0YMQ3w9cCp7ImA9WxJWGUw.&quot;"><id>tag:blogger.com,1999:blog-4903191105785361362.post-663455547225617923</id><published>2009-06-24T23:08:00.000-07:00</published><updated>2009-06-24T23:26:22.268-07:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2009-06-24T23:26:22.268-07:00</app:edited><title>How to play Bin and CUE files</title><content type="html">&lt;style&gt;&lt;br /&gt;&lt;br /&gt;p.first { background-color: gray; }&lt;br /&gt;p.second { background-color: red; }&lt;br /&gt;p.third { &lt;br /&gt; background: purple;&lt;br /&gt; color: white;&lt;br /&gt;}&lt;br /&gt;&lt;/style&gt;&lt;br /&gt;&lt;p class="third "&gt;&lt;br /&gt;&lt;br&gt;&lt;em&gt;If you have downloaded .bin and .cue files and you are sure that they are video content, then this article will tell you your options on how to play them. &lt;/em&gt;&lt;p&gt;&lt;/p&gt;&lt;br /&gt;&lt;br&gt;&lt;strong&gt;About BIN and CUE files&lt;/strong&gt;&lt;br /&gt;&lt;br&gt;&lt;br /&gt;&lt;br&gt;BIN and CUE files make up a very &lt;a id="KonaLink0" target="undefined" class="kLink" style="text-decoration: underline ! important; position: static;" href="#"&gt;&lt;font style="color: green ! important; font-family: Arial,Helvetica,sans-serif; font-weight: 400; font-size: 12px; position: static;" color="green"&gt;&lt;span class="kLink" style="border-bottom: 1px solid green; color: green ! important; font-family: Arial,Helvetica,sans-serif; font-weight: 400; font-size: 12px; position: static; background-color: transparent;"&gt;popular &lt;/span&gt;&lt;span class="kLink" style="border-bottom: 1px solid green; color: green ! important; font-family: Arial,Helvetica,sans-serif; font-weight: 400; font-size: 12px; position: static; background-color: transparent;"&gt;CD&lt;/span&gt;&lt;/font&gt;&lt;/a&gt; Image format. Specifically, the BIN file contains all the contents that would be included on a CD, whereas the CUE file just has track information. You can view a CUE file in notepad for example for more information.&lt;br /&gt;&lt;br&gt;&lt;br /&gt;&lt;br&gt;&lt;strong&gt;What can BIN and CUE files contain?&lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;&lt;br&gt;&lt;br /&gt;&lt;br&gt;Anything you can find on a CD really, like games, software, VideoCD (VCD), Super VideoCD (SVCD) etc. In this article we will show you how to access that data in many different ways and provide burning instructions for BIN and CUE files. Since this is a playback guide though, it is assumed that you have either a VCD or SVCD compilation.&lt;br /&gt;&lt;br&gt;&lt;br /&gt;&lt;br&gt;&lt;strong&gt;Easiest Solution&lt;/strong&gt;&lt;br /&gt;&lt;br&gt;&lt;br /&gt;&lt;br&gt;&lt;img src="http://i.afterdawn.com/storage/pictures/vlc_window.gif" align="right" height="91" width="355"&gt;Download and install the &lt;strong&gt;VLC&lt;/strong&gt; player. The VLC package is already capable of playing bin / cue image files directly if they are VCD or SVCD.&lt;br /&gt;&lt;br&gt;&lt;br /&gt;&lt;br&gt;You can get &lt;a href="http://www.afterdawn.com/software/video_software/video_players/vlc.cfm"&gt;VLC for Windows from this URL&lt;/a&gt;.&lt;br clear="all"&gt;&lt;br /&gt;&lt;br&gt;&lt;br /&gt;&lt;br&gt;&lt;br /&gt;&lt;br /&gt;&lt;br&gt;&lt;img src="http://i.afterdawn.com/storage/pictures/vlc_open_file.gif" align="right" height="394" width="538"&gt;Click File and click the Open File option.&lt;br clear="all"&gt;&lt;br /&gt;&lt;br&gt;Now, click the &lt;strong&gt;Browse &lt;/strong&gt; button next to the first white line at the top of the window with title "Open.." and navigate through your harddrive for the &lt;a id="KonaLink1" target="undefined" class="kLink" style="text-decoration: underline ! important; position: static;" href="#"&gt;&lt;font style="color: green ! important; font-family: Arial,Helvetica,sans-serif; font-weight: 400; font-size: 12px; position: static;" color="green"&gt;&lt;span class="kLink" style="color: green ! important; font-family: Arial,Helvetica,sans-serif; font-weight: 400; font-size: 12px; position: static;"&gt;video&lt;/span&gt;&lt;/font&gt;&lt;/a&gt; you wish to watch and select it (select the CUE file). After you have selected the video, click &lt;strong&gt;OK &lt;/strong&gt; and VLC will start playing the video you chose.&lt;br /&gt;&lt;br&gt;&lt;br /&gt;&lt;br&gt;For other Operating Systems...&lt;br /&gt;&lt;br&gt;&lt;br /&gt;&lt;br&gt;Mac: &lt;a href="http://www.afterdawn.com/software/alternative_platforms/mac_software/vlc_for_mac.cfm"&gt;http://www.afterdawn.com/software/alternative_platforms/mac_software/vlc_for_mac.cfm&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;&lt;br&gt;&lt;br /&gt;&lt;br&gt;Linux: &lt;a href="http://www.afterdawn.com/software/video_software/video_players/vlc_linux.cfm"&gt;http://www.afterdawn.com/software/video_software/video_players/vlc_linux.cfm&lt;/a&gt;&lt;br /&gt;&lt;br&gt;&lt;br /&gt;&lt;br&gt;&lt;strong&gt;Media Player Classic&lt;/strong&gt;&lt;br /&gt;&lt;br&gt;&lt;br /&gt;&lt;br&gt;&lt;img src="http://i.afterdawn.com/storage/pictures/mpc.gif" align="right" height="246" width="226"&gt;Another easy solution is to play the files in &lt;strong&gt;Media Player Classic&lt;/strong&gt;. While you are browsing for files to open with MPC, it will now automatically show bin and cue files. Instead you would have to &lt;a id="KonaLink2" target="undefined" class="kLink" style="text-decoration: underline ! important; position: static;" href="#"&gt;&lt;font style="color: green ! important; font-family: Arial,Helvetica,sans-serif; font-weight: 400; font-size: 12px; position: static;" color="green"&gt;&lt;span class="kLink" style="color: green ! important; font-family: Arial,Helvetica,sans-serif; font-weight: 400; font-size: 12px; position: static;"&gt;switch&lt;/span&gt;&lt;/font&gt;&lt;/a&gt; &lt;strong&gt;File Type&lt;/strong&gt; to &lt;em&gt;"All Files"&lt;/em&gt;. Unlike VideoLan Client, you have tom play the .bin file in this case.&lt;br clear="all"&gt;&lt;br /&gt;&lt;br /&gt;&lt;br&gt;&lt;br /&gt;&lt;br&gt;&lt;br /&gt;&lt;br&gt;&lt;strong&gt;Burn bin &amp;amp; cue files&lt;/strong&gt;&lt;br /&gt;&lt;br&gt;&lt;br /&gt;&lt;br&gt;Since .BIN/.CUE files are CD images, they are designed to be burned to blank CD media. In order to do this, &lt;a href="http://www.afterdawn.com/guides/archive/bin_cue_with_nero.cfm"&gt;follow this guide&lt;/a&gt;.&lt;br /&gt;&lt;br&gt;&lt;br /&gt;&lt;br&gt;VCD and SVCD work in most modern DVD players. &lt;br /&gt;&lt;br&gt;&lt;br /&gt;&lt;br&gt;&lt;strong&gt;Extract MPEG Files&lt;/strong&gt;&lt;br /&gt;&lt;br&gt;&lt;br /&gt;&lt;br&gt;Since your BIN / CUE files are most likely VCD or SVCD (if you are certain it should be video content you have), you can extract the &lt;a id="KonaLink3" target="undefined" class="kLink" style="text-decoration: underline ! important; position: static;" href="#"&gt;&lt;font style="color: green ! important; font-family: Arial,Helvetica,sans-serif; font-weight: 400; font-size: 12px; position: static;" color="green"&gt;&lt;span class="kLink" style="color: green ! important; font-family: Arial,Helvetica,sans-serif; font-weight: 400; font-size: 12px; position: static;"&gt;MPEG &lt;/span&gt;&lt;span class="kLink" style="color: green ! important; font-family: Arial,Helvetica,sans-serif; font-weight: 400; font-size: 12px; position: static;"&gt;video&lt;/span&gt;&lt;/font&gt;&lt;/a&gt; streams directly from the bin file. To do this, you will need IsoBuster.&lt;br /&gt;&lt;br /&gt;&lt;br&gt;&lt;br /&gt;&lt;br&gt;&lt;h3&gt;IsoBuster&lt;/h3&gt;&lt;br /&gt;&lt;br&gt;&lt;br /&gt;&lt;br&gt;&lt;img src="http://i.afterdawn.com/storage/pictures/isobuster_1.gif" align="right" height="292" width="401"&gt;IsoBuster is an excellent tool for making CD images. &lt;a href="http://www.afterdawn.com/software/cdr_software/cdr_tools/isobuster.cfm"&gt;Download Isobuster from AfterDawn and install it&lt;/a&gt;. On its first run, it will look like the picture beside this text if you don't have a CD in any of your drives.&lt;br /&gt;&lt;br&gt;&lt;br /&gt;&lt;br&gt;In order to extract &lt;strong&gt;MPEG&lt;/strong&gt; streams from bin/cue images you now need to open the CD image. To do so, click &lt;strong&gt;File --&amp;gt; Open Image File&lt;/strong&gt;.&lt;br clear="all"&gt;&lt;br /&gt;&lt;br /&gt;&lt;br&gt;&lt;br /&gt;&lt;br&gt;&lt;img src="http://i.afterdawn.com/storage/pictures/isobuster_2.gif" align="right" height="69" width="169"&gt;Browse to the &lt;a id="KonaLink4" target="undefined" class="kLink" style="text-decoration: underline ! important; position: static;" href="#"&gt;&lt;font style="color: green ! important; font-family: Arial,Helvetica,sans-serif; font-weight: 400; font-size: 12px; position: static;" color="green"&gt;&lt;span class="kLink" style="color: green ! important; font-family: Arial,Helvetica,sans-serif; font-weight: 400; font-size: 12px; position: static;"&gt;folder&lt;/span&gt;&lt;/font&gt;&lt;/a&gt; with the bin and cue files in it and open the &lt;strong&gt;.CUE&lt;/strong&gt; file.&lt;br clear="all"&gt;&lt;br /&gt;&lt;br&gt;&lt;br /&gt;&lt;br&gt;&lt;img src="http://i.afterdawn.com/storage/pictures/isobuster_3.gif" align="right" height="292" width="401"&gt;The Image file will now open and you should be able to see the folders on the disc. Usually, if there is an &lt;strong&gt;MPEGAV&lt;/strong&gt; folder, then you have a VCD, which contains MPEG-1 video streams. If you have an &lt;strong&gt;MPEG2&lt;/strong&gt; folder you definitely have an SVCD. Open the folder to find MPEG file(s) in it. Please note that sometimes (most often with VCD), there will be files with &lt;strong&gt;.DAT&lt;/strong&gt; &lt;a id="KonaLink5" target="undefined" class="kLink" style="text-decoration: underline ! important; position: static;" href="#"&gt;&lt;font style="color: green ! important; font-family: Arial,Helvetica,sans-serif; font-weight: 400; font-size: 12px; position: static;" color="green"&gt;&lt;span class="kLink" style="color: green ! important; font-family: Arial,Helvetica,sans-serif; font-weight: 400; font-size: 12px; position: static;"&gt;extension&lt;/span&gt;&lt;/font&gt;&lt;/a&gt;. These are MPEG video files despite the extension.&lt;br clear="all"&gt;&lt;br /&gt;&lt;br /&gt;&lt;br&gt;&lt;br /&gt;&lt;br&gt;&lt;img src="http://i.afterdawn.com/storage/pictures/isobuster_4.gif" align="right" height="71" width="266"&gt;Extracting these files as is, is not a good idea. Instead, IsoBuster can extract them and convert them to compliant files also. To do this, right click on the &lt;strong&gt;AVSEQXX.MPG&lt;/strong&gt; or &lt;strong&gt;AVSEQXX.DAT&lt;/strong&gt; file(s) (XX representing the number of the file) and select &lt;strong&gt;Extract but FILTER only MF2F MPEG frames&lt;/strong&gt;.&lt;br clear="all"&gt;&lt;br /&gt;&lt;br&gt;&lt;br /&gt;&lt;br&gt;&lt;br /&gt;&lt;br&gt;&lt;img src="http://i.afterdawn.com/storage/pictures/isobuster_5.gif" align="right" height="172" width="245"&gt;Select a target filename and &lt;a id="KonaLink6" target="undefined" class="kLink" style="text-decoration: underline ! important; position: static;" href="#"&gt;&lt;font style="color: green ! important; font-family: Arial,Helvetica,sans-serif; font-weight: 400; font-size: 12px; position: static;" color="green"&gt;&lt;span class="kLink" style="border-bottom: 1px solid green; color: green ! important; font-family: Arial,Helvetica,sans-serif; font-weight: 400; font-size: 12px; position: static; background-color: transparent;"&gt;directory&lt;/span&gt;&lt;/font&gt;&lt;span style="position: relative;" id="preLoadWrap6"&gt;&lt;div style="position: absolute; z-index: 4000; top: -32px; left: -18px; display: none;" id="preLoadLayer6"&gt;&lt;img style="border: 0px none ;" src="http://kona.kontera.com/javascript/lib/imgs/grey_loader.gif"&gt;&lt;/div&gt;&lt;/span&gt;&lt;/a&gt; and then the program will begin extracting the MPEG data. &lt;br clear="all"&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4903191105785361362-663455547225617923?l=sanjib-swain.blogspot.com' alt='' /&gt;&lt;/div&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/ENtkGCfUNr62vzVIO9FmKpsLQz4/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/ENtkGCfUNr62vzVIO9FmKpsLQz4/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/ENtkGCfUNr62vzVIO9FmKpsLQz4/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/ENtkGCfUNr62vzVIO9FmKpsLQz4/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/blogspot/PEHIt/~4/Ge7aNCPf_0k" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://sanjib-swain.blogspot.com/feeds/663455547225617923/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://www.blogger.com/comment.g?blogID=4903191105785361362&amp;postID=663455547225617923" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/4903191105785361362/posts/default/663455547225617923?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/4903191105785361362/posts/default/663455547225617923?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/blogspot/PEHIt/~3/Ge7aNCPf_0k/how-to-play-bin-and-cue-files.html" title="How to play Bin and CUE files" /><author><name>Sanjib Kumar Swain</name><uri>http://www.blogger.com/profile/11353921866017700402</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="32" height="24" src="http://3.bp.blogspot.com/_nnkYFjJnYR0/SjDB5r7-A4I/AAAAAAAAABg/5LvGBQSMBFM/S220/100_1083.JPG" /></author><thr:total>0</thr:total><feedburner:origLink>http://sanjib-swain.blogspot.com/2009/06/how-to-play-bin-and-cue-files.html</feedburner:origLink></entry><entry gd:etag="W/&quot;A0UEQX0zfip7ImA9WxJWEEk.&quot;"><id>tag:blogger.com,1999:blog-4903191105785361362.post-231720185300973916</id><published>2009-06-14T23:55:00.000-07:00</published><updated>2009-06-15T00:00:00.386-07:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2009-06-15T00:00:00.386-07:00</app:edited><title>Java Tool : JAR anatomy</title><content type="html">JAR files are Java's version of ZIP files. In fact, JAR uses the ZIP file format. There are two main uses for JAR files which I shall explain here. The first use is to compress (make a smaller size) a number of files into one file (archiving). The second use is to make a Java executable JAR file.&lt;br /&gt;&lt;br /&gt;Compress Files To A Java Archive (JAR)&lt;br /&gt;&lt;br /&gt;This is by far the most common use for JAR files: to compress multiple files into a single JAR archive. JAR files can be opened with WinZip or WinRar. In terms of Java applications, the ability to archive any number of source or class files into one single archive represents the biggest advantage - distributing one file containing hundreds of files is so much easier than distributing hundreds of files separately!&lt;br /&gt;&lt;br /&gt;The jar utility program is run from the command line (DOS prompt or bash for example, depending on your OS). Here is how to create a compressed JAR file:&lt;br /&gt;&lt;br /&gt;   jar cf archive_name.jar files&lt;br /&gt;&lt;br /&gt;Let's look at each part of that command line.&lt;br /&gt;&lt;br /&gt;jar&lt;br /&gt;&lt;br /&gt;    The command to run the jar utility.&lt;br /&gt;&lt;br /&gt;CF&lt;br /&gt;&lt;br /&gt;    Create a new archive with the file name specified. These two options are from this list of common options:&lt;br /&gt;&lt;br /&gt;    - c create new archive&lt;br /&gt;    - t list table of contents for archive&lt;br /&gt;    - x extract named (or all) files from archive&lt;br /&gt;    - u update existing archive&lt;br /&gt;    - v generate verbose output on standard output&lt;br /&gt;    - f specify archive file name&lt;br /&gt;    - m include manifest information from specified manifest file&lt;br /&gt;    - 0 store only; use no ZIP compression&lt;br /&gt;    - M do not create a manifest file for the entries&lt;br /&gt;    - i generate index information for the specified jar files&lt;br /&gt;    - C change to the specified directory and include the following file&lt;br /&gt;&lt;br /&gt;    Multiple options can be used together. They all must appear after the "jar" command with no white space separating them.&lt;br /&gt;&lt;br /&gt;archive_name.jar&lt;br /&gt;&lt;br /&gt;    Name of the JAR file. This can only be included if you use the 'f' option.&lt;br /&gt;&lt;br /&gt;files&lt;br /&gt;&lt;br /&gt;    Names of all the files you want to put in the jar file. This could be just one name or a list of multiple names separated by space. Names can use pattern matching characters to match multiple files.&lt;br /&gt;&lt;br /&gt;Common Examples&lt;br /&gt;&lt;br /&gt;Let's say I have a Java application consisting of three source files that I wish to distribute:&lt;br /&gt;&lt;br /&gt;    One.java&lt;br /&gt;    Two.java&lt;br /&gt;    Three.java&lt;br /&gt;&lt;br /&gt;I also want to call my JAR file example.jar. To make a JAR file with just One.java:&lt;br /&gt;&lt;br /&gt;   jar CF example.jar One.java&lt;br /&gt;&lt;br /&gt;To make a file with all three files listed separately:&lt;br /&gt;&lt;br /&gt;   jar CF example.jar One.java Two.java Three.java&lt;br /&gt;&lt;br /&gt;To make a file with all three files using a pattern match:&lt;br /&gt;&lt;br /&gt;   jar CF example.jar *.java&lt;br /&gt;&lt;br /&gt;It goes (almost) without saying that the source files are in the same directory you are running the jar command in.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Compress Files To An Executable Java Archive (JAR)&lt;br /&gt;&lt;br /&gt;It is also possible to make an archive that can be executed (run) by Java and even by a double click through your OS, if you have it set up correctly. Of course, to do this you must store compiled class files in the archive, as well as or instead of Java source files, since Java source files cannot be run!&lt;br /&gt;&lt;br /&gt;Continuing the example above, I now compile my Java source files:&lt;br /&gt;&lt;br /&gt;   javac *Java&lt;br /&gt;&lt;br /&gt;or&lt;br /&gt;&lt;br /&gt;   javac One.java Two.java Three.java&lt;br /&gt;&lt;br /&gt;Create An Executable JAR&lt;br /&gt;&lt;br /&gt;All JAR files contain something called a manifest file which holds information Java wants to know. One piece of information a manifest file may contain is the name of a class that will be run if the JAR file is executed.&lt;br /&gt;&lt;br /&gt;The first thing you must do is create a text file that lists the "main" class - the class that has the main method you want executed when the JAR is executed. Let's say that Three from the above example has the main method I want executed. I create a text file called "mainClass.txt" with the following text:&lt;br /&gt;&lt;br /&gt;    Main-Class: Three&lt;br /&gt;&lt;br /&gt;     &lt;br /&gt;&lt;br /&gt;IMPORTANT: the text file only needs the one line of text for this purpose. However, the file must end with a blank line or this will not work, ie the file has two lines in it - the second one is empty. Note too the class is called "Three" and not "Three.java" (the file containing the source code) or "Three.class" (the file containing the byte codes). If your class file is in a package hierarchy, you must use the fully qualified name of the class (eg "myPackage.MyClass").&lt;br /&gt;&lt;br /&gt;I then run the jar utility with this command line:&lt;br /&gt;&lt;br /&gt;   jar cmf mainClass.txt example.jar *.class&lt;br /&gt;&lt;br /&gt;With this line, I told jar to create a JAR file (option c) with modifications to the manifest file (option m) as specified within mainClass.txt, naming the JAR file (option f) as example.jar and including everything that matches the pattern *Class&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Running An Executable JAR From Command Line&lt;br /&gt;&lt;br /&gt;I can run it from the command line like this:&lt;br /&gt;&lt;br /&gt;   java -jar example.jar&lt;br /&gt;&lt;br /&gt;Within Windows, it is also possible to set up Windows Explorer so that you can double click on the JAR file icon to execute the file (handy for GUI applications). The first thing you must do is set up the correct association with the 'javaw.exe' application that JDK for Windows will have. Click here for an older example with pictures! Open Windows Explorer and select Tools | Folder Options | File Types.&lt;br /&gt;&lt;br /&gt;If there is no JAR file type, create it. Give it a description like&lt;br /&gt;&lt;br /&gt;   jar - Executable Jar File&lt;br /&gt;&lt;br /&gt;to ensure it sorts under 'jar'. Create or edit the action called "open" and associate it with the following action:&lt;br /&gt;&lt;br /&gt;   "C:\Java\jdk1.4.0\bin\javaw.exe" -jar "%1"&lt;br /&gt;&lt;br /&gt;Of course, you will replace "C:\Java\jdk1.4.0\bin\javaw.exe" with whatever path is correct on your machine.&lt;br /&gt;&lt;br /&gt;IMPORTANT: include the double quotes to take care of names with spaces.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight:bold;"&gt;Some useful Tips&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;1. jar command can also operate on zip files. I usually run jar tvf hello.zip to quickly view its content, without starting up the WinZip program. jar xvf hello.zip  should also be able to expand the target zip files. I find it hard to memorize Unix zip/unzip command line options, so I just use jar tvf/jar xvf instead. For example:&lt;br /&gt;&lt;br /&gt;C:\tmp&gt;jar tvf eclipse-SDK-3.2RC7-win32.zip&lt;br /&gt;&lt;br /&gt;2. jar tvf can selectively list table of contents for archive. I used to run jar tvf j2ee.jar | grep javax/servlet/http to search for servlet classes in j2ee.jar. Replace grep with findstr on Windows. In fact, I don't need grep or findstr; I can just run this command:&lt;br /&gt;&lt;br /&gt;jar tvf j2ee.jar javax/servlet/http&lt;br /&gt;&lt;br /&gt;Note that the search criteria are matched against the beginning of all entries in jar file. It uses String.startsWith(what) rather than String.contains(what). So this command jar tvf j2ee.jar ejb will not return any matching entries, though jar tvf j2ee.jar javax/ejb will return all ejb classes. The search is also case-sensitive.&lt;br /&gt;&lt;br /&gt;If you want case-insensitive search, or match by any parts (not just the beginning) of entries, you still need to use jar tvf my.jar | grep -i aNynAmE&lt;br /&gt;&lt;br /&gt;3. You can extract selected entries from a jar file. For instance, if you only want to view the meta-inf/manifest.mf file, you can&lt;br /&gt;&lt;br /&gt;C:\Sun\AppServer\lib&gt;jar xvf j2ee.jar META-INF/MANIFEST.MF&lt;br /&gt;inflated: META-INF/MANIFEST.MF&lt;br /&gt;&lt;br /&gt;Or using a backslash instead of a forward slash:&lt;br /&gt;&lt;br /&gt;C:\Sun\AppServer\lib&gt;jar xvf j2ee.jar META-INF\MANIFEST.MF&lt;br /&gt;inflated: META-INF/MANIFEST.MF&lt;br /&gt;&lt;br /&gt;The entry names are case sensitive, and so the following will not extract anything:&lt;br /&gt;&lt;br /&gt;C:\Sun\AppServer\lib&gt;jar xvf j2ee.jar meta-inf/manifest.mf&lt;br /&gt;&lt;br /&gt;Of course, you can always double-click the entry to view it in WinZip, fileroller, or other tools.&lt;br /&gt;&lt;br /&gt;4. You can choose not to have manifest file when creating a jar file, using M option:&lt;br /&gt;&lt;br /&gt;jar cvfM no-meta.jar A.class&lt;br /&gt;adding: A.class(in = 405) (out= 279)(deflated 31%)&lt;br /&gt;&lt;br /&gt;Note: it's upper-case M. Lower-case m has a different meaning.&lt;br /&gt;&lt;br /&gt;5. You can specify your own manifest file when creating a jar file, using m option:&lt;br /&gt;&lt;br /&gt;jar cvfm my-meta.jar my-meta-inf\my.mf A.class&lt;br /&gt;added manifest&lt;br /&gt;adding: A.class(in = 405) (out= 279)(deflated 31%)&lt;br /&gt;&lt;br /&gt;The option used here cvfm tells the jar command that the destination file (f) will come next and then custom manifest file (m). I can also specify them in a different order:&lt;br /&gt;&lt;br /&gt;jar cvmf my-meta-inf\my.mf my-meta.jar A.class&lt;br /&gt;added manifest&lt;br /&gt;adding: A.class(in = 405) (out= 279)(deflated 31%)&lt;br /&gt;&lt;br /&gt;It's lower-case m. Upper-case M has a different meaning.&lt;br /&gt;&lt;br /&gt;6.META-INF/MANIFEST.MF file in source files is always ignored.&lt;br /&gt;&lt;br /&gt;jar cvf ignore.jar A.class META-INF&lt;br /&gt;added manifest&lt;br /&gt;adding: A.class(in = 405) (out= 279)(deflated 31%)&lt;br /&gt;ignoring entry META-INF/&lt;br /&gt;adding: META-INF/LICENSE.txt(in = 2657) (out= 1185)(deflated 55%)&lt;br /&gt;ignoring entry META-INF/MANIFEST.MF&lt;br /&gt;&lt;br /&gt;When it comes to manifest files for new jar file, you only have 3 options:&lt;br /&gt;&lt;br /&gt;    * Do not specify any manifest-related options and use the default MANIFEST.MF&lt;br /&gt;&lt;br /&gt;    * Use option M not to include a manifest file&lt;br /&gt;&lt;br /&gt;    * Use option m to use a custom manifest file. Inside the jar file, this file will always be named MANIFEST.MF under META-INF directory. Outside of the jar file, this custom manifest file can be anywhere and have any name.&lt;br /&gt;&lt;br /&gt;7. If you unjar an archive, do nothing, and then jar it up again, the resulted new archive may not equal to the original one. And applications using this new archive may not work correctly because of the wrong manifest file. The original jar may have a custom manifest file, which is expaned into META-INF/MANIFEST.MF. But when you jar these files up again without using cvfm option, this custom manifest file is ignored and a default MANIFEST.MF is included.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;8. jar command options can start with optional -. jar tvf a.jar is the same as jar -tvf a.jar&lt;br /&gt;&lt;br /&gt;9. You would usually use relative paths for source files, relative to the current directory. These relative paths will be preserved inside the target jar file. For example, jar cvf \tmp\b.jar com\javahowto\test\ will create the directory tree com\javahowto\test\ inside the target jar, and include all files under &lt;current-dir&gt;\com\javahowto\test\.&lt;br /&gt;&lt;br /&gt;If you use absolute paths for source files, jar will copy the absolute paths inside the jar file, which is not what you want. For example,&lt;br /&gt;&lt;br /&gt;C:\tmp&gt;jar cvf a.jar C:\tmp\A.class&lt;br /&gt;added manifest&lt;br /&gt;adding: C:/tmp/A.class(in = 405) (out= 279)(deflated 31%)&lt;br /&gt;&lt;br /&gt;10. If source files are not located in the current directory, you can use -C option to tell jar command to implicitly change to another directory and then include files there. For example,&lt;br /&gt;&lt;br /&gt;C:\ws\nb\scrap\dist&gt;jar cvf hello-world.jar -C ..\build\classes com\javahowto\test&lt;br /&gt;&lt;br /&gt;11. If you use -C ../build/classes option and want to include all files under ../build/classes, use . (dot) to represent all files there. Note that you can't use *, which will resolve by OS to all files to the current directory. For example,&lt;br /&gt;&lt;br /&gt;C:\ws\nb\scrap\dist&gt;jar cvf hello-world.jar -C ..\build\classes .&lt;br /&gt;&lt;br /&gt;The following example (using -C and *) will ignore -C option and instead include all files in the current directory, which is not what we want:&lt;br /&gt;&lt;br /&gt;C:\ws\nb\scrap\dist&gt;jar cvf hello-world.jar -C ..\build\classes *&lt;br /&gt;..\build\classes\com\hello-world.jar : no such file or directory&lt;br /&gt;added manifest&lt;br /&gt;adding: scrap.jar(in = 20487) (out= 7472)(deflated 63%)&lt;br /&gt;&lt;br /&gt;12. There are 3 types of paths in jar command:&lt;br /&gt;&lt;br /&gt;    * path to the destination jar file, either relative or absolute path is fine. In fact, any format is ok as long as it can be correctly resolved by the OS&lt;br /&gt;&lt;br /&gt;    * path to the manifest file, if m option is present. Either relative or absolute path is fine. The same as destination file.&lt;br /&gt;&lt;br /&gt;    * multiple paths to source files. They should be relative to the current directory, unless -C option is present. In that case, all source files should be relative to the value of -C option.&lt;br /&gt;&lt;br /&gt;If you don't like using -C option, I'd suggest you always cd into the parent directory of all source files, and then run jar command.&lt;br /&gt;&lt;br /&gt;13. It is not possible to include source files from multiple different parent directories. But you can always first copy them into a common parent directory. Jar task in Apache Ant is more flexible and can accommodate almost all use cases.&lt;br /&gt;&lt;br /&gt;14. In JDK 6 or newer version, you can use e option to specify an entry-point class (Main-Class in META-INF/MANIFEST.MF) for self-contained applications packaged in a jar file. See this post for details.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4903191105785361362-231720185300973916?l=sanjib-swain.blogspot.com' alt='' /&gt;&lt;/div&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/33MG_xER8JEhhFXw2FBWrN_uJt4/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/33MG_xER8JEhhFXw2FBWrN_uJt4/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/33MG_xER8JEhhFXw2FBWrN_uJt4/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/33MG_xER8JEhhFXw2FBWrN_uJt4/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/blogspot/PEHIt/~4/EjHuR2MnHa4" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://sanjib-swain.blogspot.com/feeds/231720185300973916/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://www.blogger.com/comment.g?blogID=4903191105785361362&amp;postID=231720185300973916" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/4903191105785361362/posts/default/231720185300973916?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/4903191105785361362/posts/default/231720185300973916?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/blogspot/PEHIt/~3/EjHuR2MnHa4/java-tool-jar-anatomy.html" title="Java Tool : JAR anatomy" /><author><name>Sanjib Kumar Swain</name><uri>http://www.blogger.com/profile/11353921866017700402</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="32" height="24" src="http://3.bp.blogspot.com/_nnkYFjJnYR0/SjDB5r7-A4I/AAAAAAAAABg/5LvGBQSMBFM/S220/100_1083.JPG" /></author><thr:total>0</thr:total><feedburner:origLink>http://sanjib-swain.blogspot.com/2009/06/java-tool-jar-anatomy.html</feedburner:origLink></entry><entry gd:etag="W/&quot;CkYHSX0_fip7ImA9WxJXF0w.&quot;"><id>tag:blogger.com,1999:blog-4903191105785361362.post-5152344857578267754</id><published>2009-06-11T01:45:00.000-07:00</published><updated>2009-06-11T01:48:58.346-07:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2009-06-11T01:48:58.346-07:00</app:edited><title>How to Find out the IP address assigned to eth0 and display IP only</title><content type="html">For shell script or may be for other cause you may need the IP address only. You can use ifconfig command with grep and other filters.&lt;br /&gt;&lt;br /&gt;Default output of /sbin/ifconfig command is all interfaces:&lt;br /&gt;$ /sbin/ifconfigOutput:&lt;br /&gt;&lt;br /&gt;lo        Link encap:Local Loopback&lt;br /&gt;          inet addr:127.0.0.1  Mask:255.0.0.0&lt;br /&gt;          inet6 addr: ::1/128 Scope:Host&lt;br /&gt;          UP LOOPBACK RUNNING  MTU:16436  Metric:1&lt;br /&gt;          RX packets:69527 errors:0 dropped:0 overruns:0 frame:0&lt;br /&gt;          TX packets:69527 errors:0 dropped:0 overruns:0 carrier:0&lt;br /&gt;          collisions:0 txqueuelen:0&lt;br /&gt;          RX bytes:41559546 (39.6 MiB)  TX bytes:41559546 (39.6 MiB)&lt;br /&gt;&lt;br /&gt;eth0      Link encap:Ethernet  HWaddr 00:17:9A:0A:F6:44&lt;br /&gt;          inet addr:192.168.2.1  Bcast:192.168.1.255  Mask:255.255.255.0&lt;br /&gt;          inet6 addr: fe80::217:9aff:fe0a:f644/64 Scope:Link&lt;br /&gt;          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1&lt;br /&gt;          RX packets:227614 errors:0 dropped:0 overruns:0 frame:0&lt;br /&gt;          TX packets:60421 errors:0 dropped:0 overruns:0 carrier:0&lt;br /&gt;          collisions:272 txqueuelen:1000&lt;br /&gt;          RX bytes:69661583 (66.4 MiB)  TX bytes:10361043 (9.8 MiB)&lt;br /&gt;          Interrupt:17&lt;br /&gt;&lt;br /&gt;ra0       Link encap:Ethernet  HWaddr 00:50:56:C0:00:01&lt;br /&gt;          inet addr:192.168.1.2  Bcast:192.168.2.255  Mask:255.255.255.0&lt;br /&gt;          inet6 addr: fe80::250:56ff:fec0:1/64 Scope:Link&lt;br /&gt;          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1&lt;br /&gt;          RX packets:1024 errors:0 dropped:0 overruns:0 frame:0&lt;br /&gt;          TX packets:1320 errors:0 dropped:0 overruns:0 carrier:0&lt;br /&gt;          collisions:0 txqueuelen:1000&lt;br /&gt;          RX bytes:0 (0.0 b)  TX bytes:0 (0.0 b)&lt;br /&gt;&lt;br /&gt;Now you just select eth0 as follows:&lt;br /&gt;$ /sbin/ifconfig eth0&lt;br /&gt;&lt;br /&gt;Now you just wanted the IP address, use grep to get the IP:&lt;br /&gt;$ /sbin/ifconfig eth0| grep 'inet addr:'Output:&lt;br /&gt;&lt;br /&gt;inet addr:192.168.2.1  Bcast:192.168.2.255  Mask:255.255.255.0&lt;br /&gt;&lt;br /&gt;To get IP address from use cut command:&lt;br /&gt;$ /sbin/ifconfig eth0 | grep 'inet addr:' | cut -d: -f2Output:&lt;br /&gt;&lt;br /&gt;192.168.2.1  Bcast&lt;br /&gt;&lt;br /&gt;Finally remove Bcast with awk&lt;br /&gt;$ /sbin/ifconfig eth0 | grep 'inet addr:' | cut -d: -f2 | awk '{ print $1}'&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4903191105785361362-5152344857578267754?l=sanjib-swain.blogspot.com' alt='' /&gt;&lt;/div&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/MGBGgxs0c41aIFi_NPafQZl_BRs/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/MGBGgxs0c41aIFi_NPafQZl_BRs/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/MGBGgxs0c41aIFi_NPafQZl_BRs/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/MGBGgxs0c41aIFi_NPafQZl_BRs/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/blogspot/PEHIt/~4/MtI72069vDs" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://sanjib-swain.blogspot.com/feeds/5152344857578267754/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://www.blogger.com/comment.g?blogID=4903191105785361362&amp;postID=5152344857578267754" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/4903191105785361362/posts/default/5152344857578267754?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/4903191105785361362/posts/default/5152344857578267754?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/blogspot/PEHIt/~3/MtI72069vDs/how-to-find-out-ip-address-assigned-to.html" title="How to Find out the IP address assigned to eth0 and display IP only" /><author><name>Sanjib Kumar Swain</name><uri>http://www.blogger.com/profile/11353921866017700402</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="32" height="24" src="http://3.bp.blogspot.com/_nnkYFjJnYR0/SjDB5r7-A4I/AAAAAAAAABg/5LvGBQSMBFM/S220/100_1083.JPG" /></author><thr:total>0</thr:total><feedburner:origLink>http://sanjib-swain.blogspot.com/2009/06/how-to-find-out-ip-address-assigned-to.html</feedburner:origLink></entry><entry gd:etag="W/&quot;CU8GQnozeip7ImA9WxJRF0Q.&quot;"><id>tag:blogger.com,1999:blog-4903191105785361362.post-914651511958170387</id><published>2009-05-19T21:28:00.000-07:00</published><updated>2009-05-19T21:30:23.482-07:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2009-05-19T21:30:23.482-07:00</app:edited><title>Implemating MEDIAWIKI</title><content type="html">MediaWiki requires much more manual work to install than MoinMoin Wiki. Unfortunately, I was unable to find a comprehensive guide detailing how to go from scratch to fully operational wiki. There is the Installation Guide which details the basic server setup. It then redirects you to two pages: one on configuration and one on administration. Most of these documents are fine but at the time of this writing the ‘configuration’ document is fairly empty and I was left wondering about many configuration options. Hence this guide which will try to tie together all the things you need in order to get up and running.&lt;br /&gt;&lt;br /&gt;To keep things moving this guide will be written at a fairly advanced level. If you don’t feel comfortable installing server side software you may want to check out some of our other How To’s for inspiration.&lt;br /&gt;&lt;br /&gt;These instructions are suitable for FreeBSD 5.3-RELEASE-p37 and MediaWiki 1.9.3, although you will probably find it useful regardless of the platform and MediaWiki version you use.&lt;br /&gt;Basic Installation&lt;br /&gt;&lt;br /&gt;This part is covered very well by the Installation page of MediaWiki. Here’s the super condensed FreeBSD take on installation:&lt;br /&gt;&lt;br /&gt;To install MediaWiki in FreeBSD,&lt;br /&gt;&lt;br /&gt;# cd /usr/ports/www/mediawiki&lt;br /&gt;# make install&lt;br /&gt;&lt;br /&gt;This will install MediaWiki into /usr/local/www/mediawiki/, by default. You will probably want to copy this installation to some other folder since MediaWiki changes files in its installation folder during use.&lt;br /&gt;&lt;br /&gt;# cp -Rf /usr/local/www/mediawiki /www/mywiki&lt;br /&gt;&lt;br /&gt;Then,&lt;br /&gt;&lt;br /&gt;   1. Make sure the config folder is writable by the httpd user (www usually).&lt;br /&gt;   2. Set up your web server to serve pages from the location.&lt;br /&gt;   3. Surf to your new wiki. You will be prompted to go through an installation procedure. This part is very straight forward.&lt;br /&gt;   4. Move config/LocalSettings.php to the root of the wiki installation. You can now delete the config folder.&lt;br /&gt;&lt;br /&gt;Now that was the easy part. Here comes the stuff that took a little bit longer to figure out. Thanks to Playing With Wire you’ll be able to do it in minutes! :)&lt;br /&gt;Additional Manual Configuration&lt;br /&gt;&lt;br /&gt;The installer does some things but not everything. While many online applications such as WordPress come with fancy online configuration tools, MediaWiki uses more traditional configuration files which you’ll be editing by hand.&lt;br /&gt;&lt;br /&gt;Here’s what you’ll need to do:&lt;br /&gt;&lt;br /&gt;   1. Copy AdminSettings.sample to AdminSettings.php in the base folder. Edit the new file. The config file requires you to configure a database account for maintenance scripts. Presumably you may use the same account you used for the wiki, although I didn’t run any of the maintenance scripts yet to test this.&lt;br /&gt;   2. Edit LocalSettings.php. This file has been created for you by the installer, so it will contain some good defaults.&lt;br /&gt;&lt;br /&gt;LocalSettings.php is the primary configuration file of your new wiki. This file contains the actual basic settings for MediaWiki, and it overrides the defaults found in includes/DefaultSettings.php. You shouldn’t edit DefaultSettings.php directly, but it should be your first stop if you’re wondering what variables you can put in LocalSettings.php.&lt;br /&gt;Linking up the Help Pages&lt;br /&gt;&lt;br /&gt;By default MediaWiki ships without help pages. Unless you want to write them yourself you have a couple of options. The option I chose is to simply copy all Help sections from the primary MediaWiki site - they’re released into the public domain. Follow the instructions on Help:Copying to do this.&lt;br /&gt;&lt;br /&gt;You may wish to export the following pages:&lt;br /&gt;&lt;br /&gt;    Help:Contents&lt;br /&gt;    Help:Navigation&lt;br /&gt;    Help:Searching&lt;br /&gt;    Help:Tracking_changes&lt;br /&gt;    Help:Editing_pages&lt;br /&gt;    Help:Starting_a_new_page&lt;br /&gt;    Help:Formatting&lt;br /&gt;    Help:Links&lt;br /&gt;    Help:Categories&lt;br /&gt;    Help:Images&lt;br /&gt;    Help:Templates&lt;br /&gt;    Help:Tables&lt;br /&gt;    Help:Variables&lt;br /&gt;    Help:Managing_files&lt;br /&gt;    Help:Preferences&lt;br /&gt;    Help:Skins&lt;br /&gt;    Help:Namespaces&lt;br /&gt;    Help:Interwiki_linking&lt;br /&gt;    Help:Special pages&lt;br /&gt;    Template:PD_Help_Page&lt;br /&gt;    Template:Meta&lt;br /&gt;    Template:Admin_tip&lt;br /&gt;    Template:Prettytable&lt;br /&gt;    Template:Hl2&lt;br /&gt;    Template:Hl3&lt;br /&gt;    Template:Thankyou&lt;br /&gt;    Image:Example.jpg&lt;br /&gt;    Image:Geographylogo.png&lt;br /&gt;    Help:Editing&lt;br /&gt;    Image:PD-icon.svg&lt;br /&gt;&lt;br /&gt;This is the same list as found on the Help:Copying page at the time of this writing, with the addition of the two last entries.&lt;br /&gt;&lt;br /&gt;Notice that Template:Languages isn’t included in this list, although it is referenced from Template:PD_Help_Page. You may wish to edit the PD Help Page template and remove the {{Languages}} part towards the end to get rid of this dependency.&lt;br /&gt;&lt;br /&gt;You will have to download and upload the images separately by clicking them and finding their respective file downloads. Upload the images using the normal ‘Upload file’ link from your wiki. The .svg image probably won’t upload by default. We’ll tackle the SVG format later.&lt;br /&gt;Nice URLs&lt;br /&gt;&lt;br /&gt;At this point the installer script has probably given you URLs that look like,&lt;br /&gt;&lt;br /&gt;http://www.yourdomain.com/index.php/My_Page&lt;br /&gt;&lt;br /&gt;(Unless your PHP runs as a CGI script in which case things might even look worse. Don’t run as CGI.)&lt;br /&gt;&lt;br /&gt;To make your URLs more readable, you’ll need to configure both your web server and MediaWiki to cooperate. Here’s a good resource: Using a very short URL.&lt;br /&gt;&lt;br /&gt;Basically you will want to edit your httpd.conf, if you can do that, or an appropriate .htaccess file, if you have to. Remember that a .htaccess file is slower than httpd.conf. If you can use httpd.conf, do that and disable .htaccess support.&lt;br /&gt;&lt;br /&gt;Here’s how to set things up within Apache’s httpd.conf. Edit your Directory entry to resemble the following:&lt;br /&gt;&lt;br /&gt;&lt;Directory /www/mysite.com/&gt;&lt;br /&gt;        Options Includes FollowSymLinks&lt;br /&gt;&lt;br /&gt;        AllowOverride None&lt;br /&gt;&lt;br /&gt;        RewriteEngine On&lt;br /&gt;        RewriteCond %{REQUEST_FILENAME} !-f&lt;br /&gt;        RewriteCond %{REQUEST_FILENAME} !-d&lt;br /&gt;        RewriteRule ^(.+)$ /index.php?title=$1 [L,QSA]&lt;br /&gt;&lt;br /&gt;Notice the AllowOverride None line. This is the part that turns off .htaccess support. It’ll give you a bit of a speed boost since your web server won’t have to look for a .htaccess file for every request made.&lt;br /&gt;&lt;br /&gt;Next, add this line to LocalSettings.php:&lt;br /&gt;&lt;br /&gt;$wgArticlePath = "$wgScriptPath/$1";&lt;br /&gt;Change the Wiki Theme or Looks&lt;br /&gt;&lt;br /&gt;MediaWiki’s term for themes is ’skins’. The default skin looks exactly like Wikipedia, so you may want to change this if you’re looking to achieve a spiffy unique look for your public wiki.&lt;br /&gt;&lt;br /&gt;To find out what skins came with your MediaWiki installation, look in your skins/ folder. You will see something like,&lt;br /&gt;&lt;br /&gt;# ls skins&lt;br /&gt;Chick.deps.php          Nostalgia.php           common&lt;br /&gt;Chick.php               Simple.deps.php         disabled&lt;br /&gt;CologneBlue.php         Simple.php              htmldump&lt;br /&gt;MonoBook.deps.php       Skin.sample             monobook&lt;br /&gt;MonoBook.php            SkinPHPTal.sample       myskin&lt;br /&gt;MySkin.deps.php         Standard.php            simple&lt;br /&gt;MySkin.php              chick&lt;br /&gt;&lt;br /&gt;From this list you can infer the list of available skins. In this case it looks like we have Chick, CologneBlue, MonoBook, MySkin, Nostalgia, Simple and Standard. The folder names (the lower case names) are the skin names.&lt;br /&gt;&lt;br /&gt;To make the change, edit your LocalSettings.php file again and alter the line that reads,&lt;br /&gt;&lt;br /&gt;$wgDefaultSkin = ...&lt;br /&gt;&lt;br /&gt;In our case we might put,&lt;br /&gt;&lt;br /&gt;$wgDefaultSkin = 'cologneblue';&lt;br /&gt;&lt;br /&gt;If you make a mistake setting the property you will get a default skin.&lt;br /&gt;&lt;br /&gt;You can find more skins here. Each skin is accompanied by instructions for how to set it up. Normally this involves downloading a zip file and unzipping it into the skins/ folder. You may also have to edit theme files to set up proper paths.&lt;br /&gt;Changing User Access Levels&lt;br /&gt;&lt;br /&gt;If you want to disable anonymous editing, you can add something like the following to LocalSettings.php:&lt;br /&gt;&lt;br /&gt;$wgGroupPermissions['*'    ]['createaccount']   = true;&lt;br /&gt;$wgGroupPermissions['*'    ]['read']            = true;&lt;br /&gt;$wgGroupPermissions['*'    ]['edit']            = false;&lt;br /&gt;$wgGroupPermissions['*'    ]['createpage']      = false;&lt;br /&gt;$wgGroupPermissions['*'    ]['createtalk']      = true;&lt;br /&gt;&lt;br /&gt;For other possible settings, take a look at the defaults provided in includes/DefaultSettings.php. Again, remember not to edit the defaults file: just copy the lines you want to change to LocalSettings.php and make your changes there.&lt;br /&gt;Support for SVG images&lt;br /&gt;&lt;br /&gt;The SVG image file format is very useful but turned off by default in MediaWiki. Look in include/DefaultSettings.php and locate the SVG related stuff. For my installation this is what I had to add to LocalSettings.php:&lt;br /&gt;&lt;br /&gt;$wgSVGConverter = 'inkscape';&lt;br /&gt;$wgSVGConverterPath = '';&lt;br /&gt;$wgSVGMaxSize = 1024;&lt;br /&gt;$wgMaxImageArea = 1.25e7;&lt;br /&gt;$wgThumbnailEpoch = '20030516000000';&lt;br /&gt;$wgIgnoreImageErrors = false;&lt;br /&gt;$wgGenerateThumbnailOnParse = true;&lt;br /&gt;&lt;br /&gt;$wgFileExtensions = array( 'png', 'gif', 'jpg', 'jpeg', 'svg' );&lt;br /&gt;&lt;br /&gt;You will also need to install inkscape. There are options to use rsvg, ImageMagick and others instead but none of those options worked for me. Rsvg and ImageMagick didn’t render gradients right, and I was unable to install the other alternatives on FreeBSD without crashes or other problems. This is unfortunate because inkscape is positively enormous if you also consider all the pre-requirements that you normally wouldn’t have to install on a server. It is the one program that does things right though and SVG is a really nice format to have support for.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4903191105785361362-914651511958170387?l=sanjib-swain.blogspot.com' alt='' /&gt;&lt;/div&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/HGoh2WynSI25plIOySTXZGpJHDs/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/HGoh2WynSI25plIOySTXZGpJHDs/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/HGoh2WynSI25plIOySTXZGpJHDs/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/HGoh2WynSI25plIOySTXZGpJHDs/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/blogspot/PEHIt/~4/zjHn6tbKit8" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://sanjib-swain.blogspot.com/feeds/914651511958170387/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://www.blogger.com/comment.g?blogID=4903191105785361362&amp;postID=914651511958170387" title="1 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/4903191105785361362/posts/default/914651511958170387?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/4903191105785361362/posts/default/914651511958170387?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/blogspot/PEHIt/~3/zjHn6tbKit8/implemating-mediawiki.html" title="Implemating MEDIAWIKI" /><author><name>Sanjib Kumar Swain</name><uri>http://www.blogger.com/profile/11353921866017700402</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="32" height="24" src="http://3.bp.blogspot.com/_nnkYFjJnYR0/SjDB5r7-A4I/AAAAAAAAABg/5LvGBQSMBFM/S220/100_1083.JPG" /></author><thr:total>1</thr:total><feedburner:origLink>http://sanjib-swain.blogspot.com/2009/05/implemating-mediawiki.html</feedburner:origLink></entry><entry gd:etag="W/&quot;D0EGSX4yfSp7ImA9WxJREkQ.&quot;"><id>tag:blogger.com,1999:blog-4903191105785361362.post-5395936354973644383</id><published>2009-05-14T03:05:00.000-07:00</published><updated>2009-05-14T03:07:08.095-07:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2009-05-14T03:07:08.095-07:00</app:edited><title>Implementing the callback pattern in Java</title><content type="html">A callback in programming is executable code that is passed as an argument to other code. The higher-level code usually starts by calling a function within the lower-level function, passing to it a pointer, or handle to another function.&lt;br /&gt;&lt;br /&gt;When the lower-level function executes, it may call the passed-in function any number of times to perform a subtask. In another scenario, the lower-level function registers the passed-in function as a handler that is to be called asynchronously by the lower-level function later in reaction to something.&lt;br /&gt;&lt;br /&gt;Java’s object-oriented model does not currently support method pointers, and some developers may think that Java does not permit such a comfortable mechanism. Discover the main reasons why you may want to implement the callback pattern through interfaces in Java. I also discuss alternative ways of implementing the callback pattern.&lt;br /&gt;Why use callbacks at all?&lt;br /&gt;&lt;br /&gt;You can use a callback as a simpler alternative to polymorphism and generic programming, in that the exact behavior of a function can be dynamically determined by passing different (yet compatible) function pointers or handles to the lower-level function. This can be a very powerful technique for code reuse.&lt;br /&gt;&lt;br /&gt;To understand the motivation for using callbacks, consider the problem of performing an arbitrary operation on each item in a list. One approach is to iterate over the list, operating on each object. This is the most common solution in practice, but it is not ideal; the code to manage the iterator (for example, a for statement) must be duplicated at each point in the code where the list is traversed. Furthermore, if the list is updated by an asynchronous process (for example, if an item is added or removed), the iterator might skip over items or become corrupt during the traversal.&lt;br /&gt;&lt;br /&gt;An alternative might be to create a new library function that performs the desired operation with appropriate synchronization. This approach still requires each new library function to contain the code to traverse the list. This solution is not acceptable for generic libraries intended for various applications; the library developer cannot anticipate what every application will need, and the application developer should not need to know the details of the library implementation.&lt;br /&gt;&lt;br /&gt;Callbacks solve these shortcomings. One procedure is written to traverse the list, and this procedure uses application-provided code to operate on each item. There is a clear distinction between the library and the application without sacrificing flexibility. Callback has a totally different meaning in the context of security. For a secure login, you call the server and then it calls you back; this makes it harder for you to spoof being someone else.&lt;br /&gt;How to use callbacks in Java&lt;br /&gt;&lt;br /&gt;Java does not have procedure variables to implement function pointer callbacks the way C/C++ does. A callback would be used in C, for example, to pass a sin or cos function to a generic plotting program.&lt;br /&gt;&lt;br /&gt;There are four basic techniques to fake a callback function in Java. They include the following:&lt;br /&gt;&lt;br /&gt;    * Pass a callback delegate object that implements an interface for the callback method(s). This is how it is most commonly done.&lt;br /&gt;    * Subclassing. Subclass the calling class with an overridden callback method. Pass “this” as a parameter.&lt;br /&gt;    * Delegation via subclassing. Pass a subclassed callback delegate object that knows how to invoke the callback method(s).&lt;br /&gt;    * Use inner classes to define an anonymous callback class, instantiate an anonymous callback delegate object, and pass it as a parameter all in one line. This technique with EventListeners tends to muddle GUI and program logic, making your GUI code non-reusable. Unless the anonymous inner classes are simple, it is generally wiser to make them free-standing named classes.&lt;br /&gt;&lt;br /&gt;Here’s an example of how you can implement a callback using the first method. Java’s support of interfaces provides a mechanism by which you can get the equivalent of callbacks. The trick is to define a simple interface that declares the method you wish to be invoked. For example, suppose you want to receive notification when an event occurs. You can define an interface like this:&lt;br /&gt;&lt;br /&gt;Here is an example explain&lt;br /&gt;&lt;br /&gt;   1. interface Callable  &lt;br /&gt;   2. {  &lt;br /&gt;   3.     public void callBackMethod();  &lt;br /&gt;   4. }  &lt;br /&gt;   5. class Worker  &lt;br /&gt;   6. {  &lt;br /&gt;   7.     // Worker gets a handle to the boss object via the Callable interface.  &lt;br /&gt;   8.     // There's no way this worker class can call any other method other than  &lt;br /&gt;   9.     // the one in Callable.  &lt;br /&gt;  10.     public void doSomeWork(Callable myBoss)  &lt;br /&gt;  11.     {  &lt;br /&gt;  12.         myBoss.callBackMethod();  &lt;br /&gt;  13.         // ERROR!  &lt;br /&gt;  14.         //myBoss.directMethod();  &lt;br /&gt;  15.     }  &lt;br /&gt;  16. }  &lt;br /&gt;  17. class Boss implements Callable  &lt;br /&gt;  18. {  &lt;br /&gt;  19.     public Boss()  &lt;br /&gt;  20.     {  &lt;br /&gt;  21.         // Boss creates a worker object, and tells it to do some work.  &lt;br /&gt;  22.         Worker w1 = new Worker();  &lt;br /&gt;  23.         // Notice, we're passing a reference of the boss to the worker.  &lt;br /&gt;  24.         w1.doSomeWork(this);  &lt;br /&gt;  25.     }  &lt;br /&gt;  26.     public void callBackMethod()  &lt;br /&gt;  27.     {  &lt;br /&gt;  28.         System.out.println("What do you want?");  &lt;br /&gt;  29.     }  &lt;br /&gt;  30.     public void directMethod()  &lt;br /&gt;  31.     {  &lt;br /&gt;  32.         System.out.println("I'm out for coffee.");  &lt;br /&gt;  33.     }  &lt;br /&gt;  34. }  &lt;br /&gt;  35. public class CallBack  &lt;br /&gt;  36. {  &lt;br /&gt;  37.     // Main driver.  &lt;br /&gt;  38.     public static void main(String[] args)  &lt;br /&gt;  39.     {  &lt;br /&gt;  40.         Boss b = new Boss();  &lt;br /&gt;  41.         b.directMethod();  &lt;br /&gt;  42.     }  &lt;br /&gt;  43. }&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4903191105785361362-5395936354973644383?l=sanjib-swain.blogspot.com' alt='' /&gt;&lt;/div&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/pnhulZuZL3JYhajnNZBCSdMJXrE/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/pnhulZuZL3JYhajnNZBCSdMJXrE/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/pnhulZuZL3JYhajnNZBCSdMJXrE/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/pnhulZuZL3JYhajnNZBCSdMJXrE/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/blogspot/PEHIt/~4/Q8qzgPj95XY" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://sanjib-swain.blogspot.com/feeds/5395936354973644383/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://www.blogger.com/comment.g?blogID=4903191105785361362&amp;postID=5395936354973644383" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/4903191105785361362/posts/default/5395936354973644383?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/4903191105785361362/posts/default/5395936354973644383?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/blogspot/PEHIt/~3/Q8qzgPj95XY/implementing-callback-pattern-in-java.html" title="Implementing the callback pattern in Java" /><author><name>Sanjib Kumar Swain</name><uri>http://www.blogger.com/profile/11353921866017700402</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="32" height="24" src="http://3.bp.blogspot.com/_nnkYFjJnYR0/SjDB5r7-A4I/AAAAAAAAABg/5LvGBQSMBFM/S220/100_1083.JPG" /></author><thr:total>0</thr:total><feedburner:origLink>http://sanjib-swain.blogspot.com/2009/05/implementing-callback-pattern-in-java.html</feedburner:origLink></entry><entry gd:etag="W/&quot;CEQNRngyfCp7ImA9WxVaFk4.&quot;"><id>tag:blogger.com,1999:blog-4903191105785361362.post-5707871484727115129</id><published>2009-04-13T07:10:00.000-07:00</published><updated>2009-04-13T07:19:57.694-07:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2009-04-13T07:19:57.694-07:00</app:edited><title>Understanding User-Agent Strings</title><content type="html">&lt;h2&gt;&lt;a id="UnderstandUA"&gt;&lt;!----&gt;&lt;/a&gt;Understanding the User-Agent String&lt;/h2&gt;&lt;p&gt;When you request a Web page, your browser sends a number of headers to the server hosting the site that you are visiting. Each header contains details that help the server determine the best way to provide the information that you requested. The user-agent header identifies the application requesting the information from the server. The user-agent string can contain optional details called tokens, which must be enclosed in parentheses and vary among programs. Internet Explorer uses tokens to describe additional details about your computer system.&lt;/p&gt;&lt;p&gt;The following figure shows a sample user-agent string reported by Internet Explorer that highlights its tokens.&lt;/p&gt;&lt;p&gt;&lt;!--src=[../../../graphics/aboutuseragent_fig01.gif]--&gt;&lt;img alt="A typical Internet Explorer user-agent string." src="http://i.msdn.microsoft.com/ms537503.aboutuseragent_fig01%28en-us,VS.85%29.gif"&gt;&lt;/p&gt;&lt;p&gt;For historical reasons, Internet Explorer identifies itself as a Mozilla 4.0 browser.&lt;/p&gt;&lt;p&gt;The sample user-agent string contains three tokens.&lt;/p&gt;&lt;ol&gt;&lt;li&gt;&lt;p&gt;The Compatibility flag ("compatible") is used by most modern browsers. It indicates that Internet Explorer is compatible with a common set of features.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;The Version token identifies the browser and contains the version number. The version token in the example ("MSIE 7.0") identifies Internet Explorer 7.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;The Platform token identifies your operating system and contains the version number. The platform token in the example ("Windows NT 6.0") indicates Windows Vista.&lt;/p&gt;&lt;/li&gt;&lt;/ol&gt;&lt;p&gt;In the example, Internet Explorer is the user agent.  However, other programs also provide user-agent strings when contacting servers over the Internet. For example, the &lt;a id="ctl00_rs1_mainContentContainer_ctl02" onclick="javascript:Track('ctl00_rs1_mainContentContainer_ctl00|ctl00_rs1_mainContentContainer_ctl02',this);" href="http://msdn.microsoft.com/en-us/library/ms684701%28VS.85%29.aspx"&gt;Windows RSS Platform&lt;/a&gt; provides the following user-agent header when requesting RSS data.&lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;a id="ctl00_rs1_mainContentContainer_ctl02"  color="blue" onclick="javascript:Track('ctl00_rs1_mainContentContainer_ctl00|ctl00_rs1_mainContentContainer_ctl02',this);" href="http://msdn.microsoft.com/en-us/library/ms537503.aspx"&gt;MORE &gt;&gt; &lt;/a&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4903191105785361362-5707871484727115129?l=sanjib-swain.blogspot.com' alt='' /&gt;&lt;/div&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/_JEZ7segCZ2Ij1mABAHHEodrJbg/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/_JEZ7segCZ2Ij1mABAHHEodrJbg/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/_JEZ7segCZ2Ij1mABAHHEodrJbg/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/_JEZ7segCZ2Ij1mABAHHEodrJbg/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/blogspot/PEHIt/~4/dv8ba0eNhR0" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://sanjib-swain.blogspot.com/feeds/5707871484727115129/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://www.blogger.com/comment.g?blogID=4903191105785361362&amp;postID=5707871484727115129" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/4903191105785361362/posts/default/5707871484727115129?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/4903191105785361362/posts/default/5707871484727115129?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/blogspot/PEHIt/~3/dv8ba0eNhR0/understanding-user-agent-string-when.html" title="Understanding User-Agent Strings" /><author><name>Sanjib Kumar Swain</name><uri>http://www.blogger.com/profile/11353921866017700402</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="32" height="24" src="http://3.bp.blogspot.com/_nnkYFjJnYR0/SjDB5r7-A4I/AAAAAAAAABg/5LvGBQSMBFM/S220/100_1083.JPG" /></author><thr:total>0</thr:total><feedburner:origLink>http://sanjib-swain.blogspot.com/2009/04/understanding-user-agent-string-when.html</feedburner:origLink></entry><entry gd:etag="W/&quot;CEUBR3k6eSp7ImA9WxVbFEU.&quot;"><id>tag:blogger.com,1999:blog-4903191105785361362.post-7220101117083666298</id><published>2009-03-30T23:50:00.001-07:00</published><updated>2009-03-30T23:50:56.711-07:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2009-03-30T23:50:56.711-07:00</app:edited><title>The Nuts and Bolts of Credit Card Processing</title><content type="html">Consumers increasingly are turning to plastic over paper when they open their wallets. Credit and debit card spending exceeded $1 trillion in 1998, making it a necessary payment option for most businesses.&lt;br /&gt;&lt;br /&gt;Yet many small businesses still don't accept credit cards. If you're one of the laggards,&lt;br /&gt;the entire transaction may retain the aura of a mystic ritual — swipe a card, input some numbers, and money magically appears in the bank. In reality, though, credit card transactions involve coordination between multiple high-speed computer networks.&lt;br /&gt;&lt;br /&gt;How the Process Works&lt;br /&gt;&lt;br /&gt;When a merchant makes a sale and swipes a customer's credit card, the card number, the amount, and the merchant ID travel over the credit card processor's computer network. The credit card processor can either be a bank or a company that does nothing but provide credit card processing services.&lt;br /&gt;&lt;br /&gt;From the processor's network the transaction goes to a credit card computer network. If the customer is using Visa, for example, the transaction will go to Visa's network. In turn, the electronic transaction goes to the bank that actually issued the card. The bank then checks the account and verifies the customer has adequate credit to cover the purchase. The bank then sends the merchant an authorization over the network. Now the sale is complete, but the transaction is not — no money has changed hands yet.&lt;br /&gt;&lt;br /&gt;At the end of the business day, the merchant sends that day's charges, in a batch, to the credit card network for processing. The transactions travel via the merchant's credit card processor. Individual transactions are then stripped out and sent back to the individual cardholders' banks. Banks then debit cardholders' accounts and make appropriate payments to the merchant's credit card processor through the Federal Reserve Bank's Automated Clearing House.&lt;br /&gt;&lt;br /&gt;The credit card processor then credits the merchant's bank account for the transaction amount, minus its fees for the transaction. Those fees also go toward paying transaction fees to the issuing bank and the credit card network. Despite the use of computers, it can take two business days before the merchant's account is credited.&lt;br /&gt;&lt;br /&gt;Opening a Merchant Account&lt;br /&gt;&lt;br /&gt;In order to accept credit cards, you must open a merchant account with a bank. However, many banks have gotten out of the credit card processing business, and those that remain are often skittish about servicing small businesses, particularly ones with limited operating histories.&lt;br /&gt;&lt;br /&gt;Many small businesses must therefore go through a specialized credit card processor or an independent sales organization, commonly referred to as an "ISO." Whether you use a bank or a credit card processor, you need a merchant account to receive credit card payments.&lt;br /&gt;&lt;br /&gt;Though businesses can contact credit card processors directly, banks unable or unwilling to process credit transactions often refer customers to an ISO to help them find a credit card processor and get the necessary equipment and training to begin accepting credit cards.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4903191105785361362-7220101117083666298?l=sanjib-swain.blogspot.com' alt='' /&gt;&lt;/div&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/SvcVKFa9cZ1l6qiUWO930Dk_kvI/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/SvcVKFa9cZ1l6qiUWO930Dk_kvI/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/SvcVKFa9cZ1l6qiUWO930Dk_kvI/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/SvcVKFa9cZ1l6qiUWO930Dk_kvI/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/blogspot/PEHIt/~4/HCjBUvJc4MQ" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://sanjib-swain.blogspot.com/feeds/7220101117083666298/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://www.blogger.com/comment.g?blogID=4903191105785361362&amp;postID=7220101117083666298" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/4903191105785361362/posts/default/7220101117083666298?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/4903191105785361362/posts/default/7220101117083666298?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/blogspot/PEHIt/~3/HCjBUvJc4MQ/nuts-and-bolts-of-credit-card.html" title="The Nuts and Bolts of Credit Card Processing" /><author><name>Sanjib Kumar Swain</name><uri>http://www.blogger.com/profile/11353921866017700402</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="32" height="24" src="http://3.bp.blogspot.com/_nnkYFjJnYR0/SjDB5r7-A4I/AAAAAAAAABg/5LvGBQSMBFM/S220/100_1083.JPG" /></author><thr:total>0</thr:total><feedburner:origLink>http://sanjib-swain.blogspot.com/2009/03/nuts-and-bolts-of-credit-card.html</feedburner:origLink></entry><entry gd:etag="W/&quot;A0IASH05eCp7ImA9WxVUGUg.&quot;"><id>tag:blogger.com,1999:blog-4903191105785361362.post-6487553516025273719</id><published>2009-03-24T22:27:00.000-07:00</published><updated>2009-03-24T22:39:09.320-07:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2009-03-24T22:39:09.320-07:00</app:edited><title>What does “&gt; /dev/null 2&gt;&amp;1 in Unix  mean?</title><content type="html">I remember being confused for a very long time about the trailing garbage in commands I saw in Unix systems, especially while watching compilers do their work. Nobody I asked could tell me what the funny greater-thans, ampersands and numbers after the commands meant, and search engines never turned up anything but examples of it being used without explanation. In this article I’ll explain those weird commands.&lt;br /&gt;&lt;br /&gt;before explaining above let me begin from waht is ' /dev/null '&lt;br /&gt;&lt;br /&gt;/dev/null&lt;br /&gt;&lt;br /&gt;Definition: /dev/null: On UNIX, this is a virtual-file that can be written to. Data written to this file gets discarded. It is similar to the file call NUL on Windows machines. Key point: When rooting a machine, intruders will often redirect logging to /dev/null For example, the command ln -s /dev/null .bash_history will cause the system to stop logging bash commands. Culture: In the vernacular, means much the same thing as black hole. Typical usage: if you don't like what I have to say, please direct your comments to /dev/null.&lt;br /&gt;&lt;br /&gt;There is a special device know as /dev/null to which you can redirect unwanted output. This is a null (non-existent) device represented by the file null in the directory /dev .&lt;br /&gt;&lt;br /&gt;    * Example&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;To carry out a conditional action:&lt;br /&gt;&lt;br /&gt;   if who | grep -s keith &gt; /dev/null&lt;br /&gt;   then&lt;br /&gt;   echo keith is logged in&lt;br /&gt;   else&lt;br /&gt;   echo keith not available&lt;br /&gt;   fi&lt;br /&gt;&lt;br /&gt;This lists who is currently logged on to the sytem and pipes the output through grep to search for the username keith.&lt;br /&gt;&lt;br /&gt;The -s option causes grep to work silently and any error messages are directed to the file /dev/null instead of the standard output.&lt;br /&gt;&lt;br /&gt;If the command is succesful i.e. the username keith is found in the list of users currently logged in then the message&lt;br /&gt;&lt;br /&gt;   keith is logged on&lt;br /&gt;&lt;br /&gt;is displayed, otherwise the second message is displayed.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Here’s an example command:&lt;br /&gt;&lt;br /&gt;wibble &gt; /dev/null 2&gt;&amp;amp;1&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Output redirection&lt;br /&gt;&lt;br /&gt;The greater-thans (&gt;) in commands like these redirect the program’s output somewhere. In this case, something is being redirected into /dev/null, and something is being redirected into &amp;amp;1.&lt;br /&gt;Standard in, out, and error&lt;br /&gt;&lt;br /&gt;There are three standard sources of input and output for a program. Standard input usually comes from the keyboard if it’s an interactive program, or from another program if it’s processing the other program’s output. The program usually prints to standard output, and sometimes prints to standard error. These three file descriptors (you can think of them as “data pipes”) are often called STDIN, STDOUT, and STDERR.&lt;br /&gt;&lt;br /&gt;Sometimes they’re not named, they’re numbered! The built-in numberings for them are 0, 1, and 2, in that order. By default, if you don’t name or number one explicitly, you’re talking about STDOUT.&lt;br /&gt;&lt;br /&gt;Given that context, you can see the command above is redirecting standard output into /dev/null, which is a place you can dump anything you don’t want (often called the bit-bucket), then redirecting standard error into standard output (you have to put an &amp;amp; in front of the destination when you do this).&lt;br /&gt;&lt;br /&gt;The short explanation, therefore, is “all output from this command should be shoved into a black hole.” That’s one good way to make a program be really quiet!&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4903191105785361362-6487553516025273719?l=sanjib-swain.blogspot.com' alt='' /&gt;&lt;/div&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/5e4fEv0Vs8ZAScQNoVQwzFSeFF0/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/5e4fEv0Vs8ZAScQNoVQwzFSeFF0/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/5e4fEv0Vs8ZAScQNoVQwzFSeFF0/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/5e4fEv0Vs8ZAScQNoVQwzFSeFF0/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/blogspot/PEHIt/~4/X54XFh8EewM" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://sanjib-swain.blogspot.com/feeds/6487553516025273719/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://www.blogger.com/comment.g?blogID=4903191105785361362&amp;postID=6487553516025273719" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/4903191105785361362/posts/default/6487553516025273719?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/4903191105785361362/posts/default/6487553516025273719?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/blogspot/PEHIt/~3/X54XFh8EewM/what-does-devnull-2-in-unix-mean.html" title="What does “&gt; /dev/null 2&gt;&amp;1 in Unix  mean?" /><author><name>Sanjib Kumar Swain</name><uri>http://www.blogger.com/profile/11353921866017700402</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="32" height="24" src="http://3.bp.blogspot.com/_nnkYFjJnYR0/SjDB5r7-A4I/AAAAAAAAABg/5LvGBQSMBFM/S220/100_1083.JPG" /></author><thr:total>0</thr:total><feedburner:origLink>http://sanjib-swain.blogspot.com/2009/03/what-does-devnull-2-in-unix-mean.html</feedburner:origLink></entry><entry gd:etag="W/&quot;A0IFQng8fyp7ImA9WxRaFU0.&quot;"><id>tag:blogger.com,1999:blog-4903191105785361362.post-8066455673515238810</id><published>2008-12-17T02:23:00.000-08:00</published><updated>2008-12-17T02:25:13.677-08:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2008-12-17T02:25:13.677-08:00</app:edited><title>How can you Store and Forward</title><content type="html">&lt;div class="aContent"&gt;     &lt;p&gt;Store and forward is an application that some credit card terminals can run, that allows transactions to be taken without the terminal being connected to a phone line. The transactions are later processed when a connection is available.&lt;/p&gt; &lt;p&gt;Most wireless terminals have the ability to do store and forward, when there is no cellular coverage. But, there are also some land-line terminals that support store and forward. These terminals are a lot cheaper than wireless terminals, some having battery packs, making them moderately portable.&lt;/p&gt; &lt;p&gt;Store and forward on a land-line terminal can be a good solution for low volume mobile businesses, and can make a great backup for a wireless terminal. If you use a manual imprinter for your transactions, a store and forward battery operated terminal can be a good low cost step, without going to a wireless terminal.&lt;/p&gt; &lt;p&gt;&lt;strong&gt;What terminals work:&lt;/strong&gt;&lt;br /&gt;It’s not quite as simple as which terminals can support store and forward, because the correct terminal also has to be with the correct processing bank in order for the store and forward to be programmed correctly. Overall Lipman ‘Nurit’ terminals are the only ones that support store and forward. The wireless terminals (Nurit 3010, Nurit 8000) can be programmed with store and forward through at least Nova and FDMS, and the land-line terminals can potentially support store and forward at FDMS only.&lt;/p&gt; &lt;p&gt;As far as battery powered terminals go, there is the Nurit 2085U, the Nurit 3020U, and the Nurit 8320U, that have battery packs. These terminals are more difficult to obtain than the standard models, and will probably have to be special ordered, but are still much cheaper than wireless terminal.&lt;/p&gt; &lt;p&gt;Also, in the case of these terminals, you processor may charge extra to program these terminals with store and forward because the programming is almost always outsourced to the processing bank, who charges for it. Even if this normally wouldn’t be an issue, it is something to be aware of.&lt;/p&gt; &lt;p&gt;&lt;strong&gt;Store and forward isn’t perfect:&lt;/strong&gt;&lt;br /&gt;Store and forward creates an illusion that you are processing your customer’s cards just like normal, but this isn’t the case. No actual authorization is being made when using store and forward, so there is a chance that the card will decline when you finally go to run it. The second drawback is that if you don’t process the stored transactions quickly enough, they can all downgrade.&lt;/p&gt; &lt;p&gt;So, if you have an abnormally large transaction, or you have a bad feeling that the card may be no good, I recommend making a voice authorization before accepting the card. Businesses that get a lot of declined cards probably want to stay away from store and forward because all those declines will hurt your business and your time. Also, make sure to batch all of the transactions out of the terminal every day that you process to prevent downgrading.&lt;/p&gt;     &lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4903191105785361362-8066455673515238810?l=sanjib-swain.blogspot.com' alt='' /&gt;&lt;/div&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/meM6laagWKI02-_O2R3iTrc4X3M/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/meM6laagWKI02-_O2R3iTrc4X3M/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/meM6laagWKI02-_O2R3iTrc4X3M/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/meM6laagWKI02-_O2R3iTrc4X3M/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/blogspot/PEHIt/~4/OqMO4qNfgKo" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://sanjib-swain.blogspot.com/feeds/8066455673515238810/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://www.blogger.com/comment.g?blogID=4903191105785361362&amp;postID=8066455673515238810" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/4903191105785361362/posts/default/8066455673515238810?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/4903191105785361362/posts/default/8066455673515238810?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/blogspot/PEHIt/~3/OqMO4qNfgKo/how-can-you-store-and-forward.html" title="How can you Store and Forward" /><author><name>Sanjib Kumar Swain</name><uri>http://www.blogger.com/profile/11353921866017700402</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="32" height="24" src="http://3.bp.blogspot.com/_nnkYFjJnYR0/SjDB5r7-A4I/AAAAAAAAABg/5LvGBQSMBFM/S220/100_1083.JPG" /></author><thr:total>0</thr:total><feedburner:origLink>http://sanjib-swain.blogspot.com/2008/12/how-can-you-store-and-forward.html</feedburner:origLink></entry><entry gd:etag="W/&quot;DkEGQXk_fCp7ImA9WxRUFk8.&quot;"><id>tag:blogger.com,1999:blog-4903191105785361362.post-7076235868754340966</id><published>2008-11-25T06:49:00.000-08:00</published><updated>2008-11-25T06:50:20.744-08:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2008-11-25T06:50:20.744-08:00</app:edited><title>Why is Thread.stop deprecated?</title><content type="html">&lt;span class="Apple-style-span" style="border-collapse: separate; color: rgb(0, 0, 0); font-family: 'times new roman'; font-size: 16px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: 2; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px;"&gt;&lt;p&gt;Because it is inherently unsafe. Stopping a thread causes it to unlock all the monitors that it has locked. (The monitors are unlocked as the&lt;span class="Apple-converted-space"&gt; &lt;/span&gt;&lt;code&gt;ThreadDeath&lt;/code&gt;&lt;span class="Apple-converted-space"&gt; &lt;/span&gt;exception propagates up the stack.) If any of the objects previously protected by these monitors were in an inconsistent state, other threads may now view these objects in an inconsistent state. Such objects are said to be&lt;span class="Apple-converted-space"&gt; &lt;/span&gt;&lt;i&gt;damaged&lt;/i&gt;. When threads operate on damaged objects, arbitrary behavior can result. This behavior may be subtle and difficult to detect, or it may be pronounced. Unlike other unchecked exceptions,&lt;span class="Apple-converted-space"&gt; &lt;/span&gt;&lt;code&gt;ThreadDeath&lt;/code&gt;&lt;span class="Apple-converted-space"&gt; &lt;/span&gt;kills threads silently; thus, the user has no warning that his program may be corrupted. The corruption can manifest itself at any time after the actual damage occurs, even hours or days in the future.&lt;/p&gt;&lt;hr /&gt;&lt;h3&gt;Couldn't I just catch the&lt;span class="Apple-converted-space"&gt; &lt;/span&gt;&lt;code&gt;ThreadDeath&lt;/code&gt;&lt;span class="Apple-converted-space"&gt; &lt;/span&gt;exception and fix the damaged object?&lt;/h3&gt;&lt;p&gt;In theory, perhaps, but it would&lt;span class="Apple-converted-space"&gt; &lt;/span&gt;&lt;em&gt;vastly&lt;/em&gt;&lt;span class="Apple-converted-space"&gt; &lt;/span&gt;complicate the task of writing correct multithreaded code. The task would be nearly insurmountable for two reasons:&lt;/p&gt;&lt;ol&gt;&lt;li&gt;A thread can throw a&lt;span class="Apple-converted-space"&gt; &lt;/span&gt;&lt;code&gt;ThreadDeath&lt;/code&gt;&lt;span class="Apple-converted-space"&gt; &lt;/span&gt;exception&lt;span class="Apple-converted-space"&gt; &lt;/span&gt;&lt;i&gt;almost anywhere&lt;/i&gt;. All synchronized methods and blocks would have to be studied in great detail, with this in mind.&lt;/li&gt;&lt;li&gt;A thread can throw a second&lt;span class="Apple-converted-space"&gt; &lt;/span&gt;&lt;code&gt;ThreadDeath&lt;/code&gt;&lt;span class="Apple-converted-space"&gt; &lt;/span&gt;exception while cleaning up from the first (in the&lt;span class="Apple-converted-space"&gt; &lt;/span&gt;&lt;code&gt;catch&lt;/code&gt;&lt;span class="Apple-converted-space"&gt; &lt;/span&gt;or&lt;span class="Apple-converted-space"&gt; &lt;/span&gt;&lt;code&gt;finally&lt;/code&gt;&lt;span class="Apple-converted-space"&gt; &lt;/span&gt;clause). Cleanup would have to repeated till it succeeded. The code to ensure this would be quite complex.&lt;/li&gt;&lt;/ol&gt;In sum, it just isn't practical.&lt;hr /&gt;&lt;h3&gt;What about&lt;span class="Apple-converted-space"&gt; &lt;/span&gt;&lt;code&gt;Thread.stop(Throwable)&lt;/code&gt;?&lt;/h3&gt;&lt;p&gt;In addition to all of the problems noted above, this method may be used to generate exceptions that its target thread is unprepared to handle (including checked exceptions that the thread could not possibly throw, were it not for this method). For example, the following method is behaviorally identical to Java's&lt;span class="Apple-converted-space"&gt; &lt;/span&gt;&lt;code&gt;throw&lt;/code&gt;&lt;span class="Apple-converted-space"&gt; &lt;/span&gt;operation, but circumvents the compiler's attempts to guarantee that the calling method has declared all of the checked exceptions that it may throw:&lt;/p&gt;&lt;pre&gt;    static void sneakyThrow(Throwable t) {&lt;br /&gt;       Thread.currentThread().stop(t);&lt;br /&gt;   }&lt;br /&gt;&lt;/pre&gt;&lt;hr /&gt;&lt;h3&gt;What should I use instead of&lt;span class="Apple-converted-space"&gt; &lt;/span&gt;&lt;code&gt;Thread.stop&lt;/code&gt;?&lt;/h3&gt;&lt;p&gt;Most uses of&lt;span class="Apple-converted-space"&gt; &lt;/span&gt;&lt;code&gt;stop&lt;/code&gt;&lt;span class="Apple-converted-space"&gt; &lt;/span&gt;should be replaced by code that simply modifies some variable to indicate that the target thread should stop running. The target thread should check this variable regularly, and return from its run method in an orderly fashion if the variable indicates that it is to stop running. (This is the approach that JavaSoft's&lt;span class="Apple-converted-space"&gt; &lt;/span&gt;&lt;a href="/docs/books/tutorial/essential/TOC.html"&gt;Tutorial&lt;/a&gt;&lt;span class="Apple-converted-space"&gt; &lt;/span&gt;has always recommended.) To ensure prompt communication of the stop-request, the variable must be&lt;span class="Apple-converted-space"&gt; &lt;/span&gt;&lt;tt&gt;volatile&lt;/tt&gt;&lt;span class="Apple-converted-space"&gt; &lt;/span&gt;(or access to the variable must be synchronized).&lt;/p&gt;&lt;p&gt;For example, suppose your applet contains the following&lt;span class="Apple-converted-space"&gt; &lt;/span&gt;&lt;code&gt;start&lt;/code&gt;,&lt;span class="Apple-converted-space"&gt; &lt;/span&gt;&lt;code&gt;stop&lt;/code&gt;&lt;span class="Apple-converted-space"&gt; &lt;/span&gt;and&lt;span class="Apple-converted-space"&gt; &lt;/span&gt;&lt;code&gt;run&lt;/code&gt;&lt;span class="Apple-converted-space"&gt; &lt;/span&gt;methods:&lt;/p&gt;&lt;pre&gt;    private Thread blinker;&lt;br /&gt;&lt;br /&gt;   public void start() {&lt;br /&gt;       blinker = new Thread(this);&lt;br /&gt;       blinker.start();&lt;br /&gt;   }&lt;br /&gt;&lt;br /&gt;   public void stop() {&lt;br /&gt;       blinker.stop();  // UNSAFE!&lt;br /&gt;   }&lt;br /&gt;&lt;br /&gt;   public void run() {&lt;br /&gt;       Thread thisThread = Thread.currentThread();&lt;br /&gt;       while (true) {&lt;br /&gt;           try {&lt;br /&gt;               thisThread.sleep(interval);&lt;br /&gt;           } catch (InterruptedException e){&lt;br /&gt;           }&lt;br /&gt;           repaint();&lt;br /&gt;       }&lt;br /&gt;   }&lt;br /&gt;&lt;/pre&gt;You can avoid the use of&lt;span class="Apple-converted-space"&gt; &lt;/span&gt;&lt;code&gt;Thread.stop&lt;/code&gt;&lt;span class="Apple-converted-space"&gt; &lt;/span&gt;by replacing the applet's&lt;span class="Apple-converted-space"&gt; &lt;/span&gt;&lt;code&gt;stop&lt;/code&gt;&lt;span class="Apple-converted-space"&gt; &lt;/span&gt;and&lt;span class="Apple-converted-space"&gt; &lt;/span&gt;&lt;code&gt;run&lt;/code&gt;&lt;span class="Apple-converted-space"&gt; &lt;/span&gt;methods with:&lt;pre&gt;    private volatile Thread blinker;&lt;br /&gt;&lt;br /&gt;   public void stop() {&lt;br /&gt;       blinker = null;&lt;br /&gt;   }&lt;br /&gt;&lt;br /&gt;   public void run() {&lt;br /&gt;       Thread thisThread = Thread.currentThread();&lt;br /&gt;       while (blinker == thisThread) {&lt;br /&gt;           try {&lt;br /&gt;               thisThread.sleep(interval);&lt;br /&gt;           } catch (InterruptedException e){&lt;br /&gt;           }&lt;br /&gt;           repaint();&lt;br /&gt;       }&lt;br /&gt;   }&lt;br /&gt;&lt;/pre&gt;&lt;hr /&gt;&lt;h3&gt;How do I stop a thread that waits for long periods (e.g., for input)?&lt;/h3&gt;&lt;p&gt;That's what the&lt;span class="Apple-converted-space"&gt; &lt;/span&gt;&lt;code&gt;Thread.interrupt&lt;/code&gt;&lt;span class="Apple-converted-space"&gt; &lt;/span&gt;method is for. The same "state based" signaling mechanism shown above can be used, but the state change (&lt;code&gt;blinker = null&lt;/code&gt;, in the previous example) can be followed by a call to&lt;span class="Apple-converted-space"&gt; &lt;/span&gt;&lt;code&gt;Thread.interrupt&lt;/code&gt;, to interrupt the wait:&lt;/p&gt;&lt;pre&gt;    public void stop() {&lt;br /&gt;       Thread moribund = waiter;&lt;br /&gt;       waiter = null;&lt;br /&gt;       moribund.interrupt();&lt;br /&gt;   }&lt;br /&gt;&lt;/pre&gt;For this technique to work, it's critical that any method that catches an interrupt exception and is not prepared to deal with it immediately reasserts the exception. We say&lt;span class="Apple-converted-space"&gt; &lt;/span&gt;&lt;em&gt;reasserts&lt;/em&gt;&lt;span class="Apple-converted-space"&gt; &lt;/span&gt;rather than&lt;span class="Apple-converted-space"&gt; &lt;/span&gt;&lt;em&gt;rethrows&lt;/em&gt;, because it is not always possible to rethrow the exception. If the method that catches the&lt;span class="Apple-converted-space"&gt; &lt;/span&gt;&lt;code&gt;InterruptedException&lt;/code&gt;&lt;span class="Apple-converted-space"&gt; &lt;/span&gt;is not declared to throw this (checked) exception, then it should "reinterrupt itself" with the following incantation:&lt;pre&gt;    Thread.currentThread().interrupt();&lt;br /&gt;&lt;/pre&gt;This ensures that the Thread will reraise the&lt;span class="Apple-converted-space"&gt; &lt;/span&gt;&lt;code&gt;InterruptedException&lt;/code&gt;&lt;span class="Apple-converted-space"&gt; &lt;/span&gt;as soon as it is able.&lt;hr /&gt;&lt;h3&gt;What if a thread doesn't respond to&lt;span class="Apple-converted-space"&gt; &lt;/span&gt;&lt;code&gt;Thread.interrupt&lt;/code&gt;?&lt;/h3&gt;&lt;p&gt;In some cases, you can use application specific tricks. For example, if a thread is waiting on a known socket, you can close the socket to cause the thread to return immediately. Unfortunately, there really isn't any technique that works in general.&lt;span class="Apple-converted-space"&gt; &lt;/span&gt;&lt;em&gt;It should be noted that in all situations where a waiting thread doesn't respond to&lt;span class="Apple-converted-space"&gt; &lt;/span&gt;&lt;code&gt;Thread.interrupt&lt;/code&gt;, it wouldn't respond to&lt;span class="Apple-converted-space"&gt; &lt;/span&gt;&lt;code&gt;Thread.stop&lt;/code&gt;&lt;span class="Apple-converted-space"&gt; &lt;/span&gt;either.&lt;/em&gt;&lt;span class="Apple-converted-space"&gt; &lt;/span&gt;Such cases include deliberate denial-of-service attacks, and I/O operations for which thread.stop and thread.interrupt do not work properly.&lt;/p&gt;&lt;hr /&gt;&lt;h3&gt;Why are&lt;span class="Apple-converted-space"&gt; &lt;/span&gt;&lt;code&gt;Thread.suspend&lt;/code&gt;&lt;span class="Apple-converted-space"&gt; &lt;/span&gt;and&lt;span class="Apple-converted-space"&gt; &lt;/span&gt;&lt;code&gt;Thread.resume&lt;/code&gt;&lt;span class="Apple-converted-space"&gt; &lt;/span&gt;deprecated?&lt;/h3&gt;&lt;p&gt;&lt;code&gt;Thread.suspend&lt;/code&gt;&lt;span class="Apple-converted-space"&gt; &lt;/span&gt;is inherently deadlock-prone. If the target thread holds a lock on the monitor protecting a critical system resource when it is suspended, no thread can access this resource until the target thread is resumed. If the thread that would resume the target thread attempts to lock this monitor prior to calling&lt;span class="Apple-converted-space"&gt; &lt;/span&gt;&lt;code&gt;resume&lt;/code&gt;, deadlock results. Such deadlocks typically manifest themselves as "frozen" processes.&lt;/p&gt;&lt;hr /&gt;&lt;h3&gt;What should I use instead of&lt;span class="Apple-converted-space"&gt; &lt;/span&gt;&lt;code&gt;Thread.suspend&lt;/code&gt;&lt;span class="Apple-converted-space"&gt; &lt;/span&gt;and&lt;span class="Apple-converted-space"&gt; &lt;/span&gt;&lt;code&gt;Thread.resume&lt;/code&gt;?&lt;/h3&gt;&lt;p&gt;As with&lt;span class="Apple-converted-space"&gt; &lt;/span&gt;&lt;code&gt;Thread.stop&lt;/code&gt;, the prudent approach is to have the "target thread" poll a variable indicating the desired state of the thread (active or suspended). When the desired state is suspended, the thread waits using&lt;span class="Apple-converted-space"&gt; &lt;/span&gt;&lt;code&gt;Object.wait&lt;/code&gt;. When the thread is resumed, the target thread is notified using&lt;span class="Apple-converted-space"&gt; &lt;/span&gt;&lt;code&gt;Object.notify&lt;/code&gt;.&lt;/p&gt;&lt;p&gt;For example, suppose your applet contains the following mousePressed event handler, which toggles the state of a thread called&lt;span class="Apple-converted-space"&gt; &lt;/span&gt;&lt;code&gt;blinker&lt;/code&gt;:&lt;/p&gt;&lt;pre&gt;    private boolean threadSuspended;&lt;br /&gt;&lt;br /&gt;   Public void mousePressed(MouseEvent e) {&lt;br /&gt;       e.consume();&lt;br /&gt;&lt;br /&gt;       if (threadSuspended)&lt;br /&gt;           blinker.resume();&lt;br /&gt;       else&lt;br /&gt;           blinker.suspend();  // DEADLOCK-PRONE!&lt;br /&gt;&lt;br /&gt;       threadSuspended = !threadSuspended;&lt;br /&gt;   }&lt;br /&gt;&lt;/pre&gt;You can avoid the use of&lt;span class="Apple-converted-space"&gt; &lt;/span&gt;&lt;code&gt;Thread.suspend&lt;/code&gt;&lt;span class="Apple-converted-space"&gt; &lt;/span&gt;and&lt;span class="Apple-converted-space"&gt; &lt;/span&gt;&lt;code&gt;Thread.resume&lt;/code&gt;&lt;span class="Apple-converted-space"&gt; &lt;/span&gt;by replacing the event handler above with:&lt;pre&gt;    public synchronized void mousePressed(MouseEvent e) {&lt;br /&gt;       e.consume();&lt;br /&gt;&lt;br /&gt;       threadSuspended = !threadSuspended;&lt;br /&gt;&lt;br /&gt;       if (!threadSuspended)&lt;br /&gt;           notify();&lt;br /&gt;   }&lt;br /&gt;&lt;/pre&gt;and adding the following code to the "run loop":&lt;pre&gt;                synchronized(this) {&lt;br /&gt;                   while (threadSuspended)&lt;br /&gt;                       wait();&lt;br /&gt;               }&lt;br /&gt;&lt;/pre&gt;The&lt;span class="Apple-converted-space"&gt; &lt;/span&gt;&lt;code&gt;wait&lt;/code&gt;&lt;span class="Apple-converted-space"&gt; &lt;/span&gt;method throws the&lt;span class="Apple-converted-space"&gt; &lt;/span&gt;&lt;code&gt;InterruptedException&lt;/code&gt;, so it must be inside a&lt;span class="Apple-converted-space"&gt; &lt;/span&gt;&lt;code&gt;try ... catch&lt;/code&gt;&lt;span class="Apple-converted-space"&gt; &lt;/span&gt;clause. It's fine to put it in the same clause as the&lt;span class="Apple-converted-space"&gt; &lt;/span&gt;&lt;code&gt;sleep&lt;/code&gt;. The check should follow (rather than precede) the&lt;code&gt;sleep&lt;/code&gt;&lt;span class="Apple-converted-space"&gt; &lt;/span&gt;so the window is immediately repainted when the the thread is "resumed." The resulting&lt;span class="Apple-converted-space"&gt; &lt;/span&gt;&lt;code&gt;run&lt;/code&gt;&lt;span class="Apple-converted-space"&gt; &lt;/span&gt;method follows:&lt;pre&gt;    public void run() {&lt;br /&gt;       while (true) {&lt;br /&gt;           try {&lt;br /&gt;               Thread.currentThread().sleep(interval);&lt;br /&gt;&lt;br /&gt;               synchronized(this) {&lt;br /&gt;                   while (threadSuspended)&lt;br /&gt;                       wait();&lt;br /&gt;               }&lt;br /&gt;           } catch (InterruptedException e){&lt;br /&gt;           }&lt;br /&gt;           repaint();&lt;br /&gt;       }&lt;br /&gt;   }&lt;br /&gt;&lt;/pre&gt;Note that the&lt;span class="Apple-converted-space"&gt; &lt;/span&gt;&lt;code&gt;notify&lt;/code&gt;&lt;span class="Apple-converted-space"&gt; &lt;/span&gt;in the&lt;span class="Apple-converted-space"&gt; &lt;/span&gt;&lt;code&gt;mousePressed&lt;/code&gt;&lt;span class="Apple-converted-space"&gt; &lt;/span&gt;method and the&lt;span class="Apple-converted-space"&gt; &lt;/span&gt;&lt;code&gt;wait&lt;/code&gt;&lt;span class="Apple-converted-space"&gt; &lt;/span&gt;in the&lt;span class="Apple-converted-space"&gt; &lt;/span&gt;&lt;code&gt;run&lt;/code&gt;&lt;span class="Apple-converted-space"&gt; &lt;/span&gt;method are inside&lt;span class="Apple-converted-space"&gt; &lt;/span&gt;&lt;code&gt;synchronized&lt;/code&gt;&lt;span class="Apple-converted-space"&gt; &lt;/span&gt;blocks. This is required by the language, and ensures that&lt;span class="Apple-converted-space"&gt; &lt;/span&gt;&lt;code&gt;wait&lt;/code&gt;&lt;span class="Apple-converted-space"&gt; &lt;/span&gt;and&lt;span class="Apple-converted-space"&gt; &lt;/span&gt;&lt;code&gt;notify&lt;/code&gt;&lt;span class="Apple-converted-space"&gt; &lt;/span&gt;are properly serialized. In practical terms, this eliminates race conditions that could cause the "suspended" thread to miss a&lt;span class="Apple-converted-space"&gt; &lt;/span&gt;&lt;code&gt;notify&lt;/code&gt;&lt;span class="Apple-converted-space"&gt; &lt;/span&gt;and remain suspended indefinitely.&lt;p&gt;While the cost of synchronization in Java is decreasing as the platform matures, it will never be free. A simple trick can be used to remove the synchronization that we've added to each iteration of the "run loop." The synchronized block that was added is replaced by a slightly more complex piece of code that enters a synchronized block only if the thread has actually been suspended:&lt;/p&gt;&lt;pre&gt;                if (threadSuspended) {&lt;br /&gt;                   synchronized(this) {&lt;br /&gt;                       while (threadSuspended)&lt;br /&gt;                           wait();&lt;br /&gt;                   }&lt;br /&gt;               }&lt;br /&gt;&lt;/pre&gt;&lt;p&gt;In the absence of explicit synchronization,&lt;span class="Apple-converted-space"&gt; &lt;/span&gt;&lt;tt&gt;threadSuspended&lt;/tt&gt;&lt;span class="Apple-converted-space"&gt; &lt;/span&gt;must be made&lt;span class="Apple-converted-space"&gt; &lt;/span&gt;&lt;tt&gt;volatile&lt;/tt&gt;&lt;span class="Apple-converted-space"&gt; &lt;/span&gt;to ensure prompt communication of the suspend-request.&lt;/p&gt;The resulting&lt;span class="Apple-converted-space"&gt; &lt;/span&gt;&lt;code&gt;run&lt;/code&gt;&lt;span class="Apple-converted-space"&gt; &lt;/span&gt;method is:&lt;pre&gt;    private boolean volatile threadSuspended;&lt;br /&gt;&lt;br /&gt;   public void run() {&lt;br /&gt;       while (true) {&lt;br /&gt;           try {&lt;br /&gt;               Thread.currentThread().sleep(interval);&lt;br /&gt;&lt;br /&gt;               if (threadSuspended) {&lt;br /&gt;                   synchronized(this) {&lt;br /&gt;                       while (threadSuspended)&lt;br /&gt;                           wait();&lt;br /&gt;                   }&lt;br /&gt;               }&lt;br /&gt;           } catch (InterruptedException e){&lt;br /&gt;           }&lt;br /&gt;           repaint();&lt;br /&gt;       }&lt;br /&gt;   }&lt;br /&gt;&lt;/pre&gt;&lt;hr size="3" noshade="noshade"&gt;&lt;h3&gt;Can I combine the two techniques to produce a thread that may be safely "stopped" or "suspended"?&lt;/h3&gt;Yes; it's reasonably straightforward. The one subtlety is that the target thread may already be suspended at the time that another thread tries to stop it. If the&lt;span class="Apple-converted-space"&gt; &lt;/span&gt;&lt;tt&gt;stop&lt;/tt&gt;&lt;span class="Apple-converted-space"&gt; &lt;/span&gt;method merely sets the state variable (&lt;tt&gt;blinker&lt;/tt&gt;) to null, the target thread will remain suspended (waiting on the monitor), rather than exiting gracefully as it should. If the applet is restarted, multiple threads could end up waiting on the monitor at the same time, resulting in erratic behavior.&lt;p&gt;To rectify this situation, the&lt;span class="Apple-converted-space"&gt; &lt;/span&gt;&lt;tt&gt;stop&lt;/tt&gt;&lt;span class="Apple-converted-space"&gt; &lt;/span&gt;method must ensure that the target thread resumes immediately if it is suspended. Once the target thread resumes, it must recognize immediately that it has been stopped, and exit gracefully. Here's how the resulting&lt;span class="Apple-converted-space"&gt; &lt;/span&gt;&lt;tt&gt;run&lt;/tt&gt;&lt;span class="Apple-converted-space"&gt; &lt;/span&gt;and&lt;span class="Apple-converted-space"&gt; &lt;/span&gt;&lt;tt&gt;stop&lt;/tt&gt;&lt;span class="Apple-converted-space"&gt; &lt;/span&gt;methods look:&lt;/p&gt;&lt;pre&gt;    public void run() {&lt;br /&gt;       Thread thisThread = Thread.currentThread();&lt;br /&gt;       while (blinker == thisThread) {&lt;br /&gt;           try {&lt;br /&gt;               thisThread.sleep(interval);&lt;br /&gt;&lt;br /&gt;               synchronized(this) {&lt;br /&gt;                   while (threadSuspended &amp;amp;&amp;amp; blinker==thisThread)&lt;br /&gt;                       wait();&lt;br /&gt;               }&lt;br /&gt;           } catch (InterruptedException e){&lt;br /&gt;           }&lt;br /&gt;           repaint();&lt;br /&gt;       }&lt;br /&gt;   }&lt;br /&gt;&lt;br /&gt;   public synchronized void stop() {&lt;br /&gt;       blinker = null;&lt;br /&gt;       notify();&lt;br /&gt;   }&lt;br /&gt;&lt;/pre&gt;If the&lt;span class="Apple-converted-space"&gt; &lt;/span&gt;&lt;tt&gt;stop&lt;/tt&gt;&lt;span class="Apple-converted-space"&gt; &lt;/span&gt;method calls&lt;span class="Apple-converted-space"&gt; &lt;/span&gt;&lt;tt&gt;Thread.interrupt&lt;/tt&gt;, as described above, it needn't call&lt;span class="Apple-converted-space"&gt; &lt;/span&gt;&lt;tt&gt;notify&lt;/tt&gt;&lt;span class="Apple-converted-space"&gt; &lt;/span&gt;as well, but it still must be synchronized. This ensures that the target thread won't miss an interrupt due to a race condition.&lt;hr /&gt;&lt;h3&gt;What about&lt;span class="Apple-converted-space"&gt; &lt;/span&gt;&lt;code&gt;Thread.destroy&lt;/code&gt;?&lt;/h3&gt;&lt;code&gt;Thread.destroy&lt;/code&gt;&lt;span class="Apple-converted-space"&gt; &lt;/span&gt;has never been implemented. If it were implemented, it would be deadlock-prone in the manner of&lt;span class="Apple-converted-space"&gt; &lt;/span&gt;&lt;code&gt;Thread.suspend&lt;/code&gt;. (In fact, it is roughly equivalent to&lt;span class="Apple-converted-space"&gt; &lt;/span&gt;&lt;code&gt;Thread.suspend&lt;/code&gt;&lt;span class="Apple-converted-space"&gt; &lt;/span&gt;without the possibility of a subsequent&lt;span class="Apple-converted-space"&gt; &lt;/span&gt;&lt;code&gt;Thread.resume&lt;/code&gt;.) We are not implementing it at this time, but neither are we deprecating it (forestalling its implementation in future). While it would certainly be deadlock prone, it has been argued that there may be circumstances where a program is willing to risk a deadlock rather than exit outright.&lt;hr /&gt;&lt;h3&gt;Why is&lt;span class="Apple-converted-space"&gt; &lt;/span&gt;&lt;code&gt;Runtime.runFinalizersOnExit&lt;/code&gt;&lt;span class="Apple-converted-space"&gt; &lt;/span&gt;deprecated?&lt;/h3&gt;Because it is inherently unsafe. It may result in finalizers being called on live objects while other threads are concurrently manipulating those objects, resulting in erratic behavior or deadlock. While this problem could be prevented if the class whose objects are being finalized were coded to "defend against" this call, most programmers do&lt;span class="Apple-converted-space"&gt; &lt;/span&gt;&lt;i&gt;not&lt;/i&gt;&lt;span class="Apple-converted-space"&gt; &lt;/span&gt;defend against it. They assume that an object is dead at the time that its finalizer is called.&lt;p&gt;Further, the call is not "thread-safe" in the sense that it sets a VM-global flag. This forces&lt;span class="Apple-converted-space"&gt; &lt;/span&gt;&lt;i&gt;every&lt;/i&gt;&lt;span class="Apple-converted-space"&gt; &lt;/span&gt;class with a finalizer to defend against the finalization of live objects!&lt;/p&gt;&lt;/span&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4903191105785361362-7076235868754340966?l=sanjib-swain.blogspot.com' alt='' /&gt;&lt;/div&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/xFHvvRTj8GuIDCU-01ZY2CweSDA/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/xFHvvRTj8GuIDCU-01ZY2CweSDA/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/xFHvvRTj8GuIDCU-01ZY2CweSDA/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/xFHvvRTj8GuIDCU-01ZY2CweSDA/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/blogspot/PEHIt/~4/NQ83E1w7r2w" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://sanjib-swain.blogspot.com/feeds/7076235868754340966/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://www.blogger.com/comment.g?blogID=4903191105785361362&amp;postID=7076235868754340966" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/4903191105785361362/posts/default/7076235868754340966?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/4903191105785361362/posts/default/7076235868754340966?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/blogspot/PEHIt/~3/NQ83E1w7r2w/why-is-threadstop-deprecated.html" title="Why is Thread.stop deprecated?" /><author><name>Sanjib Kumar Swain</name><uri>http://www.blogger.com/profile/11353921866017700402</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="32" height="24" src="http://3.bp.blogspot.com/_nnkYFjJnYR0/SjDB5r7-A4I/AAAAAAAAABg/5LvGBQSMBFM/S220/100_1083.JPG" /></author><thr:total>0</thr:total><feedburner:origLink>http://sanjib-swain.blogspot.com/2008/11/why-is-threadstop-deprecated.html</feedburner:origLink></entry><entry gd:etag="W/&quot;CEEDQ3s7cCp7ImA9WxRRF0o.&quot;"><id>tag:blogger.com,1999:blog-4903191105785361362.post-8441910166540236998</id><published>2008-09-30T03:42:00.000-07:00</published><updated>2008-09-30T04:04:32.508-07:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2008-09-30T04:04:32.508-07:00</app:edited><title>Apache Tomcat - Restrict Access By IP</title><content type="html">&lt;p&gt;Normally I do not do IP based restrictions in applications I build since they almost universally need to be accessed from anywhere on the Internet. The few times I have given it much thought I pretty much settled on letting the Apache rewrite manage it and let it go at that. I am highly Apache Rewrite Dependent but that’s another story for another day.&lt;/p&gt; &lt;p&gt;Recently however I was tasked with building a small XML-RPC gateway for a friend. This gateway was in front some fairly sensitive workflow for a specific customer of his and thus would have a limited subset of static IP addresses connecting to it. The app itself was simple and I wanted to keep it that way, no database, straight-through XML-RPC gateway to a back-end service and, for simplicity, no Apache2 in the loop. No Apache2, no Restrict By IP(!), at least in my simple thinking.&lt;/p&gt; &lt;p&gt;Amazingly enough, after reading the docs, I discovered that Tomcat has the ability to restrict based on IP built in. Probably common knowledge to most Tomcat developers but in my Google Searches I never came across an answer for it so I thought I’d post it here for future Google Visitors since most of known civilization searches with Google before reading the Tomcat docs. &lt;/p&gt; &lt;p&gt;Basically Tomcat implements Allow/Deny IP lists as a Valve called a ‘RemoteAddrValve’ that intercepts requests. &lt;/p&gt; &lt;p&gt;&lt;code&gt;Valve className="org.apache.catalina.valves.RemoteAddrValve"&lt;br /&gt;         allow="127.0.0.1|localhost|10.0.1.123" deny=""/&gt;&lt;/code&gt;&lt;/p&gt; &lt;p&gt;Add this to your virtualhost in server.xml and you will instantly allow only access to the IP’s listed in the allow directive. Add IP’s to the deny directive to specifically deny them. I don’t know who wins a tie, let me know if you have a chance to experiment with it.&lt;/p&gt; &lt;p&gt;This has been invaluable for this particular app. Its not robust enough for apps of a much larger scale (allowed/denied client wise) but for this app its Just Right and so I post it for future generations. I imagine you could easily subclass this valve and create a JDBC backed Remote IP store. Hmm, maybe a project for another day..&lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4903191105785361362-8441910166540236998?l=sanjib-swain.blogspot.com' alt='' /&gt;&lt;/div&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/yvqRK78keGBXD7Hf7CrJqVbjrV4/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/yvqRK78keGBXD7Hf7CrJqVbjrV4/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/yvqRK78keGBXD7Hf7CrJqVbjrV4/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/yvqRK78keGBXD7Hf7CrJqVbjrV4/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/blogspot/PEHIt/~4/eaDkrzz9OUo" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://sanjib-swain.blogspot.com/feeds/8441910166540236998/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://www.blogger.com/comment.g?blogID=4903191105785361362&amp;postID=8441910166540236998" title="2 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/4903191105785361362/posts/default/8441910166540236998?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/4903191105785361362/posts/default/8441910166540236998?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/blogspot/PEHIt/~3/eaDkrzz9OUo/apache-tomcat-restrict-access-by-ip.html" title="Apache Tomcat - Restrict Access By IP" /><author><name>Sanjib Kumar Swain</name><uri>http://www.blogger.com/profile/11353921866017700402</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="32" height="24" src="http://3.bp.blogspot.com/_nnkYFjJnYR0/SjDB5r7-A4I/AAAAAAAAABg/5LvGBQSMBFM/S220/100_1083.JPG" /></author><thr:total>2</thr:total><feedburner:origLink>http://sanjib-swain.blogspot.com/2008/09/apache-tomcat-restrict-access-by-ip.html</feedburner:origLink></entry><entry gd:etag="W/&quot;Dk4AQHgzcCp7ImA9WxRRF0g.&quot;"><id>tag:blogger.com,1999:blog-4903191105785361362.post-4184526174412100644</id><published>2008-09-29T23:07:00.000-07:00</published><updated>2008-09-29T23:09:01.688-07:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2008-09-29T23:09:01.688-07:00</app:edited><title>Apache restrict access based on IP address to selected directories</title><content type="html">&lt;p&gt;Apache web server allows server access based upon various conditions. For example you just want to restrict access to url http://payroll.nixcraft.in/ (mapped to /var/www/sub/payroll directory) from 192.168.1.0/24 network (within intranet).&lt;/p&gt; &lt;p&gt;Apache provides access control based on client hostname, IP address, or other characteristics of the client request using mod_access module.&lt;/p&gt; &lt;p&gt;Open your httpd.conf file:&lt;br /&gt;&lt;code&gt;# vi /etc/httpd/conf/httpd.conf&lt;/code&gt;Locate directory section (for example/var/www/sub/payroll) and set it as follows:&lt;code&gt;&lt;br /&gt;&lt;directory&gt;&lt;br /&gt;          Order allow,deny&lt;br /&gt;          Allow from 192.168.1.0/24&lt;br /&gt;          Allow from 127&lt;br /&gt;&lt;/directory&gt;&lt;/code&gt;Where,&lt;/p&gt; &lt;ul&gt;&lt;li&gt;Order allow,deny: The Order directive controls the default access state and the order in which Allow and Deny directives are evaluated. The (allow,deny) Allow directives are evaluated before the Deny directives. Access is denied by default. Any client which does not match an Allow directive or does match a Deny directive will be denied access to the server.&lt;/li&gt;&lt;li&gt;Allow from192.168.1.0/24: The Allow directive affects which hosts can access an area of the server (i.e. /var/www/sub/payroll/). Access is only allowed from network 192.168.1.0/24 and localhost (127.0.0.1).&lt;/li&gt;&lt;/ul&gt; &lt;p&gt;Save file and restart apache web server:&lt;br /&gt;&lt;code&gt;# /etc/init.d/httpd restart&lt;/code&gt;&lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4903191105785361362-4184526174412100644?l=sanjib-swain.blogspot.com' alt='' /&gt;&lt;/div&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/sNzoXyNVTVkJgpRdK_ykFnVuzwE/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/sNzoXyNVTVkJgpRdK_ykFnVuzwE/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/sNzoXyNVTVkJgpRdK_ykFnVuzwE/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/sNzoXyNVTVkJgpRdK_ykFnVuzwE/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/blogspot/PEHIt/~4/uHelXjQxdDE" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://sanjib-swain.blogspot.com/feeds/4184526174412100644/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://www.blogger.com/comment.g?blogID=4903191105785361362&amp;postID=4184526174412100644" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/4903191105785361362/posts/default/4184526174412100644?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/4903191105785361362/posts/default/4184526174412100644?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/blogspot/PEHIt/~3/uHelXjQxdDE/apache-restrict-access-based-on-ip.html" title="Apache restrict access based on IP address to selected directories" /><author><name>Sanjib Kumar Swain</name><uri>http://www.blogger.com/profile/11353921866017700402</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="32" height="24" src="http://3.bp.blogspot.com/_nnkYFjJnYR0/SjDB5r7-A4I/AAAAAAAAABg/5LvGBQSMBFM/S220/100_1083.JPG" /></author><thr:total>0</thr:total><feedburner:origLink>http://sanjib-swain.blogspot.com/2008/09/apache-restrict-access-based-on-ip.html</feedburner:origLink></entry><entry gd:etag="W/&quot;CE4NQnY4cSp7ImA9WxRbGE0.&quot;"><id>tag:blogger.com,1999:blog-4903191105785361362.post-876595074539411667</id><published>2008-07-24T03:52:00.000-07:00</published><updated>2008-12-08T22:09:53.839-08:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2008-12-08T22:09:53.839-08:00</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="java" /><category scheme="http://www.blogger.com/atom/ns#" term="eclipse" /><title>Eclipse Short cuts</title><content type="html">&lt;h3&gt;&lt;br /&gt;&lt;/h3&gt;&lt;br /&gt;You should try to keep your hands on keyboard. The less you touch the mouse, the more code you can write. I am trying to keep the mouse laying still and control the IDE completely using keyboard. What do you think is faster: pressing &lt;span style="font-style: italic;"&gt;ALT + C&lt;/span&gt; or right clicking the project, selecting &lt;span style="font-style: italic;"&gt;Team -&gt; Commit&lt;/span&gt;?&lt;br /&gt;&lt;p&gt;It is said, that if a function does not have a key binding, it is useless. Below you will find a set of essential keyboard shortcuts that I love. These shortcuts are set up by default, they should all work.&lt;br /&gt;&lt;/p&gt;&lt;dl&gt;&lt;dt&gt;&lt;span style="font-weight: bold;"&gt;CTRL + D&lt;/span&gt;&lt;/dt&gt;&lt;br /&gt;&lt;dd&gt;Delete row. Try it! You no more need to grab the mouse and select the line, no more Home, Shift + End, Delete. Quick and clean.&lt;/dd&gt;&lt;br /&gt;&lt;dt&gt;&lt;span style="font-weight: bold;"&gt;ALT + Up/Down Arrow&lt;/span&gt;&lt;/dt&gt;&lt;br /&gt;&lt;dd&gt;Move the row (or the entire selection) up or down. Very useful when rearranging code. You can even select more rows and move them all. Notice, that it will be always correctly indented.&lt;/dd&gt;&lt;dt&gt;&lt;br /&gt;&lt;/dt&gt;&lt;dt&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://4.bp.blogspot.com/_GFNxMeHpbcw/R7bIJuAFphI/AAAAAAAAAJg/sBbK3i86bgU/s1600-h/alt-arrow.png"&gt;&lt;img style="margin: 0px auto 10px; display: block; text-align: center; cursor: pointer;" src="http://4.bp.blogspot.com/_GFNxMeHpbcw/R7bIJuAFphI/AAAAAAAAAJg/sBbK3i86bgU/s400/alt-arrow.png" alt="" id="BLOGGER_PHOTO_ID_5167537691747001874" border="0" /&gt;&lt;/a&gt;&lt;/dt&gt;&lt;br /&gt;&lt;dt&gt;&lt;span style="font-weight: bold;"&gt;ALT + Left/Right Arrow&lt;/span&gt;&lt;/dt&gt;&lt;br /&gt;&lt;dd&gt;Move to the last location you edited. Imagine you just created a class Foo, and now you are working on a class Boo. Now, if you need to look at the Foo class, just press Alt+Left Arrow. Alt+Right Arrow brings you back to Boo.&lt;/dd&gt;&lt;br /&gt;&lt;dt&gt;&lt;span style="font-weight: bold;"&gt;CTRL+SHIFT+O&lt;/span&gt;&lt;/dt&gt;&lt;br /&gt;&lt;dd&gt;Organize imports. What happens when you first use a class you have not yet imported? You will see an error. But when you press this magical combination, all your missing classes will be imported, and the unused imports will vanish.&lt;/dd&gt;&lt;br /&gt;&lt;dt&gt;&lt;span style="font-weight: bold;"&gt;CTRL+1&lt;/span&gt;&lt;/dt&gt;&lt;br /&gt;&lt;dd&gt;Probably the most useful one. It activates the quick fix. Imagine you create a class, which implements some interface. You will get an error, because the inherited methods are not yet implemented. While you are on line where the error occurs, press this combination to activate the quick fix. Now, select the "Add unimplemented methods" option. You can use the quick fix at every error you ever receive.&lt;br /&gt;&lt;br /&gt;Quick fix comes handy in other situations too. My favorite is the "Split variable declaration". Sometimes I need to broaden the scope of a variable. I activate the quick fix, split declaration, and use alt + arrow to put it where it belongs. You can find even more usages: Convert local variable to field, rename in file, Inline local variable..&lt;br /&gt;&lt;br /&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://2.bp.blogspot.com/_GFNxMeHpbcw/RxUAZm2okoI/AAAAAAAAAFI/FEDfs4d2mGE/s1600-h/quickfix.png"&gt;&lt;img style="cursor: pointer;" src="http://2.bp.blogspot.com/_GFNxMeHpbcw/RxUAZm2okoI/AAAAAAAAAFI/FEDfs4d2mGE/s400/quickfix.png" alt="" id="BLOGGER_PHOTO_ID_5122000591130235522" border="0" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;span style="font-size: 78%;"&gt;You could use the "Split variable declaration" on the bar variable, and then move it with Alt+Arrows above the try block..&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://3.bp.blogspot.com/_GFNxMeHpbcw/RxUAq22okpI/AAAAAAAAAFQ/umsmSUHU80s/s1600-h/quickfix2.png"&gt;&lt;img style="cursor: pointer;" src="http://3.bp.blogspot.com/_GFNxMeHpbcw/RxUAq22okpI/AAAAAAAAAFQ/umsmSUHU80s/s400/quickfix2.png" alt="" id="BLOGGER_PHOTO_ID_5122000887482978962" border="0" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;span style="font-size: 78%;"&gt;Or you could use the "Add unimplemented methods" fix here.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;The best thing you can do if you see an error is to use the quick fix.&lt;br /&gt;&lt;/dd&gt;&lt;br /&gt;&lt;dt&gt;&lt;span style="font-weight: bold;"&gt;CTRL+SHIFT+T&lt;/span&gt;&lt;/dt&gt;&lt;br /&gt;&lt;dd&gt;Open Type. Imagine, that you need to have a look at the Foo class. But, where is the Foo class? Is it in the Boo project and in the foo.bar package? Or somewhere else? With this shortcut, you don't need to know. Just press it, type Foo and you are in.&lt;/dd&gt;&lt;dt&gt;&lt;br /&gt;&lt;/dt&gt;&lt;dt&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://2.bp.blogspot.com/_GFNxMeHpbcw/R7bIbOAFpiI/AAAAAAAAAJo/Yhj4X5xVHHw/s1600-h/open-type.png"&gt;&lt;img style="margin: 0px auto 10px; display: block; text-align: center; cursor: pointer;" src="http://2.bp.blogspot.com/_GFNxMeHpbcw/R7bIbOAFpiI/AAAAAAAAAJo/Yhj4X5xVHHw/s400/open-type.png" alt="" id="BLOGGER_PHOTO_ID_5167537992394712610" border="0" /&gt;&lt;/a&gt;&lt;/dt&gt;&lt;br /&gt;&lt;dt&gt;&lt;span style="font-weight: bold;"&gt;CTRL+E&lt;/span&gt;&lt;/dt&gt;&lt;br /&gt;&lt;dd&gt;Shows you a list of all open editors.&lt;/dd&gt;&lt;dd&gt;&lt;br /&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://1.bp.blogspot.com/_GFNxMeHpbcw/RxUBOW2okqI/AAAAAAAAAFY/TqPXyZ_7btA/s1600-h/ctrl-e.png"&gt;&lt;img style="cursor: pointer;" src="http://1.bp.blogspot.com/_GFNxMeHpbcw/RxUBOW2okqI/AAAAAAAAAFY/TqPXyZ_7btA/s400/ctrl-e.png" alt="" id="BLOGGER_PHOTO_ID_5122001497368335010" border="0" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;/dd&gt;&lt;br /&gt;&lt;dt&gt;&lt;span style="font-weight: bold;"&gt;CTRL+F6&lt;/span&gt;&lt;/dt&gt;&lt;br /&gt;&lt;dd&gt;Use to move between open editors. This is an slower alternative to Ctrl + E. Comes handy in a situation when you want to periodically switch between two editors, something, what is nearly impossible with Ctrl+E as it sorts entries quite randomly. Or you might just use Alt+Arrows..&lt;/dd&gt;&lt;br /&gt;&lt;dt&gt;&lt;span style="font-weight: bold;"&gt;CTRL+F7&lt;/span&gt;&lt;/dt&gt;&lt;br /&gt;&lt;dd&gt;Move between views. When in editor, press Ctrl+F7 to switch to the Package Explorer, or hold Ctrl and press F7 multiple times to switch to other views.&lt;/dd&gt;&lt;dt&gt;&lt;br /&gt;&lt;/dt&gt;&lt;dt&gt;&lt;span style="font-weight: bold;"&gt;CTRL+F8&lt;/span&gt;&lt;/dt&gt;&lt;dd&gt;&lt;br /&gt;&lt;/dd&gt;&lt;dd&gt;Move between perspectives. The same as previous.&lt;/dd&gt;&lt;dt&gt;&lt;br /&gt;&lt;/dt&gt;&lt;dt&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://2.bp.blogspot.com/_GFNxMeHpbcw/R7bIuOAFpjI/AAAAAAAAAJw/GGQOLb7k7wg/s1600-h/switching-trio.png"&gt;&lt;img style="margin: 0px auto 10px; display: block; text-align: center; cursor: pointer;" src="http://2.bp.blogspot.com/_GFNxMeHpbcw/R7bIuOAFpjI/AAAAAAAAAJw/GGQOLb7k7wg/s400/switching-trio.png" alt="" id="BLOGGER_PHOTO_ID_5167538318812227122" border="0" /&gt;&lt;/a&gt;&lt;/dt&gt;&lt;dt&gt;&lt;span style="font-weight: bold;"&gt;CTRL + F11&lt;/span&gt;&lt;/dt&gt;&lt;br /&gt;&lt;dd&gt;Runs the application. What gets launched depends on your settings. It will either launch the last launched class (my preffered way) or it will launch currently selected resource (the default way). If you want to change its behavior read the previous post.&lt;/dd&gt;&lt;br /&gt;&lt;dt&gt;&lt;span style="font-weight: bold;"&gt;CTL + N&lt;/span&gt;&lt;/dt&gt;&lt;br /&gt;&lt;dd&gt;Open new type wizard. This is not very quick because you have to select the wizard type (weather you want to create new class, jsp, xml or something else) in the next step. Much faster way would be if you could just hit the shortcut and invoke the particular wizard. It is possible, just keep reading..&lt;/dd&gt;&lt;br /&gt;&lt;dt&gt;&lt;span style="font-weight: bold;"&gt;CTRL + M&lt;/span&gt;&lt;/dt&gt;&lt;br /&gt;&lt;dd&gt;Maximize or umaximize current tab.&lt;/dd&gt;&lt;br /&gt;&lt;dt&gt;&lt;span style="font-weight: bold;"&gt;CTRL + I&lt;/span&gt;&lt;/dt&gt;&lt;br /&gt;&lt;dd&gt;Corrects indentation.&lt;/dd&gt;&lt;br /&gt;&lt;dt&gt;&lt;span style="font-weight: bold;"&gt;CTRL + SHIFT + F&lt;/span&gt;&lt;/dt&gt;&lt;br /&gt;&lt;dd&gt;Formats code. You can make a beautiful looking code out of a mess with this. It requires a bit of setup, but it is well worth it. You can find its settings under Window-&gt;Preferences-&gt;Java-&gt;Code style-&gt;Formatter&lt;/dd&gt;&lt;br /&gt;&lt;dt&gt;&lt;span style="font-weight: bold;"&gt;CTRL + J&lt;/span&gt;&lt;/dt&gt;&lt;br /&gt;&lt;dd&gt;Incremental search. Similar to the search in firefox. It shows you results as you type. Don't be surprised, if you hit this combination, nothing happens - at the first glance. Just start typing and eclipse will move your cursor to the first ocurence.&lt;/dd&gt;&lt;br /&gt;&lt;dt&gt;&lt;span style="font-weight: bold;"&gt;CTRL + SHIFT + L&lt;/span&gt;&lt;/dt&gt;&lt;br /&gt;&lt;dd&gt;Shows you a list of your currently defined shortcut keys.&lt;/dd&gt;&lt;/dl&gt;&lt;h3&gt;I don't like your shortcuts&lt;/h3&gt;Such is life nowadays. Remember, you can always change those bindings to match your preferences. Open Windows-&gt;Preferences-&gt;General-&gt;Keys. Now you can use the filter to find your shortcut and change its binding.&lt;br /&gt;&lt;p&gt;The real fun begins when you cannot find the command you are looking for. The key here, is to have the "Include unbounds commands" checkbox checked. It will show you all commands, even those, which have no keys bound.&lt;br /&gt;&lt;br /&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://1.bp.blogspot.com/_GFNxMeHpbcw/RxUBzW2oksI/AAAAAAAAAFo/qFEt6n3Y8V0/s1600-h/key-binding.png"&gt;&lt;img style="cursor: pointer;" src="http://1.bp.blogspot.com/_GFNxMeHpbcw/RxUBzW2oksI/AAAAAAAAAFo/qFEt6n3Y8V0/s400/key-binding.png" alt="" id="BLOGGER_PHOTO_ID_5122002133023494850" border="0" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;While you are here, I recommend to add the following bindings:&lt;br /&gt;&lt;/p&gt;&lt;dl&gt;&lt;dt&gt;&lt;span style="font-weight: bold;"&gt;CTRL+SHIFT+G&lt;/span&gt;&lt;/dt&gt;&lt;br /&gt;&lt;dd&gt;Bind this to "Generate getters and setters". This is a "must have".&lt;/dd&gt;&lt;br /&gt;&lt;dt&gt;&lt;span style="font-weight: bold;"&gt;ALT+C&lt;/span&gt;&lt;/dt&gt;&lt;br /&gt;&lt;dd&gt;Bind this to SVN/CVS "Commit".&lt;/dd&gt;&lt;br /&gt;&lt;dt&gt;&lt;span style="font-weight: bold;"&gt;ALT+U&lt;/span&gt;&lt;/dt&gt;&lt;br /&gt;&lt;dd&gt;Bind this to SVN/CVS "Update".&lt;/dd&gt;&lt;/dl&gt;Now, type "new" (without quotes) in the filter text. You should see a list of all new type wizards. Choose the most frequently used and assign them a shortcut. For example, the most used wizard for me is the new class wizard. Thus I assigned it the &lt;span style="font-style: italic;"&gt;CTRL+SHIFT+N&lt;/span&gt; keys.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Let me demonstrate a quick way to create new class now.&lt;br /&gt;&lt;br /&gt;Hit &lt;span style="font-style: italic;"&gt;CTRL + SHIFT + N&lt;/span&gt; (or the combination you assigned in the previous step). This should bring up new class wizard. Type in the name and press &lt;span style="font-style: italic;"&gt;ALT+E&lt;/span&gt;. You can now select a class which will be a superclass for the newly created class. Hit &lt;span style="font-style: italic;"&gt;ALT+A&lt;/span&gt; and select all implemented interfaces . Now hit ALT+F and your class will be generated. Eclipse will also provide the default implementation for all abstract and interface methods you inherited.&lt;br /&gt;&lt;p&gt;Did you notice the weird underscores everywhere in the dialog? They give you a hint about the shortcut key. Hit &lt;span style="font-style: italic;"&gt;ALT&lt;/span&gt; and the underlined letter to press the button, check the checkbox or get focus for a textfield.&lt;br /&gt;&lt;br /&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://3.bp.blogspot.com/_GFNxMeHpbcw/RxUBg22okrI/AAAAAAAAAFg/5K2bopJ-6_Q/s1600-h/newtype.png"&gt;&lt;img style="cursor: pointer;" src="http://3.bp.blogspot.com/_GFNxMeHpbcw/RxUBg22okrI/AAAAAAAAAFg/5K2bopJ-6_Q/s400/newtype.png" alt="" id="BLOGGER_PHOTO_ID_5122001815195914930" border="0" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;/p&gt;&lt;p&gt;&lt;span style="font-size: 78%;"&gt;Did you notice the underscores?&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;I think that using shortcut keys is the fastest way to productivity and if not, then at least your wrists will say you a silent thanks. Now, don't wait, go on and assign keys to the features you use most.&lt;/p&gt;&lt;p&gt;One final tip from Andriy:&lt;/p&gt;&lt;blockquote&gt;The problem is that there are so many keyboard shortcuts. I used to keep a printout with all the shortcuts I wanted to use. Finally I wrote an Eclipse plugin &lt;a rel="nofollow" href="http://www.mousefeed.com/"&gt;MouseFeed&lt;/a&gt;, which reminds the keyboard shortcuts for the actions called with mouse. You can even tell it to enforce some shortcuts - the action will run only if called with a keyboard shortcut.&lt;br /&gt;&lt;/blockquote&gt;&lt;p&gt;So if you are struggling with yourself, if you want to use shortcuts, but always subconsciously touch the mouse, install the plugin and let it enforce the shortcuts - the mouse will be useless and you will be forced to use keyboard.&lt;/p&gt;&lt;p&gt;What shortcuts do you use? &lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4903191105785361362-876595074539411667?l=sanjib-swain.blogspot.com' alt='' /&gt;&lt;/div&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/IaCicP9_TVbh9ytO8952mL3qrkM/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/IaCicP9_TVbh9ytO8952mL3qrkM/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/IaCicP9_TVbh9ytO8952mL3qrkM/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/IaCicP9_TVbh9ytO8952mL3qrkM/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/blogspot/PEHIt/~4/1g0_cNfEsRg" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://sanjib-swain.blogspot.com/feeds/876595074539411667/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://www.blogger.com/comment.g?blogID=4903191105785361362&amp;postID=876595074539411667" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/4903191105785361362/posts/default/876595074539411667?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/4903191105785361362/posts/default/876595074539411667?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/blogspot/PEHIt/~3/1g0_cNfEsRg/eclipse-short-cuts.html" title="Eclipse Short cuts" /><author><name>Sanjib Kumar Swain</name><uri>http://www.blogger.com/profile/11353921866017700402</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="32" height="24" src="http://3.bp.blogspot.com/_nnkYFjJnYR0/SjDB5r7-A4I/AAAAAAAAABg/5LvGBQSMBFM/S220/100_1083.JPG" /></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="http://4.bp.blogspot.com/_GFNxMeHpbcw/R7bIJuAFphI/AAAAAAAAAJg/sBbK3i86bgU/s72-c/alt-arrow.png" height="72" width="72" /><thr:total>0</thr:total><feedburner:origLink>http://sanjib-swain.blogspot.com/2008/07/eclipse-short-cuts.html</feedburner:origLink></entry></feed>

