tag:blogger.com,1999:blog-6159731487157322922024-03-26T23:38:10.582-07:00java explorerjavaexplor03http://www.blogger.com/profile/07455293496498711738noreply@blogger.comBlogger477125tag:blogger.com,1999:blog-615973148715732292.post-7866047376094582472017-07-17T00:01:00.001-07:002017-07-17T00:01:24.034-07:00Java | Reverse a String without using String class function<div dir="ltr" style="text-align: left;" trbidi="on">
<div>
<br /></div>
<div>
<div style="background: #DBE5F1; border: solid windowtext 1.0pt; mso-background-themecolor: accent1; mso-background-themetint: 51; mso-border-alt: solid windowtext .5pt; mso-element: para-border-div; padding: 1.0pt 4.0pt 1.0pt 4.0pt;">
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="color: #7f0055; font-family: Consolas; font-size: 12.0pt; mso-bidi-font-weight: bold;">package</span><span style="font-family: Consolas; font-size: 12pt;"> com.java.tricks;</span><span style="font-family: Consolas; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="color: #7f0055; font-family: Consolas; font-size: 12.0pt; mso-bidi-font-weight: bold;">import</span><span style="font-family: Consolas; font-size: 12pt;"> java.lang.reflect.Field;</span><span style="font-family: Consolas; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="color: #7f0055; font-family: Consolas; font-size: 12.0pt; mso-bidi-font-weight: bold;">public</span><span style="font-family: Consolas; font-size: 12pt;"> </span><span style="color: #7f0055; font-family: Consolas; font-size: 12.0pt; mso-bidi-font-weight: bold;">class</span><span style="font-family: Consolas; font-size: 12pt;"> ReverseString {</span><span style="font-family: Consolas; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<br /></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: Consolas; font-size: 12pt;"> </span><span style="color: #3f5fbf; font-family: Consolas; font-size: 12.0pt;">/**</span><span style="font-family: Consolas; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="color: #3f5fbf; font-family: Consolas; font-size: 12.0pt;"> * This method is used to reverse string without using any string class method.</span><span style="font-family: Consolas; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="color: #3f5fbf; font-family: Consolas; font-size: 12.0pt;"> */</span><span style="font-family: Consolas; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: Consolas; font-size: 12pt;"> </span><span style="color: #7f0055; font-family: Consolas; font-size: 12.0pt; mso-bidi-font-weight: bold;">private</span><span style="font-family: Consolas; font-size: 12pt;"> </span><span style="color: #7f0055; font-family: Consolas; font-size: 12.0pt; mso-bidi-font-weight: bold;">static</span><span style="font-family: Consolas; font-size: 12pt;"> </span><span style="color: #7f0055; font-family: Consolas; font-size: 12.0pt; mso-bidi-font-weight: bold;">void</span><span style="font-family: Consolas; font-size: 12pt;"> reverseString(String </span><span style="color: #6a3e3e; font-family: Consolas; font-size: 12.0pt;">value</span><span style="font-family: Consolas; font-size: 12pt;">) {</span><span style="font-family: Consolas; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: Consolas; font-size: 12pt;"> </span><span style="color: #7f0055; font-family: Consolas; font-size: 12.0pt; mso-bidi-font-weight: bold;">try</span><span style="font-family: Consolas; font-size: 12pt;"> {</span><span style="font-family: Consolas; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: Consolas; font-size: 12pt;"> </span><span style="font-family: Consolas; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: Consolas; font-size: 12pt;"> </span><span style="color: #3f5fbf; font-family: Consolas; font-size: 12.0pt;">/** to access the private value[] array of String class. */</span><span style="font-family: Consolas; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: Consolas; font-size: 12pt;"> Field </span><span style="color: #6a3e3e; font-family: Consolas; font-size: 12.0pt;">field</span><span style="font-family: Consolas; font-size: 12pt;"> = String.</span><span style="color: #7f0055; font-family: Consolas; font-size: 12.0pt; mso-bidi-font-weight: bold;">class</span><span style="font-family: Consolas; font-size: 12pt;">.getDeclaredField(</span><span style="color: #2a00ff; font-family: Consolas; font-size: 12.0pt;">"value"</span><span style="font-family: Consolas; font-size: 12pt;">);</span><span style="font-family: Consolas; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<br /></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: Consolas; font-size: 12pt;"> </span><span style="color: #3f5fbf; font-family: Consolas; font-size: 12.0pt;">/** Grant the access to access the field value. */</span><span style="font-family: Consolas; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: Consolas; font-size: 12pt;"> </span><span style="color: #6a3e3e; font-family: Consolas; font-size: 12.0pt;">field</span><span style="font-family: Consolas; font-size: 12pt;">.setAccessible(</span><span style="color: #7f0055; font-family: Consolas; font-size: 12.0pt; mso-bidi-font-weight: bold;">true</span><span style="font-family: Consolas; font-size: 12pt;">);</span><span style="font-family: Consolas; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<br /></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: Consolas; font-size: 12pt;"> </span><span style="color: #3f5fbf; font-family: Consolas; font-size: 12.0pt;">/** Access the value array from the String class. */</span><span style="font-family: Consolas; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: Consolas; font-size: 12pt;"> </span><span style="color: #7f0055; font-family: Consolas; font-size: 12.0pt; mso-bidi-font-weight: bold;">char</span><span style="font-family: Consolas; font-size: 12pt;">[] </span><span style="color: #6a3e3e; font-family: Consolas; font-size: 12.0pt;">array</span><span style="font-family: Consolas; font-size: 12pt;"> = (</span><span style="color: #7f0055; font-family: Consolas; font-size: 12.0pt; mso-bidi-font-weight: bold;">char</span><span style="font-family: Consolas; font-size: 12pt;">[]) </span><span style="color: #6a3e3e; font-family: Consolas; font-size: 12.0pt;">field</span><span style="font-family: Consolas; font-size: 12pt;">.get(</span><span style="color: #6a3e3e; font-family: Consolas; font-size: 12.0pt;">value</span><span style="font-family: Consolas; font-size: 12pt;">);</span><span style="font-family: Consolas; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: Consolas; font-size: 12pt;"> </span><span style="color: #7f0055; font-family: Consolas; font-size: 12.0pt; mso-bidi-font-weight: bold;">int</span><span style="font-family: Consolas; font-size: 12pt;"> </span><span style="color: #6a3e3e; font-family: Consolas; font-size: 12.0pt;">i</span><span style="font-family: Consolas; font-size: 12pt;"> = 0; </span><span style="color: #7f0055; font-family: Consolas; font-size: 12.0pt; mso-bidi-font-weight: bold;">int</span><span style="font-family: Consolas; font-size: 12pt;"> </span><span style="color: #6a3e3e; font-family: Consolas; font-size: 12.0pt;">j</span><span style="font-family: Consolas; font-size: 12pt;"> = </span><span style="color: #6a3e3e; font-family: Consolas; font-size: 12.0pt;">array</span><span style="font-family: Consolas; font-size: 12pt;">.</span><span style="color: #0000c0; font-family: Consolas; font-size: 12.0pt;">length</span><span style="font-family: Consolas; font-size: 12pt;">-1;</span><span style="font-family: Consolas; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<br /></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: Consolas; font-size: 12pt;"> </span><span style="color: #3f5fbf; font-family: Consolas; font-size: 12.0pt;">/** Reverse the array values to reverse it. */</span><span style="font-family: Consolas; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: Consolas; font-size: 12pt;"> </span><span style="color: #7f0055; font-family: Consolas; font-size: 12.0pt; mso-bidi-font-weight: bold;">while</span><span style="font-family: Consolas; font-size: 12pt;">(</span><span style="color: #6a3e3e; font-family: Consolas; font-size: 12.0pt;">i</span><span style="font-family: Consolas; font-size: 12pt;"><</span><span style="color: #6a3e3e; font-family: Consolas; font-size: 12.0pt;">j</span><span style="font-family: Consolas; font-size: 12pt;">) {</span><span style="font-family: Consolas; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: Consolas; font-size: 12pt;"> </span><span style="color: #7f0055; font-family: Consolas; font-size: 12.0pt; mso-bidi-font-weight: bold;">char</span><span style="font-family: Consolas; font-size: 12pt;"> </span><span style="color: #6a3e3e; font-family: Consolas; font-size: 12.0pt;">temp</span><span style="font-family: Consolas; font-size: 12pt;"> = </span><span style="color: #6a3e3e; font-family: Consolas; font-size: 12.0pt;">array</span><span style="font-family: Consolas; font-size: 12pt;">[</span><span style="color: #6a3e3e; font-family: Consolas; font-size: 12.0pt;">i</span><span style="font-family: Consolas; font-size: 12pt;">];</span><span style="font-family: Consolas; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: Consolas; font-size: 12pt;"> </span><span style="color: #6a3e3e; font-family: Consolas; font-size: 12.0pt;">array</span><span style="font-family: Consolas; font-size: 12pt;">[</span><span style="color: #6a3e3e; font-family: Consolas; font-size: 12.0pt;">i</span><span style="font-family: Consolas; font-size: 12pt;">] = </span><span style="color: #6a3e3e; font-family: Consolas; font-size: 12.0pt;">array</span><span style="font-family: Consolas; font-size: 12pt;">[</span><span style="color: #6a3e3e; font-family: Consolas; font-size: 12.0pt;">j</span><span style="font-family: Consolas; font-size: 12pt;">];</span><span style="font-family: Consolas; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: Consolas; font-size: 12pt;"> </span><span style="color: #6a3e3e; font-family: Consolas; font-size: 12.0pt;">array</span><span style="font-family: Consolas; font-size: 12pt;">[</span><span style="color: #6a3e3e; font-family: Consolas; font-size: 12.0pt;">j</span><span style="font-family: Consolas; font-size: 12pt;">] = </span><span style="color: #6a3e3e; font-family: Consolas; font-size: 12.0pt;">temp</span><span style="font-family: Consolas; font-size: 12pt;">;</span><span style="font-family: Consolas; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: Consolas; font-size: 12pt;"> </span><span style="color: #6a3e3e; font-family: Consolas; font-size: 12.0pt;">i</span><span style="font-family: Consolas; font-size: 12pt;">++; </span><span style="color: #6a3e3e; font-family: Consolas; font-size: 12.0pt;">j</span><span style="font-family: Consolas; font-size: 12pt;">--;</span><span style="font-family: Consolas; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: Consolas; font-size: 12pt;"> }</span><span style="font-family: Consolas; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: Consolas; font-size: 12pt;"> </span><span style="font-family: Consolas; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: Consolas; font-size: 12pt;"> </span><span style="color: #3f5fbf; font-family: Consolas; font-size: 12.0pt;">/** Set the reversed array into the String Object. */</span><span style="font-family: Consolas; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: Consolas; font-size: 12pt;"> </span><span style="color: #6a3e3e; font-family: Consolas; font-size: 12.0pt;">field</span><span style="font-family: Consolas; font-size: 12pt;">.set(</span><span style="color: #6a3e3e; font-family: Consolas; font-size: 12.0pt;">value</span><span style="font-family: Consolas; font-size: 12pt;">, </span><span style="color: #6a3e3e; font-family: Consolas; font-size: 12.0pt;">array</span><span style="font-family: Consolas; font-size: 12pt;">);</span><span style="font-family: Consolas; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: Consolas; font-size: 12pt;"> } </span><span style="color: #7f0055; font-family: Consolas; font-size: 12.0pt; mso-bidi-font-weight: bold;">catch</span><span style="font-family: Consolas; font-size: 12pt;"> (NoSuchFieldException | SecurityException |</span><span style="font-family: Consolas; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: Consolas; font-size: 12pt;"> IllegalArgumentException | IllegalAccessException </span><span style="color: #6a3e3e; font-family: Consolas; font-size: 12.0pt;">e</span><span style="font-family: Consolas; font-size: 12pt;">) {</span><span style="font-family: Consolas; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: Consolas; font-size: 12pt;"> System.</span><i><span style="color: #0000c0; font-family: Consolas; font-size: 12.0pt; mso-bidi-font-weight: bold;">err</span></i><span style="font-family: Consolas; font-size: 12pt;">.println(</span><span style="color: #6a3e3e; font-family: Consolas; font-size: 12.0pt;">e</span><span style="font-family: Consolas; font-size: 12pt;">.getCause());</span><span style="font-family: Consolas; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: Consolas; font-size: 12pt;"> }</span><span style="font-family: Consolas; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: Consolas; font-size: 12pt;"> }</span><span style="font-family: Consolas; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<br /></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: Consolas; font-size: 12pt;"> </span><span style="color: #3f5fbf; font-family: Consolas; font-size: 12.0pt;">/**</span><span style="font-family: Consolas; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="color: #3f5fbf; font-family: Consolas; font-size: 12.0pt;"> * Driver method to reverse a String.</span><span style="font-family: Consolas; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="color: #3f5fbf; font-family: Consolas; font-size: 12.0pt;"> */</span><span style="font-family: Consolas; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: Consolas; font-size: 12pt;"> </span><span style="color: #7f0055; font-family: Consolas; font-size: 12.0pt; mso-bidi-font-weight: bold;">public</span><span style="font-family: Consolas; font-size: 12pt;"> </span><span style="color: #7f0055; font-family: Consolas; font-size: 12.0pt; mso-bidi-font-weight: bold;">static</span><span style="font-family: Consolas; font-size: 12pt;"> </span><span style="color: #7f0055; font-family: Consolas; font-size: 12.0pt; mso-bidi-font-weight: bold;">void</span><span style="font-family: Consolas; font-size: 12pt;"> main(String[] </span><span style="color: #6a3e3e; font-family: Consolas; font-size: 12.0pt;">args</span><span style="font-family: Consolas; font-size: 12pt;">) {</span><span style="font-family: Consolas; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: Consolas; font-size: 12pt;"> String </span><span style="color: #6a3e3e; font-family: Consolas; font-size: 12.0pt;">value</span><span style="font-family: Consolas; font-size: 12pt;"> = </span><span style="color: #2a00ff; font-family: Consolas; font-size: 12.0pt;">"geeksforgeeks"</span><span style="font-family: Consolas; font-size: 12pt;">;</span><span style="font-family: Consolas; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: Consolas; font-size: 12pt;"> System.</span><i><span style="color: #0000c0; font-family: Consolas; font-size: 12.0pt; mso-bidi-font-weight: bold;">out</span></i><span style="font-family: Consolas; font-size: 12pt;">.println(</span><span style="color: #6a3e3e; font-family: Consolas; font-size: 12.0pt;">value</span><span style="font-family: Consolas; font-size: 12pt;">);</span><span style="font-family: Consolas; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: Consolas; font-size: 12pt;"> <i>reverseString</i>(</span><span style="color: #6a3e3e; font-family: Consolas; font-size: 12.0pt;">value</span><span style="font-family: Consolas; font-size: 12pt;">);</span><span style="font-family: Consolas; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: Consolas; font-size: 12pt;"> System.</span><i><span style="color: #0000c0; font-family: Consolas; font-size: 12.0pt; mso-bidi-font-weight: bold;">out</span></i><span style="font-family: Consolas; font-size: 12pt;">.println(</span><span style="color: #6a3e3e; font-family: Consolas; font-size: 12.0pt;">value</span><span style="font-family: Consolas; font-size: 12pt;">);</span><span style="font-family: Consolas; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: Consolas; font-size: 12pt;"> }</span><span style="font-family: Consolas; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: Consolas; font-size: 12pt;">}</span><span style="font-family: "Book Antiqua","serif"; font-size: 12.0pt;"><o:p></o:p></span></div>
</div>
</div>
</div>
javaexplor03http://www.blogger.com/profile/07455293496498711738noreply@blogger.com5tag:blogger.com,1999:blog-615973148715732292.post-89543273540540542642017-06-29T12:34:00.002-07:002017-06-29T12:34:29.945-07:00Ping an IP address in Java | Java Networking<div dir="ltr" style="text-align: left;" trbidi="on">
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in;">
<span style="font-family: "Book Antiqua", serif; font-size: 13pt;">We
can ping an IP address using java.net.InetAddress.isReachable() method.</span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in;">
<span style="font-family: "Book Antiqua","serif"; font-size: 13.0pt;"><br /></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in;">
<span style="font-family: "Book Antiqua","serif"; font-size: 13.0pt;">This
example is by using ProcessBuilder class, Process class. ProcessBuilder class
is used to create operating system processes and ProcessBuilder.start() starts
the sub-process which will execute the ping command.</span></div>
<div style="background: #DBE5F1; border: solid windowtext 1.0pt; mso-background-themecolor: accent1; mso-background-themetint: 51; mso-border-alt: solid windowtext .5pt; mso-element: para-border-div; padding: 1.0pt 4.0pt 1.0pt 4.0pt;">
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="color: #7f0055; font-family: Consolas; font-size: 12.0pt; mso-bidi-font-weight: bold;">package</span><span style="font-family: Consolas; font-size: 12pt;"> com.java.networking;</span><span style="font-family: Consolas; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<br /></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="color: #7f0055; font-family: Consolas; font-size: 12.0pt; mso-bidi-font-weight: bold;">import</span><span style="font-family: Consolas; font-size: 12pt;"> java.io.BufferedReader;</span><span style="font-family: Consolas; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="color: #7f0055; font-family: Consolas; font-size: 12.0pt; mso-bidi-font-weight: bold;">import</span><span style="font-family: Consolas; font-size: 12pt;"> java.io.InputStreamReader;</span><span style="font-family: Consolas; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="color: #7f0055; font-family: Consolas; font-size: 12.0pt; mso-bidi-font-weight: bold;">import</span><span style="font-family: Consolas; font-size: 12pt;"> java.util.ArrayList;</span><span style="font-family: Consolas; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<br /></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="color: #7f0055; font-family: Consolas; font-size: 12.0pt; mso-bidi-font-weight: bold;">public</span><span style="font-family: Consolas; font-size: 12pt;"> </span><span style="color: #7f0055; font-family: Consolas; font-size: 12.0pt; mso-bidi-font-weight: bold;">class</span><span style="font-family: Consolas; font-size: 12pt;"> PingIP {</span><span style="font-family: Consolas; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: Consolas; font-size: 12pt;"> </span><span style="font-family: Consolas; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: Consolas; font-size: 12pt;"> </span><span style="color: #7f0055; font-family: Consolas; font-size: 12.0pt; mso-bidi-font-weight: bold;">static</span><span style="font-family: Consolas; font-size: 12pt;"> </span><span style="color: #7f0055; font-family: Consolas; font-size: 12.0pt; mso-bidi-font-weight: bold;">void</span><span style="font-family: Consolas; font-size: 12pt;">
runOSCommands(ArrayList<String> </span><span style="color: #6a3e3e; font-family: Consolas; font-size: 12.0pt;">commandList</span><span style="font-family: Consolas; font-size: 12pt;">) </span><span style="color: #7f0055; font-family: Consolas; font-size: 12.0pt; mso-bidi-font-weight: bold;">throws</span><span style="font-family: Consolas; font-size: 12pt;"> Exception { </span><span style="font-family: Consolas; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: Consolas; font-size: 12pt;"> </span><span style="color: #3f5fbf; font-family: Consolas; font-size: 12.0pt;">/** creating the sub process, execute
system command. */</span><span style="font-family: Consolas; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: Consolas; font-size: 12pt;"> ProcessBuilder </span><span style="color: #6a3e3e; font-family: Consolas; font-size: 12.0pt;">build</span><span style="font-family: Consolas; font-size: 12pt;"> = </span><span style="color: #7f0055; font-family: Consolas; font-size: 12.0pt; mso-bidi-font-weight: bold;">new</span><span style="font-family: Consolas; font-size: 12pt;">
ProcessBuilder(</span><span style="color: #6a3e3e; font-family: Consolas; font-size: 12.0pt;">commandList</span><span style="font-family: Consolas; font-size: 12pt;">);</span><span style="font-family: Consolas; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: Consolas; font-size: 12pt;"> </span><span style="font-family: Consolas; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: Consolas; font-size: 12pt;"> Process </span><span style="color: #6a3e3e; font-family: Consolas; font-size: 12.0pt;">process</span><span style="font-family: Consolas; font-size: 12pt;"> = </span><span style="color: #6a3e3e; font-family: Consolas; font-size: 12.0pt;">build</span><span style="font-family: Consolas; font-size: 12pt;">.start();</span><span style="font-family: Consolas; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<br /></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: Consolas; font-size: 12pt;"> </span><span style="color: #3f5fbf; font-family: Consolas; font-size: 12.0pt;">/** to read the output. */</span><span style="font-family: Consolas; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: Consolas; font-size: 12pt;"> BufferedReader </span><span style="color: #6a3e3e; font-family: Consolas; font-size: 12.0pt;">input</span><span style="font-family: Consolas; font-size: 12pt;"> = </span><span style="color: #7f0055; font-family: Consolas; font-size: 12.0pt; mso-bidi-font-weight: bold;">new</span><span style="font-family: Consolas; font-size: 12pt;">
BufferedReader(</span><span style="color: #7f0055; font-family: Consolas; font-size: 12.0pt; mso-bidi-font-weight: bold;">new</span><span style="font-family: Consolas; font-size: 12pt;"> InputStreamReader(</span><span style="color: #6a3e3e; font-family: Consolas; font-size: 12.0pt;">process</span><span style="font-family: Consolas; font-size: 12pt;">.getInputStream()));</span><span style="font-family: Consolas; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: Consolas; font-size: 12pt;"> BufferedReader </span><span style="color: #6a3e3e; font-family: Consolas; font-size: 12.0pt;">error</span><span style="font-family: Consolas; font-size: 12pt;"> = </span><span style="color: #7f0055; font-family: Consolas; font-size: 12.0pt; mso-bidi-font-weight: bold;">new</span><span style="font-family: Consolas; font-size: 12pt;">
BufferedReader(</span><span style="color: #7f0055; font-family: Consolas; font-size: 12.0pt; mso-bidi-font-weight: bold;">new</span><span style="font-family: Consolas; font-size: 12pt;"> InputStreamReader(</span><span style="color: #6a3e3e; font-family: Consolas; font-size: 12.0pt;">process</span><span style="font-family: Consolas; font-size: 12pt;">.getErrorStream()));</span><span style="font-family: Consolas; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: Consolas; font-size: 12pt;"> </span><span style="font-family: Consolas; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: Consolas; font-size: 12pt;"> String </span><span style="color: #6a3e3e; font-family: Consolas; font-size: 12.0pt;">s</span><span style="font-family: Consolas; font-size: 12pt;"> = </span><span style="color: #7f0055; font-family: Consolas; font-size: 12.0pt; mso-bidi-font-weight: bold;">null</span><span style="font-family: Consolas; font-size: 12pt;">;</span><span style="font-family: Consolas; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: Consolas; font-size: 12pt;"> System.</span><i><span style="color: #0000c0; font-family: Consolas; font-size: 12.0pt; mso-bidi-font-weight: bold;">out</span></i><span style="font-family: Consolas; font-size: 12pt;">.println(</span><span style="color: #2a00ff; font-family: Consolas; font-size: 12.0pt;">"Ping result: "</span><span style="font-family: Consolas; font-size: 12pt;">);</span><span style="font-family: Consolas; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: Consolas; font-size: 12pt;"> </span><span style="font-family: Consolas; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: Consolas; font-size: 12pt;"> </span><span style="color: #7f0055; font-family: Consolas; font-size: 12.0pt; mso-bidi-font-weight: bold;">while</span><span style="font-family: Consolas; font-size: 12pt;">((</span><span style="color: #6a3e3e; font-family: Consolas; font-size: 12.0pt;">s</span><span style="font-family: Consolas; font-size: 12pt;"> = </span><span style="color: #6a3e3e; font-family: Consolas; font-size: 12.0pt;">input</span><span style="font-family: Consolas; font-size: 12pt;">.readLine()) != </span><span style="color: #7f0055; font-family: Consolas; font-size: 12.0pt; mso-bidi-font-weight: bold;">null</span><span style="font-family: Consolas; font-size: 12pt;">)
{</span><span style="font-family: Consolas; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: Consolas; font-size: 12pt;"> System.</span><i><span style="color: #0000c0; font-family: Consolas; font-size: 12.0pt; mso-bidi-font-weight: bold;">out</span></i><span style="font-family: Consolas; font-size: 12pt;">.println(</span><span style="color: #6a3e3e; font-family: Consolas; font-size: 12.0pt;">s</span><span style="font-family: Consolas; font-size: 12pt;">);</span><span style="font-family: Consolas; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: Consolas; font-size: 12pt;"> }</span><span style="font-family: Consolas; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: Consolas; font-size: 12pt;"> </span><span style="font-family: Consolas; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: Consolas; font-size: 12pt;"> System.</span><i><span style="color: #0000c0; font-family: Consolas; font-size: 12.0pt; mso-bidi-font-weight: bold;">out</span></i><span style="font-family: Consolas; font-size: 12pt;">.println(</span><span style="color: #2a00ff; font-family: Consolas; font-size: 12.0pt;">"Print error (if any): "</span><span style="font-family: Consolas; font-size: 12pt;">);</span><span style="font-family: Consolas; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: Consolas; font-size: 12pt;"> </span><span style="color: #7f0055; font-family: Consolas; font-size: 12.0pt; mso-bidi-font-weight: bold;">while</span><span style="font-family: Consolas; font-size: 12pt;">((</span><span style="color: #6a3e3e; font-family: Consolas; font-size: 12.0pt;">s</span><span style="font-family: Consolas; font-size: 12pt;"> = </span><span style="color: #6a3e3e; font-family: Consolas; font-size: 12.0pt;">error</span><span style="font-family: Consolas; font-size: 12pt;">.readLine()) != </span><span style="color: #7f0055; font-family: Consolas; font-size: 12.0pt; mso-bidi-font-weight: bold;">null</span><span style="font-family: Consolas; font-size: 12pt;">)
{</span><span style="font-family: Consolas; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: Consolas; font-size: 12pt;"> System.</span><i><span style="color: #0000c0; font-family: Consolas; font-size: 12.0pt; mso-bidi-font-weight: bold;">out</span></i><span style="font-family: Consolas; font-size: 12pt;">.println(</span><span style="color: #6a3e3e; font-family: Consolas; font-size: 12.0pt;">s</span><span style="font-family: Consolas; font-size: 12pt;">);</span><span style="font-family: Consolas; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: Consolas; font-size: 12pt;"> }</span><span style="font-family: Consolas; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: Consolas; font-size: 12pt;"> }</span><span style="font-family: Consolas; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<br /></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: Consolas; font-size: 12pt;"> </span><span style="color: #7f0055; font-family: Consolas; font-size: 12.0pt; mso-bidi-font-weight: bold;">public</span><span style="font-family: Consolas; font-size: 12pt;"> </span><span style="color: #7f0055; font-family: Consolas; font-size: 12.0pt; mso-bidi-font-weight: bold;">static</span><span style="font-family: Consolas; font-size: 12pt;"> </span><span style="color: #7f0055; font-family: Consolas; font-size: 12.0pt; mso-bidi-font-weight: bold;">void</span><span style="font-family: Consolas; font-size: 12pt;"> main(String </span><span style="color: #6a3e3e; font-family: Consolas; font-size: 12.0pt;">args</span><span style="font-family: Consolas; font-size: 12pt;">[]) </span><span style="color: #7f0055; font-family: Consolas; font-size: 12.0pt; mso-bidi-font-weight: bold;">throws</span><span style="font-family: Consolas; font-size: 12pt;"> Exception {</span><span style="font-family: Consolas; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: Consolas; font-size: 12pt;"> </span><span style="font-family: Consolas; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: Consolas; font-size: 12pt;"> </span><span style="color: #3f5fbf; font-family: Consolas; font-size: 12.0pt;">/** Initialize the command list. */</span><span style="font-family: Consolas; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: Consolas; font-size: 12pt;"> ArrayList<String> </span><span style="color: #6a3e3e; font-family: Consolas; font-size: 12.0pt;">commandList</span><span style="font-family: Consolas; font-size: 12pt;"> = </span><span style="color: #7f0055; font-family: Consolas; font-size: 12.0pt; mso-bidi-font-weight: bold;">new</span><span style="font-family: Consolas; font-size: 12pt;">
ArrayList<String>();</span><span style="font-family: Consolas; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<br /></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: Consolas; font-size: 12pt;"> </span><span style="color: #6a3e3e; font-family: Consolas; font-size: 12.0pt;">commandList</span><span style="font-family: Consolas; font-size: 12pt;">.add(</span><span style="color: #2a00ff; font-family: Consolas; font-size: 12.0pt;">"ping"</span><span style="font-family: Consolas; font-size: 12pt;">);</span><span style="font-family: Consolas; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: Consolas; font-size: 12pt;"> </span><span style="color: #6a3e3e; font-family: Consolas; font-size: 12.0pt;">commandList</span><span style="font-family: Consolas; font-size: 12pt;">.add(</span><span style="color: #2a00ff; font-family: Consolas; font-size: 12.0pt;">"www.google.com"</span><span style="font-family: Consolas; font-size: 12pt;">);</span><span style="font-family: Consolas; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: Consolas; font-size: 12pt;"> </span><span style="font-family: Consolas; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: Consolas; font-size: 12pt;"> <i>runOSCommands</i>(</span><span style="color: #6a3e3e; font-family: Consolas; font-size: 12.0pt;">commandList</span><span style="font-family: Consolas; font-size: 12pt;">);</span><span style="font-family: Consolas; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: Consolas; font-size: 12pt;"> }<o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: Consolas; font-size: 12pt;">}<o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: Consolas; font-size: 12pt;">Ping result:<o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: Consolas; font-size: 12pt;">Pinging
www.google.com [74.125.68.104] with 32 bytes of data:</span><span style="font-family: Consolas; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: Consolas; font-size: 12pt;">Reply from
74.125.68.104: bytes=32 time=403ms TTL=45</span><span style="font-family: Consolas; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: Consolas; font-size: 12pt;">Reply from
74.125.68.104: bytes=32 time=341ms TTL=45</span><span style="font-family: Consolas; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: Consolas; font-size: 12pt;">Reply from
74.125.68.104: bytes=32 time=359ms TTL=45</span><span style="font-family: Consolas; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: Consolas; font-size: 12pt;">Reply from
74.125.68.104: bytes=32 time=329ms TTL=45</span><span style="font-family: Consolas; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<br /></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: Consolas; font-size: 12pt;">Ping statistics for
74.125.68.104:</span><span style="font-family: Consolas; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: Consolas; font-size: 12pt;"> Packets: Sent = 4, Received = 4, Lost = 0
(0% loss),</span><span style="font-family: Consolas; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: Consolas; font-size: 12pt;">Approximate round
trip times in milli-seconds:</span><span style="font-family: Consolas; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: Consolas; font-size: 12pt;"> Minimum = 329ms, Maximum = 403ms, Average =
358ms</span></div>
</div>
</div>
javaexplor03http://www.blogger.com/profile/07455293496498711738noreply@blogger.com2tag:blogger.com,1999:blog-615973148715732292.post-73748822766510278042017-06-29T03:58:00.002-07:002017-06-29T09:31:59.611-07:00To Maximize the Probability of Red Marble<div dir="ltr" style="text-align: left;" trbidi="on">
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in;">
<span style="font-family: "book antiqua" , serif; font-size: 13pt;">You
have 50 red balls and 50 blue balls, you have to place these balls in two
containers in such a way that probability of a person picking up a red ball
from any container is maximum.</span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in;">
<span style="font-family: "book antiqua" , serif; font-size: 13pt;"><br /></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in;">
<b><span style="color: #1f497d; font-family: "book antiqua" , "serif"; font-size: 13.0pt;">1. For container 1,</span></b></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in;">
<span style="font-family: "book antiqua" , "serif"; font-size: 13.0pt;">You
should have to place one red marble into 1st Container. By this when we select this Container 1 P(Red|C1) will be 1.</span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in;">
<b><span style="color: #1f497d; font-family: "book antiqua" , "serif"; font-size: 13.0pt;"><br /></span></b></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in;">
<b><span style="color: #1f497d; font-family: "book antiqua" , "serif"; font-size: 13.0pt;">2. For container 2,</span></b></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in;">
<span style="font-family: "book antiqua" , "serif"; font-size: 13.0pt;">Rest
all marbles should have to place into 2nd container. By this when we select this Container 2 P(Red|C2) will be 49/99.</span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in;">
<span style="font-family: "book antiqua" , serif; font-size: 13pt;"><br /></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in;">
<span style="font-family: "book antiqua" , serif; font-size: 13pt;">Here,
P(C1) = P(C2) = 1/2 as there is only 2 containers.</span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in;">
<span style="font-family: "book antiqua" , serif; font-size: 13pt;"><br /></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in;">
<span style="font-family: "book antiqua" , "serif"; font-size: 13.0pt;">So
answer will be P(Red) = P(C1)*P(Red|C1) + P(C2)*(Red|C2)<o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in;">
<span style="font-family: "book antiqua" , "serif"; font-size: 13.0pt;"> P(Red) = (1/2)*(1) + (1/2)*(49/99)<o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in;">
<span style="font-family: "book antiqua" , "serif"; font-size: 13.0pt;"> P(Red) = 0.747474.</span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in;">
<span style="font-family: "book antiqua" , "serif"; font-size: 13.0pt;"><br /></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in;">
<b><span style="color: #1f497d; font-family: "book antiqua" , "serif"; font-size: 13.0pt;">Proof of
above given solution using the Java code:</span></b></div>
<div style="background: #DBE5F1; border: solid windowtext 1.0pt; mso-background-themecolor: accent1; mso-background-themetint: 51; mso-border-alt: solid windowtext .5pt; mso-element: para-border-div; padding: 1.0pt 4.0pt 1.0pt 4.0pt;">
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="color: #7f0055; font-family: "consolas"; font-size: 12.0pt;">public</span><span style="font-family: "consolas"; font-size: 12pt;"> </span><span style="color: #7f0055; font-family: "consolas"; font-size: 12.0pt;">class</span><span style="font-family: "consolas"; font-size: 12pt;">
MaximizeRedBallProbability {</span><span style="font-family: "consolas"; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: "consolas"; font-size: 12pt;"> </span><span style="color: #3f5fbf; font-family: "consolas"; font-size: 12.0pt;">/**</span><span style="font-family: "consolas"; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="color: #3f5fbf; font-family: "consolas"; font-size: 12.0pt;"> * This is the code which maximize the
probability.</span><span style="font-family: "consolas"; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="color: #3f5fbf; font-family: "consolas"; font-size: 12.0pt;"> * </span><span style="color: #7f9fbf; font-family: "consolas"; font-size: 12.0pt;">@param</span><span style="color: #3f5fbf; font-family: "consolas"; font-size: 12.0pt;"> red</span><span style="font-family: "consolas"; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="color: #3f5fbf; font-family: "consolas"; font-size: 12.0pt;"> * </span><span style="color: #7f9fbf; font-family: "consolas"; font-size: 12.0pt;">@param</span><span style="color: #3f5fbf; font-family: "consolas"; font-size: 12.0pt;"> blue</span><span style="font-family: "consolas"; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="color: #3f5fbf; font-family: "consolas"; font-size: 12.0pt;"> * </span><span style="color: #7f9fbf; font-family: "consolas"; font-size: 12.0pt;">@return</span><span style="color: #3f5fbf; font-family: "consolas"; font-size: 12.0pt;"> probability</span><span style="font-family: "consolas"; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="color: #3f5fbf; font-family: "consolas"; font-size: 12.0pt;"> */</span><span style="font-family: "consolas"; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: "consolas"; font-size: 12pt;"> </span><span style="color: #7f0055; font-family: "consolas"; font-size: 12.0pt;">private</span><span style="font-family: "consolas"; font-size: 12pt;"> </span><span style="color: #7f0055; font-family: "consolas"; font-size: 12.0pt;">static</span><span style="font-family: "consolas"; font-size: 12pt;"> </span><span style="color: #7f0055; font-family: "consolas"; font-size: 12.0pt;">double</span><span style="font-family: "consolas"; font-size: 12pt;">
getProbability(</span><span style="color: #7f0055; font-family: "consolas"; font-size: 12.0pt;">int</span><span style="font-family: "consolas"; font-size: 12pt;"> </span><span style="color: #6a3e3e; font-family: "consolas"; font-size: 12.0pt;">red</span><span style="font-family: "consolas"; font-size: 12pt;">, </span><span style="color: #7f0055; font-family: "consolas"; font-size: 12.0pt;">int</span><span style="font-family: "consolas"; font-size: 12pt;"> </span><span style="color: #6a3e3e; font-family: "consolas"; font-size: 12.0pt;">blue</span><span style="font-family: "consolas"; font-size: 12pt;">) {</span><span style="font-family: "consolas"; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: "consolas"; font-size: 12pt;"> </span><span style="color: #7f0055; font-family: "consolas"; font-size: 12.0pt;">double</span><span style="font-family: "consolas"; font-size: 12pt;"> </span><span style="color: #6a3e3e; font-family: "consolas"; font-size: 12.0pt;">max</span><span style="font-family: "consolas"; font-size: 12pt;">=0;</span><span style="font-family: "consolas"; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: "consolas"; font-size: 12pt;"> </span><span style="color: #7f0055; font-family: "consolas"; font-size: 12.0pt;">int</span><span style="font-family: "consolas"; font-size: 12pt;"> </span><span style="color: #6a3e3e; font-family: "consolas"; font-size: 12.0pt;">maxRed</span><span style="font-family: "consolas"; font-size: 12pt;"> = 0;</span><span style="font-family: "consolas"; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: "consolas"; font-size: 12pt;"> </span><span style="color: #7f0055; font-family: "consolas"; font-size: 12.0pt;">int</span><span style="font-family: "consolas"; font-size: 12pt;"> </span><span style="color: #6a3e3e; font-family: "consolas"; font-size: 12.0pt;">maxBlue</span><span style="font-family: "consolas"; font-size: 12pt;"> = 0;</span><span style="font-family: "consolas"; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: "consolas"; font-size: 12pt;"> </span><span style="font-family: "consolas"; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: "consolas"; font-size: 12pt;"> </span><span style="color: #7f0055; font-family: "consolas"; font-size: 12.0pt;">for</span><span style="font-family: "consolas"; font-size: 12pt;"> (</span><span style="color: #7f0055; font-family: "consolas"; font-size: 12.0pt;">int</span><span style="font-family: "consolas"; font-size: 12pt;"> </span><span style="color: #6a3e3e; font-family: "consolas"; font-size: 12.0pt;">i</span><span style="font-family: "consolas"; font-size: 12pt;"> = 1; </span><span style="color: #6a3e3e; font-family: "consolas"; font-size: 12.0pt;">i</span><span style="font-family: "consolas"; font-size: 12pt;"> < </span><span style="color: #6a3e3e; font-family: "consolas"; font-size: 12.0pt;">red</span><span style="font-family: "consolas"; font-size: 12pt;">; </span><span style="color: #6a3e3e; font-family: "consolas"; font-size: 12.0pt;">i</span><span style="font-family: "consolas"; font-size: 12pt;">++) {</span><span style="font-family: "consolas"; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: "consolas"; font-size: 12pt;"> </span><span style="color: #7f0055; font-family: "consolas"; font-size: 12.0pt;">for</span><span style="font-family: "consolas"; font-size: 12pt;"> (</span><span style="color: #7f0055; font-family: "consolas"; font-size: 12.0pt;">int</span><span style="font-family: "consolas"; font-size: 12pt;"> </span><span style="color: #6a3e3e; font-family: "consolas"; font-size: 12.0pt;">j</span><span style="font-family: "consolas"; font-size: 12pt;"> = 0; </span><span style="color: #6a3e3e; font-family: "consolas"; font-size: 12.0pt;">j</span><span style="font-family: "consolas"; font-size: 12pt;"> < </span><span style="color: #6a3e3e; font-family: "consolas"; font-size: 12.0pt;">blue</span><span style="font-family: "consolas"; font-size: 12pt;">; </span><span style="color: #6a3e3e; font-family: "consolas"; font-size: 12.0pt;">j</span><span style="font-family: "consolas"; font-size: 12pt;">++) {</span><span style="font-family: "consolas"; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: "consolas"; font-size: 12pt;"> </span><span style="color: #7f0055; font-family: "consolas"; font-size: 12.0pt;">double</span><span style="font-family: "consolas"; font-size: 12pt;"> </span><span style="color: #6a3e3e; font-family: "consolas"; font-size: 12.0pt;">prb</span><span style="font-family: "consolas"; font-size: 12pt;"> = (0.5*</span><span style="color: #6a3e3e; font-family: "consolas"; font-size: 12.0pt;">i</span><span style="font-family: "consolas"; font-size: 12pt;">)/(</span><span style="color: #6a3e3e; font-family: "consolas"; font-size: 12.0pt;">i</span><span style="font-family: "consolas"; font-size: 12pt;">+</span><span style="color: #6a3e3e; font-family: "consolas"; font-size: 12.0pt;">j</span><span style="font-family: "consolas"; font-size: 12pt;">) + (0.5*(50-</span><span style="color: #6a3e3e; font-family: "consolas"; font-size: 12.0pt;">i</span><span style="font-family: "consolas"; font-size: 12pt;">))/(100-</span><span style="color: #6a3e3e; font-family: "consolas"; font-size: 12.0pt;">i</span><span style="font-family: "consolas"; font-size: 12pt;">-</span><span style="color: #6a3e3e; font-family: "consolas"; font-size: 12.0pt;">j</span><span style="font-family: "consolas"; font-size: 12pt;">);</span><span style="font-family: "consolas"; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: "consolas"; font-size: 12pt;"> </span><span style="font-family: "consolas"; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: "consolas"; font-size: 12pt;"> </span><span style="color: #7f0055; font-family: "consolas"; font-size: 12.0pt;">if</span><span style="font-family: "consolas"; font-size: 12pt;"> (</span><span style="color: #6a3e3e; font-family: "consolas"; font-size: 12.0pt;">prb</span><span style="font-family: "consolas"; font-size: 12pt;">></span><span style="color: #6a3e3e; font-family: "consolas"; font-size: 12.0pt;">max</span><span style="font-family: "consolas"; font-size: 12pt;">) {</span><span style="font-family: "consolas"; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: "consolas"; font-size: 12pt;"> </span><span style="color: #6a3e3e; font-family: "consolas"; font-size: 12.0pt;">max</span><span style="font-family: "consolas"; font-size: 12pt;"> = </span><span style="color: #6a3e3e; font-family: "consolas"; font-size: 12.0pt;">prb</span><span style="font-family: "consolas"; font-size: 12pt;">;</span><span style="font-family: "consolas"; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: "consolas"; font-size: 12pt;"> </span><span style="color: #6a3e3e; font-family: "consolas"; font-size: 12.0pt;">maxRed</span><span style="font-family: "consolas"; font-size: 12pt;">=</span><span style="color: #6a3e3e; font-family: "consolas"; font-size: 12.0pt;">i</span><span style="font-family: "consolas"; font-size: 12pt;">;</span><span style="font-family: "consolas"; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: "consolas"; font-size: 12pt;"> </span><span style="color: #6a3e3e; font-family: "consolas"; font-size: 12.0pt;">maxBlue</span><span style="font-family: "consolas"; font-size: 12pt;">=</span><span style="color: #6a3e3e; font-family: "consolas"; font-size: 12.0pt;">j</span><span style="font-family: "consolas"; font-size: 12pt;">;</span><span style="font-family: "consolas"; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: "consolas"; font-size: 12pt;"> }</span><span style="font-family: "consolas"; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: "consolas"; font-size: 12pt;"> }</span><span style="font-family: "consolas"; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: "consolas"; font-size: 12pt;"> }</span><span style="font-family: "consolas"; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: "consolas"; font-size: 12pt;"> System.</span><i><span style="color: #0000c0; font-family: "consolas"; font-size: 12.0pt;">out</span></i><span style="font-family: "consolas"; font-size: 12pt;">.println(</span><span style="color: #2a00ff; font-family: "consolas"; font-size: 12.0pt;">"Container 1, Red balls: "</span><span style="font-family: "consolas"; font-size: 12pt;">+</span><span style="color: #6a3e3e; font-family: "consolas"; font-size: 12.0pt;">maxRed</span><span style="font-family: "consolas"; font-size: 12pt;"> +</span><span style="color: #2a00ff; font-family: "consolas"; font-size: 12.0pt;">" Blue balls
: "</span><span style="font-family: "consolas"; font-size: 12pt;">+</span><span style="color: #6a3e3e; font-family: "consolas"; font-size: 12.0pt;">maxBlue</span><span style="font-family: "consolas"; font-size: 12pt;">);</span><span style="font-family: "consolas"; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: "consolas"; font-size: 12pt;"> System.</span><i><span style="color: #0000c0; font-family: "consolas"; font-size: 12.0pt;">out</span></i><span style="font-family: "consolas"; font-size: 12pt;">.println(</span><span style="color: #2a00ff; font-family: "consolas"; font-size: 12.0pt;">"Container 2, Red balls: "</span><span style="font-family: "consolas"; font-size: 12pt;">+(</span><span style="color: #6a3e3e; font-family: "consolas"; font-size: 12.0pt;">red</span><span style="font-family: "consolas"; font-size: 12pt;">-</span><span style="color: #6a3e3e; font-family: "consolas"; font-size: 12.0pt;">maxRed</span><span style="font-family: "consolas"; font-size: 12pt;">) +</span><span style="color: #2a00ff; font-family: "consolas"; font-size: 12.0pt;">" Blue balls : "</span><span style="font-family: "consolas"; font-size: 12pt;">+(</span><span style="color: #6a3e3e; font-family: "consolas"; font-size: 12.0pt;">blue</span><span style="font-family: "consolas"; font-size: 12pt;">-</span><span style="color: #6a3e3e; font-family: "consolas"; font-size: 12.0pt;">maxBlue</span><span style="font-family: "consolas"; font-size: 12pt;">));</span><span style="font-family: "consolas"; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: "consolas"; font-size: 12pt;"> </span><span style="color: #7f0055; font-family: "consolas"; font-size: 12.0pt;">return</span><span style="font-family: "consolas"; font-size: 12pt;"> </span><span style="color: #6a3e3e; font-family: "consolas"; font-size: 12.0pt;">max</span><span style="font-family: "consolas"; font-size: 12pt;">;</span><span style="font-family: "consolas"; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: "consolas"; font-size: 12pt;"> }</span><span style="font-family: "consolas"; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: "consolas"; font-size: 12pt;"> </span><span style="font-family: "consolas"; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: "consolas"; font-size: 12pt;"> </span><span style="color: #3f5fbf; font-family: "consolas"; font-size: 12.0pt;">/** Driver Method. */</span><span style="font-family: "consolas"; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: "consolas"; font-size: 12pt;"> </span><span style="color: #7f0055; font-family: "consolas"; font-size: 12.0pt;">public</span><span style="font-family: "consolas"; font-size: 12pt;"> </span><span style="color: #7f0055; font-family: "consolas"; font-size: 12.0pt;">static</span><span style="font-family: "consolas"; font-size: 12pt;"> </span><span style="color: #7f0055; font-family: "consolas"; font-size: 12.0pt;">void</span><span style="font-family: "consolas"; font-size: 12pt;">
main(String[] </span><span style="color: #6a3e3e; font-family: "consolas"; font-size: 12.0pt;">args</span><span style="font-family: "consolas"; font-size: 12pt;">) {</span><span style="font-family: "consolas"; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: "consolas"; font-size: 12pt;"> </span><span style="color: #7f0055; font-family: "consolas"; font-size: 12.0pt;">int</span><span style="font-family: "consolas"; font-size: 12pt;"> </span><span style="color: #6a3e3e; font-family: "consolas"; font-size: 12.0pt;">red</span><span style="font-family: "consolas"; font-size: 12pt;"> = 50;</span><span style="font-family: "consolas"; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: "consolas"; font-size: 12pt;"> </span><span style="color: #7f0055; font-family: "consolas"; font-size: 12.0pt;">int</span><span style="font-family: "consolas"; font-size: 12pt;"> </span><span style="color: #6a3e3e; font-family: "consolas"; font-size: 12.0pt;">blue</span><span style="font-family: "consolas"; font-size: 12pt;"> = 50;</span><span style="font-family: "consolas"; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: "consolas"; font-size: 12pt;"> </span><span style="color: #7f0055; font-family: "consolas"; font-size: 12.0pt;">double</span><span style="font-family: "consolas"; font-size: 12pt;"> </span><span style="color: #6a3e3e; font-family: "consolas"; font-size: 12.0pt;">p</span><span style="font-family: "consolas"; font-size: 12pt;"> = <i>getProbability</i>(</span><span style="color: #6a3e3e; font-family: "consolas"; font-size: 12.0pt;">red</span><span style="font-family: "consolas"; font-size: 12pt;">,</span><span style="color: #6a3e3e; font-family: "consolas"; font-size: 12.0pt;">blue</span><span style="font-family: "consolas"; font-size: 12pt;">);</span><span style="font-family: "consolas"; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: "consolas"; font-size: 12pt;"> System.</span><i><span style="color: #0000c0; font-family: "consolas"; font-size: 12.0pt;">out</span></i><span style="font-family: "consolas"; font-size: 12pt;">.println(</span><span style="color: #2a00ff; font-family: "consolas"; font-size: 12.0pt;">"Maximum probability of RED ball "</span><span style="font-family: "consolas"; font-size: 12pt;">+</span><span style="color: #6a3e3e; font-family: "consolas"; font-size: 12.0pt;">p</span><span style="font-family: "consolas"; font-size: 12pt;">);</span><span style="font-family: "consolas"; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: "consolas"; font-size: 12pt;"> }</span><span style="font-family: "consolas"; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: "consolas"; font-size: 12pt;">}<o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: "consolas"; font-size: 12pt;">Output:</span><span style="font-family: "consolas"; font-size: 10pt;"> </span><span style="font-family: "consolas"; font-size: 12pt;">7474747474747475</span><span style="color: #1f497d; font-family: "book antiqua" , "serif"; font-size: 16.0pt;"><o:p></o:p></span></div>
</div>
<br />
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in;">
<span style="font-family: "book antiqua" , "serif"; font-size: 13.0pt;"> <o:p></o:p></span></div>
</div>
javaexplor03http://www.blogger.com/profile/07455293496498711738noreply@blogger.com17tag:blogger.com,1999:blog-615973148715732292.post-54808062194842908192017-06-28T22:56:00.001-07:002017-06-28T22:57:13.211-07:00Search an element in an unsorted array using minimum number of comparisons<div dir="ltr" style="text-align: left;" trbidi="on">
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in;">
<span style="font-family: "book antiqua" , serif; font-size: 13pt;">Given
an array and an element, search the element x in the array using minimum number
of comparisons.</span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in;">
<span style="font-family: "book antiqua" , serif; font-size: 13pt;"><br /></span></div>
<div style="background: #DBE5F1; border: solid windowtext 1.0pt; mso-background-themecolor: accent1; mso-background-themetint: 51; mso-border-alt: solid windowtext .5pt; mso-element: para-border-div; padding: 1.0pt 4.0pt 1.0pt 4.0pt;">
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="color: #3f5fbf; font-family: "consolas"; font-size: 12.0pt;">/**This is generic
algorithm which takes 2n+1</span><span style="font-family: "consolas"; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="color: #3f5fbf; font-family: "consolas"; font-size: 12.0pt;"> * comparisons(worst case) to search element.
*/</span><span style="font-family: "consolas"; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="color: #7f0055; font-family: "consolas"; font-size: 12.0pt;">private</span><span style="font-family: "consolas"; font-size: 12pt;"> </span><span style="color: #7f0055; font-family: "consolas"; font-size: 12.0pt;">static</span><span style="font-family: "consolas"; font-size: 12pt;"> </span><span style="color: #7f0055; font-family: "consolas"; font-size: 12.0pt;">int</span><span style="font-family: "consolas"; font-size: 12pt;"> searchElementUsingGenericAlgo(</span><span style="color: #7f0055; font-family: "consolas"; font-size: 12.0pt;">int</span><span style="font-family: "consolas"; font-size: 12pt;">[]
</span><span style="color: #6a3e3e; font-family: "consolas"; font-size: 12.0pt;">array</span><span style="font-family: "consolas"; font-size: 12pt;">, </span><span style="color: #7f0055; font-family: "consolas"; font-size: 12.0pt;">int</span><span style="font-family: "consolas"; font-size: 12pt;">
</span><span style="color: #6a3e3e; font-family: "consolas"; font-size: 12.0pt;">value</span><span style="font-family: "consolas"; font-size: 12pt;">) {</span><span style="font-family: "consolas"; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: "consolas"; font-size: 12pt;"> </span><span style="color: #7f0055; font-family: "consolas"; font-size: 12.0pt;">int</span><span style="font-family: "consolas"; font-size: 12pt;"> </span><span style="color: #6a3e3e; font-family: "consolas"; font-size: 12.0pt;">idx</span><span style="font-family: "consolas"; font-size: 12pt;"> = -1;</span><span style="font-family: "consolas"; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: "consolas"; font-size: 12pt;"> </span><span style="color: #7f0055; font-family: "consolas"; font-size: 12.0pt;">int</span><span style="font-family: "consolas"; font-size: 12pt;"> </span><span style="color: #6a3e3e; font-family: "consolas"; font-size: 12.0pt;">length</span><span style="font-family: "consolas"; font-size: 12pt;"> = </span><span style="color: #6a3e3e; font-family: "consolas"; font-size: 12.0pt;">array</span><span style="font-family: "consolas"; font-size: 12pt;">.</span><span style="color: #0000c0; font-family: "consolas"; font-size: 12.0pt;">length</span><span style="font-family: "consolas"; font-size: 12pt;">;</span><span style="font-family: "consolas"; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: "consolas"; font-size: 12pt;"> </span><span style="color: #7f0055; font-family: "consolas"; font-size: 12.0pt;">for</span><span style="font-family: "consolas"; font-size: 12pt;"> (</span><span style="color: #7f0055; font-family: "consolas"; font-size: 12.0pt;">int</span><span style="font-family: "consolas"; font-size: 12pt;">
</span><span style="color: #6a3e3e; font-family: "consolas"; font-size: 12.0pt;">i</span><span style="font-family: "consolas"; font-size: 12pt;"> = 0;</span><span style="color: #6a3e3e; font-family: "consolas"; font-size: 12.0pt;">i</span><span style="font-family: "consolas"; font-size: 12pt;"><</span><span style="color: #6a3e3e; font-family: "consolas"; font-size: 12.0pt;">length</span><span style="font-family: "consolas"; font-size: 12pt;">; </span><span style="color: #6a3e3e; font-family: "consolas"; font-size: 12.0pt;">i</span><span style="font-family: "consolas"; font-size: 12pt;">++) { </span><span style="color: #3f7f5f; font-family: "consolas"; font-size: 12.0pt;">/* n+1 comparisons.
*/</span><span style="font-family: "consolas"; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: "consolas"; font-size: 12pt;"> </span><span style="color: #7f0055; font-family: "consolas"; font-size: 12.0pt;">if</span><span style="font-family: "consolas"; font-size: 12pt;">(</span><span style="color: #6a3e3e; font-family: "consolas"; font-size: 12.0pt;">value</span><span style="font-family: "consolas"; font-size: 12pt;"> == </span><span style="color: #6a3e3e; font-family: "consolas"; font-size: 12.0pt;">array</span><span style="font-family: "consolas"; font-size: 12pt;">[</span><span style="color: #6a3e3e; font-family: "consolas"; font-size: 12.0pt;">i</span><span style="font-family: "consolas"; font-size: 12pt;">]) { </span><span style="color: #3f7f5f; font-family: "consolas"; font-size: 12.0pt;">/* n comparisons.
*/</span><span style="font-family: "consolas"; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: "consolas"; font-size: 12pt;"> </span><span style="color: #6a3e3e; font-family: "consolas"; font-size: 12.0pt;">idx</span><span style="font-family: "consolas"; font-size: 12pt;"> = </span><span style="color: #6a3e3e; font-family: "consolas"; font-size: 12.0pt;">i</span><span style="font-family: "consolas"; font-size: 12pt;">;</span><span style="font-family: "consolas"; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: "consolas"; font-size: 12pt;"> </span><span style="color: #7f0055; font-family: "consolas"; font-size: 12.0pt;">break</span><span style="font-family: "consolas"; font-size: 12pt;">;</span><span style="font-family: "consolas"; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: "consolas"; font-size: 12pt;"> }</span><span style="font-family: "consolas"; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: "consolas"; font-size: 12pt;"> }</span><span style="font-family: "consolas"; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: "consolas"; font-size: 12pt;"> </span><span style="color: #7f0055; font-family: "consolas"; font-size: 12.0pt;">return</span><span style="font-family: "consolas"; font-size: 12pt;"> </span><span style="color: #6a3e3e; font-family: "consolas"; font-size: 12.0pt;">idx</span><span style="font-family: "consolas"; font-size: 12pt;">;</span><span style="font-family: "consolas"; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: "consolas"; font-size: 12pt;">}<o:p></o:p></span></div>
</div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in;">
<span style="font-family: "book antiqua" , "serif"; font-size: 13.0pt;">This
algorithm is developed to return the element index in 2n+1 comparison in the
worst case.</span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in;">
<span style="font-family: "book antiqua" , "serif"; font-size: 13.0pt;"><br /></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in;">
<b><span style="color: #1f497d; font-family: "book antiqua" , "serif"; font-size: 13.0pt;">Approach:</span></b></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in;">
<span style="font-family: "book antiqua" , "serif"; font-size: 13.0pt;">To
avoid the comparison that is taking place in the loop.</span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in;">
<span style="font-family: "book antiqua" , "serif"; font-size: 13.0pt;"><br /></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in;">
<b><span style="color: #1f497d; font-family: "book antiqua" , "serif"; font-size: 13.0pt;">Algorithm:<o:p></o:p></span></b></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in;">
<span style="font-family: "book antiqua" , "serif"; font-size: 13.0pt;">1.
Check that the last element in the array is equal to searched element.<o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in;">
<span style="font-family: "book antiqua" , "serif"; font-size: 13.0pt;"> a. YES, element index is found, return the
index.<o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in;">
<span style="font-family: "book antiqua" , "serif"; font-size: 13.0pt;"> b. NO, Take back up of last element and put
the searched element on last index of array.<o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in;">
<span style="font-family: "book antiqua" , "serif"; font-size: 13.0pt;">2.
Search for element with Infinite loop (without termination condition) and break
when the element is found<o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in;">
<span style="font-family: "book antiqua" , "serif"; font-size: 13.0pt;"> a. If element is found on last index, this
is the element put by us to terminate the search and this signals that element
not found in the array.<o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in;">
<span style="font-family: "book antiqua" , "serif"; font-size: 13.0pt;"> b. If element found other than last index,
set the backup to last index and return the index.<o:p></o:p></span><br />
<span style="font-family: "book antiqua" , "serif"; font-size: 13.0pt;"><br /></span></div>
<div style="background: #DBE5F1; border: solid windowtext 1.0pt; mso-background-themecolor: accent1; mso-background-themetint: 51; mso-border-alt: solid windowtext .5pt; mso-element: para-border-div; padding: 1.0pt 4.0pt 1.0pt 4.0pt;">
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="color: #7f0055; font-family: "consolas"; font-size: 12.0pt;">public</span><span style="font-family: "consolas"; font-size: 12pt;"> </span><span style="color: #7f0055; font-family: "consolas"; font-size: 12.0pt;">class</span><span style="font-family: "consolas"; font-size: 12pt;"> MinComparison {</span><span style="font-family: "consolas"; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<br /></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: "consolas"; font-size: 12pt;"> </span><span style="color: #3f5fbf; font-family: "consolas"; font-size: 12.0pt;">/**This algorithm is developed to return
the</span><span style="font-family: "consolas"; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="color: #3f5fbf; font-family: "consolas"; font-size: 12.0pt;"> *
element index in n+1 comparison in the worst case.</span><span style="font-family: "consolas"; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="color: #3f5fbf; font-family: "consolas"; font-size: 12.0pt;"> *
Approach: To avoid the comparison that is taking place in the loop.</span><span style="font-family: "consolas"; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="color: #3f5fbf; font-family: "consolas"; font-size: 12.0pt;"> *
Steps: </span><span style="font-family: "consolas"; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="color: #3f5fbf; font-family: "consolas"; font-size: 12.0pt;"> * 1.
Check that the last element in the array is equal to searched element.</span><span style="font-family: "consolas"; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="color: #3f5fbf; font-family: "consolas"; font-size: 12.0pt;"> * a.
YES, element index is found, return the index.</span><span style="font-family: "consolas"; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="color: #3f5fbf; font-family: "consolas"; font-size: 12.0pt;"> * b.
NO, Take back up of last element and put the searched element on last index of
array.</span><span style="font-family: "consolas"; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="color: #3f5fbf; font-family: "consolas"; font-size: 12.0pt;"> * 2.
Search for element with Infinite loop(without termination condition) and break
when the element is found</span><span style="font-family: "consolas"; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="color: #3f5fbf; font-family: "consolas"; font-size: 12.0pt;"> * a.
If element is found on last index, this is the element put by us to terminate</span><span style="font-family: "consolas"; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="color: #3f5fbf; font-family: "consolas"; font-size: 12.0pt;"> *
the search and this signals that element not found in the array.</span><span style="font-family: "consolas"; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="color: #3f5fbf; font-family: "consolas"; font-size: 12.0pt;"> * b.
If element found other than last index, set the backup to last index and return
the index.</span><span style="font-family: "consolas"; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="color: #3f5fbf; font-family: "consolas"; font-size: 12.0pt;"> **/</span><span style="font-family: "consolas"; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: "consolas"; font-size: 12pt;"> </span><span style="color: #7f0055; font-family: "consolas"; font-size: 12.0pt;">private</span><span style="font-family: "consolas"; font-size: 12pt;"> </span><span style="color: #7f0055; font-family: "consolas"; font-size: 12.0pt;">static</span><span style="font-family: "consolas"; font-size: 12pt;"> </span><span style="color: #7f0055; font-family: "consolas"; font-size: 12.0pt;">int</span><span style="font-family: "consolas"; font-size: 12pt;"> searchElement(</span><span style="color: #7f0055; font-family: "consolas"; font-size: 12.0pt;">int</span><span style="font-family: "consolas"; font-size: 12pt;">[] </span><span style="color: #6a3e3e; font-family: "consolas"; font-size: 12.0pt;">array</span><span style="font-family: "consolas"; font-size: 12pt;">, </span><span style="color: #7f0055; font-family: "consolas"; font-size: 12.0pt;">int</span><span style="font-family: "consolas"; font-size: 12pt;">
</span><span style="color: #6a3e3e; font-family: "consolas"; font-size: 12.0pt;">value</span><span style="font-family: "consolas"; font-size: 12pt;">) {</span><span style="font-family: "consolas"; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: "consolas"; font-size: 12pt;"> </span><span style="color: #7f0055; font-family: "consolas"; font-size: 12.0pt;">int</span><span style="font-family: "consolas"; font-size: 12pt;"> </span><span style="color: #6a3e3e; font-family: "consolas"; font-size: 12.0pt;">idx</span><span style="font-family: "consolas"; font-size: 12pt;"> = -1;</span><span style="font-family: "consolas"; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<br /></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: "consolas"; font-size: 12pt;"> </span><span style="color: #7f0055; font-family: "consolas"; font-size: 12.0pt;">int</span><span style="font-family: "consolas"; font-size: 12pt;"> </span><span style="color: #6a3e3e; font-family: "consolas"; font-size: 12.0pt;">length</span><span style="font-family: "consolas"; font-size: 12pt;"> = </span><span style="color: #6a3e3e; font-family: "consolas"; font-size: 12.0pt;">array</span><span style="font-family: "consolas"; font-size: 12pt;">.</span><span style="color: #0000c0; font-family: "consolas"; font-size: 12.0pt;">length</span><span style="font-family: "consolas"; font-size: 12pt;">;</span><span style="font-family: "consolas"; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: "consolas"; font-size: 12pt;"> </span><span style="color: #7f0055; font-family: "consolas"; font-size: 12.0pt;">int</span><span style="font-family: "consolas"; font-size: 12pt;"> </span><span style="color: #6a3e3e; font-family: "consolas"; font-size: 12.0pt;">backup</span><span style="font-family: "consolas"; font-size: 12pt;"> = </span><span style="color: #6a3e3e; font-family: "consolas"; font-size: 12.0pt;">array</span><span style="font-family: "consolas"; font-size: 12pt;">[</span><span style="color: #6a3e3e; font-family: "consolas"; font-size: 12.0pt;">length</span><span style="font-family: "consolas"; font-size: 12pt;">-1];</span><span style="font-family: "consolas"; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<br /></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: "consolas"; font-size: 12pt;"> </span><span style="color: #7f0055; font-family: "consolas"; font-size: 12.0pt;">if</span><span style="font-family: "consolas"; font-size: 12pt;">(</span><span style="color: #6a3e3e; font-family: "consolas"; font-size: 12.0pt;">backup</span><span style="font-family: "consolas"; font-size: 12pt;">==</span><span style="color: #6a3e3e; font-family: "consolas"; font-size: 12.0pt;">value</span><span style="font-family: "consolas"; font-size: 12pt;">) {</span><span style="font-family: "consolas"; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: "consolas"; font-size: 12pt;"> </span><span style="color: #7f0055; font-family: "consolas"; font-size: 12.0pt;">return</span><span style="font-family: "consolas"; font-size: 12pt;"> (</span><span style="color: #6a3e3e; font-family: "consolas"; font-size: 12.0pt;">length</span><span style="font-family: "consolas"; font-size: 12pt;">-1);</span><span style="font-family: "consolas"; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: "consolas"; font-size: 12pt;"> }</span><span style="font-family: "consolas"; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<br /></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: "consolas"; font-size: 12pt;"> </span><span style="color: #6a3e3e; font-family: "consolas"; font-size: 12.0pt;">array</span><span style="font-family: "consolas"; font-size: 12pt;">[</span><span style="color: #6a3e3e; font-family: "consolas"; font-size: 12.0pt;">length</span><span style="font-family: "consolas"; font-size: 12pt;">-1] = </span><span style="color: #6a3e3e; font-family: "consolas"; font-size: 12.0pt;">value</span><span style="font-family: "consolas"; font-size: 12pt;">;</span><span style="font-family: "consolas"; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<br /></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: "consolas"; font-size: 12pt;"> </span><span style="color: #7f0055; font-family: "consolas"; font-size: 12.0pt;">for</span><span style="font-family: "consolas"; font-size: 12pt;"> (</span><span style="color: #7f0055; font-family: "consolas"; font-size: 12.0pt;">int</span><span style="font-family: "consolas"; font-size: 12pt;">
</span><span style="color: #6a3e3e; font-family: "consolas"; font-size: 12.0pt;">i</span><span style="font-family: "consolas"; font-size: 12pt;"> = 0;; </span><span style="color: #6a3e3e; font-family: "consolas"; font-size: 12.0pt;">i</span><span style="font-family: "consolas"; font-size: 12pt;">++) {</span><span style="font-family: "consolas"; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: "consolas"; font-size: 12pt;"> </span><span style="color: #7f0055; font-family: "consolas"; font-size: 12.0pt;">if</span><span style="font-family: "consolas"; font-size: 12pt;">(</span><span style="color: #6a3e3e; font-family: "consolas"; font-size: 12.0pt;">value</span><span style="font-family: "consolas"; font-size: 12pt;"> == </span><span style="color: #6a3e3e; font-family: "consolas"; font-size: 12.0pt;">array</span><span style="font-family: "consolas"; font-size: 12pt;">[</span><span style="color: #6a3e3e; font-family: "consolas"; font-size: 12.0pt;">i</span><span style="font-family: "consolas"; font-size: 12pt;">]) { </span><span style="font-family: "consolas"; font-size: 12.0pt;"><o:p></o:p></span><span style="color: #3f7f5f; font-family: "consolas"; font-size: 16px;">/* n comparisons. */</span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: "consolas"; font-size: 12pt;"> </span><span style="color: #6a3e3e; font-family: "consolas"; font-size: 12.0pt;">idx</span><span style="font-family: "consolas"; font-size: 12pt;"> = </span><span style="color: #6a3e3e; font-family: "consolas"; font-size: 12.0pt;">i</span><span style="font-family: "consolas"; font-size: 12pt;">;</span><span style="font-family: "consolas"; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: "consolas"; font-size: 12pt;"> </span><span style="color: #7f0055; font-family: "consolas"; font-size: 12.0pt;">break</span><span style="font-family: "consolas"; font-size: 12pt;">;</span><span style="font-family: "consolas"; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: "consolas"; font-size: 12pt;"> }</span><span style="font-family: "consolas"; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: "consolas"; font-size: 12pt;"> }</span><span style="font-family: "consolas"; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<br /></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: "consolas"; font-size: 12pt;"> </span><span style="color: #7f0055; font-family: "consolas"; font-size: 12.0pt;">if</span><span style="font-family: "consolas"; font-size: 12pt;">(</span><span style="color: #6a3e3e; font-family: "consolas"; font-size: 12.0pt;">idx</span><span style="font-family: "consolas"; font-size: 12pt;">==</span><span style="color: #6a3e3e; font-family: "consolas"; font-size: 12.0pt;">length</span><span style="font-family: "consolas"; font-size: 12pt;">-1) { </span><span style="font-family: "consolas"; font-size: 12.0pt;"><o:p></o:p></span><span style="color: #3f7f5f; font-family: "consolas"; font-size: 16px;">/* 1 comparison. */</span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: "consolas"; font-size: 12pt;"> </span><span style="color: #6a3e3e; font-family: "consolas"; font-size: 12.0pt;">idx</span><span style="font-family: "consolas"; font-size: 12pt;"> = -1;</span><span style="font-family: "consolas"; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: "consolas"; font-size: 12pt;"> }</span><span style="font-family: "consolas"; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: "consolas"; font-size: 12pt;"> </span><span style="color: #7f0055; font-family: "consolas"; font-size: 12.0pt;">return</span><span style="font-family: "consolas"; font-size: 12pt;"> </span><span style="color: #6a3e3e; font-family: "consolas"; font-size: 12.0pt;">idx</span><span style="font-family: "consolas"; font-size: 12pt;">;</span><span style="font-family: "consolas"; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: "consolas"; font-size: 12pt;"> }</span><span style="font-family: "consolas"; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: "consolas"; font-size: 12pt;"> </span><span style="font-family: "consolas"; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: "consolas"; font-size: 12pt;"> </span><span style="color: #7f0055; font-family: "consolas"; font-size: 12.0pt;">public</span><span style="font-family: "consolas"; font-size: 12pt;"> </span><span style="color: #7f0055; font-family: "consolas"; font-size: 12.0pt;">static</span><span style="font-family: "consolas"; font-size: 12pt;"> </span><span style="color: #7f0055; font-family: "consolas"; font-size: 12.0pt;">void</span><span style="font-family: "consolas"; font-size: 12pt;"> main(String[] </span><span style="color: #6a3e3e; font-family: "consolas"; font-size: 12.0pt;">args</span><span style="font-family: "consolas"; font-size: 12pt;">) {</span><span style="font-family: "consolas"; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: "consolas"; font-size: 12pt;"> </span><span style="color: #7f0055; font-family: "consolas"; font-size: 12.0pt;">int</span><span style="font-family: "consolas"; font-size: 12pt;"> </span><span style="color: #6a3e3e; font-family: "consolas"; font-size: 12.0pt;">value</span><span style="font-family: "consolas"; font-size: 12pt;"> = 1;</span><span style="font-family: "consolas"; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: "consolas"; font-size: 12pt;"> </span><span style="color: #7f0055; font-family: "consolas"; font-size: 12.0pt;">int</span><span style="font-family: "consolas"; font-size: 12pt;"> [] </span><span style="color: #6a3e3e; font-family: "consolas"; font-size: 12.0pt;">array</span><span style="font-family: "consolas"; font-size: 12pt;"> = {4, 6, 1, 5, 8};</span><span style="font-family: "consolas"; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<br /></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: "consolas"; font-size: 12pt;"> </span><span style="color: #7f0055; font-family: "consolas"; font-size: 12.0pt;">int</span><span style="font-family: "consolas"; font-size: 12pt;"> </span><span style="color: #6a3e3e; font-family: "consolas"; font-size: 12.0pt;">index</span><span style="font-family: "consolas"; font-size: 12pt;"> = <i>searchElement</i>(</span><span style="color: #6a3e3e; font-family: "consolas"; font-size: 12.0pt;">array</span><span style="font-family: "consolas"; font-size: 12pt;">, </span><span style="color: #6a3e3e; font-family: "consolas"; font-size: 12.0pt;">value</span><span style="font-family: "consolas"; font-size: 12pt;">);</span><span style="font-family: "consolas"; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: "consolas"; font-size: 12pt;"> System.</span><i><span style="color: #0000c0; font-family: "consolas"; font-size: 12.0pt;">out</span></i><span style="font-family: "consolas"; font-size: 12pt;">.println(</span><span style="color: #2a00ff; font-family: "consolas"; font-size: 12.0pt;">"Element index in array "</span><span style="font-family: "consolas"; font-size: 12pt;">+</span><span style="color: #6a3e3e; font-family: "consolas"; font-size: 12.0pt;">index</span><span style="font-family: "consolas"; font-size: 12pt;">);</span><span style="font-family: "consolas"; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: "consolas"; font-size: 12pt;"> }</span><span style="font-family: "consolas"; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: "consolas"; font-size: 12pt;">}</span><span style="font-family: "book antiqua" , "serif"; font-size: 12.0pt;"><o:p></o:p></span></div>
</div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in;">
<span style="font-family: "book antiqua" , serif; font-size: 13pt;"><br /></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in;">
<span style="font-family: "book antiqua" , serif; font-size: 13pt;">This
algorithm is developed to return the element index in n+1 comparison in the
worst case.</span></div>
<br />
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in;">
<br /></div>
</div>
javaexplor03http://www.blogger.com/profile/07455293496498711738noreply@blogger.com0tag:blogger.com,1999:blog-615973148715732292.post-32181193129341860282017-06-28T05:33:00.000-07:002017-06-28T05:33:02.784-07:00Types of Java Garbage Collectors<div dir="ltr" style="text-align: left;" trbidi="on">
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in;">
<b><span style="font-family: "Book Antiqua","serif"; font-size: 13.0pt;">In java, Garbage means unreferenced
objects.</span></b></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in;">
<b><span style="font-family: "Book Antiqua","serif"; font-size: 13.0pt;"><br /></span></b></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in;">
<span style="font-family: Book Antiqua, serif;"><span style="font-size: 13pt;">Garbage
Collection is process of reclaiming the </span><span style="font-size: 17.3333px;">run-time</span><span style="font-size: 13pt;"> unused memory automatically. In
other words, it is a way to destroy the unused objects. Garbage collection is
an automatic process in Java which relieves the programmer of object memory
allocation and de-allocation chores.<o:p></o:p></span></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in;">
<br /></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in;">
<b><span style="color: #002060; font-family: "Book Antiqua","serif"; font-size: 13.0pt;">Java has four types of
garbage collectors:<o:p></o:p></span></b></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in;">
<span style="font-family: "Book Antiqua","serif"; font-size: 13.0pt;">1.
Serial Garbage Collector<o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in;">
<span style="font-family: "Book Antiqua","serif"; font-size: 13.0pt;">2.
Parallel Garbage Collector<o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in;">
<span style="font-family: "Book Antiqua","serif"; font-size: 13.0pt;">3.
CMS Garbage Collector<o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in;">
<span style="font-family: "Book Antiqua","serif"; font-size: 13.0pt;">4. G1
Garbage Collector.</span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in;">
<span style="font-family: "Book Antiqua","serif"; font-size: 13.0pt;"><br /></span></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgmuiL5leFHdZKNlnzE9RpTmPSHF0XY5eeXV8HceCAMCX586XIbnhqkhtYZO6A2wk6urdFghqSsJVNfGb_AHnnO2iBM3aoeCb5Lf4JlPT2bxM46JqkMUsSvfO_JaCssUal8BhS-QQMC4Evs/s1600/maxresdefault.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="900" data-original-width="1600" height="360" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgmuiL5leFHdZKNlnzE9RpTmPSHF0XY5eeXV8HceCAMCX586XIbnhqkhtYZO6A2wk6urdFghqSsJVNfGb_AHnnO2iBM3aoeCb5Lf4JlPT2bxM46JqkMUsSvfO_JaCssUal8BhS-QQMC4Evs/s640/maxresdefault.jpg" width="640" /></a></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in;">
<br /></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in;">
<br /></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in;">
<span style="font-family: "Book Antiqua","serif"; font-size: 13.0pt;">Each
of these four types has its own Pros and Cons. Most importantly, we can choose
the type of garbage collector to be used by the JVM. This can be achieved by
passing the choice as JVM argument. Each of these types differ largely and can
provide completely different application performance therefore It is important
to understand each of these types of garbage collectors and use it rightly
based on the application.<o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in;">
<br /></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in;">
<b><span style="color: #002060; font-family: "Book Antiqua","serif"; font-size: 14.0pt; mso-bidi-font-size: 13.0pt;">1.
Serial Garbage Collector<o:p></o:p></span></b></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in;">
<span style="font-family: "Book Antiqua","serif"; font-size: 13.0pt;">Serial
garbage collector works by holding all the application threads. It is designed
for the single-threaded environments. It uses just a single thread for garbage
collection. This collector freezes all application threads whenever it’s
working, which disqualifies it for all intents and purposes from being used in
a server environment. It is best suited for simple command-line programs.<o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in;">
<br /></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in;">
<b><span style="color: #002060; font-family: "Book Antiqua","serif"; font-size: 13.0pt;">How to use it?<o:p></o:p></span></b></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in;">
<span style="font-family: "Book Antiqua","serif"; font-size: 13.0pt;">Turn
on the -XX:+UseSerialGC JVM argument to use the serial garbage collector.<o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in;">
<br /></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in;">
<b><span style="color: #002060; font-family: "Book Antiqua","serif"; font-size: 14.0pt; mso-bidi-font-size: 13.0pt;">2.
The Parallel / Throughput collector<o:p></o:p></span></b></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in;">
<span style="font-family: "Book Antiqua","serif"; font-size: 13.0pt;">Parallel
garbage collector is also called as throughput collector. It is the default
garbage collector of the JVM. Unlike serial garbage collector, its biggest
advantage is that multiple threads scan to through and compact the heap.
Similar to serial garbage collector this also freezes all the application
threads while performing garbage collection. The downside to the parallel
collector is that it will stop application threads when performing either a
minor or full GC collection. The parallel collector is best suited for apps
that can tolerate application pauses and are trying to optimize for lower CPU
overhead caused by the collector.<o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in;">
<br /></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in;">
<span style="font-family: "Book Antiqua","serif"; font-size: 13.0pt;">The
parallel garbage collector uses multiple threads to perform the young genertion
garbage collection.<o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in;">
<br /></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in;">
<span style="font-family: "Book Antiqua","serif"; font-size: 13.0pt;">By
default on a host with N CPUs, the parallel garbage collector uses N garbage
collector threads in the collection. The number of garbage collector threads
can be controlled with command-line options:<o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in;">
<span style="color: #002060; font-family: "Book Antiqua","serif"; font-size: 13.0pt;">-XX:ParallelGCThreads=<desired number><o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in;">
<br /></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in;">
<span style="font-family: "Book Antiqua","serif"; font-size: 13.0pt;">On a
host with a single CPU the default garbage collector is used even if the
parallel garbage collector has been requested. On a host with two CPUs the
parallel garbage collector generally performs as well as the default garbage
collector and a reduction in the young generation garbage collector pause times
can be expected on hosts with more than two CPUs. The Parallel GC comes in two
flavours.<o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in;">
<br /></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in;">
<b><span style="color: #002060; font-family: "Book Antiqua","serif"; font-size: 13.0pt;">Usage Cases<o:p></o:p></span></b></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in;">
<span style="font-family: Book Antiqua, serif;"><span style="font-size: 13pt;">The
Parallel collector is also called a throughput collector. Since it can use </span><span style="font-size: 17.3333px;">multiple</span><span style="font-size: 13pt;"> CPUs to speed up the application throughput. This collector should be used when
a lot of work need to be done and long pauses is acceptable.<o:p></o:p></span></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in;">
<b><span style="color: #002060; font-family: "Book Antiqua","serif"; font-size: 13.0pt;">For example</span></b><span style="font-family: "Book Antiqua","serif"; font-size: 13.0pt;">, batch processing
like printing reports or bills or performing a large number of database
queries.<o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in;">
<br /></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in;">
<b><span style="color: #002060; font-family: "Book Antiqua","serif"; font-size: 13.0pt;">How to use it?<o:p></o:p></span></b></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in;">
<span style="font-family: "Book Antiqua","serif"; font-size: 13.0pt;">Turn
on the -XX:+UseParallelGC JVM argument to use the serial garbage collector.<o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in;">
<br /></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in;">
<span style="font-family: "Book Antiqua","serif"; font-size: 13.0pt;">With
this command line option you get a multi-thread young generation collector with
a single-threaded old generation collector. The option also does
single-threaded compaction of old generation.<o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in;">
<br /></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in;">
<b><span style="color: #002060; font-family: "Book Antiqua","serif"; font-size: 13.0pt;">Command line to start the ParallelGCDemo:<o:p></o:p></span></b></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in;">
<span style="font-family: "Book Antiqua","serif"; font-size: 13.0pt;">java
-Xmx12m -Xms3m -Xmn1m -XX:PermSize=20m -XX:MaxPermSize=20m -XX:+UseParallelGC
-jar c:\javademos\demo\jfc\Java2D\ParallelGCDemo.jar<o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in;">
<br /></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in;">
<b><span style="color: #002060; font-family: "Book Antiqua","serif"; font-size: 13.0pt;">-XX:+UseParallelOldGC<o:p></o:p></span></b></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in;">
<span style="font-family: Book Antiqua, serif;"><span style="font-size: 13pt;">With
the -XX:+UseParallelOldGC option, the GC is both a </span><span style="font-size: 17.3333px;">multi threaded</span><span style="font-size: 13pt;"> young
generation collector and multithreaded old generation collector. It is also a
multithreaded compacting collector. HotSpot does compaction only in the old
generation. Young generation in HotSpot is considered a copy collector; therefore,
there is no need for compaction.<o:p></o:p></span></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in;">
<br /></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in;">
<span style="font-family: "Book Antiqua","serif"; font-size: 13.0pt;">Compacting
describes the act of moving objects in a way that there are no holes between
objects. After a garbage collection sweep, there may be holes left between live
objects. Compacting moves objects so that there are no remaining holes. It is
possible that a garbage collector be a non-compacting collector. Therefore, the
difference between a parallel collector and a parallel compacting collector
could be the latter compacts the space after a garbage collection sweep. The
former would not.<o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in;">
<br /></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in;">
<b><span style="color: #002060; font-family: "Book Antiqua","serif"; font-size: 13.0pt;">Command line to start the ParallelOldGCDemo:<o:p></o:p></span></b></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in;">
<span style="font-family: "Book Antiqua","serif"; font-size: 13.0pt;">java
-Xmx12m -Xms3m -Xmn1m -XX:PermSize=20m -XX:MaxPermSize=20m
-XX:+UseParallelOldGC -jar c:\javademos\demo\jfc\Java2D\ParallelOldGCdemo.jar<o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in;">
<br /></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in;">
<b><span style="color: #002060; font-family: "Book Antiqua","serif"; font-size: 14.0pt; mso-bidi-font-size: 13.0pt;">The
Concurrent Mark Sweep (CMS) Collector<o:p></o:p></span></b></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in;">
<span style="font-family: "Book Antiqua","serif"; font-size: 13.0pt;">CMS
collector (also referred to as the concurrent low pause collector) collects the
tenured generation. It attempts to minimize the pauses due to garbage
collection by doing most of the garbage collection work concurrently with the
application threads. Normally the concurrent low pause collector does not copy
or compact the live objects. A garbage collection is done without moving the
live objects. If fragmentation becomes a problem, allocate a larger heap.<o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in;">
<br /></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in;">
<span style="font-family: "Book Antiqua","serif"; font-size: 13.0pt;">Note:
CMS collector on young generation uses the same algorithm as that of the
parallel collector.<o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in;">
<br /></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in;">
<b><span style="color: #002060; font-family: "Book Antiqua","serif"; font-size: 13.0pt;">Usage Cases<o:p></o:p></span></b></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in;">
<span style="font-family: "Book Antiqua","serif"; font-size: 13.0pt;">The
CMS collector should be used for applications that require low pause times and
can share resources with the garbage collector.<o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in;">
<b><span style="color: #002060; font-family: "Book Antiqua","serif"; font-size: 13.0pt;">Examples:</span></b><span style="font-family: Book Antiqua, serif;"><span style="font-size: 13pt;"> Desktop UI
application that respond to events, a </span><span style="font-size: 17.3333px;">web-server</span><span style="font-size: 13pt;"> responding to a request or a
database responding to queries.<o:p></o:p></span></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in;">
<br /></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in;">
<b><span style="color: #002060; font-family: "Book Antiqua","serif"; font-size: 13.0pt;">Command Line Switches<o:p></o:p></span></b></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in;">
<span style="font-family: "Book Antiqua","serif"; font-size: 13.0pt;">To
enable the CMS Collector use:<o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in;">
<span style="font-family: "Book Antiqua","serif"; font-size: 13.0pt;">-XX:+UseConcMarkSweepGC</span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in;">
<span style="font-family: "Book Antiqua", serif; font-size: 13pt;"><br /></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in;">
<span style="font-family: "Book Antiqua", serif; font-size: 13pt;">To
set the number of threads use:</span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in;">
<span style="font-family: "Book Antiqua","serif"; font-size: 13.0pt;">-XX:ParallelCMSThreads=<n></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in;">
<b><span style="color: #002060; font-family: "Book Antiqua","serif"; font-size: 13.0pt;"><br /></span></b></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in;">
<b><span style="color: #002060; font-family: "Book Antiqua","serif"; font-size: 13.0pt;">Command line example to start
the ConcMarkSweepDemo:</span></b></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in;">
<span style="font-family: "Book Antiqua","serif"; font-size: 13.0pt;">java
-Xmx12m -Xms3m -Xmn1m -XX:PermSize=20m -XX:MaxPermSize=20m
-XX:+UseConcMarkSweepGC -XX:ParallelCMSThreads=2 -jar
c:\javademos\demo\jfc\Java2D\ConcMarkSweepdemo.jar</span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in;">
<b><span style="color: #002060; font-family: "Book Antiqua","serif"; font-size: 14.0pt; mso-bidi-font-size: 13.0pt;"><br /></span></b></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in;">
<b><span style="color: #002060; font-family: "Book Antiqua","serif"; font-size: 14.0pt; mso-bidi-font-size: 13.0pt;">The
G1 Garbage Collector</span></b></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in;">
<span style="font-family: "Book Antiqua","serif"; font-size: 13.0pt;">The
Garbage First or G1 garbage collector is available in Java 7 and is designed to
be the long term replacement for the CMS collector. The G1 collector is a
parallel, concurrent, and incrementally compacting low-pause garbage collector
that has quite a different layout from the other garbage collectors described
previously.</span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in;">
<b><span style="color: #002060; font-family: "Book Antiqua","serif"; font-size: 13.0pt;"><br /></span></b></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in;">
<b><span style="color: #002060; font-family: "Book Antiqua","serif"; font-size: 13.0pt;">Command Line Switches</span></b></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in;">
<span style="font-family: "Book Antiqua","serif"; font-size: 13.0pt;">To
enable the G1 Collector use:<o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in;">
<span style="font-family: "Book Antiqua","serif"; font-size: 13.0pt;">-XX:+UseG1GC</span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in;">
<b><span style="color: #002060; font-family: "Book Antiqua","serif"; font-size: 13.0pt;"><br /></span></b></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in;">
<b><span style="color: #002060; font-family: "Book Antiqua","serif"; font-size: 13.0pt;">Command line example to start
the G1GCDemo:</span></b></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in;">
<span style="font-family: "Book Antiqua","serif"; font-size: 13.0pt;">java
-Xmx12m -Xms3m -XX:+UseG1GC -jar c:\javademos\demo\jfc\Java2D\ G1GCDemo.jar</span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in;">
<br /></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in;">
<a href="https://docs.oracle.com/javase/8/docs/technotes/guides/vm/gctuning/parallel.html"><span style="font-family: "Book Antiqua","serif"; font-size: 13.0pt;">https://docs.oracle.com/javase/8/docs/technotes/guides/vm/gctuning/parallel.html</span></a><span style="font-family: "Book Antiqua","serif"; font-size: 13.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in;">
<span style="font-family: "Book Antiqua","serif"; font-size: 13.0pt;"><a href="http://www.oracle.com/webfolder/technetwork/tutorials/obe/java/gc01/index.html">http://www.oracle.com/webfolder/technetwork/tutorials/obe/java/gc01/index.html</a></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in;">
<br /></div>
</div>
javaexplor03http://www.blogger.com/profile/07455293496498711738noreply@blogger.com0tag:blogger.com,1999:blog-615973148715732292.post-16414601857329774952017-06-28T03:06:00.002-07:002017-06-28T03:07:32.156-07:00Minimize Cash Flow among the friends who have borrowed money from each other<div dir="ltr" style="text-align: left;" trbidi="on">
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in;">
<span style="font-family: "book antiqua", serif; font-size: 13pt;">There
are a number of friends who have to give or take some amount of money from one
another. Task is to design an algorithm by which the total cash flow among all
the friends is minimized.</span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in;">
<b><span style="color: #10253f; font-family: "book antiqua" , "serif"; font-size: 13.0pt;"><br /></span></b></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in;">
<b><span style="color: #10253f; font-family: "book antiqua" , "serif"; font-size: 13.0pt;">Approach#</span></b></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in;">
<span style="font-family: "book antiqua" , "serif"; font-size: 13.0pt;">The approach
is using the <b>Greedy algorithm</b> where
we are settling amount of one person (Debts or credits) at every step and
recurring the same for remaining n-1 persons.</span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in;">
<span style="font-family: "book antiqua" , serif; font-size: 13pt;"><br /></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in;">
<span style="font-family: "book antiqua" , serif; font-size: 13pt;">First,
we will calculate the net amount for every person where net amount is obtained
by subtracting all debts (amounts to pay) from all credits (amounts to be
paid). Once net amount for every person is evaluated, find two persons with
maximum and minimum net amounts. These two persons are the most creditors and
debtors. The person with minimum of two is our first person to be settled and
removed from list.</span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in;">
<br /></div>
<div style="background: #DBE5F1; border: solid windowtext 1.0pt; mso-background-themecolor: accent1; mso-background-themetint: 51; mso-border-alt: solid windowtext .5pt; mso-element: para-border-div; padding: 1.0pt 1.0pt 1.0pt 1.0pt;">
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="color: #7f0055; font-family: "consolas"; font-size: 12.0pt;">public</span><span style="font-family: "consolas"; font-size: 12pt;"> </span><span style="color: #7f0055; font-family: "consolas"; font-size: 12.0pt;">class</span><span style="font-family: "consolas"; font-size: 12pt;"> MinCashFlow {</span><span style="font-family: "consolas"; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: "consolas"; font-size: 12pt;"> </span><span style="font-family: "consolas"; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: "consolas"; font-size: 12pt;"> </span><span style="color: #3f5fbf; font-family: "consolas"; font-size: 12.0pt;">/** Recursively calling for next
transaction */</span><span style="font-family: "consolas"; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: "consolas"; font-size: 12pt;"> </span><span style="color: #7f0055; font-family: "consolas"; font-size: 12.0pt;">private</span><span style="font-family: "consolas"; font-size: 12pt;"> </span><span style="color: #7f0055; font-family: "consolas"; font-size: 12.0pt;">static</span><span style="font-family: "consolas"; font-size: 12pt;"> </span><span style="color: #7f0055; font-family: "consolas"; font-size: 12.0pt;">void</span><span style="font-family: "consolas"; font-size: 12pt;"> calculateTheFlow(</span><span style="color: #7f0055; font-family: "consolas"; font-size: 12.0pt;">int</span><span style="font-family: "consolas"; font-size: 12pt;">[]
</span><span style="color: #6a3e3e; font-family: "consolas"; font-size: 12.0pt;">amount</span><span style="font-family: "consolas"; font-size: 12pt;">) {</span><span style="font-family: "consolas"; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<br /></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: "consolas"; font-size: 12pt;"> </span><span style="color: #7f0055; font-family: "consolas"; font-size: 12.0pt;">int</span><span style="font-family: "consolas"; font-size: 12pt;"> </span><span style="color: #6a3e3e; font-family: "consolas"; font-size: 12.0pt;">maxDRIdx</span><span style="font-family: "consolas"; font-size: 12pt;"> = <i>getMaximumDRIdx</i>(</span><span style="color: #6a3e3e; font-family: "consolas"; font-size: 12.0pt;">amount</span><span style="font-family: "consolas"; font-size: 12pt;">);</span><span style="font-family: "consolas"; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: "consolas"; font-size: 12pt;"> </span><span style="color: #7f0055; font-family: "consolas"; font-size: 12.0pt;">int</span><span style="font-family: "consolas"; font-size: 12pt;"> </span><span style="color: #6a3e3e; font-family: "consolas"; font-size: 12.0pt;">maxCRIdx</span><span style="font-family: "consolas"; font-size: 12pt;"> = <i>getMaximumCRIdx</i>(</span><span style="color: #6a3e3e; font-family: "consolas"; font-size: 12.0pt;">amount</span><span style="font-family: "consolas"; font-size: 12pt;">);</span><span style="font-family: "consolas"; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<br /></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: "consolas"; font-size: 12pt;"> </span><span style="color: #7f0055; font-family: "consolas"; font-size: 12.0pt;">if</span><span style="font-family: "consolas"; font-size: 12pt;">(</span><span style="color: #6a3e3e; font-family: "consolas"; font-size: 12.0pt;">amount</span><span style="font-family: "consolas"; font-size: 12pt;">[</span><span style="color: #6a3e3e; font-family: "consolas"; font-size: 12.0pt;">maxDRIdx</span><span style="font-family: "consolas"; font-size: 12pt;">]==0 && </span><span style="color: #6a3e3e; font-family: "consolas"; font-size: 12.0pt;">amount</span><span style="font-family: "consolas"; font-size: 12pt;">[</span><span style="color: #6a3e3e; font-family: "consolas"; font-size: 12.0pt;">maxCRIdx</span><span style="font-family: "consolas"; font-size: 12pt;">]==0) {</span><span style="font-family: "consolas"; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: "consolas"; font-size: 12pt;"> </span><span style="color: #7f0055; font-family: "consolas"; font-size: 12.0pt;">return</span><span style="font-family: "consolas"; font-size: 12pt;">;</span><span style="font-family: "consolas"; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: "consolas"; font-size: 12pt;"> }</span><span style="font-family: "consolas"; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: "consolas"; font-size: 12pt;"> </span><span style="font-family: "consolas"; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: "consolas"; font-size: 12pt;"> </span><span style="color: #7f0055; font-family: "consolas"; font-size: 12.0pt;">int</span><span style="font-family: "consolas"; font-size: 12pt;"> </span><span style="color: #6a3e3e; font-family: "consolas"; font-size: 12.0pt;">crAmount</span><span style="font-family: "consolas"; font-size: 12pt;"> = </span><span style="color: #6a3e3e; font-family: "consolas"; font-size: 12.0pt;">amount</span><span style="font-family: "consolas"; font-size: 12pt;">[</span><span style="color: #6a3e3e; font-family: "consolas"; font-size: 12.0pt;">maxCRIdx</span><span style="font-family: "consolas"; font-size: 12pt;">];</span><span style="font-family: "consolas"; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: "consolas"; font-size: 12pt;"> </span><span style="color: #7f0055; font-family: "consolas"; font-size: 12.0pt;">int</span><span style="font-family: "consolas"; font-size: 12pt;"> </span><span style="color: #6a3e3e; font-family: "consolas"; font-size: 12.0pt;">drAmount</span><span style="font-family: "consolas"; font-size: 12pt;"> = </span><span style="color: #6a3e3e; font-family: "consolas"; font-size: 12.0pt;">amount</span><span style="font-family: "consolas"; font-size: 12pt;">[</span><span style="color: #6a3e3e; font-family: "consolas"; font-size: 12.0pt;">maxDRIdx</span><span style="font-family: "consolas"; font-size: 12pt;">];</span><span style="font-family: "consolas"; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: "consolas"; font-size: 12pt;"> </span><span style="font-family: "consolas"; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: "consolas"; font-size: 12pt;"> </span><span style="color: #7f0055; font-family: "consolas"; font-size: 12.0pt;">int</span><span style="font-family: "consolas"; font-size: 12pt;"> </span><span style="color: #6a3e3e; font-family: "consolas"; font-size: 12.0pt;">diff</span><span style="font-family: "consolas"; font-size: 12pt;"> = </span><span style="color: #6a3e3e; font-family: "consolas"; font-size: 12.0pt;">crAmount</span><span style="font-family: "consolas"; font-size: 12pt;"> + </span><span style="color: #6a3e3e; font-family: "consolas"; font-size: 12.0pt;">drAmount</span><span style="font-family: "consolas"; font-size: 12pt;">;</span><span style="font-family: "consolas"; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: "consolas"; font-size: 12pt;"> </span><span style="font-family: "consolas"; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: "consolas"; font-size: 12pt;"> </span><span style="color: #7f0055; font-family: "consolas"; font-size: 12.0pt;">if</span><span style="font-family: "consolas"; font-size: 12pt;">(</span><span style="color: #6a3e3e; font-family: "consolas"; font-size: 12.0pt;">diff</span><span style="font-family: "consolas"; font-size: 12pt;"><0) {</span><span style="font-family: "consolas"; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: "consolas"; font-size: 12pt;"> System.</span><i><span style="color: #0000c0; font-family: "consolas"; font-size: 12.0pt;">out</span></i><span style="font-family: "consolas"; font-size: 12pt;">.println(</span><span style="color: #2a00ff; font-family: "consolas"; font-size: 12.0pt;">"Person "</span><span style="font-family: "consolas"; font-size: 12pt;">+</span><span style="color: #6a3e3e; font-family: "consolas"; font-size: 12.0pt;">maxDRIdx</span><span style="font-family: "consolas"; font-size: 12pt;"> +</span><span style="color: #2a00ff; font-family: "consolas"; font-size: 12.0pt;">" will pay "</span><span style="font-family: "consolas"; font-size: 12pt;">+ </span><span style="color: #6a3e3e; font-family: "consolas"; font-size: 12.0pt;">crAmount</span><span style="font-family: "consolas"; font-size: 12pt;">+ </span><span style="color: #2a00ff; font-family: "consolas"; font-size: 12.0pt;">" rs. to pay
to "</span><span style="font-family: "consolas"; font-size: 12pt;">+</span><span style="color: #6a3e3e; font-family: "consolas"; font-size: 12.0pt;">maxCRIdx</span><span style="font-family: "consolas"; font-size: 12pt;">);</span><span style="font-family: "consolas"; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: "consolas"; font-size: 12pt;"> </span><span style="color: #6a3e3e; font-family: "consolas"; font-size: 12.0pt;">amount</span><span style="font-family: "consolas"; font-size: 12pt;">[</span><span style="color: #6a3e3e; font-family: "consolas"; font-size: 12.0pt;">maxCRIdx</span><span style="font-family: "consolas"; font-size: 12pt;">] = 0;</span><span style="font-family: "consolas"; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: "consolas"; font-size: 12pt;"> </span><span style="color: #6a3e3e; font-family: "consolas"; font-size: 12.0pt;">amount</span><span style="font-family: "consolas"; font-size: 12pt;">[</span><span style="color: #6a3e3e; font-family: "consolas"; font-size: 12.0pt;">maxDRIdx</span><span style="font-family: "consolas"; font-size: 12pt;">] = </span><span style="color: #6a3e3e; font-family: "consolas"; font-size: 12.0pt;">diff</span><span style="font-family: "consolas"; font-size: 12pt;">;</span><span style="font-family: "consolas"; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: "consolas"; font-size: 12pt;"> } </span><span style="color: #7f0055; font-family: "consolas"; font-size: 12.0pt;">else</span><span style="font-family: "consolas"; font-size: 12pt;"> {</span><span style="font-family: "consolas"; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: "consolas"; font-size: 12pt;"> System.</span><i><span style="color: #0000c0; font-family: "consolas"; font-size: 12.0pt;">out</span></i><span style="font-family: "consolas"; font-size: 12pt;">.println(</span><span style="color: #2a00ff; font-family: "consolas"; font-size: 12.0pt;">"Person "</span><span style="font-family: "consolas"; font-size: 12pt;">+</span><span style="color: #6a3e3e; font-family: "consolas"; font-size: 12.0pt;">maxDRIdx</span><span style="font-family: "consolas"; font-size: 12pt;"> +</span><span style="color: #2a00ff; font-family: "consolas"; font-size: 12.0pt;">" will pay "</span><span style="font-family: "consolas"; font-size: 12pt;">+ Math.<i>abs</i>(</span><span style="color: #6a3e3e; font-family: "consolas"; font-size: 12.0pt;">drAmount</span><span style="font-family: "consolas"; font-size: 12pt;">)+ </span><span style="color: #2a00ff; font-family: "consolas"; font-size: 12.0pt;">" rs. to pay
to "</span><span style="font-family: "consolas"; font-size: 12pt;">+</span><span style="color: #6a3e3e; font-family: "consolas"; font-size: 12.0pt;">maxCRIdx</span><span style="font-family: "consolas"; font-size: 12pt;">);</span><span style="font-family: "consolas"; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: "consolas"; font-size: 12pt;"> </span><span style="color: #6a3e3e; font-family: "consolas"; font-size: 12.0pt;">amount</span><span style="font-family: "consolas"; font-size: 12pt;">[</span><span style="color: #6a3e3e; font-family: "consolas"; font-size: 12.0pt;">maxDRIdx</span><span style="font-family: "consolas"; font-size: 12pt;">] = 0;</span><span style="font-family: "consolas"; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: "consolas"; font-size: 12pt;"> </span><span style="color: #6a3e3e; font-family: "consolas"; font-size: 12.0pt;">amount</span><span style="font-family: "consolas"; font-size: 12pt;">[</span><span style="color: #6a3e3e; font-family: "consolas"; font-size: 12.0pt;">maxCRIdx</span><span style="font-family: "consolas"; font-size: 12pt;">] = </span><span style="color: #6a3e3e; font-family: "consolas"; font-size: 12.0pt;">diff</span><span style="font-family: "consolas"; font-size: 12pt;">;</span><span style="font-family: "consolas"; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: "consolas"; font-size: 12pt;"> }</span><span style="font-family: "consolas"; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: "consolas"; font-size: 12pt;"> </span><span style="color: #3f7f5f; font-family: "consolas"; font-size: 12.0pt;">//printArray(amount);</span><span style="font-family: "consolas"; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: "consolas"; font-size: 12pt;"> <i>calculateTheFlow</i>(</span><span style="color: #6a3e3e; font-family: "consolas"; font-size: 12.0pt;">amount</span><span style="font-family: "consolas"; font-size: 12pt;">);</span><span style="font-family: "consolas"; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: "consolas"; font-size: 12pt;"> </span><span style="font-family: "consolas"; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: "consolas"; font-size: 12pt;"> }</span><span style="font-family: "consolas"; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<br /></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: "consolas"; font-size: 12pt;"> </span><span style="color: #3f5fbf; font-family: "consolas"; font-size: 12.0pt;">/** To get the maximum <u>debited</u>
amount. */</span><span style="font-family: "consolas"; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: "consolas"; font-size: 12pt;"> </span><span style="color: #7f0055; font-family: "consolas"; font-size: 12.0pt;">private</span><span style="font-family: "consolas"; font-size: 12pt;"> </span><span style="color: #7f0055; font-family: "consolas"; font-size: 12.0pt;">static</span><span style="font-family: "consolas"; font-size: 12pt;"> </span><span style="color: #7f0055; font-family: "consolas"; font-size: 12.0pt;">int</span><span style="font-family: "consolas"; font-size: 12pt;"> getMaximumDRIdx(</span><span style="color: #7f0055; font-family: "consolas"; font-size: 12.0pt;">int</span><span style="font-family: "consolas"; font-size: 12pt;">[]
</span><span style="color: #6a3e3e; font-family: "consolas"; font-size: 12.0pt;">amount</span><span style="font-family: "consolas"; font-size: 12pt;">) {</span><span style="font-family: "consolas"; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: "consolas"; font-size: 12pt;"> </span><span style="font-family: "consolas"; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: "consolas"; font-size: 12pt;"> </span><span style="color: #7f0055; font-family: "consolas"; font-size: 12.0pt;">if</span><span style="font-family: "consolas"; font-size: 12pt;">(</span><span style="color: #6a3e3e; font-family: "consolas"; font-size: 12.0pt;">amount</span><span style="font-family: "consolas"; font-size: 12pt;">.</span><span style="color: #0000c0; font-family: "consolas"; font-size: 12.0pt;">length</span><span style="font-family: "consolas"; font-size: 12pt;"><=1) {</span><span style="font-family: "consolas"; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: "consolas"; font-size: 12pt;"> </span><span style="color: #7f0055; font-family: "consolas"; font-size: 12.0pt;">return</span><span style="font-family: "consolas"; font-size: 12pt;"> 0;</span><span style="font-family: "consolas"; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: "consolas"; font-size: 12pt;"> }</span><span style="font-family: "consolas"; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<br /></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: "consolas"; font-size: 12pt;"> </span><span style="color: #7f0055; font-family: "consolas"; font-size: 12.0pt;">int</span><span style="font-family: "consolas"; font-size: 12pt;"> </span><span style="color: #6a3e3e; font-family: "consolas"; font-size: 12.0pt;">maxDRIdx</span><span style="font-family: "consolas"; font-size: 12pt;"> = 0;</span><span style="font-family: "consolas"; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: "consolas"; font-size: 12pt;"> </span><span style="color: #7f0055; font-family: "consolas"; font-size: 12.0pt;">int</span><span style="font-family: "consolas"; font-size: 12pt;"> </span><span style="color: #6a3e3e; font-family: "consolas"; font-size: 12.0pt;">min</span><span style="font-family: "consolas"; font-size: 12pt;"> = </span><span style="color: #6a3e3e; font-family: "consolas"; font-size: 12.0pt;">amount</span><span style="font-family: "consolas"; font-size: 12pt;">[0];</span><span style="font-family: "consolas"; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: "consolas"; font-size: 12pt;"> </span><span style="color: #7f0055; font-family: "consolas"; font-size: 12.0pt;">int</span><span style="font-family: "consolas"; font-size: 12pt;"> </span><span style="color: #6a3e3e; font-family: "consolas"; font-size: 12.0pt;">temp</span><span style="font-family: "consolas"; font-size: 12pt;"> = 0;</span><span style="font-family: "consolas"; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: "consolas"; font-size: 12pt;"> </span><span style="color: #7f0055; font-family: "consolas"; font-size: 12.0pt;">for</span><span style="font-family: "consolas"; font-size: 12pt;"> (</span><span style="color: #7f0055; font-family: "consolas"; font-size: 12.0pt;">int</span><span style="font-family: "consolas"; font-size: 12pt;">
</span><span style="color: #6a3e3e; font-family: "consolas"; font-size: 12.0pt;">i</span><span style="font-family: "consolas"; font-size: 12pt;"> = 1; </span><span style="color: #6a3e3e; font-family: "consolas"; font-size: 12.0pt;">i</span><span style="font-family: "consolas"; font-size: 12pt;"> < </span><span style="color: #6a3e3e; font-family: "consolas"; font-size: 12.0pt;">amount</span><span style="font-family: "consolas"; font-size: 12pt;">.</span><span style="color: #0000c0; font-family: "consolas"; font-size: 12.0pt;">length</span><span style="font-family: "consolas"; font-size: 12pt;">; </span><span style="color: #6a3e3e; font-family: "consolas"; font-size: 12.0pt;">i</span><span style="font-family: "consolas"; font-size: 12pt;">++) {</span><span style="font-family: "consolas"; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: "consolas"; font-size: 12pt;"> </span><span style="color: #7f0055; font-family: "consolas"; font-size: 12.0pt;">if</span><span style="font-family: "consolas"; font-size: 12pt;">(</span><span style="color: #6a3e3e; font-family: "consolas"; font-size: 12.0pt;">min</span><span style="font-family: "consolas"; font-size: 12pt;">>(</span><span style="color: #6a3e3e; font-family: "consolas"; font-size: 12.0pt;">temp</span><span style="font-family: "consolas"; font-size: 12pt;">=Math.<i>min</i>(</span><span style="color: #6a3e3e; font-family: "consolas"; font-size: 12.0pt;">min</span><span style="font-family: "consolas"; font-size: 12pt;">, </span><span style="color: #6a3e3e; font-family: "consolas"; font-size: 12.0pt;">amount</span><span style="font-family: "consolas"; font-size: 12pt;">[</span><span style="color: #6a3e3e; font-family: "consolas"; font-size: 12.0pt;">i</span><span style="font-family: "consolas"; font-size: 12pt;">]))) {</span><span style="font-family: "consolas"; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: "consolas"; font-size: 12pt;"> </span><span style="color: #6a3e3e; font-family: "consolas"; font-size: 12.0pt;">maxDRIdx</span><span style="font-family: "consolas"; font-size: 12pt;"> = </span><span style="color: #6a3e3e; font-family: "consolas"; font-size: 12.0pt;">i</span><span style="font-family: "consolas"; font-size: 12pt;">;</span><span style="font-family: "consolas"; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: "consolas"; font-size: 12pt;"> </span><span style="color: #6a3e3e; font-family: "consolas"; font-size: 12.0pt;">min</span><span style="font-family: "consolas"; font-size: 12pt;"> = </span><span style="color: #6a3e3e; font-family: "consolas"; font-size: 12.0pt;">temp</span><span style="font-family: "consolas"; font-size: 12pt;">;</span><span style="font-family: "consolas"; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: "consolas"; font-size: 12pt;"> }</span><span style="font-family: "consolas"; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: "consolas"; font-size: 12pt;"> }</span><span style="font-family: "consolas"; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<br /></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: "consolas"; font-size: 12pt;"> </span><span style="color: #7f0055; font-family: "consolas"; font-size: 12.0pt;">return</span><span style="font-family: "consolas"; font-size: 12pt;"> </span><span style="color: #6a3e3e; font-family: "consolas"; font-size: 12.0pt;">maxDRIdx</span><span style="font-family: "consolas"; font-size: 12pt;">;</span><span style="font-family: "consolas"; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: "consolas"; font-size: 12pt;"> }</span><span style="font-family: "consolas"; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<br /></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: "consolas"; font-size: 12pt;"> </span><span style="color: #3f5fbf; font-family: "consolas"; font-size: 12.0pt;">/**</span><span style="font-family: "consolas"; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="color: #3f5fbf; font-family: "consolas"; font-size: 12.0pt;"> * To
get the maximum credited amount.</span><span style="font-family: "consolas"; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="color: #3f5fbf; font-family: "consolas"; font-size: 12.0pt;"> */</span><span style="font-family: "consolas"; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: "consolas"; font-size: 12pt;"> </span><span style="color: #7f0055; font-family: "consolas"; font-size: 12.0pt;">private</span><span style="font-family: "consolas"; font-size: 12pt;"> </span><span style="color: #7f0055; font-family: "consolas"; font-size: 12.0pt;">static</span><span style="font-family: "consolas"; font-size: 12pt;"> </span><span style="color: #7f0055; font-family: "consolas"; font-size: 12.0pt;">int</span><span style="font-family: "consolas"; font-size: 12pt;"> getMaximumCRIdx(</span><span style="color: #7f0055; font-family: "consolas"; font-size: 12.0pt;">int</span><span style="font-family: "consolas"; font-size: 12pt;">[]
</span><span style="color: #6a3e3e; font-family: "consolas"; font-size: 12.0pt;">amount</span><span style="font-family: "consolas"; font-size: 12pt;">) {</span><span style="font-family: "consolas"; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: "consolas"; font-size: 12pt;"> </span><span style="font-family: "consolas"; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: "consolas"; font-size: 12pt;"> </span><span style="color: #7f0055; font-family: "consolas"; font-size: 12.0pt;">if</span><span style="font-family: "consolas"; font-size: 12pt;">(</span><span style="color: #6a3e3e; font-family: "consolas"; font-size: 12.0pt;">amount</span><span style="font-family: "consolas"; font-size: 12pt;">.</span><span style="color: #0000c0; font-family: "consolas"; font-size: 12.0pt;">length</span><span style="font-family: "consolas"; font-size: 12pt;"><=1) {</span><span style="font-family: "consolas"; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: "consolas"; font-size: 12pt;"> </span><span style="color: #7f0055; font-family: "consolas"; font-size: 12.0pt;">return</span><span style="font-family: "consolas"; font-size: 12pt;"> 0;</span><span style="font-family: "consolas"; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: "consolas"; font-size: 12pt;"> }</span><span style="font-family: "consolas"; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: "consolas"; font-size: 12pt;"> </span><span style="font-family: "consolas"; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: "consolas"; font-size: 12pt;"> </span><span style="color: #7f0055; font-family: "consolas"; font-size: 12.0pt;">int</span><span style="font-family: "consolas"; font-size: 12pt;"> </span><span style="color: #6a3e3e; font-family: "consolas"; font-size: 12.0pt;">maxCRIdx</span><span style="font-family: "consolas"; font-size: 12pt;"> = 0;</span><span style="font-family: "consolas"; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: "consolas"; font-size: 12pt;"> </span><span style="color: #7f0055; font-family: "consolas"; font-size: 12.0pt;">int</span><span style="font-family: "consolas"; font-size: 12pt;"> </span><span style="color: #6a3e3e; font-family: "consolas"; font-size: 12.0pt;">max</span><span style="font-family: "consolas"; font-size: 12pt;"> = </span><span style="color: #6a3e3e; font-family: "consolas"; font-size: 12.0pt;">amount</span><span style="font-family: "consolas"; font-size: 12pt;">[0];</span><span style="font-family: "consolas"; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: "consolas"; font-size: 12pt;"> </span><span style="color: #7f0055; font-family: "consolas"; font-size: 12.0pt;">int</span><span style="font-family: "consolas"; font-size: 12pt;"> </span><span style="color: #6a3e3e; font-family: "consolas"; font-size: 12.0pt;">temp</span><span style="font-family: "consolas"; font-size: 12pt;"> = 0;</span><span style="font-family: "consolas"; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: "consolas"; font-size: 12pt;"> </span><span style="color: #7f0055; font-family: "consolas"; font-size: 12.0pt;">for</span><span style="font-family: "consolas"; font-size: 12pt;"> (</span><span style="color: #7f0055; font-family: "consolas"; font-size: 12.0pt;">int</span><span style="font-family: "consolas"; font-size: 12pt;">
</span><span style="color: #6a3e3e; font-family: "consolas"; font-size: 12.0pt;">i</span><span style="font-family: "consolas"; font-size: 12pt;"> = 1; </span><span style="color: #6a3e3e; font-family: "consolas"; font-size: 12.0pt;">i</span><span style="font-family: "consolas"; font-size: 12pt;"> < </span><span style="color: #6a3e3e; font-family: "consolas"; font-size: 12.0pt;">amount</span><span style="font-family: "consolas"; font-size: 12pt;">.</span><span style="color: #0000c0; font-family: "consolas"; font-size: 12.0pt;">length</span><span style="font-family: "consolas"; font-size: 12pt;">; </span><span style="color: #6a3e3e; font-family: "consolas"; font-size: 12.0pt;">i</span><span style="font-family: "consolas"; font-size: 12pt;">++) {</span><span style="font-family: "consolas"; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: "consolas"; font-size: 12pt;"> </span><span style="color: #7f0055; font-family: "consolas"; font-size: 12.0pt;">if</span><span style="font-family: "consolas"; font-size: 12pt;">(</span><span style="color: #6a3e3e; font-family: "consolas"; font-size: 12.0pt;">max</span><span style="font-family: "consolas"; font-size: 12pt;"><(</span><span style="color: #6a3e3e; font-family: "consolas"; font-size: 12.0pt;">temp</span><span style="font-family: "consolas"; font-size: 12pt;">=Math.<i>max</i>(</span><span style="color: #6a3e3e; font-family: "consolas"; font-size: 12.0pt;">max</span><span style="font-family: "consolas"; font-size: 12pt;">, </span><span style="color: #6a3e3e; font-family: "consolas"; font-size: 12.0pt;">amount</span><span style="font-family: "consolas"; font-size: 12pt;">[</span><span style="color: #6a3e3e; font-family: "consolas"; font-size: 12.0pt;">i</span><span style="font-family: "consolas"; font-size: 12pt;">]))) {</span><span style="font-family: "consolas"; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: "consolas"; font-size: 12pt;"> </span><span style="color: #6a3e3e; font-family: "consolas"; font-size: 12.0pt;">maxCRIdx</span><span style="font-family: "consolas"; font-size: 12pt;"> = </span><span style="color: #6a3e3e; font-family: "consolas"; font-size: 12.0pt;">i</span><span style="font-family: "consolas"; font-size: 12pt;">;</span><span style="font-family: "consolas"; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: "consolas"; font-size: 12pt;"> </span><span style="color: #6a3e3e; font-family: "consolas"; font-size: 12.0pt;">max</span><span style="font-family: "consolas"; font-size: 12pt;"> = </span><span style="color: #6a3e3e; font-family: "consolas"; font-size: 12.0pt;">temp</span><span style="font-family: "consolas"; font-size: 12pt;">;</span><span style="font-family: "consolas"; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: "consolas"; font-size: 12pt;"> }</span><span style="font-family: "consolas"; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: "consolas"; font-size: 12pt;"> }</span><span style="font-family: "consolas"; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<br /></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: "consolas"; font-size: 12pt;"> </span><span style="color: #7f0055; font-family: "consolas"; font-size: 12.0pt;">return</span><span style="font-family: "consolas"; font-size: 12pt;"> </span><span style="color: #6a3e3e; font-family: "consolas"; font-size: 12.0pt;">maxCRIdx</span><span style="font-family: "consolas"; font-size: 12pt;">;</span><span style="font-family: "consolas"; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: "consolas"; font-size: 12pt;"> }</span><span style="font-family: "consolas"; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<br /></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: "consolas"; font-size: 12pt;"> </span><span style="color: #3f5fbf; font-family: "consolas"; font-size: 12.0pt;">/** Method to to calculate the minimum cash
flow. */</span><span style="font-family: "consolas"; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: "consolas"; font-size: 12pt;"> </span><span style="color: #7f0055; font-family: "consolas"; font-size: 12.0pt;">private</span><span style="font-family: "consolas"; font-size: 12pt;"> </span><span style="color: #7f0055; font-family: "consolas"; font-size: 12.0pt;">static</span><span style="font-family: "consolas"; font-size: 12pt;"> </span><span style="color: #7f0055; font-family: "consolas"; font-size: 12.0pt;">void</span><span style="font-family: "consolas"; font-size: 12pt;"> minCashFlow(</span><span style="color: #7f0055; font-family: "consolas"; font-size: 12.0pt;">int</span><span style="font-family: "consolas"; font-size: 12pt;">[][]
</span><span style="color: #6a3e3e; font-family: "consolas"; font-size: 12.0pt;">flowGraph</span><span style="font-family: "consolas"; font-size: 12pt;">) {</span><span style="font-family: "consolas"; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: "consolas"; font-size: 12pt;"> </span><span style="color: #7f0055; font-family: "consolas"; font-size: 12.0pt;">int</span><span style="font-family: "consolas"; font-size: 12pt;"> </span><span style="color: #6a3e3e; font-family: "consolas"; font-size: 12.0pt;">row</span><span style="font-family: "consolas"; font-size: 12pt;"> = </span><span style="color: #6a3e3e; font-family: "consolas"; font-size: 12.0pt;">flowGraph</span><span style="font-family: "consolas"; font-size: 12pt;">.</span><span style="color: #0000c0; font-family: "consolas"; font-size: 12.0pt;">length</span><span style="font-family: "consolas"; font-size: 12pt;">;</span><span style="font-family: "consolas"; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: "consolas"; font-size: 12pt;"> </span><span style="color: #7f0055; font-family: "consolas"; font-size: 12.0pt;">int</span><span style="font-family: "consolas"; font-size: 12pt;"> </span><span style="color: #6a3e3e; font-family: "consolas"; font-size: 12.0pt;">col</span><span style="font-family: "consolas"; font-size: 12pt;"> = </span><span style="color: #6a3e3e; font-family: "consolas"; font-size: 12.0pt;">flowGraph</span><span style="font-family: "consolas"; font-size: 12pt;">[0].</span><span style="color: #0000c0; font-family: "consolas"; font-size: 12.0pt;">length</span><span style="font-family: "consolas"; font-size: 12pt;">;</span><span style="font-family: "consolas"; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: "consolas"; font-size: 12pt;"> </span><span style="font-family: "consolas"; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: "consolas"; font-size: 12pt;"> </span><span style="color: #7f0055; font-family: "consolas"; font-size: 12.0pt;">int</span><span style="font-family: "consolas"; font-size: 12pt;"> </span><span style="color: #6a3e3e; font-family: "consolas"; font-size: 12.0pt;">amount</span><span style="font-family: "consolas"; font-size: 12pt;">[] = </span><span style="color: #7f0055; font-family: "consolas"; font-size: 12.0pt;">new</span><span style="font-family: "consolas"; font-size: 12pt;">
</span><span style="color: #7f0055; font-family: "consolas"; font-size: 12.0pt;">int</span><span style="font-family: "consolas"; font-size: 12pt;">[</span><span style="color: #6a3e3e; font-family: "consolas"; font-size: 12.0pt;">row</span><span style="font-family: "consolas"; font-size: 12pt;">];</span><span style="font-family: "consolas"; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: "consolas"; font-size: 12pt;"> </span><span style="font-family: "consolas"; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: "consolas"; font-size: 12pt;"> </span><span style="color: #3f5fbf; font-family: "consolas"; font-size: 12.0pt;">/**</span><span style="font-family: "consolas"; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="color: #3f5fbf; font-family: "consolas"; font-size: 12.0pt;">
* Calculate the net amount to be paid to person, and stores it in
amount[person].</span><span style="font-family: "consolas"; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="color: #3f5fbf; font-family: "consolas"; font-size: 12.0pt;">
* The value of amount[person] can be calculated by subtracting</span><span style="font-family: "consolas"; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="color: #3f5fbf; font-family: "consolas"; font-size: 12.0pt;">
* debts of 'person' from credits of 'person'</span><span style="font-family: "consolas"; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="color: #3f5fbf; font-family: "consolas"; font-size: 12.0pt;">
*/</span><span style="font-family: "consolas"; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: "consolas"; font-size: 12pt;"> </span><span style="color: #7f0055; font-family: "consolas"; font-size: 12.0pt;">for</span><span style="font-family: "consolas"; font-size: 12pt;"> (</span><span style="color: #7f0055; font-family: "consolas"; font-size: 12.0pt;">int</span><span style="font-family: "consolas"; font-size: 12pt;">
</span><span style="color: #6a3e3e; font-family: "consolas"; font-size: 12.0pt;">person</span><span style="font-family: "consolas"; font-size: 12pt;"> = 0; </span><span style="color: #6a3e3e; font-family: "consolas"; font-size: 12.0pt;">person</span><span style="font-family: "consolas"; font-size: 12pt;"> < </span><span style="color: #6a3e3e; font-family: "consolas"; font-size: 12.0pt;">row</span><span style="font-family: "consolas"; font-size: 12pt;">; </span><span style="color: #6a3e3e; font-family: "consolas"; font-size: 12.0pt;">person</span><span style="font-family: "consolas"; font-size: 12pt;">++) {</span><span style="font-family: "consolas"; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: "consolas"; font-size: 12pt;"> </span><span style="color: #7f0055; font-family: "consolas"; font-size: 12.0pt;">for</span><span style="font-family: "consolas"; font-size: 12pt;"> (</span><span style="color: #7f0055; font-family: "consolas"; font-size: 12.0pt;">int</span><span style="font-family: "consolas"; font-size: 12pt;">
</span><span style="color: #6a3e3e; font-family: "consolas"; font-size: 12.0pt;">j</span><span style="font-family: "consolas"; font-size: 12pt;"> = 0; </span><span style="color: #6a3e3e; font-family: "consolas"; font-size: 12.0pt;">j</span><span style="font-family: "consolas"; font-size: 12pt;"> < </span><span style="color: #6a3e3e; font-family: "consolas"; font-size: 12.0pt;">col</span><span style="font-family: "consolas"; font-size: 12pt;">; </span><span style="color: #6a3e3e; font-family: "consolas"; font-size: 12.0pt;">j</span><span style="font-family: "consolas"; font-size: 12pt;">++) {</span><span style="font-family: "consolas"; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: "consolas"; font-size: 12pt;"> </span><span style="color: #6a3e3e; font-family: "consolas"; font-size: 12.0pt;">amount</span><span style="font-family: "consolas"; font-size: 12pt;">[</span><span style="color: #6a3e3e; font-family: "consolas"; font-size: 12.0pt;">person</span><span style="font-family: "consolas"; font-size: 12pt;">] += </span><span style="color: #6a3e3e; font-family: "consolas"; font-size: 12.0pt;">flowGraph</span><span style="font-family: "consolas"; font-size: 12pt;">[</span><span style="color: #6a3e3e; font-family: "consolas"; font-size: 12.0pt;">j</span><span style="font-family: "consolas"; font-size: 12pt;">][</span><span style="color: #6a3e3e; font-family: "consolas"; font-size: 12.0pt;">person</span><span style="font-family: "consolas"; font-size: 12pt;">] - </span><span style="color: #6a3e3e; font-family: "consolas"; font-size: 12.0pt;">flowGraph</span><span style="font-family: "consolas"; font-size: 12pt;">[</span><span style="color: #6a3e3e; font-family: "consolas"; font-size: 12.0pt;">person</span><span style="font-family: "consolas"; font-size: 12pt;">][</span><span style="color: #6a3e3e; font-family: "consolas"; font-size: 12.0pt;">j</span><span style="font-family: "consolas"; font-size: 12pt;">];</span><span style="font-family: "consolas"; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: "consolas"; font-size: 12pt;"> }</span><span style="font-family: "consolas"; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: "consolas"; font-size: 12pt;"> }</span><span style="font-family: "consolas"; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: "consolas"; font-size: 12pt;"> </span><span style="font-family: "consolas"; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: "consolas"; font-size: 12pt;"> <i>printArray</i>(</span><span style="color: #6a3e3e; font-family: "consolas"; font-size: 12.0pt;">amount</span><span style="font-family: "consolas"; font-size: 12pt;">);</span><span style="font-family: "consolas"; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: "consolas"; font-size: 12pt;"> </span><span style="font-family: "consolas"; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: "consolas"; font-size: 12pt;"> </span><span style="font-family: "consolas"; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: "consolas"; font-size: 12pt;"> <i>calculateTheFlow</i>(</span><span style="color: #6a3e3e; font-family: "consolas"; font-size: 12.0pt;">amount</span><span style="font-family: "consolas"; font-size: 12pt;">);</span><span style="font-family: "consolas"; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: "consolas"; font-size: 12pt;"> }</span><span style="font-family: "consolas"; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: "consolas"; font-size: 12pt;"> </span><span style="font-family: "consolas"; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: "consolas"; font-size: 12pt;"> </span><span style="color: #3f5fbf; font-family: "consolas"; font-size: 12.0pt;">/** Utility to
print an array. */</span><span style="font-family: "consolas"; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: "consolas"; font-size: 12pt;"> </span><span style="color: #7f0055; font-family: "consolas"; font-size: 12.0pt;">private</span><span style="font-family: "consolas"; font-size: 12pt;"> </span><span style="color: #7f0055; font-family: "consolas"; font-size: 12.0pt;">static</span><span style="font-family: "consolas"; font-size: 12pt;"> </span><span style="color: #7f0055; font-family: "consolas"; font-size: 12.0pt;">void</span><span style="font-family: "consolas"; font-size: 12pt;"> printArray(</span><span style="color: #7f0055; font-family: "consolas"; font-size: 12.0pt;">int</span><span style="font-family: "consolas"; font-size: 12pt;">[]
</span><span style="color: #6a3e3e; font-family: "consolas"; font-size: 12.0pt;">amount</span><span style="font-family: "consolas"; font-size: 12pt;">) {</span><span style="font-family: "consolas"; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: "consolas"; font-size: 12pt;"> </span><span style="color: #7f0055; font-family: "consolas"; font-size: 12.0pt;">for</span><span style="font-family: "consolas"; font-size: 12pt;"> (</span><span style="color: #7f0055; font-family: "consolas"; font-size: 12.0pt;">int</span><span style="font-family: "consolas"; font-size: 12pt;">
</span><span style="color: #6a3e3e; font-family: "consolas"; font-size: 12.0pt;">i</span><span style="font-family: "consolas"; font-size: 12pt;"> : </span><span style="color: #6a3e3e; font-family: "consolas"; font-size: 12.0pt;">amount</span><span style="font-family: "consolas"; font-size: 12pt;">) {</span><span style="font-family: "consolas"; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: "consolas"; font-size: 12pt;"> System.</span><i><span style="color: #0000c0; font-family: "consolas"; font-size: 12.0pt;">out</span></i><span style="font-family: "consolas"; font-size: 12pt;">.print(</span><span style="color: #6a3e3e; font-family: "consolas"; font-size: 12.0pt;">i</span><span style="font-family: "consolas"; font-size: 12pt;">+</span><span style="color: #2a00ff; font-family: "consolas"; font-size: 12.0pt;">" "</span><span style="font-family: "consolas"; font-size: 12pt;">);</span><span style="font-family: "consolas"; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: "consolas"; font-size: 12pt;"> }</span><span style="font-family: "consolas"; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: "consolas"; font-size: 12pt;"> System.</span><i><span style="color: #0000c0; font-family: "consolas"; font-size: 12.0pt;">out</span></i><span style="font-family: "consolas"; font-size: 12pt;">.println();</span><span style="font-family: "consolas"; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: "consolas"; font-size: 12pt;"> }</span><span style="font-family: "consolas"; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: "consolas"; font-size: 12pt;"> </span><span style="font-family: "consolas"; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: "consolas"; font-size: 12pt;"> </span><span style="color: #3f5fbf; font-family: "consolas"; font-size: 12.0pt;">/** Driver method. */</span><span style="font-family: "consolas"; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: "consolas"; font-size: 12pt;"> </span><span style="color: #7f0055; font-family: "consolas"; font-size: 12.0pt;">public</span><span style="font-family: "consolas"; font-size: 12pt;"> </span><span style="color: #7f0055; font-family: "consolas"; font-size: 12.0pt;">static</span><span style="font-family: "consolas"; font-size: 12pt;"> </span><span style="color: #7f0055; font-family: "consolas"; font-size: 12.0pt;">void</span><span style="font-family: "consolas"; font-size: 12pt;"> main(String[] </span><span style="color: #6a3e3e; font-family: "consolas"; font-size: 12.0pt;">args</span><span style="font-family: "consolas"; font-size: 12pt;">) {</span><span style="font-family: "consolas"; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: "consolas"; font-size: 12pt;"> </span><span style="color: #3f5fbf; font-family: "consolas"; font-size: 12.0pt;">/** flowGraph[i][j] indicates the amount
that person i needs to pay person j.*/</span><span style="font-family: "consolas"; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: "consolas"; font-size: 12pt;"> </span><span style="color: #7f0055; font-family: "consolas"; font-size: 12.0pt;">int</span><span style="font-family: "consolas"; font-size: 12pt;">[][] </span><span style="color: #6a3e3e; font-family: "consolas"; font-size: 12.0pt;">flowGraph</span><span style="font-family: "consolas"; font-size: 12pt;"> = {{0, 2000, 3000},</span><span style="font-family: "consolas"; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: "consolas"; font-size: 12pt;"> {10000, 0, 6000},</span><span style="font-family: "consolas"; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: "consolas"; font-size: 12pt;"> {0, 0, 0},};</span><span style="font-family: "consolas"; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<br /></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: "consolas"; font-size: 12pt;"> </span><span style="color: #3f5fbf; font-family: "consolas"; font-size: 12.0pt;">/** Call the function which will calculate
the cash flow. */</span><span style="font-family: "consolas"; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: "consolas"; font-size: 12pt;"> <i>minCashFlow</i>(</span><span style="color: #6a3e3e; font-family: "consolas"; font-size: 12.0pt;">flowGraph</span><span style="font-family: "consolas"; font-size: 12pt;">);</span><span style="font-family: "consolas"; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: "consolas"; font-size: 12pt;"> }</span><span style="font-family: "consolas"; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: "consolas"; font-size: 12pt;">}</span><span style="font-family: "consolas"; font-size: 12.0pt;"><o:p></o:p></span></div>
</div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in;">
<br /></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in;">
<br /></div>
</div>
javaexplor03http://www.blogger.com/profile/07455293496498711738noreply@blogger.com0tag:blogger.com,1999:blog-615973148715732292.post-40300619695644605402017-06-27T06:38:00.000-07:002017-06-27T05:04:34.707-07:00When to use interface and abstract class?<div dir="ltr" style="text-align: left;" trbidi="on">
<div class="MsoNormal">
<span style="font-family: "book antiqua" , serif; font-size: 13pt;"><b>An abstract class can have shared state or
functionality.</b></span></div>
<div class="MsoNormal">
<span style="font-family: "book antiqua" , serif; font-size: 13pt;"><b><br /></b></span></div>
<div class="MsoNormal">
<span style="font-family: "book antiqua" , "serif"; font-size: 13.0pt; line-height: 115%;"><b>An interface is only a promise to provide the state or
functionality.</b><o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-family: "book antiqua" , "serif"; font-size: 13.0pt; line-height: 115%;"><br /></span></div>
<div class="MsoNormal">
<span style="font-family: "book antiqua" , "serif"; font-size: 13.0pt; line-height: 115%;">A good abstract class will reduce the amount of code
that has to be rewritten because its functionality or state can be shared. The
interface has no defined information to be shared.<o:p></o:p></span></div>
<br />
<div class="MsoNormal">
<span style="font-family: "book antiqua" , serif; font-size: 13pt;">In case of abstract classes we are defining
characteristics of an object type, specifying what an object is but in the case
of an interface we define a capability and we bond to provide that capability,
we are talking about establishing a contract about what the object can do.</span></div>
</div>
javaexplor03http://www.blogger.com/profile/07455293496498711738noreply@blogger.com0tag:blogger.com,1999:blog-615973148715732292.post-87246760012070261002017-06-27T05:03:00.004-07:002017-06-27T05:03:56.430-07:00Check if a singly linked list is palindrome or not<div dir="ltr" style="text-align: left;" trbidi="on">
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in;">
<span style="font-family: "Book Antiqua", serif; font-size: 13pt;">Given
a singly linked list of integers, check whether the linked list is palindrome
or not using O(1) space complexity.</span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in;">
<span style="font-family: "Book Antiqua", serif; font-size: 13pt;"><br /></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in;">
<span style="font-family: "Book Antiqua", serif; font-size: 13pt;">In
this approach, we need to modify the existing linked list.</span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in;">
<span style="font-family: "Book Antiqua","serif"; font-size: 13.0pt;">1)
Get the middle of the linked list.<o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in;">
<span style="font-family: "Book Antiqua","serif"; font-size: 13.0pt;">2)
Reverse the second half of the linked list.<o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in;">
<span style="font-family: "Book Antiqua","serif"; font-size: 13.0pt;">3)
Check if the first half and second half are identical.<o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in;">
<span style="font-family: "Book Antiqua","serif"; font-size: 13.0pt;">4)
Construct the original linked list by reversing the second half again and
attaching it back to the first half.</span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in;">
<span style="font-family: "Book Antiqua","serif"; font-size: 13.0pt;"><br /></span></div>
<div style="background: #DBE5F1; border: solid windowtext 1.0pt; mso-background-themecolor: accent1; mso-background-themetint: 51; mso-border-alt: solid windowtext .5pt; mso-element: para-border-div; padding: 1.0pt 1.0pt 1.0pt 1.0pt;">
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="color: #7f0055; font-family: Consolas; font-size: 12.0pt; mso-bidi-font-weight: bold;">package</span><span style="font-family: Consolas; font-size: 12pt;"> com.geeks;</span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="color: #3f5fbf; font-family: Consolas; font-size: 12.0pt;">/**</span><span style="font-family: Consolas; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="color: #3f5fbf; font-family: Consolas; font-size: 12.0pt;"> * Class to check whether integer list is palindrome
or not.</span><span style="font-family: Consolas; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="color: #3f5fbf; font-family: Consolas; font-size: 12.0pt;"> * </span><span style="color: #7f9fbf; font-family: Consolas; font-size: 12.0pt; mso-bidi-font-weight: bold;">@author</span><span style="color: #3f5fbf; font-family: Consolas; font-size: 12.0pt;"> rajesh.dixit</span><span style="font-family: Consolas; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="color: #3f5fbf; font-family: Consolas; font-size: 12.0pt;"> */</span><span style="font-family: Consolas; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="color: #7f0055; font-family: Consolas; font-size: 12.0pt; mso-bidi-font-weight: bold;">public</span><span style="font-family: Consolas; font-size: 12pt;"> </span><span style="color: #7f0055; font-family: Consolas; font-size: 12.0pt; mso-bidi-font-weight: bold;">class</span><span style="font-family: Consolas; font-size: 12pt;"> PalidromeList {</span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: Consolas; font-size: 12pt;"> </span><span style="color: #3f5fbf; font-family: Consolas; font-size: 12.0pt;">/** Node definition. */</span><span style="font-family: Consolas; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: Consolas; font-size: 12pt;"> </span><span style="color: #7f0055; font-family: Consolas; font-size: 12.0pt; mso-bidi-font-weight: bold;">private</span><span style="font-family: Consolas; font-size: 12pt;"> </span><span style="color: #7f0055; font-family: Consolas; font-size: 12.0pt; mso-bidi-font-weight: bold;">static</span><span style="font-family: Consolas; font-size: 12pt;"> </span><span style="color: #7f0055; font-family: Consolas; font-size: 12.0pt; mso-bidi-font-weight: bold;">class</span><span style="font-family: Consolas; font-size: 12pt;"> Node {</span><span style="font-family: Consolas; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: Consolas; font-size: 12pt;"> </span><span style="color: #7f0055; font-family: Consolas; font-size: 12.0pt; mso-bidi-font-weight: bold;">int</span><span style="font-family: Consolas; font-size: 12pt;"> </span><span style="color: #0000c0; font-family: Consolas; font-size: 12.0pt;">data</span><span style="font-family: Consolas; font-size: 12pt;">; Node </span><span style="color: #0000c0; font-family: Consolas; font-size: 12.0pt;">next</span><span style="font-family: Consolas; font-size: 12pt;">;</span><span style="font-family: Consolas; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<br /></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: Consolas; font-size: 12pt;"> Node(</span><span style="color: #7f0055; font-family: Consolas; font-size: 12.0pt; mso-bidi-font-weight: bold;">int</span><span style="font-family: Consolas; font-size: 12pt;"> </span><span style="color: #6a3e3e; font-family: Consolas; font-size: 12.0pt;">data</span><span style="font-family: Consolas; font-size: 12pt;">) {</span><span style="font-family: Consolas; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: Consolas; font-size: 12pt;"> </span><span style="color: #7f0055; font-family: Consolas; font-size: 12.0pt; mso-bidi-font-weight: bold;">this</span><span style="font-family: Consolas; font-size: 12pt;">.</span><span style="color: #0000c0; font-family: Consolas; font-size: 12.0pt;">data</span><span style="font-family: Consolas; font-size: 12pt;"> = </span><span style="color: #6a3e3e; font-family: Consolas; font-size: 12.0pt;">data</span><span style="font-family: Consolas; font-size: 12pt;">;</span><span style="font-family: Consolas; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: Consolas; font-size: 12pt;"> </span><span style="color: #7f0055; font-family: Consolas; font-size: 12.0pt; mso-bidi-font-weight: bold;">this</span><span style="font-family: Consolas; font-size: 12pt;">.</span><span style="color: #0000c0; font-family: Consolas; font-size: 12.0pt;">next</span><span style="font-family: Consolas; font-size: 12pt;"> = </span><span style="color: #7f0055; font-family: Consolas; font-size: 12.0pt; mso-bidi-font-weight: bold;">null</span><span style="font-family: Consolas; font-size: 12pt;">;</span><span style="font-family: Consolas; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: Consolas; font-size: 12pt;"> }</span><span style="font-family: Consolas; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: Consolas; font-size: 12pt;"> }</span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: Consolas; font-size: 12pt;"><br /></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: Consolas; font-size: 12pt;"> </span><span style="color: #3f5fbf; font-family: Consolas; font-size: 12.0pt;">/**</span><span style="font-family: Consolas; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="color: #3f5fbf; font-family: Consolas; font-size: 12.0pt;"> * </span><span style="color: #7f9fbf; font-family: Consolas; font-size: 12.0pt; mso-bidi-font-weight: bold;">@param</span><span style="color: #3f5fbf; font-family: Consolas; font-size: 12.0pt;"> head</span><span style="font-family: Consolas; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="color: #3f5fbf; font-family: Consolas; font-size: 12.0pt;"> * </span><span style="color: #7f9fbf; font-family: Consolas; font-size: 12.0pt; mso-bidi-font-weight: bold;">@return</span><span style="color: #3f5fbf; font-family: Consolas; font-size: 12.0pt;"> String palindrome or not.</span><span style="font-family: Consolas; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="color: #3f5fbf; font-family: Consolas; font-size: 12.0pt;"> */</span><span style="font-family: Consolas; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: Consolas; font-size: 12pt;"> </span><span style="color: #7f0055; font-family: Consolas; font-size: 12.0pt; mso-bidi-font-weight: bold;">private</span><span style="font-family: Consolas; font-size: 12pt;"> </span><span style="color: #7f0055; font-family: Consolas; font-size: 12.0pt; mso-bidi-font-weight: bold;">static</span><span style="font-family: Consolas; font-size: 12pt;"> String checkListIsPalindrome(Node </span><span style="color: #6a3e3e; font-family: Consolas; font-size: 12.0pt;">head</span><span style="font-family: Consolas; font-size: 12pt;">) {</span><span style="font-family: Consolas; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: Consolas; font-size: 12pt;"> </span><span style="color: #7f0055; font-family: Consolas; font-size: 12.0pt; mso-bidi-font-weight: bold;">boolean</span><span style="font-family: Consolas; font-size: 12pt;"> </span><span style="color: #6a3e3e; font-family: Consolas; font-size: 12.0pt;">result</span><span style="font-family: Consolas; font-size: 12pt;"> = </span><span style="color: #7f0055; font-family: Consolas; font-size: 12.0pt; mso-bidi-font-weight: bold;">false</span><span style="font-family: Consolas; font-size: 12pt;">;</span><span style="font-family: Consolas; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<br /></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: Consolas; font-size: 12pt;"> </span><span style="color: #7f0055; font-family: Consolas; font-size: 12.0pt; mso-bidi-font-weight: bold;">if</span><span style="font-family: Consolas; font-size: 12pt;">(</span><span style="color: #6a3e3e; font-family: Consolas; font-size: 12.0pt;">head</span><span style="font-family: Consolas; font-size: 12pt;">==</span><span style="color: #7f0055; font-family: Consolas; font-size: 12.0pt; mso-bidi-font-weight: bold;">null</span><span style="font-family: Consolas; font-size: 12pt;">)
{</span><span style="font-family: Consolas; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: Consolas; font-size: 12pt;"> System.</span><i><span style="color: #0000c0; font-family: Consolas; font-size: 12.0pt; mso-bidi-font-weight: bold;">out</span></i><span style="font-family: Consolas; font-size: 12pt;">.println(</span><span style="color: #2a00ff; font-family: Consolas; font-size: 12.0pt;">"List is null"</span><span style="font-family: Consolas; font-size: 12pt;">);</span><span style="font-family: Consolas; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: Consolas; font-size: 12pt;"> } </span><span style="color: #7f0055; font-family: Consolas; font-size: 12.0pt; mso-bidi-font-weight: bold;">else</span><span style="font-family: Consolas; font-size: 12pt;"> </span><span style="color: #7f0055; font-family: Consolas; font-size: 12.0pt; mso-bidi-font-weight: bold;">if</span><span style="font-family: Consolas; font-size: 12pt;">(</span><span style="color: #6a3e3e; font-family: Consolas; font-size: 12.0pt;">head</span><span style="font-family: Consolas; font-size: 12pt;">.</span><span style="color: #0000c0; font-family: Consolas; font-size: 12.0pt;">next</span><span style="font-family: Consolas; font-size: 12pt;">==</span><span style="color: #7f0055; font-family: Consolas; font-size: 12.0pt; mso-bidi-font-weight: bold;">null</span><span style="font-family: Consolas; font-size: 12pt;">)
{</span><span style="font-family: Consolas; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: Consolas; font-size: 12pt;"> </span><span style="color: #6a3e3e; font-family: Consolas; font-size: 12.0pt;">result</span><span style="font-family: Consolas; font-size: 12pt;"> = </span><span style="color: #7f0055; font-family: Consolas; font-size: 12.0pt; mso-bidi-font-weight: bold;">true</span><span style="font-family: Consolas; font-size: 12pt;">;</span><span style="font-family: Consolas; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: Consolas; font-size: 12pt;"> } </span><span style="color: #7f0055; font-family: Consolas; font-size: 12.0pt; mso-bidi-font-weight: bold;">else</span><span style="font-family: Consolas; font-size: 12pt;"> </span><span style="color: #7f0055; font-family: Consolas; font-size: 12.0pt; mso-bidi-font-weight: bold;">if</span><span style="font-family: Consolas; font-size: 12pt;">(</span><span style="color: #6a3e3e; font-family: Consolas; font-size: 12.0pt;">head</span><span style="font-family: Consolas; font-size: 12pt;">.</span><span style="color: #0000c0; font-family: Consolas; font-size: 12.0pt;">next</span><span style="font-family: Consolas; font-size: 12pt;">.</span><span style="color: #0000c0; font-family: Consolas; font-size: 12.0pt;">next</span><span style="font-family: Consolas; font-size: 12pt;">==</span><span style="color: #7f0055; font-family: Consolas; font-size: 12.0pt; mso-bidi-font-weight: bold;">null</span><span style="font-family: Consolas; font-size: 12pt;">)
{</span><span style="font-family: Consolas; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: Consolas; font-size: 12pt;"> </span><span style="color: #6a3e3e; font-family: Consolas; font-size: 12.0pt;">result</span><span style="font-family: Consolas; font-size: 12pt;"> = (</span><span style="color: #6a3e3e; font-family: Consolas; font-size: 12.0pt;">head</span><span style="font-family: Consolas; font-size: 12pt;">.</span><span style="color: #0000c0; font-family: Consolas; font-size: 12.0pt;">data</span><span style="font-family: Consolas; font-size: 12pt;"> == </span><span style="color: #6a3e3e; font-family: Consolas; font-size: 12.0pt;">head</span><span style="font-family: Consolas; font-size: 12pt;">.</span><span style="color: #0000c0; font-family: Consolas; font-size: 12.0pt;">next</span><span style="font-family: Consolas; font-size: 12pt;">.</span><span style="color: #0000c0; font-family: Consolas; font-size: 12.0pt;">data</span><span style="font-family: Consolas; font-size: 12pt;">);</span><span style="font-family: Consolas; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: Consolas; font-size: 12pt;"> } </span><span style="color: #7f0055; font-family: Consolas; font-size: 12.0pt; mso-bidi-font-weight: bold;">else</span><span style="font-family: Consolas; font-size: 12pt;"> {</span><span style="font-family: Consolas; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<br /></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: Consolas; font-size: 12pt;"> </span><span style="color: #3f5fbf; font-family: Consolas; font-size: 12.0pt;">/** Reverse the second half of
linked list. */</span><span style="font-family: Consolas; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: Consolas; font-size: 12pt;"> </span><span style="color: #7f0055; font-family: Consolas; font-size: 12.0pt; mso-bidi-font-weight: bold;">int</span><span style="font-family: Consolas; font-size: 12pt;"> </span><span style="color: #6a3e3e; font-family: Consolas; font-size: 12.0pt;">len</span><span style="font-family: Consolas; font-size: 12pt;"> = <i>reverseSecondHalfOfList</i>(</span><span style="color: #6a3e3e; font-family: Consolas; font-size: 12.0pt;">head</span><span style="font-family: Consolas; font-size: 12pt;">);</span><span style="font-family: Consolas; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: Consolas; font-size: 12pt;"> </span><span style="font-family: Consolas; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: Consolas; font-size: 12pt;"> </span><span style="color: #6a3e3e; font-family: Consolas; font-size: 12.0pt;">result</span><span style="font-family: Consolas; font-size: 12pt;"> = <i>compareList</i>(</span><span style="color: #6a3e3e; font-family: Consolas; font-size: 12.0pt;">head</span><span style="font-family: Consolas; font-size: 12pt;">, </span><span style="color: #6a3e3e; font-family: Consolas; font-size: 12.0pt;">len</span><span style="font-family: Consolas; font-size: 12pt;">);</span><span style="font-family: Consolas; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<br /></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: Consolas; font-size: 12pt;"> </span><span style="color: #3f5fbf; font-family: Consolas; font-size: 12.0pt;">/** Reverse the second half of
linked list to get original list. */</span><span style="font-family: Consolas; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: Consolas; font-size: 12pt;"> <i>reverseSecondHalfOfList</i>(</span><span style="color: #6a3e3e; font-family: Consolas; font-size: 12.0pt;">head</span><span style="font-family: Consolas; font-size: 12pt;">);</span><span style="font-family: Consolas; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: Consolas; font-size: 12pt;"> }</span><span style="font-family: Consolas; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: Consolas; font-size: 12pt;"> </span><span style="color: #7f0055; font-family: Consolas; font-size: 12.0pt; mso-bidi-font-weight: bold;">return</span><span style="font-family: Consolas; font-size: 12pt;"> </span><span style="color: #6a3e3e; font-family: Consolas; font-size: 12.0pt;">result</span><span style="font-family: Consolas; font-size: 12pt;"> == </span><span style="color: #7f0055; font-family: Consolas; font-size: 12.0pt; mso-bidi-font-weight: bold;">true</span><span style="font-family: Consolas; font-size: 12pt;">?</span><span style="color: #2a00ff; font-family: Consolas; font-size: 12.0pt;">"Palindome"</span><span style="font-family: Consolas; font-size: 12pt;">:</span><span style="color: #2a00ff; font-family: Consolas; font-size: 12.0pt;">"Not
Palindrome"</span><span style="font-family: Consolas; font-size: 12pt;">;</span><span style="font-family: Consolas; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: Consolas; font-size: 12pt;"> }</span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: Consolas; font-size: 12pt;"><br /></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: Consolas; font-size: 12pt;"> </span><span style="color: #3f5fbf; font-family: Consolas; font-size: 12.0pt;">/**</span><span style="font-family: Consolas; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="color: #3f5fbf; font-family: Consolas; font-size: 12.0pt;"> *
Compare first and second half of list.</span><span style="font-family: Consolas; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="color: #3f5fbf; font-family: Consolas; font-size: 12.0pt;"> * </span><span style="color: #7f9fbf; font-family: Consolas; font-size: 12.0pt; mso-bidi-font-weight: bold;">@param</span><span style="color: #3f5fbf; font-family: Consolas; font-size: 12.0pt;"> head</span><span style="font-family: Consolas; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="color: #3f5fbf; font-family: Consolas; font-size: 12.0pt;"> * </span><span style="color: #7f9fbf; font-family: Consolas; font-size: 12.0pt; mso-bidi-font-weight: bold;">@param</span><span style="color: #3f5fbf; font-family: Consolas; font-size: 12.0pt;"> length</span><span style="font-family: Consolas; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="color: #3f5fbf; font-family: Consolas; font-size: 12.0pt;"> * </span><span style="color: #7f9fbf; font-family: Consolas; font-size: 12.0pt; mso-bidi-font-weight: bold;">@return</span><span style="font-family: Consolas; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="color: #3f5fbf; font-family: Consolas; font-size: 12.0pt;"> */</span><span style="font-family: Consolas; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: Consolas; font-size: 12pt;"> </span><span style="color: #7f0055; font-family: Consolas; font-size: 12.0pt; mso-bidi-font-weight: bold;">private</span><span style="font-family: Consolas; font-size: 12pt;"> </span><span style="color: #7f0055; font-family: Consolas; font-size: 12.0pt; mso-bidi-font-weight: bold;">static</span><span style="font-family: Consolas; font-size: 12pt;"> </span><span style="color: #7f0055; font-family: Consolas; font-size: 12.0pt; mso-bidi-font-weight: bold;">boolean</span><span style="font-family: Consolas; font-size: 12pt;"> compareList(Node </span><span style="color: #6a3e3e; font-family: Consolas; font-size: 12.0pt;">head</span><span style="font-family: Consolas; font-size: 12pt;">, </span><span style="color: #7f0055; font-family: Consolas; font-size: 12.0pt; mso-bidi-font-weight: bold;">int</span><span style="font-family: Consolas; font-size: 12pt;">
</span><span style="color: #6a3e3e; font-family: Consolas; font-size: 12.0pt;">length</span><span style="font-family: Consolas; font-size: 12pt;">) {</span><span style="font-family: Consolas; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: Consolas; font-size: 12pt;"> </span><span style="color: #7f0055; font-family: Consolas; font-size: 12.0pt; mso-bidi-font-weight: bold;">int</span><span style="font-family: Consolas; font-size: 12pt;"> </span><span style="color: #6a3e3e; font-family: Consolas; font-size: 12.0pt;">counter</span><span style="font-family: Consolas; font-size: 12pt;"> = 0;</span><span style="font-family: Consolas; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: Consolas; font-size: 12pt;"> Node </span><span style="color: #6a3e3e; font-family: Consolas; font-size: 12.0pt;">start</span><span style="font-family: Consolas; font-size: 12pt;"> = </span><span style="color: #6a3e3e; font-family: Consolas; font-size: 12.0pt;">head</span><span style="font-family: Consolas; font-size: 12pt;">;</span><span style="font-family: Consolas; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: Consolas; font-size: 12pt;"> Node </span><span style="color: #6a3e3e; font-family: Consolas; font-size: 12.0pt;">end</span><span style="font-family: Consolas; font-size: 12pt;"> = </span><span style="color: #6a3e3e; font-family: Consolas; font-size: 12.0pt;">head</span><span style="font-family: Consolas; font-size: 12pt;">;</span><span style="font-family: Consolas; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: Consolas; font-size: 12pt;"> Node </span><span style="color: #6a3e3e; font-family: Consolas; font-size: 12.0pt;">secHalf</span><span style="font-family: Consolas; font-size: 12pt;"> = </span><span style="color: #6a3e3e; font-family: Consolas; font-size: 12.0pt;">head</span><span style="font-family: Consolas; font-size: 12pt;">;</span><span style="font-family: Consolas; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<br /></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: Consolas; font-size: 12pt;"> </span><span style="color: #7f0055; font-family: Consolas; font-size: 12.0pt; mso-bidi-font-weight: bold;">while</span><span style="font-family: Consolas; font-size: 12pt;">(</span><span style="color: #7f0055; font-family: Consolas; font-size: 12.0pt; mso-bidi-font-weight: bold;">true</span><span style="font-family: Consolas; font-size: 12pt;">)
{</span><span style="font-family: Consolas; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: Consolas; font-size: 12pt;"> </span><span style="color: #7f0055; font-family: Consolas; font-size: 12.0pt; mso-bidi-font-weight: bold;">if</span><span style="font-family: Consolas; font-size: 12pt;">(</span><span style="color: #6a3e3e; font-family: Consolas; font-size: 12.0pt;">counter</span><span style="font-family: Consolas; font-size: 12pt;">++<</span><span style="color: #6a3e3e; font-family: Consolas; font-size: 12.0pt;">length</span><span style="font-family: Consolas; font-size: 12pt;">) {</span><span style="font-family: Consolas; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: Consolas; font-size: 12pt;"> </span><span style="color: #6a3e3e; font-family: Consolas; font-size: 12.0pt;">end</span><span style="font-family: Consolas; font-size: 12pt;"> = </span><span style="color: #6a3e3e; font-family: Consolas; font-size: 12.0pt;">end</span><span style="font-family: Consolas; font-size: 12pt;">.</span><span style="color: #0000c0; font-family: Consolas; font-size: 12.0pt;">next</span><span style="font-family: Consolas; font-size: 12pt;">;</span><span style="font-family: Consolas; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: Consolas; font-size: 12pt;"> } </span><span style="color: #7f0055; font-family: Consolas; font-size: 12.0pt; mso-bidi-font-weight: bold;">else</span><span style="font-family: Consolas; font-size: 12pt;"> {</span><span style="font-family: Consolas; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: Consolas; font-size: 12pt;"> </span><span style="color: #6a3e3e; font-family: Consolas; font-size: 12.0pt;">secHalf</span><span style="font-family: Consolas; font-size: 12pt;"> = </span><span style="color: #6a3e3e; font-family: Consolas; font-size: 12.0pt;">secHalf</span><span style="font-family: Consolas; font-size: 12pt;">.</span><span style="color: #0000c0; font-family: Consolas; font-size: 12.0pt;">next</span><span style="font-family: Consolas; font-size: 12pt;">;</span><span style="font-family: Consolas; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: Consolas; font-size: 12pt;"> </span><span style="color: #6a3e3e; font-family: Consolas; font-size: 12.0pt;">end</span><span style="font-family: Consolas; font-size: 12pt;"> = </span><span style="color: #6a3e3e; font-family: Consolas; font-size: 12.0pt;">end</span><span style="font-family: Consolas; font-size: 12pt;">.</span><span style="color: #0000c0; font-family: Consolas; font-size: 12.0pt;">next</span><span style="font-family: Consolas; font-size: 12pt;">;</span><span style="font-family: Consolas; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: Consolas; font-size: 12pt;"> </span><span style="color: #7f0055; font-family: Consolas; font-size: 12.0pt; mso-bidi-font-weight: bold;">if</span><span style="font-family: Consolas; font-size: 12pt;">(</span><span style="color: #6a3e3e; font-family: Consolas; font-size: 12.0pt;">end</span><span style="font-family: Consolas; font-size: 12pt;">==</span><span style="color: #7f0055; font-family: Consolas; font-size: 12.0pt; mso-bidi-font-weight: bold;">null</span><span style="font-family: Consolas; font-size: 12pt;">)
{</span><span style="font-family: Consolas; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: Consolas; font-size: 12pt;"> </span><span style="color: #7f0055; font-family: Consolas; font-size: 12.0pt; mso-bidi-font-weight: bold;">break</span><span style="font-family: Consolas; font-size: 12pt;">;</span><span style="font-family: Consolas; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: Consolas; font-size: 12pt;"> }</span><span style="font-family: Consolas; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: Consolas; font-size: 12pt;"> }</span><span style="font-family: Consolas; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: Consolas; font-size: 12pt;"> }</span><span style="font-family: Consolas; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<br /></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: Consolas; font-size: 12pt;"> </span><span style="color: #7f0055; font-family: Consolas; font-size: 12.0pt; mso-bidi-font-weight: bold;">boolean</span><span style="font-family: Consolas; font-size: 12pt;"> </span><span style="color: #6a3e3e; font-family: Consolas; font-size: 12.0pt;">result</span><span style="font-family: Consolas; font-size: 12pt;"> = </span><span style="color: #7f0055; font-family: Consolas; font-size: 12.0pt; mso-bidi-font-weight: bold;">true</span><span style="font-family: Consolas; font-size: 12pt;">;</span><span style="font-family: Consolas; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: Consolas; font-size: 12pt;"> </span><span style="color: #7f0055; font-family: Consolas; font-size: 12.0pt; mso-bidi-font-weight: bold;">while</span><span style="font-family: Consolas; font-size: 12pt;">(</span><span style="color: #6a3e3e; font-family: Consolas; font-size: 12.0pt;">result</span><span style="font-family: Consolas; font-size: 12pt;"> && </span><span style="color: #6a3e3e; font-family: Consolas; font-size: 12.0pt;">secHalf</span><span style="font-family: Consolas; font-size: 12pt;"> !=</span><span style="color: #7f0055; font-family: Consolas; font-size: 12.0pt; mso-bidi-font-weight: bold;">null</span><span style="font-family: Consolas; font-size: 12pt;">)
{</span><span style="font-family: Consolas; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: Consolas; font-size: 12pt;"> </span><span style="color: #6a3e3e; font-family: Consolas; font-size: 12.0pt;">result</span><span style="font-family: Consolas; font-size: 12pt;"> = (</span><span style="color: #6a3e3e; font-family: Consolas; font-size: 12.0pt;">start</span><span style="font-family: Consolas; font-size: 12pt;">.</span><span style="color: #0000c0; font-family: Consolas; font-size: 12.0pt;">data</span><span style="font-family: Consolas; font-size: 12pt;">==</span><span style="color: #6a3e3e; font-family: Consolas; font-size: 12.0pt;">secHalf</span><span style="font-family: Consolas; font-size: 12pt;">.</span><span style="color: #0000c0; font-family: Consolas; font-size: 12.0pt;">data</span><span style="font-family: Consolas; font-size: 12pt;">);</span><span style="font-family: Consolas; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: Consolas; font-size: 12pt;"> </span><span style="color: #6a3e3e; font-family: Consolas; font-size: 12.0pt;">start</span><span style="font-family: Consolas; font-size: 12pt;"> = </span><span style="color: #6a3e3e; font-family: Consolas; font-size: 12.0pt;">start</span><span style="font-family: Consolas; font-size: 12pt;">.</span><span style="color: #0000c0; font-family: Consolas; font-size: 12.0pt;">next</span><span style="font-family: Consolas; font-size: 12pt;">;</span><span style="font-family: Consolas; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: Consolas; font-size: 12pt;"> </span><span style="color: #6a3e3e; font-family: Consolas; font-size: 12.0pt;">secHalf</span><span style="font-family: Consolas; font-size: 12pt;"> = </span><span style="color: #6a3e3e; font-family: Consolas; font-size: 12.0pt;">secHalf</span><span style="font-family: Consolas; font-size: 12pt;">.</span><span style="color: #0000c0; font-family: Consolas; font-size: 12.0pt;">next</span><span style="font-family: Consolas; font-size: 12pt;">;</span><span style="font-family: Consolas; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: Consolas; font-size: 12pt;"> }</span><span style="font-family: Consolas; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: Consolas; font-size: 12pt;"> </span><span style="color: #7f0055; font-family: Consolas; font-size: 12.0pt; mso-bidi-font-weight: bold;">return</span><span style="font-family: Consolas; font-size: 12pt;"> </span><span style="color: #6a3e3e; font-family: Consolas; font-size: 12.0pt;">result</span><span style="font-family: Consolas; font-size: 12pt;">;</span><span style="font-family: Consolas; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: Consolas; font-size: 12pt;"> }</span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: Consolas; font-size: 12pt;"><br /></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: Consolas; font-size: 12pt;"> </span><span style="color: #3f5fbf; font-family: Consolas; font-size: 12.0pt;">/** Reverse the second half of the list. */</span><span style="font-family: Consolas; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: Consolas; font-size: 12pt;"> </span><span style="color: #7f0055; font-family: Consolas; font-size: 12.0pt; mso-bidi-font-weight: bold;">private</span><span style="font-family: Consolas; font-size: 12pt;"> </span><span style="color: #7f0055; font-family: Consolas; font-size: 12.0pt; mso-bidi-font-weight: bold;">static</span><span style="font-family: Consolas; font-size: 12pt;"> </span><span style="color: #7f0055; font-family: Consolas; font-size: 12.0pt; mso-bidi-font-weight: bold;">int</span><span style="font-family: Consolas; font-size: 12pt;"> reverseSecondHalfOfList(Node </span><span style="color: #6a3e3e; font-family: Consolas; font-size: 12.0pt;">head</span><span style="font-family: Consolas; font-size: 12pt;">) {</span><span style="font-family: Consolas; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: Consolas; font-size: 12pt;"> Node </span><span style="color: #6a3e3e; font-family: Consolas; font-size: 12.0pt;">p1</span><span style="font-family: Consolas; font-size: 12pt;"> = </span><span style="color: #6a3e3e; font-family: Consolas; font-size: 12.0pt;">head</span><span style="font-family: Consolas; font-size: 12pt;">.</span><span style="color: #0000c0; font-family: Consolas; font-size: 12.0pt;">next</span><span style="font-family: Consolas; font-size: 12pt;">;</span><span style="font-family: Consolas; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: Consolas; font-size: 12pt;"> Node </span><span style="color: #6a3e3e; font-family: Consolas; font-size: 12.0pt;">p2</span><span style="font-family: Consolas; font-size: 12pt;"> = </span><span style="color: #6a3e3e; font-family: Consolas; font-size: 12.0pt;">p1</span><span style="font-family: Consolas; font-size: 12pt;">.</span><span style="color: #0000c0; font-family: Consolas; font-size: 12.0pt;">next</span><span style="font-family: Consolas; font-size: 12pt;">;</span><span style="font-family: Consolas; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<br /></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: Consolas; font-size: 12pt;"> </span><span style="color: #7f0055; font-family: Consolas; font-size: 12.0pt; mso-bidi-font-weight: bold;">int</span><span style="font-family: Consolas; font-size: 12pt;"> </span><span style="color: #6a3e3e; font-family: Consolas; font-size: 12.0pt;">counter</span><span style="font-family: Consolas; font-size: 12pt;"> = 0;</span><span style="font-family: Consolas; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: Consolas; font-size: 12pt;"> </span><span style="color: #7f0055; font-family: Consolas; font-size: 12.0pt; mso-bidi-font-weight: bold;">while</span><span style="font-family: Consolas; font-size: 12pt;">(</span><span style="color: #6a3e3e; font-family: Consolas; font-size: 12.0pt;">p2</span><span style="font-family: Consolas; font-size: 12pt;">!=</span><span style="color: #7f0055; font-family: Consolas; font-size: 12.0pt; mso-bidi-font-weight: bold;">null</span><span style="font-family: Consolas; font-size: 12pt;">)
{</span><span style="font-family: Consolas; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: Consolas; font-size: 12pt;"> </span><span style="color: #6a3e3e; font-family: Consolas; font-size: 12.0pt;">counter</span><span style="font-family: Consolas; font-size: 12pt;">++;</span><span style="font-family: Consolas; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: Consolas; font-size: 12pt;"> </span><span style="color: #6a3e3e; font-family: Consolas; font-size: 12.0pt;">p2</span><span style="font-family: Consolas; font-size: 12pt;"> = </span><span style="color: #6a3e3e; font-family: Consolas; font-size: 12.0pt;">p2</span><span style="font-family: Consolas; font-size: 12pt;">.</span><span style="color: #0000c0; font-family: Consolas; font-size: 12.0pt;">next</span><span style="font-family: Consolas; font-size: 12pt;">;</span><span style="font-family: Consolas; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: Consolas; font-size: 12pt;"> </span><span style="color: #7f0055; font-family: Consolas; font-size: 12.0pt; mso-bidi-font-weight: bold;">if</span><span style="font-family: Consolas; font-size: 12pt;">(</span><span style="color: #6a3e3e; font-family: Consolas; font-size: 12.0pt;">p2</span><span style="font-family: Consolas; font-size: 12pt;">==</span><span style="color: #7f0055; font-family: Consolas; font-size: 12.0pt; mso-bidi-font-weight: bold;">null</span><span style="font-family: Consolas; font-size: 12pt;">)
{</span><span style="font-family: Consolas; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: Consolas; font-size: 12pt;"> </span><span style="color: #7f0055; font-family: Consolas; font-size: 12.0pt; mso-bidi-font-weight: bold;">break</span><span style="font-family: Consolas; font-size: 12pt;">;</span><span style="font-family: Consolas; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: Consolas; font-size: 12pt;"> }</span><span style="font-family: Consolas; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: Consolas; font-size: 12pt;"> </span><span style="color: #6a3e3e; font-family: Consolas; font-size: 12.0pt;">p1</span><span style="font-family: Consolas; font-size: 12pt;"> = </span><span style="color: #6a3e3e; font-family: Consolas; font-size: 12.0pt;">p1</span><span style="font-family: Consolas; font-size: 12pt;">.</span><span style="color: #0000c0; font-family: Consolas; font-size: 12.0pt;">next</span><span style="font-family: Consolas; font-size: 12pt;">; </span><span style="color: #6a3e3e; font-family: Consolas; font-size: 12.0pt;">p2</span><span style="font-family: Consolas; font-size: 12pt;"> = </span><span style="color: #6a3e3e; font-family: Consolas; font-size: 12.0pt;">p2</span><span style="font-family: Consolas; font-size: 12pt;">.</span><span style="color: #0000c0; font-family: Consolas; font-size: 12.0pt;">next</span><span style="font-family: Consolas; font-size: 12pt;">;</span><span style="font-family: Consolas; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: Consolas; font-size: 12pt;"> }</span><span style="font-family: Consolas; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<br /></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: Consolas; font-size: 12pt;"> Node </span><span style="color: #6a3e3e; font-family: Consolas; font-size: 12.0pt;">start</span><span style="font-family: Consolas; font-size: 12pt;"> = </span><span style="color: #6a3e3e; font-family: Consolas; font-size: 12.0pt;">p1</span><span style="font-family: Consolas; font-size: 12pt;">.</span><span style="color: #0000c0; font-family: Consolas; font-size: 12.0pt;">next</span><span style="font-family: Consolas; font-size: 12pt;">;</span><span style="font-family: Consolas; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: Consolas; font-size: 12pt;"> Node </span><span style="color: #6a3e3e; font-family: Consolas; font-size: 12.0pt;">temp</span><span style="font-family: Consolas; font-size: 12pt;"> = </span><span style="color: #7f0055; font-family: Consolas; font-size: 12.0pt; mso-bidi-font-weight: bold;">null</span><span style="font-family: Consolas; font-size: 12pt;">;</span><span style="font-family: Consolas; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: Consolas; font-size: 12pt;"> Node </span><span style="color: #6a3e3e; font-family: Consolas; font-size: 12.0pt;">preNext</span><span style="font-family: Consolas; font-size: 12pt;"> = </span><span style="color: #7f0055; font-family: Consolas; font-size: 12.0pt; mso-bidi-font-weight: bold;">null</span><span style="font-family: Consolas; font-size: 12pt;">;</span><span style="font-family: Consolas; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<br /></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: Consolas; font-size: 12pt;"> </span><span style="color: #7f0055; font-family: Consolas; font-size: 12.0pt; mso-bidi-font-weight: bold;">while</span><span style="font-family: Consolas; font-size: 12pt;"> (</span><span style="color: #6a3e3e; font-family: Consolas; font-size: 12.0pt;">start</span><span style="font-family: Consolas; font-size: 12pt;"> != </span><span style="color: #7f0055; font-family: Consolas; font-size: 12.0pt; mso-bidi-font-weight: bold;">null</span><span style="font-family: Consolas; font-size: 12pt;">)
{</span><span style="font-family: Consolas; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: Consolas; font-size: 12pt;"> </span><span style="color: #6a3e3e; font-family: Consolas; font-size: 12.0pt;">temp</span><span style="font-family: Consolas; font-size: 12pt;"> = </span><span style="color: #6a3e3e; font-family: Consolas; font-size: 12.0pt;">start</span><span style="font-family: Consolas; font-size: 12pt;">.</span><span style="color: #0000c0; font-family: Consolas; font-size: 12.0pt;">next</span><span style="font-family: Consolas; font-size: 12pt;">;</span><span style="font-family: Consolas; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: Consolas; font-size: 12pt;"> </span><span style="color: #6a3e3e; font-family: Consolas; font-size: 12.0pt;">start</span><span style="font-family: Consolas; font-size: 12pt;">.</span><span style="color: #0000c0; font-family: Consolas; font-size: 12.0pt;">next</span><span style="font-family: Consolas; font-size: 12pt;"> = </span><span style="color: #6a3e3e; font-family: Consolas; font-size: 12.0pt;">preNext</span><span style="font-family: Consolas; font-size: 12pt;">;</span><span style="font-family: Consolas; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: Consolas; font-size: 12pt;"> </span><span style="color: #6a3e3e; font-family: Consolas; font-size: 12.0pt;">preNext</span><span style="font-family: Consolas; font-size: 12pt;"> = </span><span style="color: #6a3e3e; font-family: Consolas; font-size: 12.0pt;">start</span><span style="font-family: Consolas; font-size: 12pt;">;</span><span style="font-family: Consolas; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: Consolas; font-size: 12pt;"> </span><span style="color: #6a3e3e; font-family: Consolas; font-size: 12.0pt;">start</span><span style="font-family: Consolas; font-size: 12pt;"> = </span><span style="color: #6a3e3e; font-family: Consolas; font-size: 12.0pt;">temp</span><span style="font-family: Consolas; font-size: 12pt;">;</span><span style="font-family: Consolas; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: Consolas; font-size: 12pt;"> }</span><span style="font-family: Consolas; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: Consolas; font-size: 12pt;"> </span><span style="color: #6a3e3e; font-family: Consolas; font-size: 12.0pt;">p1</span><span style="font-family: Consolas; font-size: 12pt;">.</span><span style="color: #0000c0; font-family: Consolas; font-size: 12.0pt;">next</span><span style="font-family: Consolas; font-size: 12pt;"> = </span><span style="color: #6a3e3e; font-family: Consolas; font-size: 12.0pt;">preNext</span><span style="font-family: Consolas; font-size: 12pt;">;</span><span style="font-family: Consolas; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: Consolas; font-size: 12pt;"> </span><span style="color: #7f0055; font-family: Consolas; font-size: 12.0pt; mso-bidi-font-weight: bold;">return</span><span style="font-family: Consolas; font-size: 12pt;"> </span><span style="color: #6a3e3e; font-family: Consolas; font-size: 12.0pt;">counter</span><span style="font-family: Consolas; font-size: 12pt;">;</span><span style="font-family: Consolas; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: Consolas; font-size: 12pt;"> }</span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: Consolas; font-size: 12pt;"><br /></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: Consolas; font-size: 12pt;"> </span><span style="color: #3f5fbf; font-family: Consolas; font-size: 12.0pt;">/** Util method to print the List. */</span><span style="font-family: Consolas; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: Consolas; font-size: 12pt;"> </span><span style="color: #7f0055; font-family: Consolas; font-size: 12.0pt; mso-bidi-font-weight: bold;">private</span><span style="font-family: Consolas; font-size: 12pt;"> </span><span style="color: #7f0055; font-family: Consolas; font-size: 12.0pt; mso-bidi-font-weight: bold;">static</span><span style="font-family: Consolas; font-size: 12pt;"> </span><span style="color: #7f0055; font-family: Consolas; font-size: 12.0pt; mso-bidi-font-weight: bold;">void</span><span style="font-family: Consolas; font-size: 12pt;"> printList(Node </span><span style="color: #6a3e3e; font-family: Consolas; font-size: 12.0pt;">head</span><span style="font-family: Consolas; font-size: 12pt;">) {</span><span style="font-family: Consolas; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: Consolas; font-size: 12pt;"> </span><span style="color: #7f0055; font-family: Consolas; font-size: 12.0pt; mso-bidi-font-weight: bold;">if</span><span style="font-family: Consolas; font-size: 12pt;">(</span><span style="color: #6a3e3e; font-family: Consolas; font-size: 12.0pt;">head</span><span style="font-family: Consolas; font-size: 12pt;">==</span><span style="color: #7f0055; font-family: Consolas; font-size: 12.0pt; mso-bidi-font-weight: bold;">null</span><span style="font-family: Consolas; font-size: 12pt;">)
{</span><span style="font-family: Consolas; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: Consolas; font-size: 12pt;"> System.</span><i><span style="color: #0000c0; font-family: Consolas; font-size: 12.0pt; mso-bidi-font-weight: bold;">out</span></i><span style="font-family: Consolas; font-size: 12pt;">.println(</span><span style="color: #2a00ff; font-family: Consolas; font-size: 12.0pt;">"List is null"</span><span style="font-family: Consolas; font-size: 12pt;">);</span><span style="font-family: Consolas; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: Consolas; font-size: 12pt;"> }</span><span style="font-family: Consolas; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<br /></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: Consolas; font-size: 12pt;"> </span><span style="color: #7f0055; font-family: Consolas; font-size: 12.0pt; mso-bidi-font-weight: bold;">if</span><span style="font-family: Consolas; font-size: 12pt;">(</span><span style="color: #6a3e3e; font-family: Consolas; font-size: 12.0pt;">head</span><span style="font-family: Consolas; font-size: 12pt;">.</span><span style="color: #0000c0; font-family: Consolas; font-size: 12.0pt;">next</span><span style="font-family: Consolas; font-size: 12pt;">==</span><span style="color: #7f0055; font-family: Consolas; font-size: 12.0pt; mso-bidi-font-weight: bold;">null</span><span style="font-family: Consolas; font-size: 12pt;">)
{</span><span style="font-family: Consolas; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: Consolas; font-size: 12pt;"> System.</span><i><span style="color: #0000c0; font-family: Consolas; font-size: 12.0pt; mso-bidi-font-weight: bold;">out</span></i><span style="font-family: Consolas; font-size: 12pt;">.print(</span><span style="color: #2a00ff; font-family: Consolas; font-size: 12.0pt;">"List : "</span><span style="font-family: Consolas; font-size: 12pt;">+</span><span style="color: #6a3e3e; font-family: Consolas; font-size: 12.0pt;">head</span><span style="font-family: Consolas; font-size: 12pt;">.</span><span style="color: #0000c0; font-family: Consolas; font-size: 12.0pt;">data</span><span style="font-family: Consolas; font-size: 12pt;">+</span><span style="color: #2a00ff; font-family: Consolas; font-size: 12.0pt;">" "</span><span style="font-family: Consolas; font-size: 12pt;">);</span><span style="font-family: Consolas; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: Consolas; font-size: 12pt;"> </span><span style="color: #7f0055; font-family: Consolas; font-size: 12.0pt; mso-bidi-font-weight: bold;">return</span><span style="font-family: Consolas; font-size: 12pt;">;</span><span style="font-family: Consolas; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: Consolas; font-size: 12pt;"> }</span><span style="font-family: Consolas; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<br /></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: Consolas; font-size: 12pt;"> Node </span><span style="color: #6a3e3e; font-family: Consolas; font-size: 12.0pt;">next</span><span style="font-family: Consolas; font-size: 12pt;"> = </span><span style="color: #6a3e3e; font-family: Consolas; font-size: 12.0pt;">head</span><span style="font-family: Consolas; font-size: 12pt;">.</span><span style="color: #0000c0; font-family: Consolas; font-size: 12.0pt;">next</span><span style="font-family: Consolas; font-size: 12pt;">;</span><span style="font-family: Consolas; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: Consolas; font-size: 12pt;"> System.</span><i><span style="color: #0000c0; font-family: Consolas; font-size: 12.0pt; mso-bidi-font-weight: bold;">out</span></i><span style="font-family: Consolas; font-size: 12pt;">.print(</span><span style="color: #2a00ff; font-family: Consolas; font-size: 12.0pt;">"List : "</span><span style="font-family: Consolas; font-size: 12pt;">+</span><span style="color: #6a3e3e; font-family: Consolas; font-size: 12.0pt;">head</span><span style="font-family: Consolas; font-size: 12pt;">.</span><span style="color: #0000c0; font-family: Consolas; font-size: 12.0pt;">data</span><span style="font-family: Consolas; font-size: 12pt;">+</span><span style="color: #2a00ff; font-family: Consolas; font-size: 12.0pt;">" "</span><span style="font-family: Consolas; font-size: 12pt;">);</span><span style="font-family: Consolas; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: Consolas; font-size: 12pt;"> </span><span style="color: #7f0055; font-family: Consolas; font-size: 12.0pt; mso-bidi-font-weight: bold;">while</span><span style="font-family: Consolas; font-size: 12pt;">(</span><span style="color: #6a3e3e; font-family: Consolas; font-size: 12.0pt;">next</span><span style="font-family: Consolas; font-size: 12pt;">!=</span><span style="color: #7f0055; font-family: Consolas; font-size: 12.0pt; mso-bidi-font-weight: bold;">null</span><span style="font-family: Consolas; font-size: 12pt;">)
{</span><span style="font-family: Consolas; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: Consolas; font-size: 12pt;"> System.</span><i><span style="color: #0000c0; font-family: Consolas; font-size: 12.0pt; mso-bidi-font-weight: bold;">out</span></i><span style="font-family: Consolas; font-size: 12pt;">.print(</span><span style="color: #6a3e3e; font-family: Consolas; font-size: 12.0pt;">next</span><span style="font-family: Consolas; font-size: 12pt;">.</span><span style="color: #0000c0; font-family: Consolas; font-size: 12.0pt;">data</span><span style="font-family: Consolas; font-size: 12pt;">+</span><span style="color: #2a00ff; font-family: Consolas; font-size: 12.0pt;">" "</span><span style="font-family: Consolas; font-size: 12pt;">);</span><span style="font-family: Consolas; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: Consolas; font-size: 12pt;"> </span><span style="color: #6a3e3e; font-family: Consolas; font-size: 12.0pt;">next</span><span style="font-family: Consolas; font-size: 12pt;"> = </span><span style="color: #6a3e3e; font-family: Consolas; font-size: 12.0pt;">next</span><span style="font-family: Consolas; font-size: 12pt;">.</span><span style="color: #0000c0; font-family: Consolas; font-size: 12.0pt;">next</span><span style="font-family: Consolas; font-size: 12pt;">;</span><span style="font-family: Consolas; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: Consolas; font-size: 12pt;"> }</span><span style="font-family: Consolas; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: Consolas; font-size: 12pt;"> }</span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: Consolas; font-size: 12pt;"><br /></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: Consolas; font-size: 12pt;"> </span><span style="color: #3f5fbf; font-family: Consolas; font-size: 12.0pt;">/** Driver method. */</span><span style="font-family: Consolas; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: Consolas; font-size: 12pt;"> </span><span style="color: #7f0055; font-family: Consolas; font-size: 12.0pt; mso-bidi-font-weight: bold;">public</span><span style="font-family: Consolas; font-size: 12pt;"> </span><span style="color: #7f0055; font-family: Consolas; font-size: 12.0pt; mso-bidi-font-weight: bold;">static</span><span style="font-family: Consolas; font-size: 12pt;"> </span><span style="color: #7f0055; font-family: Consolas; font-size: 12.0pt; mso-bidi-font-weight: bold;">void</span><span style="font-family: Consolas; font-size: 12pt;"> main(String[] </span><span style="color: #6a3e3e; font-family: Consolas; font-size: 12.0pt;">args</span><span style="font-family: Consolas; font-size: 12pt;">) {</span><span style="font-family: Consolas; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<br /></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: Consolas; font-size: 12pt;"> </span><span style="color: #3f7f5f; font-family: Consolas; font-size: 12.0pt;">/*Node head = new Node(1);</span><span style="font-family: Consolas; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="color: #3f7f5f; font-family: Consolas; font-size: 12.0pt;"> head.next = new Node(2);</span><span style="font-family: Consolas; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="color: #3f7f5f; font-family: Consolas; font-size: 12.0pt;"> head.next.next = new Node(3);</span><span style="font-family: Consolas; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="color: #3f7f5f; font-family: Consolas; font-size: 12.0pt;"> head.next.next.next = new Node(4);</span><span style="font-family: Consolas; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="color: #3f7f5f; font-family: Consolas; font-size: 12.0pt;"> head.next.next.next.next = new
Node(3);</span><span style="font-family: Consolas; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="color: #3f7f5f; font-family: Consolas; font-size: 12.0pt;"> head.next.next.next.next.next = new
Node(2);</span><span style="font-family: Consolas; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="color: #3f7f5f; font-family: Consolas; font-size: 12.0pt;"> head.next.next.next.next.next.next =
new Node(1);*/</span><span style="font-family: Consolas; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<br /></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: Consolas; font-size: 12pt;"> Node </span><span style="color: #6a3e3e; font-family: Consolas; font-size: 12.0pt;">head</span><span style="font-family: Consolas; font-size: 12pt;"> = </span><span style="color: #7f0055; font-family: Consolas; font-size: 12.0pt; mso-bidi-font-weight: bold;">new</span><span style="font-family: Consolas; font-size: 12pt;"> Node(1);</span><span style="font-family: Consolas; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: Consolas; font-size: 12pt;"> </span><span style="color: #6a3e3e; font-family: Consolas; font-size: 12.0pt;">head</span><span style="font-family: Consolas; font-size: 12pt;">.</span><span style="color: #0000c0; font-family: Consolas; font-size: 12.0pt;">next</span><span style="font-family: Consolas; font-size: 12pt;"> = </span><span style="color: #7f0055; font-family: Consolas; font-size: 12.0pt; mso-bidi-font-weight: bold;">new</span><span style="font-family: Consolas; font-size: 12pt;"> Node(2);</span><span style="font-family: Consolas; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: Consolas; font-size: 12pt;"> </span><span style="color: #6a3e3e; font-family: Consolas; font-size: 12.0pt;">head</span><span style="font-family: Consolas; font-size: 12pt;">.</span><span style="color: #0000c0; font-family: Consolas; font-size: 12.0pt;">next</span><span style="font-family: Consolas; font-size: 12pt;">.</span><span style="color: #0000c0; font-family: Consolas; font-size: 12.0pt;">next</span><span style="font-family: Consolas; font-size: 12pt;"> = </span><span style="color: #7f0055; font-family: Consolas; font-size: 12.0pt; mso-bidi-font-weight: bold;">new</span><span style="font-family: Consolas; font-size: 12pt;"> Node(3);</span><span style="font-family: Consolas; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: Consolas; font-size: 12pt;"> </span><span style="color: #6a3e3e; font-family: Consolas; font-size: 12.0pt;">head</span><span style="font-family: Consolas; font-size: 12pt;">.</span><span style="color: #0000c0; font-family: Consolas; font-size: 12.0pt;">next</span><span style="font-family: Consolas; font-size: 12pt;">.</span><span style="color: #0000c0; font-family: Consolas; font-size: 12.0pt;">next</span><span style="font-family: Consolas; font-size: 12pt;">.</span><span style="color: #0000c0; font-family: Consolas; font-size: 12.0pt;">next</span><span style="font-family: Consolas; font-size: 12pt;"> = </span><span style="color: #7f0055; font-family: Consolas; font-size: 12.0pt; mso-bidi-font-weight: bold;">new</span><span style="font-family: Consolas; font-size: 12pt;"> Node(3);</span><span style="font-family: Consolas; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: Consolas; font-size: 12pt;"> </span><span style="color: #6a3e3e; font-family: Consolas; font-size: 12.0pt;">head</span><span style="font-family: Consolas; font-size: 12pt;">.</span><span style="color: #0000c0; font-family: Consolas; font-size: 12.0pt;">next</span><span style="font-family: Consolas; font-size: 12pt;">.</span><span style="color: #0000c0; font-family: Consolas; font-size: 12.0pt;">next</span><span style="font-family: Consolas; font-size: 12pt;">.</span><span style="color: #0000c0; font-family: Consolas; font-size: 12.0pt;">next</span><span style="font-family: Consolas; font-size: 12pt;">.</span><span style="color: #0000c0; font-family: Consolas; font-size: 12.0pt;">next</span><span style="font-family: Consolas; font-size: 12pt;"> = </span><span style="color: #7f0055; font-family: Consolas; font-size: 12.0pt; mso-bidi-font-weight: bold;">new</span><span style="font-family: Consolas; font-size: 12pt;"> Node(2);</span><span style="font-family: Consolas; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: Consolas; font-size: 12pt;"> </span><span style="color: #6a3e3e; font-family: Consolas; font-size: 12.0pt;">head</span><span style="font-family: Consolas; font-size: 12pt;">.</span><span style="color: #0000c0; font-family: Consolas; font-size: 12.0pt;">next</span><span style="font-family: Consolas; font-size: 12pt;">.</span><span style="color: #0000c0; font-family: Consolas; font-size: 12.0pt;">next</span><span style="font-family: Consolas; font-size: 12pt;">.</span><span style="color: #0000c0; font-family: Consolas; font-size: 12.0pt;">next</span><span style="font-family: Consolas; font-size: 12pt;">.</span><span style="color: #0000c0; font-family: Consolas; font-size: 12.0pt;">next</span><span style="font-family: Consolas; font-size: 12pt;">.</span><span style="color: #0000c0; font-family: Consolas; font-size: 12.0pt;">next</span><span style="font-family: Consolas; font-size: 12pt;"> = </span><span style="color: #7f0055; font-family: Consolas; font-size: 12.0pt; mso-bidi-font-weight: bold;">new</span><span style="font-family: Consolas; font-size: 12pt;"> Node(1);</span><span style="font-family: Consolas; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<br /></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: Consolas; font-size: 12pt;"> <i>printList</i>(</span><span style="color: #6a3e3e; font-family: Consolas; font-size: 12.0pt;">head</span><span style="font-family: Consolas; font-size: 12pt;">);</span><span style="font-family: Consolas; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: Consolas; font-size: 12pt;"> String </span><span style="color: #6a3e3e; font-family: Consolas; font-size: 12.0pt;">result</span><span style="font-family: Consolas; font-size: 12pt;"> = <i>checkListIsPalindrome</i>(</span><span style="color: #6a3e3e; font-family: Consolas; font-size: 12.0pt;">head</span><span style="font-family: Consolas; font-size: 12pt;">);</span><span style="font-family: Consolas; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: Consolas; font-size: 12pt;"> System.</span><i><span style="color: #0000c0; font-family: Consolas; font-size: 12.0pt; mso-bidi-font-weight: bold;">out</span></i><span style="font-family: Consolas; font-size: 12pt;">.println(</span><span style="color: #2a00ff; font-family: Consolas; font-size: 12.0pt;">"\nList is "</span><span style="font-family: Consolas; font-size: 12pt;">+</span><span style="color: #6a3e3e; font-family: Consolas; font-size: 12.0pt;">result</span><span style="font-family: Consolas; font-size: 12pt;">);</span><span style="font-family: Consolas; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: Consolas; font-size: 12pt;"> }</span><span style="font-family: Consolas; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: Consolas; font-size: 12pt;">}</span><span style="font-family: Consolas; font-size: 12.0pt;"><o:p></o:p></span></div>
</div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in;">
<span style="font-family: "Book Antiqua", serif; font-size: 13pt;"><br /></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in;">
<span style="font-family: "Book Antiqua", serif; font-size: 13pt;">This
method takes O(n) time and O(1) extra space.</span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in;">
<span style="font-family: "Book Antiqua","serif"; font-size: 13.0pt;"><br /></span></div>
</div>
javaexplor03http://www.blogger.com/profile/07455293496498711738noreply@blogger.com0tag:blogger.com,1999:blog-615973148715732292.post-88885992984693812552017-06-26T04:47:00.000-07:002017-06-26T04:47:02.401-07:00Find next greater number with same set of digits<div dir="ltr" style="text-align: left;" trbidi="on">
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in;">
<span style="font-family: "Book Antiqua", serif; font-size: 13pt;">Given
a number, find the smallest number that has same set of digits as number and is
greater than number.</span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in;">
<b><span style="font-family: "Book Antiqua","serif"; font-size: 13.0pt;"><br /></span></b></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in;">
<b><span style="font-family: "Book Antiqua","serif"; font-size: 13.0pt;">Examples:</span></b></div>
<div style="background: #B8CCE4; border: solid windowtext 1.0pt; mso-background-themecolor: accent1; mso-background-themetint: 102; mso-border-alt: solid windowtext .5pt; mso-element: para-border-div; padding: 1.0pt 4.0pt 1.0pt 4.0pt;">
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: "Book Antiqua","serif"; font-size: 13.0pt;">Input: 329876<o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: "Book Antiqua","serif"; font-size: 13.0pt;">Output:
362789<o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<br /></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: "Book Antiqua","serif"; font-size: 13.0pt;">Input: 3689<o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: "Book Antiqua","serif"; font-size: 13.0pt;">Output:
3698<o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<br /></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: "Book Antiqua","serif"; font-size: 13.0pt;">Input:
98732<o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: "Book Antiqua","serif"; font-size: 13.0pt;">Output:
No possible sequence !!<o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: "Book Antiqua","serif"; font-size: 13.0pt;">-1<o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<br /></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: "Book Antiqua","serif"; font-size: 13.0pt;">Input:
n = 645987<o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: "Book Antiqua","serif"; font-size: 13.0pt;">Output:
647589<o:p></o:p></span></div>
</div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in;">
<b><span style="color: #1f497d; font-family: "Book Antiqua","serif"; font-size: 14.0pt; mso-bidi-font-size: 13.0pt; mso-themecolor: text2;"><br /></span></b></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in;">
<b><span style="color: #1f497d; font-family: "Book Antiqua","serif"; font-size: 14.0pt; mso-bidi-font-size: 13.0pt; mso-themecolor: text2;">Approach:</span></b></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in;">
<span style="font-family: "Book Antiqua","serif"; font-size: 13.0pt;">1) If
all digits sorted in descending order, then output is always “<b>No possible sequence !!</b>”.<o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in;">
<span style="font-family: "Book Antiqua","serif"; font-size: 13.0pt;">Example:
98732.<o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in;">
<br /></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in;">
<span style="font-family: "Book Antiqua","serif"; font-size: 13.0pt;">2) If
all digits are sorted in ascending order, then we need to swap last two digits
only.<o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in;">
<span style="font-family: "Book Antiqua","serif"; font-size: 13.0pt;">Example:
3689.<o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in;">
<br /></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in;">
<span style="font-family: "Book Antiqua","serif"; font-size: 13.0pt;">3)
For other cases, we need to process the number from rightmost side because we
need to find the smallest of all greater numbers<o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in;">
<span style="font-family: "Book Antiqua","serif"; font-size: 13.0pt;"> 3.a) Traverse the given number from
rightmost digit, keep traversing till you find a digit which is smaller than
the previously traversed digit.<o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in;">
<span style="font-family: "Book Antiqua","serif"; font-size: 13.0pt;"> Example: If the input number is
645987, we will stop traversing at 5 as 5 is smaller than next digit i.e. 9. If
we do not find such a digit, then output is “Not Possible”.</span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in;">
<span style="font-family: "Book Antiqua","serif"; font-size: 13.0pt;"><br /></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in;">
<span style="font-family: "Book Antiqua","serif"; font-size: 13.0pt;"> 3.b) Now search the right side of
above found digit ‘d’ for the smallest digit greater than ‘d’.<o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in;">
<span style="font-family: "Book Antiqua","serif"; font-size: 13.0pt;"> For 645987, the right side of 5
contains 987. The smallest digit greater than 5 is 7.<o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in;">
<span style="font-family: "Book Antiqua", serif; font-size: 13pt;"> </span><span style="font-family: "Book Antiqua", serif; font-size: 13pt;">3.c) Swap the above found two
digits, we get 647985 in above example.</span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in;">
<br /></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in;">
<span style="font-family: "Book Antiqua","serif"; font-size: 13.0pt;"> 3.d) Now sort all digits from
position next to end of number in ascending order. </span><span style="font-family: "Book Antiqua", serif; font-size: 13pt;">For above input, we get 647589 which
is the next greater number for input 645987 after sorting.</span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in;">
<br /></div>
<br />
<div style="background: #DBE5F1; border: solid windowtext 1.0pt; mso-background-themecolor: accent1; mso-background-themetint: 51; mso-border-alt: solid windowtext .5pt; mso-element: para-border-div; padding: 1.0pt 1.0pt 1.0pt 1.0pt;">
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="color: #7f0055; font-family: Consolas; font-size: 12.0pt; mso-bidi-font-weight: bold;">package</span><span style="font-family: Consolas; font-size: 12pt;"> com.geeks;</span><span style="font-family: Consolas; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="color: #7f0055; font-family: Consolas; font-size: 12.0pt; mso-bidi-font-weight: bold;">import</span><span style="font-family: Consolas; font-size: 12pt;"> java.util.Arrays;</span><span style="font-family: Consolas; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="color: #7f0055; font-family: Consolas; font-size: 12.0pt; mso-bidi-font-weight: bold;">public</span><span style="font-family: Consolas; font-size: 12pt;"> </span><span style="color: #7f0055; font-family: Consolas; font-size: 12.0pt; mso-bidi-font-weight: bold;">class</span><span style="font-family: Consolas; font-size: 12pt;"> NextBigInteger {</span><span style="font-family: Consolas; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: Consolas; font-size: 12pt;"> </span><span style="font-family: Consolas; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: Consolas; font-size: 12pt;"> </span><span style="color: #3f5fbf; font-family: Consolas; font-size: 12.0pt;">/**</span><span style="font-family: Consolas; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="color: #3f5fbf; font-family: Consolas; font-size: 12.0pt;"> *
Get Next big integer.</span><span style="font-family: Consolas; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="color: #3f5fbf; font-family: Consolas; font-size: 12.0pt;"> * </span><span style="color: #7f9fbf; font-family: Consolas; font-size: 12.0pt; mso-bidi-font-weight: bold;">@param</span><span style="color: #3f5fbf; font-family: Consolas; font-size: 12.0pt;"> number</span><span style="font-family: Consolas; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="color: #3f5fbf; font-family: Consolas; font-size: 12.0pt;"> * </span><span style="color: #7f9fbf; font-family: Consolas; font-size: 12.0pt; mso-bidi-font-weight: bold;">@return</span><span style="color: #3f5fbf; font-family: Consolas; font-size: 12.0pt;"> return the next big integer.</span><span style="font-family: Consolas; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="color: #3f5fbf; font-family: Consolas; font-size: 12.0pt;"> */</span><span style="font-family: Consolas; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: Consolas; font-size: 12pt;"> </span><span style="color: #7f0055; font-family: Consolas; font-size: 12.0pt; mso-bidi-font-weight: bold;">private</span><span style="font-family: Consolas; font-size: 12pt;"> </span><span style="color: #7f0055; font-family: Consolas; font-size: 12.0pt; mso-bidi-font-weight: bold;">static</span><span style="font-family: Consolas; font-size: 12pt;"> </span><span style="color: #7f0055; font-family: Consolas; font-size: 12.0pt; mso-bidi-font-weight: bold;">int</span><span style="font-family: Consolas; font-size: 12pt;"> getNextBigInt(</span><span style="color: #7f0055; font-family: Consolas; font-size: 12.0pt; mso-bidi-font-weight: bold;">int</span><span style="font-family: Consolas; font-size: 12pt;"> </span><span style="color: #6a3e3e; font-family: Consolas; font-size: 12.0pt;">number</span><span style="font-family: Consolas; font-size: 12pt;">) {</span><span style="font-family: Consolas; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: Consolas; font-size: 12pt;"> </span><span style="font-family: Consolas; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: Consolas; font-size: 12pt;"> </span><span style="color: #7f0055; font-family: Consolas; font-size: 12.0pt; mso-bidi-font-weight: bold;">int</span><span style="font-family: Consolas; font-size: 12pt;"> </span><span style="color: #6a3e3e; font-family: Consolas; font-size: 12.0pt;">length</span><span style="font-family: Consolas; font-size: 12pt;"> = (</span><span style="color: #7f0055; font-family: Consolas; font-size: 12.0pt; mso-bidi-font-weight: bold;">int</span><span style="font-family: Consolas; font-size: 12pt;">)
Math.<i>ceil</i>(Math.<i>log10</i>(</span><span style="color: #6a3e3e; font-family: Consolas; font-size: 12.0pt;">number</span><span style="font-family: Consolas; font-size: 12pt;">));</span><span style="font-family: Consolas; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: Consolas; font-size: 12pt;"> </span><span style="font-family: Consolas; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: Consolas; font-size: 12pt;"> System.</span><i><span style="color: #0000c0; font-family: Consolas; font-size: 12.0pt; mso-bidi-font-weight: bold;">out</span></i><span style="font-family: Consolas; font-size: 12pt;">.println(</span><span style="color: #6a3e3e; font-family: Consolas; font-size: 12.0pt;">length</span><span style="font-family: Consolas; font-size: 12pt;">);</span><span style="font-family: Consolas; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: Consolas; font-size: 12pt;"> </span><span style="color: #7f0055; font-family: Consolas; font-size: 12.0pt; mso-bidi-font-weight: bold;">int</span><span style="font-family: Consolas; font-size: 12pt;">[] </span><span style="color: #6a3e3e; font-family: Consolas; font-size: 12.0pt;">array</span><span style="font-family: Consolas; font-size: 12pt;"> = </span><span style="color: #7f0055; font-family: Consolas; font-size: 12.0pt; mso-bidi-font-weight: bold;">new</span><span style="font-family: Consolas; font-size: 12pt;">
</span><span style="color: #7f0055; font-family: Consolas; font-size: 12.0pt; mso-bidi-font-weight: bold;">int</span><span style="font-family: Consolas; font-size: 12pt;">[</span><span style="color: #6a3e3e; font-family: Consolas; font-size: 12.0pt;">length</span><span style="font-family: Consolas; font-size: 12pt;">];</span><span style="font-family: Consolas; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: Consolas; font-size: 12pt;"> </span><span style="font-family: Consolas; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: Consolas; font-size: 12pt;"> </span><span style="color: #7f0055; font-family: Consolas; font-size: 12.0pt; mso-bidi-font-weight: bold;">for</span><span style="font-family: Consolas; font-size: 12pt;"> (</span><span style="color: #7f0055; font-family: Consolas; font-size: 12.0pt; mso-bidi-font-weight: bold;">int</span><span style="font-family: Consolas; font-size: 12pt;">
</span><span style="color: #6a3e3e; font-family: Consolas; font-size: 12.0pt;">i</span><span style="font-family: Consolas; font-size: 12pt;"> = 0; </span><span style="color: #6a3e3e; font-family: Consolas; font-size: 12.0pt;">i</span><span style="font-family: Consolas; font-size: 12pt;"> < </span><span style="color: #6a3e3e; font-family: Consolas; font-size: 12.0pt;">length</span><span style="font-family: Consolas; font-size: 12pt;">; </span><span style="color: #6a3e3e; font-family: Consolas; font-size: 12.0pt;">i</span><span style="font-family: Consolas; font-size: 12pt;">++) {</span><span style="font-family: Consolas; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: Consolas; font-size: 12pt;"> </span><span style="color: #6a3e3e; font-family: Consolas; font-size: 12.0pt;">array</span><span style="font-family: Consolas; font-size: 12pt;">[</span><span style="color: #6a3e3e; font-family: Consolas; font-size: 12.0pt;">length</span><span style="font-family: Consolas; font-size: 12pt;">-</span><span style="color: #6a3e3e; font-family: Consolas; font-size: 12.0pt;">i</span><span style="font-family: Consolas; font-size: 12pt;">-1] = </span><span style="color: #6a3e3e; font-family: Consolas; font-size: 12.0pt;">number</span><span style="font-family: Consolas; font-size: 12pt;">%10;</span><span style="font-family: Consolas; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: Consolas; font-size: 12pt;"> </span><span style="color: #6a3e3e; font-family: Consolas; font-size: 12.0pt;">number</span><span style="font-family: Consolas; font-size: 12pt;"> = </span><span style="color: #6a3e3e; font-family: Consolas; font-size: 12.0pt;">number</span><span style="font-family: Consolas; font-size: 12pt;">/10;</span><span style="font-family: Consolas; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: Consolas; font-size: 12pt;"> }</span><span style="font-family: Consolas; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: Consolas; font-size: 12pt;"> </span><span style="font-family: Consolas; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: Consolas; font-size: 12pt;"> </span><span style="color: #3f5fbf; font-family: Consolas; font-size: 12.0pt;">/** Find the index of smallest one from
right to left. */</span><span style="font-family: Consolas; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: Consolas; font-size: 12pt;"> </span><span style="color: #7f0055; font-family: Consolas; font-size: 12.0pt; mso-bidi-font-weight: bold;">int</span><span style="font-family: Consolas; font-size: 12pt;"> </span><span style="color: #6a3e3e; font-family: Consolas; font-size: 12.0pt;">index</span><span style="font-family: Consolas; font-size: 12pt;"> = -1;</span><span style="font-family: Consolas; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: Consolas; font-size: 12pt;"> </span><span style="color: #7f0055; font-family: Consolas; font-size: 12.0pt; mso-bidi-font-weight: bold;">for</span><span style="font-family: Consolas; font-size: 12pt;"> (</span><span style="color: #7f0055; font-family: Consolas; font-size: 12.0pt; mso-bidi-font-weight: bold;">int</span><span style="font-family: Consolas; font-size: 12pt;">
</span><span style="color: #6a3e3e; font-family: Consolas; font-size: 12.0pt;">i</span><span style="font-family: Consolas; font-size: 12pt;"> = 0; </span><span style="color: #6a3e3e; font-family: Consolas; font-size: 12.0pt;">i</span><span style="font-family: Consolas; font-size: 12pt;"> < </span><span style="color: #6a3e3e; font-family: Consolas; font-size: 12.0pt;">length</span><span style="font-family: Consolas; font-size: 12pt;">-1; </span><span style="color: #6a3e3e; font-family: Consolas; font-size: 12.0pt;">i</span><span style="font-family: Consolas; font-size: 12pt;">++) {</span><span style="font-family: Consolas; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: Consolas; font-size: 12pt;"> </span><span style="color: #7f0055; font-family: Consolas; font-size: 12.0pt; mso-bidi-font-weight: bold;">if</span><span style="font-family: Consolas; font-size: 12pt;">(</span><span style="color: #6a3e3e; font-family: Consolas; font-size: 12.0pt;">array</span><span style="font-family: Consolas; font-size: 12pt;">[</span><span style="color: #6a3e3e; font-family: Consolas; font-size: 12.0pt;">length</span><span style="font-family: Consolas; font-size: 12pt;">-</span><span style="color: #6a3e3e; font-family: Consolas; font-size: 12.0pt;">i</span><span style="font-family: Consolas; font-size: 12pt;">-2]<</span><span style="color: #6a3e3e; font-family: Consolas; font-size: 12.0pt;">array</span><span style="font-family: Consolas; font-size: 12pt;">[</span><span style="color: #6a3e3e; font-family: Consolas; font-size: 12.0pt;">length</span><span style="font-family: Consolas; font-size: 12pt;">-</span><span style="color: #6a3e3e; font-family: Consolas; font-size: 12.0pt;">i</span><span style="font-family: Consolas; font-size: 12pt;">-1]) {</span><span style="font-family: Consolas; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: Consolas; font-size: 12pt;"> </span><span style="color: #6a3e3e; font-family: Consolas; font-size: 12.0pt;">index</span><span style="font-family: Consolas; font-size: 12pt;"> = </span><span style="color: #6a3e3e; font-family: Consolas; font-size: 12.0pt;">length</span><span style="font-family: Consolas; font-size: 12pt;">-</span><span style="color: #6a3e3e; font-family: Consolas; font-size: 12.0pt;">i</span><span style="font-family: Consolas; font-size: 12pt;">-2;</span><span style="font-family: Consolas; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: Consolas; font-size: 12pt;"> </span><span style="color: #7f0055; font-family: Consolas; font-size: 12.0pt; mso-bidi-font-weight: bold;">break</span><span style="font-family: Consolas; font-size: 12pt;">;</span><span style="font-family: Consolas; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: Consolas; font-size: 12pt;"> }</span><span style="font-family: Consolas; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: Consolas; font-size: 12pt;"> }</span><span style="font-family: Consolas; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: Consolas; font-size: 12pt;"> </span><span style="font-family: Consolas; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: Consolas; font-size: 12pt;"> </span><span style="color: #3f5fbf; font-family: Consolas; font-size: 12.0pt;">/** If no index found then greater number
is no possible. */</span><span style="font-family: Consolas; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: Consolas; font-size: 12pt;"> </span><span style="color: #7f0055; font-family: Consolas; font-size: 12.0pt; mso-bidi-font-weight: bold;">if</span><span style="font-family: Consolas; font-size: 12pt;">(</span><span style="color: #6a3e3e; font-family: Consolas; font-size: 12.0pt;">index</span><span style="font-family: Consolas; font-size: 12pt;">==-1) {</span><span style="font-family: Consolas; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: Consolas; font-size: 12pt;"> System.</span><i><span style="color: #0000c0; font-family: Consolas; font-size: 12.0pt; mso-bidi-font-weight: bold;">out</span></i><span style="font-family: Consolas; font-size: 12pt;">.println(</span><span style="color: #2a00ff; font-family: Consolas; font-size: 12.0pt;">"No possible sequence !!"</span><span style="font-family: Consolas; font-size: 12pt;">);</span><span style="font-family: Consolas; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: Consolas; font-size: 12pt;"> </span><span style="color: #7f0055; font-family: Consolas; font-size: 12.0pt; mso-bidi-font-weight: bold;">return</span><span style="font-family: Consolas; font-size: 12pt;"> -1;</span><span style="font-family: Consolas; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: Consolas; font-size: 12pt;"> }</span><span style="font-family: Consolas; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: Consolas; font-size: 12pt;"> </span><span style="font-family: Consolas; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: Consolas; font-size: 12pt;"> </span><span style="color: #7f0055; font-family: Consolas; font-size: 12.0pt; mso-bidi-font-weight: bold;">int</span><span style="font-family: Consolas; font-size: 12pt;"> </span><span style="color: #6a3e3e; font-family: Consolas; font-size: 12.0pt;">smallMaxIdx</span><span style="font-family: Consolas; font-size: 12pt;"> = </span><span style="color: #6a3e3e; font-family: Consolas; font-size: 12.0pt;">index</span><span style="font-family: Consolas; font-size: 12pt;">+1;</span><span style="font-family: Consolas; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: Consolas; font-size: 12pt;"> </span><span style="color: #7f0055; font-family: Consolas; font-size: 12.0pt; mso-bidi-font-weight: bold;">for</span><span style="font-family: Consolas; font-size: 12pt;"> (</span><span style="color: #7f0055; font-family: Consolas; font-size: 12.0pt; mso-bidi-font-weight: bold;">int</span><span style="font-family: Consolas; font-size: 12pt;">
</span><span style="color: #6a3e3e; font-family: Consolas; font-size: 12.0pt;">i</span><span style="font-family: Consolas; font-size: 12pt;"> = </span><span style="color: #6a3e3e; font-family: Consolas; font-size: 12.0pt;">index</span><span style="font-family: Consolas; font-size: 12pt;">+2; </span><span style="color: #6a3e3e; font-family: Consolas; font-size: 12.0pt;">i</span><span style="font-family: Consolas; font-size: 12pt;"> < </span><span style="color: #6a3e3e; font-family: Consolas; font-size: 12.0pt;">length</span><span style="font-family: Consolas; font-size: 12pt;">; </span><span style="color: #6a3e3e; font-family: Consolas; font-size: 12.0pt;">i</span><span style="font-family: Consolas; font-size: 12pt;">++) {</span><span style="font-family: Consolas; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: Consolas; font-size: 12pt;"> </span><span style="color: #7f0055; font-family: Consolas; font-size: 12.0pt; mso-bidi-font-weight: bold;">if</span><span style="font-family: Consolas; font-size: 12pt;">(</span><span style="color: #6a3e3e; font-family: Consolas; font-size: 12.0pt;">array</span><span style="font-family: Consolas; font-size: 12pt;">[</span><span style="color: #6a3e3e; font-family: Consolas; font-size: 12.0pt;">smallMaxIdx</span><span style="font-family: Consolas; font-size: 12pt;">]></span><span style="color: #6a3e3e; font-family: Consolas; font-size: 12.0pt;">array</span><span style="font-family: Consolas; font-size: 12pt;">[</span><span style="color: #6a3e3e; font-family: Consolas; font-size: 12.0pt;">i</span><span style="font-family: Consolas; font-size: 12pt;">]) {</span><span style="font-family: Consolas; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: Consolas; font-size: 12pt;"> </span><span style="color: #6a3e3e; font-family: Consolas; font-size: 12.0pt;">smallMaxIdx</span><span style="font-family: Consolas; font-size: 12pt;"> = </span><span style="color: #6a3e3e; font-family: Consolas; font-size: 12.0pt;">i</span><span style="font-family: Consolas; font-size: 12pt;">;</span><span style="font-family: Consolas; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: Consolas; font-size: 12pt;"> }</span><span style="font-family: Consolas; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: Consolas; font-size: 12pt;"> }</span><span style="font-family: Consolas; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: Consolas; font-size: 12pt;"> </span><span style="font-family: Consolas; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: Consolas; font-size: 12pt;"> </span><span style="color: #7f0055; font-family: Consolas; font-size: 12.0pt; mso-bidi-font-weight: bold;">int</span><span style="font-family: Consolas; font-size: 12pt;"> </span><span style="color: #6a3e3e; font-family: Consolas; font-size: 12.0pt;">temp</span><span style="font-family: Consolas; font-size: 12pt;"> = </span><span style="color: #6a3e3e; font-family: Consolas; font-size: 12.0pt;">array</span><span style="font-family: Consolas; font-size: 12pt;">[</span><span style="color: #6a3e3e; font-family: Consolas; font-size: 12.0pt;">index</span><span style="font-family: Consolas; font-size: 12pt;">];</span><span style="font-family: Consolas; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: Consolas; font-size: 12pt;"> </span><span style="color: #6a3e3e; font-family: Consolas; font-size: 12.0pt;">array</span><span style="font-family: Consolas; font-size: 12pt;">[</span><span style="color: #6a3e3e; font-family: Consolas; font-size: 12.0pt;">index</span><span style="font-family: Consolas; font-size: 12pt;">] = </span><span style="color: #6a3e3e; font-family: Consolas; font-size: 12.0pt;">array</span><span style="font-family: Consolas; font-size: 12pt;">[</span><span style="color: #6a3e3e; font-family: Consolas; font-size: 12.0pt;">smallMaxIdx</span><span style="font-family: Consolas; font-size: 12pt;">];</span><span style="font-family: Consolas; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: Consolas; font-size: 12pt;"> </span><span style="color: #6a3e3e; font-family: Consolas; font-size: 12.0pt;">array</span><span style="font-family: Consolas; font-size: 12pt;">[</span><span style="color: #6a3e3e; font-family: Consolas; font-size: 12.0pt;">smallMaxIdx</span><span style="font-family: Consolas; font-size: 12pt;">] = </span><span style="color: #6a3e3e; font-family: Consolas; font-size: 12.0pt;">temp</span><span style="font-family: Consolas; font-size: 12pt;">;</span><span style="font-family: Consolas; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: Consolas; font-size: 12pt;"> </span><span style="font-family: Consolas; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: Consolas; font-size: 12pt;"> Arrays.<i>sort</i>(</span><span style="color: #6a3e3e; font-family: Consolas; font-size: 12.0pt;">array</span><span style="font-family: Consolas; font-size: 12pt;">, </span><span style="color: #6a3e3e; font-family: Consolas; font-size: 12.0pt;">index</span><span style="font-family: Consolas; font-size: 12pt;">+1, </span><span style="color: #6a3e3e; font-family: Consolas; font-size: 12.0pt;">length</span><span style="font-family: Consolas; font-size: 12pt;">);</span><span style="font-family: Consolas; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: Consolas; font-size: 12pt;"> </span><span style="font-family: Consolas; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: Consolas; font-size: 12pt;"> </span><span style="color: #7f0055; font-family: Consolas; font-size: 12.0pt; mso-bidi-font-weight: bold;">return</span><span style="font-family: Consolas; font-size: 12pt;"> <i>integerArrayToInt</i>(</span><span style="color: #6a3e3e; font-family: Consolas; font-size: 12.0pt;">array</span><span style="font-family: Consolas; font-size: 12pt;">);</span><span style="font-family: Consolas; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: Consolas; font-size: 12pt;"> </span><span style="font-family: Consolas; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: Consolas; font-size: 12pt;"> }</span><span style="font-family: Consolas; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<br /></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: Consolas; font-size: 12pt;"> </span><span style="color: #3f5fbf; font-family: Consolas; font-size: 12.0pt;">/**</span><span style="font-family: Consolas; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="color: #3f5fbf; font-family: Consolas; font-size: 12.0pt;"> * <u>Util</u>
method to convert the <u>int</u> array to integer.</span><span style="font-family: Consolas; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="color: #3f5fbf; font-family: Consolas; font-size: 12.0pt;"> * </span><span style="color: #7f9fbf; font-family: Consolas; font-size: 12.0pt; mso-bidi-font-weight: bold;">@param</span><span style="color: #3f5fbf; font-family: Consolas; font-size: 12.0pt;"> array</span><span style="font-family: Consolas; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="color: #3f5fbf; font-family: Consolas; font-size: 12.0pt;"> * </span><span style="color: #7f9fbf; font-family: Consolas; font-size: 12.0pt; mso-bidi-font-weight: bold;">@return</span><span style="color: #3f5fbf; font-family: Consolas; font-size: 12.0pt;"> integer.</span><span style="font-family: Consolas; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="color: #3f5fbf; font-family: Consolas; font-size: 12.0pt;"> */</span><span style="font-family: Consolas; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: Consolas; font-size: 12pt;"> </span><span style="color: #7f0055; font-family: Consolas; font-size: 12.0pt; mso-bidi-font-weight: bold;">private</span><span style="font-family: Consolas; font-size: 12pt;"> </span><span style="color: #7f0055; font-family: Consolas; font-size: 12.0pt; mso-bidi-font-weight: bold;">static</span><span style="font-family: Consolas; font-size: 12pt;"> </span><span style="color: #7f0055; font-family: Consolas; font-size: 12.0pt; mso-bidi-font-weight: bold;">int</span><span style="font-family: Consolas; font-size: 12pt;"> integerArrayToInt(</span><span style="color: #7f0055; font-family: Consolas; font-size: 12.0pt; mso-bidi-font-weight: bold;">int</span><span style="font-family: Consolas; font-size: 12pt;">[]
</span><span style="color: #6a3e3e; font-family: Consolas; font-size: 12.0pt;">array</span><span style="font-family: Consolas; font-size: 12pt;">) {</span><span style="font-family: Consolas; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: Consolas; font-size: 12pt;"> </span><span style="color: #7f0055; font-family: Consolas; font-size: 12.0pt; mso-bidi-font-weight: bold;">int</span><span style="font-family: Consolas; font-size: 12pt;"> </span><span style="color: #6a3e3e; font-family: Consolas; font-size: 12.0pt;">len</span><span style="font-family: Consolas; font-size: 12pt;"> = </span><span style="color: #6a3e3e; font-family: Consolas; font-size: 12.0pt;">array</span><span style="font-family: Consolas; font-size: 12pt;">.</span><span style="color: #0000c0; font-family: Consolas; font-size: 12.0pt;">length</span><span style="font-family: Consolas; font-size: 12pt;">;</span><span style="font-family: Consolas; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: Consolas; font-size: 12pt;"> </span><span style="color: #7f0055; font-family: Consolas; font-size: 12.0pt; mso-bidi-font-weight: bold;">int</span><span style="font-family: Consolas; font-size: 12pt;"> </span><span style="color: #6a3e3e; font-family: Consolas; font-size: 12.0pt;">number</span><span style="font-family: Consolas; font-size: 12pt;"> = </span><span style="color: #6a3e3e; font-family: Consolas; font-size: 12.0pt;">array</span><span style="font-family: Consolas; font-size: 12pt;">[</span><span style="color: #6a3e3e; font-family: Consolas; font-size: 12.0pt;">len</span><span style="font-family: Consolas; font-size: 12pt;">-1];</span><span style="font-family: Consolas; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: Consolas; font-size: 12pt;"> </span><span style="color: #7f0055; font-family: Consolas; font-size: 12.0pt; mso-bidi-font-weight: bold;">int</span><span style="font-family: Consolas; font-size: 12pt;"> </span><span style="color: #6a3e3e; font-family: Consolas; font-size: 12.0pt;">factor</span><span style="font-family: Consolas; font-size: 12pt;"> = 10;</span><span style="font-family: Consolas; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: Consolas; font-size: 12pt;"> </span><span style="font-family: Consolas; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: Consolas; font-size: 12pt;"> </span><span style="color: #7f0055; font-family: Consolas; font-size: 12.0pt; mso-bidi-font-weight: bold;">for</span><span style="font-family: Consolas; font-size: 12pt;"> (</span><span style="color: #7f0055; font-family: Consolas; font-size: 12.0pt; mso-bidi-font-weight: bold;">int</span><span style="font-family: Consolas; font-size: 12pt;">
</span><span style="color: #6a3e3e; font-family: Consolas; font-size: 12.0pt;">i</span><span style="font-family: Consolas; font-size: 12pt;"> = 1; </span><span style="color: #6a3e3e; font-family: Consolas; font-size: 12.0pt;">i</span><span style="font-family: Consolas; font-size: 12pt;"> < </span><span style="color: #6a3e3e; font-family: Consolas; font-size: 12.0pt;">len</span><span style="font-family: Consolas; font-size: 12pt;">; </span><span style="color: #6a3e3e; font-family: Consolas; font-size: 12.0pt;">i</span><span style="font-family: Consolas; font-size: 12pt;">++) {</span><span style="font-family: Consolas; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: Consolas; font-size: 12pt;"> </span><span style="color: #6a3e3e; font-family: Consolas; font-size: 12.0pt;">number</span><span style="font-family: Consolas; font-size: 12pt;"> = </span><span style="color: #6a3e3e; font-family: Consolas; font-size: 12.0pt;">number</span><span style="font-family: Consolas; font-size: 12pt;"> + </span><span style="color: #6a3e3e; font-family: Consolas; font-size: 12.0pt;">factor</span><span style="font-family: Consolas; font-size: 12pt;"> * </span><span style="color: #6a3e3e; font-family: Consolas; font-size: 12.0pt;">array</span><span style="font-family: Consolas; font-size: 12pt;">[</span><span style="color: #6a3e3e; font-family: Consolas; font-size: 12.0pt;">len</span><span style="font-family: Consolas; font-size: 12pt;">-</span><span style="color: #6a3e3e; font-family: Consolas; font-size: 12.0pt;">i</span><span style="font-family: Consolas; font-size: 12pt;">-1];</span><span style="font-family: Consolas; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: Consolas; font-size: 12pt;"> </span><span style="color: #6a3e3e; font-family: Consolas; font-size: 12.0pt;">factor</span><span style="font-family: Consolas; font-size: 12pt;"> = </span><span style="color: #6a3e3e; font-family: Consolas; font-size: 12.0pt;">factor</span><span style="font-family: Consolas; font-size: 12pt;"> * 10;</span><span style="font-family: Consolas; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: Consolas; font-size: 12pt;"> }</span><span style="font-family: Consolas; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: Consolas; font-size: 12pt;"> </span><span style="color: #7f0055; font-family: Consolas; font-size: 12.0pt; mso-bidi-font-weight: bold;">return</span><span style="font-family: Consolas; font-size: 12pt;"> </span><span style="color: #6a3e3e; font-family: Consolas; font-size: 12.0pt;">number</span><span style="font-family: Consolas; font-size: 12pt;">;</span><span style="font-family: Consolas; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: Consolas; font-size: 12pt;"> }</span><span style="font-family: Consolas; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: Consolas; font-size: 12pt;"> </span><span style="font-family: Consolas; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: Consolas; font-size: 12pt;"> </span><span style="color: #3f5fbf; font-family: Consolas; font-size: 12.0pt;">/**</span><span style="font-family: Consolas; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="color: #3f5fbf; font-family: Consolas; font-size: 12.0pt;"> *
Driver method.</span><span style="font-family: Consolas; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="color: #3f5fbf; font-family: Consolas; font-size: 12.0pt;"> * </span><span style="color: #7f9fbf; font-family: Consolas; font-size: 12.0pt; mso-bidi-font-weight: bold;">@param</span><span style="color: #3f5fbf; font-family: Consolas; font-size: 12.0pt;"> args</span><span style="font-family: Consolas; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="color: #3f5fbf; font-family: Consolas; font-size: 12.0pt;"> */</span><span style="font-family: Consolas; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: Consolas; font-size: 12pt;"> </span><span style="color: #7f0055; font-family: Consolas; font-size: 12.0pt; mso-bidi-font-weight: bold;">public</span><span style="font-family: Consolas; font-size: 12pt;"> </span><span style="color: #7f0055; font-family: Consolas; font-size: 12.0pt; mso-bidi-font-weight: bold;">static</span><span style="font-family: Consolas; font-size: 12pt;"> </span><span style="color: #7f0055; font-family: Consolas; font-size: 12.0pt; mso-bidi-font-weight: bold;">void</span><span style="font-family: Consolas; font-size: 12pt;"> main(String[] </span><span style="color: #6a3e3e; font-family: Consolas; font-size: 12.0pt;">args</span><span style="font-family: Consolas; font-size: 12pt;">) {</span><span style="font-family: Consolas; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: Consolas; font-size: 12pt;"> </span><span style="color: #7f0055; font-family: Consolas; font-size: 12.0pt; mso-bidi-font-weight: bold;">int</span><span style="font-family: Consolas; font-size: 12pt;"> </span><span style="color: #6a3e3e; font-family: Consolas; font-size: 12.0pt;">number</span><span style="font-family: Consolas; font-size: 12pt;"> = 645987;</span><span style="font-family: Consolas; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: Consolas; font-size: 12pt;"> </span><span style="color: #7f0055; font-family: Consolas; font-size: 12.0pt; mso-bidi-font-weight: bold;">int</span><span style="font-family: Consolas; font-size: 12pt;"> </span><span style="color: #6a3e3e; font-family: Consolas; font-size: 12.0pt;">nextBigNumb</span><span style="font-family: Consolas; font-size: 12pt;"> = <i>getNextBigInt</i>(</span><span style="color: #6a3e3e; font-family: Consolas; font-size: 12.0pt;">number</span><span style="font-family: Consolas; font-size: 12pt;">);</span><span style="font-family: Consolas; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: Consolas; font-size: 12pt;"> System.</span><i><span style="color: #0000c0; font-family: Consolas; font-size: 12.0pt; mso-bidi-font-weight: bold;">out</span></i><span style="font-family: Consolas; font-size: 12pt;">.println(</span><span style="color: #6a3e3e; font-family: Consolas; font-size: 12.0pt;">nextBigNumb</span><span style="font-family: Consolas; font-size: 12pt;">);</span><span style="font-family: Consolas; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: Consolas; font-size: 12pt;"> }</span><span style="font-family: Consolas; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: Consolas; font-size: 12pt;">}</span><span style="font-family: "Book Antiqua","serif"; font-size: 12.0pt;"><o:p></o:p></span></div>
</div>
</div>
javaexplor03http://www.blogger.com/profile/07455293496498711738noreply@blogger.com0tag:blogger.com,1999:blog-615973148715732292.post-19604289112603019262017-06-26T03:13:00.003-07:002017-06-26T03:13:54.797-07:00Abstract Class vs Interface<div dir="ltr" style="text-align: left;" trbidi="on">
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in;">
<span style="font-family: "Book Antiqua", serif; font-size: 13pt;">An
interface is a "</span><b style="font-family: "Book Antiqua", serif; font-size: 13pt;">contract</b><span style="font-family: "Book Antiqua", serif; font-size: 13pt;">".
If a class implements an interface it has to propose all the services listed in
the interface.</span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in;">
<span style="font-family: "Book Antiqua", serif; font-size: 13pt;"><br /></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in;">
<span style="font-family: "Book Antiqua", serif; font-size: 13pt;">An
abstract class is a skeleton. It defines a certain way its extended classes
will work while letting them some free space (the abstract methods) to be
unique.</span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in;">
<span style="font-family: "Book Antiqua", serif; font-size: 13pt;"><br /></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in;">
<span style="font-family: "Book Antiqua", serif; font-size: 13pt;">A
pure abstract class doing the same thing as an interface but have the problem
of unique extending so, for me, it have no interest.</span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in;">
<b><span style="color: #002060; font-family: "Book Antiqua","serif"; font-size: 13.0pt;"><br /></span></b></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in;">
<b><span style="color: #002060; font-family: "Book Antiqua","serif"; font-size: 13.0pt;">Every interface is implicitly
abstract</span></b></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in;">
<span style="font-family: "Book Antiqua","serif"; font-size: 13.0pt;">Every
method declaration in the body of interface is implicitly abstract and public.<o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in;">
<br /></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in;">
<span style="font-family: "Book Antiqua","serif"; font-size: 13.0pt;">An
abstract class has methods that can contain implementation. Abstract methods
can be either <span style="color: #10253f; mso-style-textfill-fill-alpha: 100.0%; mso-style-textfill-fill-color: #10253F; mso-style-textfill-fill-colortransforms: lumm=50000; mso-style-textfill-fill-themecolor: text2; mso-themecolor: text2; mso-themeshade: 128;">public, protected or default access </span>(package visible). <span style="color: red;">Unlike </span>interfaces abstract classes can contain fields
that are not static and final.<o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in;">
<br /></div>
<br />
<table border="1" cellpadding="0" cellspacing="0" class="MsoTableGrid" style="border-collapse: collapse; border: none; mso-border-alt: solid windowtext .5pt; mso-padding-alt: 0in 5.4pt 0in 5.4pt; mso-table-layout-alt: fixed; mso-yfti-tbllook: 1184; width: 701px;">
<tbody>
<tr style="height: 16.5pt; mso-yfti-firstrow: yes; mso-yfti-irow: 0;">
<td style="border: solid windowtext 1.0pt; height: 16.5pt; mso-border-alt: solid windowtext .5pt; padding: 0in 5.4pt 0in 5.4pt; width: 151.85pt;" valign="top" width="202">
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in;">
<br /></div>
</td>
<td style="border-left: none; border: solid windowtext 1.0pt; height: 16.5pt; mso-border-alt: solid windowtext .5pt; mso-border-left-alt: solid windowtext .5pt; padding: 0in 5.4pt 0in 5.4pt; width: 155.65pt;" valign="top" width="208">
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in;">
<b><span style="color: #1f497d; font-family: "Book Antiqua","serif"; font-size: 13.0pt; mso-themecolor: text2;">Interface
<o:p></o:p></span></b></div>
</td>
<td style="border-left: none; border: solid windowtext 1.0pt; height: 16.5pt; mso-border-alt: solid windowtext .5pt; mso-border-left-alt: solid windowtext .5pt; padding: 0in 5.4pt 0in 5.4pt; width: 218.15pt;" valign="top" width="291">
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in;">
<b><span style="color: #1f497d; font-family: "Book Antiqua","serif"; font-size: 13.0pt; mso-themecolor: text2;">Abstract
Class<o:p></o:p></span></b></div>
</td>
</tr>
<tr style="height: 16.5pt; mso-yfti-irow: 1;">
<td style="border-top: none; border: solid windowtext 1.0pt; height: 16.5pt; mso-border-alt: solid windowtext .5pt; mso-border-top-alt: solid windowtext .5pt; padding: 0in 5.4pt 0in 5.4pt; width: 151.85pt;" valign="top" width="202">
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in;">
<b><span style="color: #1f497d; font-family: "Book Antiqua","serif"; font-size: 13.0pt; mso-themecolor: text2;">Extend
Class <o:p></o:p></span></b></div>
</td>
<td style="border-bottom: solid windowtext 1.0pt; border-left: none; border-right: solid windowtext 1.0pt; border-top: none; height: 16.5pt; mso-border-alt: solid windowtext .5pt; mso-border-left-alt: solid windowtext .5pt; mso-border-top-alt: solid windowtext .5pt; padding: 0in 5.4pt 0in 5.4pt; width: 155.65pt;" valign="top" width="208">
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in;">
<span style="font-family: "Book Antiqua","serif"; font-size: 13.0pt;">No<o:p></o:p></span></div>
</td>
<td style="border-bottom: solid windowtext 1.0pt; border-left: none; border-right: solid windowtext 1.0pt; border-top: none; height: 16.5pt; mso-border-alt: solid windowtext .5pt; mso-border-left-alt: solid windowtext .5pt; mso-border-top-alt: solid windowtext .5pt; padding: 0in 5.4pt 0in 5.4pt; width: 218.15pt;" valign="top" width="291">
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in;">
<span style="font-family: "Book Antiqua","serif"; font-size: 13.0pt;">Yes<o:p></o:p></span></div>
</td>
</tr>
<tr style="height: 16.5pt; mso-yfti-irow: 2;">
<td style="border-top: none; border: solid windowtext 1.0pt; height: 16.5pt; mso-border-alt: solid windowtext .5pt; mso-border-top-alt: solid windowtext .5pt; padding: 0in 5.4pt 0in 5.4pt; width: 151.85pt;" valign="top" width="202">
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in;">
<b><span style="color: #1f497d; font-family: "Book Antiqua","serif"; font-size: 13.0pt; mso-themecolor: text2;">Extend
Abstract Class<o:p></o:p></span></b></div>
</td>
<td style="border-bottom: solid windowtext 1.0pt; border-left: none; border-right: solid windowtext 1.0pt; border-top: none; height: 16.5pt; mso-border-alt: solid windowtext .5pt; mso-border-left-alt: solid windowtext .5pt; mso-border-top-alt: solid windowtext .5pt; padding: 0in 5.4pt 0in 5.4pt; width: 155.65pt;" valign="top" width="208">
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in;">
<span style="font-family: "Book Antiqua","serif"; font-size: 13.0pt;">No<o:p></o:p></span></div>
</td>
<td style="border-bottom: solid windowtext 1.0pt; border-left: none; border-right: solid windowtext 1.0pt; border-top: none; height: 16.5pt; mso-border-alt: solid windowtext .5pt; mso-border-left-alt: solid windowtext .5pt; mso-border-top-alt: solid windowtext .5pt; padding: 0in 5.4pt 0in 5.4pt; width: 218.15pt;" valign="top" width="291">
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in;">
<span style="font-family: "Book Antiqua","serif"; font-size: 13.0pt;">Yes<o:p></o:p></span></div>
</td>
</tr>
<tr style="height: 17.25pt; mso-yfti-irow: 3;">
<td style="border-top: none; border: solid windowtext 1.0pt; height: 17.25pt; mso-border-alt: solid windowtext .5pt; mso-border-top-alt: solid windowtext .5pt; padding: 0in 5.4pt 0in 5.4pt; width: 151.85pt;" valign="top" width="202">
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in;">
<b><span style="color: #1f497d; font-family: "Book Antiqua","serif"; font-size: 13.0pt; mso-themecolor: text2;">Implement
Interface<o:p></o:p></span></b></div>
</td>
<td style="border-bottom: solid windowtext 1.0pt; border-left: none; border-right: solid windowtext 1.0pt; border-top: none; height: 17.25pt; mso-border-alt: solid windowtext .5pt; mso-border-left-alt: solid windowtext .5pt; mso-border-top-alt: solid windowtext .5pt; padding: 0in 5.4pt 0in 5.4pt; width: 155.65pt;" valign="top" width="208">
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in;">
<span style="font-family: "Book Antiqua","serif"; font-size: 13.0pt;">Yes(Extend
Interface)<o:p></o:p></span></div>
</td>
<td style="border-bottom: solid windowtext 1.0pt; border-left: none; border-right: solid windowtext 1.0pt; border-top: none; height: 17.25pt; mso-border-alt: solid windowtext .5pt; mso-border-left-alt: solid windowtext .5pt; mso-border-top-alt: solid windowtext .5pt; padding: 0in 5.4pt 0in 5.4pt; width: 218.15pt;" valign="top" width="291">
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in;">
<span style="font-family: "Book Antiqua","serif"; font-size: 13.0pt;">Yes<o:p></o:p></span></div>
</td>
</tr>
<tr style="height: 32.95pt; mso-yfti-irow: 4;">
<td style="border-top: none; border: solid windowtext 1.0pt; height: 32.95pt; mso-border-alt: solid windowtext .5pt; mso-border-top-alt: solid windowtext .5pt; padding: 0in 5.4pt 0in 5.4pt; width: 151.85pt;" valign="top" width="202">
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in;">
<b><span style="color: #1f497d; font-family: "Book Antiqua","serif"; font-size: 13.0pt; mso-themecolor: text2;">Variables<o:p></o:p></span></b></div>
</td>
<td style="border-bottom: solid windowtext 1.0pt; border-left: none; border-right: solid windowtext 1.0pt; border-top: none; height: 32.95pt; mso-border-alt: solid windowtext .5pt; mso-border-left-alt: solid windowtext .5pt; mso-border-top-alt: solid windowtext .5pt; padding: 0in 5.4pt 0in 5.4pt; width: 155.65pt;" valign="top" width="208">
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in;">
<span style="font-family: "Book Antiqua","serif"; font-size: 13.0pt;">public
static final <o:p></o:p></span></div>
</td>
<td style="border-bottom: solid windowtext 1.0pt; border-left: none; border-right: solid windowtext 1.0pt; border-top: none; height: 32.95pt; mso-border-alt: solid windowtext .5pt; mso-border-left-alt: solid windowtext .5pt; mso-border-top-alt: solid windowtext .5pt; padding: 0in 5.4pt 0in 5.4pt; width: 218.15pt;" valign="top" width="291">
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in;">
<span style="font-family: "Book Antiqua","serif"; font-size: 13.0pt;">public/protected/private/static/final/transient/volatile<o:p></o:p></span></div>
</td>
</tr>
<tr style="height: 33.75pt; mso-yfti-irow: 5;">
<td style="border-top: none; border: solid windowtext 1.0pt; height: 33.75pt; mso-border-alt: solid windowtext .5pt; mso-border-top-alt: solid windowtext .5pt; padding: 0in 5.4pt 0in 5.4pt; width: 151.85pt;" valign="top" width="202">
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in;">
<b><span style="color: #1f497d; font-family: "Book Antiqua","serif"; font-size: 13.0pt; mso-themecolor: text2;">Contain
Non-Public Method <o:p></o:p></span></b></div>
</td>
<td style="border-bottom: solid windowtext 1.0pt; border-left: none; border-right: solid windowtext 1.0pt; border-top: none; height: 33.75pt; mso-border-alt: solid windowtext .5pt; mso-border-left-alt: solid windowtext .5pt; mso-border-top-alt: solid windowtext .5pt; padding: 0in 5.4pt 0in 5.4pt; width: 155.65pt;" valign="top" width="208">
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in;">
<span style="font-family: "Book Antiqua","serif"; font-size: 13.0pt;">No<o:p></o:p></span></div>
</td>
<td style="border-bottom: solid windowtext 1.0pt; border-left: none; border-right: solid windowtext 1.0pt; border-top: none; height: 33.75pt; mso-border-alt: solid windowtext .5pt; mso-border-left-alt: solid windowtext .5pt; mso-border-top-alt: solid windowtext .5pt; padding: 0in 5.4pt 0in 5.4pt; width: 218.15pt;" valign="top" width="291">
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in;">
<span style="font-family: "Book Antiqua","serif"; font-size: 13.0pt;">Yes<o:p></o:p></span></div>
</td>
</tr>
<tr style="height: 34.5pt; mso-yfti-irow: 6; mso-yfti-lastrow: yes;">
<td style="border-top: none; border: solid windowtext 1.0pt; height: 34.5pt; mso-border-alt: solid windowtext .5pt; mso-border-top-alt: solid windowtext .5pt; padding: 0in 5.4pt 0in 5.4pt; width: 151.85pt;" valign="top" width="202">
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in;">
<b><span style="color: #1f497d; font-family: "Book Antiqua","serif"; font-size: 13.0pt; mso-themecolor: text2;">Contain
Abstract Method <o:p></o:p></span></b></div>
</td>
<td style="border-bottom: solid windowtext 1.0pt; border-left: none; border-right: solid windowtext 1.0pt; border-top: none; height: 34.5pt; mso-border-alt: solid windowtext .5pt; mso-border-left-alt: solid windowtext .5pt; mso-border-top-alt: solid windowtext .5pt; padding: 0in 5.4pt 0in 5.4pt; width: 155.65pt;" valign="top" width="208">
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in;">
<span style="font-family: "Book Antiqua","serif"; font-size: 13.0pt;">Yes<o:p></o:p></span></div>
</td>
<td style="border-bottom: solid windowtext 1.0pt; border-left: none; border-right: solid windowtext 1.0pt; border-top: none; height: 34.5pt; mso-border-alt: solid windowtext .5pt; mso-border-left-alt: solid windowtext .5pt; mso-border-top-alt: solid windowtext .5pt; padding: 0in 5.4pt 0in 5.4pt; width: 218.15pt;" valign="top" width="291">
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in;">
<span style="font-family: "Book Antiqua","serif"; font-size: 13.0pt;">No<o:p></o:p></span></div>
</td>
</tr>
</tbody></table>
</div>
javaexplor03http://www.blogger.com/profile/07455293496498711738noreply@blogger.com0tag:blogger.com,1999:blog-615973148715732292.post-77926537430323641632017-06-26T01:00:00.000-07:002017-06-26T01:05:30.834-07:00Find the next smallest palindrome for a number<div dir="ltr" style="text-align: left;" trbidi="on">
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in;">
<br /></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in;">
<span style="font-family: "Book Antiqua","serif"; font-size: 13.0pt;">For a
given a number, find the next smallest palindrome larger than this number.</span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in;">
<span style="font-family: "Book Antiqua","serif"; font-size: 13.0pt;"><br /></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in;">
<span style="font-family: "Book Antiqua","serif"; font-size: 13.0pt;">Examples:<o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in;">
<span style="font-family: "Book Antiqua","serif"; font-size: 13.0pt;">1. If
the input number is “3 4 6 5 6”, the output should be “3 4 7 4 3”.<o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in;">
<span style="font-family: "Book Antiqua","serif"; font-size: 13.0pt;">2. If
the input number is “9 9 9 9”, the output should be “1 0 0 0 1”.</span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in;">
<span style="font-family: "Book Antiqua","serif"; font-size: 13.0pt;"><br /></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in;">
<b><span style="color: #002060; font-family: "Book Antiqua","serif"; font-size: 14.0pt; mso-bidi-font-size: 13.0pt;">Approach:<o:p></o:p></span></b></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in;">
<span style="font-family: "Book Antiqua","serif"; font-size: 13.0pt;">There
can be three different cases those should be handled separately.<o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in;">
<span style="font-family: "Book Antiqua","serif"; font-size: 13.0pt;">1)
The input number is palindrome and has all 9s.<o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in;">
<b><span style="font-family: "Book Antiqua","serif"; font-size: 13.0pt;">Example<o:p></o:p></span></b></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in;">
<span style="font-family: "Book Antiqua","serif"; font-size: 13.0pt;">Input:
9 9 9 9<o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in;">
<span style="font-family: "Book Antiqua","serif"; font-size: 13.0pt;">Output:1
0 0 0 1.</span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in;">
<span style="font-family: "Book Antiqua","serif"; font-size: 13.0pt;"><br /></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in;">
<span style="font-family: "Book Antiqua","serif"; font-size: 13.0pt;"><b>It
can be get by adding 2 into the number.</b><o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in;">
<br /></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in;">
<span style="font-family: "Book Antiqua","serif"; font-size: 13.0pt;">2)
The input number is not palindrome.<o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in;">
<b><span style="font-family: "Book Antiqua","serif"; font-size: 13.0pt;">Example<o:p></o:p></span></b></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in;">
<span style="font-family: "Book Antiqua","serif"; font-size: 13.0pt;">Input:
2 3 4 5<o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in;">
<span style="font-family: "Book Antiqua","serif"; font-size: 13.0pt;">Output:2
4 4 2.<o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in;">
<br /></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in;">
<span style="font-family: "Book Antiqua","serif"; font-size: 13.0pt;">3)
The input number is palindrome and doesn’t have all 9s.<o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in;">
<b><span style="font-family: "Book Antiqua","serif"; font-size: 13.0pt;">Example<o:p></o:p></span></b></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in;">
<span style="font-family: "Book Antiqua","serif"; font-size: 13.0pt;">Input:
2 3 3 2.<o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in;">
<span style="font-family: "Book Antiqua","serif"; font-size: 13.0pt;">Output:2
4 4 2.<o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in;">
<br /></div>
<div style="background: #DBE5F1; border: solid windowtext 1.0pt; mso-background-themecolor: accent1; mso-background-themetint: 51; mso-border-alt: solid windowtext .5pt; mso-element: para-border-div; padding: 1.0pt 1.0pt 1.0pt 1.0pt;">
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="color: #7f0055; font-family: Consolas; font-size: 12.0pt; mso-bidi-font-weight: bold;">package</span><span style="font-family: Consolas; font-size: 12pt;"> com.geeks;</span><span style="font-family: Consolas; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<br /></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="color: #7f0055; font-family: Consolas; font-size: 12.0pt; mso-bidi-font-weight: bold;">public</span><span style="font-family: Consolas; font-size: 12pt;"> </span><span style="color: #7f0055; font-family: Consolas; font-size: 12.0pt; mso-bidi-font-weight: bold;">class</span><span style="font-family: Consolas; font-size: 12pt;"> NextGreaterPalindrome {</span><span style="font-family: Consolas; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<br /></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: Consolas; font-size: 12pt;"> </span><span style="color: #3f5fbf; font-family: Consolas; font-size: 12.0pt;">/**</span><span style="font-family: Consolas; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="color: #3f5fbf; font-family: Consolas; font-size: 12.0pt;"> *
getNextPalindrome</span><span style="font-family: Consolas; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="color: #3f5fbf; font-family: Consolas; font-size: 12.0pt;"> * </span><span style="color: #7f9fbf; font-family: Consolas; font-size: 12.0pt; mso-bidi-font-weight: bold;">@param</span><span style="color: #3f5fbf; font-family: Consolas; font-size: 12.0pt;"> number</span><span style="font-family: Consolas; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="color: #3f5fbf; font-family: Consolas; font-size: 12.0pt;"> * </span><span style="color: #7f9fbf; font-family: Consolas; font-size: 12.0pt; mso-bidi-font-weight: bold;">@author</span><span style="color: #3f5fbf; font-family: Consolas; font-size: 12.0pt;"> rajesh.dixit</span><span style="font-family: Consolas; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="color: #3f5fbf; font-family: Consolas; font-size: 12.0pt;"> * </span><span style="color: #7f9fbf; font-family: Consolas; font-size: 12.0pt; mso-bidi-font-weight: bold;">@return</span><span style="font-family: Consolas; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="color: #3f5fbf; font-family: Consolas; font-size: 12.0pt;"> */</span><span style="font-family: Consolas; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: Consolas; font-size: 12pt;"> </span><span style="color: #7f0055; font-family: Consolas; font-size: 12.0pt; mso-bidi-font-weight: bold;">private</span><span style="font-family: Consolas; font-size: 12pt;"> </span><span style="color: #7f0055; font-family: Consolas; font-size: 12.0pt; mso-bidi-font-weight: bold;">static</span><span style="font-family: Consolas; font-size: 12pt;"> </span><span style="color: #7f0055; font-family: Consolas; font-size: 12.0pt; mso-bidi-font-weight: bold;">void</span><span style="font-family: Consolas; font-size: 12pt;"> getNextPalindrome(</span><span style="color: #7f0055; font-family: Consolas; font-size: 12.0pt; mso-bidi-font-weight: bold;">int</span><span style="font-family: Consolas; font-size: 12pt;">
</span><span style="color: #6a3e3e; font-family: Consolas; font-size: 12.0pt;">number</span><span style="font-family: Consolas; font-size: 12pt;">) {</span><span style="font-family: Consolas; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: Consolas; font-size: 12pt;"> </span><span style="font-family: Consolas; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: Consolas; font-size: 12pt;"> </span><span style="color: #3f5fbf; font-family: Consolas; font-size: 12.0pt;">/** To handle the case when all digits in
number are 9. */</span><span style="font-family: Consolas; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: Consolas; font-size: 12pt;"> </span><span style="color: #7f0055; font-family: Consolas; font-size: 12.0pt; mso-bidi-font-weight: bold;">if</span><span style="font-family: Consolas; font-size: 12pt;">((</span><span style="color: #7f0055; font-family: Consolas; font-size: 12.0pt; mso-bidi-font-weight: bold;">int</span><span style="font-family: Consolas; font-size: 12pt;">)Math.<i>log10</i>(</span><span style="color: #6a3e3e; font-family: Consolas; font-size: 12.0pt;">number</span><span style="font-family: Consolas; font-size: 12pt;">+1)!=(</span><span style="color: #7f0055; font-family: Consolas; font-size: 12.0pt; mso-bidi-font-weight: bold;">int</span><span style="font-family: Consolas; font-size: 12pt;">)Math.<i>log10</i>(</span><span style="color: #6a3e3e; font-family: Consolas; font-size: 12.0pt;">number</span><span style="font-family: Consolas; font-size: 12pt;">)) {</span><span style="font-family: Consolas; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: Consolas; font-size: 12pt;"> System.</span><i><span style="color: #0000c0; font-family: Consolas; font-size: 12.0pt; mso-bidi-font-weight: bold;">out</span></i><span style="font-family: Consolas; font-size: 12pt;">.println(</span><span style="color: #2a00ff; font-family: Consolas; font-size: 12.0pt;">"All 9s"</span><span style="font-family: Consolas; font-size: 12pt;">);</span><span style="font-family: Consolas; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: Consolas; font-size: 12pt;"> System.</span><i><span style="color: #0000c0; font-family: Consolas; font-size: 12.0pt; mso-bidi-font-weight: bold;">out</span></i><span style="font-family: Consolas; font-size: 12pt;">.println(</span><span style="color: #2a00ff; font-family: Consolas; font-size: 12.0pt;">"Next Palidrome for the number "</span><span style="font-family: Consolas; font-size: 12pt;">+ </span><span style="color: #6a3e3e; font-family: Consolas; font-size: 12.0pt;">number</span><span style="font-family: Consolas; font-size: 12pt;"> +</span><span style="color: #2a00ff; font-family: Consolas; font-size: 12.0pt;">" is: "</span><span style="font-family: Consolas; font-size: 12pt;">+(</span><span style="color: #6a3e3e; font-family: Consolas; font-size: 12.0pt;">number</span><span style="font-family: Consolas; font-size: 12pt;">+2));</span><span style="font-family: Consolas; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: Consolas; font-size: 12pt;"> }</span><span style="font-family: Consolas; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<br /></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: Consolas; font-size: 12pt;"> </span><span style="color: #7f0055; font-family: Consolas; font-size: 12.0pt; mso-bidi-font-weight: bold;">int</span><span style="font-family: Consolas; font-size: 12pt;">[] </span><span style="color: #6a3e3e; font-family: Consolas; font-size: 12.0pt;">array</span><span style="font-family: Consolas; font-size: 12pt;"> = <i>getNumberArray</i>(</span><span style="color: #6a3e3e; font-family: Consolas; font-size: 12.0pt;">number</span><span style="font-family: Consolas; font-size: 12pt;">);</span><span style="font-family: Consolas; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<br /></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: Consolas; font-size: 12pt;"> </span><span style="color: #7f0055; font-family: Consolas; font-size: 12.0pt; mso-bidi-font-weight: bold;">int</span><span style="font-family: Consolas; font-size: 12pt;"> </span><span style="color: #6a3e3e; font-family: Consolas; font-size: 12.0pt;">length</span><span style="font-family: Consolas; font-size: 12pt;"> = </span><span style="color: #6a3e3e; font-family: Consolas; font-size: 12.0pt;">array</span><span style="font-family: Consolas; font-size: 12pt;">.</span><span style="color: #0000c0; font-family: Consolas; font-size: 12.0pt;">length</span><span style="font-family: Consolas; font-size: 12pt;">;</span><span style="font-family: Consolas; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<br /></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: Consolas; font-size: 12pt;"> </span><span style="color: #3f7f5f; font-family: Consolas; font-size: 12.0pt;">// find the index of middle digit</span><span style="font-family: Consolas; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: Consolas; font-size: 12pt;"> </span><span style="color: #7f0055; font-family: Consolas; font-size: 12.0pt; mso-bidi-font-weight: bold;">int</span><span style="font-family: Consolas; font-size: 12pt;"> </span><span style="color: #6a3e3e; font-family: Consolas; font-size: 12.0pt;">mid</span><span style="font-family: Consolas; font-size: 12pt;"> = </span><span style="color: #6a3e3e; font-family: Consolas; font-size: 12.0pt;">length</span><span style="font-family: Consolas; font-size: 12pt;">/2;</span><span style="font-family: Consolas; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<br /></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: Consolas; font-size: 12pt;"> </span><span style="color: #3f7f5f; font-family: Consolas; font-size: 12.0pt;">// A boolean variable to check if copy of
left side to right is sufficient or not</span><span style="font-family: Consolas; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: Consolas; font-size: 12pt;"> </span><span style="color: #7f0055; font-family: Consolas; font-size: 12.0pt; mso-bidi-font-weight: bold;">boolean</span><span style="font-family: Consolas; font-size: 12pt;"> </span><span style="color: #6a3e3e; font-family: Consolas; font-size: 12.0pt;">leftSmaller</span><span style="font-family: Consolas; font-size: 12pt;"> = </span><span style="color: #7f0055; font-family: Consolas; font-size: 12.0pt; mso-bidi-font-weight: bold;">false</span><span style="font-family: Consolas; font-size: 12pt;">;</span><span style="font-family: Consolas; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<br /></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: Consolas; font-size: 12pt;"> </span><span style="color: #3f7f5f; font-family: Consolas; font-size: 12.0pt;">// end of left side is always 'mid -1'</span><span style="font-family: Consolas; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: Consolas; font-size: 12pt;"> </span><span style="color: #7f0055; font-family: Consolas; font-size: 12.0pt; mso-bidi-font-weight: bold;">int</span><span style="font-family: Consolas; font-size: 12pt;"> </span><span style="color: #6a3e3e; font-family: Consolas; font-size: 12.0pt;">i</span><span style="font-family: Consolas; font-size: 12pt;"> = </span><span style="color: #6a3e3e; font-family: Consolas; font-size: 12.0pt;">mid</span><span style="font-family: Consolas; font-size: 12pt;"> - 1;</span><span style="font-family: Consolas; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<br /></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: Consolas; font-size: 12pt;"> </span><span style="color: #3f7f5f; font-family: Consolas; font-size: 12.0pt;">// Beginning of right side depends if n is
odd or even</span><span style="font-family: Consolas; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: Consolas; font-size: 12pt;"> </span><span style="color: #7f0055; font-family: Consolas; font-size: 12.0pt; mso-bidi-font-weight: bold;">int</span><span style="font-family: Consolas; font-size: 12pt;"> </span><span style="color: #6a3e3e; font-family: Consolas; font-size: 12.0pt;">j</span><span style="font-family: Consolas; font-size: 12pt;"> = (</span><span style="color: #6a3e3e; font-family: Consolas; font-size: 12.0pt;">length</span><span style="font-family: Consolas; font-size: 12pt;">%2)!=0? </span><span style="color: #6a3e3e; font-family: Consolas; font-size: 12.0pt;">mid</span><span style="font-family: Consolas; font-size: 12pt;"> + 1 : </span><span style="color: #6a3e3e; font-family: Consolas; font-size: 12.0pt;">mid</span><span style="font-family: Consolas; font-size: 12pt;">;</span><span style="font-family: Consolas; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<br /></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: Consolas; font-size: 12pt;"> </span><span style="color: #7f0055; font-family: Consolas; font-size: 12.0pt; mso-bidi-font-weight: bold;">while</span><span style="font-family: Consolas; font-size: 12pt;">(</span><span style="color: #6a3e3e; font-family: Consolas; font-size: 12.0pt;">i</span><span style="font-family: Consolas; font-size: 12pt;"> >= 0 && </span><span style="color: #6a3e3e; font-family: Consolas; font-size: 12.0pt;">array</span><span style="font-family: Consolas; font-size: 12pt;">[</span><span style="color: #6a3e3e; font-family: Consolas; font-size: 12.0pt;">i</span><span style="font-family: Consolas; font-size: 12pt;">]==</span><span style="color: #6a3e3e; font-family: Consolas; font-size: 12.0pt;">array</span><span style="font-family: Consolas; font-size: 12pt;">[</span><span style="color: #6a3e3e; font-family: Consolas; font-size: 12.0pt;">j</span><span style="font-family: Consolas; font-size: 12pt;">]) {</span><span style="font-family: Consolas; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: Consolas; font-size: 12pt;"> </span><span style="color: #6a3e3e; font-family: Consolas; font-size: 12.0pt;">i</span><span style="font-family: Consolas; font-size: 12pt;">--;</span><span style="color: #6a3e3e; font-family: Consolas; font-size: 12.0pt;">j</span><span style="font-family: Consolas; font-size: 12pt;">++;</span><span style="font-family: Consolas; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: Consolas; font-size: 12pt;"> }</span><span style="font-family: Consolas; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<br /></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<br /></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: Consolas; font-size: 12pt;"> </span><span style="color: #3f7f5f; font-family: Consolas; font-size: 12.0pt;">/*</span><span style="font-family: Consolas; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="color: #3f7f5f; font-family: Consolas; font-size: 12.0pt;"> * leftSmaller when the left side array small
then right one</span><span style="font-family: Consolas; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="color: #3f7f5f; font-family: Consolas; font-size: 12.0pt;"> * or left array is equal to right array
(i<0)</span><span style="font-family: Consolas; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="color: #3f7f5f; font-family: Consolas; font-size: 12.0pt;"> * */</span><span style="font-family: Consolas; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: Consolas; font-size: 12pt;"> </span><span style="color: #7f0055; font-family: Consolas; font-size: 12.0pt; mso-bidi-font-weight: bold;">if</span><span style="font-family: Consolas; font-size: 12pt;">(</span><span style="color: #6a3e3e; font-family: Consolas; font-size: 12.0pt;">i</span><span style="font-family: Consolas; font-size: 12pt;"><0 || </span><span style="color: #6a3e3e; font-family: Consolas; font-size: 12.0pt;">array</span><span style="font-family: Consolas; font-size: 12pt;">[</span><span style="color: #6a3e3e; font-family: Consolas; font-size: 12.0pt;">i</span><span style="font-family: Consolas; font-size: 12pt;">]<</span><span style="color: #6a3e3e; font-family: Consolas; font-size: 12.0pt;">array</span><span style="font-family: Consolas; font-size: 12pt;">[</span><span style="color: #6a3e3e; font-family: Consolas; font-size: 12.0pt;">j</span><span style="font-family: Consolas; font-size: 12pt;">]) {</span><span style="font-family: Consolas; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: Consolas; font-size: 12pt;"> </span><span style="color: #6a3e3e; font-family: Consolas; font-size: 12.0pt;">leftSmaller</span><span style="font-family: Consolas; font-size: 12pt;"> = </span><span style="color: #7f0055; font-family: Consolas; font-size: 12.0pt; mso-bidi-font-weight: bold;">true</span><span style="font-family: Consolas; font-size: 12pt;">;</span><span style="font-family: Consolas; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: Consolas; font-size: 12pt;"> }</span><span style="font-family: Consolas; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<br /></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<br /></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: Consolas; font-size: 12pt;"> </span><span style="color: #3f7f5f; font-family: Consolas; font-size: 12.0pt;">// Copy the mirror of left to right</span><span style="font-family: Consolas; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: Consolas; font-size: 12pt;"> </span><span style="color: #7f0055; font-family: Consolas; font-size: 12.0pt; mso-bidi-font-weight: bold;">if</span><span style="font-family: Consolas; font-size: 12pt;">(!</span><span style="color: #6a3e3e; font-family: Consolas; font-size: 12.0pt;">leftSmaller</span><span style="font-family: Consolas; font-size: 12pt;">) {</span><span style="font-family: Consolas; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: Consolas; font-size: 12pt;"> </span><span style="color: #7f0055; font-family: Consolas; font-size: 12.0pt; mso-bidi-font-weight: bold;">while</span><span style="font-family: Consolas; font-size: 12pt;"> (</span><span style="color: #6a3e3e; font-family: Consolas; font-size: 12.0pt;">i</span><span style="font-family: Consolas; font-size: 12pt;"> >= 0) {</span><span style="font-family: Consolas; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: Consolas; font-size: 12pt;"> </span><span style="color: #6a3e3e; font-family: Consolas; font-size: 12.0pt;">array</span><span style="font-family: Consolas; font-size: 12pt;">[</span><span style="color: #6a3e3e; font-family: Consolas; font-size: 12.0pt;">j</span><span style="font-family: Consolas; font-size: 12pt;">] = </span><span style="color: #6a3e3e; font-family: Consolas; font-size: 12.0pt;">array</span><span style="font-family: Consolas; font-size: 12pt;">[</span><span style="color: #6a3e3e; font-family: Consolas; font-size: 12.0pt;">i</span><span style="font-family: Consolas; font-size: 12pt;">];</span><span style="font-family: Consolas; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: Consolas; font-size: 12pt;"> </span><span style="color: #6a3e3e; font-family: Consolas; font-size: 12.0pt;">j</span><span style="font-family: Consolas; font-size: 12pt;">++;</span><span style="font-family: Consolas; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: Consolas; font-size: 12pt;"> </span><span style="color: #6a3e3e; font-family: Consolas; font-size: 12.0pt;">i</span><span style="font-family: Consolas; font-size: 12pt;">--;</span><span style="font-family: Consolas; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: Consolas; font-size: 12pt;"> }</span><span style="font-family: Consolas; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: Consolas; font-size: 12pt;"> } </span><span style="color: #7f0055; font-family: Consolas; font-size: 12.0pt; mso-bidi-font-weight: bold;">else</span><span style="font-family: Consolas; font-size: 12pt;"> {</span><span style="font-family: Consolas; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: Consolas; font-size: 12pt;"> </span><span style="color: #3f7f5f; font-family: Consolas; font-size: 12.0pt;">/* Case: When left side is small or
equal to right side.</span><span style="font-family: Consolas; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="color: #3f7f5f; font-family: Consolas; font-size: 12.0pt;"> * need to increment the middle element.</span><span style="font-family: Consolas; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="color: #3f7f5f; font-family: Consolas; font-size: 12.0pt;"> * */</span><span style="font-family: Consolas; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: Consolas; font-size: 12pt;"> </span><span style="color: #6a3e3e; font-family: Consolas; font-size: 12.0pt;">i</span><span style="font-family: Consolas; font-size: 12pt;"> = </span><span style="color: #6a3e3e; font-family: Consolas; font-size: 12.0pt;">mid</span><span style="font-family: Consolas; font-size: 12pt;"> - 1;</span><span style="font-family: Consolas; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: Consolas; font-size: 12pt;"> </span><span style="color: #7f0055; font-family: Consolas; font-size: 12.0pt; mso-bidi-font-weight: bold;">int</span><span style="font-family: Consolas; font-size: 12pt;"> </span><span style="color: #6a3e3e; font-family: Consolas; font-size: 12.0pt;">carry</span><span style="font-family: Consolas; font-size: 12pt;"> = 1;</span><span style="font-family: Consolas; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: Consolas; font-size: 12pt;"> </span><span style="color: #7f0055; font-family: Consolas; font-size: 12.0pt; mso-bidi-font-weight: bold;">if</span><span style="font-family: Consolas; font-size: 12pt;">(</span><span style="color: #6a3e3e; font-family: Consolas; font-size: 12.0pt;">length</span><span style="font-family: Consolas; font-size: 12pt;">%2==1) {</span><span style="font-family: Consolas; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: Consolas; font-size: 12pt;"> </span><span style="color: #7f0055; font-family: Consolas; font-size: 12.0pt; mso-bidi-font-weight: bold;">int</span><span style="font-family: Consolas; font-size: 12pt;">
</span><span style="color: #6a3e3e; font-family: Consolas; font-size: 12.0pt;">temp</span><span style="font-family: Consolas; font-size: 12pt;"> = </span><span style="color: #6a3e3e; font-family: Consolas; font-size: 12.0pt;">array</span><span style="font-family: Consolas; font-size: 12pt;">[</span><span style="color: #6a3e3e; font-family: Consolas; font-size: 12.0pt;">mid</span><span style="font-family: Consolas; font-size: 12pt;">]+</span><span style="color: #6a3e3e; font-family: Consolas; font-size: 12.0pt;">carry</span><span style="font-family: Consolas; font-size: 12pt;">;</span><span style="font-family: Consolas; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: Consolas; font-size: 12pt;"> </span><span style="color: #6a3e3e; font-family: Consolas; font-size: 12.0pt;">carry</span><span style="font-family: Consolas; font-size: 12pt;"> = </span><span style="color: #6a3e3e; font-family: Consolas; font-size: 12.0pt;">temp</span><span style="font-family: Consolas; font-size: 12pt;">/10;</span><span style="font-family: Consolas; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: Consolas; font-size: 12pt;"> </span><span style="color: #6a3e3e; font-family: Consolas; font-size: 12.0pt;">array</span><span style="font-family: Consolas; font-size: 12pt;">[</span><span style="color: #6a3e3e; font-family: Consolas; font-size: 12.0pt;">mid</span><span style="font-family: Consolas; font-size: 12pt;">] = </span><span style="color: #6a3e3e; font-family: Consolas; font-size: 12.0pt;">temp</span><span style="font-family: Consolas; font-size: 12pt;">%10;</span><span style="font-family: Consolas; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: Consolas; font-size: 12pt;"> </span><span style="color: #6a3e3e; font-family: Consolas; font-size: 12.0pt;">j</span><span style="font-family: Consolas; font-size: 12pt;"> = </span><span style="color: #6a3e3e; font-family: Consolas; font-size: 12.0pt;">mid</span><span style="font-family: Consolas; font-size: 12pt;">+1;</span><span style="font-family: Consolas; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: Consolas; font-size: 12pt;"> } </span><span style="color: #7f0055; font-family: Consolas; font-size: 12.0pt; mso-bidi-font-weight: bold;">else</span><span style="font-family: Consolas; font-size: 12pt;"> {</span><span style="font-family: Consolas; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: Consolas; font-size: 12pt;"> </span><span style="color: #6a3e3e; font-family: Consolas; font-size: 12.0pt;">j</span><span style="font-family: Consolas; font-size: 12pt;"> = </span><span style="color: #6a3e3e; font-family: Consolas; font-size: 12.0pt;">mid</span><span style="font-family: Consolas; font-size: 12pt;">;</span><span style="font-family: Consolas; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: Consolas; font-size: 12pt;"> }</span><span style="font-family: Consolas; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<br /></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: Consolas; font-size: 12pt;"> </span><span style="color: #7f0055; font-family: Consolas; font-size: 12.0pt; mso-bidi-font-weight: bold;">while</span><span style="font-family: Consolas; font-size: 12pt;">(</span><span style="color: #6a3e3e; font-family: Consolas; font-size: 12.0pt;">i</span><span style="font-family: Consolas; font-size: 12pt;">>=0) {</span><span style="font-family: Consolas; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: Consolas; font-size: 12pt;"> </span><span style="color: #7f0055; font-family: Consolas; font-size: 12.0pt; mso-bidi-font-weight: bold;">int</span><span style="font-family: Consolas; font-size: 12pt;">
</span><span style="color: #6a3e3e; font-family: Consolas; font-size: 12.0pt;">temp</span><span style="font-family: Consolas; font-size: 12pt;"> = </span><span style="color: #6a3e3e; font-family: Consolas; font-size: 12.0pt;">array</span><span style="font-family: Consolas; font-size: 12pt;">[</span><span style="color: #6a3e3e; font-family: Consolas; font-size: 12.0pt;">i</span><span style="font-family: Consolas; font-size: 12pt;">]+</span><span style="color: #6a3e3e; font-family: Consolas; font-size: 12.0pt;">carry</span><span style="font-family: Consolas; font-size: 12pt;">;</span><span style="font-family: Consolas; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: Consolas; font-size: 12pt;"> </span><span style="color: #6a3e3e; font-family: Consolas; font-size: 12.0pt;">carry</span><span style="font-family: Consolas; font-size: 12pt;"> = </span><span style="color: #6a3e3e; font-family: Consolas; font-size: 12.0pt;">temp</span><span style="font-family: Consolas; font-size: 12pt;">/10;</span><span style="font-family: Consolas; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: Consolas; font-size: 12pt;"> </span><span style="color: #6a3e3e; font-family: Consolas; font-size: 12.0pt;">temp</span><span style="font-family: Consolas; font-size: 12pt;"> = </span><span style="color: #6a3e3e; font-family: Consolas; font-size: 12.0pt;">temp</span><span style="font-family: Consolas; font-size: 12pt;">%10;</span><span style="font-family: Consolas; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: Consolas; font-size: 12pt;"> </span><span style="color: #6a3e3e; font-family: Consolas; font-size: 12.0pt;">array</span><span style="font-family: Consolas; font-size: 12pt;">[</span><span style="color: #6a3e3e; font-family: Consolas; font-size: 12.0pt;">j</span><span style="font-family: Consolas; font-size: 12pt;">] = </span><span style="color: #6a3e3e; font-family: Consolas; font-size: 12.0pt;">temp</span><span style="font-family: Consolas; font-size: 12pt;">;</span><span style="font-family: Consolas; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: Consolas; font-size: 12pt;"> </span><span style="color: #6a3e3e; font-family: Consolas; font-size: 12.0pt;">array</span><span style="font-family: Consolas; font-size: 12pt;">[</span><span style="color: #6a3e3e; font-family: Consolas; font-size: 12.0pt;">i</span><span style="font-family: Consolas; font-size: 12pt;">] = </span><span style="color: #6a3e3e; font-family: Consolas; font-size: 12.0pt;">temp</span><span style="font-family: Consolas; font-size: 12pt;">;</span><span style="font-family: Consolas; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: Consolas; font-size: 12pt;"> </span><span style="color: #6a3e3e; font-family: Consolas; font-size: 12.0pt;">i</span><span style="font-family: Consolas; font-size: 12pt;">--;</span><span style="color: #6a3e3e; font-family: Consolas; font-size: 12.0pt;">j</span><span style="font-family: Consolas; font-size: 12pt;">++;</span><span style="font-family: Consolas; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: Consolas; font-size: 12pt;"> }</span><span style="font-family: Consolas; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: Consolas; font-size: 12pt;"> }</span><span style="font-family: Consolas; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<br /></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: Consolas; font-size: 12pt;"> System.</span><i><span style="color: #0000c0; font-family: Consolas; font-size: 12.0pt; mso-bidi-font-weight: bold;">out</span></i><span style="font-family: Consolas; font-size: 12pt;">.print(</span><span style="color: #2a00ff; font-family: Consolas; font-size: 12.0pt;">"Next Palidrome for the number "</span><span style="font-family: Consolas; font-size: 12pt;">+ </span><span style="color: #6a3e3e; font-family: Consolas; font-size: 12.0pt;">number</span><span style="font-family: Consolas; font-size: 12pt;"> +</span><span style="color: #2a00ff; font-family: Consolas; font-size: 12.0pt;">" is: "</span><span style="font-family: Consolas; font-size: 12pt;">);</span><span style="font-family: Consolas; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: Consolas; font-size: 12pt;"> <i>printArray</i>(</span><span style="color: #6a3e3e; font-family: Consolas; font-size: 12.0pt;">array</span><span style="font-family: Consolas; font-size: 12pt;">);</span><span style="font-family: Consolas; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: Consolas; font-size: 12pt;"> }</span><span style="font-family: Consolas; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<br /></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<br /></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: Consolas; font-size: 12pt;"> </span><span style="color: #3f5fbf; font-family: Consolas; font-size: 12.0pt;">/**</span><span style="font-family: Consolas; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="color: #3f5fbf; font-family: Consolas; font-size: 12.0pt;"> *
Convert number into <u>int</u> Array</span><span style="font-family: Consolas; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="color: #3f5fbf; font-family: Consolas; font-size: 12.0pt;"> * </span><span style="color: #7f9fbf; font-family: Consolas; font-size: 12.0pt; mso-bidi-font-weight: bold;">@param</span><span style="color: #3f5fbf; font-family: Consolas; font-size: 12.0pt;"> number</span><span style="font-family: Consolas; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="color: #3f5fbf; font-family: Consolas; font-size: 12.0pt;"> * </span><span style="color: #7f9fbf; font-family: Consolas; font-size: 12.0pt; mso-bidi-font-weight: bold;">@return</span><span style="color: #3f5fbf; font-family: Consolas; font-size: 12.0pt;"> <u>int</u>[] array</span><span style="font-family: Consolas; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="color: #3f5fbf; font-family: Consolas; font-size: 12.0pt;"> */</span><span style="font-family: Consolas; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: Consolas; font-size: 12pt;"> </span><span style="color: #7f0055; font-family: Consolas; font-size: 12.0pt; mso-bidi-font-weight: bold;">private</span><span style="font-family: Consolas; font-size: 12pt;"> </span><span style="color: #7f0055; font-family: Consolas; font-size: 12.0pt; mso-bidi-font-weight: bold;">static</span><span style="font-family: Consolas; font-size: 12pt;"> </span><span style="color: #7f0055; font-family: Consolas; font-size: 12.0pt; mso-bidi-font-weight: bold;">int</span><span style="font-family: Consolas; font-size: 12pt;">[] getNumberArray(</span><span style="color: #7f0055; font-family: Consolas; font-size: 12.0pt; mso-bidi-font-weight: bold;">int</span><span style="font-family: Consolas; font-size: 12pt;">
</span><span style="color: #6a3e3e; font-family: Consolas; font-size: 12.0pt;">number</span><span style="font-family: Consolas; font-size: 12pt;">) {</span><span style="font-family: Consolas; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<br /></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: Consolas; font-size: 12pt;"> </span><span style="color: #7f0055; font-family: Consolas; font-size: 12.0pt; mso-bidi-font-weight: bold;">int</span><span style="font-family: Consolas; font-size: 12pt;"> </span><span style="color: #6a3e3e; font-family: Consolas; font-size: 12.0pt;">length</span><span style="font-family: Consolas; font-size: 12pt;"> = (</span><span style="color: #7f0055; font-family: Consolas; font-size: 12.0pt; mso-bidi-font-weight: bold;">int</span><span style="font-family: Consolas; font-size: 12pt;">)(Math.<i>log10</i>(</span><span style="color: #6a3e3e; font-family: Consolas; font-size: 12.0pt;">number</span><span style="font-family: Consolas; font-size: 12pt;">)+1);</span><span style="font-family: Consolas; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<br /></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: Consolas; font-size: 12pt;"> </span><span style="color: #7f0055; font-family: Consolas; font-size: 12.0pt; mso-bidi-font-weight: bold;">int</span><span style="font-family: Consolas; font-size: 12pt;">[] </span><span style="color: #6a3e3e; font-family: Consolas; font-size: 12.0pt;">array</span><span style="font-family: Consolas; font-size: 12pt;"> = </span><span style="color: #7f0055; font-family: Consolas; font-size: 12.0pt; mso-bidi-font-weight: bold;">new</span><span style="font-family: Consolas; font-size: 12pt;">
</span><span style="color: #7f0055; font-family: Consolas; font-size: 12.0pt; mso-bidi-font-weight: bold;">int</span><span style="font-family: Consolas; font-size: 12pt;">[</span><span style="color: #6a3e3e; font-family: Consolas; font-size: 12.0pt;">length</span><span style="font-family: Consolas; font-size: 12pt;">];</span><span style="font-family: Consolas; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<br /></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: Consolas; font-size: 12pt;"> </span><span style="color: #7f0055; font-family: Consolas; font-size: 12.0pt; mso-bidi-font-weight: bold;">for</span><span style="font-family: Consolas; font-size: 12pt;"> (</span><span style="color: #7f0055; font-family: Consolas; font-size: 12.0pt; mso-bidi-font-weight: bold;">int</span><span style="font-family: Consolas; font-size: 12pt;">
</span><span style="color: #6a3e3e; font-family: Consolas; font-size: 12.0pt;">i</span><span style="font-family: Consolas; font-size: 12pt;"> = 0; </span><span style="color: #6a3e3e; font-family: Consolas; font-size: 12.0pt;">i</span><span style="font-family: Consolas; font-size: 12pt;"> < </span><span style="color: #6a3e3e; font-family: Consolas; font-size: 12.0pt;">length</span><span style="font-family: Consolas; font-size: 12pt;">; </span><span style="color: #6a3e3e; font-family: Consolas; font-size: 12.0pt;">i</span><span style="font-family: Consolas; font-size: 12pt;">++) {</span><span style="font-family: Consolas; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: Consolas; font-size: 12pt;"> </span><span style="color: #7f0055; font-family: Consolas; font-size: 12.0pt; mso-bidi-font-weight: bold;">int</span><span style="font-family: Consolas; font-size: 12pt;"> </span><span style="color: #6a3e3e; font-family: Consolas; font-size: 12.0pt;">val</span><span style="font-family: Consolas; font-size: 12pt;"> = </span><span style="color: #6a3e3e; font-family: Consolas; font-size: 12.0pt;">number</span><span style="font-family: Consolas; font-size: 12pt;">%10;</span><span style="font-family: Consolas; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: Consolas; font-size: 12pt;"> </span><span style="color: #6a3e3e; font-family: Consolas; font-size: 12.0pt;">number</span><span style="font-family: Consolas; font-size: 12pt;"> = </span><span style="color: #6a3e3e; font-family: Consolas; font-size: 12.0pt;">number</span><span style="font-family: Consolas; font-size: 12pt;">/10;</span><span style="font-family: Consolas; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: Consolas; font-size: 12pt;"> </span><span style="color: #6a3e3e; font-family: Consolas; font-size: 12.0pt;">array</span><span style="font-family: Consolas; font-size: 12pt;">[</span><span style="color: #6a3e3e; font-family: Consolas; font-size: 12.0pt;">length</span><span style="font-family: Consolas; font-size: 12pt;">-</span><span style="color: #6a3e3e; font-family: Consolas; font-size: 12.0pt;">i</span><span style="font-family: Consolas; font-size: 12pt;">-1] = </span><span style="color: #6a3e3e; font-family: Consolas; font-size: 12.0pt;">val</span><span style="font-family: Consolas; font-size: 12pt;">; </span><span style="font-family: Consolas; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: Consolas; font-size: 12pt;"> }</span><span style="font-family: Consolas; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: Consolas; font-size: 12pt;"> </span><span style="color: #7f0055; font-family: Consolas; font-size: 12.0pt; mso-bidi-font-weight: bold;">return</span><span style="font-family: Consolas; font-size: 12pt;"> </span><span style="color: #6a3e3e; font-family: Consolas; font-size: 12.0pt;">array</span><span style="font-family: Consolas; font-size: 12pt;">;</span><span style="font-family: Consolas; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: Consolas; font-size: 12pt;"> }</span><span style="font-family: Consolas; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<br /></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<br /></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: Consolas; font-size: 12pt;"> </span><span style="color: #3f5fbf; font-family: Consolas; font-size: 12.0pt;">/**</span><span style="font-family: Consolas; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="color: #3f5fbf; font-family: Consolas; font-size: 12.0pt;"> *
Utility Method to print numbers.</span><span style="font-family: Consolas; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="color: #3f5fbf; font-family: Consolas; font-size: 12.0pt;"> * </span><span style="color: #7f9fbf; font-family: Consolas; font-size: 12.0pt; mso-bidi-font-weight: bold;">@param</span><span style="color: #3f5fbf; font-family: Consolas; font-size: 12.0pt;"> number</span><span style="font-family: Consolas; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="color: #3f5fbf; font-family: Consolas; font-size: 12.0pt;"> */</span><span style="font-family: Consolas; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: Consolas; font-size: 12pt;"> </span><span style="color: #7f0055; font-family: Consolas; font-size: 12.0pt; mso-bidi-font-weight: bold;">private</span><span style="font-family: Consolas; font-size: 12pt;"> </span><span style="color: #7f0055; font-family: Consolas; font-size: 12.0pt; mso-bidi-font-weight: bold;">static</span><span style="font-family: Consolas; font-size: 12pt;"> </span><span style="color: #7f0055; font-family: Consolas; font-size: 12.0pt; mso-bidi-font-weight: bold;">void</span><span style="font-family: Consolas; font-size: 12pt;"> printArray(</span><span style="color: #7f0055; font-family: Consolas; font-size: 12.0pt; mso-bidi-font-weight: bold;">int</span><span style="font-family: Consolas; font-size: 12pt;">[]
</span><span style="color: #6a3e3e; font-family: Consolas; font-size: 12.0pt;">number</span><span style="font-family: Consolas; font-size: 12pt;">) {</span><span style="font-family: Consolas; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: Consolas; font-size: 12pt;"> </span><span style="color: #7f0055; font-family: Consolas; font-size: 12.0pt; mso-bidi-font-weight: bold;">for</span><span style="font-family: Consolas; font-size: 12pt;">(</span><span style="color: #7f0055; font-family: Consolas; font-size: 12.0pt; mso-bidi-font-weight: bold;">int</span><span style="font-family: Consolas; font-size: 12pt;">
</span><span style="color: #6a3e3e; font-family: Consolas; font-size: 12.0pt;">value</span><span style="font-family: Consolas; font-size: 12pt;"> : </span><span style="color: #6a3e3e; font-family: Consolas; font-size: 12.0pt;">number</span><span style="font-family: Consolas; font-size: 12pt;">) {</span><span style="font-family: Consolas; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: Consolas; font-size: 12pt;"> System.</span><i><span style="color: #0000c0; font-family: Consolas; font-size: 12.0pt; mso-bidi-font-weight: bold;">out</span></i><span style="font-family: Consolas; font-size: 12pt;">.print(</span><span style="color: #6a3e3e; font-family: Consolas; font-size: 12.0pt;">value</span><span style="font-family: Consolas; font-size: 12pt;">);</span><span style="font-family: Consolas; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: Consolas; font-size: 12pt;"> }</span><span style="font-family: Consolas; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: Consolas; font-size: 12pt;"> }</span><span style="font-family: Consolas; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<br /></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: Consolas; font-size: 12pt;"> </span><span style="color: #3f5fbf; font-family: Consolas; font-size: 12.0pt;">/**</span><span style="font-family: Consolas; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="color: #3f5fbf; font-family: Consolas; font-size: 12.0pt;"> *
Driver Method</span><span style="font-family: Consolas; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="color: #3f5fbf; font-family: Consolas; font-size: 12.0pt;"> * </span><span style="color: #7f9fbf; font-family: Consolas; font-size: 12.0pt; mso-bidi-font-weight: bold;">@param</span><span style="color: #3f5fbf; font-family: Consolas; font-size: 12.0pt;"> args</span><span style="font-family: Consolas; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="color: #3f5fbf; font-family: Consolas; font-size: 12.0pt;"> */</span><span style="font-family: Consolas; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: Consolas; font-size: 12pt;"> </span><span style="color: #7f0055; font-family: Consolas; font-size: 12.0pt; mso-bidi-font-weight: bold;">public</span><span style="font-family: Consolas; font-size: 12pt;"> </span><span style="color: #7f0055; font-family: Consolas; font-size: 12.0pt; mso-bidi-font-weight: bold;">static</span><span style="font-family: Consolas; font-size: 12pt;"> </span><span style="color: #7f0055; font-family: Consolas; font-size: 12.0pt; mso-bidi-font-weight: bold;">void</span><span style="font-family: Consolas; font-size: 12pt;"> main(String[] </span><span style="color: #6a3e3e; font-family: Consolas; font-size: 12.0pt;">args</span><span style="font-family: Consolas; font-size: 12pt;">) {</span><span style="font-family: Consolas; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<br /></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: Consolas; font-size: 12pt;"> </span><span style="color: #7f0055; font-family: Consolas; font-size: 12.0pt; mso-bidi-font-weight: bold;">int</span><span style="font-family: Consolas; font-size: 12pt;"> </span><span style="color: #6a3e3e; font-family: Consolas; font-size: 12.0pt;">number</span><span style="font-family: Consolas; font-size: 12pt;"> = 34656;</span><span style="font-family: Consolas; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: Consolas; font-size: 12pt;"> <i>getNextPalindrome</i>(</span><span style="color: #6a3e3e; font-family: Consolas; font-size: 12.0pt;">number</span><span style="font-family: Consolas; font-size: 12pt;">);</span><span style="font-family: Consolas; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: Consolas; font-size: 12pt;"> }</span><span style="font-family: Consolas; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: Consolas; font-size: 12pt;">}</span><span style="font-size: 12.0pt;"><o:p></o:p></span></div>
</div>
</div>
javaexplor03http://www.blogger.com/profile/07455293496498711738noreply@blogger.com15tag:blogger.com,1999:blog-615973148715732292.post-2854180971135700112017-06-14T19:35:00.004-07:002017-06-15T00:28:34.594-07:00Array | Noble integers in an array<div dir="ltr" style="text-align: left;" trbidi="on">
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<span style="font-family: "book antiqua", serif; font-size: 13pt;">Given an array, find a Noble integer in it.</span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<b><span lang="EN-GB" style="font-family: "book antiqua" , serif; font-size: 13pt;">Noble Integer<o:p></o:p></span></b></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<span lang="EN-GB" style="font-family: "book antiqua" , serif; font-size: 13pt;">An integer x is said to be Noble in an array if the number of integers greater than x is equal to x. If there are many Noble integers, return any of them. If there is no, then return -1.<o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<span lang="EN-GB" style="font-family: "consolas"; font-size: 10pt;"> <o:p></o:p></span></div>
<div style="background: #DBE5F1; border: solid windowtext 1.0pt; mso-background-themecolor: accent1; mso-background-themetint: 51; mso-border-alt: solid windowtext .5pt; mso-element: para-border-div; padding: 1.0pt 4.0pt 1.0pt 4.0pt;">
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span lang="EN-GB" style="color: #7f0055; font-family: "consolas"; font-size: 12.0pt;">private</span><span lang="EN-GB" style="font-family: "consolas"; font-size: 12pt;"> </span><span lang="EN-GB" style="color: #7f0055; font-family: "consolas"; font-size: 12.0pt;">static</span><span lang="EN-GB" style="font-family: "consolas"; font-size: 12pt;"> </span><span lang="EN-GB" style="color: #7f0055; font-family: "consolas"; font-size: 12.0pt;">int</span><span lang="EN-GB" style="font-family: "consolas"; font-size: 12pt;"> findNobleInteger(</span><span lang="EN-GB" style="color: #7f0055; font-family: "consolas"; font-size: 12.0pt;">int</span><span lang="EN-GB" style="font-family: "consolas"; font-size: 12pt;">[] </span><span lang="EN-GB" style="color: #6a3e3e; font-family: "consolas"; font-size: 12.0pt;">array</span><span lang="EN-GB" style="font-family: "consolas"; font-size: 12pt;">) {</span><span lang="EN-GB" style="font-family: "consolas"; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span lang="EN-GB" style="font-family: "consolas"; font-size: 12pt;"> </span><span lang="EN-GB" style="color: #7f0055; font-family: "consolas"; font-size: 12.0pt;">int</span><span lang="EN-GB" style="font-family: "consolas"; font-size: 12pt;"> </span><span lang="EN-GB" style="color: #6a3e3e; font-family: "consolas"; font-size: 12.0pt;">noble</span><span lang="EN-GB" style="font-family: "consolas"; font-size: 12pt;"> = -1;</span><span lang="EN-GB" style="font-family: "consolas"; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span lang="EN-GB" style="font-family: "consolas"; font-size: 12pt;"> /**Sort the array. */</span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span lang="EN-GB" style="font-family: "consolas"; font-size: 12pt;"> Arrays.<i>sort</i>(</span><span lang="EN-GB" style="color: #6a3e3e; font-family: "consolas"; font-size: 12.0pt;">array</span><span lang="EN-GB" style="font-family: "consolas"; font-size: 12pt;">);</span><span lang="EN-GB" style="font-family: "consolas"; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span lang="EN-GB" style="font-family: "consolas"; font-size: 12pt;"><br /></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span lang="EN-GB" style="font-family: "consolas"; font-size: 12pt;"> </span><span lang="EN-GB" style="color: #7f0055; font-family: "consolas"; font-size: 12.0pt;">int</span><span lang="EN-GB" style="font-family: "consolas"; font-size: 12pt;"> </span><span lang="EN-GB" style="color: #6a3e3e; font-family: "consolas"; font-size: 12.0pt;">length</span><span lang="EN-GB" style="font-family: "consolas"; font-size: 12pt;"> = </span><span lang="EN-GB" style="color: #6a3e3e; font-family: "consolas"; font-size: 12.0pt;">array</span><span lang="EN-GB" style="font-family: "consolas"; font-size: 12pt;">.</span><span lang="EN-GB" style="color: #0000c0; font-family: "consolas"; font-size: 12.0pt;">length</span><span lang="EN-GB" style="font-family: "consolas"; font-size: 12pt;">;</span><span lang="EN-GB" style="font-family: "consolas"; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span lang="EN-GB" style="font-family: "consolas"; font-size: 12pt;"> </span><span lang="EN-GB" style="color: #7f0055; font-family: "consolas"; font-size: 12.0pt;">for</span><span lang="EN-GB" style="font-family: "consolas"; font-size: 12pt;"> (</span><span lang="EN-GB" style="color: #7f0055; font-family: "consolas"; font-size: 12.0pt;">int</span><span lang="EN-GB" style="font-family: "consolas"; font-size: 12pt;"> </span><span lang="EN-GB" style="color: #6a3e3e; font-family: "consolas"; font-size: 12.0pt;">i</span><span lang="EN-GB" style="font-family: "consolas"; font-size: 12pt;"> = 0; </span><span lang="EN-GB" style="color: #6a3e3e; font-family: "consolas"; font-size: 12.0pt;">i</span><span lang="EN-GB" style="font-family: "consolas"; font-size: 12pt;"> < </span><span lang="EN-GB" style="color: #6a3e3e; font-family: "consolas"; font-size: 12.0pt;">length</span><span lang="EN-GB" style="font-family: "consolas"; font-size: 12pt;">; </span><span lang="EN-GB" style="color: #6a3e3e; font-family: "consolas"; font-size: 12.0pt;">i</span><span lang="EN-GB" style="font-family: "consolas"; font-size: 12pt;">++) {</span><span lang="EN-GB" style="font-family: "consolas"; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span lang="EN-GB" style="font-family: "consolas"; font-size: 12pt;"> </span><span lang="EN-GB" style="color: #7f0055; font-family: "consolas"; font-size: 12.0pt;">if</span><span lang="EN-GB" style="font-family: "consolas"; font-size: 12pt;"> (</span><span lang="EN-GB" style="color: #6a3e3e; font-family: "consolas"; font-size: 12.0pt;">array</span><span lang="EN-GB" style="font-family: "consolas"; font-size: 12pt;">[</span><span lang="EN-GB" style="color: #6a3e3e; font-family: "consolas"; font-size: 12.0pt;">i</span><span lang="EN-GB" style="font-family: "consolas"; font-size: 12pt;">] == </span><span lang="EN-GB" style="color: #6a3e3e; font-family: "consolas"; font-size: 12.0pt;">array</span><span lang="EN-GB" style="font-family: "consolas"; font-size: 12pt;">[</span><span lang="EN-GB" style="color: #6a3e3e; font-family: "consolas"; font-size: 12.0pt;">i</span><span lang="EN-GB" style="font-family: "consolas"; font-size: 12pt;">+1]) {</span><span lang="EN-GB" style="font-family: "consolas"; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span lang="EN-GB" style="font-family: "consolas"; font-size: 12pt;"> </span><span lang="EN-GB" style="color: #7f0055; font-family: "consolas"; font-size: 12.0pt;">continue</span><span lang="EN-GB" style="font-family: "consolas"; font-size: 12pt;">;</span><span lang="EN-GB" style="font-family: "consolas"; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span lang="EN-GB" style="font-family: "consolas"; font-size: 12pt;"> }</span><span lang="EN-GB" style="font-family: "consolas"; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span lang="EN-GB" style="font-family: "consolas"; font-size: 12pt;"> /**Check wheter the small number count is greater than number.*/ </span><span lang="EN-GB" style="font-family: "consolas"; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span lang="EN-GB" style="font-family: "consolas"; font-size: 12pt;"> </span><span lang="EN-GB" style="color: #7f0055; font-family: "consolas"; font-size: 12.0pt;">if</span><span lang="EN-GB" style="font-family: "consolas"; font-size: 12pt;">(</span><span lang="EN-GB" style="color: #6a3e3e; font-family: "consolas"; font-size: 12.0pt;">array</span><span lang="EN-GB" style="font-family: "consolas"; font-size: 12pt;">[</span><span lang="EN-GB" style="color: #6a3e3e; font-family: "consolas"; font-size: 12.0pt;">i</span><span lang="EN-GB" style="font-family: "consolas"; font-size: 12pt;">]<</span><span lang="EN-GB" style="color: #6a3e3e; font-family: "consolas"; font-size: 12.0pt;">length</span><span lang="EN-GB" style="font-family: "consolas"; font-size: 12pt;">-</span><span lang="EN-GB" style="color: #6a3e3e; font-family: "consolas"; font-size: 12.0pt;">i</span><span lang="EN-GB" style="font-family: "consolas"; font-size: 12pt;">) {</span><span lang="EN-GB" style="font-family: "consolas"; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span lang="EN-GB" style="font-family: "consolas"; font-size: 12pt;"> </span><span lang="EN-GB" style="color: #6a3e3e; font-family: "consolas"; font-size: 12.0pt;">noble</span><span lang="EN-GB" style="font-family: "consolas"; font-size: 12pt;"> = </span><span lang="EN-GB" style="color: #6a3e3e; font-family: "consolas"; font-size: 12.0pt;">array</span><span lang="EN-GB" style="font-family: "consolas"; font-size: 12pt;">[</span><span lang="EN-GB" style="color: #6a3e3e; font-family: "consolas"; font-size: 12.0pt;">i</span><span lang="EN-GB" style="font-family: "consolas"; font-size: 12pt;">];</span><span lang="EN-GB" style="font-family: "consolas"; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span lang="EN-GB" style="font-family: "consolas"; font-size: 12pt;"> </span><span lang="EN-GB" style="color: #7f0055; font-family: "consolas"; font-size: 12.0pt;">break</span><span lang="EN-GB" style="font-family: "consolas"; font-size: 12pt;">;</span><span lang="EN-GB" style="font-family: "consolas"; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span lang="EN-GB" style="font-family: "consolas"; font-size: 12pt;"> }</span><span lang="EN-GB" style="font-family: "consolas"; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span lang="EN-GB" style="font-family: "consolas"; font-size: 12pt;"> }</span><span lang="EN-GB" style="font-family: "consolas"; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span lang="EN-GB" style="font-family: "consolas"; font-size: 12pt;"> </span><span lang="EN-GB" style="color: #7f0055; font-family: "consolas"; font-size: 12.0pt;">return </span><span lang="EN-GB" style="color: #6a3e3e; font-family: "consolas"; font-size: 12.0pt;">noble</span><span lang="EN-GB" style="font-family: "consolas"; font-size: 12pt;">;</span><span lang="EN-GB" style="font-family: "consolas"; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; padding: 0in;">
<span lang="EN-GB" style="font-family: "consolas"; font-size: 12pt; line-height: 115%;">}</span></div>
</div>
</div>
javaexplor03http://www.blogger.com/profile/07455293496498711738noreply@blogger.com0tag:blogger.com,1999:blog-615973148715732292.post-19221606220918553982017-06-10T20:16:00.002-07:002017-06-10T21:06:50.411-07:00The purpose of software tests<div dir="ltr" style="text-align: left;" trbidi="on">
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in;">
<span style="font-family: "book antiqua" , serif; font-size: 13pt;">Software testing is a process of executing a program or application with the intent of finding the software bugs. It can also be stated as the </span><b style="font-family: "Book Antiqua", serif; font-size: 13pt;">process of validating and verifying </b><span style="font-family: "book antiqua" , serif; font-size: 13pt;">that a software program or application or product: Meets the business and technical requirements that guided its design and development.</span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in;">
<br /></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in;">
<b><span style="font-family: "book antiqua" , serif; font-size: 14pt;">What are software tests?<o:p></o:p></span></b></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in;">
<span style="font-family: "book antiqua" , "serif"; font-size: 13.0pt;">A software test is a piece of software, which executes another piece of software. It validates if that code results in the <b>expected state (state testing)</b> or executes the expected sequence of events <b>(behavior testing).</b><o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in;">
<br /></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in;">
<span style="font-family: "book antiqua" , "serif"; font-size: 13.0pt;">Software unit tests help the developer to verify that the logic of a piece of the program is correct.<o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in;">
<br /></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in;">
<span style="font-family: "book antiqua" , "serif"; font-size: 13.0pt;">Running tests automatically helps to identify software regressions introduced by changes in the source code. Having high test coverage of code allows us to continue developing features without having to perform lots of manual tests.<o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in;">
<br /></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in;">
<b><u><span style="color: #002060; font-family: "book antiqua" , "serif"; font-size: 14.0pt;">Testing terminology<o:p></o:p></span></u></b></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in;">
<b><span style="font-family: "book antiqua" , "serif"; font-size: 14.0pt;">1. Code (or application) under test<o:p></o:p></span></b></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in;">
<span style="font-family: "book antiqua" , "serif"; font-size: 13.0pt;">The code which is tested is typically called the code under test. If we are testing an application, this is called the application under test.<o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in;">
<br /></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in;">
<b><span style="font-family: "book antiqua" , "serif"; font-size: 14.0pt;">2. Test fixture<o:p></o:p></span></b></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in;">
<span style="font-family: "book antiqua" , "serif"; font-size: 13.0pt;">A test fixture is a fixed state in code which is tested used as input for a test. Another way to describe this is a test precondition.<o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in;">
<br /></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in;">
<span style="font-family: "book antiqua" , "serif"; font-size: 13.0pt;">For example, a test fixture might be a fixed string, which is used as input for a method. The test would validate if the method behaves correctly with this input.<o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in;">
<br /></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in;">
<b><span style="color: #c00000; font-family: "book antiqua" , "serif"; font-size: 14.0pt;">3. Unit tests and unit testing<o:p></o:p></span></b></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in;">
<span style="font-family: "book antiqua" , "serif"; font-size: 13.0pt;">A unit test is a piece of code written by a developer that executes a specific functionality in the code to be tested and asserts a certain behavior or state.<o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in;">
<br /></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in;">
<b><span style="color: #c00000; font-family: "book antiqua" , "serif"; font-size: 13.0pt;">The percentage of code which is tested by unit tests is typically called test coverage.<o:p></o:p></span></b></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in;">
<br /></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in;">
<span style="font-family: "book antiqua" , "serif"; font-size: 13.0pt;">A unit test targets a small unit of code, e.g., a <b>method or a class</b>. External dependencies should be removed from unit tests, e.g., by replacing the dependency with a test implementation or a (mock) object created by a test framework.<o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in;">
<br /></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in;">
<span style="font-family: "book antiqua" , "serif"; font-size: 13.0pt;">Unit tests are not suitable for testing complex user interface or component interaction. For this, we should develop integration tests.<o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in;">
<br /></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in;">
<b><span style="font-family: "book antiqua" , "serif"; font-size: 14.0pt;">4. Integration tests<o:p></o:p></span></b></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in;">
<span style="font-family: "book antiqua" , "serif"; font-size: 13.0pt;">An integration test aims to test the behavior of a component or the integration between a set of components. The term functional test is sometimes used as synonym for integration test. Integration tests check that the whole system works as intended; therefore they are reducing the need for intensive manual tests.<o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in;">
<br /></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in;">
<span style="font-family: "book antiqua" , "serif"; font-size: 13.0pt;">These kinds of tests allow you to translate user stories into a test suite. The test would resemble an expected user interaction with the application.<o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in;">
<br /></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in;">
<b><span style="font-family: "book antiqua" , "serif"; font-size: 14.0pt;">5. Behavior vs. state testing<o:p></o:p></span></b></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in;">
<span style="font-family: "book antiqua" , "serif"; font-size: 13.0pt;">A test is a behavior test (also called interaction test) if it checks if certain methods were called with the correct input parameters. A behavior test does not validate the result of a method call.<o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in;">
<br /></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in;">
<span style="font-family: "book antiqua" , "serif"; font-size: 13.0pt;">State testing is about validating the result. Behavior testing is about testing the behavior of the application under test.<o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in;">
<br /></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in;">
<span style="font-family: "book antiqua" , "serif"; font-size: 13.0pt;">While testing algorithms or system functionality, in most cases you may want to test state and not interactions. A typical test setup uses mocks or stubs of related classes to abstract the interactions with these other classes away afterwards you test the state or the behavior depending on your need.<o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in;">
<br /></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in;">
<b><span style="font-family: "book antiqua" , "serif"; font-size: 14.0pt;">6. Performance tests<o:p></o:p></span></b></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in;">
<span style="font-family: "book antiqua" , "serif"; font-size: 13.0pt;">Performance tests are used to benchmark software components repeatedly. Their purpose is to ensure that the code under test runs fast enough even if it’s under high load.<o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in;">
<br /></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in;">
<b><u><span style="color: #002060; font-family: "book antiqua" , "serif"; font-size: 14.0pt;">Testing frameworks for Java<o:p></o:p></span></u></b></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in;">
<span style="font-family: "book antiqua" , "serif"; font-size: 13.0pt;">There are several testing frameworks available for Java. The most popular ones are JUnit and TestNG<o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in;">
<br /></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in;">
<b><u><span style="color: #002060; font-family: "book antiqua" , "serif"; font-size: 14.0pt;">Where should the test be located?<o:p></o:p></span></u></b></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in;">
<span style="font-family: "book antiqua" , "serif"; font-size: 13.0pt;">Typical, unit tests are created in a separate project or separate source folder to keep the test code separate from the real code. The standard convention from the Maven and Gradle build tools is to use:<o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in;">
<br /></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in;">
<span style="font-family: "book antiqua" , "serif"; font-size: 13.0pt;">src/main/java - for Java classes<o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in;">
<br /></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in;">
<span style="font-family: "book antiqua" , "serif"; font-size: 13.0pt;">src/test/java - for test classes<o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in;">
<br /></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in;">
<b><u><span style="color: #002060; font-family: "book antiqua" , "serif"; font-size: 14.0pt;">Which part of the software should be tested?<o:p></o:p></span></u></b></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in;">
<span style="font-family: "book antiqua" , "serif"; font-size: 13.0pt;">It is a highly controversial topic as some developers believe every statement in code should be tested.</span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in;">
<br /></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in;">
<span style="font-family: "book antiqua" , "serif"; font-size: 13.0pt;">In any case, we should write software tests for the critical and complex parts of application. If we introduce new features a solid test suite also protects us against regression in existing code.</span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in;">
<br /></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in;">
<span style="font-family: "book antiqua" , "serif"; font-size: 13.0pt;">In general, it is safe to ignore trivial code (useless to write tests for getter and setter methods). Writing tests for these statements is time consuming and pointless, as you would be testing the Java virtual machine. The JVM itself already has test cases for this. If you are developing end user applications you are safe to assume that a field assignment works in Java.</span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in;">
<br /></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in;">
<b><span style="font-family: "book antiqua" , "serif"; font-size: 13.0pt;">If we start developing tests for an existing code base without any tests, it is good practice to start writing tests for code in which most of the errors happened in the past. This way we can focus on the critical parts of our application.<o:p></o:p></span></b></div>
</div>
javaexplor03http://www.blogger.com/profile/07455293496498711738noreply@blogger.com0tag:blogger.com,1999:blog-615973148715732292.post-12917703182726506542017-06-09T12:47:00.002-07:002017-06-09T12:48:02.160-07:00Why would one declare an immutable class final in Java?<div dir="ltr" style="text-align: left;" trbidi="on">
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in;">
<span style="font-family: "Book Antiqua", serif; font-size: 13pt;"><br /></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in;">
<span style="font-family: "Book Antiqua", serif; font-size: 13pt;">If you don't mark the class final, it might be possible for me to suddenly make your seemingly immutable class actually mutable.</span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in;">
<span style="font-family: "Book Antiqua", serif; font-size: 13pt;"><br /></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in;">
<b><span style="color: #002060; font-family: "Book Antiqua","serif"; font-size: 14.0pt; mso-bidi-font-size: 13.0pt;">Example:<o:p></o:p></span></b></div>
<div style="background: #C6D9F1; border: solid windowtext 1.0pt; mso-background-themecolor: text2; mso-background-themetint: 51; mso-border-alt: solid windowtext .5pt; mso-element: para-border-div; padding: 1.0pt 4.0pt 1.0pt 4.0pt;">
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="color: #7f0055; font-family: Consolas; font-size: 12.0pt; mso-bidi-font-size: 10.0pt; mso-bidi-font-weight: bold;">package</span><span style="font-family: Consolas; font-size: 12pt;"> com.dp;</span><span style="font-family: Consolas; font-size: 12.0pt; mso-bidi-font-size: 10.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="color: #7f0055; font-family: Consolas; font-size: 12.0pt; mso-bidi-font-size: 10.0pt; mso-bidi-font-weight: bold;">class</span><span style="font-family: Consolas; font-size: 12pt;"> Immutable {</span><span style="font-family: Consolas; font-size: 12.0pt; mso-bidi-font-size: 10.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: Consolas; font-size: 12pt;"> </span><span style="color: #7f0055; font-family: Consolas; font-size: 12.0pt; mso-bidi-font-size: 10.0pt; mso-bidi-font-weight: bold;">private</span><span style="font-family: Consolas; font-size: 12pt;"> </span><span style="color: #7f0055; font-family: Consolas; font-size: 12.0pt; mso-bidi-font-size: 10.0pt; mso-bidi-font-weight: bold;">final</span><span style="font-family: Consolas; font-size: 12pt;"> </span><span style="color: #7f0055; font-family: Consolas; font-size: 12.0pt; mso-bidi-font-size: 10.0pt; mso-bidi-font-weight: bold;">int</span><span style="font-family: Consolas; font-size: 12pt;"> </span><span style="color: #0000c0; font-family: Consolas; font-size: 12.0pt; mso-bidi-font-size: 10.0pt;">value</span><span style="font-family: Consolas; font-size: 12pt;">;</span><span style="font-family: Consolas; font-size: 12.0pt; mso-bidi-font-size: 10.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<br /></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: Consolas; font-size: 12pt;"> </span><span style="color: #7f0055; font-family: Consolas; font-size: 12.0pt; mso-bidi-font-size: 10.0pt; mso-bidi-font-weight: bold;">public</span><span style="font-family: Consolas; font-size: 12pt;"> Immutable(</span><span style="color: #7f0055; font-family: Consolas; font-size: 12.0pt; mso-bidi-font-size: 10.0pt; mso-bidi-font-weight: bold;">int</span><span style="font-family: Consolas; font-size: 12pt;"> </span><span style="color: #6a3e3e; font-family: Consolas; font-size: 12.0pt; mso-bidi-font-size: 10.0pt;">value</span><span style="font-family: Consolas; font-size: 12pt;">) {</span><span style="font-family: Consolas; font-size: 12.0pt; mso-bidi-font-size: 10.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: Consolas; font-size: 12pt;"> </span><span style="color: #7f0055; font-family: Consolas; font-size: 12.0pt; mso-bidi-font-size: 10.0pt; mso-bidi-font-weight: bold;">this</span><span style="font-family: Consolas; font-size: 12pt;">.</span><span style="color: #0000c0; font-family: Consolas; font-size: 12.0pt; mso-bidi-font-size: 10.0pt;">value</span><span style="font-family: Consolas; font-size: 12pt;"> = </span><span style="color: #6a3e3e; font-family: Consolas; font-size: 12.0pt; mso-bidi-font-size: 10.0pt;">value</span><span style="font-family: Consolas; font-size: 12pt;">;</span><span style="font-family: Consolas; font-size: 12.0pt; mso-bidi-font-size: 10.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: Consolas; font-size: 12pt;"> }</span><span style="font-family: Consolas; font-size: 12.0pt; mso-bidi-font-size: 10.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<br /></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: Consolas; font-size: 12pt;"> </span><span style="color: #7f0055; font-family: Consolas; font-size: 12.0pt; mso-bidi-font-size: 10.0pt; mso-bidi-font-weight: bold;">public</span><span style="font-family: Consolas; font-size: 12pt;"> </span><span style="color: #7f0055; font-family: Consolas; font-size: 12.0pt; mso-bidi-font-size: 10.0pt; mso-bidi-font-weight: bold;">int</span><span style="font-family: Consolas; font-size: 12pt;"> getValue() {</span><span style="font-family: Consolas; font-size: 12.0pt; mso-bidi-font-size: 10.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: Consolas; font-size: 12pt;"> </span><span style="color: #7f0055; font-family: Consolas; font-size: 12.0pt; mso-bidi-font-size: 10.0pt; mso-bidi-font-weight: bold;">return</span><span style="font-family: Consolas; font-size: 12pt;"> </span><span style="color: #0000c0; font-family: Consolas; font-size: 12.0pt; mso-bidi-font-size: 10.0pt;">value</span><span style="font-family: Consolas; font-size: 12pt;">;</span><span style="font-family: Consolas; font-size: 12.0pt; mso-bidi-font-size: 10.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: Consolas; font-size: 12pt;"> }</span><span style="font-family: Consolas; font-size: 12.0pt; mso-bidi-font-size: 10.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: Consolas; font-size: 12pt;">}</span><span style="font-family: Consolas; font-size: 12.0pt; mso-bidi-font-size: 10.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<br /></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="color: #7f0055; font-family: Consolas; font-size: 12.0pt; mso-bidi-font-size: 10.0pt; mso-bidi-font-weight: bold;">public</span><span style="font-family: Consolas; font-size: 12pt;"> </span><span style="color: #7f0055; font-family: Consolas; font-size: 12.0pt; mso-bidi-font-size: 10.0pt; mso-bidi-font-weight: bold;">class</span><span style="font-family: Consolas; font-size: 12pt;"> Mutable </span><span style="color: #7f0055; font-family: Consolas; font-size: 12.0pt; mso-bidi-font-size: 10.0pt; mso-bidi-font-weight: bold;">extends</span><span style="font-family: Consolas; font-size: 12pt;"> Immutable {</span><span style="font-family: Consolas; font-size: 12.0pt; mso-bidi-font-size: 10.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: Consolas; font-size: 12pt;"> </span><span style="color: #7f0055; font-family: Consolas; font-size: 12.0pt; mso-bidi-font-size: 10.0pt; mso-bidi-font-weight: bold;">private</span><span style="font-family: Consolas; font-size: 12pt;"> </span><span style="color: #7f0055; font-family: Consolas; font-size: 12.0pt; mso-bidi-font-size: 10.0pt; mso-bidi-font-weight: bold;">int</span><span style="font-family: Consolas; font-size: 12pt;"> </span><span style="color: #0000c0; font-family: Consolas; font-size: 12.0pt; mso-bidi-font-size: 10.0pt;">realValue</span><span style="font-family: Consolas; font-size: 12pt;">;</span><span style="font-family: Consolas; font-size: 12.0pt; mso-bidi-font-size: 10.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<br /></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: Consolas; font-size: 12pt;"> </span><span style="color: #7f0055; font-family: Consolas; font-size: 12.0pt; mso-bidi-font-size: 10.0pt; mso-bidi-font-weight: bold;">public</span><span style="font-family: Consolas; font-size: 12pt;"> Mutable(</span><span style="color: #7f0055; font-family: Consolas; font-size: 12.0pt; mso-bidi-font-size: 10.0pt; mso-bidi-font-weight: bold;">int</span><span style="font-family: Consolas; font-size: 12pt;"> </span><span style="color: #6a3e3e; font-family: Consolas; font-size: 12.0pt; mso-bidi-font-size: 10.0pt;">value</span><span style="font-family: Consolas; font-size: 12pt;">) {</span><span style="font-family: Consolas; font-size: 12.0pt; mso-bidi-font-size: 10.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: Consolas; font-size: 12pt;"> </span><span style="color: #7f0055; font-family: Consolas; font-size: 12.0pt; mso-bidi-font-size: 10.0pt; mso-bidi-font-weight: bold;">super</span><span style="font-family: Consolas; font-size: 12pt;">(</span><span style="color: #6a3e3e; font-family: Consolas; font-size: 12.0pt; mso-bidi-font-size: 10.0pt;">value</span><span style="font-family: Consolas; font-size: 12pt;">);</span><span style="font-family: Consolas; font-size: 12.0pt; mso-bidi-font-size: 10.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: Consolas; font-size: 12pt;"> </span><span style="color: #0000c0; font-family: Consolas; font-size: 12.0pt; mso-bidi-font-size: 10.0pt;">realValue</span><span style="font-family: Consolas; font-size: 12pt;"> = </span><span style="color: #6a3e3e; font-family: Consolas; font-size: 12.0pt; mso-bidi-font-size: 10.0pt;">value</span><span style="font-family: Consolas; font-size: 12pt;">;</span><span style="font-family: Consolas; font-size: 12.0pt; mso-bidi-font-size: 10.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: Consolas; font-size: 12pt;"> }</span><span style="font-family: Consolas; font-size: 12.0pt; mso-bidi-font-size: 10.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<br /></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: Consolas; font-size: 12pt;"> </span><span style="color: #7f0055; font-family: Consolas; font-size: 12.0pt; mso-bidi-font-size: 10.0pt; mso-bidi-font-weight: bold;">public</span><span style="font-family: Consolas; font-size: 12pt;"> </span><span style="color: #7f0055; font-family: Consolas; font-size: 12.0pt; mso-bidi-font-size: 10.0pt; mso-bidi-font-weight: bold;">int</span><span style="font-family: Consolas; font-size: 12pt;"> getValue() {</span><span style="font-family: Consolas; font-size: 12.0pt; mso-bidi-font-size: 10.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: Consolas; font-size: 12pt;"> </span><span style="color: #7f0055; font-family: Consolas; font-size: 12.0pt; mso-bidi-font-size: 10.0pt; mso-bidi-font-weight: bold;">return</span><span style="font-family: Consolas; font-size: 12pt;"> </span><span style="color: #0000c0; font-family: Consolas; font-size: 12.0pt; mso-bidi-font-size: 10.0pt;">realValue</span><span style="font-family: Consolas; font-size: 12pt;">;</span><span style="font-family: Consolas; font-size: 12.0pt; mso-bidi-font-size: 10.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: Consolas; font-size: 12pt;"> }</span><span style="font-family: Consolas; font-size: 12.0pt; mso-bidi-font-size: 10.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: Consolas; font-size: 12pt;"> </span><span style="color: #7f0055; font-family: Consolas; font-size: 12.0pt; mso-bidi-font-size: 10.0pt; mso-bidi-font-weight: bold;">public</span><span style="font-family: Consolas; font-size: 12pt;"> </span><span style="color: #7f0055; font-family: Consolas; font-size: 12.0pt; mso-bidi-font-size: 10.0pt; mso-bidi-font-weight: bold;">void</span><span style="font-family: Consolas; font-size: 12pt;"> setValue(</span><span style="color: #7f0055; font-family: Consolas; font-size: 12.0pt; mso-bidi-font-size: 10.0pt; mso-bidi-font-weight: bold;">int</span><span style="font-family: Consolas; font-size: 12pt;"> </span><span style="color: #6a3e3e; font-family: Consolas; font-size: 12.0pt; mso-bidi-font-size: 10.0pt;">newValue</span><span style="font-family: Consolas; font-size: 12pt;">) {</span><span style="font-family: Consolas; font-size: 12.0pt; mso-bidi-font-size: 10.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: Consolas; font-size: 12pt;"> </span><span style="color: #0000c0; font-family: Consolas; font-size: 12.0pt; mso-bidi-font-size: 10.0pt;">realValue</span><span style="font-family: Consolas; font-size: 12pt;"> = </span><span style="color: #6a3e3e; font-family: Consolas; font-size: 12.0pt; mso-bidi-font-size: 10.0pt;">newValue</span><span style="font-family: Consolas; font-size: 12pt;">;</span><span style="font-family: Consolas; font-size: 12.0pt; mso-bidi-font-size: 10.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: Consolas; font-size: 12pt;"> }</span><span style="font-family: Consolas; font-size: 12.0pt; mso-bidi-font-size: 10.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<br /></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: Consolas; font-size: 12pt;"> </span><span style="color: #7f0055; font-family: Consolas; font-size: 12.0pt; mso-bidi-font-size: 10.0pt; mso-bidi-font-weight: bold;">public</span><span style="font-family: Consolas; font-size: 12pt;"> </span><span style="color: #7f0055; font-family: Consolas; font-size: 12.0pt; mso-bidi-font-size: 10.0pt; mso-bidi-font-weight: bold;">static</span><span style="font-family: Consolas; font-size: 12pt;"> </span><span style="color: #7f0055; font-family: Consolas; font-size: 12.0pt; mso-bidi-font-size: 10.0pt; mso-bidi-font-weight: bold;">void</span><span style="font-family: Consolas; font-size: 12pt;"> main(String[] </span><span style="color: #6a3e3e; font-family: Consolas; font-size: 12.0pt; mso-bidi-font-size: 10.0pt;">arg</span><span style="font-family: Consolas; font-size: 12pt;">){</span><span style="font-family: Consolas; font-size: 12.0pt; mso-bidi-font-size: 10.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: Consolas; font-size: 12pt;"> Mutable </span><span style="color: #6a3e3e; font-family: Consolas; font-size: 12.0pt; mso-bidi-font-size: 10.0pt;">obj</span><span style="font-family: Consolas; font-size: 12pt;"> = </span><span style="color: #7f0055; font-family: Consolas; font-size: 12.0pt; mso-bidi-font-size: 10.0pt; mso-bidi-font-weight: bold;">new</span><span style="font-family: Consolas; font-size: 12pt;"> Mutable(4);<o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="color: #0000c0; font-family: Consolas; font-size: 12.0pt; mso-bidi-font-size: 10.0pt;"> /** <o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="color: #0000c0; font-family: Consolas; font-size: 12.0pt; mso-bidi-font-size: 10.0pt;"> * Object </span><span style="color: #6a3e3e; font-family: Consolas; font-size: 12.0pt; mso-bidi-font-size: 10.0pt;">obj</span><span style="color: #0000c0; font-family: Consolas; font-size: 12.0pt; mso-bidi-font-size: 10.0pt;"> is Mutable object which seem like Immutable<o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="color: #0000c0; font-family: Consolas; font-size: 12.0pt; mso-bidi-font-size: 10.0pt;"> * as it has been caste into the parent class.<o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="color: #0000c0; font-family: Consolas; font-size: 12.0pt; mso-bidi-font-size: 10.0pt;"> */<o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: Consolas; font-size: 12pt;"> <span style="background: red; mso-highlight: red;">Immutable </span></span><span style="background: red; color: #6a3e3e; font-family: Consolas; font-size: 12.0pt; mso-bidi-font-size: 10.0pt; mso-highlight: red;">immObj</span><span style="background: red; font-family: Consolas; font-size: 12pt;"> = (Immutable)</span><span style="background: red; color: #6a3e3e; font-family: Consolas; font-size: 12.0pt; mso-bidi-font-size: 10.0pt; mso-highlight: red;">obj</span><span style="background: red; font-family: Consolas; font-size: 12pt;">;</span><span style="font-family: Consolas; font-size: 12pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<br /></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: Consolas; font-size: 12pt;"> System.</span><i><span style="color: #0000c0; font-family: Consolas; font-size: 12.0pt; mso-bidi-font-size: 10.0pt; mso-bidi-font-weight: bold;">out</span></i><span style="font-family: Consolas; font-size: 12pt;">.println(</span><span style="color: #6a3e3e; font-family: Consolas; font-size: 12.0pt; mso-bidi-font-size: 10.0pt;">immObj</span><span style="font-family: Consolas; font-size: 12pt;">.getValue());<o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="color: #0000c0; font-family: Consolas; font-size: 12.0pt; mso-bidi-font-size: 10.0pt;"> /** <o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="color: #0000c0; font-family: Consolas; font-size: 12.0pt; mso-bidi-font-size: 10.0pt;"> * Changing the state on Mutable class which is <o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="color: #0000c0; font-family: Consolas; font-size: 12.0pt; mso-bidi-font-size: 10.0pt;"> * referenced by the immutable class.<o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="color: #0000c0; font-family: Consolas; font-size: 12.0pt; mso-bidi-font-size: 10.0pt;"> */<o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: Consolas; font-size: 12pt;"> </span><span style="color: #6a3e3e; font-family: Consolas; font-size: 12.0pt; mso-bidi-font-size: 10.0pt;">obj</span><span style="font-family: Consolas; font-size: 12pt;">.setValue(8);<o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<br /></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="color: #0000c0; font-family: Consolas; font-size: 12.0pt; mso-bidi-font-size: 10.0pt;"> /** <o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="color: #0000c0; font-family: Consolas; font-size: 12.0pt; mso-bidi-font-size: 10.0pt;"> * It will print the mutable class value field as </span><span style="color: #6a3e3e; font-family: Consolas; font-size: 12.0pt; mso-bidi-font-size: 10.0pt;">immObj <o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="color: #6a3e3e; font-family: Consolas; font-size: 12.0pt; mso-bidi-font-size: 10.0pt;"> </span><span style="color: #0000c0; font-family: Consolas; font-size: 12.0pt; mso-bidi-font-size: 10.0pt;">* contains the instance of the Mutable class.<o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="color: #0000c0; font-family: Consolas; font-size: 12.0pt; mso-bidi-font-size: 10.0pt;"> */<o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: Consolas; font-size: 12pt;"> System.</span><i><span style="color: #0000c0; font-family: Consolas; font-size: 12.0pt; mso-bidi-font-size: 10.0pt; mso-bidi-font-weight: bold;">out</span></i><span style="font-family: Consolas; font-size: 12pt;">.println(</span><span style="color: #6a3e3e; font-family: Consolas; font-size: 12.0pt; mso-bidi-font-size: 10.0pt;">immObj</span><span style="font-family: Consolas; font-size: 12pt;">.getValue());</span><span style="font-family: Consolas; font-size: 12.0pt; mso-bidi-font-size: 10.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: Consolas; font-size: 12pt;"> }</span><span style="font-family: Consolas; font-size: 12.0pt; mso-bidi-font-size: 10.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: Consolas; font-size: 12pt;">}</span><span style="font-family: "Book Antiqua","serif"; font-size: 16.0pt; mso-bidi-font-size: 13.0pt;"><o:p></o:p></span></div>
</div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in;">
<span style="font-family: "Book Antiqua", serif; font-size: 13pt;"><br /></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in;">
<span style="font-family: "Book Antiqua", serif; font-size: 13pt;">Notice, In the Mutable subclass, we've overridden the behavior of getValue to read a new, mutable field declared in my </span><span style="font-family: "Book Antiqua", serif; font-size: 17.3333px;">Mutable</span><span style="font-family: "Book Antiqua", serif; font-size: 17.3333px;"> </span><span style="font-family: "Book Antiqua", serif; font-size: 13pt;">subclass. As a result, our object, which initially looks immutable, really isn't immutable (contains the instance of the mutable class).</span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in;">
<span style="font-family: "Book Antiqua", serif; font-size: 13pt;"><br /></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in;">
<span style="font-family: "Book Antiqua","serif"; font-size: 13.0pt;">In above scenario, we have passed Mutable object wherever an Immutable object is expected, which can lead a big trouble while execution of code because we are assuming the object is truly immutable(Problem when this object will use the key of HashMap).<o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in;">
<span style="font-family: "Book Antiqua","serif"; font-size: 13.0pt;"><br /></span></div>
<br />
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in;">
<b><span style="color: #00b050; font-family: "Book Antiqua","serif"; font-size: 13.0pt;">Marking the base class final prevents this from happening.<o:p></o:p></span></b></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in;">
<b><span style="color: #00b050; font-family: "Book Antiqua","serif"; font-size: 13.0pt;"><br /></span></b></div>
</div>
javaexplor03http://www.blogger.com/profile/07455293496498711738noreply@blogger.com0tag:blogger.com,1999:blog-615973148715732292.post-6062703386271068182017-06-08T21:01:00.000-07:002017-06-08T21:01:02.240-07:00Subset Sum Problem | Dynamic Programming<div dir="ltr" style="text-align: left;" trbidi="on">
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in;">
<span style="font-family: "Book Antiqua", serif; font-size: 13pt;">Given an array of non-negative integers, and a value sum, determine if there is a subset of the given set with a sum equal to given </span>sum<span style="font-family: "Book Antiqua", serif; font-size: 13pt;"> and find out that subset.</span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in;">
<br /></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in;">
<b><span style="font-family: "Book Antiqua","serif"; font-size: 14.0pt; mso-bidi-font-size: 13.0pt;">Examples:<o:p></o:p></span></b></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in;">
<span style="font-family: "Book Antiqua","serif"; font-size: 13.0pt;">Input:<o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in;">
<span style="font-family: "Book Antiqua","serif"; font-size: 13.0pt;">array [] = {3, 12, 4, 12, 5, 2}<o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in;">
<span style="font-family: "Book Antiqua","serif"; font-size: 13.0pt;">sum = 7<o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in;">
<span style="font-family: "Book Antiqua","serif"; font-size: 13.0pt;">Output:<o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in;">
<span style="font-family: "Book Antiqua","serif"; font-size: 13.0pt;">true<o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in;">
<br /></div>
<br />
<div style="background: #C6D9F1; border: solid windowtext 1.0pt; mso-background-themecolor: text2; mso-background-themetint: 51; mso-border-alt: solid windowtext .5pt; mso-element: para-border-div; padding: 1.0pt 1.0pt 1.0pt 1.0pt;">
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="color: #7f0055; font-family: Consolas; font-size: 12.0pt; mso-bidi-font-weight: bold;">package</span><span style="font-family: Consolas; font-size: 12pt;"> com.dp;</span><span style="font-family: Consolas; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="color: #7f0055; font-family: Consolas; font-size: 12.0pt; mso-bidi-font-weight: bold;">public</span><span style="font-family: Consolas; font-size: 12pt;"> </span><span style="color: #7f0055; font-family: Consolas; font-size: 12.0pt; mso-bidi-font-weight: bold;">class</span><span style="font-family: Consolas; font-size: 12pt;"> SubsetSumProblem {</span><span style="font-family: Consolas; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<br /></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: Consolas; font-size: 12pt;"> </span><span style="color: #7f0055; font-family: Consolas; font-size: 12.0pt; mso-bidi-font-weight: bold;">private</span><span style="font-family: Consolas; font-size: 12pt;"> </span><span style="color: #7f0055; font-family: Consolas; font-size: 12.0pt; mso-bidi-font-weight: bold;">static</span><span style="font-family: Consolas; font-size: 12pt;"> </span><span style="color: #7f0055; font-family: Consolas; font-size: 12.0pt; mso-bidi-font-weight: bold;">boolean</span><span style="font-family: Consolas; font-size: 12pt;"> isSumSubsetExist(</span><span style="color: #7f0055; font-family: Consolas; font-size: 12.0pt; mso-bidi-font-weight: bold;">int</span><span style="font-family: Consolas; font-size: 12pt;">[] </span><span style="color: #6a3e3e; font-family: Consolas; font-size: 12.0pt;">array</span><span style="font-family: Consolas; font-size: 12pt;">, </span><span style="color: #7f0055; font-family: Consolas; font-size: 12.0pt; mso-bidi-font-weight: bold;">int</span><span style="font-family: Consolas; font-size: 12pt;"> </span><span style="color: #6a3e3e; font-family: Consolas; font-size: 12.0pt;">sum</span><span style="font-family: Consolas; font-size: 12pt;">) {</span><span style="font-family: Consolas; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: Consolas; font-size: 12pt;"> </span><span style="color: #7f0055; font-family: Consolas; font-size: 12.0pt; mso-bidi-font-weight: bold;">int</span><span style="font-family: Consolas; font-size: 12pt;"> </span><span style="color: #6a3e3e; font-family: Consolas; font-size: 12.0pt;">col</span><span style="font-family: Consolas; font-size: 12pt;"> = </span><span style="color: #6a3e3e; font-family: Consolas; font-size: 12.0pt;">sum</span><span style="font-family: Consolas; font-size: 12pt;">+1;</span><span style="font-family: Consolas; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: Consolas; font-size: 12pt;"> </span><span style="color: #7f0055; font-family: Consolas; font-size: 12.0pt; mso-bidi-font-weight: bold;">int</span><span style="font-family: Consolas; font-size: 12pt;"> </span><span style="color: #6a3e3e; font-family: Consolas; font-size: 12.0pt;">row</span><span style="font-family: Consolas; font-size: 12pt;"> = </span><span style="color: #6a3e3e; font-family: Consolas; font-size: 12.0pt;">array</span><span style="font-family: Consolas; font-size: 12pt;">.</span><span style="color: #0000c0; font-family: Consolas; font-size: 12.0pt;">length</span><span style="font-family: Consolas; font-size: 12pt;">+1;</span><span style="font-family: Consolas; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: Consolas; font-size: 12pt;"> </span><span style="color: #7f0055; font-family: Consolas; font-size: 12.0pt; mso-bidi-font-weight: bold;">boolean</span><span style="font-family: Consolas; font-size: 12pt;">[][] </span><span style="color: #6a3e3e; font-family: Consolas; font-size: 12.0pt;">dp</span><span style="font-family: Consolas; font-size: 12pt;"> = </span><span style="color: #7f0055; font-family: Consolas; font-size: 12.0pt; mso-bidi-font-weight: bold;">new</span><span style="font-family: Consolas; font-size: 12pt;"> </span><span style="color: #7f0055; font-family: Consolas; font-size: 12.0pt; mso-bidi-font-weight: bold;">boolean</span><span style="font-family: Consolas; font-size: 12pt;">[</span><span style="color: #6a3e3e; font-family: Consolas; font-size: 12.0pt;">row</span><span style="font-family: Consolas; font-size: 12pt;">][</span><span style="color: #6a3e3e; font-family: Consolas; font-size: 12.0pt;">col</span><span style="font-family: Consolas; font-size: 12pt;">];</span><span style="font-family: Consolas; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: Consolas; font-size: 12pt;"> </span><span style="font-family: Consolas; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: Consolas; font-size: 12pt;"> </span><span style="color: #7f0055; font-family: Consolas; font-size: 12.0pt; mso-bidi-font-weight: bold;">for</span><span style="font-family: Consolas; font-size: 12pt;">(</span><span style="color: #7f0055; font-family: Consolas; font-size: 12.0pt; mso-bidi-font-weight: bold;">int</span><span style="font-family: Consolas; font-size: 12pt;"> </span><span style="color: #6a3e3e; font-family: Consolas; font-size: 12.0pt;">i</span><span style="font-family: Consolas; font-size: 12pt;">=0;</span><span style="color: #6a3e3e; font-family: Consolas; font-size: 12.0pt;">i</span><span style="font-family: Consolas; font-size: 12pt;"><</span><span style="color: #6a3e3e; font-family: Consolas; font-size: 12.0pt;">row</span><span style="font-family: Consolas; font-size: 12pt;">;</span><span style="color: #6a3e3e; font-family: Consolas; font-size: 12.0pt;">i</span><span style="font-family: Consolas; font-size: 12pt;">++) {</span><span style="font-family: Consolas; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: Consolas; font-size: 12pt;"> </span><span style="color: #6a3e3e; font-family: Consolas; font-size: 12.0pt;">dp</span><span style="font-family: Consolas; font-size: 12pt;">[</span><span style="color: #6a3e3e; font-family: Consolas; font-size: 12.0pt;">i</span><span style="font-family: Consolas; font-size: 12pt;">][0] = </span><span style="color: #7f0055; font-family: Consolas; font-size: 12.0pt; mso-bidi-font-weight: bold;">true</span><span style="font-family: Consolas; font-size: 12pt;">;</span><span style="font-family: Consolas; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: Consolas; font-size: 12pt;"> }</span><span style="font-family: Consolas; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: Consolas; font-size: 12pt;"> </span><span style="font-family: Consolas; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: Consolas; font-size: 12pt;"> </span><span style="color: #7f0055; font-family: Consolas; font-size: 12.0pt; mso-bidi-font-weight: bold;">for</span><span style="font-family: Consolas; font-size: 12pt;">(</span><span style="color: #7f0055; font-family: Consolas; font-size: 12.0pt; mso-bidi-font-weight: bold;">int</span><span style="font-family: Consolas; font-size: 12pt;"> </span><span style="color: #6a3e3e; font-family: Consolas; font-size: 12.0pt;">i</span><span style="font-family: Consolas; font-size: 12pt;">=1;</span><span style="color: #6a3e3e; font-family: Consolas; font-size: 12.0pt;">i</span><span style="font-family: Consolas; font-size: 12pt;"><</span><span style="color: #6a3e3e; font-family: Consolas; font-size: 12.0pt;">col</span><span style="font-family: Consolas; font-size: 12pt;">;</span><span style="color: #6a3e3e; font-family: Consolas; font-size: 12.0pt;">i</span><span style="font-family: Consolas; font-size: 12pt;">++) {</span><span style="font-family: Consolas; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: Consolas; font-size: 12pt;"> </span><span style="color: #6a3e3e; font-family: Consolas; font-size: 12.0pt;">dp</span><span style="font-family: Consolas; font-size: 12pt;">[0][</span><span style="color: #6a3e3e; font-family: Consolas; font-size: 12.0pt;">i</span><span style="font-family: Consolas; font-size: 12pt;">] = </span><span style="color: #7f0055; font-family: Consolas; font-size: 12.0pt; mso-bidi-font-weight: bold;">false</span><span style="font-family: Consolas; font-size: 12pt;">;</span><span style="font-family: Consolas; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: Consolas; font-size: 12pt;"> }</span><span style="font-family: Consolas; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: Consolas; font-size: 12pt;"> </span><span style="font-family: Consolas; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: Consolas; font-size: 12pt;"> </span><span style="color: #7f0055; font-family: Consolas; font-size: 12.0pt; mso-bidi-font-weight: bold;">for</span><span style="font-family: Consolas; font-size: 12pt;"> (</span><span style="color: #7f0055; font-family: Consolas; font-size: 12.0pt; mso-bidi-font-weight: bold;">int</span><span style="font-family: Consolas; font-size: 12pt;"> </span><span style="color: #6a3e3e; font-family: Consolas; font-size: 12.0pt;">i</span><span style="font-family: Consolas; font-size: 12pt;"> = 1; </span><span style="color: #6a3e3e; font-family: Consolas; font-size: 12.0pt;">i</span><span style="font-family: Consolas; font-size: 12pt;"> < </span><span style="color: #6a3e3e; font-family: Consolas; font-size: 12.0pt;">row</span><span style="font-family: Consolas; font-size: 12pt;">; </span><span style="color: #6a3e3e; font-family: Consolas; font-size: 12.0pt;">i</span><span style="font-family: Consolas; font-size: 12pt;">++) {</span><span style="font-family: Consolas; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: Consolas; font-size: 12pt;"> </span><span style="color: #7f0055; font-family: Consolas; font-size: 12.0pt; mso-bidi-font-weight: bold;">int</span><span style="font-family: Consolas; font-size: 12pt;"> </span><span style="color: #6a3e3e; font-family: Consolas; font-size: 12.0pt;">value</span><span style="font-family: Consolas; font-size: 12pt;"> = </span><span style="color: #6a3e3e; font-family: Consolas; font-size: 12.0pt;">array</span><span style="font-family: Consolas; font-size: 12pt;">[</span><span style="color: #6a3e3e; font-family: Consolas; font-size: 12.0pt;">i</span><span style="font-family: Consolas; font-size: 12pt;">-1];</span><span style="font-family: Consolas; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: Consolas; font-size: 12pt;"> </span><span style="color: #3f7f5f; font-family: Consolas; font-size: 12.0pt;">/* Create DP. */</span><span style="font-family: Consolas; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: Consolas; font-size: 12pt;"> </span><span style="color: #7f0055; font-family: Consolas; font-size: 12.0pt; mso-bidi-font-weight: bold;">for</span><span style="font-family: Consolas; font-size: 12pt;"> (</span><span style="color: #7f0055; font-family: Consolas; font-size: 12.0pt; mso-bidi-font-weight: bold;">int</span><span style="font-family: Consolas; font-size: 12pt;"> </span><span style="color: #6a3e3e; font-family: Consolas; font-size: 12.0pt;">j</span><span style="font-family: Consolas; font-size: 12pt;"> = 1; </span><span style="color: #6a3e3e; font-family: Consolas; font-size: 12.0pt;">j</span><span style="font-family: Consolas; font-size: 12pt;"> < </span><span style="color: #6a3e3e; font-family: Consolas; font-size: 12.0pt;">col</span><span style="font-family: Consolas; font-size: 12pt;">; </span><span style="color: #6a3e3e; font-family: Consolas; font-size: 12.0pt;">j</span><span style="font-family: Consolas; font-size: 12pt;">++) {</span><span style="font-family: Consolas; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: Consolas; font-size: 12pt;"> </span><span style="color: #7f0055; font-family: Consolas; font-size: 12.0pt; mso-bidi-font-weight: bold;">if</span><span style="font-family: Consolas; font-size: 12pt;">(</span><span style="color: #6a3e3e; font-family: Consolas; font-size: 12.0pt;">j</span><span style="font-family: Consolas; font-size: 12pt;"><</span><span style="color: #6a3e3e; font-family: Consolas; font-size: 12.0pt;">value</span><span style="font-family: Consolas; font-size: 12pt;">) {</span><span style="font-family: Consolas; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: Consolas; font-size: 12pt;"> </span><span style="color: #6a3e3e; font-family: Consolas; font-size: 12.0pt;">dp</span><span style="font-family: Consolas; font-size: 12pt;">[</span><span style="color: #6a3e3e; font-family: Consolas; font-size: 12.0pt;">i</span><span style="font-family: Consolas; font-size: 12pt;">][</span><span style="color: #6a3e3e; font-family: Consolas; font-size: 12.0pt;">j</span><span style="font-family: Consolas; font-size: 12pt;">] = </span><span style="color: #6a3e3e; font-family: Consolas; font-size: 12.0pt;">dp</span><span style="font-family: Consolas; font-size: 12pt;">[</span><span style="color: #6a3e3e; font-family: Consolas; font-size: 12.0pt;">i</span><span style="font-family: Consolas; font-size: 12pt;">-1][</span><span style="color: #6a3e3e; font-family: Consolas; font-size: 12.0pt;">j</span><span style="font-family: Consolas; font-size: 12pt;">];</span><span style="font-family: Consolas; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: Consolas; font-size: 12pt;"> } </span><span style="color: #7f0055; font-family: Consolas; font-size: 12.0pt; mso-bidi-font-weight: bold;">else</span><span style="font-family: Consolas; font-size: 12pt;"> {</span><span style="font-family: Consolas; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: Consolas; font-size: 12pt;"> </span><span style="color: #6a3e3e; font-family: Consolas; font-size: 12.0pt;">dp</span><span style="font-family: Consolas; font-size: 12pt;">[</span><span style="color: #6a3e3e; font-family: Consolas; font-size: 12.0pt;">i</span><span style="font-family: Consolas; font-size: 12pt;">][</span><span style="color: #6a3e3e; font-family: Consolas; font-size: 12.0pt;">j</span><span style="font-family: Consolas; font-size: 12pt;">] = </span><span style="color: #6a3e3e; font-family: Consolas; font-size: 12.0pt;">dp</span><span style="font-family: Consolas; font-size: 12pt;">[</span><span style="color: #6a3e3e; font-family: Consolas; font-size: 12.0pt;">i</span><span style="font-family: Consolas; font-size: 12pt;">-1][</span><span style="color: #6a3e3e; font-family: Consolas; font-size: 12.0pt;">j</span><span style="font-family: Consolas; font-size: 12pt;">-</span><span style="color: #6a3e3e; font-family: Consolas; font-size: 12.0pt;">value</span><span style="font-family: Consolas; font-size: 12pt;">];</span><span style="font-family: Consolas; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: Consolas; font-size: 12pt;"> }</span><span style="font-family: Consolas; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: Consolas; font-size: 12pt;"> }</span><span style="font-family: Consolas; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: Consolas; font-size: 12pt;"> }</span><span style="font-family: Consolas; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: Consolas; font-size: 12pt;"> </span><span style="font-family: Consolas; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: Consolas; font-size: 12pt;"> </span><span style="color: #3f5fbf; font-family: Consolas; font-size: 12.0pt;">/** Print the elements set. */</span><span style="font-family: Consolas; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: Consolas; font-size: 12pt;"> <i>printElements</i>(</span><span style="color: #6a3e3e; font-family: Consolas; font-size: 12.0pt;">dp</span><span style="font-family: Consolas; font-size: 12pt;">, </span><span style="color: #6a3e3e; font-family: Consolas; font-size: 12.0pt;">array</span><span style="font-family: Consolas; font-size: 12pt;">, </span><span style="color: #6a3e3e; font-family: Consolas; font-size: 12.0pt;">row</span><span style="font-family: Consolas; font-size: 12pt;">, </span><span style="color: #6a3e3e; font-family: Consolas; font-size: 12.0pt;">col</span><span style="font-family: Consolas; font-size: 12pt;">);</span><span style="font-family: Consolas; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: Consolas; font-size: 12pt;"> </span><span style="font-family: Consolas; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: Consolas; font-size: 12pt;"> </span><span style="color: #7f0055; font-family: Consolas; font-size: 12.0pt; mso-bidi-font-weight: bold;">return</span><span style="font-family: Consolas; font-size: 12pt;"> </span><span style="color: #6a3e3e; font-family: Consolas; font-size: 12.0pt;">dp</span><span style="font-family: Consolas; font-size: 12pt;">[</span><span style="color: #6a3e3e; font-family: Consolas; font-size: 12.0pt;">row</span><span style="font-family: Consolas; font-size: 12pt;">-1][</span><span style="color: #6a3e3e; font-family: Consolas; font-size: 12.0pt;">col</span><span style="font-family: Consolas; font-size: 12pt;">-1];</span><span style="font-family: Consolas; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: Consolas; font-size: 12pt;"> }</span><span style="font-family: Consolas; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: Consolas; font-size: 12pt;"> </span><span style="font-family: Consolas; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: Consolas; font-size: 12pt;"> </span><span style="color: #7f0055; font-family: Consolas; font-size: 12.0pt; mso-bidi-font-weight: bold;">private</span><span style="font-family: Consolas; font-size: 12pt;"> </span><span style="color: #7f0055; font-family: Consolas; font-size: 12.0pt; mso-bidi-font-weight: bold;">static</span><span style="font-family: Consolas; font-size: 12pt;"> </span><span style="color: #7f0055; font-family: Consolas; font-size: 12.0pt; mso-bidi-font-weight: bold;">void</span><span style="font-family: Consolas; font-size: 12pt;"> printElements(</span><span style="color: #7f0055; font-family: Consolas; font-size: 12.0pt; mso-bidi-font-weight: bold;">boolean</span><span style="font-family: Consolas; font-size: 12pt;">[][] </span><span style="color: #6a3e3e; font-family: Consolas; font-size: 12.0pt;">dp</span><span style="font-family: Consolas; font-size: 12pt;">, </span><span style="color: #7f0055; font-family: Consolas; font-size: 12.0pt; mso-bidi-font-weight: bold;">int</span><span style="font-family: Consolas; font-size: 12pt;">[] </span><span style="color: #6a3e3e; font-family: Consolas; font-size: 12.0pt;">array</span><span style="font-family: Consolas; font-size: 12pt;">, </span><span style="color: #7f0055; font-family: Consolas; font-size: 12.0pt; mso-bidi-font-weight: bold;">int</span><span style="font-family: Consolas; font-size: 12pt;"> </span><span style="color: #6a3e3e; font-family: Consolas; font-size: 12.0pt;">row</span><span style="font-family: Consolas; font-size: 12pt;">, </span><span style="color: #7f0055; font-family: Consolas; font-size: 12.0pt; mso-bidi-font-weight: bold;">int</span><span style="font-family: Consolas; font-size: 12pt;"> </span><span style="color: #6a3e3e; font-family: Consolas; font-size: 12.0pt;">col</span><span style="font-family: Consolas; font-size: 12pt;">) {</span><span style="font-family: Consolas; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: Consolas; font-size: 12pt;"> </span><span style="color: #7f0055; font-family: Consolas; font-size: 12.0pt; mso-bidi-font-weight: bold;">int</span><span style="font-family: Consolas; font-size: 12pt;"> </span><span style="color: #6a3e3e; font-family: Consolas; font-size: 12.0pt;">i</span><span style="font-family: Consolas; font-size: 12pt;"> = </span><span style="color: #6a3e3e; font-family: Consolas; font-size: 12.0pt;">row</span><span style="font-family: Consolas; font-size: 12pt;">-1; </span><span style="color: #7f0055; font-family: Consolas; font-size: 12.0pt; mso-bidi-font-weight: bold;">int</span><span style="font-family: Consolas; font-size: 12pt;"> </span><span style="color: #6a3e3e; font-family: Consolas; font-size: 12.0pt;">j</span><span style="font-family: Consolas; font-size: 12pt;"> = </span><span style="color: #6a3e3e; font-family: Consolas; font-size: 12.0pt;">col</span><span style="font-family: Consolas; font-size: 12pt;">-1;</span><span style="font-family: Consolas; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: Consolas; font-size: 12pt;"> </span><span style="font-family: Consolas; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: Consolas; font-size: 12pt;"> </span><span style="color: #7f0055; font-family: Consolas; font-size: 12.0pt; mso-bidi-font-weight: bold;">while</span><span style="font-family: Consolas; font-size: 12pt;">(</span><span style="color: #6a3e3e; font-family: Consolas; font-size: 12.0pt;">i</span><span style="font-family: Consolas; font-size: 12pt;">>0 && </span><span style="color: #6a3e3e; font-family: Consolas; font-size: 12.0pt;">j</span><span style="font-family: Consolas; font-size: 12pt;">>=0) {</span><span style="font-family: Consolas; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: Consolas; font-size: 12pt;"> </span><span style="color: #7f0055; font-family: Consolas; font-size: 12.0pt; mso-bidi-font-weight: bold;">int</span><span style="font-family: Consolas; font-size: 12pt;"> </span><span style="color: #6a3e3e; font-family: Consolas; font-size: 12.0pt;">value</span><span style="font-family: Consolas; font-size: 12pt;"> = </span><span style="color: #6a3e3e; font-family: Consolas; font-size: 12.0pt;">array</span><span style="font-family: Consolas; font-size: 12pt;">[</span><span style="color: #6a3e3e; font-family: Consolas; font-size: 12.0pt;">i</span><span style="font-family: Consolas; font-size: 12pt;">-1];</span><span style="font-family: Consolas; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: Consolas; font-size: 12pt;"> </span><span style="color: #7f0055; font-family: Consolas; font-size: 12.0pt; mso-bidi-font-weight: bold;">if</span><span style="font-family: Consolas; font-size: 12pt;">(</span><span style="color: #6a3e3e; font-family: Consolas; font-size: 12.0pt;">j</span><span style="font-family: Consolas; font-size: 12pt;">-</span><span style="color: #6a3e3e; font-family: Consolas; font-size: 12.0pt;">value</span><span style="font-family: Consolas; font-size: 12pt;">>=0 && </span><span style="color: #6a3e3e; font-family: Consolas; font-size: 12.0pt;">dp</span><span style="font-family: Consolas; font-size: 12pt;">[</span><span style="color: #6a3e3e; font-family: Consolas; font-size: 12.0pt;">i</span><span style="font-family: Consolas; font-size: 12pt;">-1][</span><span style="color: #6a3e3e; font-family: Consolas; font-size: 12.0pt;">j</span><span style="font-family: Consolas; font-size: 12pt;">-</span><span style="color: #6a3e3e; font-family: Consolas; font-size: 12.0pt;">value</span><span style="font-family: Consolas; font-size: 12pt;">]) {</span><span style="font-family: Consolas; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: Consolas; font-size: 12pt;"> </span><span style="color: #6a3e3e; font-family: Consolas; font-size: 12.0pt;">i</span><span style="font-family: Consolas; font-size: 12pt;"> = </span><span style="color: #6a3e3e; font-family: Consolas; font-size: 12.0pt;">i</span><span style="font-family: Consolas; font-size: 12pt;"> -1;</span><span style="font-family: Consolas; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: Consolas; font-size: 12pt;"> </span><span style="color: #6a3e3e; font-family: Consolas; font-size: 12.0pt;">j</span><span style="font-family: Consolas; font-size: 12pt;"> = </span><span style="color: #6a3e3e; font-family: Consolas; font-size: 12.0pt;">j</span><span style="font-family: Consolas; font-size: 12pt;">-</span><span style="color: #6a3e3e; font-family: Consolas; font-size: 12.0pt;">value</span><span style="font-family: Consolas; font-size: 12pt;">;</span><span style="font-family: Consolas; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: Consolas; font-size: 12pt;"> System.</span><i><span style="color: #0000c0; font-family: Consolas; font-size: 12.0pt; mso-bidi-font-weight: bold;">out</span></i><span style="font-family: Consolas; font-size: 12pt;">.println(</span><span style="color: #6a3e3e; font-family: Consolas; font-size: 12.0pt;">value</span><span style="font-family: Consolas; font-size: 12pt;">);</span><span style="font-family: Consolas; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: Consolas; font-size: 12pt;"> } </span><span style="color: #7f0055; font-family: Consolas; font-size: 12.0pt; mso-bidi-font-weight: bold;">else</span><span style="font-family: Consolas; font-size: 12pt;"> {</span><span style="font-family: Consolas; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: Consolas; font-size: 12pt;"> </span><span style="color: #6a3e3e; font-family: Consolas; font-size: 12.0pt;">i</span><span style="font-family: Consolas; font-size: 12pt;">--;</span><span style="font-family: Consolas; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: Consolas; font-size: 12pt;"> } </span><span style="font-family: Consolas; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: Consolas; font-size: 12pt;"> }</span><span style="font-family: Consolas; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: Consolas; font-size: 12pt;"> }</span><span style="font-family: Consolas; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<br /></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: Consolas; font-size: 12pt;"> </span><span style="color: #3f5fbf; font-family: Consolas; font-size: 12.0pt;">/**</span><span style="font-family: Consolas; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="color: #3f5fbf; font-family: Consolas; font-size: 12.0pt;"> * Driver Method</span><span style="font-family: Consolas; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="color: #3f5fbf; font-family: Consolas; font-size: 12.0pt;"> * </span><span style="color: #7f9fbf; font-family: Consolas; font-size: 12.0pt; mso-bidi-font-weight: bold;">@param</span><span style="color: #3f5fbf; font-family: Consolas; font-size: 12.0pt;"> args</span><span style="font-family: Consolas; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="color: #3f5fbf; font-family: Consolas; font-size: 12.0pt;"> */</span><span style="font-family: Consolas; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: Consolas; font-size: 12pt;"> </span><span style="color: #7f0055; font-family: Consolas; font-size: 12.0pt; mso-bidi-font-weight: bold;">public</span><span style="font-family: Consolas; font-size: 12pt;"> </span><span style="color: #7f0055; font-family: Consolas; font-size: 12.0pt; mso-bidi-font-weight: bold;">static</span><span style="font-family: Consolas; font-size: 12pt;"> </span><span style="color: #7f0055; font-family: Consolas; font-size: 12.0pt; mso-bidi-font-weight: bold;">void</span><span style="font-family: Consolas; font-size: 12pt;"> main(String[] </span><span style="color: #6a3e3e; font-family: Consolas; font-size: 12.0pt;">args</span><span style="font-family: Consolas; font-size: 12pt;">) {</span><span style="font-family: Consolas; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: Consolas; font-size: 12pt;"> </span><span style="color: #7f0055; font-family: Consolas; font-size: 12.0pt; mso-bidi-font-weight: bold;">int</span><span style="font-family: Consolas; font-size: 12pt;">[] </span><span style="color: #6a3e3e; font-family: Consolas; font-size: 12.0pt;">array</span><span style="font-family: Consolas; font-size: 12pt;"> = {3, 12, 4, 12, 5, 2};</span><span style="font-family: Consolas; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: Consolas; font-size: 12pt;"> </span><span style="color: #7f0055; font-family: Consolas; font-size: 12.0pt; mso-bidi-font-weight: bold;">int</span><span style="font-family: Consolas; font-size: 12pt;"> </span><span style="color: #6a3e3e; font-family: Consolas; font-size: 12.0pt;">sum</span><span style="font-family: Consolas; font-size: 12pt;"> = 7;</span><span style="font-family: Consolas; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: Consolas; font-size: 12pt;"> </span><span style="color: #7f0055; font-family: Consolas; font-size: 12.0pt; mso-bidi-font-weight: bold;">boolean</span><span style="font-family: Consolas; font-size: 12pt;"> </span><span style="color: #6a3e3e; font-family: Consolas; font-size: 12.0pt;">isExist</span><span style="font-family: Consolas; font-size: 12pt;"> = <i>isSumSubsetExist</i>(</span><span style="color: #6a3e3e; font-family: Consolas; font-size: 12.0pt;">array</span><span style="font-family: Consolas; font-size: 12pt;">,</span><span style="color: #6a3e3e; font-family: Consolas; font-size: 12.0pt;">sum</span><span style="font-family: Consolas; font-size: 12pt;">);</span><span style="font-family: Consolas; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: Consolas; font-size: 12pt;"> System.</span><i><span style="color: #0000c0; font-family: Consolas; font-size: 12.0pt; mso-bidi-font-weight: bold;">out</span></i><span style="font-family: Consolas; font-size: 12pt;">.println(</span><span style="color: #6a3e3e; font-family: Consolas; font-size: 12.0pt;">isExist</span><span style="font-family: Consolas; font-size: 12pt;">);</span><span style="font-family: Consolas; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: Consolas; font-size: 12pt;"> }</span><span style="font-family: Consolas; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: Consolas; font-size: 12pt;">}</span><span style="font-family: "Book Antiqua","serif"; font-size: 12.0pt;"><o:p></o:p></span></div>
</div>
</div>
javaexplor03http://www.blogger.com/profile/07455293496498711738noreply@blogger.com0tag:blogger.com,1999:blog-615973148715732292.post-4926900051601609472017-05-26T08:41:00.000-07:002017-05-26T03:42:59.451-07:00Mediator pattern<div dir="ltr" style="text-align: left;" trbidi="on">
<div class="MsoNormal" style="margin-bottom: 0.0001pt; text-align: justify;">
<span style="font-family: "book antiqua" , serif; font-size: 13pt;">Mediator
pattern defines an object that encapsulates how a set of objects interact.</span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt; text-align: justify;">
<br /></div>
<div style="background: #DBE5F1; border: solid windowtext 1.0pt; mso-background-themecolor: accent1; mso-background-themetint: 51; mso-border-alt: solid windowtext .5pt; mso-element: para-border-div; padding: 1.0pt 4.0pt 1.0pt 4.0pt;">
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; margin-bottom: 0.0001pt; padding: 0in; text-align: justify;">
<b><span style="font-family: "book antiqua" , "serif"; font-size: 16.0pt;">Participants<o:p></o:p></span></b></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; margin-bottom: 0.0001pt; padding: 0in; text-align: justify;">
<b><span style="font-family: "book antiqua" , "serif"; font-size: 13.0pt;">Mediator</span></b><span style="font-family: "book antiqua" , serif; font-size: 13pt;"> - defines the
interface for communication between Colleague objects.</span><br />
<span style="font-family: "book antiqua" , serif; font-size: 13pt;"><br /></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; margin-bottom: 0.0001pt; padding: 0in; text-align: justify;">
<b><span style="font-family: "book antiqua" , "serif"; font-size: 13.0pt;">ConcreteMediator</span></b><span style="font-family: "book antiqua" , "serif"; font-size: 13.0pt;"> - implements the
Mediator interface.<o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; margin-bottom: 0.0001pt; padding: 0in; text-align: justify;">
<span style="font-family: "book antiqua" , "serif"; font-size: 13.0pt;">Implements the communication and
transfer the messages between the colleague objects.</span><br />
<span style="font-family: "book antiqua" , "serif"; font-size: 13.0pt;"><br /></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; margin-bottom: 0.0001pt; padding: 0in; text-align: justify;">
<b><span style="font-family: "book antiqua" , "serif"; font-size: 13.0pt;">ConcreteColleague</span></b><span style="font-family: "book antiqua" , "serif"; font-size: 13.0pt;"> - communicates
with other Colleagues through its.</span></div>
</div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt; text-align: justify;">
<br /></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt; text-align: justify;">
<b><span style="font-family: "book antiqua" , "serif"; font-size: 16.0pt;">Before
Mediator Design Pattern<o:p></o:p></span></b></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt; text-align: justify;">
<b><span style="font-family: "book antiqua" , "serif"; font-size: 16.0pt;"><br /></span></b></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgan8Xcjn2bMc_WTD7w_8SWId9ZAc_D91rlQiFmBcj78Dsm06Qfx4oS1nfUa11qyX3vhhPUGq8lPshxg3DxI4LHccxWTscMPp9VVF0a4HIuTAsQWDbJE1QUA7-KjHKdk6TSJwVnx9S0vuMn/s1600/md1.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="178" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgan8Xcjn2bMc_WTD7w_8SWId9ZAc_D91rlQiFmBcj78Dsm06Qfx4oS1nfUa11qyX3vhhPUGq8lPshxg3DxI4LHccxWTscMPp9VVF0a4HIuTAsQWDbJE1QUA7-KjHKdk6TSJwVnx9S0vuMn/s200/md1.png" width="200" /></a></div>
<b style="text-align: justify;"><span style="font-family: "book antiqua" , "serif"; font-size: 16.0pt;">After
Mediator Design Pattern</span></b><br />
<b style="text-align: justify;"><span style="font-family: "book antiqua" , "serif"; font-size: 16.0pt;"><br /></span></b>
<br />
<div class="MsoNormal" style="margin-bottom: 0.0001pt; text-align: left;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhZsBcauwQ68rvKd4625vwu8ArSUQPWQ_omQLtasu8zLELxU3y4IWK6vRa0Upvn6N18MmulsQgoMLfJ89yMYmXXNqih4RzlL8ozHkEikfhh-tll0LPA4RawCCtM5fikuAZEKxZJQs9i34Gq/s1600/md2.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em; text-align: center;"><img border="0" height="200" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhZsBcauwQ68rvKd4625vwu8ArSUQPWQ_omQLtasu8zLELxU3y4IWK6vRa0Upvn6N18MmulsQgoMLfJ89yMYmXXNqih4RzlL8ozHkEikfhh-tll0LPA4RawCCtM5fikuAZEKxZJQs9i34Gq/s200/md2.png" width="192" /></a></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt; text-align: justify;">
<br /></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt; text-align: justify;">
<b><span style="font-family: "book antiqua" , "serif"; font-size: 16.0pt;">Chat
application<o:p></o:p></span></b></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt; text-align: justify;">
<br /></div>
<div style="background: #DBE5F1; border: solid windowtext 1.0pt; mso-background-themecolor: accent1; mso-background-themetint: 51; mso-border-alt: solid windowtext .5pt; mso-element: para-border-div; padding: 1.0pt 1.0pt 1.0pt 1.0pt;">
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; margin-bottom: 0.0001pt; padding: 0in;">
<span style="color: #7f0055; font-family: "consolas";">package</span><span style="font-family: "consolas";"> designpattern.mediator;</span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; margin-bottom: 0.0001pt; padding: 0in;">
<br /></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; margin-bottom: 0.0001pt; padding: 0in;">
<span style="color: #7f0055; font-family: "consolas"; mso-bidi-font-weight: bold;">public</span><span style="font-family: "consolas";"> </span><span style="color: #7f0055; font-family: "consolas"; mso-bidi-font-weight: bold;">interface</span><span style="font-family: "consolas";"> IChatMediator {</span><span style="font-family: "consolas";"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: "consolas";">
</span><span style="color: #7f0055; font-family: "consolas"; mso-bidi-font-weight: bold;">public</span><span style="font-family: "consolas";"> </span><span style="color: #7f0055; font-family: "consolas"; mso-bidi-font-weight: bold;">void</span><span style="font-family: "consolas";"> sendMessage(IUser </span><span style="color: #6a3e3e; font-family: "consolas";">from</span><span style="font-family: "consolas";">, IUser </span><span style="color: #6a3e3e; font-family: "consolas";">to</span><span style="font-family: "consolas";">, String
</span><span style="color: #6a3e3e; font-family: "consolas";">msg</span><span style="font-family: "consolas";">);</span><span style="font-family: "consolas";"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; margin-bottom: 0.0001pt; padding: 0in;">
<br /></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: "consolas";">
</span><span style="color: #7f0055; font-family: "consolas"; mso-bidi-font-weight: bold;">void</span><span style="font-family: "consolas";"> addUser(IUser </span><span style="color: #6a3e3e; font-family: "consolas";">user</span><span style="font-family: "consolas";">);</span><span style="font-family: "consolas";"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; margin-bottom: 0.0001pt; padding: 0in; text-align: justify;">
<span style="font-family: "consolas";">}<o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; margin-bottom: 0.0001pt; padding: 0in; text-align: justify;">
<br /></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; margin-bottom: 0.0001pt; padding: 0in;">
<span style="color: #7f0055; font-family: "consolas"; mso-bidi-font-weight: bold;">import</span><span style="font-family: "consolas";"> java.util.ArrayList;</span><span style="font-family: "consolas";"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; margin-bottom: 0.0001pt; padding: 0in;">
<span style="color: #7f0055; font-family: "consolas"; mso-bidi-font-weight: bold;">import</span><span style="font-family: "consolas";"> java.util.List;</span><span style="font-family: "consolas";"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; margin-bottom: 0.0001pt; padding: 0in;">
<span style="color: #7f0055; font-family: "consolas"; mso-bidi-font-weight: bold;">public</span><span style="font-family: "consolas";"> </span><span style="color: #7f0055; font-family: "consolas"; mso-bidi-font-weight: bold;">class</span><span style="font-family: "consolas";"> ChatMediator </span><span style="color: #7f0055; font-family: "consolas"; mso-bidi-font-weight: bold;">implements</span><span style="font-family: "consolas";"> IChatMediator {</span><span style="font-family: "consolas";"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: "consolas";"> </span><span style="color: #7f0055; font-family: "consolas"; mso-bidi-font-weight: bold;">private</span><span style="font-family: "consolas";"> List<IUser> </span><span style="color: #0000c0; font-family: "consolas";">users</span><span style="font-family: "consolas";">;</span><span style="font-family: "consolas";"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; margin-bottom: 0.0001pt; padding: 0in;">
<br /></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: "consolas";"> </span><span style="color: #7f0055; font-family: "consolas"; mso-bidi-font-weight: bold;">public</span><span style="font-family: "consolas";"> ChatMediator() {</span><span style="font-family: "consolas";"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: "consolas";"> </span><span style="color: #7f0055; font-family: "consolas"; mso-bidi-font-weight: bold;">this</span><span style="font-family: "consolas";">.</span><span style="color: #0000c0; font-family: "consolas";">users</span><span style="font-family: "consolas";">=</span><span style="color: #7f0055; font-family: "consolas"; mso-bidi-font-weight: bold;">new</span><span style="font-family: "consolas";"> ArrayList<>();</span><span style="font-family: "consolas";"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: "consolas";"> }</span><span style="font-family: "consolas";"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; margin-bottom: 0.0001pt; padding: 0in;">
<br /></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: "consolas";"> </span><span style="color: #646464; font-family: "consolas";">@Override</span><span style="font-family: "consolas";"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: "consolas";"> </span><span style="color: #7f0055; font-family: "consolas"; mso-bidi-font-weight: bold;">public</span><span style="font-family: "consolas";"> </span><span style="color: #7f0055; font-family: "consolas"; mso-bidi-font-weight: bold;">void</span><span style="font-family: "consolas";"> <span style="background: silver; mso-highlight: silver;">addUser</span>(IUser
</span><span style="color: #6a3e3e; font-family: "consolas";">user</span><span style="font-family: "consolas";">) {</span><span style="font-family: "consolas";"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: "consolas";"> </span><span style="color: #7f0055; font-family: "consolas"; mso-bidi-font-weight: bold;">this</span><span style="font-family: "consolas";">.</span><span style="color: #0000c0; font-family: "consolas";">users</span><span style="font-family: "consolas";">.add(</span><span style="color: #6a3e3e; font-family: "consolas";">user</span><span style="font-family: "consolas";">);</span><span style="font-family: "consolas";"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: "consolas";"> }</span><span style="font-family: "consolas";"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; margin-bottom: 0.0001pt; padding: 0in;">
<br /></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: "consolas";"> </span><span style="color: #646464; font-family: "consolas";">@Override</span><span style="font-family: "consolas";"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: "consolas";"> </span><span style="color: #7f0055; font-family: "consolas"; mso-bidi-font-weight: bold;">public</span><span style="font-family: "consolas";"> </span><span style="color: #7f0055; font-family: "consolas"; mso-bidi-font-weight: bold;">void</span><span style="font-family: "consolas";"> sendMessage(IUser </span><span style="color: #6a3e3e; font-family: "consolas";">from</span><span style="font-family: "consolas";">,
IUser </span><span style="color: #6a3e3e; font-family: "consolas";">to</span><span style="font-family: "consolas";">, String </span><span style="color: #6a3e3e; font-family: "consolas";">msg</span><span style="font-family: "consolas";">) {</span><span style="font-family: "consolas";"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: "consolas";"> </span><span style="color: #6a3e3e; font-family: "consolas";">to</span><span style="font-family: "consolas";">.receive(</span><span style="color: #6a3e3e; font-family: "consolas";">from</span><span style="font-family: "consolas";">,</span><span style="color: #6a3e3e; font-family: "consolas";">msg</span><span style="font-family: "consolas";">);</span><span style="font-family: "consolas";"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: "consolas";"> }</span><span style="font-family: "consolas";"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; margin-bottom: 0.0001pt; padding: 0in; text-align: justify;">
<span style="font-family: "consolas";">}<o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; margin-bottom: 0.0001pt; padding: 0in; text-align: justify;">
<br /></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; margin-bottom: 0.0001pt; padding: 0in;">
<span style="color: #7f0055; font-family: "consolas"; mso-bidi-font-weight: bold;">public</span><span style="font-family: "consolas";"> </span><span style="color: #7f0055; font-family: "consolas"; mso-bidi-font-weight: bold;">abstract</span><span style="font-family: "consolas";"> </span><span style="color: #7f0055; font-family: "consolas"; mso-bidi-font-weight: bold;">class</span><span style="font-family: "consolas";"> IUser {</span><span style="font-family: "consolas";"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: "consolas";"> </span><span style="color: #7f0055; font-family: "consolas"; mso-bidi-font-weight: bold;">protected</span><span style="font-family: "consolas";"> <span style="background: silver; mso-highlight: silver;">IChatMediator</span> </span><span style="color: #0000c0; font-family: "consolas";">mediator</span><span style="font-family: "consolas";">;</span><span style="font-family: "consolas";"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: "consolas";"> </span><span style="color: #7f0055; font-family: "consolas"; mso-bidi-font-weight: bold;">protected</span><span style="font-family: "consolas";"> String </span><span style="color: #0000c0; font-family: "consolas";">name</span><span style="font-family: "consolas";">;</span><span style="font-family: "consolas";"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; margin-bottom: 0.0001pt; padding: 0in;">
<br /></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: "consolas";"> </span><span style="color: #7f0055; font-family: "consolas"; mso-bidi-font-weight: bold;">public</span><span style="font-family: "consolas";"> IUser(<span style="background: silver; mso-highlight: silver;">IChatMediator</span> </span><span style="color: #6a3e3e; font-family: "consolas";">med</span><span style="font-family: "consolas";">,
String </span><span style="color: #6a3e3e; font-family: "consolas";">name</span><span style="font-family: "consolas";">){</span><span style="font-family: "consolas";"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: "consolas";"> </span><span style="color: #7f0055; font-family: "consolas"; mso-bidi-font-weight: bold;">this</span><span style="font-family: "consolas";">.</span><span style="color: #0000c0; font-family: "consolas";">mediator</span><span style="font-family: "consolas";">=</span><span style="color: #6a3e3e; font-family: "consolas";">med</span><span style="font-family: "consolas";">;</span><span style="font-family: "consolas";"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: "consolas";"> </span><span style="color: #7f0055; font-family: "consolas"; mso-bidi-font-weight: bold;">this</span><span style="font-family: "consolas";">.</span><span style="color: #0000c0; font-family: "consolas";">name</span><span style="font-family: "consolas";">=</span><span style="color: #6a3e3e; font-family: "consolas";">name</span><span style="font-family: "consolas";">;</span><span style="font-family: "consolas";"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: "consolas";"> }</span><span style="font-family: "consolas";"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; margin-bottom: 0.0001pt; padding: 0in;">
<br /></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: "consolas";"> </span><span style="color: #7f0055; font-family: "consolas"; mso-bidi-font-weight: bold;">public</span><span style="font-family: "consolas";"> </span><span style="color: #7f0055; font-family: "consolas"; mso-bidi-font-weight: bold;">abstract</span><span style="font-family: "consolas";"> </span><span style="color: #7f0055; font-family: "consolas"; mso-bidi-font-weight: bold;">void</span><span style="font-family: "consolas";"> send(IUser </span><span style="color: #6a3e3e; font-family: "consolas";">to</span><span style="font-family: "consolas";">, String </span><span style="color: #6a3e3e; font-family: "consolas";">msg</span><span style="font-family: "consolas";">);</span><span style="font-family: "consolas";"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; margin-bottom: 0.0001pt; padding: 0in;">
<br /></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: "consolas";"> </span><span style="color: #7f0055; font-family: "consolas"; mso-bidi-font-weight: bold;">public</span><span style="font-family: "consolas";"> </span><span style="color: #7f0055; font-family: "consolas"; mso-bidi-font-weight: bold;">abstract</span><span style="font-family: "consolas";"> </span><span style="color: #7f0055; font-family: "consolas"; mso-bidi-font-weight: bold;">void</span><span style="font-family: "consolas";"> receive(IUser </span><span style="color: #6a3e3e; font-family: "consolas";">from</span><span style="font-family: "consolas";">,String
</span><span style="color: #6a3e3e; font-family: "consolas";">msg</span><span style="font-family: "consolas";">);</span><span style="font-family: "consolas";"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; margin-bottom: 0.0001pt; padding: 0in; text-align: justify;">
<span style="font-family: "consolas";">}<o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; margin-bottom: 0.0001pt; padding: 0in;">
<br /></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; margin-bottom: 0.0001pt; padding: 0in;">
<span style="color: #7f0055; font-family: "consolas"; mso-bidi-font-weight: bold;">public</span><span style="font-family: "consolas";"> </span><span style="color: #7f0055; font-family: "consolas"; mso-bidi-font-weight: bold;">class</span><span style="font-family: "consolas";"> User </span><span style="color: #7f0055; font-family: "consolas"; mso-bidi-font-weight: bold;">extends</span><span style="font-family: "consolas";"> IUser {</span><span style="font-family: "consolas";"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: "consolas";"> </span><span style="color: #7f0055; font-family: "consolas"; mso-bidi-font-weight: bold;">public</span><span style="font-family: "consolas";"> User(ChatMediator </span><span style="color: #6a3e3e; font-family: "consolas";">med</span><span style="font-family: "consolas";">, String </span><span style="color: #6a3e3e; font-family: "consolas";">name</span><span style="font-family: "consolas";">) {</span><span style="font-family: "consolas";"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: "consolas";"> </span><span style="color: #7f0055; font-family: "consolas"; mso-bidi-font-weight: bold;">super</span><span style="font-family: "consolas";">(</span><span style="color: #6a3e3e; font-family: "consolas";">med</span><span style="font-family: "consolas";">, </span><span style="color: #6a3e3e; font-family: "consolas";">name</span><span style="font-family: "consolas";">);</span><span style="font-family: "consolas";"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: "consolas";"> }</span><span style="font-family: "consolas";"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; margin-bottom: 0.0001pt; padding: 0in;">
<br /></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: "consolas";"> </span><span style="color: #646464; font-family: "consolas";">@Override</span><span style="font-family: "consolas";"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: "consolas";"> </span><span style="color: #7f0055; font-family: "consolas"; mso-bidi-font-weight: bold;">public</span><span style="font-family: "consolas";"> </span><span style="color: #7f0055; font-family: "consolas"; mso-bidi-font-weight: bold;">void</span><span style="font-family: "consolas";"> send(IUser </span><span style="color: #6a3e3e; font-family: "consolas";">to</span><span style="font-family: "consolas";">, String
</span><span style="color: #6a3e3e; font-family: "consolas";">msg</span><span style="font-family: "consolas";">) {</span><span style="font-family: "consolas";"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: "consolas";"> System.</span><i><span style="color: #0000c0; font-family: "consolas"; mso-bidi-font-weight: bold;">out</span></i><span style="font-family: "consolas";">.println(</span><span style="color: #7f0055; font-family: "consolas"; mso-bidi-font-weight: bold;">this</span><span style="font-family: "consolas";">.</span><span style="color: #0000c0; font-family: "consolas";">name</span><span style="font-family: "consolas";">+</span><span style="color: #2a00ff; font-family: "consolas";">": Sending Message="</span><span style="font-family: "consolas";">+</span><span style="color: #6a3e3e; font-family: "consolas";">msg</span><span style="font-family: "consolas";">);</span><span style="font-family: "consolas";"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: "consolas";"> </span><span style="color: #0000c0; font-family: "consolas";">mediator</span><span style="font-family: "consolas";">.sendMessage(</span><span style="color: #7f0055; font-family: "consolas"; mso-bidi-font-weight: bold;">this</span><span style="font-family: "consolas";">, </span><span style="color: #6a3e3e; font-family: "consolas";">to</span><span style="font-family: "consolas";">,</span><span style="color: #6a3e3e; font-family: "consolas";">msg</span><span style="font-family: "consolas";">);</span><span style="font-family: "consolas";"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: "consolas";"> }</span><span style="font-family: "consolas";"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: "consolas";"> </span><span style="font-family: "consolas";"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: "consolas";"> </span><span style="color: #646464; font-family: "consolas";">@Override</span><span style="font-family: "consolas";"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: "consolas";"> </span><span style="color: #7f0055; font-family: "consolas"; mso-bidi-font-weight: bold;">public</span><span style="font-family: "consolas";"> </span><span style="color: #7f0055; font-family: "consolas"; mso-bidi-font-weight: bold;">void</span><span style="font-family: "consolas";"> receive(IUser </span><span style="color: #6a3e3e; font-family: "consolas";">from</span><span style="font-family: "consolas";">,
String </span><span style="color: #6a3e3e; font-family: "consolas";">msg</span><span style="font-family: "consolas";">) {</span><span style="font-family: "consolas";"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: "consolas";"> System.</span><i><span style="color: #0000c0; font-family: "consolas"; mso-bidi-font-weight: bold;">out</span></i><span style="font-family: "consolas";">.println(</span><span style="color: #2a00ff; font-family: "consolas";">"Delivered from "</span><span style="font-family: "consolas";">+</span><span style="color: #6a3e3e; font-family: "consolas";">from</span><span style="font-family: "consolas";">.</span><span style="color: #0000c0; font-family: "consolas";">name</span><span style="font-family: "consolas";">+</span><span style="color: #2a00ff; font-family: "consolas";">"
to "</span><span style="font-family: "consolas";">+</span><span style="color: #7f0055; font-family: "consolas"; mso-bidi-font-weight: bold;">this</span><span style="font-family: "consolas";">.</span><span style="color: #0000c0; font-family: "consolas";">name</span><span style="font-family: "consolas";">);</span><span style="font-family: "consolas";"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: "consolas";"> }</span><span style="font-family: "consolas";"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; margin-bottom: 0.0001pt; padding: 0in; text-align: justify;">
<span style="font-family: "consolas";">}<o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; margin-bottom: 0.0001pt; padding: 0in;">
<br /></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; margin-bottom: 0.0001pt; padding: 0in;">
<span style="color: #7f0055; font-family: "consolas"; mso-bidi-font-weight: bold;">public</span><span style="font-family: "consolas";"> </span><span style="color: #7f0055; font-family: "consolas"; mso-bidi-font-weight: bold;">class</span><span style="font-family: "consolas";"> ChatClient {</span><span style="font-family: "consolas";"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: "consolas";"> </span><span style="color: #7f0055; font-family: "consolas"; mso-bidi-font-weight: bold;">public</span><span style="font-family: "consolas";"> </span><span style="color: #7f0055; font-family: "consolas"; mso-bidi-font-weight: bold;">static</span><span style="font-family: "consolas";"> </span><span style="color: #7f0055; font-family: "consolas"; mso-bidi-font-weight: bold;">void</span><span style="font-family: "consolas";"> main(String[] </span><span style="color: #6a3e3e; font-family: "consolas";">args</span><span style="font-family: "consolas";">) {</span><span style="font-family: "consolas";"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: "consolas";"> ChatMediator
</span><span style="color: #6a3e3e; font-family: "consolas";">mediator</span><span style="font-family: "consolas";"> = </span><span style="color: #7f0055; font-family: "consolas"; mso-bidi-font-weight: bold;">new</span><span style="font-family: "consolas";"> ChatMediator();</span><span style="font-family: "consolas";"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: "consolas";"> IUser
</span><span style="color: #6a3e3e; font-family: "consolas";">john</span><span style="font-family: "consolas";"> = </span><span style="color: #7f0055; font-family: "consolas"; mso-bidi-font-weight: bold;">new</span><span style="font-family: "consolas";"> User(</span><span style="color: #6a3e3e; font-family: "consolas";">mediator</span><span style="font-family: "consolas";">, </span><span style="color: #2a00ff; font-family: "consolas";">"john"</span><span style="font-family: "consolas";">);</span><span style="font-family: "consolas";"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: "consolas";"> IUser
</span><span style="color: #6a3e3e; font-family: "consolas";">micheal</span><span style="font-family: "consolas";"> = </span><span style="color: #7f0055; font-family: "consolas"; mso-bidi-font-weight: bold;">new</span><span style="font-family: "consolas";"> User(</span><span style="color: #6a3e3e; font-family: "consolas";">mediator</span><span style="font-family: "consolas";">, </span><span style="color: #2a00ff; font-family: "consolas";">"micheal"</span><span style="font-family: "consolas";">);</span><span style="font-family: "consolas";"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: "consolas";"> </span><span style="font-family: "consolas";"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: "consolas";"> </span><span style="color: #6a3e3e; font-family: "consolas";">mediator</span><span style="font-family: "consolas";">.addUser(</span><span style="color: #6a3e3e; font-family: "consolas";">john</span><span style="font-family: "consolas";">);</span><span style="font-family: "consolas";"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: "consolas";"> </span><span style="color: #6a3e3e; font-family: "consolas";">mediator</span><span style="font-family: "consolas";">.addUser(</span><span style="color: #6a3e3e; font-family: "consolas";">micheal</span><span style="font-family: "consolas";">);</span><span style="font-family: "consolas";"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: "consolas";"> </span><span style="font-family: "consolas";"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: "consolas";"> </span><span style="color: #6a3e3e; font-family: "consolas";">john</span><span style="font-family: "consolas";">.send(</span><span style="color: #6a3e3e; font-family: "consolas";">micheal</span><span style="font-family: "consolas";">, </span><span style="color: #2a00ff; font-family: "consolas";">"hello micheal!"</span><span style="font-family: "consolas";">);</span><span style="font-family: "consolas";"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: "consolas";"> </span><span style="font-family: "consolas";"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: "consolas";"> </span><span style="color: #6a3e3e; font-family: "consolas";">micheal</span><span style="font-family: "consolas";">.send(</span><span style="color: #6a3e3e; font-family: "consolas";">john</span><span style="font-family: "consolas";">, </span><span style="color: #2a00ff; font-family: "consolas";">"hello
john!"</span><span style="font-family: "consolas";">);</span><span style="font-family: "consolas";"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: "consolas";"> }</span><span style="font-family: "consolas";"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; margin-bottom: 0.0001pt; padding: 0in; text-align: justify;">
<span style="font-family: "consolas";">}<o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; margin-bottom: 0.0001pt; padding: 0in; text-align: justify;">
<br /></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; margin-bottom: 0.0001pt; padding: 0in; text-align: justify;">
<span style="font-family: "consolas";">Output:<o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: "consolas";">john: Sending Message=hello micheal!</span><span style="font-family: "consolas";"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: "consolas";">Delivered from john to micheal</span><span style="font-family: "consolas";"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: "consolas";">micheal: Sending Message=hello john!</span><span style="font-family: "consolas";"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; margin-bottom: 0.0001pt; padding: 0in; text-align: justify;">
<span style="font-family: "consolas";">Delivered from micheal to john</span></div>
</div>
<div class="MsoNormal" style="background: white; margin-bottom: 0.0001pt; text-align: justify;">
<b style="background-color: transparent;"><span style="font-family: "book antiqua" , "serif"; font-size: 16.0pt;"><br /></span></b>
<b style="background-color: transparent;"><span style="font-family: "book antiqua" , "serif"; font-size: 16.0pt;">Mediator
Pattern usage in JDK</span></b></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt; text-align: justify;">
<span style="font-family: "book antiqua" , "serif"; font-size: 13.0pt;"><br /></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt; text-align: justify;">
<span style="font-family: "book antiqua" , "serif"; font-size: 13.0pt;">Java
Message Service (JMS) uses Mediator pattern along with Observer pattern to
allow applications to subscribe and publish data to other applications.<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt; text-align: justify;">
<span style="font-family: "book antiqua" , "serif"; font-size: 13.0pt;"><br /></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt; text-align: justify;">
<span style="font-family: "book antiqua" , "serif"; font-size: 13.0pt;">java.util.Timer
class schedule (i.e scheduleAtFixedRate) methods.<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt; text-align: justify;">
<span style="font-family: "book antiqua" , "serif"; font-size: 13.0pt;"><br /></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt; text-align: justify;">
<span style="font-family: "book antiqua" , "serif"; font-size: 13.0pt;">Java
Concurrency Executor execute() method.<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt; text-align: justify;">
<span style="font-family: "book antiqua" , "serif"; font-size: 13.0pt;"><br /></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt; text-align: justify;">
<span style="font-family: "book antiqua" , "serif"; font-size: 13.0pt;">java.lang.reflect.Method
invoke() method.</span></div>
</div>
javaexplor03http://www.blogger.com/profile/07455293496498711738noreply@blogger.com0tag:blogger.com,1999:blog-615973148715732292.post-49663122338952288662017-05-26T04:36:00.000-07:002017-06-29T02:48:54.570-07:00Shutdown Hook - addShutdownHook<div dir="ltr" style="text-align: left;" trbidi="on">
<div class="MsoNormal" style="margin-bottom: .0001pt; margin-bottom: 0in; mso-line-height-alt: 14.7pt; text-align: justify;">
<b><span style="color: #333333; font-family: "book antiqua" , "serif"; font-size: 13.0pt;">public void addShutdownHook(Thread hook)</span></b></div>
<div class="MsoNormal" style="line-height: 14.7pt; margin-bottom: .0001pt; margin-bottom: 0in; text-align: justify;">
<b><span style="color: #333333; font-family: "book antiqua" , "serif"; font-size: 13.0pt;"><br /></span></b></div>
<div class="MsoNormal" style="line-height: 14.7pt; margin-bottom: .0001pt; margin-bottom: 0in; text-align: justify;">
<span style="color: #333333; font-family: "book antiqua" , "serif"; font-size: 13.0pt;">Registers a new virtual-machine shutdown hook.</span></div>
<div class="MsoNormal" style="line-height: 14.7pt; margin-bottom: .0001pt; margin-bottom: 0in; text-align: justify;">
<span style="color: #333333; font-family: "book antiqua" , "serif"; font-size: 13.0pt;"><br /></span></div>
<div class="MsoNormal" style="line-height: 14.7pt; margin-bottom: .0001pt; margin-bottom: 0in; text-align: justify;">
<b><span style="color: #333333; font-family: "book antiqua" , "serif"; font-size: 13.0pt;">The JVM shuts down:</span></b><span style="color: #333333; font-family: "book antiqua" , "serif"; font-size: 13.0pt;"> </span><span style="color: #333333; font-family: "book antiqua" , "serif"; font-size: 13.0pt;">The program exits
normally, when the last non-daemon thread exits or when the exit (equivalently,
System.exit) method is invoked, or t</span><span style="color: #333333; font-family: "book antiqua" , serif; font-size: 13pt; line-height: 14.7pt;">he virtual machine is terminated in response to a user
interrupt, such as typing ^C, or a system-wide event, such as user logoff or
system shutdown.</span></div>
<div class="MsoNormal" style="line-height: 14.7pt; margin-bottom: .0001pt; margin-bottom: 0in; text-align: justify;">
<b style="line-height: 14.7pt;"><span style="color: #333333; font-family: "book antiqua" , "serif"; font-size: 13.0pt;"><br /></span></b></div>
<div class="MsoNormal" style="line-height: 14.7pt; margin-bottom: .0001pt; margin-bottom: 0in; text-align: justify;">
<b style="line-height: 14.7pt;"><span style="color: #333333; font-family: "book antiqua" , "serif"; font-size: 13.0pt;">Examples:</span></b><span style="color: #333333; font-family: "book antiqua" , serif; font-size: 13pt; line-height: 14.7pt;"> user presses ctrl+c on the command prompt,
System.exit(int) method is invoked, user logoff, user shutdown etc.</span></div>
<div class="MsoNormal" style="line-height: 14.7pt; margin-bottom: .0001pt; margin-bottom: 0in; text-align: justify;">
<span style="color: #333333; font-family: "book antiqua" , serif; font-size: 13pt; line-height: 14.7pt;"><br /></span></div>
<div class="MsoNormal" style="line-height: 14.7pt; margin-bottom: .0001pt; margin-bottom: 0in; text-align: justify;">
<span style="color: #333333; font-family: "book antiqua" , serif; font-size: 13pt; line-height: 14.7pt;">The shutdown hook can be used to perform cleanup resource or
save the state when JVM shuts down normally or abruptly. Performing clean
resource means <b>closing log file, sending some alerts or something else</b>. So if
you want to execute some code before JVM shuts down, use shutdown hook.</span></div>
<div class="MsoNormal" style="line-height: 14.7pt; margin-bottom: .0001pt; margin-bottom: 0in; text-align: justify;">
<span style="color: #333333; font-family: "book antiqua" , serif; font-size: 13pt; line-height: 14.7pt;"><br /></span>
<span style="color: #333333; font-family: "book antiqua" , serif; font-size: 13pt; line-height: 14.7pt;"><b style="color: black; font-family: "Times New Roman"; font-size: medium;"><span style="color: #333333; font-family: "book antiqua" , "serif"; font-size: 16pt;">How it works?</span></b></span></div>
<div class="MsoNormal" style="line-height: 14.7pt; margin-bottom: .0001pt; margin-bottom: 0in; text-align: justify;">
<span style="color: #333333; font-family: "book antiqua" , serif; font-size: 13pt; line-height: 14.7pt;">A shutdown hook is simply an initialized but unstarted thread.
When the virtual machine begins its shutdown sequence it will start all
registered shutdown hooks in some <b>unspecified</b> <b>order</b> and let them run
concurrently. When all the hooks have finished it will then run all uninvoked
finalizers if finalization-on-exit has been enabled. Finally, the virtual
machine will halt.</span></div>
<div class="MsoNormal" style="line-height: 14.7pt; margin-bottom: .0001pt; margin-bottom: 0in; text-align: justify;">
<span style="color: #333333; font-family: "book antiqua" , serif; font-size: 13pt; line-height: 14.7pt;"><br /></span></div>
<div class="MsoNormal" style="line-height: 14.7pt; margin-bottom: .0001pt; margin-bottom: 0in; text-align: justify;">
<span style="color: #333333; font-family: "book antiqua" , serif; font-size: 13pt; line-height: 14.7pt;">Note that daemon threads will continue to run during the
shutdown sequence, as will non-daemon threads if shutdown was initiated by invoking
the exit method.</span></div>
<div class="MsoNormal" style="line-height: 14.7pt; margin-bottom: .0001pt; margin-bottom: 0in; text-align: justify;">
<span style="color: #333333; font-family: "book antiqua" , serif; font-size: 13pt; line-height: 14.7pt;"><br /></span></div>
<div class="MsoNormal" style="line-height: 14.7pt; margin-bottom: .0001pt; margin-bottom: 0in; text-align: justify;">
<span style="color: #333333; font-family: "book antiqua" , serif; font-size: 13pt; line-height: 14.7pt;">Once the shutdown sequence has begun it can be stopped only by
invoking the halt method, which forcibly terminates the virtual machine.</span></div>
<div class="MsoNormal" style="line-height: 14.7pt; margin-bottom: .0001pt; margin-bottom: 0in; text-align: justify;">
<span style="color: #333333; font-family: "book antiqua" , serif; font-size: 13pt; line-height: 14.7pt;"><br /></span></div>
<div class="MsoNormal" style="line-height: 14.7pt; margin-bottom: .0001pt; margin-bottom: 0in; text-align: justify;">
<span style="color: #333333; font-family: "book antiqua" , serif; font-size: 13pt; line-height: 14.7pt;">Once the shutdown sequence has begun it is impossible to
register a new shutdown hook or de-register a previously-registered hook.
Attempting either of these operations will cause an <b>IllegalStateException</b> to be
thrown.</span></div>
<div class="MsoNormal" style="line-height: 14.7pt; margin-bottom: .0001pt; margin-bottom: 0in; text-align: justify;">
<span style="color: #333333; font-family: "book antiqua" , serif; font-size: 13pt; line-height: 14.7pt;"><br /></span></div>
<div class="MsoNormal" style="line-height: 14.7pt; margin-bottom: .0001pt; margin-bottom: 0in; text-align: justify;">
<span style="color: #333333; font-family: "book antiqua" , serif; font-size: 13pt; line-height: 14.7pt;">Shutdown hooks should also finish their work quickly. When a
program invokes exit the expectation is that the virtual machine will promptly
shut down and exit.</span></div>
<div class="MsoNormal" style="line-height: 14.7pt; margin-bottom: .0001pt; margin-bottom: 0in; text-align: justify;">
<span style="color: #333333; font-family: "book antiqua" , "serif"; font-size: 13.0pt;"><br /></span></div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin-bottom: 0in; mso-line-height-alt: 14.7pt; text-align: justify;">
<b><span style="color: #333333; font-family: "book antiqua" , "serif"; font-size: 16.0pt;">addShutdownHook(Runnable
r)</span></b><span style="color: #333333; font-family: "book antiqua" , "serif"; font-size: 16.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: 14.7pt; margin-bottom: .0001pt; margin-bottom: 0in; text-align: justify;">
<span style="color: #333333; font-family: "book antiqua" , "serif"; font-size: 13.0pt;"><br /></span></div>
<div class="MsoNormal" style="line-height: 14.7pt; margin-bottom: .0001pt; margin-bottom: 0in; text-align: justify;">
<span style="color: #333333; font-family: "book antiqua" , "serif"; font-size: 13.0pt;">The addShutdownHook() method of Runtime class is used to
register the thread with the Virtual Machine.</span></div>
<div class="MsoNormal" style="line-height: 14.7pt; margin-bottom: .0001pt; margin-bottom: 0in; text-align: justify;">
<b style="line-height: 14.7pt;"><span style="color: #333333; font-family: "book antiqua" , "serif"; font-size: 13.0pt;"><br /></span></b></div>
<div class="MsoNormal" style="line-height: 14.7pt; margin-bottom: .0001pt; margin-bottom: 0in; text-align: justify;">
<b style="line-height: 14.7pt;"><span style="color: #333333; font-family: "book antiqua" , "serif"; font-size: 13.0pt;">Syntax:</span></b></div>
<div class="MsoNormal" style="line-height: 14.7pt; margin-bottom: .0001pt; margin-bottom: 0in; text-align: justify;">
<span style="color: #333333; font-family: "book antiqua" , "serif"; font-size: 13.0pt;">public void addShutdownHook(Runnable r){ }</span></div>
<div class="MsoNormal" style="line-height: 14.7pt; margin-bottom: .0001pt; margin-bottom: 0in; text-align: justify;">
<span style="color: #333333; font-family: "book antiqua" , serif; font-size: 13pt; line-height: 14.7pt;"><br /></span></div>
<div class="MsoNormal" style="line-height: 14.7pt; margin-bottom: .0001pt; margin-bottom: 0in; text-align: justify;">
<span style="color: #333333; font-family: "book antiqua" , serif; font-size: 13pt; line-height: 14.7pt;">The object of Runtime class can be obtained by calling the
static factory method getRuntime().</span></div>
<div class="MsoNormal" style="line-height: 14.7pt; margin-bottom: .0001pt; margin-bottom: 0in; text-align: justify;">
<span style="color: #333333; font-family: "book antiqua" , serif; font-size: 13pt; line-height: 14.7pt;"><br /></span></div>
<div class="MsoNormal" style="line-height: 14.7pt; margin-bottom: .0001pt; margin-bottom: 0in; text-align: justify;">
<span style="color: #333333; font-family: "book antiqua" , serif; font-size: 13pt; line-height: 14.7pt;">Runtime r = Runtime.getRuntime();</span></div>
<div class="MsoNormal" style="line-height: 14.7pt; margin-bottom: .0001pt; margin-bottom: 0in; text-align: justify;">
<b style="line-height: 14.7pt;"><span style="color: #333333; font-family: "book antiqua" , "serif"; font-size: 13.0pt;"><br /></span></b></div>
<div class="MsoNormal" style="line-height: 14.7pt; margin-bottom: .0001pt; margin-bottom: 0in; text-align: justify;">
<b style="line-height: 14.7pt;"><span style="color: #333333; font-family: "book antiqua" , "serif"; font-size: 13.0pt;">Factory method</span></b></div>
<div class="MsoNormal" style="line-height: 14.7pt; margin-bottom: .0001pt; margin-bottom: 0in; text-align: justify;">
<span style="color: #333333; font-family: "book antiqua" , serif; font-size: 13pt; line-height: 14.7pt;"><br /></span></div>
<div class="MsoNormal" style="line-height: 14.7pt; margin-bottom: .0001pt; margin-bottom: 0in; text-align: justify;">
<span style="color: #333333; font-family: "book antiqua" , serif; font-size: 13pt; line-height: 14.7pt;">The method that returns the instance of a class is known as
factory method.</span></div>
<div class="MsoNormal" style="line-height: 14.7pt; margin-bottom: .0001pt; margin-bottom: 0in;">
<b><span style="color: #333333; font-family: "book antiqua" , "serif"; font-size: 16.0pt;"><br /></span></b></div>
<div class="MsoNormal" style="line-height: 14.7pt; margin-bottom: .0001pt; margin-bottom: 0in;">
<b><span style="color: #333333; font-family: "book antiqua" , "serif"; font-size: 16.0pt;">Shutdown Hook example</span></b></div>
<div class="MsoNormal" style="line-height: 14.7pt; margin-bottom: .0001pt; margin-bottom: 0in;">
<br /></div>
<div style="background: #DBE5F1; border: solid windowtext 1.0pt; mso-background-themecolor: accent1; mso-background-themetint: 51; mso-border-alt: solid windowtext .5pt; mso-element: para-border-div; padding: 1.0pt 4.0pt 1.0pt 4.0pt;">
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: 14.7pt; margin-bottom: 0.0001pt; padding: 0in;">
<span style="color: #7f0055; font-family: "consolas"; mso-bidi-font-weight: bold; mso-fareast-font-family: "Times New Roman";">package</span><span style="color: #333333; font-family: "consolas"; mso-fareast-font-family: "Times New Roman";"> com.threads.shutdown;</span><span style="color: #333333; font-family: "helvetica" , "sans-serif"; mso-fareast-font-family: "Times New Roman";"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: 14.7pt; margin-bottom: 0.0001pt; padding: 0in;">
<br /></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: 14.7pt; margin-bottom: 0.0001pt; padding: 0in;">
<span style="color: #7f0055; font-family: "consolas"; mso-bidi-font-weight: bold; mso-fareast-font-family: "Times New Roman";">class</span><span style="color: #333333; font-family: "consolas"; mso-fareast-font-family: "Times New Roman";"> ShutDownHook </span><span style="color: #7f0055; font-family: "consolas"; mso-bidi-font-weight: bold; mso-fareast-font-family: "Times New Roman";">extends</span><span style="color: #333333; font-family: "consolas"; mso-fareast-font-family: "Times New Roman";"> Thread { </span><span style="color: #333333; font-family: "helvetica" , "sans-serif"; mso-fareast-font-family: "Times New Roman";"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: 14.7pt; margin-bottom: 0.0001pt; padding: 0in;">
<span style="color: #333333; font-family: "consolas"; mso-fareast-font-family: "Times New Roman";"> </span><span style="color: #7f0055; font-family: "consolas"; mso-bidi-font-weight: bold; mso-fareast-font-family: "Times New Roman";">public</span><span style="color: #333333; font-family: "consolas"; mso-fareast-font-family: "Times New Roman";"> </span><span style="color: #7f0055; font-family: "consolas"; mso-bidi-font-weight: bold; mso-fareast-font-family: "Times New Roman";">void</span><span style="color: #333333; font-family: "consolas"; mso-fareast-font-family: "Times New Roman";"> run(){ </span><span style="color: #333333; font-family: "helvetica" , "sans-serif"; mso-fareast-font-family: "Times New Roman";"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: 14.7pt; margin-bottom: 0.0001pt; padding: 0in;">
<span style="color: #333333; font-family: "consolas"; mso-fareast-font-family: "Times New Roman";">
System.</span><i><span style="color: #0000c0; font-family: "consolas"; mso-bidi-font-weight: bold; mso-fareast-font-family: "Times New Roman";">out</span></i><span style="color: #333333; font-family: "consolas"; mso-fareast-font-family: "Times New Roman";">.println(</span><span style="color: #2a00ff; font-family: "consolas"; mso-fareast-font-family: "Times New Roman";">"cleanup.. shut down hook task"</span><span style="color: #333333; font-family: "consolas"; mso-fareast-font-family: "Times New Roman";">); </span><span style="color: #333333; font-family: "helvetica" , "sans-serif"; mso-fareast-font-family: "Times New Roman";"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: 14.7pt; margin-bottom: 0.0001pt; padding: 0in;">
<span style="color: #333333; font-family: "consolas"; mso-fareast-font-family: "Times New Roman";"> } </span><span style="color: #333333; font-family: "helvetica" , "sans-serif"; mso-fareast-font-family: "Times New Roman";"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: 14.7pt; margin-bottom: 0.0001pt; padding: 0in; text-align: justify;">
<span style="color: #333333; font-family: "consolas"; mso-fareast-font-family: "Times New Roman";">}</span><span style="color: #333333; font-family: "helvetica" , "sans-serif"; mso-fareast-font-family: "Times New Roman";"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: 14.7pt; margin-bottom: 0.0001pt; padding: 0in; text-align: justify;">
<br /></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: 14.7pt; margin-bottom: 0.0001pt; padding: 0in;">
<span style="color: #7f0055; font-family: "consolas"; mso-bidi-font-weight: bold; mso-fareast-font-family: "Times New Roman";">package</span><span style="color: #333333; font-family: "consolas"; mso-fareast-font-family: "Times New Roman";"> com.threads.shutdown;</span><span style="color: #333333; font-family: "helvetica" , "sans-serif"; mso-fareast-font-family: "Times New Roman";"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: 14.7pt; margin-bottom: 0.0001pt; padding: 0in;">
<span style="color: #7f0055; font-family: "consolas"; mso-bidi-font-weight: bold; mso-fareast-font-family: "Times New Roman";">public</span><span style="color: #333333; font-family: "consolas"; mso-fareast-font-family: "Times New Roman";"> </span><span style="color: #7f0055; font-family: "consolas"; mso-bidi-font-weight: bold; mso-fareast-font-family: "Times New Roman";">class</span><span style="color: #333333; font-family: "consolas"; mso-fareast-font-family: "Times New Roman";"> TestShutDownHook { </span><span style="color: #333333; font-family: "helvetica" , "sans-serif"; mso-fareast-font-family: "Times New Roman";"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: 14.7pt; margin-bottom: 0.0001pt; padding: 0in;">
<span style="color: #333333; font-family: "consolas"; mso-fareast-font-family: "Times New Roman";"> </span><span style="color: #7f0055; font-family: "consolas"; mso-bidi-font-weight: bold; mso-fareast-font-family: "Times New Roman";">public</span><span style="color: #333333; font-family: "consolas"; mso-fareast-font-family: "Times New Roman";"> </span><span style="color: #7f0055; font-family: "consolas"; mso-bidi-font-weight: bold; mso-fareast-font-family: "Times New Roman";">static</span><span style="color: #333333; font-family: "consolas"; mso-fareast-font-family: "Times New Roman";"> </span><span style="color: #7f0055; font-family: "consolas"; mso-bidi-font-weight: bold; mso-fareast-font-family: "Times New Roman";">void</span><span style="color: #333333; font-family: "consolas"; mso-fareast-font-family: "Times New Roman";"> main(String[] </span><span style="color: #6a3e3e; font-family: "consolas"; mso-fareast-font-family: "Times New Roman";">args</span><span style="color: #333333; font-family: "consolas"; mso-fareast-font-family: "Times New Roman";">)</span><span style="color: #7f0055; font-family: "consolas"; mso-bidi-font-weight: bold; mso-fareast-font-family: "Times New Roman";">throws</span><span style="color: #333333; font-family: "consolas"; mso-fareast-font-family: "Times New Roman";"> Exception { </span><span style="color: #333333; font-family: "helvetica" , "sans-serif"; mso-fareast-font-family: "Times New Roman";"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: 14.7pt; margin-bottom: 0.0001pt; padding: 0in;">
<br /></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: 14.7pt; margin-bottom: 0.0001pt; padding: 0in;">
<span style="color: #333333; font-family: "consolas"; mso-fareast-font-family: "Times New Roman";"> <span style="background: silver; mso-bidi-font-weight: bold;">Runtime </span></span><span style="background: silver; color: #6a3e3e; font-family: "consolas";">runtime</span><span style="background: silver; color: #333333; font-family: "consolas";">= Runtime.<i>getRuntime</i>();</span><span style="color: #333333; font-family: "helvetica" , "sans-serif"; mso-fareast-font-family: "Times New Roman";"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: 14.7pt; margin-bottom: 0.0001pt; padding: 0in;">
<span style="color: #333333; font-family: "consolas"; mso-bidi-font-weight: bold; mso-fareast-font-family: "Times New Roman";"> </span><span style="background: silver; color: #6a3e3e; font-family: "consolas";">runtime</span><span style="background: silver; color: #333333; font-family: "consolas";">.addShutdownHook(</span><span style="background: silver; color: #7f0055; font-family: "consolas";">new</span><span style="background: silver; color: #333333; font-family: "consolas";"> ShutDownHook());</span><span style="color: #333333; font-family: "helvetica" , "sans-serif"; mso-fareast-font-family: "Times New Roman";"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: 14.7pt; margin-bottom: 0.0001pt; padding: 0in;">
<br /></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: 14.7pt; margin-bottom: 0.0001pt; padding: 0in;">
<span style="color: #333333; font-family: "consolas"; mso-fareast-font-family: "Times New Roman";">
System.</span><i><span style="color: #0000c0; font-family: "consolas"; mso-bidi-font-weight: bold; mso-fareast-font-family: "Times New Roman";">out</span></i><span style="color: #333333; font-family: "consolas"; mso-fareast-font-family: "Times New Roman";">.println(</span><span style="color: #2a00ff; font-family: "consolas"; mso-fareast-font-family: "Times New Roman";">"Now main sleeping.press ctrl+c to
exit"</span><span style="color: #333333; font-family: "consolas"; mso-fareast-font-family: "Times New Roman";">); </span><span style="color: #333333; font-family: "helvetica" , "sans-serif"; mso-fareast-font-family: "Times New Roman";"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: 14.7pt; margin-bottom: 0.0001pt; padding: 0in;">
<span style="color: #333333; font-family: "consolas"; mso-fareast-font-family: "Times New Roman";"> </span><span style="color: #7f0055; font-family: "consolas"; mso-bidi-font-weight: bold; mso-fareast-font-family: "Times New Roman";">try</span><span style="color: #333333; font-family: "consolas"; mso-fareast-font-family: "Times New Roman";"> {</span><span style="color: #333333; font-family: "helvetica" , "sans-serif"; mso-fareast-font-family: "Times New Roman";"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: 14.7pt; margin-bottom: 0.0001pt; padding: 0in;">
<span style="color: #333333; font-family: "consolas"; mso-fareast-font-family: "Times New Roman";">
Thread.<i>sleep</i>(3000);</span><span style="color: #333333; font-family: "helvetica" , "sans-serif"; mso-fareast-font-family: "Times New Roman";"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: 14.7pt; margin-bottom: 0.0001pt; padding: 0in;">
<span style="color: #333333; font-family: "consolas"; mso-fareast-font-family: "Times New Roman";">
} </span><span style="color: #7f0055; font-family: "consolas"; mso-bidi-font-weight: bold; mso-fareast-font-family: "Times New Roman";">catch</span><span style="color: #333333; font-family: "consolas"; mso-fareast-font-family: "Times New Roman";"> (InterruptedException </span><span style="color: #6a3e3e; font-family: "consolas"; mso-fareast-font-family: "Times New Roman";">e</span><span style="color: #333333; font-family: "consolas"; mso-fareast-font-family: "Times New Roman";">) {</span><span style="color: #333333; font-family: "helvetica" , "sans-serif"; mso-fareast-font-family: "Times New Roman";"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: 14.7pt; margin-bottom: 0.0001pt; padding: 0in;">
<span style="color: #333333; font-family: "consolas"; mso-fareast-font-family: "Times New Roman";">
System.</span><i><span style="color: #0000c0; font-family: "consolas"; mso-bidi-font-weight: bold; mso-fareast-font-family: "Times New Roman";">out</span></i><span style="color: #333333; font-family: "consolas"; mso-fareast-font-family: "Times New Roman";">.println(</span><span style="color: #2a00ff; font-family: "consolas"; mso-fareast-font-family: "Times New Roman";">"Interrupted Exception"</span><span style="color: #333333; font-family: "consolas"; mso-fareast-font-family: "Times New Roman";">);</span><span style="color: #333333; font-family: "helvetica" , "sans-serif"; mso-fareast-font-family: "Times New Roman";"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: 14.7pt; margin-bottom: 0.0001pt; padding: 0in;">
<span style="color: #333333; font-family: "consolas"; mso-fareast-font-family: "Times New Roman";">
}</span><span style="color: #333333; font-family: "helvetica" , "sans-serif"; mso-fareast-font-family: "Times New Roman";"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: 14.7pt; margin-bottom: 0.0001pt; padding: 0in;">
<span style="color: #333333; font-family: "consolas"; mso-fareast-font-family: "Times New Roman";"> } </span><span style="color: #333333; font-family: "helvetica" , "sans-serif"; mso-fareast-font-family: "Times New Roman";"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: 14.7pt; margin-bottom: 0.0001pt; padding: 0in; text-align: justify;">
<span style="color: #333333; font-family: "consolas"; mso-fareast-font-family: "Times New Roman";">}</span><span style="color: #333333; font-family: "helvetica" , "sans-serif"; mso-fareast-font-family: "Times New Roman";"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: 14.7pt; margin-bottom: 0.0001pt; padding: 0in; text-align: justify;">
<br /></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: 14.7pt; margin-bottom: 0.0001pt; padding: 0in; text-align: justify;">
<span style="color: #333333; font-family: "consolas"; mso-fareast-font-family: "Times New Roman";">Output:</span><span style="color: #333333; font-family: "helvetica" , "sans-serif"; mso-fareast-font-family: "Times New Roman";"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: 14.7pt; margin-bottom: 0.0001pt; padding: 0in;">
<span style="color: #333333; font-family: "consolas"; mso-fareast-font-family: "Times New Roman";">Now main sleeping.press ctrl+c to exit</span><span style="color: #333333; font-family: "helvetica" , "sans-serif"; mso-fareast-font-family: "Times New Roman";"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: 14.7pt; margin-bottom: 0.0001pt; padding: 0in;">
<span style="color: #333333; font-family: "consolas"; mso-fareast-font-family: "Times New Roman";">cleanup.. shut down hook task</span><span style="color: #333333; font-family: "helvetica" , "sans-serif"; mso-fareast-font-family: "Times New Roman";"><o:p></o:p></span></div>
</div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin-bottom: 0in; mso-line-height-alt: 14.7pt;">
<b><span style="color: #333333; font-family: "book antiqua" , "serif"; font-size: 16.0pt;"><br /></span></b></div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin-bottom: 0in; mso-line-height-alt: 14.7pt;">
<b><span style="color: #333333; font-family: "book antiqua" , "serif"; font-size: 16.0pt;">Shutdown Hook by annonymous class</span></b></div>
<div class="MsoNormal" style="line-height: 14.7pt; margin-bottom: .0001pt; margin-bottom: 0in;">
<br /></div>
<div style="background: #DBE5F1; border: solid windowtext 1.0pt; mso-background-themecolor: accent1; mso-background-themetint: 51; mso-border-alt: solid windowtext .5pt; mso-element: para-border-div; padding: 1.0pt 4.0pt 1.0pt 4.0pt;">
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: 14.7pt; margin-bottom: 0.0001pt; padding: 0in;">
<span style="color: #7f0055; font-family: "consolas"; mso-bidi-font-weight: bold; mso-fareast-font-family: "Times New Roman";">public</span><span style="color: #333333; font-family: "consolas"; mso-fareast-font-family: "Times New Roman";"> </span><span style="color: #7f0055; font-family: "consolas"; mso-bidi-font-weight: bold; mso-fareast-font-family: "Times New Roman";">class</span><span style="color: #333333; font-family: "consolas"; mso-fareast-font-family: "Times New Roman";"> TestShutDownHookOnFly { </span><span style="color: #333333; font-family: "helvetica" , "sans-serif"; mso-fareast-font-family: "Times New Roman";"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: 14.7pt; margin-bottom: 0.0001pt; padding: 0in;">
<span style="color: #333333; font-family: "consolas"; mso-fareast-font-family: "Times New Roman";"> </span><span style="color: #7f0055; font-family: "consolas"; mso-bidi-font-weight: bold; mso-fareast-font-family: "Times New Roman";">public</span><span style="color: #333333; font-family: "consolas"; mso-fareast-font-family: "Times New Roman";"> </span><span style="color: #7f0055; font-family: "consolas"; mso-bidi-font-weight: bold; mso-fareast-font-family: "Times New Roman";">static</span><span style="color: #333333; font-family: "consolas"; mso-fareast-font-family: "Times New Roman";"> </span><span style="color: #7f0055; font-family: "consolas"; mso-bidi-font-weight: bold; mso-fareast-font-family: "Times New Roman";">void</span><span style="color: #333333; font-family: "consolas"; mso-fareast-font-family: "Times New Roman";"> main(String[] </span><span style="color: #6a3e3e; font-family: "consolas"; mso-fareast-font-family: "Times New Roman";">args</span><span style="color: #333333; font-family: "consolas"; mso-fareast-font-family: "Times New Roman";">)</span><span style="color: #7f0055; font-family: "consolas"; mso-bidi-font-weight: bold; mso-fareast-font-family: "Times New Roman";">throws</span><span style="color: #333333; font-family: "consolas"; mso-fareast-font-family: "Times New Roman";"> Exception { </span><span style="color: #333333; font-family: "helvetica" , "sans-serif"; mso-fareast-font-family: "Times New Roman";"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: 14.7pt; margin-bottom: 0.0001pt; padding: 0in;">
<br /></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: 14.7pt; margin-bottom: 0.0001pt; padding: 0in;">
<span style="color: #333333; font-family: "consolas"; mso-fareast-font-family: "Times New Roman";">
Runtime </span><span style="color: #6a3e3e; font-family: "consolas"; mso-fareast-font-family: "Times New Roman";">runtime</span><span style="color: #333333; font-family: "consolas"; mso-fareast-font-family: "Times New Roman";"> = Runtime.<i>getRuntime</i>(); </span><span style="color: #333333; font-family: "helvetica" , "sans-serif"; mso-fareast-font-family: "Times New Roman";"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: 14.7pt; margin-bottom: 0.0001pt; padding: 0in;">
<span style="color: #333333; font-family: "consolas"; mso-fareast-font-family: "Times New Roman";"> </span><span style="color: #6a3e3e; font-family: "consolas"; mso-fareast-font-family: "Times New Roman";">runtime</span><span style="color: #333333; font-family: "consolas"; mso-fareast-font-family: "Times New Roman";">.addShutdownHook(</span><span style="color: #7f0055; font-family: "consolas"; mso-bidi-font-weight: bold; mso-fareast-font-family: "Times New Roman";">new</span><span style="color: #333333; font-family: "consolas"; mso-fareast-font-family: "Times New Roman";"> Thread()
{ </span><span style="color: #333333; font-family: "helvetica" , "sans-serif"; mso-fareast-font-family: "Times New Roman";"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: 14.7pt; margin-bottom: 0.0001pt; padding: 0in;">
<span style="color: #333333; font-family: "consolas"; mso-fareast-font-family: "Times New Roman";"> </span><span style="color: #7f0055; font-family: "consolas"; mso-bidi-font-weight: bold; mso-fareast-font-family: "Times New Roman";">public</span><span style="color: #333333; font-family: "consolas"; mso-fareast-font-family: "Times New Roman";"> </span><span style="color: #7f0055; font-family: "consolas"; mso-bidi-font-weight: bold; mso-fareast-font-family: "Times New Roman";">void</span><span style="color: #333333; font-family: "consolas"; mso-fareast-font-family: "Times New Roman";"> run()
{ </span><span style="color: #333333; font-family: "helvetica" , "sans-serif"; mso-fareast-font-family: "Times New Roman";"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: 14.7pt; margin-bottom: 0.0001pt; padding: 0in;">
<span style="color: #333333; font-family: "consolas"; mso-fareast-font-family: "Times New Roman";">
System.</span><i><span style="color: #0000c0; font-family: "consolas"; mso-bidi-font-weight: bold; mso-fareast-font-family: "Times New Roman";">out</span></i><span style="color: #333333; font-family: "consolas"; mso-fareast-font-family: "Times New Roman";">.println(</span><span style="color: #2a00ff; font-family: "consolas"; mso-fareast-font-family: "Times New Roman";">"cleanup.. shut down hook task"</span><span style="color: #333333; font-family: "consolas"; mso-fareast-font-family: "Times New Roman";">); </span><span style="color: #333333; font-family: "helvetica" , "sans-serif"; mso-fareast-font-family: "Times New Roman";"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: 14.7pt; margin-bottom: 0.0001pt; padding: 0in;">
<span style="color: #333333; font-family: "consolas"; mso-fareast-font-family: "Times New Roman";">
}}); </span><span style="color: #333333; font-family: "helvetica" , "sans-serif"; mso-fareast-font-family: "Times New Roman";"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: 14.7pt; margin-bottom: 0.0001pt; padding: 0in;">
<br /></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: 14.7pt; margin-bottom: 0.0001pt; padding: 0in;">
<span style="color: #333333; font-family: "consolas"; mso-fareast-font-family: "Times New Roman";">
System.</span><i><span style="color: #0000c0; font-family: "consolas"; mso-bidi-font-weight: bold; mso-fareast-font-family: "Times New Roman";">out</span></i><span style="color: #333333; font-family: "consolas"; mso-fareast-font-family: "Times New Roman";">.println(</span><span style="color: #2a00ff; font-family: "consolas"; mso-fareast-font-family: "Times New Roman";">"Now main sleeping... press ctrl+c to
exit"</span><span style="color: #333333; font-family: "consolas"; mso-fareast-font-family: "Times New Roman";">); </span><span style="color: #333333; font-family: "helvetica" , "sans-serif"; mso-fareast-font-family: "Times New Roman";"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: 14.7pt; margin-bottom: 0.0001pt; padding: 0in;">
<span style="color: #333333; font-family: "consolas"; mso-fareast-font-family: "Times New Roman";"> </span><span style="color: #7f0055; font-family: "consolas"; mso-bidi-font-weight: bold; mso-fareast-font-family: "Times New Roman";">try</span><span style="color: #333333; font-family: "consolas"; mso-fareast-font-family: "Times New Roman";"> {</span><span style="color: #333333; font-family: "helvetica" , "sans-serif"; mso-fareast-font-family: "Times New Roman";"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: 14.7pt; margin-bottom: 0.0001pt; padding: 0in;">
<span style="color: #333333; font-family: "consolas"; mso-fareast-font-family: "Times New Roman";">
Thread.<i>sleep</i>(3000);</span><span style="color: #333333; font-family: "helvetica" , "sans-serif"; mso-fareast-font-family: "Times New Roman";"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: 14.7pt; margin-bottom: 0.0001pt; padding: 0in;">
<span style="color: #333333; font-family: "consolas"; mso-fareast-font-family: "Times New Roman";">
} </span><span style="color: #7f0055; font-family: "consolas"; mso-bidi-font-weight: bold; mso-fareast-font-family: "Times New Roman";">catch</span><span style="color: #333333; font-family: "consolas"; mso-fareast-font-family: "Times New Roman";"> (InterruptedException </span><span style="color: #6a3e3e; font-family: "consolas"; mso-fareast-font-family: "Times New Roman";">e</span><span style="color: #333333; font-family: "consolas"; mso-fareast-font-family: "Times New Roman";">) {</span><span style="color: #333333; font-family: "helvetica" , "sans-serif"; mso-fareast-font-family: "Times New Roman";"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: 14.7pt; margin-bottom: 0.0001pt; padding: 0in;">
<span style="color: #333333; font-family: "consolas"; mso-fareast-font-family: "Times New Roman";">
System.</span><i><span style="color: #0000c0; font-family: "consolas"; mso-bidi-font-weight: bold; mso-fareast-font-family: "Times New Roman";">out</span></i><span style="color: #333333; font-family: "consolas"; mso-fareast-font-family: "Times New Roman";">.println(</span><span style="color: #2a00ff; font-family: "consolas"; mso-fareast-font-family: "Times New Roman";">"Interrupted Exception"</span><span style="color: #333333; font-family: "consolas"; mso-fareast-font-family: "Times New Roman";">);</span><span style="color: #333333; font-family: "helvetica" , "sans-serif"; mso-fareast-font-family: "Times New Roman";"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: 14.7pt; margin-bottom: 0.0001pt; padding: 0in;">
<span style="color: #333333; font-family: "consolas"; mso-fareast-font-family: "Times New Roman";">
} </span><span style="color: #333333; font-family: "helvetica" , "sans-serif"; mso-fareast-font-family: "Times New Roman";"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: 14.7pt; margin-bottom: 0.0001pt; padding: 0in;">
<span style="color: #333333; font-family: "consolas"; mso-fareast-font-family: "Times New Roman";"> }</span><span style="color: #333333; font-family: "helvetica" , "sans-serif"; mso-fareast-font-family: "Times New Roman";"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: 14.7pt; margin-bottom: 0.0001pt; padding: 0in;">
<span style="color: #333333; font-family: "consolas"; mso-fareast-font-family: "Times New Roman";">}</span><span style="color: #333333; font-family: "helvetica" , "sans-serif"; mso-fareast-font-family: "Times New Roman";"><o:p></o:p></span></div>
</div>
</div>
javaexplor03http://www.blogger.com/profile/07455293496498711738noreply@blogger.com0tag:blogger.com,1999:blog-615973148715732292.post-58854951857248705832017-05-25T21:35:00.000-07:002017-05-25T12:18:19.524-07:00Can we execute the java program after calling System.exit(0)<div dir="ltr" style="text-align: left;" trbidi="on">
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<b><span style="font-family: "book antiqua" , "serif"; font-size: 13.0pt;">Approach#1</span></b></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: "book antiqua" , "serif"; font-size: 13.0pt;">Using
ShutdownHook</span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: "book antiqua" , "serif"; font-size: 13.0pt;"><br /></span></div>
<div style="background: #DBE5F1; border: solid windowtext 1.0pt; mso-background-themecolor: accent1; mso-background-themetint: 51; mso-border-alt: solid windowtext .5pt; mso-element: para-border-div; padding: 1.0pt 4.0pt 1.0pt 4.0pt;">
<div class="MsoNormal" style="background-position: initial initial; background-repeat: initial initial; border: none; margin-bottom: 0.0001pt; padding: 0in;">
<span style="color: #7f0055; font-family: "consolas"; font-size: 12.0pt;">class</span><span style="font-family: "consolas"; font-size: 12pt;"> MyThread </span><span style="color: #7f0055; font-family: "consolas"; font-size: 12.0pt;">extends</span><span style="font-family: "consolas"; font-size: 12pt;"> Thread
{ </span><span style="font-family: "consolas"; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-position: initial initial; background-repeat: initial initial; border: none; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: "consolas"; font-size: 12pt;"> </span><span style="color: #7f0055; font-family: "consolas"; font-size: 12.0pt;">public</span><span style="font-family: "consolas"; font-size: 12pt;"> </span><span style="color: #7f0055; font-family: "consolas"; font-size: 12.0pt;">void</span><span style="font-family: "consolas"; font-size: 12pt;"> run()
{ </span><span style="font-family: "consolas"; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-position: initial initial; background-repeat: initial initial; border: none; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: "consolas"; font-size: 12pt;"> System.</span><i><span style="color: #0000c0; font-family: "consolas"; font-size: 12.0pt;">out</span></i><span style="font-family: "consolas"; font-size: 12pt;">.println(</span><span style="color: #2a00ff; font-family: "consolas"; font-size: 12.0pt;">"After System exit call."</span><span style="font-family: "consolas"; font-size: 12pt;">);</span><span style="font-family: "consolas"; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-position: initial initial; background-repeat: initial initial; border: none; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: "consolas"; font-size: 12pt;"> } </span><span style="font-family: "consolas"; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-position: initial initial; background-repeat: initial initial; border: none; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: "consolas"; font-size: 12pt;">} </span><span style="font-family: "consolas"; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-position: initial initial; background-repeat: initial initial; border: none; margin-bottom: 0.0001pt; padding: 0in;">
<br /></div>
<div class="MsoNormal" style="background-position: initial initial; background-repeat: initial initial; border: none; margin-bottom: 0.0001pt; padding: 0in;">
<span style="color: #7f0055; font-family: "consolas"; font-size: 12.0pt;">public</span><span style="font-family: "consolas"; font-size: 12pt;"> </span><span style="color: #7f0055; font-family: "consolas"; font-size: 12.0pt;">class</span><span style="font-family: "consolas"; font-size: 12pt;">
TestSystemExit { </span><span style="font-family: "consolas"; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-position: initial initial; background-repeat: initial initial; border: none; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: "consolas"; font-size: 12pt;"> </span><span style="color: #7f0055; font-family: "consolas"; font-size: 12.0pt;">public</span><span style="font-family: "consolas"; font-size: 12pt;"> </span><span style="color: #7f0055; font-family: "consolas"; font-size: 12.0pt;">static</span><span style="font-family: "consolas"; font-size: 12pt;"> </span><span style="color: #7f0055; font-family: "consolas"; font-size: 12.0pt;">void</span><span style="font-family: "consolas"; font-size: 12pt;">
main(String[] args)</span><span style="color: #7f0055; font-family: "consolas"; font-size: 12.0pt;">throws</span><span style="font-family: "consolas"; font-size: 12pt;"> Exception { </span><span style="font-family: "consolas"; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-position: initial initial; background-repeat: initial initial; border: none; margin-bottom: 0.0001pt; padding: 0in;">
<br /></div>
<div class="MsoNormal" style="background-position: initial initial; background-repeat: initial initial; border: none; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: "consolas"; font-size: 12pt;"> Runtime runtime =
Runtime.<i>getRuntime</i>(); </span><span style="font-family: "consolas"; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-position: initial initial; background-repeat: initial initial; border: none; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: "consolas"; font-size: 12pt;"> </span><span style="font-family: "consolas"; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-position: initial initial; background-repeat: initial initial; border: none; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: "consolas"; font-size: 12pt;"> runtime.addShutdownHook(</span><span style="color: #7f0055; font-family: "consolas"; font-size: 12.0pt;">new</span><span style="font-family: "consolas"; font-size: 12pt;"> MyThread()); </span><span style="font-family: "consolas"; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-position: initial initial; background-repeat: initial initial; border: none; margin-bottom: 0.0001pt; padding: 0in;">
<br /></div>
<div class="MsoNormal" style="background-position: initial initial; background-repeat: initial initial; border: none; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: "consolas"; font-size: 12pt;"> System.</span><i><span style="color: #0000c0; font-family: "consolas"; font-size: 12.0pt;">out</span></i><span style="font-family: "consolas"; font-size: 12pt;">.println(</span><span style="color: #2a00ff; font-family: "consolas"; font-size: 12.0pt;">"Before System exit call."</span><span style="font-family: "consolas"; font-size: 12pt;">);</span><span style="font-family: "consolas"; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-position: initial initial; background-repeat: initial initial; border: none; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: "consolas"; font-size: 12pt;"> System.<i>exit</i>(0); </span><span style="font-family: "consolas"; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-position: initial initial; background-repeat: initial initial; border: none; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: "consolas"; font-size: 12pt;"> </span><span style="font-family: "consolas"; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-position: initial initial; background-repeat: initial initial; border: none; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: "consolas"; font-size: 12pt;"> } </span><span style="font-family: "consolas"; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-position: initial initial; background-repeat: initial initial; border: none; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: "consolas"; font-size: 12pt;">}<o:p></o:p></span></div>
<div class="MsoNormal" style="background-position: initial initial; background-repeat: initial initial; border: none; margin-bottom: 0.0001pt; padding: 0in;">
<b><span style="font-family: "consolas"; font-size: 12pt;">Output:<o:p></o:p></span></b></div>
<div class="MsoNormal" style="background-position: initial initial; background-repeat: initial initial; border: none; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: "consolas"; font-size: 12pt;">Before System exit call.<o:p></o:p></span></div>
<div class="MsoNormal" style="background-position: initial initial; background-repeat: initial initial; border: none; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: "consolas"; font-size: 12pt;">After System exit call.</span></div>
</div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<b><span style="font-family: "book antiqua" , "serif"; font-size: 13.0pt;"><br /></span></b></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<b><span style="font-family: "book antiqua" , "serif"; font-size: 13.0pt;">What is ShutDownHook?<o:p></o:p></span></b></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<b><span style="font-family: "book antiqua" , "serif"; font-size: 13.0pt;">Shutdown Hooks</span></b><span style="font-family: "book antiqua" , "serif"; font-size: 13.0pt;"> are a special construct that allow developers to plug
in a piece of code to be executed when the JVM is shutting down.</span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: "book antiqua" , "serif"; font-size: 13.0pt;"><br /></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<b><span style="font-family: "book antiqua" , "serif"; font-size: 13.0pt;">Approach#2<o:p></o:p></span></b></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: "book antiqua" , "serif"; font-size: 13.0pt;">We
can achieve it by overriding the checkExit method of SecurityManager class.</span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: "book antiqua" , "serif"; font-size: 13.0pt;"><br /></span></div>
<div style="background: #DBE5F1; border: solid windowtext 1.0pt; mso-background-themecolor: accent1; mso-background-themetint: 51; mso-border-alt: solid windowtext .5pt; mso-element: para-border-div; padding: 1.0pt 1.0pt 1.0pt 1.0pt;">
<div class="MsoNormal" style="background-position: initial initial; background-repeat: initial initial; border: none; margin-bottom: 0.0001pt; padding: 0in;">
<span style="color: #7f0055; font-family: "consolas"; font-size: 12.0pt;">import</span><span style="font-family: "consolas"; font-size: 12pt;">
java.security.Permission;</span><span style="font-family: "consolas"; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-position: initial initial; background-repeat: initial initial; border: none; margin-bottom: 0.0001pt; padding: 0in;">
<br /></div>
<div class="MsoNormal" style="background-position: initial initial; background-repeat: initial initial; border: none; margin-bottom: 0.0001pt; padding: 0in;">
<span style="color: #7f0055; font-family: "consolas"; font-size: 12.0pt;">public</span><span style="font-family: "consolas"; font-size: 12pt;"> </span><span style="color: #7f0055; font-family: "consolas"; font-size: 12.0pt;">class</span><span style="font-family: "consolas"; font-size: 12pt;">
SystemExitBreaked {</span><span style="font-family: "consolas"; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-position: initial initial; background-repeat: initial initial; border: none; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: "consolas"; font-size: 12pt;"> </span><span style="color: #7f0055; font-family: "consolas"; font-size: 12.0pt;">public</span><span style="font-family: "consolas"; font-size: 12pt;"> </span><span style="color: #7f0055; font-family: "consolas"; font-size: 12.0pt;">static</span><span style="font-family: "consolas"; font-size: 12pt;"> </span><span style="color: #7f0055; font-family: "consolas"; font-size: 12.0pt;">void</span><span style="font-family: "consolas"; font-size: 12pt;">
main(String[] args) {</span><span style="font-family: "consolas"; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-position: initial initial; background-repeat: initial initial; border: none; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: "consolas"; font-size: 12pt;"> System.<i>setSecurityManager</i>(</span><span style="color: #7f0055; font-family: "consolas"; font-size: 12.0pt;">new</span><span style="font-family: "consolas"; font-size: 12pt;"> SecurityManager()
{</span><span style="font-family: "consolas"; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-position: initial initial; background-repeat: initial initial; border: none; margin-bottom: 0.0001pt; padding: 0in;">
<br /></div>
<div class="MsoNormal" style="background-position: initial initial; background-repeat: initial initial; border: none; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: "consolas"; font-size: 12pt;"> </span><span style="color: #646464; font-family: "consolas"; font-size: 12.0pt;">@Override</span><span style="font-family: "consolas"; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-position: initial initial; background-repeat: initial initial; border: none; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: "consolas"; font-size: 12pt;"> </span><span style="color: #7f0055; font-family: "consolas"; font-size: 12.0pt;">public</span><span style="font-family: "consolas"; font-size: 12pt;"> </span><span style="color: #7f0055; font-family: "consolas"; font-size: 12.0pt;">void</span><span style="font-family: "consolas"; font-size: 12pt;">
checkPermission(Permission perm) {</span><span style="font-family: "consolas"; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-position: initial initial; background-repeat: initial initial; border: none; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: "consolas"; font-size: 12pt;"> }</span><span style="font-family: "consolas"; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-position: initial initial; background-repeat: initial initial; border: none; margin-bottom: 0.0001pt; padding: 0in;">
<br /></div>
<div class="MsoNormal" style="background-position: initial initial; background-repeat: initial initial; border: none; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: "consolas"; font-size: 12pt;"> </span><span style="color: #646464; font-family: "consolas"; font-size: 12.0pt;">@Override</span><span style="font-family: "consolas"; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-position: initial initial; background-repeat: initial initial; border: none; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: "consolas"; font-size: 12pt;"> </span><span style="color: #7f0055; font-family: "consolas"; font-size: 12.0pt;">public</span><span style="font-family: "consolas"; font-size: 12pt;"> </span><span style="color: #7f0055; font-family: "consolas"; font-size: 12.0pt;">void</span><span style="font-family: "consolas"; font-size: 12pt;"> checkExit(</span><span style="color: #7f0055; font-family: "consolas"; font-size: 12.0pt;">int</span><span style="font-family: "consolas"; font-size: 12pt;"> status) {</span><span style="font-family: "consolas"; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-position: initial initial; background-repeat: initial initial; border: none; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: "consolas"; font-size: 12pt;"> </span><span style="color: #3f7f5f; font-family: "consolas"; font-size: 12.0pt;">//throw new SecurityException(); // Line 10</span><span style="font-family: "consolas"; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-position: initial initial; background-repeat: initial initial; border: none; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: "consolas"; font-size: 12pt;"> }</span><span style="font-family: "consolas"; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-position: initial initial; background-repeat: initial initial; border: none; margin-bottom: 0.0001pt; padding: 0in;">
<br /></div>
<div class="MsoNormal" style="background-position: initial initial; background-repeat: initial initial; border: none; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: "consolas"; font-size: 12pt;"> });</span><span style="font-family: "consolas"; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-position: initial initial; background-repeat: initial initial; border: none; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: "consolas"; font-size: 12pt;"> <i>checkSystemExit</i>();</span><span style="font-family: "consolas"; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-position: initial initial; background-repeat: initial initial; border: none; margin-bottom: 0.0001pt; padding: 0in;">
<br /></div>
<div class="MsoNormal" style="background-position: initial initial; background-repeat: initial initial; border: none; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: "consolas"; font-size: 12pt;"> }</span><span style="font-family: "consolas"; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-position: initial initial; background-repeat: initial initial; border: none; margin-bottom: 0.0001pt; padding: 0in;">
<br /></div>
<div class="MsoNormal" style="background-position: initial initial; background-repeat: initial initial; border: none; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: "consolas"; font-size: 12pt;"> </span><span style="color: #7f0055; font-family: "consolas"; font-size: 12.0pt;">public</span><span style="font-family: "consolas"; font-size: 12pt;"> </span><span style="color: #7f0055; font-family: "consolas"; font-size: 12.0pt;">static</span><span style="font-family: "consolas"; font-size: 12pt;"> </span><span style="color: #7f0055; font-family: "consolas"; font-size: 12.0pt;">void</span><span style="font-family: "consolas"; font-size: 12pt;">
checkSystemExit() {</span><span style="font-family: "consolas"; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-position: initial initial; background-repeat: initial initial; border: none; margin-bottom: 0.0001pt; padding: 0in;">
<br /></div>
<div class="MsoNormal" style="background-position: initial initial; background-repeat: initial initial; border: none; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: "consolas"; font-size: 12pt;"> System.</span><i><span style="color: #0000c0; font-family: "consolas"; font-size: 12.0pt;">out</span></i><span style="font-family: "consolas"; font-size: 12pt;">.println(</span><span style="color: #2a00ff; font-family: "consolas"; font-size: 12.0pt;">"Before System.exit(0)"</span><span style="font-family: "consolas"; font-size: 12pt;">);</span><span style="font-family: "consolas"; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-position: initial initial; background-repeat: initial initial; border: none; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: "consolas"; font-size: 12pt;"> </span><span style="color: #7f0055; font-family: "consolas"; font-size: 12.0pt;">try</span><span style="font-family: "consolas"; font-size: 12pt;"> {</span><span style="font-family: "consolas"; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-position: initial initial; background-repeat: initial initial; border: none; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: "consolas"; font-size: 12pt;"> System.<i>exit</i>(0);</span><span style="font-family: "consolas"; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-position: initial initial; background-repeat: initial initial; border: none; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: "consolas"; font-size: 12pt;"> } </span><span style="color: #7f0055; font-family: "consolas"; font-size: 12.0pt;">catch</span><span style="font-family: "consolas"; font-size: 12pt;">
(SecurityException se) {</span><span style="font-family: "consolas"; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-position: initial initial; background-repeat: initial initial; border: none; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: "consolas"; font-size: 12pt;"> System.</span><i><span style="color: #0000c0; font-family: "consolas"; font-size: 12.0pt;">out</span></i><span style="font-family: "consolas"; font-size: 12pt;">.println(</span><span style="color: #2a00ff; font-family: "consolas"; font-size: 12.0pt;">"Inside the catch block !"</span><span style="font-family: "consolas"; font-size: 12pt;">);</span><span style="font-family: "consolas"; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-position: initial initial; background-repeat: initial initial; border: none; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: "consolas"; font-size: 12pt;"> }</span><span style="font-family: "consolas"; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-position: initial initial; background-repeat: initial initial; border: none; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: "consolas"; font-size: 12pt;"> System.</span><i><span style="color: #0000c0; font-family: "consolas"; font-size: 12.0pt;">out</span></i><span style="font-family: "consolas"; font-size: 12pt;">.println(</span><span style="color: #2a00ff; font-family: "consolas"; font-size: 12.0pt;">"After System.exit(0)"</span><span style="font-family: "consolas"; font-size: 12pt;">);</span><span style="font-family: "consolas"; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-position: initial initial; background-repeat: initial initial; border: none; margin-bottom: 0.0001pt; padding: 0in;">
<br /></div>
<div class="MsoNormal" style="background-position: initial initial; background-repeat: initial initial; border: none; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: "consolas"; font-size: 12pt;"> }<o:p></o:p></span></div>
<div class="MsoNormal" style="background-position: initial initial; background-repeat: initial initial; border: none; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: "consolas"; font-size: 12pt;">}</span></div>
<div class="MsoNormal" style="background-position: initial initial; background-repeat: initial initial; border: none; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: "consolas"; font-size: 12pt;"><br /></span></div>
<div class="MsoNormal" style="background-position: initial initial; background-repeat: initial initial; border: none; margin-bottom: 0.0001pt; padding: 0in;">
<b><span style="font-family: "consolas"; font-size: 12pt;">Output:</span></b><span style="font-family: "consolas"; font-size: 12pt;"> Before System.exit(0)</span><span style="font-family: "consolas"; font-size: 10.0pt;"><o:p></o:p></span></div>
</div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: "book antiqua" , serif; font-size: 13pt;"><br /></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: "book antiqua" , serif; font-size: 13pt;">Now
uncomment the line 10 i.e </span><span style="color: red; font-family: "book antiqua" , serif; font-size: 13pt;">throw new SecurityException().</span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: "book antiqua" , "serif"; font-size: 13.0pt;"><span style="color: red;"><br /></span></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: "book antiqua" , serif; font-size: 13pt;">The new output will be: <span style="color: red;"><o:p></o:p></span></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
</div>
<div style="background: #DBE5F1; border: solid windowtext 1.0pt; mso-background-themecolor: accent1; mso-background-themetint: 51; mso-border-alt: solid windowtext .5pt; mso-element: para-border-div; padding: 1.0pt 4.0pt 1.0pt 4.0pt;">
<div class="MsoNormal" style="background-position: initial initial; background-repeat: initial initial; border: none; margin-bottom: 0.0001pt; padding: 0in;">
<b><span style="font-family: "consolas"; font-size: 12pt;">Output:<o:p></o:p></span></b></div>
<div class="MsoNormal" style="background-position: initial initial; background-repeat: initial initial; border: none; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: "consolas"; font-size: 12pt;">Before System.exit(0)<o:p></o:p></span></div>
<div class="MsoNormal" style="background-position: initial initial; background-repeat: initial initial; border: none; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: "consolas"; font-size: 12pt;">Inside the catch block!<o:p></o:p></span></div>
<div class="MsoNormal" style="background-position: initial initial; background-repeat: initial initial; border: none; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: "consolas"; font-size: 12pt;">After System.exit(0)</span></div>
</div>
</div>
javaexplor03http://www.blogger.com/profile/07455293496498711738noreply@blogger.com0tag:blogger.com,1999:blog-615973148715732292.post-35123730151865479102017-05-22T20:36:00.001-07:002017-05-22T20:36:35.435-07:00What are the different types of dependency injections in spring?<div dir="ltr" style="text-align: left;" trbidi="on">
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in;">
<span style="font-family: "Book Antiqua", serif; font-size: 13pt;">Basically, instead of having your objects creating a dependency or asking a factory object to make one for them, you pass the needed dependencies into the object externally, and you make it somebody else's problem. This "someone" is either an object further up the dependency graph, or a dependency injector (framework) that builds the dependency graph.</span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in;">
<b><span style="color: #c00000; font-family: "Book Antiqua","serif"; font-size: 14.0pt; mso-bidi-font-size: 13.0pt;"><br /></span></b></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in;">
<b><span style="color: #c00000; font-family: "Book Antiqua","serif"; font-size: 14.0pt; mso-bidi-font-size: 13.0pt;">Spring supports 2 types of dependency injection</span></b></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in;">
<span style="font-family: "Book Antiqua","serif"; font-size: 13.0pt;">Spring supports two types of dependency Injection, using setter method e.g. setXXX() where XXX is a dependency or via a constructor argument.</span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in;">
<b><span style="color: #c00000; font-family: "Book Antiqua","serif"; font-size: 14.0pt; mso-bidi-font-size: 13.0pt;"><br /></span></b></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in;">
<b><span style="color: #c00000; font-family: "Book Antiqua","serif"; font-size: 14.0pt; mso-bidi-font-size: 13.0pt;">1) Constructor- based dependency injection</span></b></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in;">
<span style="font-family: "Book Antiqua","serif"; font-size: 13.0pt;">It is accomplished when the container invokes a class constructor with a number of arguments, each representing a dependency on other class.</span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in;">
<b><span style="color: #c00000; font-family: "Book Antiqua","serif"; font-size: 14.0pt; mso-bidi-font-size: 13.0pt;"><br /></span></b></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in;">
<b><span style="color: #c00000; font-family: "Book Antiqua","serif"; font-size: 14.0pt; mso-bidi-font-size: 13.0pt;">2) Setter-based dependency injection</span></b></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in;">
<span style="font-family: "Book Antiqua","serif"; font-size: 13.0pt;">It is accomplished by the container calling setter methods on your beans after invoking a no-argument constructor or no-argument static factory method to instantiate your bean.</span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in;">
<b><span style="color: #c00000; font-family: "Book Antiqua","serif"; font-size: 14.0pt; mso-bidi-font-size: 13.0pt;"><br /></span></b></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in;">
<b><span style="color: #c00000; font-family: "Book Antiqua","serif"; font-size: 14.0pt; mso-bidi-font-size: 13.0pt;">Spring Setter vs. Constructor Injection</span></b></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in;">
<b><span style="color: #c00000; font-family: "Book Antiqua","serif"; font-size: 14.0pt; mso-bidi-font-size: 13.0pt;">1. Partial dependency:</span></b><span style="font-family: "Book Antiqua","serif"; font-size: 13.0pt;"> Partial dependency can be injected using setter injection but it is not possible by the constructor. Suppose there are 4 properties in a class, having 4 arguments constructor and setters methods. In such case, if you want to pass information to only one property, it is possible by setter method only.<o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in;">
<br /></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in;">
<b><span style="color: #c00000; font-family: "Book Antiqua","serif"; font-size: 14.0pt; mso-bidi-font-size: 13.0pt;">2. Overriding:</span></b><span style="font-family: "Book Antiqua","serif"; font-size: 13.0pt;"> Setter injection overrides the constructor injection. If we use constructor and setter injection, IOC container will use the setter injection.</span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in;">
<span style="font-family: "Book Antiqua","serif"; font-size: 13.0pt;"><br /></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in;">
<b><span style="color: #c00000; font-family: "Book Antiqua","serif"; font-size: 14.0pt; mso-bidi-font-size: 13.0pt;">3. Changes:</span></b><span style="font-family: "Book Antiqua","serif"; font-size: 13.0pt;"> We can easily change the value by setter injection. It doesn't create a new bean instance always like a constructor. So setter injection is flexible than constructor injection.</span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in;">
<span style="font-family: "Book Antiqua","serif"; font-size: 13.0pt;"><br /></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in;">
<b><span style="color: #c00000; font-family: "Book Antiqua","serif"; font-size: 14.0pt; mso-bidi-font-size: 13.0pt;">4.</span></b><span style="font-family: "Book Antiqua","serif"; font-size: 13.0pt;"> Because of using setter method, setter Injection in more readable than constructor injection in Spring configuration file usually applicationContext.xml.</span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in;">
<span style="font-family: "Book Antiqua","serif"; font-size: 13.0pt;"><br /></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in;">
<b><span style="color: #c00000; font-family: "Book Antiqua","serif"; font-size: 14.0pt; mso-bidi-font-size: 13.0pt;">5.</span></b><span style="font-family: "Book Antiqua","serif"; font-size: 13.0pt;"> There is one drawback of setter Injection is Security. By using setter injection, we can override certain dependency which is not possible which is not possible with constructor injection because every time we call the constructor, a new object is gets created.</span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in;">
<b><span style="color: #c00000; font-family: "Book Antiqua","serif"; font-size: 14.0pt; mso-bidi-font-size: 13.0pt;"><br /></span></b></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in;">
<b><span style="color: #c00000; font-family: "Book Antiqua","serif"; font-size: 14.0pt; mso-bidi-font-size: 13.0pt;">6.</span></b><span style="font-family: "Book Antiqua", serif; font-size: 13pt;"> Setter and Constructor injection in Spring, where later can help if there is a circular dependency between two object A and B.</span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in;">
<b><span style="color: #c00000; font-family: "Book Antiqua","serif"; font-size: 14.0pt; mso-bidi-font-size: 13.0pt;"><br /></span></b></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in;">
<b><span style="color: #c00000; font-family: "Book Antiqua","serif"; font-size: 14.0pt; mso-bidi-font-size: 13.0pt;">When to use Setter Injection over Constructor Injection in Spring?</span></b></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in;">
<span style="font-family: "Book Antiqua","serif"; font-size: 13.0pt;">Setter Injection has upper hand over Constructor Injection in terms of readability. Since for configuring Spring, we use XML files, readability is a much bigger concern. Also, the drawback of setter Injection around ensuring mandatory dependency injected or not can be handled by configuring Spring to check dependency using "dependency-check" attribute of the tag.</span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in;">
<b><span style="font-family: "Book Antiqua","serif"; font-size: 13.0pt;"><br /></span></b></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in;">
<b><span style="font-family: "Book Antiqua","serif"; font-size: 13.0pt;">Once the number of dependencies crossed a threshold e.g. 5 or 6 its handy manageable to passing dependency via the constructor. Setter Injection is preferred choice when the number of dependencies to be injected is a lot more than normal, if some of those arguments are optional than using Builder design pattern is also a good option.</span></b></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in;">
<b><span style="font-family: "Book Antiqua","serif"; font-size: 13.0pt;"><br /></span></b></div>
</div>
javaexplor03http://www.blogger.com/profile/07455293496498711738noreply@blogger.com0tag:blogger.com,1999:blog-615973148715732292.post-72274868523445541962017-05-20T20:50:00.000-07:002017-05-20T20:50:11.802-07:00Semaphores Using Java<div dir="ltr" style="text-align: left;" trbidi="on">
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in;">
<br /></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in;">
<span style="font-family: Consolas; font-size: 13.0pt;">public class Semaphore extends Object implements Serializable<o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in;">
<br /></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in;">
<span style="font-family: "Book Antiqua","serif"; font-size: 13.0pt;">Counting Semaphore maintains a specified number of pass or permits. In order to access a shared resource, Current Thread must acquire a permit. If the permit is already exhausted by other thread then it can wait until a permit is available due to a release of a permit from a different thread.<o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in;">
<br /></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in;">
<span style="font-family: "Book Antiqua","serif"; font-size: 13.0pt;">Semaphores are often used to restrict the number of threads than can access some (physical or logical) resource.<o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in;">
<br /></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in;">
<span style="font-family: "Book Antiqua","serif"; font-size: 13.0pt;">This concurrency utility can be very useful to implement producer-consumer design pattern or <b>implement bounded pool or resources like Thread Pool, DB Connection pool etc</b>.<o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in;">
<br /></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in;">
<span style="font-family: "Book Antiqua","serif"; font-size: 13.0pt;">java.util.concurrent.Semaphore class represent a Counting semaphore which is initialized with a number of permits. It provides two main methods <b>acquire()</b> and <b>release()</b> for getting permits and releasing permits.<o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in;">
<br /></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in;">
<b><span style="color: #c00000; font-family: "Book Antiqua","serif"; font-size: 13.0pt;">acquire()</span></b><span style="font-family: "Book Antiqua","serif"; font-size: 13.0pt;"> method blocks until the permit is available. Semaphore provides both blocking methods as well as unblocking method to acquire permits.<o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in;">
<b><span style="color: #c00000; font-family: "Book Antiqua","serif"; font-size: 13.0pt;">release()</span></b><span style="color: #c00000; font-family: "Book Antiqua","serif"; font-size: 13.0pt;"> </span><span style="font-family: "Book Antiqua","serif"; font-size: 13.0pt;">adds a permit, potentially releasing a blocking acquirer.<o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in;">
<br /></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in;">
<b><span style="color: #c00000; font-family: "Book Antiqua","serif"; font-size: 16.0pt; mso-bidi-font-size: 13.0pt;">Some Scenario where Semaphore is useful<o:p></o:p></span></b></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in;">
<span style="font-family: "Book Antiqua","serif"; font-size: 13.0pt;">1) To implement better Database connection pooling which will block if no more connection is available instead of failing and handover Connection as soon as it’s available.<o:p></o:p></span></div>
<div style="background: #C6D9F1; border: solid windowtext 1.0pt; mso-background-themecolor: text2; mso-background-themetint: 51; mso-border-alt: solid windowtext .5pt; mso-element: para-border-div; padding: 1.0pt 1.0pt 1.0pt 1.0pt;">
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="color: #7f0055; font-family: Consolas; font-size: 12.0pt; mso-bidi-font-weight: bold;">import</span><span style="font-family: Consolas; font-size: 12pt;"> java.io.IOException;</span><span style="font-family: Consolas; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="color: #7f0055; font-family: Consolas; font-size: 12.0pt; mso-bidi-font-weight: bold;">import</span><span style="font-family: Consolas; font-size: 12pt;"> java.net.MalformedURLException;</span><span style="font-family: Consolas; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="color: #7f0055; font-family: Consolas; font-size: 12.0pt; mso-bidi-font-weight: bold;">import</span><span style="font-family: Consolas; font-size: 12pt;"> java.net.URL;</span><span style="font-family: Consolas; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="color: #7f0055; font-family: Consolas; font-size: 12.0pt; mso-bidi-font-weight: bold;">import</span><span style="font-family: Consolas; font-size: 12pt;"> java.net.URLConnection;</span><span style="font-family: Consolas; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="color: #7f0055; font-family: Consolas; font-size: 12.0pt; mso-bidi-font-weight: bold;">import</span><span style="font-family: Consolas; font-size: 12pt;"> java.util.concurrent.Semaphore;</span><span style="font-family: Consolas; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<br /></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="color: #3f5fbf; font-family: Consolas; font-size: 12.0pt;">/**</span><span style="font-family: Consolas; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="color: #3f5fbf; font-family: Consolas; font-size: 12.0pt;"> * Limit Maximum number of URL connection allowed through Counting Semaphore</span><span style="font-family: Consolas; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="color: #3f5fbf; font-family: Consolas; font-size: 12.0pt;"> * </span><span style="color: #7f9fbf; font-family: Consolas; font-size: 12.0pt; mso-bidi-font-weight: bold;">@author</span><span style="color: #3f5fbf; font-family: Consolas; font-size: 12.0pt;"> Rajesh Dixit</span><span style="font-family: Consolas; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="color: #3f5fbf; font-family: Consolas; font-size: 12.0pt;"> */</span><span style="font-family: Consolas; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="color: #7f0055; font-family: Consolas; font-size: 12.0pt; mso-bidi-font-weight: bold;">class</span><span style="font-family: Consolas; font-size: 12pt;"> URLConnectionManager {</span><span style="font-family: Consolas; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: Consolas; font-size: 12pt;"> </span><span style="color: #7f0055; font-family: Consolas; font-size: 12.0pt; mso-bidi-font-weight: bold;">private</span><span style="font-family: Consolas; font-size: 12pt;"> </span><span style="color: #7f0055; font-family: Consolas; font-size: 12.0pt; mso-bidi-font-weight: bold;">final</span><span style="font-family: Consolas; font-size: 12pt;"> Semaphore </span><span style="color: #0000c0; font-family: Consolas; font-size: 12.0pt;">semaphore</span><span style="font-family: Consolas; font-size: 12pt;">;</span><span style="font-family: Consolas; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: Consolas; font-size: 12pt;"> </span><span style="color: #7f0055; font-family: Consolas; font-size: 12.0pt; mso-bidi-font-weight: bold;">private</span><span style="font-family: Consolas; font-size: 12pt;"> </span><span style="color: #7f0055; font-family: Consolas; font-size: 12.0pt; mso-bidi-font-weight: bold;">final</span><span style="font-family: Consolas; font-size: 12pt;"> </span><span style="color: #7f0055; font-family: Consolas; font-size: 12.0pt; mso-bidi-font-weight: bold;">int</span><span style="font-family: Consolas; font-size: 12pt;"> </span><span style="color: #0000c0; font-family: Consolas; font-size: 12.0pt;">DEFAULT_ALLOWEED</span><span style="font-family: Consolas; font-size: 12pt;"> = 10;</span><span style="font-family: Consolas; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<br /></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: Consolas; font-size: 12pt;"> URLConnectionManager(</span><span style="color: #7f0055; font-family: Consolas; font-size: 12.0pt; mso-bidi-font-weight: bold;">int</span><span style="font-family: Consolas; font-size: 12pt;"> </span><span style="color: #6a3e3e; font-family: Consolas; font-size: 12.0pt;">maxConcurrentRequests</span><span style="font-family: Consolas; font-size: 12pt;">) {</span><span style="font-family: Consolas; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: Consolas; font-size: 12pt;"> </span><span style="color: #0000c0; font-family: Consolas; font-size: 12.0pt;">semaphore</span><span style="font-family: Consolas; font-size: 12pt;"> = </span><span style="color: #7f0055; font-family: Consolas; font-size: 12.0pt; mso-bidi-font-weight: bold;">new</span><span style="font-family: Consolas; font-size: 12pt;"> Semaphore(</span><span style="color: #6a3e3e; font-family: Consolas; font-size: 12.0pt;">maxConcurrentRequests</span><span style="font-family: Consolas; font-size: 12pt;">);</span><span style="font-family: Consolas; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: Consolas; font-size: 12pt;"> }</span><span style="font-family: Consolas; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<br /></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: Consolas; font-size: 12pt;"> URLConnectionManager() {</span><span style="font-family: Consolas; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: Consolas; font-size: 12pt;"> </span><span style="color: #0000c0; font-family: Consolas; font-size: 12.0pt;">semaphore</span><span style="font-family: Consolas; font-size: 12pt;"> = </span><span style="color: #7f0055; font-family: Consolas; font-size: 12.0pt; mso-bidi-font-weight: bold;">new</span><span style="font-family: Consolas; font-size: 12pt;"> Semaphore(</span><span style="color: #0000c0; font-family: Consolas; font-size: 12.0pt;">DEFAULT_ALLOWEED</span><span style="font-family: Consolas; font-size: 12pt;">);</span><span style="font-family: Consolas; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: Consolas; font-size: 12pt;"> }</span><span style="font-family: Consolas; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<br /></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: Consolas; font-size: 12pt;"> </span><span style="color: #7f0055; font-family: Consolas; font-size: 12.0pt; mso-bidi-font-weight: bold;">public</span><span style="font-family: Consolas; font-size: 12pt;"> URLConnection acquire(URL </span><span style="color: #6a3e3e; font-family: Consolas; font-size: 12.0pt;">url</span><span style="font-family: Consolas; font-size: 12pt;">) </span><span style="color: #7f0055; font-family: Consolas; font-size: 12.0pt; mso-bidi-font-weight: bold;">throws</span><span style="font-family: Consolas; font-size: 12pt;"> InterruptedException, IOException {</span><span style="font-family: Consolas; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: Consolas; font-size: 12pt;"> </span><span style="color: #0000c0; font-family: Consolas; font-size: 12.0pt;">semaphore</span><span style="font-family: Consolas; font-size: 12pt;">.acquire();</span><span style="font-family: Consolas; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: Consolas; font-size: 12pt;"> </span><span style="color: #7f0055; font-family: Consolas; font-size: 12.0pt; mso-bidi-font-weight: bold;">return</span><span style="font-family: Consolas; font-size: 12pt;"> URLConnectionManager.<i>openConnection</i>(</span><span style="color: #6a3e3e; font-family: Consolas; font-size: 12.0pt;">url</span><span style="font-family: Consolas; font-size: 12pt;">);</span><span style="font-family: Consolas; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: Consolas; font-size: 12pt;"> }</span><span style="font-family: Consolas; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<br /></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: Consolas; font-size: 12pt;"> </span><span style="color: #7f0055; font-family: Consolas; font-size: 12.0pt; mso-bidi-font-weight: bold;">private</span><span style="font-family: Consolas; font-size: 12pt;"> </span><span style="color: #7f0055; font-family: Consolas; font-size: 12.0pt; mso-bidi-font-weight: bold;">static</span><span style="font-family: Consolas; font-size: 12pt;"> URLConnection openConnection(URL </span><span style="color: #6a3e3e; font-family: Consolas; font-size: 12.0pt;">url</span><span style="font-family: Consolas; font-size: 12pt;">) </span><span style="color: #7f0055; font-family: Consolas; font-size: 12.0pt; mso-bidi-font-weight: bold;">throws</span><span style="font-family: Consolas; font-size: 12pt;"> IOException {</span><span style="font-family: Consolas; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: Consolas; font-size: 12pt;"> System.</span><i><span style="color: #0000c0; font-family: Consolas; font-size: 12.0pt; mso-bidi-font-weight: bold;">out</span></i><span style="font-family: Consolas; font-size: 12pt;">.println(</span><span style="color: #2a00ff; font-family: Consolas; font-size: 12.0pt;">"open connection - START!!"</span><span style="font-family: Consolas; font-size: 12pt;">);</span><span style="font-family: Consolas; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<br /></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: Consolas; font-size: 12pt;"> URLConnection </span><span style="color: #6a3e3e; font-family: Consolas; font-size: 12.0pt;">urlConnection</span><span style="font-family: Consolas; font-size: 12pt;"> = </span><span style="color: #6a3e3e; font-family: Consolas; font-size: 12.0pt;">url</span><span style="font-family: Consolas; font-size: 12pt;">==</span><span style="color: #7f0055; font-family: Consolas; font-size: 12.0pt; mso-bidi-font-weight: bold;">null</span><span style="font-family: Consolas; font-size: 12pt;">?</span><span style="color: #6a3e3e; font-family: Consolas; font-size: 12.0pt;">url</span><span style="font-family: Consolas; font-size: 12pt;">.openConnection():</span><span style="color: #7f0055; font-family: Consolas; font-size: 12.0pt; mso-bidi-font-weight: bold;">null</span><span style="font-family: Consolas; font-size: 12pt;">;</span><span style="font-family: Consolas; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<br /></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: Consolas; font-size: 12pt;"> System.</span><i><span style="color: #0000c0; font-family: Consolas; font-size: 12.0pt; mso-bidi-font-weight: bold;">out</span></i><span style="font-family: Consolas; font-size: 12pt;">.println(</span><span style="color: #2a00ff; font-family: Consolas; font-size: 12.0pt;">"open connection - END!!"</span><span style="font-family: Consolas; font-size: 12pt;">);</span><span style="font-family: Consolas; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: Consolas; font-size: 12pt;"> </span><span style="color: #7f0055; font-family: Consolas; font-size: 12.0pt; mso-bidi-font-weight: bold;">return</span><span style="font-family: Consolas; font-size: 12pt;"> </span><span style="color: #6a3e3e; font-family: Consolas; font-size: 12.0pt;">urlConnection</span><span style="font-family: Consolas; font-size: 12pt;">;</span><span style="font-family: Consolas; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: Consolas; font-size: 12pt;"> }</span><span style="font-family: Consolas; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<br /></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: Consolas; font-size: 12pt;"> </span><span style="color: #7f0055; font-family: Consolas; font-size: 12.0pt; mso-bidi-font-weight: bold;">public</span><span style="font-family: Consolas; font-size: 12pt;"> </span><span style="color: #7f0055; font-family: Consolas; font-size: 12.0pt; mso-bidi-font-weight: bold;">void</span><span style="font-family: Consolas; font-size: 12pt;"> release(URLConnection </span><span style="color: #6a3e3e; font-family: Consolas; font-size: 12.0pt;">conn</span><span style="font-family: Consolas; font-size: 12pt;">) </span><span style="color: #7f0055; font-family: Consolas; font-size: 12.0pt; mso-bidi-font-weight: bold;">throws</span><span style="font-family: Consolas; font-size: 12pt;"> InterruptedException {</span><span style="font-family: Consolas; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: Consolas; font-size: 12pt;"> </span><span style="color: #7f0055; font-family: Consolas; font-size: 12.0pt; mso-bidi-font-weight: bold;">try</span><span style="font-family: Consolas; font-size: 12pt;"> {</span><span style="font-family: Consolas; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: Consolas; font-size: 12pt;"> Thread.<i>sleep</i>(200);</span><span style="font-family: Consolas; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: Consolas; font-size: 12pt;"> </span><span style="color: #3f7f5f; font-family: Consolas; font-size: 12.0pt;">// clean up activity if required</span><span style="font-family: Consolas; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: Consolas; font-size: 12pt;"> System.</span><i><span style="color: #0000c0; font-family: Consolas; font-size: 12.0pt; mso-bidi-font-weight: bold;">out</span></i><span style="font-family: Consolas; font-size: 12pt;">.println(</span><span style="color: #2a00ff; font-family: Consolas; font-size: 12.0pt;">"Release the URL !!"</span><span style="font-family: Consolas; font-size: 12pt;">);</span><span style="font-family: Consolas; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: Consolas; font-size: 12pt;"> } </span><span style="color: #7f0055; font-family: Consolas; font-size: 12.0pt; mso-bidi-font-weight: bold;">finally</span><span style="font-family: Consolas; font-size: 12pt;"> {</span><span style="font-family: Consolas; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: Consolas; font-size: 12pt;"> </span><span style="color: #0000c0; font-family: Consolas; font-size: 12.0pt;">semaphore</span><span style="font-family: Consolas; font-size: 12pt;">.release();</span><span style="font-family: Consolas; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: Consolas; font-size: 12pt;"> }</span><span style="font-family: Consolas; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: Consolas; font-size: 12pt;"> }</span><span style="font-family: Consolas; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: Consolas; font-size: 12pt;">}</span><span style="font-family: Consolas; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<br /></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<br /></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="color: #7f0055; font-family: Consolas; font-size: 12.0pt; mso-bidi-font-weight: bold;">public</span><span style="font-family: Consolas; font-size: 12pt;"> </span><span style="color: #7f0055; font-family: Consolas; font-size: 12.0pt; mso-bidi-font-weight: bold;">class</span><span style="font-family: Consolas; font-size: 12pt;"> TestURLManager {</span><span style="font-family: Consolas; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: Consolas; font-size: 12pt;"> </span><span style="color: #7f0055; font-family: Consolas; font-size: 12.0pt; mso-bidi-font-weight: bold;">public</span><span style="font-family: Consolas; font-size: 12pt;"> </span><span style="color: #7f0055; font-family: Consolas; font-size: 12.0pt; mso-bidi-font-weight: bold;">static</span><span style="font-family: Consolas; font-size: 12pt;"> </span><span style="color: #7f0055; font-family: Consolas; font-size: 12.0pt; mso-bidi-font-weight: bold;">void</span><span style="font-family: Consolas; font-size: 12pt;"> main(String[] </span><span style="color: #6a3e3e; font-family: Consolas; font-size: 12.0pt;">args</span><span style="font-family: Consolas; font-size: 12pt;">) </span><span style="color: #7f0055; font-family: Consolas; font-size: 12.0pt; mso-bidi-font-weight: bold;">throws</span><span style="font-family: Consolas; font-size: 12pt;"> MalformedURLException, InterruptedException, IOException {</span><span style="font-family: Consolas; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: Consolas; font-size: 12pt;"> URLConnectionManager </span><span style="color: #6a3e3e; font-family: Consolas; font-size: 12.0pt;">manager</span><span style="font-family: Consolas; font-size: 12pt;"> = </span><span style="color: #7f0055; font-family: Consolas; font-size: 12.0pt; mso-bidi-font-weight: bold;">new</span><span style="font-family: Consolas; font-size: 12pt;"> URLConnectionManager(3);</span><span style="font-family: Consolas; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: Consolas; font-size: 12pt;"> </span><span style="color: #7f0055; font-family: Consolas; font-size: 12.0pt; mso-bidi-font-weight: bold;">for</span><span style="font-family: Consolas; font-size: 12pt;"> (</span><span style="color: #7f0055; font-family: Consolas; font-size: 12.0pt; mso-bidi-font-weight: bold;">int</span><span style="font-family: Consolas; font-size: 12pt;"> </span><span style="color: #6a3e3e; font-family: Consolas; font-size: 12.0pt;">i</span><span style="font-family: Consolas; font-size: 12pt;"> = 0; </span><span style="color: #6a3e3e; font-family: Consolas; font-size: 12.0pt;">i</span><span style="font-family: Consolas; font-size: 12pt;"> < 10; </span><span style="color: #6a3e3e; font-family: Consolas; font-size: 12.0pt;">i</span><span style="font-family: Consolas; font-size: 12pt;">++) {</span><span style="font-family: Consolas; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: Consolas; font-size: 12pt;"> </span><span style="color: #6a3e3e; font-family: Consolas; font-size: 12.0pt;">manager</span><span style="font-family: Consolas; font-size: 12pt;">.acquire(</span><span style="color: #7f0055; font-family: Consolas; font-size: 12.0pt; mso-bidi-font-weight: bold;">new</span><span style="font-family: Consolas; font-size: 12pt;"> URL(</span><span style="color: #2a00ff; font-family: Consolas; font-size: 12.0pt;">"http:\\www.google.com"</span><span style="font-family: Consolas; font-size: 12pt;">));</span><span style="font-family: Consolas; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: Consolas; font-size: 12pt;"> }</span><span style="font-family: Consolas; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<br /></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: Consolas; font-size: 12pt;"> }</span><span style="font-family: Consolas; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: Consolas; font-size: 12pt;">}</span><span style="font-family: "Book Antiqua","serif"; font-size: 12.0pt;"><o:p></o:p></span></div>
</div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in;">
<span style="font-family: "Book Antiqua","serif"; font-size: 13.0pt;">In above case; semaphore maintains a set of permits or pass. <b>semaphore.acquire()</b> method blocks if necessary until the permit is available and then takes it and each <b>semaphore.release()</b> adds/returns a permit.<o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in;">
<br /></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in;">
<b><span style="color: #00b050; font-family: "Book Antiqua","serif"; font-size: 13.0pt;">Semaphore is like a gatekeeper which keeps track of the number of visitors allowed in a building.<o:p></o:p></span></b></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in;">
<br /></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in;">
<span style="font-family: "Book Antiqua","serif"; font-size: 13.0pt;">2) To put a bound on collection classes. By using semaphore you can implement bounded collection whose bound is specified by counting semaphore.<o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<br /></div>
<div style="background: #C6D9F1; border: solid windowtext 1.0pt; mso-background-themecolor: text2; mso-background-themetint: 51; mso-border-alt: solid windowtext .5pt; mso-element: para-border-div; padding: 1.0pt 1.0pt 1.0pt 1.0pt;">
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="color: #7f0055; font-family: Consolas; font-size: 12.0pt; mso-bidi-font-weight: bold;">import</span><span style="font-family: Consolas; font-size: 12pt;"> java.util.Collections;</span><span style="font-family: Consolas; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="color: #7f0055; font-family: Consolas; font-size: 12.0pt; mso-bidi-font-weight: bold;">import</span><span style="font-family: Consolas; font-size: 12pt;"> java.util.LinkedList;</span><span style="font-family: Consolas; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="color: #7f0055; font-family: Consolas; font-size: 12.0pt; mso-bidi-font-weight: bold;">import</span><span style="font-family: Consolas; font-size: 12pt;"> java.util.List;</span><span style="font-family: Consolas; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="color: #7f0055; font-family: Consolas; font-size: 12.0pt; mso-bidi-font-weight: bold;">import</span><span style="font-family: Consolas; font-size: 12pt;"> java.util.concurrent.Semaphore;</span><span style="font-family: Consolas; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="color: #7f0055; font-family: Consolas; font-size: 12.0pt; mso-bidi-font-weight: bold;">import</span><span style="font-family: Consolas; font-size: 12pt;"> java.util.concurrent.TimeUnit;</span><span style="font-family: Consolas; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<br /></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="color: #3f5fbf; font-family: Consolas; font-size: 12.0pt;">/**</span><span style="font-family: Consolas; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="color: #3f5fbf; font-family: Consolas; font-size: 12.0pt;"> * Bounded List using Semaphore. </span><span style="font-family: Consolas; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="color: #3f5fbf; font-family: Consolas; font-size: 12.0pt;"> * </span><span style="color: #7f9fbf; font-family: Consolas; font-size: 12.0pt; mso-bidi-font-weight: bold;">@author</span><span style="color: #3f5fbf; font-family: Consolas; font-size: 12.0pt;"> Rajesh dixit</span><span style="font-family: Consolas; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="color: #3f5fbf; font-family: Consolas; font-size: 12.0pt;"> */</span><span style="font-family: Consolas; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="color: #7f0055; font-family: Consolas; font-size: 12.0pt; mso-bidi-font-weight: bold;">public</span><span style="font-family: Consolas; font-size: 12pt;"> </span><span style="color: #7f0055; font-family: Consolas; font-size: 12.0pt; mso-bidi-font-weight: bold;">class</span><span style="font-family: Consolas; font-size: 12pt;"> BoundedLinkedList<T> {</span><span style="font-family: Consolas; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: Consolas; font-size: 12pt;"> </span><span style="font-family: Consolas; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: Consolas; font-size: 12pt;"> </span><span style="color: #7f0055; font-family: Consolas; font-size: 12.0pt; mso-bidi-font-weight: bold;">private</span><span style="font-family: Consolas; font-size: 12pt;"> List<T> </span><span style="color: #0000c0; font-family: Consolas; font-size: 12.0pt;">list</span><span style="font-family: Consolas; font-size: 12pt;">;</span><span style="font-family: Consolas; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: Consolas; font-size: 12pt;"> </span><span style="color: #7f0055; font-family: Consolas; font-size: 12.0pt; mso-bidi-font-weight: bold;">private</span><span style="font-family: Consolas; font-size: 12pt;"> Semaphore </span><span style="color: #0000c0; font-family: Consolas; font-size: 12.0pt;">semaphore</span><span style="font-family: Consolas; font-size: 12pt;">;</span><span style="font-family: Consolas; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<br /></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: Consolas; font-size: 12pt;"> </span><span style="color: #7f0055; font-family: Consolas; font-size: 12.0pt; mso-bidi-font-weight: bold;">public</span><span style="font-family: Consolas; font-size: 12pt;"> BoundedLinkedList(</span><span style="color: #7f0055; font-family: Consolas; font-size: 12.0pt; mso-bidi-font-weight: bold;">final</span><span style="font-family: Consolas; font-size: 12pt;"> </span><span style="color: #7f0055; font-family: Consolas; font-size: 12.0pt; mso-bidi-font-weight: bold;">int</span><span style="font-family: Consolas; font-size: 12pt;"> </span><span style="color: #6a3e3e; font-family: Consolas; font-size: 12.0pt;">bound</span><span style="font-family: Consolas; font-size: 12pt;">) {</span><span style="font-family: Consolas; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: Consolas; font-size: 12pt;"> </span><span style="color: #0000c0; font-family: Consolas; font-size: 12.0pt;">list</span><span style="font-family: Consolas; font-size: 12pt;"> = Collections.<i>synchronizedList</i>(</span><span style="color: #7f0055; font-family: Consolas; font-size: 12.0pt; mso-bidi-font-weight: bold;">new</span><span style="font-family: Consolas; font-size: 12pt;"> LinkedList<T>());</span><span style="font-family: Consolas; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: Consolas; font-size: 12pt;"> </span><span style="color: #0000c0; font-family: Consolas; font-size: 12.0pt;">semaphore</span><span style="font-family: Consolas; font-size: 12pt;"> = </span><span style="color: #7f0055; font-family: Consolas; font-size: 12.0pt; mso-bidi-font-weight: bold;">new</span><span style="font-family: Consolas; font-size: 12pt;"> Semaphore(</span><span style="color: #6a3e3e; font-family: Consolas; font-size: 12.0pt;">bound</span><span style="font-family: Consolas; font-size: 12pt;">);</span><span style="font-family: Consolas; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: Consolas; font-size: 12pt;"> }</span><span style="font-family: Consolas; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<br /></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: Consolas; font-size: 12pt;"> </span><span style="color: #7f0055; font-family: Consolas; font-size: 12.0pt; mso-bidi-font-weight: bold;">public</span><span style="font-family: Consolas; font-size: 12pt;"> </span><span style="color: #7f0055; font-family: Consolas; font-size: 12.0pt; mso-bidi-font-weight: bold;">void</span><span style="font-family: Consolas; font-size: 12pt;"> add(T </span><span style="color: #6a3e3e; font-family: Consolas; font-size: 12.0pt;">o</span><span style="font-family: Consolas; font-size: 12pt;">) </span><span style="color: #7f0055; font-family: Consolas; font-size: 12.0pt; mso-bidi-font-weight: bold;">throws</span><span style="font-family: Consolas; font-size: 12pt;"> InterruptedException {</span><span style="font-family: Consolas; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: Consolas; font-size: 12pt;"> </span><span style="color: #0000c0; font-family: Consolas; font-size: 12.0pt;">semaphore</span><span style="font-family: Consolas; font-size: 12pt;">.acquire();</span><span style="font-family: Consolas; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: Consolas; font-size: 12pt;"> </span><span style="color: #0000c0; font-family: Consolas; font-size: 12.0pt;">list</span><span style="font-family: Consolas; font-size: 12pt;">.add(</span><span style="color: #6a3e3e; font-family: Consolas; font-size: 12.0pt;">o</span><span style="font-family: Consolas; font-size: 12pt;">);</span><span style="font-family: Consolas; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: Consolas; font-size: 12pt;"> System.</span><i><span style="color: #0000c0; font-family: Consolas; font-size: 12.0pt; mso-bidi-font-weight: bold;">out</span></i><span style="font-family: Consolas; font-size: 12pt;">.println(</span><span style="color: #2a00ff; font-family: Consolas; font-size: 12.0pt;">" Added element :"</span><span style="font-family: Consolas; font-size: 12pt;">+ </span><span style="color: #6a3e3e; font-family: Consolas; font-size: 12.0pt;">o</span><span style="font-family: Consolas; font-size: 12pt;">);</span><span style="font-family: Consolas; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: Consolas; font-size: 12pt;"> }</span><span style="font-family: Consolas; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<br /></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: Consolas; font-size: 12pt;"> </span><span style="color: #7f0055; font-family: Consolas; font-size: 12.0pt; mso-bidi-font-weight: bold;">public</span><span style="font-family: Consolas; font-size: 12pt;"> </span><span style="color: #7f0055; font-family: Consolas; font-size: 12.0pt; mso-bidi-font-weight: bold;">void</span><span style="font-family: Consolas; font-size: 12pt;"> remove(T </span><span style="color: #6a3e3e; font-family: Consolas; font-size: 12.0pt;">o</span><span style="font-family: Consolas; font-size: 12pt;">) {</span><span style="font-family: Consolas; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: Consolas; font-size: 12pt;"> </span><span style="color: #7f0055; font-family: Consolas; font-size: 12.0pt; mso-bidi-font-weight: bold;">if</span><span style="font-family: Consolas; font-size: 12pt;"> (</span><span style="color: #0000c0; font-family: Consolas; font-size: 12.0pt;">list</span><span style="font-family: Consolas; font-size: 12pt;">.contains(</span><span style="color: #6a3e3e; font-family: Consolas; font-size: 12.0pt;">o</span><span style="font-family: Consolas; font-size: 12pt;">)) {</span><span style="font-family: Consolas; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: Consolas; font-size: 12pt;"> </span><span style="color: #0000c0; font-family: Consolas; font-size: 12.0pt;">list</span><span style="font-family: Consolas; font-size: 12pt;">.remove(</span><span style="color: #6a3e3e; font-family: Consolas; font-size: 12.0pt;">o</span><span style="font-family: Consolas; font-size: 12pt;">);</span><span style="font-family: Consolas; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: Consolas; font-size: 12pt;"> </span><span style="color: #0000c0; font-family: Consolas; font-size: 12.0pt;">semaphore</span><span style="font-family: Consolas; font-size: 12pt;">.release();</span><span style="font-family: Consolas; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: Consolas; font-size: 12pt;"> System.</span><i><span style="color: #0000c0; font-family: Consolas; font-size: 12.0pt; mso-bidi-font-weight: bold;">out</span></i><span style="font-family: Consolas; font-size: 12pt;">.println(</span><span style="color: #2a00ff; font-family: Consolas; font-size: 12.0pt;">" Removed element :"</span><span style="font-family: Consolas; font-size: 12pt;">+ </span><span style="color: #6a3e3e; font-family: Consolas; font-size: 12.0pt;">o</span><span style="font-family: Consolas; font-size: 12pt;">);</span><span style="font-family: Consolas; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: Consolas; font-size: 12pt;"> }</span><span style="font-family: Consolas; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: Consolas; font-size: 12pt;"> }</span><span style="font-family: Consolas; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<br /></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: Consolas; font-size: 12pt;"> </span><span style="color: #3f5fbf; font-family: Consolas; font-size: 12.0pt;">/**</span><span style="font-family: Consolas; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="color: #3f5fbf; font-family: Consolas; font-size: 12.0pt;"> * Test Method</span><span style="font-family: Consolas; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="color: #3f5fbf; font-family: Consolas; font-size: 12.0pt;"> * Adds 6 elements; then waits for 5 seconds; removes one element</span><span style="font-family: Consolas; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="color: #3f5fbf; font-family: Consolas; font-size: 12.0pt;"> */</span><span style="font-family: Consolas; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: Consolas; font-size: 12pt;"> </span><span style="color: #7f0055; font-family: Consolas; font-size: 12.0pt; mso-bidi-font-weight: bold;">public</span><span style="font-family: Consolas; font-size: 12pt;"> </span><span style="color: #7f0055; font-family: Consolas; font-size: 12.0pt; mso-bidi-font-weight: bold;">static</span><span style="font-family: Consolas; font-size: 12pt;"> </span><span style="color: #7f0055; font-family: Consolas; font-size: 12.0pt; mso-bidi-font-weight: bold;">void</span><span style="font-family: Consolas; font-size: 12pt;"> main(String[] </span><span style="color: #6a3e3e; font-family: Consolas; font-size: 12.0pt;">args</span><span style="font-family: Consolas; font-size: 12pt;">) {</span><span style="font-family: Consolas; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: Consolas; font-size: 12pt;"> </span><span style="color: #7f0055; font-family: Consolas; font-size: 12.0pt; mso-bidi-font-weight: bold;">final</span><span style="font-family: Consolas; font-size: 12pt;"> BoundedLinkedList<Integer> </span><span style="color: #6a3e3e; font-family: Consolas; font-size: 12.0pt;">bll</span><span style="font-family: Consolas; font-size: 12pt;"> = </span><span style="color: #7f0055; font-family: Consolas; font-size: 12.0pt; mso-bidi-font-weight: bold;">new</span><span style="font-family: Consolas; font-size: 12pt;"> BoundedLinkedList<>(5);</span><span style="font-family: Consolas; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: Consolas; font-size: 12pt;"> </span><span style="color: #7f0055; font-family: Consolas; font-size: 12.0pt; mso-bidi-font-weight: bold;">new</span><span style="font-family: Consolas; font-size: 12pt;"> Thread(</span><span style="color: #7f0055; font-family: Consolas; font-size: 12.0pt; mso-bidi-font-weight: bold;">new</span><span style="font-family: Consolas; font-size: 12pt;"> Runnable(){</span><span style="font-family: Consolas; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: Consolas; font-size: 12pt;"> </span><span style="color: #7f0055; font-family: Consolas; font-size: 12.0pt; mso-bidi-font-weight: bold;">public</span><span style="font-family: Consolas; font-size: 12pt;"> </span><span style="color: #7f0055; font-family: Consolas; font-size: 12.0pt; mso-bidi-font-weight: bold;">void</span><span style="font-family: Consolas; font-size: 12pt;"> run(){</span><span style="font-family: Consolas; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: Consolas; font-size: 12pt;"> </span><span style="color: #7f0055; font-family: Consolas; font-size: 12.0pt; mso-bidi-font-weight: bold;">for</span><span style="font-family: Consolas; font-size: 12pt;">(</span><span style="color: #7f0055; font-family: Consolas; font-size: 12.0pt; mso-bidi-font-weight: bold;">int</span><span style="font-family: Consolas; font-size: 12pt;"> </span><span style="color: #6a3e3e; font-family: Consolas; font-size: 12.0pt;">i</span><span style="font-family: Consolas; font-size: 12pt;"> = 1; </span><span style="color: #6a3e3e; font-family: Consolas; font-size: 12.0pt;">i</span><span style="font-family: Consolas; font-size: 12pt;"> <= 7; </span><span style="color: #6a3e3e; font-family: Consolas; font-size: 12.0pt;">i</span><span style="font-family: Consolas; font-size: 12pt;">++)</span><span style="font-family: Consolas; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: Consolas; font-size: 12pt;"> </span><span style="color: #7f0055; font-family: Consolas; font-size: 12.0pt; mso-bidi-font-weight: bold;">try</span><span style="font-family: Consolas; font-size: 12pt;"> {</span><span style="font-family: Consolas; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: Consolas; font-size: 12pt;"> </span><span style="color: #6a3e3e; font-family: Consolas; font-size: 12.0pt;">bll</span><span style="font-family: Consolas; font-size: 12pt;">.add(</span><span style="color: #6a3e3e; font-family: Consolas; font-size: 12.0pt;">i</span><span style="font-family: Consolas; font-size: 12pt;">);</span><span style="font-family: Consolas; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: Consolas; font-size: 12pt;"> } </span><span style="color: #7f0055; font-family: Consolas; font-size: 12.0pt; mso-bidi-font-weight: bold;">catch</span><span style="font-family: Consolas; font-size: 12pt;"> (InterruptedException </span><span style="color: #6a3e3e; font-family: Consolas; font-size: 12.0pt;">e</span><span style="font-family: Consolas; font-size: 12pt;">) {</span><span style="font-family: Consolas; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: Consolas; font-size: 12pt;"> </span><span style="color: #6a3e3e; font-family: Consolas; font-size: 12.0pt;">e</span><span style="font-family: Consolas; font-size: 12pt;">.printStackTrace();</span><span style="font-family: Consolas; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: Consolas; font-size: 12pt;"> }</span><span style="font-family: Consolas; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: Consolas; font-size: 12pt;"> }</span><span style="font-family: Consolas; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: Consolas; font-size: 12pt;"> }).start();</span><span style="font-family: Consolas; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<br /></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: Consolas; font-size: 12pt;"> </span><span style="color: #7f0055; font-family: Consolas; font-size: 12.0pt; mso-bidi-font-weight: bold;">try</span><span style="font-family: Consolas; font-size: 12pt;"> {</span><span style="font-family: Consolas; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: Consolas; font-size: 12pt;"> TimeUnit.</span><i><span style="color: #0000c0; font-family: Consolas; font-size: 12.0pt; mso-bidi-font-weight: bold;">SECONDS</span></i><span style="font-family: Consolas; font-size: 12pt;">.sleep(5);</span><span style="font-family: Consolas; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: Consolas; font-size: 12pt;"> } </span><span style="color: #7f0055; font-family: Consolas; font-size: 12.0pt; mso-bidi-font-weight: bold;">catch</span><span style="font-family: Consolas; font-size: 12pt;"> (InterruptedException </span><span style="color: #6a3e3e; font-family: Consolas; font-size: 12.0pt;">e</span><span style="font-family: Consolas; font-size: 12pt;">) {</span><span style="font-family: Consolas; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: Consolas; font-size: 12pt;"> </span><span style="color: #6a3e3e; font-family: Consolas; font-size: 12.0pt;">e</span><span style="font-family: Consolas; font-size: 12pt;">.printStackTrace();</span><span style="font-family: Consolas; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: Consolas; font-size: 12pt;"> } </span><span style="font-family: Consolas; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<br /></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: Consolas; font-size: 12pt;"> </span><span style="color: #6a3e3e; font-family: Consolas; font-size: 12.0pt;">bll</span><span style="font-family: Consolas; font-size: 12pt;">.remove(4);</span><span style="font-family: Consolas; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: Consolas; font-size: 12pt;"> }</span><span style="font-family: Consolas; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: Consolas; font-size: 12pt;">}<o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<b><span style="font-family: Consolas; font-size: 12pt;">Output:<o:p></o:p></span></b></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: Consolas; font-size: 12pt;">Added element :1</span><span style="font-family: Consolas; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: Consolas; font-size: 12pt;">Added element :2</span><span style="font-family: Consolas; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: Consolas; font-size: 12pt;">Added element :3</span><span style="font-family: Consolas; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: Consolas; font-size: 12pt;">Added element :4</span><span style="font-family: Consolas; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: Consolas; font-size: 12pt;">Added element :5</span><span style="font-family: Consolas; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: Consolas; font-size: 12pt;">Removed element :4<o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: Consolas; font-size: 12pt;">Added element :6</span><span style="font-family: Consolas; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<br /></div>
</div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in;">
<br /></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in;">
<br /></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in;">
<b><span style="color: #c00000; font-family: "Book Antiqua","serif"; font-size: 16.0pt; mso-bidi-font-size: 13.0pt;">Important points of Counting Semaphore<o:p></o:p></span></b></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in;">
<span style="font-family: "Book Antiqua","serif"; font-size: 13.0pt;">1. Semaphore class supports various overloaded version of <b>tryAquire()</b> method which acquires the permit from semaphore only if it's available during the time of the call.<o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in;">
<br /></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in;">
<span style="font-family: "Book Antiqua","serif"; font-size: 13.0pt;">2. Another worth noting method from Semaphore is <b>acquireUninterruptibly()</b> which is a blocking call and wait until a permit is available.<o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in;">
<br /></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in;">
<span style="font-family: "Book Antiqua","serif"; font-size: 13.0pt;">3. We should be very careful to make sure that we are releasing after acquire which can be missed due to programming error or any exception.<o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in;">
<br /></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in;">
<span style="font-family: "Book Antiqua","serif"; font-size: 13.0pt;">4. Long held lock can cause starvation <o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in;">
<br /></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in;">
<span style="font-family: "Book Antiqua","serif"; font-size: 13.0pt;">5. release() method doesn't have to be called by the same thread which called acquire. This is an important property that we don't have with a normal mutex in Java.<o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in;">
<br /></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in;">
<span style="font-family: "Book Antiqua","serif"; font-size: 13.0pt;">6. We can increase the number of permits at runtime (we should be careful though). This is because the number of permits in a semaphore is not fixed, and call to release will always increase the number of permits, even if no corresponding acquire call was made.<o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in;">
<br /></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in;">
<b><span style="color: #c00000; font-family: "Book Antiqua","serif"; font-size: 16.0pt; mso-bidi-font-size: 13.0pt;">Binary semaphore<o:p></o:p></span></b></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in;">
<span style="font-family: "Book Antiqua","serif"; font-size: 13.0pt;">A semaphore initialized to one, and which is used such that it only has at most one permit available, <b>can serve as a mutual exclusion lock</b>. <b>This is more commonly known as a binary semaphore because it only has two states: one permit available, or zero permits available. </b>When used in this way, the binary semaphore has the property (unlike many Lock implementations), that the "lock" can be released by a thread other than the owner (as semaphores have no notion of ownership). This can be useful in some specialized contexts, such as deadlock recovery.<o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in;">
<br /></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in;">
<b><span style="color: #c00000; font-family: "Book Antiqua","serif"; font-size: 16.0pt; mso-bidi-font-size: 13.0pt;">Fairness in semaphore<o:p></o:p></span></b></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in;">
<span style="font-family: "Book Antiqua","serif"; font-size: 13.0pt;">The constructor for this class optionally accepts a fairness parameter. When set false, this class makes no guarantees about the order in which threads acquire permits. In particular, barging is permitted, that is, a thread invoking acquire() can be allocated a permit ahead of a thread that has been waiting - logically the new thread places itself at the head of the queue of waiting threads. When fairness is set to true, the semaphore guarantees that threads invoking any of the acquire methods are selected to obtain permits in the order in which their invocation of those methods was processed (first-in-first-out; FIFO). Note that FIFO ordering necessarily applies to specific internal points of execution within these methods. So, it is possible for one thread to invoke acquire before another, but reach the ordering point after the other, and similarly upon return from the method. Also note that the untimed tryAcquire methods do not honor the fairness setting, but will take any permits that are available.<o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in;">
<br /></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in;">
<span style="font-family: "Book Antiqua","serif"; font-size: 13.0pt;">Generally, semaphores used to control resource access should be initialized as fair, to ensure that no thread is starved out from accessing a resource. When using semaphores for other kinds of synchronization control, the throughput advantages of non-fair ordering often outweigh fairness considerations.<o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in;">
<br /></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in;">
<span style="font-family: "Book Antiqua","serif"; font-size: 13.0pt;">This class also provides convenience methods to acquire and release multiple permits at a time. Beware of the increased risk of indefinite postponement when these methods are used without fairness set true.<o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in;">
<br /></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in;">
<b><span style="color: #c00000; font-family: "Book Antiqua","serif"; font-size: 16.0pt; mso-bidi-font-size: 13.0pt;">Memory consistency effects<o:p></o:p></span></b></div>
<br />
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in;">
<span style="font-family: "Book Antiqua","serif"; font-size: 13.0pt;">Actions in a thread prior to calling a "release" method such as release() happen-before actions following a successful "acquire" method such as acquire() in another thread.<o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in;">
<span style="font-family: "Book Antiqua","serif"; font-size: 13.0pt;"><br /></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in;">
<span style="font-family: "Book Antiqua","serif"; font-size: 13.0pt;"><br /></span></div>
</div>
javaexplor03http://www.blogger.com/profile/07455293496498711738noreply@blogger.com0tag:blogger.com,1999:blog-615973148715732292.post-15274341660578727542017-05-18T22:37:00.000-07:002017-05-23T07:51:30.598-07:00What is metaspace in Java?<div dir="ltr" style="text-align: left;" trbidi="on">
<div class="MsoNormal">
<span style="font-family: "book antiqua" , serif; font-size: 13pt; line-height: 115%;">Until Java 7, there was an area in JVM memory called
PermGen, where JVM used to keep its classes. </span><span style="font-family: "book antiqua" , serif; font-size: 17.3333px; line-height: 19.9333px;">In Java 8, </span><span style="font-family: "book antiqua" , serif; font-size: 13pt; line-height: 115%;">Permanent Generation (PermGen) space was completely removed and is </span><b style="font-family: "book antiqua", serif; font-size: 13pt; line-height: 115%;">replaced by a new space called Metaspace</b><span style="font-family: "book antiqua" , serif; font-size: 13pt; line-height: 115%;">.</span></div>
<div class="MsoNormal">
<span style="font-family: "book antiqua" , "serif"; font-size: 13.0pt; line-height: 115%;"><br /></span></div>
<div class="MsoNormal">
<span style="font-family: "book antiqua" , "serif"; font-size: 13.0pt; line-height: 115%;">The consequences of the PermGen removal is that
obviously the PermSize and MaxPermSize JVM arguments are ignored and you will
never get a <span style="color: red;">java.lang.OutOfMemoryError: PermGen error.</span><o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-family: "book antiqua" , "serif"; font-size: 13.0pt; line-height: 115%;"><span style="color: #38761d;"><br /></span></span></div>
<div class="MsoNormal">
<span style="font-family: "book antiqua" , "serif"; font-size: 13.0pt; line-height: 115%;"><i style="font-weight: bold;"><span style="color: #38761d;">Metaspace by default auto increases its size</span></i> (up to
what the underlying OS provides), while PermGen always has a fixed maximum
size. You can set a fixed maximum for Metaspace with JVM parameters, but you
cannot make PermGen auto increase.<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-family: "book antiqua" , "serif"; font-size: 13.0pt; line-height: 115%;"><br /></span></div>
<div class="MsoNormal">
<span style="font-family: "book antiqua" , "serif"; font-size: 13.0pt; line-height: 115%;"><br /></span></div>
<div class="MsoNormal">
<span style="font-family: "book antiqua" , "serif"; font-size: 13.0pt; line-height: 115%;"><a href="http://www.oracle.com/technetwork/java/javase/8-whats-new-2157071.html">http://www.oracle.com/technetwork/java/javase/8-whats-new-2157071.html</a><o:p></o:p></span></div>
<br />
<div class="MsoNormal">
<br /></div>
</div>
javaexplor03http://www.blogger.com/profile/07455293496498711738noreply@blogger.com0tag:blogger.com,1999:blog-615973148715732292.post-51418740038420003762017-05-18T01:21:00.000-07:002017-05-24T13:14:51.836-07:00Object generations - Java heap terminology: young, old and permanent generations?<div dir="ltr" style="text-align: left;" trbidi="on">
<div class="MsoNormal">
<span style="font-family: "book antiqua" , serif; font-size: 13pt; line-height: 19px;">The heap is split into several different sections, called </span><b><span style="font-family: "book antiqua" , serif; font-size: 13pt; line-height: 19px;">generations</span></b><span style="font-family: "book antiqua" , serif; font-size: 13pt; line-height: 19px;">.</span></div>
<div class="MsoNormal">
<span style="font-family: "book antiqua" , serif; font-size: 13pt; line-height: 19px;"><br /></span></div>
<div class="MsoNormal">
<span style="font-family: "book antiqua" , serif; font-size: 13pt; line-height: 19px;">As objects survive more garbage collections, they are promoted into different generations. The older generations are not garbage collected as often. Because these objects have already proven to be longer lived, they are less likely to be garbage collected.</span></div>
<div class="MsoNormal">
<span style="font-family: "book antiqua" , serif; font-size: 13pt; line-height: 19px;"><br /></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: "book antiqua" , serif; font-size: 13pt;"><b>1.</b> Eden Space</span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: "book antiqua" , serif; font-size: 13pt;"><b>2. </b>Survivor Space</span><span style="font-family: "book antiqua" , serif; font-size: 13pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: "book antiqua" , serif; font-size: 13pt;"><b>3.</b> Tenured Generation<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: "book antiqua" , serif; font-size: 13pt;"><b>4. </b>Permanent Generation</span><span style="font-family: "book antiqua" , serif; font-size: 13pt;">, or </span><span style="font-family: "book antiqua" , serif; font-size: 13pt;">PermGen.</span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: "book antiqua" , serif; font-size: 13pt;"><br /></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: "book antiqua" , serif; font-size: 13pt;">When objects are first constructed, they are allocated in the </span><b><span style="font-family: "book antiqua" , serif; font-size: 13pt;">Eden Space</span></b><span style="font-family: "book antiqua" , serif; font-size: 13pt;">. If they survive a garbage collection, they are promoted to </span><b><span style="font-family: "book antiqua" , serif; font-size: 13pt;">Survivor Space</span></b><span style="font-family: "book antiqua" , serif; font-size: 13pt;">, and should they live long enough there, they are allocated to the </span><b><span style="font-family: "book antiqua" , serif; font-size: 13pt;">Tenured Generation</span></b><span style="font-family: "book antiqua" , serif; font-size: 13pt;">. This generation is garbage collected much less frequently.</span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<br /></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: "book antiqua" , serif; font-size: 13pt;">There is also a fourth generation, called the </span><b><span style="font-family: "book antiqua" , serif; font-size: 13pt;">Permanent Generation</span></b><b><span style="font-family: "book antiqua" , serif; font-size: 13pt;">, </span></b><span style="font-family: "book antiqua" , serif; font-size: 13pt;">or<b> </b></span><b><span style="font-family: "book antiqua" , serif; font-size: 13pt;">PermGen</span></b><span style="font-family: "book antiqua" , serif; font-size: 13pt;">. The objects that reside here are not eligible to be garbage collected, and usually contain an immutable state necessary for the JVM to run, such as class definitions and the </span><span style="font-family: "book antiqua" , serif; font-size: 13pt;">String </span><span style="font-family: "book antiqua" , serif; font-size: 13pt;">constant pool.<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<b><span style="font-family: "book antiqua" , serif; font-size: 13pt;"><br /></span></b></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<b><span style="font-family: "book antiqua" , serif; font-size: 16pt;">Note</span></b><b><span style="font-family: "book antiqua" , serif; font-size: 13pt;">:</span></b></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<b><span style="font-family: "book antiqua" , serif; font-size: 13pt;"><span style="color: red;">PermGen</span></span></b><span style="color: red; font-family: "book antiqua" , serif; font-size: 13pt;"> </span><span style="font-family: "book antiqua" , serif; font-size: 13pt;">space is planned to be removed from Java 8 and will be replaced with a new space called <b><span style="color: #00b050;">Metaspace</span></b>, which will be held in native memory.</span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<b><span style="font-family: "book antiqua" , serif; font-size: 16pt;"><br /></span></b></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<b><span style="font-family: "book antiqua" , serif; font-size: 16pt;">Using the PermGen Space</span></b></div>
<br />
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: "book antiqua" , serif; font-size: 13pt;">For most applications, the PermGen area contains traditional class definitions, </span><span style="font-family: "book antiqua" , serif; font-size: 13pt;">String </span><span style="font-family: "book antiqua" , serif; font-size: 13pt;">constants, and not much else. Newer languages running on the JVM, such as Groovy, have the capability to create dynamic class definitions, and when used under load, this can fill up the PermGen space easily. You must be careful when creating many dynamic class definitions, and you may need to tweak the default memory allocation for PermGen space.</span></div>
</div>
javaexplor03http://www.blogger.com/profile/07455293496498711738noreply@blogger.com0tag:blogger.com,1999:blog-615973148715732292.post-12822242350237674842017-05-17T21:49:00.000-07:002017-05-16T10:18:06.365-07:00Hibernate Lazy loading<div dir="ltr" style="text-align: left;" trbidi="on">
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in;">
<br /></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in;">
<span style="font-family: "book antiqua" , "serif"; font-size: 13.0pt;"><b>Lazy loading loads the child objects on demand.</b></span><br />
<span style="font-family: "book antiqua" , serif; font-size: 13pt;"><br /></span> <span style="font-family: "book antiqua" , serif; font-size: 13pt;">We have a parent and that parent has a collection of children. Using "lazy-load" concept, all children will not load while loading the parent. Instead, it loads them when requested to do so.</span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in;">
<span style="font-family: "book antiqua" , serif; font-size: 13pt;"><br /></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in;">
<span style="font-family: "book antiqua" , serif; font-size: 17.3333px;">It is used to improve performance </span><span style="font-family: "book antiqua" , serif; font-size: 13pt;">significantly since often you won't need the children and so they will not be loaded. </span><span style="font-family: "book antiqua" , serif; font-size: 17.3333px;">Since Hibernate 3.0, lazy collection is enabled by default.</span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in;">
<br /></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in;">
<b><span style="color: #c00000; font-family: "book antiqua" , "serif"; font-size: 14.0pt;">When Lazy Loading is needed: Sample Problem</span></b></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in;">
<span style="font-family: "book antiqua" , serif; font-size: 13pt;">Consider an online portal which maintains a catalog of products. This can be modeled as a catalog entity (Parent) managing a series of product entities </span><span style="font-family: "book antiqua" , serif; font-size: 13pt;">(Children). In a large store, there may be tens of thousands of products grouped into various overlapping categories.</span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in;">
<br /></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in;">
<span style="font-family: "book antiqua" , "serif"; font-size: 13.0pt;">When a customer visits the store, the catalog must be loaded from the database. We probably don’t want the implementation to load every single one of the entities representing the tens of thousands of products to be loaded into memory. For a sufficiently large retailer, this might not even be possible, given the amount of physical memory available on the machine. Even if this were possible, it would probably cripple the performance of the site. Instead, we want only the catalog to load, possibly with the categories as well. Only when the user drills down into the categories should a subset of the products in that category be loaded from the database.</span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in;">
<span style="font-family: "book antiqua" , serif; font-size: 13pt;"><br /></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in;">
<span style="font-family: "book antiqua" , serif; font-size: 13pt;">To manage this problem, Hibernate provides a facility called lazy loading. When enabled, an entity’s associated entities will be loaded only when they are directly requested.</span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in;">
<br /></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in;">
<b><span style="color: #c00000; font-family: "book antiqua" , "serif"; font-size: 14.0pt;">How to Enable Lazy Loading in Hibernate</span></b><span style="font-family: "book antiqua" , "serif"; font-size: 13.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in;">
<span style="font-family: "book antiqua" , "serif"; font-size: 13.0pt;">To enable lazy loading explicitly you must use "fetch = FetchType.LAZY" on an association which you want to lazy load when you are using hibernate annotations.<o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in;">
<br /></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in;">
<b><span style="font-family: "book antiqua" , "serif"; font-size: 12.0pt;">Lazy loading using Annotations<o:p></o:p></span></b></div>
<div style="background: #DBE5F1; border: solid windowtext 1.0pt; mso-background-themecolor: accent1; mso-background-themetint: 51; mso-border-alt: solid windowtext .5pt; mso-element: para-border-div; padding: 1.0pt 4.0pt 1.0pt 4.0pt;">
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="color: #7f0055; font-family: "consolas"; mso-bidi-font-weight: bold;">public</span><span style="font-family: "consolas";"> </span><span style="color: #7f0055; font-family: "consolas"; mso-bidi-font-weight: bold;">class</span><span style="font-family: "consolas";"> Category { </span><span style="font-family: "consolas";"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<br /></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: "consolas";"> </span><span style="color: #646464; font-family: "consolas";">@</span><span style="font-family: "consolas";">OneToMany(mappedBy = </span><span style="color: #2a00ff; font-family: "consolas";">"category"</span><span style="font-family: "consolas";">, fetch = FetchType.LAZY )</span><span style="font-family: "consolas";"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: "consolas";"> </span><span style="color: #7f0055; font-family: "consolas"; mso-bidi-font-weight: bold;">private</span><span style="font-family: "consolas";"> Set<ProductEntity> products;</span><span style="font-family: "consolas";"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<br /></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: "consolas";"> </span><span style="color: #7f0055; font-family: "consolas"; mso-bidi-font-weight: bold;">public</span><span style="font-family: "consolas";"> Set<ProductEntity> getProducts() { </span><span style="font-family: "consolas";"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: "consolas";"> </span><span style="color: #7f0055; font-family: "consolas"; mso-bidi-font-weight: bold;">return</span><span style="font-family: "consolas";"> products; </span><span style="font-family: "consolas";"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: "consolas";"> } </span><span style="font-family: "consolas";"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: "consolas";"> </span><span style="color: #7f0055; font-family: "consolas"; mso-bidi-font-weight: bold;">public</span><span style="font-family: "consolas";"> </span><span style="color: #7f0055; font-family: "consolas"; mso-bidi-font-weight: bold;">void</span><span style="font-family: "consolas";"> setProducts(Set<ProductEntity> products) { </span><span style="font-family: "consolas";"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: "consolas";"> </span><span style="color: #7f0055; font-family: "consolas"; mso-bidi-font-weight: bold;">this</span><span style="font-family: "consolas";">.products = products; </span><span style="font-family: "consolas";"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: "consolas";"> } </span><span style="font-family: "consolas";"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: "consolas";">} </span><span style="font-family: "consolas";"><o:p></o:p></span></div>
</div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in;">
<br /></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in;">
<b><span style="font-family: "book antiqua" , "serif"; font-size: 12.0pt;">Lazy loading using XML configuration<o:p></o:p></span></b></div>
<div style="background: #DBE5F1; border: solid windowtext 1.0pt; mso-background-themecolor: accent1; mso-background-themetint: 51; mso-border-alt: solid windowtext .5pt; mso-element: para-border-div; padding: 1.0pt 4.0pt 1.0pt 4.0pt;">
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: "consolas";"><set name=</span><span style="color: #2a00ff; font-family: "consolas";">"category"</span><span style="font-family: "consolas";"> inverse=</span><span style="color: #2a00ff; font-family: "consolas";">"true"</span><span style="font-family: "consolas";"> cascade=</span><span style="color: #2a00ff; font-family: "consolas";">"delete"</span><span style="font-family: "consolas";"> lazy=</span><span style="color: #2a00ff; font-family: "consolas";">"false"</span><span style="font-family: "consolas";">></span><span style="font-family: "consolas";"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: "consolas";"> <key column=</span><span style="color: #2a00ff; font-family: "consolas";">"category_id"</span><span style="font-family: "consolas";"> /> </span><span style="font-family: "consolas";"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: "consolas";"> <one-to-many </span><span style="color: #7f0055; font-family: "consolas"; mso-bidi-font-weight: bold;">class</span><span style="font-family: "consolas";">=</span><span style="color: #2a00ff; font-family: "consolas";">"ProductEntity"</span><span style="font-family: "consolas";">/> </span><span style="font-family: "consolas";"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: "consolas";"></set></span><span style="font-family: "consolas";"><o:p></o:p></span></div>
</div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in;">
<br /></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in;">
<b><span style="color: #c00000; font-family: "book antiqua" , "serif"; font-size: 14.0pt;">How Lazy Loading Works in Hibernate?<o:p></o:p></span></b></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in;">
<span style="font-family: "book antiqua" , "serif"; font-size: 13.0pt;">Hibernate uses a proxy object to support lazy loading. Basically, when you load data from tables, hibernate doesn’t load all the mapped objects. As soon as you reference a child or lookup object via getter methods, if the linked entity is not in the session cache, then the proxy code will go to the database and load the linked object. It uses <b>javassist </b>to effectively and dynamically generate sub-classed implementations of your entity objects.<o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in;">
<br /></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in;">
<b><span style="color: #c00000; font-family: "book antiqua" , "serif"; font-size: 14.0pt;">Effect of Lazy Loading on Detached Entities<o:p></o:p></span></b></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in;">
<span style="font-family: "book antiqua" , "serif"; font-size: 13.0pt;">Hibernate can only access the database via a session, so if an entity is detached from the session and when we try to access an association (via a proxy or collection wrapper) that has not yet been loaded, Hibernate <span style="color: red;">throws a org.hibernate.LazyInitializationException: could not initialize proxy - no Session in Hibernate.</span></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in;">
<span style="font-family: "book antiqua" , serif; font-size: 13pt;"><br /></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in;">
<span style="font-family: "book antiqua" , serif; font-size: 13pt;">The cure is to ensure either that the entity is made persistent again by attaching it to a session or that all of the fields that will be required are accessed (so they are loaded into entity) before the entity is detached from the session.</span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in;">
<br /></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in;">
<b><span style="color: #00b050; font-family: "book antiqua" , "serif"; font-size: 14.0pt;">Important point<o:p></o:p></span></b></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in;">
<b><span style="font-family: "book antiqua" , "serif"; font-size: 13.0pt;">We should also aware about n+1-problem.</span></b><br />
<b><span style="font-family: "book antiqua" , "serif"; font-size: 13.0pt;"><br /></span></b></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in;">
<span style="font-family: "book antiqua" , "serif"; font-size: 13.0pt;">Hibernate will not actually load all children when you access the collection. Instead, it will load each child individually. When iterating over the collection, this causes a query for every child. In order to avoid this, you can trick hibernate into loading all children simultaneously, e.g. by calling parent.getChildren().size().<o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in;">
<span style="font-family: "book antiqua" , "serif"; font-size: 13.0pt;"><br /></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in;">
<span style="font-family: "book antiqua" , "serif"; font-size: 13.0pt;"><br /></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in;">
<span style="font-family: "book antiqua" , "serif"; font-size: 13.0pt;"><br /></span></div>
</div>
javaexplor03http://www.blogger.com/profile/07455293496498711738noreply@blogger.com0tag:blogger.com,1999:blog-615973148715732292.post-13183538124296928392017-05-17T20:42:00.000-07:002017-05-17T12:53:57.585-07:00Problems with Generics (type erasure)<div dir="ltr" style="text-align: left;" trbidi="on">
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: "book antiqua" , serif; font-size: 13pt;">Generics are checked at compile-time for type-correctness. The generic type information is then removed in a process called type erasure.</span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: "book antiqua", serif; font-size: 13pt;"><br /></span>
<span style="font-family: "book antiqua", serif; font-size: 13pt;">Because of type erasure, type parameters cannot be determined at run-time.</span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: "book antiqua" , "serif"; font-size: 13.0pt;">Example, when an ArrayList is examined at runtime, there is no general way to determine whether, <b>before type erasure</b>, it was an ArrayList<Integer> or an ArrayList<Float>.</span><br />
<span style="font-family: "book antiqua" , "serif"; font-size: 13.0pt;"><br /></span></div>
<div style="background: #DBE5F1; border: solid windowtext 1.0pt; mso-background-themecolor: accent1; mso-background-themetint: 51; mso-border-alt: solid windowtext .5pt; mso-element: para-border-div; padding: 1.0pt 4.0pt 1.0pt 4.0pt;">
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: "consolas"; font-size: 12pt;">ArrayList<Integer> intList = </span><span style="color: #7f0055; font-family: "consolas"; font-size: 12.0pt;">new</span><span style="font-family: "consolas"; font-size: 12pt;"> ArrayList<Integer>();</span><span style="font-family: "consolas"; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: "consolas"; font-size: 12pt;">ArrayList<Float> floatList = </span><span style="color: #7f0055; font-family: "consolas"; font-size: 12.0pt;">new</span><span style="font-family: "consolas"; font-size: 12pt;"> ArrayList<Float>();</span><span style="font-family: "consolas"; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; margin-bottom: 0.0001pt; padding: 0in;">
<span style="color: #7f0055; font-family: "consolas"; font-size: 12.0pt;">if</span><span style="font-family: "consolas"; font-size: 12pt;"> (intList.getClass() == floatList.getClass()) { </span><span style="color: #3f7f5f; font-family: "consolas"; font-size: 12.0pt;">// evaluates to true</span><span style="font-family: "consolas"; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: "consolas"; font-size: 12pt;"> System.out.println(</span><span style="color: #2a00ff; font-family: "consolas"; font-size: 12.0pt;">"Equal"</span><span style="font-family: "consolas"; font-size: 12pt;">);</span><span style="font-family: "consolas"; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; padding: 0in;">
<span style="font-family: "consolas"; font-size: 12pt; line-height: 115%;">}<o:p></o:p></span></div>
</div>
<div class="MsoNormal">
<span style="font-family: "book antiqua", serif; font-size: 13pt;"><br /></span>
<span style="font-family: "book antiqua", serif; font-size: 13pt;">A generic class cannot extend the Throwable class in any way, directly or indirectly:</span></div>
<div style="background: #DBE5F1; border: solid windowtext 1.0pt; mso-background-themecolor: accent1; mso-background-themetint: 51; mso-border-alt: solid windowtext .5pt; mso-element: para-border-div; padding: 1.0pt 4.0pt 1.0pt 4.0pt;">
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; margin-bottom: 0.0001pt; padding: 0in;">
<span style="color: #7f0055; font-family: "consolas"; font-size: 12.0pt;">public</span><span style="font-family: "consolas"; font-size: 12pt;"> </span><span style="color: #7f0055; font-family: "consolas"; font-size: 12.0pt;">class</span><span style="font-family: "consolas"; font-size: 12pt;"> GenericException<T> </span><span style="color: #7f0055; font-family: "consolas"; font-size: 12.0pt;">extends</span><span style="font-family: "consolas"; font-size: 12pt;"> Exception</span><span style="font-family: "consolas"; font-size: 12.0pt;"><o:p></o:p></span></div>
</div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: "book antiqua", serif; font-size: 13pt;"><br /></span>
<span style="font-family: "book antiqua", serif; font-size: 13pt;">The reason why this is not supported is due to type erasure:</span></div>
<div style="background: #DBE5F1; border: solid windowtext 1.0pt; mso-background-themecolor: accent1; mso-background-themetint: 51; mso-border-alt: solid windowtext .5pt; mso-element: para-border-div; padding: 1.0pt 4.0pt 1.0pt 4.0pt;">
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; margin-bottom: 0.0001pt; padding: 0in;">
<span style="color: #7f0055; font-family: "consolas"; font-size: 12.0pt;">try</span><span style="font-family: "consolas"; font-size: 12pt;"> {</span><span style="font-family: "consolas"; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: "consolas"; font-size: 12pt;"> </span><span style="color: #7f0055; font-family: "consolas"; font-size: 12.0pt;">throw</span><span style="font-family: "consolas"; font-size: 12pt;"> </span><span style="color: #7f0055; font-family: "consolas"; font-size: 12.0pt;">new</span><span style="font-family: "consolas"; font-size: 12pt;"> GenericException<Integer>();</span><span style="font-family: "consolas"; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: "consolas"; font-size: 12pt;">} </span><span style="color: #7f0055; font-family: "consolas"; font-size: 12.0pt;">catch</span><span style="font-family: "consolas"; font-size: 12pt;">(GenericException<Integer> </span><span style="color: #0000c0; font-family: "consolas"; font-size: 12.0pt;">e</span><span style="font-family: "consolas"; font-size: 12pt;">) {</span><span style="font-family: "consolas"; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: "consolas"; font-size: 12pt;"> System.</span><i><span style="color: #0000c0; font-family: "consolas"; font-size: 12.0pt;">err</span></i><span style="font-family: "consolas"; font-size: 12pt;">.println(</span><span style="color: #2a00ff; font-family: "consolas"; font-size: 12.0pt;">"Integer"</span><span style="font-family: "consolas"; font-size: 12pt;">);</span><span style="font-family: "consolas"; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: "consolas"; font-size: 12pt;">} </span><span style="color: #7f0055; font-family: "consolas"; font-size: 12.0pt;">catch</span><span style="font-family: "consolas"; font-size: 12pt;">(GenericException<String> e) {</span><span style="font-family: "consolas"; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: "consolas"; font-size: 12pt;"> System.err.println(</span><span style="color: #2a00ff; font-family: "consolas"; font-size: 12.0pt;">"String"</span><span style="font-family: "consolas"; font-size: 12pt;">);</span><span style="font-family: "consolas"; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; padding: 0in;">
<span style="font-family: "consolas"; font-size: 12pt; line-height: 115%;">}</span><span style="font-family: "consolas"; font-size: 12pt; line-height: 115%;"> </span></div>
</div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<br />
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in;">
<b><span style="color: #c00000; font-family: "Book Antiqua","serif"; font-size: 14.0pt; mso-bidi-font-size: 13.0pt;">Deep dive in Type Erasure<o:p></o:p></span></b></div>
<div style="background: #C6D9F1; border: solid windowtext 1.0pt; mso-background-themecolor: text2; mso-background-themetint: 51; mso-border-alt: solid windowtext .5pt; mso-element: para-border-div; padding: 1.0pt 4.0pt 1.0pt 4.0pt;">
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="color: #7f0055; font-family: Consolas; font-size: 12.0pt; mso-bidi-font-size: 10.0pt; mso-bidi-font-weight: bold;">import</span><span style="font-family: Consolas; font-size: 12pt;"> java.util.HashMap;</span><span style="font-family: Consolas; font-size: 12.0pt; mso-bidi-font-size: 10.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="color: #7f0055; font-family: Consolas; font-size: 12.0pt; mso-bidi-font-size: 10.0pt; mso-bidi-font-weight: bold;">import</span><span style="font-family: Consolas; font-size: 12pt;"> java.util.Map;</span><span style="font-family: Consolas; font-size: 12.0pt; mso-bidi-font-size: 10.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<br /></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="color: #7f0055; font-family: Consolas; font-size: 12.0pt; mso-bidi-font-size: 10.0pt; mso-bidi-font-weight: bold;">public</span><span style="font-family: Consolas; font-size: 12pt;"> </span><span style="color: #7f0055; font-family: Consolas; font-size: 12.0pt; mso-bidi-font-size: 10.0pt; mso-bidi-font-weight: bold;">class</span><span style="font-family: Consolas; font-size: 12pt;"> TypeErasure {</span><span style="font-family: Consolas; font-size: 12.0pt; mso-bidi-font-size: 10.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: Consolas; font-size: 12pt;"> </span><span style="color: #7f0055; font-family: Consolas; font-size: 12.0pt; mso-bidi-font-size: 10.0pt; mso-bidi-font-weight: bold;">public</span><span style="font-family: Consolas; font-size: 12pt;"> </span><span style="color: #7f0055; font-family: Consolas; font-size: 12.0pt; mso-bidi-font-size: 10.0pt; mso-bidi-font-weight: bold;">static</span><span style="font-family: Consolas; font-size: 12pt;"> </span><span style="color: #7f0055; font-family: Consolas; font-size: 12.0pt; mso-bidi-font-size: 10.0pt; mso-bidi-font-weight: bold;">void</span><span style="font-family: Consolas; font-size: 12pt;"> main(String </span><span style="color: #6a3e3e; font-family: Consolas; font-size: 12.0pt; mso-bidi-font-size: 10.0pt;">args</span><span style="font-family: Consolas; font-size: 12pt;">[]) {</span><span style="font-family: Consolas; font-size: 12.0pt; mso-bidi-font-size: 10.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<br /></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: Consolas; font-size: 12pt;"> Map<String,String> </span><span style="color: #6a3e3e; font-family: Consolas; font-size: 12.0pt; mso-bidi-font-size: 10.0pt;">genericMap</span><span style="font-family: Consolas; font-size: 12pt;"> = </span><span style="color: #7f0055; font-family: Consolas; font-size: 12.0pt; mso-bidi-font-size: 10.0pt; mso-bidi-font-weight: bold;">new</span><span style="font-family: Consolas; font-size: 12pt;"> HashMap<>();</span><span style="font-family: Consolas; font-size: 12.0pt; mso-bidi-font-size: 10.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: Consolas; font-size: 12pt;"> </span><span style="font-family: Consolas; font-size: 12.0pt; mso-bidi-font-size: 10.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: Consolas; font-size: 12pt;"> Map </span><span style="color: #6a3e3e; font-family: Consolas; font-size: 12.0pt; mso-bidi-font-size: 10.0pt;">nonGenericMap</span><span style="font-family: Consolas; font-size: 12pt;"> = </span><span style="color: #7f0055; font-family: Consolas; font-size: 12.0pt; mso-bidi-font-size: 10.0pt; mso-bidi-font-weight: bold;">new</span><span style="font-family: Consolas; font-size: 12pt;"> HashMap();</span><span style="font-family: Consolas; font-size: 12.0pt; mso-bidi-font-size: 10.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<br /></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: Consolas; font-size: 12pt;"> </span><span style="color: #6a3e3e; font-family: Consolas; font-size: 12.0pt; mso-bidi-font-size: 10.0pt;">genericMap</span><span style="font-family: Consolas; font-size: 12pt;">.put(</span><span style="color: #2a00ff; font-family: Consolas; font-size: 12.0pt; mso-bidi-font-size: 10.0pt;">"Rajesh"</span><span style="font-family: Consolas; font-size: 12pt;">, </span><span style="color: #2a00ff; font-family: Consolas; font-size: 12.0pt; mso-bidi-font-size: 10.0pt;">"Developer"</span><span style="font-family: Consolas; font-size: 12pt;">);</span><span style="font-family: Consolas; font-size: 12.0pt; mso-bidi-font-size: 10.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: Consolas; font-size: 12pt;"> String </span><span style="color: #6a3e3e; font-family: Consolas; font-size: 12.0pt; mso-bidi-font-size: 10.0pt;">role</span><span style="font-family: Consolas; font-size: 12pt;"> = </span><span style="color: #6a3e3e; font-family: Consolas; font-size: 12.0pt; mso-bidi-font-size: 10.0pt;">genericMap</span><span style="font-family: Consolas; font-size: 12pt;">.get(</span><span style="color: #2a00ff; font-family: Consolas; font-size: 12.0pt; mso-bidi-font-size: 10.0pt;">"Rajesh"</span><span style="font-family: Consolas; font-size: 12pt;">);</span><span style="font-family: Consolas; font-size: 12.0pt; mso-bidi-font-size: 10.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: Consolas; font-size: 12pt;"> System.</span><i><span style="color: #0000c0; font-family: Consolas; font-size: 12.0pt; mso-bidi-font-size: 10.0pt; mso-bidi-font-weight: bold;">out</span></i><span style="font-family: Consolas; font-size: 12pt;">.println(</span><span style="color: #2a00ff; font-family: Consolas; font-size: 12.0pt; mso-bidi-font-size: 10.0pt;">"Role: "</span><span style="font-family: Consolas; font-size: 12pt;">+</span><span style="color: #6a3e3e; font-family: Consolas; font-size: 12.0pt; mso-bidi-font-size: 10.0pt;">language</span><span style="font-family: Consolas; font-size: 12pt;">);</span><span style="font-family: Consolas; font-size: 12.0pt; mso-bidi-font-size: 10.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: Consolas; font-size: 12pt;"> }</span><span style="font-family: Consolas; font-size: 12.0pt; mso-bidi-font-size: 10.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; padding: 0in;">
<span style="font-family: Consolas; font-size: 12pt; line-height: 115%;">}</span><span style="font-size: 14.0pt; line-height: 115%; mso-bidi-font-size: 11.0pt;"><o:p></o:p></span></div>
</div>
<div class="MsoNormal">
<span style="font-family: "Book Antiqua","serif"; font-size: 13.0pt; line-height: 115%;"><br /></span></div>
<div class="MsoNormal">
<span style="font-family: "Book Antiqua","serif"; font-size: 13.0pt; line-height: 115%;">We instantiate a generic map using the parameterized type as generic String type. <b>It provides us the type safety and helps avoid the need for explicit casting</b>.<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-family: "Book Antiqua","serif"; font-size: 13.0pt; line-height: 115%;"><br /></span></div>
<div class="MsoNormal">
<span style="color: red; font-family: "Book Antiqua","serif"; font-size: 13.0pt; line-height: 115%;">Type erasure is a process to remove these types and map it to raw type in bytecode and it is done during compilation by the Java compiler</span><span style="font-family: "Book Antiqua","serif"; font-size: 13.0pt; line-height: 115%;">. Java compiler replaces <b>generic type information from the source and adds casts as needed and delivers the bytecode</b>, generics related information are kept as metadata in the bytecode for debugging, reflection purposes. With respect to general runtime execution, the code will look like plain Java without generics.<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-family: "Book Antiqua","serif"; font-size: 13.0pt; line-height: 115%;"><br /></span></div>
<div class="MsoNormal">
<span style="font-family: "Book Antiqua","serif"; font-size: 13.0pt; line-height: 115%;"><o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-family: "Book Antiqua","serif"; font-size: 13.0pt; line-height: 115%;">Let us compile the above given Java source file and then decompile that generated the binary class file. <o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-family: "Book Antiqua","serif"; font-size: 13.0pt; line-height: 115%;"><br /></span></div>
<div style="background: #C6D9F1; border: solid windowtext 1.0pt; mso-background-themecolor: text2; mso-background-themetint: 51; mso-border-alt: solid windowtext .5pt; mso-element: para-border-div; padding: 1.0pt 1.0pt 1.0pt 1.0pt;">
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: Consolas; font-size: 12.0pt;">C:\Users\awadh\Desktop\interview>javap -c TypeErasure<o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: Consolas; font-size: 12.0pt;">Compiled from "TypeErasure.java"<o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: Consolas; font-size: 12.0pt;">public class TypeErasure {<o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: Consolas; font-size: 12.0pt;"> public TypeErasure();<o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: Consolas; font-size: 12.0pt;"> Code:<o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: Consolas; font-size: 12.0pt;"> 0: aload_0<o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: Consolas; font-size: 12.0pt;"> 1: invokespecial #1 // Method java/lang/Object."<init>":<o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: Consolas; font-size: 12.0pt;">()V<o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: Consolas; font-size: 12.0pt;"> 4: return<o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<br /></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: Consolas; font-size: 12.0pt;"> public static void main(java.lang.String[]);<o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: Consolas; font-size: 12.0pt;"> Code:<o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: Consolas; font-size: 12.0pt;"> 0: new #2 // class java/util/HashMap<o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: Consolas; font-size: 12.0pt;"> 3: dup<o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: Consolas; font-size: 12.0pt;"> 4: invokespecial #3 // Method java/util/HashMap."<init>"<o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: Consolas; font-size: 12.0pt;">:()V<o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: Consolas; font-size: 12.0pt;"> 7: astore_1<o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: Consolas; font-size: 12.0pt;"> 8: new #2 // class java/util/HashMap<o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: Consolas; font-size: 12.0pt;"> 11: dup<o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: Consolas; font-size: 12.0pt;"> 12: invokespecial #3 // Method java/util/HashMap."<init>"<o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: Consolas; font-size: 12.0pt;">:()V<o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: Consolas; font-size: 12.0pt;"> 15: astore_2<o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: Consolas; font-size: 12.0pt;"> 16: aload_1<o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: Consolas; font-size: 12.0pt;"> 17: ldc #4 // String 1954<o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: Consolas; font-size: 12.0pt;"> 19: ldc #5 // String FORTRAN<o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: Consolas; font-size: 12.0pt;"> 21: invokeinterface #6, 3 // InterfaceMethod java/util/Map.put<o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: Consolas; font-size: 12.0pt;">:(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;<o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: Consolas; font-size: 12.0pt;"> 26: pop<o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: Consolas; font-size: 12.0pt;"> 27: aload_1<o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: Consolas; font-size: 12.0pt;"> 28: ldc #4 // String 1954<o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: Consolas; font-size: 12.0pt;"> 30: invokeinterface #7, 2 // InterfaceMethod java/util/Map.get<o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: Consolas; font-size: 12.0pt;">:(Ljava/lang/Object;)Ljava/lang/Object;<o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<b><span style="color: #00b050; font-family: Consolas; font-size: 12.0pt;"> 35: checkcast #8 // class java/lang/String<o:p></o:p></span></b></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: Consolas; font-size: 12.0pt;"> 38: astore_3<o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: Consolas; font-size: 12.0pt;"> 39: getstatic #9 // Field java/lang/System.out:Ljava/<o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: Consolas; font-size: 12.0pt;">io/PrintStream;<o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: Consolas; font-size: 12.0pt;"> 42: new #10 // class java/lang/StringBuilder<o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: Consolas; font-size: 12.0pt;"> 45: dup<o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: Consolas; font-size: 12.0pt;"> 46: invokespecial #11 // Method java/lang/StringBuilder."<<o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: Consolas; font-size: 12.0pt;">init>":()V<o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: Consolas; font-size: 12.0pt;"> 49: ldc #12 // String Language:<o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: Consolas; font-size: 12.0pt;"> 51: invokevirtual #13 // Method java/lang/StringBuilder.ap<o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: Consolas; font-size: 12.0pt;">pend:(Ljava/lang/String;)Ljava/lang/StringBuilder;<o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: Consolas; font-size: 12.0pt;"> 54: aload_3<o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: Consolas; font-size: 12.0pt;"> 55: invokevirtual #13 // Method java/lang/StringBuilder.ap<o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: Consolas; font-size: 12.0pt;">pend:(Ljava/lang/String;)Ljava/lang/StringBuilder;<o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: Consolas; font-size: 12.0pt;"> 58: invokevirtual #14 // Method java/lang/StringBuilder.to<o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: Consolas; font-size: 12.0pt;">String:()Ljava/lang/String;<o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: Consolas; font-size: 12.0pt;"> 61: invokevirtual #15 // Method java/io/PrintStream.printl<o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: Consolas; font-size: 12.0pt;">n:(Ljava/lang/String;)V<o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: Consolas; font-size: 12.0pt;"> 64: return<o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: Consolas; font-size: 12.0pt;">}<o:p></o:p></span></div>
</div>
<div class="MsoNormal">
<span style="font-family: "Book Antiqua", serif; font-size: 13pt;"><br /></span></div>
<div class="MsoNormal">
<span style="font-family: "Book Antiqua", serif; font-size: 13pt;">This is done by the java compiler while compiling java source code to bytecode as part of the process java type erasure. Main reason behind having generics and type erasure is to give the programmer ability to write generic code and type safety. Generics is not forced, the generic type can be directly used as the </span>raw<span style="font-family: "Book Antiqua", serif; font-size: 13pt;"> type instead of supplying parameterized type argument. But it is not a good coding practice.</span></div>
<div class="MsoNormal">
<o:p></o:p></div>
<div class="MsoNormal">
<span style="font-family: "Book Antiqua","serif"; font-size: 13.0pt; line-height: 115%;"><br /></span></div>
</div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-size: 14pt;"> <a href="https://en.wikipedia.org/wiki/Generics_in_Java" target="_blank">Generics in Java</a></span></div>
</div>
javaexplor03http://www.blogger.com/profile/07455293496498711738noreply@blogger.com0tag:blogger.com,1999:blog-615973148715732292.post-74859876784971399252017-05-17T11:41:00.000-07:002017-05-17T11:41:04.236-07:00Create Marker/Tagging Interfaces<div dir="ltr" style="text-align: left;" trbidi="on">
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in;">
<span style="font-family: "Book Antiqua", serif; font-size: 13pt;">An interface with no methods is known as the marker interface. </span><b style="font-family: "Book Antiqua", serif; font-size: 13pt;">It provides some useful information to JVM/compiler so that JVM/compiler performs some special operations on it. </b><span style="font-family: "Book Antiqua", serif; font-size: 13pt;">It is used for better readability of code.</span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in;">
<span style="font-family: "Book Antiqua","serif"; font-size: 13.0pt;">Few marker interfaces which are used in java are Random, Serializable, Clonnable etc.</span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in;">
<span style="font-family: "Book Antiqua","serif"; font-size: 13.0pt;"><br /></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in;">
<b><span style="color: #c00000; font-family: "Book Antiqua","serif"; font-size: 14.0pt; mso-bidi-font-size: 13.0pt;">Syntax:</span></b></div>
<div style="background: #C6D9F1; border: solid windowtext 1.0pt; mso-background-themecolor: text2; mso-background-themetint: 51; mso-border-alt: solid windowtext .5pt; mso-element: para-border-div; padding: 1.0pt 4.0pt 1.0pt 4.0pt;">
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="color: #7f0055; font-family: Consolas; font-size: 12.0pt; mso-bidi-font-size: 10.0pt; mso-bidi-font-weight: bold;">public</span><span style="font-family: Consolas; font-size: 12pt;"> </span><span style="color: #7f0055; font-family: Consolas; font-size: 12.0pt; mso-bidi-font-size: 10.0pt; mso-bidi-font-weight: bold;">interface</span><span style="font-family: Consolas; font-size: 12pt;"> interface_name {</span><span style="font-family: Consolas; font-size: 12.0pt; mso-bidi-font-size: 10.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: Consolas; font-size: 12pt;">}</span><span style="font-family: "Book Antiqua","serif"; font-size: 16.0pt; mso-bidi-font-size: 13.0pt;"><o:p></o:p></span></div>
</div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in;">
<b><span style="color: #c00000; font-family: "Book Antiqua","serif"; font-size: 14.0pt; mso-bidi-font-size: 13.0pt;"><br /></span></b></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in;">
<b><span style="color: #c00000; font-family: "Book Antiqua","serif"; font-size: 14.0pt; mso-bidi-font-size: 13.0pt;">Example:</span></b></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<b><span style="font-family: Consolas; font-size: 12pt;">TierACollegeMarker.java</span></b><b><span style="font-family: Consolas; font-size: 12.0pt; mso-bidi-font-size: 10.0pt;"><o:p></o:p></span></b></div>
<div style="background: #C6D9F1; border: solid windowtext 1.0pt; mso-background-themecolor: text2; mso-background-themetint: 51; mso-border-alt: solid windowtext .5pt; mso-element: para-border-div; padding: 1.0pt 4.0pt 1.0pt 4.0pt;">
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="color: #3f5fbf; font-family: Consolas; font-size: 12.0pt; mso-bidi-font-size: 10.0pt;">/**</span><span style="font-family: Consolas; font-size: 12.0pt; mso-bidi-font-size: 10.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="color: #3f5fbf; font-family: Consolas; font-size: 12.0pt; mso-bidi-font-size: 10.0pt;"> * This is marker interface for Tier A college.</span><span style="font-family: Consolas; font-size: 12.0pt; mso-bidi-font-size: 10.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="color: #3f5fbf; font-family: Consolas; font-size: 12.0pt; mso-bidi-font-size: 10.0pt;"> * </span><span style="color: #7f9fbf; font-family: Consolas; font-size: 12.0pt; mso-bidi-font-size: 10.0pt; mso-bidi-font-weight: bold;">@author</span><span style="color: #3f5fbf; font-family: Consolas; font-size: 12.0pt; mso-bidi-font-size: 10.0pt;"> rajesh.dixit</span><span style="font-family: Consolas; font-size: 12.0pt; mso-bidi-font-size: 10.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="color: #3f5fbf; font-family: Consolas; font-size: 12.0pt; mso-bidi-font-size: 10.0pt;"> */</span><span style="font-family: Consolas; font-size: 12.0pt; mso-bidi-font-size: 10.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="color: #7f0055; font-family: Consolas; font-size: 12.0pt; mso-bidi-font-size: 10.0pt; mso-bidi-font-weight: bold;">public</span><span style="font-family: Consolas; font-size: 12pt;"> </span><span style="color: #7f0055; font-family: Consolas; font-size: 12.0pt; mso-bidi-font-size: 10.0pt; mso-bidi-font-weight: bold;">interface</span><span style="font-family: Consolas; font-size: 12pt;"> TierACollegeMarker {</span><span style="font-family: Consolas; font-size: 12.0pt; mso-bidi-font-size: 10.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<br /></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: Consolas; font-size: 12pt;">}</span><span style="font-family: Consolas; font-size: 12.0pt; mso-bidi-font-size: 10.0pt;"><o:p></o:p></span></div>
</div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<b><span style="font-family: Consolas; font-size: 12pt;"><br /></span></b></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<b><span style="font-family: Consolas; font-size: 12pt;">IITD.java</span></b></div>
<div style="background: #C6D9F1; border: solid windowtext 1.0pt; mso-background-themecolor: text2; mso-background-themetint: 51; mso-border-alt: solid windowtext .5pt; mso-element: para-border-div; padding: 1.0pt 4.0pt 1.0pt 4.0pt;">
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="color: #3f5fbf; font-family: Consolas; font-size: 12.0pt; mso-bidi-font-size: 10.0pt;">/**</span><span style="font-family: Consolas; font-size: 12.0pt; mso-bidi-font-size: 10.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="color: #3f5fbf; font-family: Consolas; font-size: 12.0pt; mso-bidi-font-size: 10.0pt;"> * This class represents Tier A grade college.</span><span style="font-family: Consolas; font-size: 12.0pt; mso-bidi-font-size: 10.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="color: #3f5fbf; font-family: Consolas; font-size: 12.0pt; mso-bidi-font-size: 10.0pt;"> * </span><span style="color: #7f9fbf; font-family: Consolas; font-size: 12.0pt; mso-bidi-font-size: 10.0pt; mso-bidi-font-weight: bold;">@author</span><span style="color: #3f5fbf; font-family: Consolas; font-size: 12.0pt; mso-bidi-font-size: 10.0pt;"> rajesh.dixit</span><span style="font-family: Consolas; font-size: 12.0pt; mso-bidi-font-size: 10.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="color: #3f5fbf; font-family: Consolas; font-size: 12.0pt; mso-bidi-font-size: 10.0pt;"> */</span><span style="font-family: Consolas; font-size: 12.0pt; mso-bidi-font-size: 10.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="color: #7f0055; font-family: Consolas; font-size: 12.0pt; mso-bidi-font-size: 10.0pt; mso-bidi-font-weight: bold;">public</span><span style="font-family: Consolas; font-size: 12pt;"> </span><span style="color: #7f0055; font-family: Consolas; font-size: 12.0pt; mso-bidi-font-size: 10.0pt; mso-bidi-font-weight: bold;">class</span><span style="font-family: Consolas; font-size: 12pt;"> IITD </span><span style="color: #7f0055; font-family: Consolas; font-size: 12.0pt; mso-bidi-font-size: 10.0pt; mso-bidi-font-weight: bold;">implements</span><span style="font-family: Consolas; font-size: 12pt;"> TierACollegeMarker {</span><span style="font-family: Consolas; font-size: 12.0pt; mso-bidi-font-size: 10.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: Consolas; font-size: 12pt;"> </span><span style="color: #3f7f5f; font-family: Consolas; font-size: 12.0pt; mso-bidi-font-size: 10.0pt;">//Do something</span><span style="font-family: Consolas; font-size: 12.0pt; mso-bidi-font-size: 10.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: Consolas; font-size: 12pt;">}</span><span style="font-family: Consolas; font-size: 12.0pt; mso-bidi-font-size: 10.0pt;"><o:p></o:p></span></div>
</div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<b><span style="font-family: Consolas; font-size: 12pt;"><br /></span></b></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<b><span style="font-family: Consolas; font-size: 12pt;">Hindustan.java</span></b></div>
<div style="background: #C6D9F1; border: solid windowtext 1.0pt; mso-background-themecolor: text2; mso-background-themetint: 51; mso-border-alt: solid windowtext .5pt; mso-element: para-border-div; padding: 1.0pt 4.0pt 1.0pt 4.0pt;">
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="color: #3f5fbf; font-family: Consolas; font-size: 12.0pt; mso-bidi-font-size: 10.0pt;">/**</span><span style="font-family: Consolas; font-size: 12.0pt; mso-bidi-font-size: 10.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="color: #3f5fbf; font-family: Consolas; font-size: 12.0pt; mso-bidi-font-size: 10.0pt;"> * This class represents a, non</span><span style="color: #7f7f9f; font-family: Consolas; font-size: 12.0pt; mso-bidi-font-size: 10.0pt;">-</span><span style="color: #3f5fbf; font-family: Consolas; font-size: 12.0pt; mso-bidi-font-size: 10.0pt;">Tier A college.</span><span style="font-family: Consolas; font-size: 12.0pt; mso-bidi-font-size: 10.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="color: #3f5fbf; font-family: Consolas; font-size: 12.0pt; mso-bidi-font-size: 10.0pt;"> * </span><span style="color: #7f9fbf; font-family: Consolas; font-size: 12.0pt; mso-bidi-font-size: 10.0pt; mso-bidi-font-weight: bold;">@author</span><span style="color: #3f5fbf; font-family: Consolas; font-size: 12.0pt; mso-bidi-font-size: 10.0pt;"> rajesh.dixit</span><span style="font-family: Consolas; font-size: 12.0pt; mso-bidi-font-size: 10.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="color: #3f5fbf; font-family: Consolas; font-size: 12.0pt; mso-bidi-font-size: 10.0pt;"> */</span><span style="font-family: Consolas; font-size: 12.0pt; mso-bidi-font-size: 10.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="color: #7f0055; font-family: Consolas; font-size: 12.0pt; mso-bidi-font-size: 10.0pt; mso-bidi-font-weight: bold;">public</span><span style="font-family: Consolas; font-size: 12pt;"> </span><span style="color: #7f0055; font-family: Consolas; font-size: 12.0pt; mso-bidi-font-size: 10.0pt; mso-bidi-font-weight: bold;">class</span><span style="font-family: Consolas; font-size: 12pt;"> Hindustan {</span><span style="font-family: Consolas; font-size: 12.0pt; mso-bidi-font-size: 10.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: Consolas; font-size: 12pt;"> </span><span style="color: #3f7f5f; font-family: Consolas; font-size: 12.0pt; mso-bidi-font-size: 10.0pt;">//Do something</span><span style="font-family: Consolas; font-size: 12.0pt; mso-bidi-font-size: 10.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: Consolas; font-size: 12pt;">}</span><span style="font-family: Consolas; font-size: 12.0pt; mso-bidi-font-size: 10.0pt;"><o:p></o:p></span></div>
</div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<b><span style="font-family: Consolas; font-size: 12pt;"><br /></span></b></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<b><span style="font-family: Consolas; font-size: 12pt;">TestCollege.java</span></b></div>
<br />
<div style="background: #C6D9F1; border: solid windowtext 1.0pt; mso-background-themecolor: text2; mso-background-themetint: 51; mso-border-alt: solid windowtext .5pt; mso-element: para-border-div; padding: 1.0pt 4.0pt 1.0pt 4.0pt;">
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="color: #3f5fbf; font-family: Consolas; font-size: 12.0pt; mso-bidi-font-size: 10.0pt;">/**</span><span style="font-family: Consolas; font-size: 12.0pt; mso-bidi-font-size: 10.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="color: #3f5fbf; font-family: Consolas; font-size: 12.0pt; mso-bidi-font-size: 10.0pt;"> * This class is used to test the custom marker interface functionality.</span><span style="font-family: Consolas; font-size: 12.0pt; mso-bidi-font-size: 10.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="color: #3f5fbf; font-family: Consolas; font-size: 12.0pt; mso-bidi-font-size: 10.0pt;"> * </span><span style="color: #7f9fbf; font-family: Consolas; font-size: 12.0pt; mso-bidi-font-size: 10.0pt; mso-bidi-font-weight: bold;">@author</span><span style="color: #3f5fbf; font-family: Consolas; font-size: 12.0pt; mso-bidi-font-size: 10.0pt;"> rajesh.dixit</span><span style="font-family: Consolas; font-size: 12.0pt; mso-bidi-font-size: 10.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="color: #3f5fbf; font-family: Consolas; font-size: 12.0pt; mso-bidi-font-size: 10.0pt;"> */</span><span style="font-family: Consolas; font-size: 12.0pt; mso-bidi-font-size: 10.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="color: #7f0055; font-family: Consolas; font-size: 12.0pt; mso-bidi-font-size: 10.0pt; mso-bidi-font-weight: bold;">public</span><span style="font-family: Consolas; font-size: 12pt;"> </span><span style="color: #7f0055; font-family: Consolas; font-size: 12.0pt; mso-bidi-font-size: 10.0pt; mso-bidi-font-weight: bold;">class</span><span style="font-family: Consolas; font-size: 12pt;"> TestCollege {</span><span style="font-family: Consolas; font-size: 12.0pt; mso-bidi-font-size: 10.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: Consolas; font-size: 12pt;"> </span><span style="color: #7f0055; font-family: Consolas; font-size: 12.0pt; mso-bidi-font-size: 10.0pt; mso-bidi-font-weight: bold;">static</span><span style="font-family: Consolas; font-size: 12pt;"> </span><span style="color: #7f0055; font-family: Consolas; font-size: 12.0pt; mso-bidi-font-size: 10.0pt; mso-bidi-font-weight: bold;">void</span><span style="font-family: Consolas; font-size: 12pt;"> tester(Object obj) {</span><span style="font-family: Consolas; font-size: 12.0pt; mso-bidi-font-size: 10.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: Consolas; font-size: 12pt;"> </span><span style="color: #7f0055; font-family: Consolas; font-size: 12.0pt; mso-bidi-font-size: 10.0pt; mso-bidi-font-weight: bold;">if</span><span style="font-family: Consolas; font-size: 12pt;"> (obj </span><span style="color: #7f0055; font-family: Consolas; font-size: 12.0pt; mso-bidi-font-size: 10.0pt; mso-bidi-font-weight: bold;">instanceof</span><span style="font-family: Consolas; font-size: 12pt;"> TierACollegeMarker) {</span><span style="font-family: Consolas; font-size: 12.0pt; mso-bidi-font-size: 10.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: Consolas; font-size: 12pt;"> System.out.println(</span><span style="color: #2a00ff; font-family: Consolas; font-size: 12.0pt; mso-bidi-font-size: 10.0pt;">"Tier A college."</span><span style="font-family: Consolas; font-size: 12pt;">);</span><span style="font-family: Consolas; font-size: 12.0pt; mso-bidi-font-size: 10.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: Consolas; font-size: 12pt;"> }</span><span style="font-family: Consolas; font-size: 12.0pt; mso-bidi-font-size: 10.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: Consolas; font-size: 12pt;"> }</span><span style="font-family: Consolas; font-size: 12.0pt; mso-bidi-font-size: 10.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<br /></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: Consolas; font-size: 12pt;"> </span><span style="color: #7f0055; font-family: Consolas; font-size: 12.0pt; mso-bidi-font-size: 10.0pt; mso-bidi-font-weight: bold;">public</span><span style="font-family: Consolas; font-size: 12pt;"> </span><span style="color: #7f0055; font-family: Consolas; font-size: 12.0pt; mso-bidi-font-size: 10.0pt; mso-bidi-font-weight: bold;">static</span><span style="font-family: Consolas; font-size: 12pt;"> </span><span style="color: #7f0055; font-family: Consolas; font-size: 12.0pt; mso-bidi-font-size: 10.0pt; mso-bidi-font-weight: bold;">void</span><span style="font-family: Consolas; font-size: 12pt;"> main(String args[]) {</span><span style="font-family: Consolas; font-size: 12.0pt; mso-bidi-font-size: 10.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: Consolas; font-size: 12pt;"> IITD college1 = </span><span style="color: #7f0055; font-family: Consolas; font-size: 12.0pt; mso-bidi-font-size: 10.0pt; mso-bidi-font-weight: bold;">new</span><span style="font-family: Consolas; font-size: 12pt;"> IITD();</span><span style="font-family: Consolas; font-size: 12.0pt; mso-bidi-font-size: 10.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: Consolas; font-size: 12pt;"> Hindustan college2 = </span><span style="color: #7f0055; font-family: Consolas; font-size: 12.0pt; mso-bidi-font-size: 10.0pt; mso-bidi-font-weight: bold;">new</span><span style="font-family: Consolas; font-size: 12pt;"> Hindustan();</span><span style="font-family: Consolas; font-size: 12.0pt; mso-bidi-font-size: 10.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<br /></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: Consolas; font-size: 12pt;"> </span><span style="color: #3f5fbf; font-family: Consolas; font-size: 12.0pt; mso-bidi-font-size: 10.0pt;">/** test college objects.*/</span><span style="font-family: Consolas; font-size: 12.0pt; mso-bidi-font-size: 10.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: Consolas; font-size: 12pt;"> tester(college1);</span><span style="font-family: Consolas; font-size: 12.0pt; mso-bidi-font-size: 10.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: Consolas; font-size: 12pt;"> tester(college2);</span><span style="font-family: Consolas; font-size: 12.0pt; mso-bidi-font-size: 10.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: Consolas; font-size: 12pt;"> }</span><span style="font-family: Consolas; font-size: 12.0pt; mso-bidi-font-size: 10.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;">
<span style="font-family: Consolas; font-size: 12pt;">}</span><span style="font-family: "Book Antiqua","serif"; font-size: 16.0pt; mso-bidi-font-size: 13.0pt;"><o:p></o:p></span></div>
</div>
</div>
javaexplor03http://www.blogger.com/profile/07455293496498711738noreply@blogger.com0