tag:blogger.com,1999:blog-12664565997061520532024-03-05T20:52:44.055+05:30javashivA blog for getting tutorials on java and spring framework,hibernate,java8.Magic is you learn and prepare for interview at same timeAnonymoushttp://www.blogger.com/profile/07685598617709117616noreply@blogger.comBlogger32125tag:blogger.com,1999:blog-1266456599706152053.post-37492805695564016562016-11-29T16:31:00.003+05:302016-11-29T16:31:44.592+05:30Java App which is getting viral<div dir="ltr" style="text-align: left;" trbidi="on">
<h3 style="text-align: left;">
<b>App has exclusive collection of Java interview questions.</b>Proudly written by most viewed java author on quora.com<br />App has detail explanation about every trending questions nowadays in interviews.<br />It coves core of every interview whether it is of fresher or experienced.<br />Topics included are<br /> <br /> #Collection<br /> #MultiThreading<br /> #Java8 <br /> #Spring<br /> #Hibernate<br /> #Jms<br /> #Angularjs</h3>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://2.bp.blogspot.com/bRFZFwjkzdrpi1VevLnIZtmnLq34FVUMrJNcAiMSLUBFHIAKLjvawx7g-9Pxj4Daf8Lg=h900" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="320" src="https://2.bp.blogspot.com/bRFZFwjkzdrpi1VevLnIZtmnLq34FVUMrJNcAiMSLUBFHIAKLjvawx7g-9Pxj4Daf8Lg=h900" width="179" /></a></div>
<h3 style="text-align: left;">
<a href="https://play.google.com/store/apps/details?id=com.javashiv.sur.rss">Most liked Java App for you in free.</a> </h3>
</div>
Anonymoushttp://www.blogger.com/profile/07685598617709117616noreply@blogger.com0United States37.71859032558816 -99.8437512.19655582558816 -141.152344 63.240624825588156 -58.535156tag:blogger.com,1999:blog-1266456599706152053.post-39455486871539306902016-11-18T15:40:00.001+05:302016-11-18T15:40:11.608+05:30Java interview questions part2<div dir="ltr" style="text-align: left;" trbidi="on">
<div dir="ltr">
<b>What is classloader</b></div>
<div dir="ltr">
When Java application starts the program it does not load all the required files at once. Rather it loads class files when required.<br />
Class loads is part of Jvm which loads when required. </div>
<div dir="ltr">
</div>
<ul style="text-align: left;">
<li><b>Types of <u>classloader</u></b></li>
<li>1.bootstrap classloader</li>
<li>2.extension class loader</li>
<li>3.system class loader</li>
<li>4.custom class loader.</li>
</ul>
<br />
<div dir="ltr">
<b>How singleton design pattern can be created without creating private constructor</b><br />
We can create it by using enum. </div>
<div dir="ltr">
<b>How to create your own immutable class </b></div>
<ul style="text-align: left;">
<li>Declare all fields as final</li>
<li>Declare class as final. </li>
<li>Don't provide setter method for any variable. </li>
<li>Perform cloning of objects in getter methods when getter returns object it should return copy.</li>
</ul>
<br />
<div dir="ltr">
<b>What is </b><b>clonable?</b><br />
Clonable is an interface must be implemented if you plan to clone object. Clonable allows to create bitwise copy of object. clone performs shallow copy. It will copy only reference. </div>
<div dir="ltr">
<br /></div>
<div dir="ltr">
<b>What is shallow and deep copy?</b><br />
<b><br /></b></div>
<div dir="ltr">
<b>Shallow copy</b><br />
When we use default implementation of clone method. you use shallow copy of objects because object refers the same object.<br />
If only primitive type like int char and immutable type like String are present then there is not much difference. <br />
<b><br /></b></div>
<div dir="ltr">
<b>Deep copy</b><br />
</div>
<div dir="ltr">
Deep copy is expensive as it recursively copies data from object getting CLONED. it <u>copies</u> mutable objects which are part of object getting cloned. </div>
<div dir="ltr">
What if I don't to use closable but still want to make copy of objects<br />
The alternative to clonable is copy constructor. </div>
<div dir="ltr">
<b><br /></b></div>
<div dir="ltr">
<b>What happens if you don't implement </b><b>Clonable</b><b>. </b><br />
It will throw CloneNotSupportedException.<br />
<br />
<ul style="text-align: left;">
<li><b>Diffrence between failfast and fail safe</b></li>
</ul>
<br />
failfast works on original collection and fail safe works on the copy of original collection.<br />
fail fast throws exception fail safe won'tthrow exception.<br />
<br />
<ul style="text-align: left;">
<li><b style="font-family: "courier new", courier, monospace; font-size: 16px;">CopyOnWriteArrayList significance</b></li>
</ul>
<br />
copy on writearraylist supports concurrency.<br />
synchronized collection locks whole collection and concurrentcollection locks portion of collection.<br />
<br />
<br />
<ul style="text-align: left;">
<li><b>Singleton vs Static class</b></li>
</ul>
<br />
<ol style="background-color: white; border: 0px; color: #242729; font-family: arial, "helvetica neue", helvetica, sans-serif; font-size: 15px; margin: 0px 0px 1em 30px; padding: 0px;">
<li style="border: 0px; margin: 0px 0px 0.5em; padding: 0px; word-wrap: break-word;">Singleton object stores in <strong style="border: 0px; margin: 0px; padding: 0px;">Heap</strong> but, static object stores in <strong style="border: 0px; margin: 0px; padding: 0px;">stack</strong></li>
<li style="border: 0px; margin: 0px 0px 0.5em; padding: 0px; word-wrap: break-word;">We can <strong style="border: 0px; margin: 0px; padding: 0px;">clone</strong> the object of Singleton but, we can not clone the static class object</li>
<li style="border: 0px; margin: 0px 0px 0.5em; padding: 0px; word-wrap: break-word;">Singleton class follow the <strong style="border: 0px; margin: 0px; padding: 0px;">OOP</strong>(object oriented principles) but not static class</li>
<li style="border: 0px; margin: 0px; padding: 0px; word-wrap: break-word;">we can implement <strong style="border: 0px; margin: 0px; padding: 0px;">interface</strong> with Singleton class but not with Static class.</li>
</ol>
<div>
<ul style="text-align: left;">
<li><b style="color: #242729; font-family: arial, "helvetica neue", helvetica, sans-serif; font-size: 15px;">Overriding Puzzle</b></li>
</ul>
<div>
<div style="color: #242729; font-family: arial, "helvetica neue", helvetica, sans-serif; font-size: 15px;">
class A</div>
<div style="color: #242729; font-family: arial, "helvetica neue", helvetica, sans-serif; font-size: 15px;">
{</div>
<div style="color: #242729; font-family: arial, "helvetica neue", helvetica, sans-serif; font-size: 15px;">
int a=10;</div>
<div style="color: #242729; font-family: arial, "helvetica neue", helvetica, sans-serif; font-size: 15px;">
void big(){</div>
<div style="color: #242729; font-family: arial, "helvetica neue", helvetica, sans-serif; font-size: 15px;">
</div>
<div style="color: #242729; font-family: arial, "helvetica neue", helvetica, sans-serif; font-size: 15px;">
System.out.println("A");</div>
<div style="color: #242729; font-family: arial, "helvetica neue", helvetica, sans-serif; font-size: 15px;">
}</div>
<div style="color: #242729; font-family: arial, "helvetica neue", helvetica, sans-serif; font-size: 15px;">
}</div>
<div style="color: #242729; font-family: arial, "helvetica neue", helvetica, sans-serif; font-size: 15px;">
class B extends A</div>
<div style="color: #242729; font-family: arial, "helvetica neue", helvetica, sans-serif; font-size: 15px;">
{</div>
<div style="color: #242729; font-family: arial, "helvetica neue", helvetica, sans-serif; font-size: 15px;">
int a=20;</div>
<div style="color: #242729; font-family: arial, "helvetica neue", helvetica, sans-serif; font-size: 15px;">
void big(){</div>
<div style="color: #242729; font-family: arial, "helvetica neue", helvetica, sans-serif; font-size: 15px;">
System.out.println("B");</div>
<div style="color: #242729; font-family: arial, "helvetica neue", helvetica, sans-serif; font-size: 15px;">
</div>
<div style="color: #242729; font-family: arial, "helvetica neue", helvetica, sans-serif; font-size: 15px;">
}</div>
<div style="color: #242729; font-family: arial, "helvetica neue", helvetica, sans-serif;">
<span style="font-size: 15px;"> <span style="background-color: yellow;"> </span></span><br />
<div style="background-color: yellow; display: inline !important; font-size: 15px;">
void childMethod()</div>
</div>
<div style="color: #242729; font-family: arial, "helvetica neue", helvetica, sans-serif;">
<span style="background-color: yellow; font-size: 15px;"> {</span></div>
<div style="color: #242729; font-family: arial, "helvetica neue", helvetica, sans-serif;">
<span style="background-color: yellow; font-size: 15px;"> System.out.println("I only exist in child");</span></div>
<div style="color: #242729; font-family: arial, "helvetica neue", helvetica, sans-serif;">
<span style="background-color: yellow; font-size: 15px;"> </span></div>
<div style="color: #242729; font-family: arial, "helvetica neue", helvetica, sans-serif;">
<span style="background-color: yellow; font-size: 15px;"> }</span></div>
<div style="color: #242729; font-family: arial, "helvetica neue", helvetica, sans-serif; font-size: 15px;">
}</div>
<div style="color: #242729; font-family: arial, "helvetica neue", helvetica, sans-serif; font-size: 15px;">
public class HelloWorld{</div>
<div style="color: #242729; font-family: arial, "helvetica neue", helvetica, sans-serif; font-size: 15px;">
<br /></div>
<div style="color: #242729; font-family: arial, "helvetica neue", helvetica, sans-serif; font-size: 15px;">
public static void main(String []args){</div>
<div style="color: #242729; font-family: arial, "helvetica neue", helvetica, sans-serif; font-size: 15px;">
A b=(A)new B();</div>
<div style="color: #242729; font-family: arial, "helvetica neue", helvetica, sans-serif; font-size: 15px;">
b.big();</div>
<div style="color: #242729; font-family: arial, "helvetica neue", helvetica, sans-serif; font-size: 15px;">
System.out.println("Value of A"+b.a);</div>
<div style="color: #242729; font-family: arial, "helvetica neue", helvetica, sans-serif; font-size: 15px;">
}</div>
<div style="color: #242729; font-family: arial, "helvetica neue", helvetica, sans-serif; font-size: 15px;">
}</div>
<div style="color: #242729; font-family: arial, "helvetica neue", helvetica, sans-serif; font-size: 15px; font-weight: bold;">
<br /></div>
<div style="color: #242729; font-family: arial, "helvetica neue", helvetica, sans-serif; font-weight: bold;">
<span style="font-size: large;">Output: B</span></div>
<div>
<ul style="color: #242729; font-family: arial, "helvetica neue", helvetica, sans-serif; font-size: 15px; font-weight: bold;">
<li><b><div style="display: inline !important;">
Case2: Newly added method can't be called with reference of top class.</div>
</b></li>
</ul>
<div style="font-family: arial, "helvetica neue", helvetica, sans-serif; font-size: 15px;">
<span style="font-size: small;"></span><br />
<div style="color: #242729;">
<span style="font-size: small;">public class HelloWorld{</span></div>
<span style="font-size: small;"><div style="color: #242729; font-size: 15px;">
<br /></div>
<div style="color: #242729; font-size: 15px;">
public static void main(String []args){</div>
<div style="color: #242729; font-size: 15px;">
A b=(A)new B();</div>
<div style="color: #242729; font-size: 15px;">
b.<span style="font-size: small;"></span><br />
<div style="background-color: yellow; display: inline;">
<span style="font-size: small;">childMethod</span></div>
<span style="font-size: small;"></span>();</div>
<div style="color: #242729; font-size: 15px;">
}</div>
<div style="color: #242729; font-size: 15px;">
}</div>
<div style="color: #242729; font-weight: bold;">
<br /></div>
<div style="font-weight: bold;">
<b style="color: #242729;"><span style="font-size: large;">Output: </span></b><b></b><br />
<div style="display: inline !important; font-size: 15px;">
<div style="display: inline !important;">
<div style="background-color: yellow; display: inline !important; font-family: "DejaVu Sans Mono", "Liberation Mono", monospace; font-size: 14px; font-weight: normal; white-space: nowrap;">
<b>HelloWorld.java:25: error: cannot find symbol </b></div>
</div>
</div>
<b></b></div>
</span><br />
<div style="font-family: "dejavu sans mono", "liberation mono", monospace; font-size: 14px; white-space: nowrap;">
<span style="background-color: yellow;"> b.childMethod(); </span></div>
<div style="font-family: "dejavu sans mono", "liberation mono", monospace; font-size: 14px; white-space: nowrap;">
<br /></div>
<div style="font-family: "DejaVu Sans Mono", "Liberation Mono", monospace; font-size: 14px; white-space: nowrap;">
<ul style="text-align: left;">
<li><b>Case3:If same variable declared in parent as well as child class.And called using reference of </b></li>
<li><b>Parent class.then always variables of parent class are refered .</b></li>
</ul>
<div>
<span style="font-family: "arial" , "helvetica neue" , "helvetica" , sans-serif; font-size: small; white-space: normal;"></span><br />
<div style="color: #242729; font-size: 15px;">
<span style="font-family: "arial" , "helvetica neue" , "helvetica" , sans-serif; font-size: small; white-space: normal;">public class HelloWorld{</span></div>
<span style="font-family: "arial" , "helvetica neue" , "helvetica" , sans-serif; font-size: small; white-space: normal;"><div style="color: #242729; font-size: 15px;">
<br /></div>
<div style="color: #242729; font-size: 15px;">
public static void main(String []args){</div>
<div style="color: #242729; font-size: 15px;">
A b=(A)new B();</div>
<div style="color: #242729; font-size: 15px;">
b<span style="background-color: #eeeeee;">.<span style="font-size: small;"></span></span><br />
<div style="display: inline;">
<span style="background-color: #eeeeee;"><span style="font-size: small;">a</span></span></div>
<span style="background-color: #eeeeee;"><span style="font-size: small;"></span></span>();</div>
<div style="color: #242729; font-size: 15px;">
}</div>
<div style="color: #242729; font-size: 15px;">
}</div>
<div style="font-size: 15px; font-weight: bold;">
<b style="font-size: medium;"><b style="color: #242729;"><span style="font-size: large;">Output: </span></b></b><span style="background-color: white; font-family: "dejavu sans mono" , "liberation mono" , monospace; font-size: 14px; white-space: nowrap;">Value of A10</span></div>
<div style="font-size: 15px; font-weight: bold;">
<span style="background-color: white; font-family: "dejavu sans mono" , "liberation mono" , monospace; font-size: 14px; white-space: nowrap;"><br /></span></div>
<div style="font-size: 15px; font-weight: bold;">
<ul style="text-align: left;">
<li>Diffrence Between the Enumeration and iteration</li>
</ul>
</div>
<div style="font-size: 15px;">
<span style="background-color: white; font-family: "dejavu sans mono" , "liberation mono" , monospace; font-size: 14px; white-space: nowrap;">Iterator more safe does not allow other thread to modify collection throws ConcurrentModificationException.</span></div>
<div style="font-size: 15px;">
<ul style="text-align: left;">
<li><b>How Hashset maintains unique item </b></li>
<li><pre class="lang-java prettyprint prettyprinted" style="background-color: #eff0f1; border: 0px; color: #393318; font-family: consolas, menlo, monaco, "lucida console", "liberation mono", "dejavu sans mono", "bitstream vera sans mono", "courier new", monospace, sans-serif; font-size: 13px; margin-bottom: 1em; max-height: 600px; overflow: auto; padding: 5px; width: auto; word-wrap: normal;"><code style="border: 0px; font-family: Consolas, Menlo, Monaco, "Lucida Console", "Liberation Mono", "DejaVu Sans Mono", "Bitstream Vera Sans Mono", "Courier New", monospace, sans-serif; margin: 0px; padding: 0px; white-space: inherit;"><span class="kwd" style="border: 0px; color: #101094; margin: 0px; padding: 0px;">private</span><span class="pln" style="border: 0px; color: #303336; margin: 0px; padding: 0px;"> </span><span class="kwd" style="border: 0px; color: #101094; margin: 0px; padding: 0px;">static</span><span class="pln" style="border: 0px; color: #303336; margin: 0px; padding: 0px;"> </span><span class="kwd" style="border: 0px; color: #101094; margin: 0px; padding: 0px;">final</span><span class="pln" style="border: 0px; color: #303336; margin: 0px; padding: 0px;"> </span><span class="typ" style="border: 0px; color: #2b91af; margin: 0px; padding: 0px;">Object</span><span class="pln" style="border: 0px; color: #303336; margin: 0px; padding: 0px;"> PRESENT </span><span class="pun" style="border: 0px; color: #303336; margin: 0px; padding: 0px;">=</span><span class="pln" style="border: 0px; color: #303336; margin: 0px; padding: 0px;"> </span><span class="kwd" style="border: 0px; color: #101094; margin: 0px; padding: 0px;">new</span><span class="pln" style="border: 0px; color: #303336; margin: 0px; padding: 0px;"> </span><span class="typ" style="border: 0px; color: #2b91af; margin: 0px; padding: 0px;">Object</span><span class="pun" style="border: 0px; color: #303336; margin: 0px; padding: 0px;">();</span><span class="pln" style="border: 0px; color: #303336; margin: 0px; padding: 0px;">
</span><span class="pln" style="border: 0px; color: #303336; margin: 0px; padding: 0px;">
</span><span class="kwd" style="border: 0px; color: #101094; margin: 0px; padding: 0px;">public</span><span class="pln" style="border: 0px; color: #303336; margin: 0px; padding: 0px;"> </span><span class="kwd" style="border: 0px; color: #101094; margin: 0px; padding: 0px;">boolean</span><span class="pln" style="border: 0px; color: #303336; margin: 0px; padding: 0px;"> add</span><span class="pun" style="border: 0px; color: #303336; margin: 0px; padding: 0px;">(</span><span class="pln" style="border: 0px; color: #303336; margin: 0px; padding: 0px;">E e</span><span class="pun" style="border: 0px; color: #303336; margin: 0px; padding: 0px;">)</span><span class="pln" style="border: 0px; color: #303336; margin: 0px; padding: 0px;"> </span><span class="pun" style="border: 0px; color: #303336; margin: 0px; padding: 0px;">{</span><span class="pln" style="border: 0px; color: #303336; margin: 0px; padding: 0px;">
</span><span class="kwd" style="border: 0px; color: #101094; margin: 0px; padding: 0px;">return</span><span class="pln" style="border: 0px; color: #303336; margin: 0px; padding: 0px;"> map</span><span class="pun" style="border: 0px; color: #303336; margin: 0px; padding: 0px;">.</span><span class="pln" style="border: 0px; color: #303336; margin: 0px; padding: 0px;">put</span><span class="pun" style="border: 0px; color: #303336; margin: 0px; padding: 0px;">(</span><span class="pln" style="border: 0px; color: #303336; margin: 0px; padding: 0px;">e</span><span class="pun" style="border: 0px; color: #303336; margin: 0px; padding: 0px;">,</span><span class="pln" style="border: 0px; color: #303336; margin: 0px; padding: 0px;"> PRESENT</span><span class="pun" style="border: 0px; color: #303336; margin: 0px; padding: 0px;">)==</span><span class="kwd" style="border: 0px; color: #101094; margin: 0px; padding: 0px;">null</span><span class="pun" style="border: 0px; color: #303336; margin: 0px; padding: 0px;">;</span><span class="pln" style="border: 0px; color: #303336; margin: 0px; padding: 0px;">
</span><span class="pun" style="border: 0px; color: #303336; margin: 0px; padding: 0px;">}</span></code></pre>
</li>
</ul>
</div>
<div style="font-size: 15px;">
<span style="background-color: white; font-family: "dejavu sans mono" , "liberation mono" , monospace; font-size: 14px; white-space: nowrap;"><br /></span></div>
<div style="font-size: 15px; font-weight: bold;">
</div>
</span></div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
Anonymoushttp://www.blogger.com/profile/07685598617709117616noreply@blogger.com0tag:blogger.com,1999:blog-1266456599706152053.post-79098087159823525652016-10-10T14:18:00.001+05:302016-10-29T18:27:40.143+05:30Frequently asked interview questions<p dir="ltr"><b>Can</b><b> we serialise the static members</b><br>
Does not make any sense to make static  members serializable<br>
Staic member belong to the class not the individual objects.<br>
<b>Why use the </b><b>hashmap</b><b> keys as immutable objects</b><br>
Since if we use mutable objects as keys at the time of storage and over the time when we change it may point to entire different location.so suppose for key 3 value 33 is associated if this key is changed then it may point to diffrent location so to avoid this keys are immutable.<br>
<b>Difference save and </b><b><u>persist</u></b><br>
Save returns serializable entity<br>
Persist return <u>void</u><br>
<b>What is </b><b>executerservice</b></p>
<p dir="ltr">Executerservice is like a threadpool.<br>
It is a way of submitting thread for execution.It is used where asynchronous tasks need to be performed.<br>
Executerservice has submit method.<br>
Which returns future class instance.<br>
Executerservice takes callable instance .<br>
Future returns the result of thread execution</p>
<p dir="ltr"><b>Can we synchronise the constructor</b></p>
<p dir="ltr">No not possible.since it will be creating lock on object being created but generally the object is not available to other thread till the time it gets created</p>
<p dir="ltr"><b>Can we synchronise the run  method </b><br>
Yes  we  can  synchronize  run method. </p>
<p dir="ltr"><b>Types of  garbage  collection </b><br>
Serial gc<br>
Parallel gc=serial works same as parallel but the girl is done by multiple  threads. </p>
<p dir="ltr"><b>What is  difference between notify and notify all</b></p>
<p dir="ltr">Notify all - will notify all waiting <u>thread</u><br>
Notify- invokes the first thread which called the wait method on the object</p>
<p dir="ltr"><b>Join()  in multithreading</b></p>
<p dir="ltr">Join method in multithreading is used to pause execution of all other threads except the one which called the join method. </p>
<p dir="ltr"><b>Why use inner classes.</b><br>
Inner classes are used to hide implementation details. To increase encapsulation. <br>
Some examples of usage of inner classes are<br>
iterator inside list.<br>
Listener in <u>gui</u>. </p>
<p dir="ltr"><i>Spread the word if you really like this share with your friends. </i><br>
</p>
Anonymoushttp://www.blogger.com/profile/07685598617709117616noreply@blogger.com0tag:blogger.com,1999:blog-1266456599706152053.post-83575676693884012982016-09-12T19:25:00.001+05:302016-09-12T19:27:57.920+05:30ConcurrentHashMap in nutshell<div dir="ltr" style="text-align: left;" trbidi="on">
<div dir="ltr">
T<span style="font-family: "arial" , "helvetica" , sans-serif;">he Java concurrent hash map may be considered as the lodge having many rooms with locking facility.</span><span style="font-family: "arial" , "helvetica" , sans-serif;">Where as hash map may be considered as the house with one door.</span><br />
<span style="font-family: "arial" , "helvetica" , sans-serif;"><br /></span>
<span style="font-family: "arial" , "helvetica" , sans-serif;">So in case of hash map if you are locking the door. Then you will not be able to access if any of the room of house. Before using hash map every thread locks the hash map making it inaccessible to other thread till the time it won't complete it's operations. </span></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhA2mc_oAyy8y3fV6bE_ORWq0RSVbYJR1OBy6sJi8FNOWdCrNP7Zh_HKKshKbVJyTqxe3Nm5SXLmyJPlAm0FaU2Tr4WyMqHXKhSan7Oal4YlHbnc5EYgvPjgexg6KtDJ1AR34AIUbrClng/s1600/house.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img alt="Hashmap is like your house" border="0" height="155" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhA2mc_oAyy8y3fV6bE_ORWq0RSVbYJR1OBy6sJi8FNOWdCrNP7Zh_HKKshKbVJyTqxe3Nm5SXLmyJPlAm0FaU2Tr4WyMqHXKhSan7Oal4YlHbnc5EYgvPjgexg6KtDJ1AR34AIUbrClng/s320/house.png" title="HashMap" width="320" /></a></div>
<div class="separator" style="clear: both; text-align: center;">
<span style="color: red;">Hashmap</span></div>
<div dir="ltr">
<br />
<span style="font-family: "arial" , "helvetica" , sans-serif;">But if concurrent hash map is viewed it may be viewed as multiple separate rooms of Lodge if any room is locked we can still access the other rooms. </span><br />
<br /></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh_M34PSOifkLWZiqJ_l8EzGag2wSaHWj4HKKTQ3e3ohBI-udRWAgcLUDCFlP85jpyq54qOzw4NQmKtU0Tl2CbNnqiFIYwIvjGfKPzxIYIWD9Tk18192MaZZsh8tQPyV3OVRN9GS26Hddg/s1600/lodge.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="310" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh_M34PSOifkLWZiqJ_l8EzGag2wSaHWj4HKKTQ3e3ohBI-udRWAgcLUDCFlP85jpyq54qOzw4NQmKtU0Tl2CbNnqiFIYwIvjGfKPzxIYIWD9Tk18192MaZZsh8tQPyV3OVRN9GS26Hddg/s640/lodge.png" width="640" /></a></div>
<div class="separator" style="clear: both; text-align: center;">
<span style="color: red;">Concurrent hashmap used by multiple thread</span></div>
<div dir="ltr">
<br />
<h3 style="text-align: left;">
<b><span style="background: white; color: #474747; font-size: 10.5pt; line-height: 107%;"><span style="font-family: "arial" , "helvetica" , sans-serif;">Creation of ConcurrentHashMap</span></span></b></h3>
<div class="MsoNormal" style="background: white; margin-bottom: 0.0001pt;">
<b><span style="color: #7f0055; font-family: "courier new"; font-size: 10.0pt;"><br /></span></b></div>
<div class="MsoNormal" style="background: white; margin-bottom: 0.0001pt;">
<b><span style="color: #7f0055; font-family: "courier new"; font-size: 10.0pt;">public</span></b><span style="font-family: "courier new"; font-size: 10pt;"> <a href="https://www.blogger.com/null" name="ConcurrentHashMap.%3Cinit%3E%28int%2Cflo">ConcurrentHashMap</a>(</span><b><span style="color: #7f0055; font-family: "courier new"; font-size: 10.0pt;">int</span></b><span style="font-family: "courier new"; font-size: 10pt;"> <span style="background: #FFBB88;">initialCapacity</span>,</span><b><span style="color: #7f0055; font-family: "courier new"; font-size: 10.0pt;">float</span></b><span style="font-family: "courier new"; font-size: 10pt;"> loadFactor, </span><b><span style="color: #7f0055; font-family: "courier new"; font-size: 10.0pt;">int</span></b><span style="font-family: "courier new"; font-size: 10pt;"> concurrencyLevel) <o:p></o:p></span></div>
<div class="MsoNormal">
<br /></div>
<h3 style="text-align: left;">
<b><span style="background: white; color: #474747; font-family: "georgia" , serif; font-size: 10.5pt; line-height: 107%;">HashMap anatomy:</span></b></h3>
<iframe frameborder="0" marginheight="0" marginwidth="0" scrolling="no" src="//ws-in.amazon-adsystem.com/widgets/q?ServiceVersion=20070822&OneJS=1&Operation=GetAdHtml&MarketPlace=IN&source=ss&ref=as_ss_li_til&ad_type=product_link&tracking_id=javashivblogs-21&marketplace=amazon&region=IN&placement=B00UOLYNS0&asins=B00UOLYNS0&linkId=745924f27562ee73388e037361cfdb43&show_border=true&link_opens_in_new_window=true" style="height: 240px; width: 120px;"></iframe><iframe frameborder="0" marginheight="0" marginwidth="0" scrolling="no" src="//ws-in.amazon-adsystem.com/widgets/q?ServiceVersion=20070822&OneJS=1&Operation=GetAdHtml&MarketPlace=IN&source=ss&ref=as_ss_li_til&ad_type=product_link&tracking_id=javashivblogs-21&marketplace=amazon&region=IN&placement=B008YW8M0G&asins=B008YW8M0G&linkId=340a1d99b675815cceb8485b49270e2a&show_border=true&link_opens_in_new_window=true" style="height: 240px; width: 120px;"></iframe><iframe frameborder="0" marginheight="0" marginwidth="0" scrolling="no" src="//ws-in.amazon-adsystem.com/widgets/q?ServiceVersion=20070822&OneJS=1&Operation=GetAdHtml&MarketPlace=IN&source=ss&ref=as_ss_li_til&ad_type=product_link&tracking_id=javashivblogs-21&marketplace=amazon&region=IN&placement=B01702RVXY&asins=B01702RVXY&linkId=77f084bdd988d2569d4453582cbb81a0&show_border=true&link_opens_in_new_window=true" style="height: 240px; width: 120px;"></iframe>
<br />
<div class="MsoNormal">
<b><span style="background: white; color: #474747; font-family: "georgia" , serif; font-size: 10.5pt; line-height: 107%;"><br /></span></b></div>
<h4 style="text-align: left;">
<b><span style="background: white; color: #474747; font-family: "georgia" , serif; font-size: 10.5pt; line-height: 107%;">Initial Capacity: </span></b></h4>
<h4 style="text-align: left;">
<span style="background: white; color: #474747; font-size: 10.5pt; line-height: 107%;"><span style="font-weight: normal;"><span style="font-family: "georgia" , serif;">Y</span><span style="font-family: "arial" , "helvetica" , sans-serif;">ou can specify the size of the
concurrenthashmap at the time of creation.</span></span><span style="font-family: "arial" , "helvetica" , sans-serif;"><o:p></o:p></span></span></h4>
<div class="MsoNormal">
<span style="background: white; font-family: "courier new"; font-size: 13.5pt; line-height: 107%;"><br /></span></div>
<div class="MsoNormal">
<span style="background: white; font-family: "courier new"; font-size: 13.5pt; line-height: 107%;"> </span><span class="kw"><b><span style="background: white; color: #7f0055; font-family: "courier new"; font-size: 13.5pt; line-height: 107%;">static</span></b></span><span style="background: white; font-family: "courier new"; font-size: 13.5pt; line-height: 107%;"> </span><span class="kw"><b><span style="background: white; color: #7f0055; font-family: "courier new"; font-size: 13.5pt; line-height: 107%;">final</span></b></span><span style="background: white; font-family: "courier new"; font-size: 13.5pt; line-height: 107%;"> </span><span class="kw"><b><span style="background: white; color: #7f0055; font-family: "courier new"; font-size: 13.5pt; line-height: 107%;">int</span></b></span><span style="background: white; font-family: "courier new"; font-size: 13.5pt; line-height: 107%;"> </span><a href="https://www.blogger.com/null" name="ConcurrentHashMap.0DEFAULT_INITIAL_CAPAC"><span class="mark-10"><span style="background: white; font-size: 13.5pt; line-height: 107%;">DEFAULT_INITIAL_CAPACITY</span></span></a><span style="background: white; font-family: "courier new"; font-size: 13.5pt; line-height: 107%;"> = 16;</span><span style="background: white; color: #474747; font-family: "georgia" , serif; font-size: 10.5pt; line-height: 107%;"><o:p></o:p></span></div>
<div class="MsoNormal">
<b><span style="background: white; color: #474747; font-family: "georgia" , serif; font-size: 10.5pt; line-height: 107%;"><br /></span></b></div>
<h3 style="text-align: left;">
<b><span style="background: white; color: #474747; font-family: "georgia" , serif; font-size: 10.5pt; line-height: 107%;">Load Factor:</span> </b></h3>
<div style="text-align: left;">
<span style="font-weight: normal;"><span style="font-family: "arial" , "helvetica" , sans-serif;">Tolerable capacity of <span style="background: white; color: #474747; font-size: 10.5pt; line-height: 107%;">concurrenthashmap </span>if it exceeds <span style="background: white; color: #474747; font-size: 10.5pt; line-height: 107%;">concurrenthashmap </span>needs to be resized. However
resizing operation is relatively slow.</span></span></div>
<div class="MsoNormal">
<span style="font-family: "arial" , "helvetica" , sans-serif;"><o:p></o:p></span></div>
<div class="MsoNormal">
<span style="background: white; font-family: "courier new"; font-size: 13.5pt; line-height: 107%;"><br /></span></div>
<div class="MsoNormal">
<span style="background: white; font-family: "courier new"; font-size: 13.5pt; line-height: 107%;"> </span><span class="kw"><b><span style="background: white; color: #7f0055; font-family: "courier new"; font-size: 13.5pt; line-height: 107%;">static</span></b></span><span style="background: white; font-family: "courier new"; font-size: 13.5pt; line-height: 107%;"> </span><span class="kw"><b><span style="background: white; color: #7f0055; font-family: "courier new"; font-size: 13.5pt; line-height: 107%;">final</span></b></span><span style="background: white; font-family: "courier new"; font-size: 13.5pt; line-height: 107%;"> </span><span class="kw"><b><span style="background: white; color: #7f0055; font-family: "courier new"; font-size: 13.5pt; line-height: 107%;">float</span></b></span><span style="background: white; font-family: "courier new"; font-size: 13.5pt; line-height: 107%;"> </span><a href="https://www.blogger.com/null" name="ConcurrentHashMap.0DEFAULT_LOAD_FACTOR"><span class="mark-20"><span style="background: white; font-size: 13.5pt; line-height: 107%;">DEFAULT_LOAD_FACTOR</span></span></a><span style="background: white; font-family: "courier new"; font-size: 13.5pt; line-height: 107%;"> = 0.75f;</span><o:p></o:p></div>
<div class="MsoNormal">
<b><span style="background: white; color: #474747; font-family: "georgia" , serif; font-size: 10.5pt; line-height: 107%;"><br /></span></b></div>
<h4 style="text-align: left;">
<b><span style="background: white; color: #474747; font-family: "georgia" , serif; font-size: 10.5pt; line-height: 107%;">ConcurrencyLevel:</span></b></h4>
<div class="MsoNormal">
<span style="background: white; color: #474747; font-size: 10.5pt; line-height: 107%;"><span style="font-family: "arial" , "helvetica" , sans-serif;"> Estimated number of concurrently updated
threads.</span><span style="font-family: "georgia" , serif;"><o:p></o:p></span></span></div>
<div class="MsoNormal">
<br /></div>
<h4 style="text-align: left;">
<b><span style="background: white; color: #474747; font-family: "georgia" , serif; font-size: 10.5pt; line-height: 107%;">Advantages of concurrenthashmap:</span></b></h4>
<iframe style="width:120px;height:240px;" marginwidth="0" marginheight="0" scrolling="no" frameborder="0" src="//ws-in.amazon-adsystem.com/widgets/q?ServiceVersion=20070822&OneJS=1&Operation=GetAdHtml&MarketPlace=IN&source=ss&ref=as_ss_li_til&ad_type=product_link&tracking_id=javashivblogs-21&marketplace=amazon®ion=IN&placement=8173666024&asins=8173666024&linkId=5a05cf62621a391d94ab470a9b7a2c2f&show_border=true&link_opens_in_new_window=true"></iframe><iframe style="width:120px;height:240px;" marginwidth="0" marginheight="0" scrolling="no" frameborder="0" src="//ws-in.amazon-adsystem.com/widgets/q?ServiceVersion=20070822&OneJS=1&Operation=GetAdHtml&MarketPlace=IN&source=ss&ref=as_ss_li_til&ad_type=product_link&tracking_id=javashivblogs-21&marketplace=amazon®ion=IN&placement=B00SIWUU2A&asins=B00SIWUU2A&linkId=0c154e3c24b941e179450d87b0bc7ee9&show_border=true&link_opens_in_new_window=true"></iframe><iframe style="width:120px;height:240px;" marginwidth="0" marginheight="0" scrolling="no" frameborder="0" src="//ws-in.amazon-adsystem.com/widgets/q?ServiceVersion=20070822&OneJS=1&Operation=GetAdHtml&MarketPlace=IN&source=ss&ref=as_ss_li_til&ad_type=product_link&tracking_id=javashivblogs-21&marketplace=amazon®ion=IN&placement=B0190V7NK4&asins=B0190V7NK4&linkId=a6da9c3ff06bbb26114f080022fce078&show_border=true&link_opens_in_new_window=true"></iframe>
<div class="MsoNormal">
<span style="background: white; color: #474747; font-family: "georgia" , serif; font-size: 10.5pt; line-height: 107%;"><br /></span></div>
<div class="MsoNormal">
<span style="background: white; color: #474747; font-size: 10.5pt; line-height: 107%;"><span style="font-family: "arial" , "helvetica" , sans-serif;">ConcurrentHashMap can be used
to make the concurrent operations possible without waiting for other threads
job completion<o:p></o:p></span></span></div>
<div class="MsoNormal">
<span style="background: white; color: #474747; font-size: 10.5pt; line-height: 107%;"><span style="font-family: "arial" , "helvetica" , sans-serif;"><br /></span></span></div>
<div class="MsoNormal">
<span style="background: white; color: #474747; font-size: 10.5pt; line-height: 107%;"><span style="font-family: "arial" , "helvetica" , sans-serif;">Increased throughput.<o:p></o:p></span></span></div>
<div class="MsoNormal">
<span style="background: white; color: #474747; font-size: 10.5pt; line-height: 107%;"><span style="font-family: "arial" , "helvetica" , sans-serif;"><br /></span></span></div>
<div class="MsoNormal">
<span style="background: white; color: #474747; font-size: 10.5pt; line-height: 107%;"><span style="font-family: "arial" , "helvetica" , sans-serif;">For Producer Consumer Example
on concurrenthashmap <a href="http://javashiv.blogspot.com/2016/09/concurrenthashmap-example.html">Producer
Consumer in ConcurrentHashmap</a></span><span style="font-family: "georgia" , serif;"><o:p></o:p></span></span></div>
<div class="MsoNormal">
<b><span style="background: white; color: #474747; font-family: "georgia" , serif; font-size: 10.5pt; line-height: 107%;"><br /></span></b></div>
<h3 style="text-align: left;">
<b><span style="background: white; color: #474747; font-family: "georgia" , serif; font-size: 10.5pt; line-height: 107%;">Disadvantages of concurrency in hashmap</span></b></h3>
<div class="MsoNormal">
<span style="background: white; color: #474747; font-family: "georgia" , serif; font-size: 10.5pt; line-height: 107%;"><br /></span></div>
<div class="MsoNormal">
<span style="background: white; color: #474747; font-family: "georgia" , serif; font-size: 10.5pt; line-height: 107%;"> </span><span style="font-family: "arial" , "helvetica" , sans-serif;"><span style="background: white; color: #474747; font-size: 10.5pt; line-height: 107%;"> Methods including<span class="apple-converted-space"> </span></span><code><span style="background: white; color: #474747; font-size: 10.5pt; line-height: 107%;">size</span></code><span style="background: white; color: #474747; font-size: 10.5pt; line-height: 107%;">,<span class="apple-converted-space"> </span></span><code><span style="background: white; color: #474747; font-size: 10.5pt; line-height: 107%;">isEmpty</span></code><span style="background: white; color: #474747; font-size: 10.5pt; line-height: 107%;">, and<span class="apple-converted-space"> </span></span><code><span style="background: white; color: #474747; font-size: 10.5pt; line-height: 107%;">containsValue</span></code></span><span class="apple-converted-space"><span style="background: white; color: #474747; font-size: 10.5pt; line-height: 107%;"><span style="font-family: "arial" , "helvetica" , sans-serif;"> </span></span><span style="background: white; color: #474747; font-size: 10.5pt; line-height: 107%;"><span style="font-family: "arial" , "helvetica" , sans-serif;">are typically useful only when a map is not
undergoing concurrent updates in other threads. Otherwise these methods procure
precise results.</span><span style="font-family: "georgia" , serif;"><o:p></o:p></span></span></span></div>
<div class="MsoNormal">
<b><span style="background: white; color: #474747; font-family: "georgia" , serif; font-size: 10.5pt; line-height: 107%;"><br /></span></b></div>
<h4 style="text-align: left;">
<b><span style="background: white; color: #474747; font-family: "georgia" , serif; font-size: 10.5pt; line-height: 107%;">When resizing is done?</span></b></h4>
<div class="MsoListParagraphCxSpFirst" style="mso-list: l1 level1 lfo1; text-indent: -.25in;">
<!--[if !supportLists]-->1.<span style="font-size: 7pt; font-stretch: normal; font-variant-numeric: normal;"> </span></div>
<div class="MsoListParagraphCxSpFirst" style="mso-list: l1 level1 lfo1; text-indent: -.25in;">
<!--[endif]--> <span style="font-family: "arial" , "helvetica" , sans-serif;"> When the concurrenthashmap is almost full 75% of
its defined capacity.<o:p></o:p></span></div>
<div class="MsoListParagraphCxSpMiddle" style="mso-list: l1 level1 lfo1; text-indent: -.25in;">
<!--[if !supportLists]--><span style="font-family: "arial" , "helvetica" , sans-serif;">2.<span style="font-size: 7pt; font-stretch: normal; font-variant-numeric: normal;">
</span><!--[endif]-->When collisions are increased so to avoid
collisions concurrenthashmap is resized.</span><o:p></o:p></div>
<div class="MsoListParagraphCxSpLast">
<br /></div>
<h4 style="text-align: left;">
<b><span style="background: white; color: #474747; font-family: "georgia" , serif; font-size: 10.5pt; line-height: 107%;">Properties of ConcurrentHashmap</span></b></h4>
<div class="MsoListParagraphCxSpFirst" style="mso-list: l0 level1 lfo2; text-indent: -.25in;">
<!--[if !supportLists]-->1.<span style="font-size: 7pt; font-stretch: normal; font-variant-numeric: normal;"> </span></div>
<div class="MsoListParagraphCxSpFirst" style="mso-list: l0 level1 lfo2; text-indent: -.25in;">
<br /></div>
<div class="MsoListParagraphCxSpFirst" style="mso-list: l0 level1 lfo2; text-indent: -.25in;">
<span style="font-size: 7pt; font-stretch: normal; font-variant-numeric: normal;"></span><!--[endif]--> <span style="font-family: "arial" , "helvetica" , sans-serif;">ConcurrentHashmap does not allow null value.<o:p></o:p></span></div>
<div class="MsoListParagraphCxSpLast" style="mso-list: l0 level1 lfo2; text-indent: -.25in;">
<!--[if !supportLists]--><span style="font-family: "arial" , "helvetica" , sans-serif;">2.<span style="font-size: 7pt; font-stretch: normal; font-variant-numeric: normal;">
</span><!--[endif]-->ConcurrentHashMap does not allow duplicate keys.</span><o:p></o:p></div>
<div class="MsoListParagraphCxSpLast" style="mso-list: l0 level1 lfo2; text-indent: -.25in;">
<br /></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<b><span style="color: #7f0055; font-family: "franklin gothic book" , sans-serif; font-size: 12.0pt;">public</span></b><span style="font-family: "franklin gothic book" , sans-serif; font-size: 12pt;"> </span><b><span style="color: #7f0055; font-family: "franklin gothic book" , sans-serif; font-size: 12.0pt;">class</span></b><span style="font-family: "franklin gothic book" , sans-serif; font-size: 12pt;"> CHashMap {</span><span style="font-family: "franklin gothic book" , sans-serif; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<br /></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: "franklin gothic book" , sans-serif; font-size: 12pt;"> </span><b><span style="color: #7f0055; font-family: "franklin gothic book" , sans-serif; font-size: 12.0pt;">public</span></b><span style="font-family: "franklin gothic book" , sans-serif; font-size: 12pt;"> </span><b><span style="color: #7f0055; font-family: "franklin gothic book" , sans-serif; font-size: 12.0pt;">static</span></b><span style="font-family: "franklin gothic book" , sans-serif; font-size: 12pt;"> </span><b><span style="color: #7f0055; font-family: "franklin gothic book" , sans-serif; font-size: 12.0pt;">void</span></b><span style="font-family: "franklin gothic book" , sans-serif; font-size: 12pt;"> main(String[] </span><span style="color: #6a3e3e; font-family: "franklin gothic book" , sans-serif; font-size: 12.0pt;">args</span><span style="font-family: "franklin gothic book" , sans-serif; font-size: 12pt;">) {</span><span style="font-family: "franklin gothic book" , sans-serif; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: "franklin gothic book" , sans-serif; font-size: 12pt;">ConcurrentHashMap<String, String> </span><span style="color: #6a3e3e; font-family: "franklin gothic book" , sans-serif; font-size: 12.0pt;">ch</span><span style="font-family: "franklin gothic book" , sans-serif; font-size: 12pt;">=</span><b><span style="color: #7f0055; font-family: "franklin gothic book" , sans-serif; font-size: 12.0pt;">new</span></b><span style="font-family: "franklin gothic book" , sans-serif; font-size: 12pt;">
ConcurrentHashMap<String, String>();</span><span style="font-family: "franklin gothic book" , sans-serif; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="color: #6a3e3e; font-family: "franklin gothic book" , sans-serif; font-size: 12.0pt;">ch</span><span style="font-family: "franklin gothic book" , sans-serif; font-size: 12pt;">.put(</span><span style="color: #2a00ff; font-family: "franklin gothic book" , sans-serif; font-size: 12.0pt;">"a"</span><span style="font-family: "franklin gothic book" , sans-serif; font-size: 12pt;">, </span><span style="color: #2a00ff; font-family: "franklin gothic book" , sans-serif; font-size: 12.0pt;">"a"</span><span style="font-family: "franklin gothic book" , sans-serif; font-size: 12pt;">);</span><span style="font-family: "franklin gothic book" , sans-serif; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="color: #6a3e3e; font-family: "franklin gothic book" , sans-serif; font-size: 12.0pt;">ch</span><span style="font-family: "franklin gothic book" , sans-serif; font-size: 12pt;">.put(</span><span style="color: #2a00ff; font-family: "franklin gothic book" , sans-serif; font-size: 12.0pt;">"a"</span><span style="font-family: "franklin gothic book" , sans-serif; font-size: 12pt;">, </span><span style="color: #2a00ff; font-family: "franklin gothic book" , sans-serif; font-size: 12.0pt;">"a"</span><span style="font-family: "franklin gothic book" , sans-serif; font-size: 12pt;">);</span><span style="font-family: "franklin gothic book" , sans-serif; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: "franklin gothic book" , sans-serif; font-size: 12pt;">Enumeration<String> </span><span style="color: #6a3e3e; font-family: "franklin gothic book" , sans-serif; font-size: 12.0pt;">enum1</span><span style="font-family: "franklin gothic book" , sans-serif; font-size: 12pt;">=</span><span style="color: #6a3e3e; font-family: "franklin gothic book" , sans-serif; font-size: 12.0pt;">ch</span><span style="font-family: "franklin gothic book" , sans-serif; font-size: 12pt;">.keys();</span><span style="font-family: "franklin gothic book" , sans-serif; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<br /></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<b><span style="color: #7f0055; font-family: "franklin gothic book" , sans-serif; font-size: 12.0pt;">while</span></b><span style="font-family: "franklin gothic book" , sans-serif; font-size: 12pt;">(</span><span style="color: #6a3e3e; font-family: "franklin gothic book" , sans-serif; font-size: 12.0pt;">enum1</span><span style="font-family: "franklin gothic book" , sans-serif; font-size: 12pt;">.hasMoreElements())</span><span style="font-family: "franklin gothic book" , sans-serif; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: "franklin gothic book" , sans-serif; font-size: 12pt;">{</span><span style="font-family: "franklin gothic book" , sans-serif; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: "franklin gothic book" , sans-serif; font-size: 12pt;"> String </span><span style="color: #6a3e3e; font-family: "franklin gothic book" , sans-serif; font-size: 12.0pt;">key</span><span style="font-family: "franklin gothic book" , sans-serif; font-size: 12pt;">=</span><span style="color: #6a3e3e; font-family: "franklin gothic book" , sans-serif; font-size: 12.0pt;">enum1</span><span style="font-family: "franklin gothic book" , sans-serif; font-size: 12pt;">.nextElement();</span><span style="font-family: "franklin gothic book" , sans-serif; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: "franklin gothic book" , sans-serif; font-size: 12pt;"> System.</span><b><i><span style="color: #0000c0; font-family: "franklin gothic book" , sans-serif; font-size: 12.0pt;">out</span></i></b><span style="font-family: "franklin gothic book" , sans-serif; font-size: 12pt;">.println(</span><span style="color: #2a00ff; font-family: "franklin gothic book" , sans-serif; font-size: 12.0pt;">"Key is
==>"</span><span style="font-family: "franklin gothic book" , sans-serif; font-size: 12pt;">+</span><span style="color: #6a3e3e; font-family: "franklin gothic book" , sans-serif; font-size: 12.0pt;">key</span><span style="font-family: "franklin gothic book" , sans-serif; font-size: 12pt;">+</span><span style="color: #2a00ff; font-family: "franklin gothic book" , sans-serif; font-size: 12.0pt;">" Value is
===>"</span><span style="font-family: "franklin gothic book" , sans-serif; font-size: 12pt;">+</span><span style="color: #6a3e3e; font-family: "franklin gothic book" , sans-serif; font-size: 12.0pt;">ch</span><span style="font-family: "franklin gothic book" , sans-serif; font-size: 12pt;">.get(</span><span style="color: #6a3e3e; font-family: "franklin gothic book" , sans-serif; font-size: 12.0pt;">key</span><span style="font-family: "franklin gothic book" , sans-serif; font-size: 12pt;">));</span><span style="font-family: "franklin gothic book" , sans-serif; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: "franklin gothic book" , sans-serif; font-size: 12pt;"> }</span><span style="font-family: "franklin gothic book" , sans-serif; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: "franklin gothic book" , sans-serif; font-size: 12pt;"> }</span><span style="font-family: "franklin gothic book" , sans-serif; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<br /></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: "franklin gothic book" , sans-serif; font-size: 12pt;">}</span><span style="font-family: "franklin gothic book" , sans-serif; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoListParagraphCxSpFirst">
<br /></div>
<div class="MsoListParagraphCxSpLast">
<b><span style="background: white; color: #474747; font-family: "georgia" , serif; font-size: 10.5pt; line-height: 107%;">Output is:</span></b><span style="font-family: "consolas"; font-size: 10pt; line-height: 107%;"> Key is ==>a Value
is ===>a<o:p></o:p></span></div>
<br />
<div class="MsoNormal">
<br /></div>
</div>
</div>
Anonymoushttp://www.blogger.com/profile/07685598617709117616noreply@blogger.com0tag:blogger.com,1999:blog-1266456599706152053.post-9403372195578292612016-09-11T18:35:00.001+05:302016-09-11T18:39:05.634+05:30Java Helloworld<div dir="ltr" style="text-align: left;" trbidi="on">
<!--[if gte mso 9]><xml>
<o:OfficeDocumentSettings>
<o:AllowPNG/>
</o:OfficeDocumentSettings>
</xml><![endif]-->
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<b><span style="color: #7f0055; font-family: Consolas; font-size: 14.0pt;">Calcuator Demo</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="color: #7f0055; font-family: Consolas; font-size: 14.0pt;">package</span></b><span style="color: black; font-family: Consolas; font-size: 14.0pt;"> com.oop;</span><span style="font-family: Consolas; font-size: 14.0pt;"></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 style="color: #7f0055; font-family: Consolas; font-size: 14.0pt;">class</span></b><span style="color: black; font-family: Consolas; font-size: 14.0pt;"> Calculator </span><span style="font-family: Consolas; font-size: 14.0pt;"></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<span style="color: black; font-family: Consolas; font-size: 14.0pt;">{</span><span style="font-family: Consolas; font-size: 14.0pt;"></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<span style="color: black; font-family: Consolas; font-size: 14.0pt;"><span style="mso-tab-count: 1;"> </span></span><b><span style="color: #7f0055; font-family: Consolas; font-size: 14.0pt;">public</span></b><span style="color: black; font-family: Consolas; font-size: 14.0pt;"> Calculator() {</span><span style="font-family: Consolas; font-size: 14.0pt;"></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<span style="color: black; font-family: Consolas; font-size: 14.0pt;"><span style="mso-tab-count: 2;"> </span>System.</span><b><i><span style="color: #0000c0; font-family: Consolas; font-size: 14.0pt;">out</span></i></b><span style="color: black; font-family: Consolas; font-size: 14.0pt;">.println(</span><span style="color: #2a00ff; font-family: Consolas; font-size: 14.0pt;">"I am
constructor"</span><span style="color: black; font-family: Consolas; font-size: 14.0pt;">);</span><span style="font-family: Consolas; font-size: 14.0pt;"></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<span style="color: black; font-family: Consolas; font-size: 14.0pt;"><span style="mso-tab-count: 2;"> </span></span><span style="font-family: Consolas; font-size: 14.0pt;"></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<span style="color: black; font-family: Consolas; font-size: 14.0pt;"><span style="mso-tab-count: 1;"> </span>}</span><span style="font-family: Consolas; font-size: 14.0pt;"></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<span style="color: black; font-family: Consolas; font-size: 14.0pt;"><span style="mso-tab-count: 1;"> </span></span><span style="color: #3f7f5f; font-family: Consolas; font-size: 14.0pt;">//1.add 2.sub
3.multiplication 4.division</span><span style="font-family: Consolas; font-size: 14.0pt;"></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<span style="color: black; font-family: Consolas; font-size: 14.0pt;"><span style="mso-tab-count: 1;"> </span></span><b><span style="color: #7f0055; font-family: Consolas; font-size: 14.0pt;">public</span></b><span style="color: black; font-family: Consolas; font-size: 14.0pt;"> </span><b><span style="color: #7f0055; font-family: Consolas; font-size: 14.0pt;">int</span></b><span style="color: black; font-family: Consolas; font-size: 14.0pt;"> add(</span><b><span style="color: #7f0055; font-family: Consolas; font-size: 14.0pt;">int</span></b><span style="color: black; font-family: Consolas; font-size: 14.0pt;"> </span><span style="color: #6a3e3e; font-family: Consolas; font-size: 14.0pt;">num1</span><span style="color: black; font-family: Consolas; font-size: 14.0pt;">,</span><b><span style="color: #7f0055; font-family: Consolas; font-size: 14.0pt;">int</span></b><span style="color: black; font-family: Consolas; font-size: 14.0pt;"> </span><span style="color: #6a3e3e; font-family: Consolas; font-size: 14.0pt;">num2</span><span style="color: black; font-family: Consolas; font-size: 14.0pt;">)</span><span style="font-family: Consolas; font-size: 14.0pt;"></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<span style="color: black; font-family: Consolas; font-size: 14.0pt;"><span style="mso-tab-count: 1;"> </span>{</span><span style="font-family: Consolas; font-size: 14.0pt;"></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<span style="color: black; font-family: Consolas; font-size: 14.0pt;"><span style="mso-tab-count: 2;"> </span></span><span style="font-family: Consolas; font-size: 14.0pt;"></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<span style="color: black; font-family: Consolas; font-size: 14.0pt;"><span style="mso-tab-count: 2;"> </span></span><b><span style="color: #7f0055; font-family: Consolas; font-size: 14.0pt;">return</span></b><span style="color: black; font-family: Consolas; font-size: 14.0pt;"> (</span><span style="color: #6a3e3e; font-family: Consolas; font-size: 14.0pt;">num1</span><span style="color: black; font-family: Consolas; font-size: 14.0pt;">+</span><span style="color: #6a3e3e; font-family: Consolas; font-size: 14.0pt;">num2</span><span style="color: black; font-family: Consolas; font-size: 14.0pt;">);</span><span style="font-family: Consolas; font-size: 14.0pt;"></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<span style="color: black; font-family: Consolas; font-size: 14.0pt;"><span style="mso-tab-count: 1;"> </span>}</span><span style="font-family: Consolas; font-size: 14.0pt;"></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<span style="color: black; font-family: Consolas; font-size: 14.0pt;">}</span><span style="font-family: Consolas; font-size: 14.0pt;"></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 style="color: #7f0055; font-family: Consolas; font-size: 14.0pt;">public</span></b><span style="color: black; font-family: Consolas; font-size: 14.0pt;"> </span><b><span style="color: #7f0055; font-family: Consolas; font-size: 14.0pt;">class</span></b><span style="color: black; font-family: Consolas; font-size: 14.0pt;"> CalculatorDemo {</span><span style="font-family: Consolas; font-size: 14.0pt;"></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 class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<span style="color: black; font-family: Consolas; font-size: 14.0pt;"><span style="mso-tab-count: 1;"> </span></span><b><span style="color: #7f0055; font-family: Consolas; font-size: 14.0pt;">public</span></b><span style="color: black; font-family: Consolas; font-size: 14.0pt;"> </span><b><span style="color: #7f0055; font-family: Consolas; font-size: 14.0pt;">static</span></b><span style="color: black; font-family: Consolas; font-size: 14.0pt;"> </span><b><span style="color: #7f0055; font-family: Consolas; font-size: 14.0pt;">void</span></b><span style="color: black; font-family: Consolas; font-size: 14.0pt;"> main(String[] </span><span style="color: #6a3e3e; font-family: Consolas; font-size: 14.0pt;">args</span><span style="color: black; font-family: Consolas; font-size: 14.0pt;">)</span><span style="font-family: Consolas; font-size: 14.0pt;"></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<span style="color: black; font-family: Consolas; font-size: 14.0pt;"><span style="mso-tab-count: 1;"> </span>{</span><span style="font-family: Consolas; font-size: 14.0pt;"></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<span style="color: black; font-family: Consolas; font-size: 14.0pt;"><span style="mso-tab-count: 2;"> </span>Calculator
</span><span style="color: #6a3e3e; font-family: Consolas; font-size: 14.0pt;">calcObj</span><span style="color: black; font-family: Consolas; font-size: 14.0pt;">=</span><b><span style="color: #7f0055; font-family: Consolas; font-size: 14.0pt;">new</span></b><span style="color: black; font-family: Consolas; font-size: 14.0pt;"> Calculator();</span><span style="font-family: Consolas; font-size: 14.0pt;"></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<span style="color: black; font-family: Consolas; font-size: 14.0pt;"><span style="mso-tab-count: 2;"> </span>System.</span><b><i><span style="color: #0000c0; font-family: Consolas; font-size: 14.0pt;">out</span></i></b><span style="color: black; font-family: Consolas; font-size: 14.0pt;">.println(</span><span style="color: #2a00ff; font-family: Consolas; font-size: 14.0pt;">"addition is
"</span><span style="color: black; font-family: Consolas; font-size: 14.0pt;">+</span><span style="color: #6a3e3e; font-family: Consolas; font-size: 14.0pt;">calcObj</span><span style="color: black; font-family: Consolas; font-size: 14.0pt;">.add(2, 3));</span><span style="font-family: Consolas; font-size: 14.0pt;"></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<span style="color: black; font-family: Consolas; font-size: 14.0pt;"><span style="mso-tab-count: 2;"> </span></span><span style="font-family: Consolas; font-size: 14.0pt;"></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<span style="color: black; font-family: Consolas; font-size: 14.0pt;"><span style="mso-tab-count: 1;"> </span>}</span><span style="font-family: Consolas; font-size: 14.0pt;"></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<span style="color: black; font-family: Consolas; font-size: 14.0pt;">}</span><span style="font-family: Consolas; font-size: 14.0pt;"></span></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<b style="mso-bidi-font-weight: normal;"><span style="font-family: Consolas;">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="color: #7f0055; font-family: Consolas; font-size: 14.0pt;">package</span></b><span style="color: black; font-family: Consolas; font-size: 14.0pt;"> com.oop;</span><span style="font-family: Consolas; font-size: 14.0pt;"></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 style="color: #7f0055; font-family: Consolas; font-size: 14.0pt;">class</span></b><span style="color: black; font-family: Consolas; font-size: 14.0pt;"> Human</span><span style="font-family: Consolas; font-size: 14.0pt;"></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<span style="color: black; font-family: Consolas; font-size: 14.0pt;">{</span><span style="font-family: Consolas; font-size: 14.0pt;"></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<span style="color: black; font-family: Consolas; font-size: 14.0pt;"><span style="mso-tab-count: 1;"> </span></span><b><span style="color: #7f0055; font-family: Consolas; font-size: 14.0pt;">private</span></b><span style="color: black; font-family: Consolas; font-size: 14.0pt;"> String </span><span style="color: #0000c0; font-family: Consolas; font-size: 14.0pt;">address</span><span style="color: black; font-family: Consolas; font-size: 14.0pt;">;</span><span style="font-family: Consolas; font-size: 14.0pt;"></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<span style="color: black; font-family: Consolas; font-size: 14.0pt;"><span style="mso-spacerun: yes;">
</span></span><b><span style="color: #7f0055; font-family: Consolas; font-size: 14.0pt;">private</span></b><span style="color: black; font-family: Consolas; font-size: 14.0pt;"> </span><b><span style="color: #7f0055; font-family: Consolas; font-size: 14.0pt;">int</span></b><span style="color: black; font-family: Consolas; font-size: 14.0pt;"> </span><span style="color: #0000c0; font-family: Consolas; font-size: 14.0pt;">age</span><span style="color: black; font-family: Consolas; font-size: 14.0pt;">;</span><span style="font-family: Consolas; font-size: 14.0pt;"></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<span style="color: black; font-family: Consolas; font-size: 14.0pt;"><span style="mso-tab-count: 1;"> </span></span><b><span style="color: #7f0055; font-family: Consolas; font-size: 14.0pt;">public</span></b><span style="color: black; font-family: Consolas; font-size: 14.0pt;"> </span><b><span style="color: #7f0055; font-family: Consolas; font-size: 14.0pt;">int</span></b><span style="color: black; font-family: Consolas; font-size: 14.0pt;"> getAge() {</span><span style="font-family: Consolas; font-size: 14.0pt;"></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<span style="color: black; font-family: Consolas; font-size: 14.0pt;"><span style="mso-tab-count: 2;"> </span></span><b><span style="color: #7f0055; font-family: Consolas; font-size: 14.0pt;">return</span></b><span style="color: black; font-family: Consolas; font-size: 14.0pt;"> </span><span style="color: #0000c0; font-family: Consolas; font-size: 14.0pt;">age</span><span style="color: black; font-family: Consolas; font-size: 14.0pt;">;</span><span style="font-family: Consolas; font-size: 14.0pt;"></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<span style="color: black; font-family: Consolas; font-size: 14.0pt;"><span style="mso-tab-count: 1;"> </span>}</span><span style="font-family: Consolas; font-size: 14.0pt;"></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 class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<span style="color: black; font-family: Consolas; font-size: 14.0pt;"><span style="mso-tab-count: 1;"> </span></span><b><span style="color: #7f0055; font-family: Consolas; font-size: 14.0pt;">public</span></b><span style="color: black; font-family: Consolas; font-size: 14.0pt;"> </span><b><span style="color: #7f0055; font-family: Consolas; font-size: 14.0pt;">void</span></b><span style="color: black; font-family: Consolas; font-size: 14.0pt;"> setAge(</span><b><span style="color: #7f0055; font-family: Consolas; font-size: 14.0pt;">int</span></b><span style="color: black; font-family: Consolas; font-size: 14.0pt;"> </span><span style="color: #6a3e3e; font-family: Consolas; font-size: 14.0pt;">age</span><span style="color: black; font-family: Consolas; font-size: 14.0pt;">) {</span><span style="font-family: Consolas; font-size: 14.0pt;"></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<span style="color: black; font-family: Consolas; font-size: 14.0pt;"><span style="mso-tab-count: 2;"> </span></span><b><span style="color: #7f0055; font-family: Consolas; font-size: 14.0pt;">this</span></b><span style="color: black; font-family: Consolas; font-size: 14.0pt;">.</span><span style="color: #0000c0; font-family: Consolas; font-size: 14.0pt;">age</span><span style="color: black; font-family: Consolas; font-size: 14.0pt;"> = </span><span style="color: #6a3e3e; font-family: Consolas; font-size: 14.0pt;">age</span><span style="color: black; font-family: Consolas; font-size: 14.0pt;">;</span><span style="font-family: Consolas; font-size: 14.0pt;"></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<span style="color: black; font-family: Consolas; font-size: 14.0pt;"><span style="mso-tab-count: 1;"> </span>}</span><span style="font-family: Consolas; font-size: 14.0pt;"></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 class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<span style="color: black; font-family: Consolas; font-size: 14.0pt;"><span style="mso-tab-count: 1;"> </span></span><b><span style="color: #7f0055; font-family: Consolas; font-size: 14.0pt;">public</span></b><span style="color: black; font-family: Consolas; font-size: 14.0pt;"> String getAddress()
{</span><span style="font-family: Consolas; font-size: 14.0pt;"></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<span style="color: black; font-family: Consolas; font-size: 14.0pt;"><span style="mso-tab-count: 2;"> </span></span><b><span style="color: #7f0055; font-family: Consolas; font-size: 14.0pt;">return</span></b><span style="color: black; font-family: Consolas; font-size: 14.0pt;"> </span><span style="color: #0000c0; font-family: Consolas; font-size: 14.0pt;">address</span><span style="color: black; font-family: Consolas; font-size: 14.0pt;">;</span><span style="font-family: Consolas; font-size: 14.0pt;"></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<span style="color: black; font-family: Consolas; font-size: 14.0pt;"><span style="mso-tab-count: 1;"> </span>}</span><span style="font-family: Consolas; font-size: 14.0pt;"></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<span style="color: black; font-family: Consolas; font-size: 14.0pt;"><span style="mso-spacerun: yes;">
</span></span><span style="font-family: Consolas; font-size: 14.0pt;"></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<span style="color: black; font-family: Consolas; font-size: 14.0pt;"><span style="mso-tab-count: 1;"> </span></span><b><span style="color: #7f0055; font-family: Consolas; font-size: 14.0pt;">public</span></b><span style="color: black; font-family: Consolas; font-size: 14.0pt;"> </span><b><span style="color: #7f0055; font-family: Consolas; font-size: 14.0pt;">void</span></b><span style="color: black; font-family: Consolas; font-size: 14.0pt;"> setAddress(String </span><span style="color: #6a3e3e; font-family: Consolas; font-size: 14.0pt;">address</span><span style="color: black; font-family: Consolas; font-size: 14.0pt;">) {</span><span style="font-family: Consolas; font-size: 14.0pt;"></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<span style="color: black; font-family: Consolas; font-size: 14.0pt;"><span style="mso-tab-count: 2;"> </span></span><b><span style="color: #7f0055; font-family: Consolas; font-size: 14.0pt;">this</span></b><span style="color: black; font-family: Consolas; font-size: 14.0pt;">.</span><span style="color: #0000c0; font-family: Consolas; font-size: 14.0pt;">address</span><span style="color: black; font-family: Consolas; font-size: 14.0pt;"> = </span><span style="color: #6a3e3e; font-family: Consolas; font-size: 14.0pt;">address</span><span style="color: black; font-family: Consolas; font-size: 14.0pt;">;</span><span style="font-family: Consolas; font-size: 14.0pt;"></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<span style="color: black; font-family: Consolas; font-size: 14.0pt;"><span style="mso-tab-count: 1;"> </span>}</span><span style="font-family: Consolas; font-size: 14.0pt;"></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<span style="color: black; font-family: Consolas; font-size: 14.0pt;"><span style="mso-tab-count: 1;"> </span></span><span style="font-family: Consolas; font-size: 14.0pt;"></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<span style="color: black; font-family: Consolas; font-size: 14.0pt;">}</span><span style="font-family: Consolas; font-size: 14.0pt;"></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 style="color: #7f0055; font-family: Consolas; font-size: 14.0pt;">public</span></b><span style="color: black; font-family: Consolas; font-size: 14.0pt;"> </span><b><span style="color: #7f0055; font-family: Consolas; font-size: 14.0pt;">class</span></b><span style="color: black; font-family: Consolas; font-size: 14.0pt;"> HelloWorld {</span><span style="font-family: Consolas; font-size: 14.0pt;"></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<span style="color: black; font-family: Consolas; font-size: 14.0pt;"><span style="mso-tab-count: 1;"> </span></span><span style="color: #3f7f5f; font-family: Consolas; font-size: 14.0pt;">//Type2:declaration
and <u>oneliner</u> <u>init</u></span><span style="font-family: Consolas; font-size: 14.0pt;"></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<span style="color: black; font-family: Consolas; font-size: 14.0pt;"><span style="mso-tab-count: 1;"> </span></span><span style="color: #3f7f5f; font-family: Consolas; font-size: 14.0pt;">//<u>datatype</u> <u>varname</u>="value"</span><span style="font-family: Consolas; font-size: 14.0pt;"></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 style="color: #7f0055; font-family: Consolas; font-size: 14.0pt;">static</span></b><span style="color: black; font-family: Consolas; font-size: 14.0pt;"> String </span><i><span style="color: #0000c0; font-family: Consolas; font-size: 14.0pt;">empName</span></i><span style="color: black; font-family: Consolas; font-size: 14.0pt;">=</span><span style="color: #2a00ff; font-family: Consolas; font-size: 14.0pt;">"Ashwin
More"</span><span style="color: black; font-family: Consolas; font-size: 14.0pt;">;</span><span style="font-family: Consolas; font-size: 14.0pt;"></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 class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<br /></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<span style="color: #3f7f5f; font-family: Consolas; font-size: 14.0pt;">//Type1: declaration and then <u>intialization</u></span><span style="font-family: Consolas; font-size: 14.0pt;"></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<span style="color: #3f7f5f; font-family: Consolas; font-size: 14.0pt;">//dataType variable Name;</span><span style="font-family: Consolas; font-size: 14.0pt;"></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<span style="color: #3f7f5f; font-family: Consolas; font-size: 14.0pt;">//variableName="value";</span><span style="font-family: Consolas; font-size: 14.0pt;"></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 class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<span style="color: #3f7f5f; font-family: Consolas; font-size: 14.0pt;">//creation of objects</span><span style="font-family: Consolas; font-size: 14.0pt;"></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<span style="color: #3f7f5f; font-family: Consolas; font-size: 14.0pt;">//ClassName objectName=new
className();</span><span style="font-family: Consolas; font-size: 14.0pt;"></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 class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<br /></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="color: #7f0055; font-family: Consolas; font-size: 14.0pt;">public</span></b><span style="color: black; font-family: Consolas; font-size: 14.0pt;"> </span><b><span style="color: #7f0055; font-family: Consolas; font-size: 14.0pt;">static</span></b><span style="color: black; font-family: Consolas; font-size: 14.0pt;"> </span><b><span style="color: #7f0055; font-family: Consolas; font-size: 14.0pt;">void</span></b><span style="color: black; font-family: Consolas; font-size: 14.0pt;"> main(String[] </span><span style="color: #6a3e3e; font-family: Consolas; font-size: 14.0pt;">args</span><span style="color: black; font-family: Consolas; font-size: 14.0pt;">) {</span><span style="font-family: Consolas; font-size: 14.0pt;"></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<span style="color: black; font-family: Consolas; font-size: 14.0pt;"><span style="mso-tab-count: 1;"> </span>System.</span><b><i><span style="color: #0000c0; font-family: Consolas; font-size: 14.0pt;">out</span></i></b><span style="color: black; font-family: Consolas; font-size: 14.0pt;">.println(</span><span style="color: #2a00ff; font-family: Consolas; font-size: 14.0pt;">"HI Java Batch
and i am "</span><span style="color: black; font-family: Consolas; font-size: 14.0pt;">+</span><i><span style="color: #0000c0; font-family: Consolas; font-size: 14.0pt;">empName</span></i><span style="color: black; font-family: Consolas; font-size: 14.0pt;">);</span><span style="font-family: Consolas; font-size: 14.0pt;"></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<span style="color: black; font-family: Consolas; font-size: 14.0pt;"><span style="mso-tab-count: 1;"> </span></span><span style="font-family: Consolas; font-size: 14.0pt;"></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<span style="color: black; font-family: Consolas; font-size: 14.0pt;"><span style="mso-tab-count: 1;"> </span>Human
</span><span style="color: #6a3e3e; font-family: Consolas; font-size: 14.0pt;">objectHuman</span><span style="color: black; font-family: Consolas; font-size: 14.0pt;">=</span><b><span style="color: #7f0055; font-family: Consolas; font-size: 14.0pt;">new</span></b><span style="color: black; font-family: Consolas; font-size: 14.0pt;"> Human();</span><span style="font-family: Consolas; font-size: 14.0pt;"></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<span style="color: black; font-family: Consolas; font-size: 14.0pt;"><span style="mso-tab-count: 1;"> </span></span><span style="color: #6a3e3e; font-family: Consolas; font-size: 14.0pt;">objectHuman</span><span style="color: black; font-family: Consolas; font-size: 14.0pt;">.setAddress(</span><span style="color: #2a00ff; font-family: Consolas; font-size: 14.0pt;">"Pune"</span><span style="color: black; font-family: Consolas; font-size: 14.0pt;">);</span><span style="font-family: Consolas; font-size: 14.0pt;"></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<span style="color: black; font-family: Consolas; font-size: 14.0pt;"><span style="mso-tab-count: 1;"> </span></span><span style="color: #6a3e3e; font-family: Consolas; font-size: 14.0pt;">objectHuman</span><span style="color: black; font-family: Consolas; font-size: 14.0pt;">.setAge(23);</span><span style="font-family: Consolas; font-size: 14.0pt;"></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<span style="color: black; font-family: Consolas; font-size: 14.0pt;"><span style="mso-tab-count: 1;"> </span></span><span style="font-family: Consolas; font-size: 14.0pt;"></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<span style="color: black; font-family: Consolas; font-size: 14.0pt;"><span style="mso-tab-count: 1;"> </span>Human
</span><span style="color: #6a3e3e; font-family: Consolas; font-size: 14.0pt;">objectHuman1</span><span style="color: black; font-family: Consolas; font-size: 14.0pt;">=</span><b><span style="color: #7f0055; font-family: Consolas; font-size: 14.0pt;">new</span></b><span style="color: black; font-family: Consolas; font-size: 14.0pt;"> Human();</span><span style="font-family: Consolas; font-size: 14.0pt;"></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<span style="color: black; font-family: Consolas; font-size: 14.0pt;"><span style="mso-tab-count: 1;"> </span></span><span style="color: #6a3e3e; font-family: Consolas; font-size: 14.0pt;">objectHuman1</span><span style="color: black; font-family: Consolas; font-size: 14.0pt;">.setAddress(</span><span style="color: #2a00ff; font-family: Consolas; font-size: 14.0pt;">"Pune"</span><span style="color: black; font-family: Consolas; font-size: 14.0pt;">);</span><span style="font-family: Consolas; font-size: 14.0pt;"></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<span style="color: black; font-family: Consolas; font-size: 14.0pt;"><span style="mso-tab-count: 1;"> </span></span><span style="color: #6a3e3e; font-family: Consolas; font-size: 14.0pt;">objectHuman1</span><span style="color: black; font-family: Consolas; font-size: 14.0pt;">.setAge(20);</span><span style="font-family: Consolas; font-size: 14.0pt;"></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<span style="color: black; font-family: Consolas; font-size: 14.0pt;"><span style="mso-tab-count: 1;"> </span></span><span style="font-family: Consolas; font-size: 14.0pt;"></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<span style="color: black; font-family: Consolas; font-size: 14.0pt;"><span style="mso-tab-count: 1;"> </span>System.</span><b><i><span style="color: #0000c0; font-family: Consolas; font-size: 14.0pt;">out</span></i></b><span style="color: black; font-family: Consolas; font-size: 14.0pt;">.println(</span><span style="color: #2a00ff; font-family: Consolas; font-size: 14.0pt;">""</span><span style="color: black; font-family: Consolas; font-size: 14.0pt;">+</span><span style="color: #6a3e3e; font-family: Consolas; font-size: 14.0pt;">objectHuman1</span><span style="color: black; font-family: Consolas; font-size: 14.0pt;">.getAddress());</span><span style="font-family: Consolas; font-size: 14.0pt;"></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<span style="color: black; font-family: Consolas; font-size: 14.0pt;">}<span style="mso-tab-count: 1;"> </span></span><span style="font-family: Consolas; font-size: 14.0pt;"></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<span style="color: black; font-family: Consolas; font-size: 14.0pt;"><span style="mso-tab-count: 1;"> </span></span><span style="font-family: Consolas; font-size: 14.0pt;"></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<span style="color: black; font-family: Consolas; font-size: 14.0pt;">}</span><span style="font-family: Consolas; font-size: 14.0pt;"></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<span style="color: #3f7f5f; font-family: Consolas; font-size: 14.0pt;">//<u>visibily</u> modifier class
ClassName</span><span style="font-family: Consolas; font-size: 14.0pt;"></span></div>
<div class="MsoNormal">
<br /></div>
<!--[if gte mso 9]><xml>
<w:WordDocument>
<w:View>Normal</w:View>
<w:Zoom>0</w:Zoom>
<w:TrackMoves/>
<w:TrackFormatting/>
<w:PunctuationKerning/>
<w:ValidateAgainstSchemas/>
<w:SaveIfXMLInvalid>false</w:SaveIfXMLInvalid>
<w:IgnoreMixedContent>false</w:IgnoreMixedContent>
<w:AlwaysShowPlaceholderText>false</w:AlwaysShowPlaceholderText>
<w:DoNotPromoteQF/>
<w:LidThemeOther>EN-US</w:LidThemeOther>
<w:LidThemeAsian>X-NONE</w:LidThemeAsian>
<w:LidThemeComplexScript>X-NONE</w:LidThemeComplexScript>
<w:Compatibility>
<w:BreakWrappedTables/>
<w:SnapToGridInCell/>
<w:WrapTextWithPunct/>
<w:UseAsianBreakRules/>
<w:DontGrowAutofit/>
<w:SplitPgBreakAndParaMark/>
<w:EnableOpenTypeKerning/>
<w:DontFlipMirrorIndents/>
<w:OverrideTableStyleHps/>
</w:Compatibility>
<m:mathPr>
<m:mathFont m:val="Cambria Math"/>
<m:brkBin m:val="before"/>
<m:brkBinSub m:val="--"/>
<m:smallFrac m:val="off"/>
<m:dispDef/>
<m:lMargin m:val="0"/>
<m:rMargin m:val="0"/>
<m:defJc m:val="centerGroup"/>
<m:wrapIndent m:val="1440"/>
<m:intLim m:val="subSup"/>
<m:naryLim m:val="undOvr"/>
</m:mathPr></w:WordDocument>
</xml><![endif]--><!--[if gte mso 9]><xml>
<w:LatentStyles DefLockedState="false" DefUnhideWhenUsed="false"
DefSemiHidden="false" DefQFormat="false" DefPriority="99"
LatentStyleCount="371">
<w:LsdException Locked="false" Priority="0" QFormat="true" Name="Normal"/>
<w:LsdException Locked="false" Priority="9" QFormat="true" Name="heading 1"/>
<w:LsdException Locked="false" Priority="9" SemiHidden="true"
UnhideWhenUsed="true" QFormat="true" Name="heading 2"/>
<w:LsdException Locked="false" Priority="9" SemiHidden="true"
UnhideWhenUsed="true" QFormat="true" Name="heading 3"/>
<w:LsdException Locked="false" Priority="9" SemiHidden="true"
UnhideWhenUsed="true" QFormat="true" Name="heading 4"/>
<w:LsdException Locked="false" Priority="9" SemiHidden="true"
UnhideWhenUsed="true" QFormat="true" Name="heading 5"/>
<w:LsdException Locked="false" Priority="9" SemiHidden="true"
UnhideWhenUsed="true" QFormat="true" Name="heading 6"/>
<w:LsdException Locked="false" Priority="9" SemiHidden="true"
UnhideWhenUsed="true" QFormat="true" Name="heading 7"/>
<w:LsdException Locked="false" Priority="9" SemiHidden="true"
UnhideWhenUsed="true" QFormat="true" Name="heading 8"/>
<w:LsdException Locked="false" Priority="9" SemiHidden="true"
UnhideWhenUsed="true" QFormat="true" Name="heading 9"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="index 1"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="index 2"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="index 3"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="index 4"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="index 5"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="index 6"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="index 7"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="index 8"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="index 9"/>
<w:LsdException Locked="false" Priority="39" SemiHidden="true"
UnhideWhenUsed="true" Name="toc 1"/>
<w:LsdException Locked="false" Priority="39" SemiHidden="true"
UnhideWhenUsed="true" Name="toc 2"/>
<w:LsdException Locked="false" Priority="39" SemiHidden="true"
UnhideWhenUsed="true" Name="toc 3"/>
<w:LsdException Locked="false" Priority="39" SemiHidden="true"
UnhideWhenUsed="true" Name="toc 4"/>
<w:LsdException Locked="false" Priority="39" SemiHidden="true"
UnhideWhenUsed="true" Name="toc 5"/>
<w:LsdException Locked="false" Priority="39" SemiHidden="true"
UnhideWhenUsed="true" Name="toc 6"/>
<w:LsdException Locked="false" Priority="39" SemiHidden="true"
UnhideWhenUsed="true" Name="toc 7"/>
<w:LsdException Locked="false" Priority="39" SemiHidden="true"
UnhideWhenUsed="true" Name="toc 8"/>
<w:LsdException Locked="false" Priority="39" SemiHidden="true"
UnhideWhenUsed="true" Name="toc 9"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Normal Indent"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="footnote text"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="annotation text"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="header"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="footer"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="index heading"/>
<w:LsdException Locked="false" Priority="35" SemiHidden="true"
UnhideWhenUsed="true" QFormat="true" Name="caption"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="table of figures"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="envelope address"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="envelope return"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="footnote reference"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="annotation reference"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="line number"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="page number"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="endnote reference"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="endnote text"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="table of authorities"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="macro"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="toa heading"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="List"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="List Bullet"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="List Number"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="List 2"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="List 3"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="List 4"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="List 5"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="List Bullet 2"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="List Bullet 3"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="List Bullet 4"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="List Bullet 5"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="List Number 2"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="List Number 3"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="List Number 4"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="List Number 5"/>
<w:LsdException Locked="false" Priority="10" QFormat="true" Name="Title"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Closing"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Signature"/>
<w:LsdException Locked="false" Priority="1" SemiHidden="true"
UnhideWhenUsed="true" Name="Default Paragraph Font"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Body Text"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Body Text Indent"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="List Continue"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="List Continue 2"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="List Continue 3"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="List Continue 4"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="List Continue 5"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Message Header"/>
<w:LsdException Locked="false" Priority="11" QFormat="true" Name="Subtitle"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Salutation"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Date"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Body Text First Indent"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Body Text First Indent 2"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Note Heading"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Body Text 2"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Body Text 3"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Body Text Indent 2"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Body Text Indent 3"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Block Text"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Hyperlink"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="FollowedHyperlink"/>
<w:LsdException Locked="false" Priority="22" QFormat="true" Name="Strong"/>
<w:LsdException Locked="false" Priority="20" QFormat="true" Name="Emphasis"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Document Map"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Plain Text"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="E-mail Signature"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="HTML Top of Form"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="HTML Bottom of Form"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Normal (Web)"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="HTML Acronym"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="HTML Address"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="HTML Cite"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="HTML Code"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="HTML Definition"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="HTML Keyboard"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="HTML Preformatted"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="HTML Sample"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="HTML Typewriter"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="HTML Variable"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Normal Table"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="annotation subject"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="No List"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Outline List 1"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Outline List 2"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Outline List 3"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Table Simple 1"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Table Simple 2"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Table Simple 3"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Table Classic 1"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Table Classic 2"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Table Classic 3"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Table Classic 4"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Table Colorful 1"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Table Colorful 2"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Table Colorful 3"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Table Columns 1"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Table Columns 2"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Table Columns 3"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Table Columns 4"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Table Columns 5"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Table Grid 1"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Table Grid 2"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Table Grid 3"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Table Grid 4"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Table Grid 5"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Table Grid 6"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Table Grid 7"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Table Grid 8"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Table List 1"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Table List 2"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Table List 3"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Table List 4"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Table List 5"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Table List 6"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Table List 7"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Table List 8"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Table 3D effects 1"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Table 3D effects 2"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Table 3D effects 3"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Table Contemporary"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Table Elegant"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Table Professional"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Table Subtle 1"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Table Subtle 2"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Table Web 1"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Table Web 2"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Table Web 3"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Balloon Text"/>
<w:LsdException Locked="false" Priority="39" Name="Table Grid"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Table Theme"/>
<w:LsdException Locked="false" SemiHidden="true" Name="Placeholder Text"/>
<w:LsdException Locked="false" Priority="1" QFormat="true" Name="No Spacing"/>
<w:LsdException Locked="false" Priority="60" Name="Light Shading"/>
<w:LsdException Locked="false" Priority="61" Name="Light List"/>
<w:LsdException Locked="false" Priority="62" Name="Light Grid"/>
<w:LsdException Locked="false" Priority="63" Name="Medium Shading 1"/>
<w:LsdException Locked="false" Priority="64" Name="Medium Shading 2"/>
<w:LsdException Locked="false" Priority="65" Name="Medium List 1"/>
<w:LsdException Locked="false" Priority="66" Name="Medium List 2"/>
<w:LsdException Locked="false" Priority="67" Name="Medium Grid 1"/>
<w:LsdException Locked="false" Priority="68" Name="Medium Grid 2"/>
<w:LsdException Locked="false" Priority="69" Name="Medium Grid 3"/>
<w:LsdException Locked="false" Priority="70" Name="Dark List"/>
<w:LsdException Locked="false" Priority="71" Name="Colorful Shading"/>
<w:LsdException Locked="false" Priority="72" Name="Colorful List"/>
<w:LsdException Locked="false" Priority="73" Name="Colorful Grid"/>
<w:LsdException Locked="false" Priority="60" Name="Light Shading Accent 1"/>
<w:LsdException Locked="false" Priority="61" Name="Light List Accent 1"/>
<w:LsdException Locked="false" Priority="62" Name="Light Grid Accent 1"/>
<w:LsdException Locked="false" Priority="63" Name="Medium Shading 1 Accent 1"/>
<w:LsdException Locked="false" Priority="64" Name="Medium Shading 2 Accent 1"/>
<w:LsdException Locked="false" Priority="65" Name="Medium List 1 Accent 1"/>
<w:LsdException Locked="false" SemiHidden="true" Name="Revision"/>
<w:LsdException Locked="false" Priority="34" QFormat="true"
Name="List Paragraph"/>
<w:LsdException Locked="false" Priority="29" QFormat="true" Name="Quote"/>
<w:LsdException Locked="false" Priority="30" QFormat="true"
Name="Intense Quote"/>
<w:LsdException Locked="false" Priority="66" Name="Medium List 2 Accent 1"/>
<w:LsdException Locked="false" Priority="67" Name="Medium Grid 1 Accent 1"/>
<w:LsdException Locked="false" Priority="68" Name="Medium Grid 2 Accent 1"/>
<w:LsdException Locked="false" Priority="69" Name="Medium Grid 3 Accent 1"/>
<w:LsdException Locked="false" Priority="70" Name="Dark List Accent 1"/>
<w:LsdException Locked="false" Priority="71" Name="Colorful Shading Accent 1"/>
<w:LsdException Locked="false" Priority="72" Name="Colorful List Accent 1"/>
<w:LsdException Locked="false" Priority="73" Name="Colorful Grid Accent 1"/>
<w:LsdException Locked="false" Priority="60" Name="Light Shading Accent 2"/>
<w:LsdException Locked="false" Priority="61" Name="Light List Accent 2"/>
<w:LsdException Locked="false" Priority="62" Name="Light Grid Accent 2"/>
<w:LsdException Locked="false" Priority="63" Name="Medium Shading 1 Accent 2"/>
<w:LsdException Locked="false" Priority="64" Name="Medium Shading 2 Accent 2"/>
<w:LsdException Locked="false" Priority="65" Name="Medium List 1 Accent 2"/>
<w:LsdException Locked="false" Priority="66" Name="Medium List 2 Accent 2"/>
<w:LsdException Locked="false" Priority="67" Name="Medium Grid 1 Accent 2"/>
<w:LsdException Locked="false" Priority="68" Name="Medium Grid 2 Accent 2"/>
<w:LsdException Locked="false" Priority="69" Name="Medium Grid 3 Accent 2"/>
<w:LsdException Locked="false" Priority="70" Name="Dark List Accent 2"/>
<w:LsdException Locked="false" Priority="71" Name="Colorful Shading Accent 2"/>
<w:LsdException Locked="false" Priority="72" Name="Colorful List Accent 2"/>
<w:LsdException Locked="false" Priority="73" Name="Colorful Grid Accent 2"/>
<w:LsdException Locked="false" Priority="60" Name="Light Shading Accent 3"/>
<w:LsdException Locked="false" Priority="61" Name="Light List Accent 3"/>
<w:LsdException Locked="false" Priority="62" Name="Light Grid Accent 3"/>
<w:LsdException Locked="false" Priority="63" Name="Medium Shading 1 Accent 3"/>
<w:LsdException Locked="false" Priority="64" Name="Medium Shading 2 Accent 3"/>
<w:LsdException Locked="false" Priority="65" Name="Medium List 1 Accent 3"/>
<w:LsdException Locked="false" Priority="66" Name="Medium List 2 Accent 3"/>
<w:LsdException Locked="false" Priority="67" Name="Medium Grid 1 Accent 3"/>
<w:LsdException Locked="false" Priority="68" Name="Medium Grid 2 Accent 3"/>
<w:LsdException Locked="false" Priority="69" Name="Medium Grid 3 Accent 3"/>
<w:LsdException Locked="false" Priority="70" Name="Dark List Accent 3"/>
<w:LsdException Locked="false" Priority="71" Name="Colorful Shading Accent 3"/>
<w:LsdException Locked="false" Priority="72" Name="Colorful List Accent 3"/>
<w:LsdException Locked="false" Priority="73" Name="Colorful Grid Accent 3"/>
<w:LsdException Locked="false" Priority="60" Name="Light Shading Accent 4"/>
<w:LsdException Locked="false" Priority="61" Name="Light List Accent 4"/>
<w:LsdException Locked="false" Priority="62" Name="Light Grid Accent 4"/>
<w:LsdException Locked="false" Priority="63" Name="Medium Shading 1 Accent 4"/>
<w:LsdException Locked="false" Priority="64" Name="Medium Shading 2 Accent 4"/>
<w:LsdException Locked="false" Priority="65" Name="Medium List 1 Accent 4"/>
<w:LsdException Locked="false" Priority="66" Name="Medium List 2 Accent 4"/>
<w:LsdException Locked="false" Priority="67" Name="Medium Grid 1 Accent 4"/>
<w:LsdException Locked="false" Priority="68" Name="Medium Grid 2 Accent 4"/>
<w:LsdException Locked="false" Priority="69" Name="Medium Grid 3 Accent 4"/>
<w:LsdException Locked="false" Priority="70" Name="Dark List Accent 4"/>
<w:LsdException Locked="false" Priority="71" Name="Colorful Shading Accent 4"/>
<w:LsdException Locked="false" Priority="72" Name="Colorful List Accent 4"/>
<w:LsdException Locked="false" Priority="73" Name="Colorful Grid Accent 4"/>
<w:LsdException Locked="false" Priority="60" Name="Light Shading Accent 5"/>
<w:LsdException Locked="false" Priority="61" Name="Light List Accent 5"/>
<w:LsdException Locked="false" Priority="62" Name="Light Grid Accent 5"/>
<w:LsdException Locked="false" Priority="63" Name="Medium Shading 1 Accent 5"/>
<w:LsdException Locked="false" Priority="64" Name="Medium Shading 2 Accent 5"/>
<w:LsdException Locked="false" Priority="65" Name="Medium List 1 Accent 5"/>
<w:LsdException Locked="false" Priority="66" Name="Medium List 2 Accent 5"/>
<w:LsdException Locked="false" Priority="67" Name="Medium Grid 1 Accent 5"/>
<w:LsdException Locked="false" Priority="68" Name="Medium Grid 2 Accent 5"/>
<w:LsdException Locked="false" Priority="69" Name="Medium Grid 3 Accent 5"/>
<w:LsdException Locked="false" Priority="70" Name="Dark List Accent 5"/>
<w:LsdException Locked="false" Priority="71" Name="Colorful Shading Accent 5"/>
<w:LsdException Locked="false" Priority="72" Name="Colorful List Accent 5"/>
<w:LsdException Locked="false" Priority="73" Name="Colorful Grid Accent 5"/>
<w:LsdException Locked="false" Priority="60" Name="Light Shading Accent 6"/>
<w:LsdException Locked="false" Priority="61" Name="Light List Accent 6"/>
<w:LsdException Locked="false" Priority="62" Name="Light Grid Accent 6"/>
<w:LsdException Locked="false" Priority="63" Name="Medium Shading 1 Accent 6"/>
<w:LsdException Locked="false" Priority="64" Name="Medium Shading 2 Accent 6"/>
<w:LsdException Locked="false" Priority="65" Name="Medium List 1 Accent 6"/>
<w:LsdException Locked="false" Priority="66" Name="Medium List 2 Accent 6"/>
<w:LsdException Locked="false" Priority="67" Name="Medium Grid 1 Accent 6"/>
<w:LsdException Locked="false" Priority="68" Name="Medium Grid 2 Accent 6"/>
<w:LsdException Locked="false" Priority="69" Name="Medium Grid 3 Accent 6"/>
<w:LsdException Locked="false" Priority="70" Name="Dark List Accent 6"/>
<w:LsdException Locked="false" Priority="71" Name="Colorful Shading Accent 6"/>
<w:LsdException Locked="false" Priority="72" Name="Colorful List Accent 6"/>
<w:LsdException Locked="false" Priority="73" Name="Colorful Grid Accent 6"/>
<w:LsdException Locked="false" Priority="19" QFormat="true"
Name="Subtle Emphasis"/>
<w:LsdException Locked="false" Priority="21" QFormat="true"
Name="Intense Emphasis"/>
<w:LsdException Locked="false" Priority="31" QFormat="true"
Name="Subtle Reference"/>
<w:LsdException Locked="false" Priority="32" QFormat="true"
Name="Intense Reference"/>
<w:LsdException Locked="false" Priority="33" QFormat="true" Name="Book Title"/>
<w:LsdException Locked="false" Priority="37" SemiHidden="true"
UnhideWhenUsed="true" Name="Bibliography"/>
<w:LsdException Locked="false" Priority="39" SemiHidden="true"
UnhideWhenUsed="true" QFormat="true" Name="TOC Heading"/>
<w:LsdException Locked="false" Priority="41" Name="Plain Table 1"/>
<w:LsdException Locked="false" Priority="42" Name="Plain Table 2"/>
<w:LsdException Locked="false" Priority="43" Name="Plain Table 3"/>
<w:LsdException Locked="false" Priority="44" Name="Plain Table 4"/>
<w:LsdException Locked="false" Priority="45" Name="Plain Table 5"/>
<w:LsdException Locked="false" Priority="40" Name="Grid Table Light"/>
<w:LsdException Locked="false" Priority="46" Name="Grid Table 1 Light"/>
<w:LsdException Locked="false" Priority="47" Name="Grid Table 2"/>
<w:LsdException Locked="false" Priority="48" Name="Grid Table 3"/>
<w:LsdException Locked="false" Priority="49" Name="Grid Table 4"/>
<w:LsdException Locked="false" Priority="50" Name="Grid Table 5 Dark"/>
<w:LsdException Locked="false" Priority="51" Name="Grid Table 6 Colorful"/>
<w:LsdException Locked="false" Priority="52" Name="Grid Table 7 Colorful"/>
<w:LsdException Locked="false" Priority="46"
Name="Grid Table 1 Light Accent 1"/>
<w:LsdException Locked="false" Priority="47" Name="Grid Table 2 Accent 1"/>
<w:LsdException Locked="false" Priority="48" Name="Grid Table 3 Accent 1"/>
<w:LsdException Locked="false" Priority="49" Name="Grid Table 4 Accent 1"/>
<w:LsdException Locked="false" Priority="50" Name="Grid Table 5 Dark Accent 1"/>
<w:LsdException Locked="false" Priority="51"
Name="Grid Table 6 Colorful Accent 1"/>
<w:LsdException Locked="false" Priority="52"
Name="Grid Table 7 Colorful Accent 1"/>
<w:LsdException Locked="false" Priority="46"
Name="Grid Table 1 Light Accent 2"/>
<w:LsdException Locked="false" Priority="47" Name="Grid Table 2 Accent 2"/>
<w:LsdException Locked="false" Priority="48" Name="Grid Table 3 Accent 2"/>
<w:LsdException Locked="false" Priority="49" Name="Grid Table 4 Accent 2"/>
<w:LsdException Locked="false" Priority="50" Name="Grid Table 5 Dark Accent 2"/>
<w:LsdException Locked="false" Priority="51"
Name="Grid Table 6 Colorful Accent 2"/>
<w:LsdException Locked="false" Priority="52"
Name="Grid Table 7 Colorful Accent 2"/>
<w:LsdException Locked="false" Priority="46"
Name="Grid Table 1 Light Accent 3"/>
<w:LsdException Locked="false" Priority="47" Name="Grid Table 2 Accent 3"/>
<w:LsdException Locked="false" Priority="48" Name="Grid Table 3 Accent 3"/>
<w:LsdException Locked="false" Priority="49" Name="Grid Table 4 Accent 3"/>
<w:LsdException Locked="false" Priority="50" Name="Grid Table 5 Dark Accent 3"/>
<w:LsdException Locked="false" Priority="51"
Name="Grid Table 6 Colorful Accent 3"/>
<w:LsdException Locked="false" Priority="52"
Name="Grid Table 7 Colorful Accent 3"/>
<w:LsdException Locked="false" Priority="46"
Name="Grid Table 1 Light Accent 4"/>
<w:LsdException Locked="false" Priority="47" Name="Grid Table 2 Accent 4"/>
<w:LsdException Locked="false" Priority="48" Name="Grid Table 3 Accent 4"/>
<w:LsdException Locked="false" Priority="49" Name="Grid Table 4 Accent 4"/>
<w:LsdException Locked="false" Priority="50" Name="Grid Table 5 Dark Accent 4"/>
<w:LsdException Locked="false" Priority="51"
Name="Grid Table 6 Colorful Accent 4"/>
<w:LsdException Locked="false" Priority="52"
Name="Grid Table 7 Colorful Accent 4"/>
<w:LsdException Locked="false" Priority="46"
Name="Grid Table 1 Light Accent 5"/>
<w:LsdException Locked="false" Priority="47" Name="Grid Table 2 Accent 5"/>
<w:LsdException Locked="false" Priority="48" Name="Grid Table 3 Accent 5"/>
<w:LsdException Locked="false" Priority="49" Name="Grid Table 4 Accent 5"/>
<w:LsdException Locked="false" Priority="50" Name="Grid Table 5 Dark Accent 5"/>
<w:LsdException Locked="false" Priority="51"
Name="Grid Table 6 Colorful Accent 5"/>
<w:LsdException Locked="false" Priority="52"
Name="Grid Table 7 Colorful Accent 5"/>
<w:LsdException Locked="false" Priority="46"
Name="Grid Table 1 Light Accent 6"/>
<w:LsdException Locked="false" Priority="47" Name="Grid Table 2 Accent 6"/>
<w:LsdException Locked="false" Priority="48" Name="Grid Table 3 Accent 6"/>
<w:LsdException Locked="false" Priority="49" Name="Grid Table 4 Accent 6"/>
<w:LsdException Locked="false" Priority="50" Name="Grid Table 5 Dark Accent 6"/>
<w:LsdException Locked="false" Priority="51"
Name="Grid Table 6 Colorful Accent 6"/>
<w:LsdException Locked="false" Priority="52"
Name="Grid Table 7 Colorful Accent 6"/>
<w:LsdException Locked="false" Priority="46" Name="List Table 1 Light"/>
<w:LsdException Locked="false" Priority="47" Name="List Table 2"/>
<w:LsdException Locked="false" Priority="48" Name="List Table 3"/>
<w:LsdException Locked="false" Priority="49" Name="List Table 4"/>
<w:LsdException Locked="false" Priority="50" Name="List Table 5 Dark"/>
<w:LsdException Locked="false" Priority="51" Name="List Table 6 Colorful"/>
<w:LsdException Locked="false" Priority="52" Name="List Table 7 Colorful"/>
<w:LsdException Locked="false" Priority="46"
Name="List Table 1 Light Accent 1"/>
<w:LsdException Locked="false" Priority="47" Name="List Table 2 Accent 1"/>
<w:LsdException Locked="false" Priority="48" Name="List Table 3 Accent 1"/>
<w:LsdException Locked="false" Priority="49" Name="List Table 4 Accent 1"/>
<w:LsdException Locked="false" Priority="50" Name="List Table 5 Dark Accent 1"/>
<w:LsdException Locked="false" Priority="51"
Name="List Table 6 Colorful Accent 1"/>
<w:LsdException Locked="false" Priority="52"
Name="List Table 7 Colorful Accent 1"/>
<w:LsdException Locked="false" Priority="46"
Name="List Table 1 Light Accent 2"/>
<w:LsdException Locked="false" Priority="47" Name="List Table 2 Accent 2"/>
<w:LsdException Locked="false" Priority="48" Name="List Table 3 Accent 2"/>
<w:LsdException Locked="false" Priority="49" Name="List Table 4 Accent 2"/>
<w:LsdException Locked="false" Priority="50" Name="List Table 5 Dark Accent 2"/>
<w:LsdException Locked="false" Priority="51"
Name="List Table 6 Colorful Accent 2"/>
<w:LsdException Locked="false" Priority="52"
Name="List Table 7 Colorful Accent 2"/>
<w:LsdException Locked="false" Priority="46"
Name="List Table 1 Light Accent 3"/>
<w:LsdException Locked="false" Priority="47" Name="List Table 2 Accent 3"/>
<w:LsdException Locked="false" Priority="48" Name="List Table 3 Accent 3"/>
<w:LsdException Locked="false" Priority="49" Name="List Table 4 Accent 3"/>
<w:LsdException Locked="false" Priority="50" Name="List Table 5 Dark Accent 3"/>
<w:LsdException Locked="false" Priority="51"
Name="List Table 6 Colorful Accent 3"/>
<w:LsdException Locked="false" Priority="52"
Name="List Table 7 Colorful Accent 3"/>
<w:LsdException Locked="false" Priority="46"
Name="List Table 1 Light Accent 4"/>
<w:LsdException Locked="false" Priority="47" Name="List Table 2 Accent 4"/>
<w:LsdException Locked="false" Priority="48" Name="List Table 3 Accent 4"/>
<w:LsdException Locked="false" Priority="49" Name="List Table 4 Accent 4"/>
<w:LsdException Locked="false" Priority="50" Name="List Table 5 Dark Accent 4"/>
<w:LsdException Locked="false" Priority="51"
Name="List Table 6 Colorful Accent 4"/>
<w:LsdException Locked="false" Priority="52"
Name="List Table 7 Colorful Accent 4"/>
<w:LsdException Locked="false" Priority="46"
Name="List Table 1 Light Accent 5"/>
<w:LsdException Locked="false" Priority="47" Name="List Table 2 Accent 5"/>
<w:LsdException Locked="false" Priority="48" Name="List Table 3 Accent 5"/>
<w:LsdException Locked="false" Priority="49" Name="List Table 4 Accent 5"/>
<w:LsdException Locked="false" Priority="50" Name="List Table 5 Dark Accent 5"/>
<w:LsdException Locked="false" Priority="51"
Name="List Table 6 Colorful Accent 5"/>
<w:LsdException Locked="false" Priority="52"
Name="List Table 7 Colorful Accent 5"/>
<w:LsdException Locked="false" Priority="46"
Name="List Table 1 Light Accent 6"/>
<w:LsdException Locked="false" Priority="47" Name="List Table 2 Accent 6"/>
<w:LsdException Locked="false" Priority="48" Name="List Table 3 Accent 6"/>
<w:LsdException Locked="false" Priority="49" Name="List Table 4 Accent 6"/>
<w:LsdException Locked="false" Priority="50" Name="List Table 5 Dark Accent 6"/>
<w:LsdException Locked="false" Priority="51"
Name="List Table 6 Colorful Accent 6"/>
<w:LsdException Locked="false" Priority="52"
Name="List Table 7 Colorful Accent 6"/>
</w:LatentStyles>
</xml><![endif]--><!--[if gte mso 10]>
<style>
/* Style Definitions */
table.MsoNormalTable
{mso-style-name:"Table Normal";
mso-tstyle-rowband-size:0;
mso-tstyle-colband-size:0;
mso-style-noshow:yes;
mso-style-priority:99;
mso-style-parent:"";
mso-padding-alt:0in 5.4pt 0in 5.4pt;
mso-para-margin-top:0in;
mso-para-margin-right:0in;
mso-para-margin-bottom:8.0pt;
mso-para-margin-left:0in;
line-height:107%;
mso-pagination:widow-orphan;
font-size:11.0pt;
font-family:"Calibri","sans-serif";
mso-ascii-font-family:Calibri;
mso-ascii-theme-font:minor-latin;
mso-hansi-font-family:Calibri;
mso-hansi-theme-font:minor-latin;
mso-bidi-font-family:"Times New Roman";
mso-bidi-theme-font:minor-bidi;}
</style>
<![endif]--></div>
Anonymoushttp://www.blogger.com/profile/07685598617709117616noreply@blogger.com0tag:blogger.com,1999:blog-1266456599706152053.post-5988534860365229422016-09-06T13:03:00.001+05:302016-09-06T22:55:59.169+05:30Concurrenthashmap Example<div dir="ltr" style="text-align: left;" trbidi="on">
<div dir="ltr" style="text-align: left;" trbidi="on">
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<h2 style="text-align: left;">
<b><span style="color: #7f0055; font-family: "franklin gothic book" , sans-serif; font-size: 12.0pt;"><u>Concurrent HashMap example:</u></span></b></h2>
</div>
<a href="https://www.amazon.com/Beginning-Programming-Java-Dummies-Barry/dp/1118407814/ref=as_li_ss_il?ie=UTF8&qid=1473146362&sr=8-5&keywords=Java&linkCode=li3&tag=javashiv-20&linkId=4f5f799d578ae5d58d9fd40b1fdd47d0" target="_blank"><img border="0" src="//ws-na.amazon-adsystem.com/widgets/q?_encoding=UTF8&ASIN=1118407814&Format=_SL250_&ID=AsinImage&MarketPlace=US&ServiceVersion=20070822&WS=1&tag=javashiv-20" /></a><img alt="" border="0" height="1" src="https://ir-na.amazon-adsystem.com/e/ir?t=javashiv-20&l=li3&o=1&a=1118407814" style="border: none !important; margin: 0px !important;" width="1" />
<br />
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: "franklin gothic book" , sans-serif; font-size: 12pt;">Concurrent HashMap works on the principle of concurrent access of the segment of hashmap.</span><br />
<span style="font-family: "franklin gothic book" , sans-serif; font-size: 12pt;">It partially locks the map which gives better performance.</span><br />
<span style="font-family: "franklin gothic book" , sans-serif; font-size: 12pt;">See the simple example where producer keeps adding the element.</span><br />
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: "franklin gothic book" , sans-serif; font-size: 12pt;"><br /></span>
<span style="font-family: "franklin gothic book" , sans-serif; font-size: 12pt;"> Producing the Element and pushing it in hashmap</span><br />
<span style="font-family: "franklin gothic book" , sans-serif; font-size: 12pt;"> </span><b><span style="color: #7f0055; font-family: "franklin gothic book" , sans-serif; font-size: 12pt;">public</span></b><span style="font-family: "franklin gothic book" , sans-serif; font-size: 12pt;"> </span><b><span style="color: #7f0055; font-family: "franklin gothic book" , sans-serif; font-size: 12pt;">void</span></b><span style="font-family: "franklin gothic book" , sans-serif; font-size: 12pt;"> addValue()</span><span style="font-family: "franklin gothic book" , sans-serif; font-size: 12pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: "franklin gothic book" , sans-serif; font-size: 12pt;"> {</span><span style="font-family: "franklin gothic book" , sans-serif; font-size: 12pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: "franklin gothic book" , sans-serif; font-size: 12pt;"> </span><b><span style="color: #7f0055; font-family: "franklin gothic book" , sans-serif; font-size: 12pt;">for</span></b><span style="font-family: "franklin gothic book" , sans-serif; font-size: 12pt;">(</span><b><span style="color: #7f0055; font-family: "franklin gothic book" , sans-serif; font-size: 12pt;">int</span></b><span style="font-family: "franklin gothic book" , sans-serif; font-size: 12pt;"> </span><span style="color: #6a3e3e; font-family: "franklin gothic book" , sans-serif; font-size: 12pt;">i</span><span style="font-family: "franklin gothic book" , sans-serif; font-size: 12pt;">=0;</span><span style="color: #6a3e3e; font-family: "franklin gothic book" , sans-serif; font-size: 12pt;">i</span><span style="font-family: "franklin gothic book" , sans-serif; font-size: 12pt;"><100;</span><span style="color: #6a3e3e; font-family: "franklin gothic book" , sans-serif; font-size: 12pt;">i</span><span style="font-family: "franklin gothic book" , sans-serif; font-size: 12pt;">++)</span><span style="font-family: "franklin gothic book" , sans-serif; font-size: 12pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: "franklin gothic book" , sans-serif; font-size: 12pt;"> {</span><span style="font-family: "franklin gothic book" , sans-serif; font-size: 12pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: "franklin gothic book" , sans-serif; font-size: 12pt;"> </span><span style="font-family: "franklin gothic book" , sans-serif; font-size: 12pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: "franklin gothic book" , sans-serif; font-size: 12pt;"> Integer </span><span style="color: #6a3e3e; font-family: "franklin gothic book" , sans-serif; font-size: 12pt;">intObj</span><span style="font-family: "franklin gothic book" , sans-serif; font-size: 12pt;">=</span><b><span style="color: #7f0055; font-family: "franklin gothic book" , sans-serif; font-size: 12pt;">new</span></b><span style="font-family: "franklin gothic book" , sans-serif; font-size: 12pt;"> Integer(</span><span style="color: #6a3e3e; font-family: "franklin gothic book" , sans-serif; font-size: 12pt;">i</span><span style="font-family: "franklin gothic book" , sans-serif; font-size: 12pt;">);</span><span style="font-family: "franklin gothic book" , sans-serif; font-size: 12pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: "franklin gothic book" , sans-serif; font-size: 12pt;"> System.</span><b><i><span style="color: #0000c0; font-family: "franklin gothic book" , sans-serif; font-size: 12pt;">out</span></i></b><span style="font-family: "franklin gothic book" , sans-serif; font-size: 12pt;">.println(Thread.<i>currentThread</i>().getName()+</span><span style="color: #2a00ff; font-family: "franklin gothic book" , sans-serif; font-size: 12pt;">"Producing "</span><span style="font-family: "franklin gothic book" , sans-serif; font-size: 12pt;">+</span><span style="color: #6a3e3e; font-family: "franklin gothic book" , sans-serif; font-size: 12pt;">intObj</span><span style="font-family: "franklin gothic book" , sans-serif; font-size: 12pt;">);</span><span style="font-family: "franklin gothic book" , sans-serif; font-size: 12pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: "franklin gothic book" , sans-serif; font-size: 12pt;"> <b> </b></span><b><span style="color: #7f0055; font-family: "franklin gothic book" , sans-serif; font-size: 12pt;">this</span><span style="font-family: "franklin gothic book" , sans-serif; font-size: 12pt;">.</span><span style="color: #0000c0; font-family: "franklin gothic book" , sans-serif; font-size: 12pt;">st</span><span style="font-family: "franklin gothic book" , sans-serif; font-size: 12pt;">.put(</span><span style="color: #6a3e3e; font-family: "franklin gothic book" , sans-serif; font-size: 12pt;">intObj</span><span style="font-family: "franklin gothic book" , sans-serif; font-size: 12pt;">, </span><span style="color: #6a3e3e; font-family: "franklin gothic book" , sans-serif; font-size: 12pt;">intObj</span><span style="font-family: "franklin gothic book" , sans-serif; font-size: 12pt;">);</span></b><span style="font-family: "franklin gothic book" , sans-serif; font-size: 12pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: "franklin gothic book" , sans-serif; font-size: 12pt;"> }</span><span style="font-family: "franklin gothic book" , sans-serif; font-size: 12pt;"><o:p></o:p></span></div>
<span style="font-family: "franklin gothic book" , sans-serif; font-size: 12pt;"></span><br />
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: "franklin gothic book" , sans-serif; font-size: 12pt;"> }</span></div>
</div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<br />
<h3 style="text-align: left;">
<b><span style="color: #7f0055; font-family: "franklin gothic book" , sans-serif; font-size: 12.0pt;"><u>Producer Code:</u></span></b></h3>
</div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<b><span style="color: #7f0055; font-family: "franklin gothic book" , sans-serif; font-size: 12.0pt;"><u><br /></u></span></b></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<b><span style="color: #7f0055; font-family: "franklin gothic book" , sans-serif; font-size: 12.0pt;">import</span></b><span style="font-family: "franklin gothic book" , sans-serif; font-size: 12pt;"> <u>java.util.ArrayList</u>;</span><span style="font-family: "franklin gothic book" , sans-serif; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<b><span style="color: #7f0055; font-family: "franklin gothic book" , sans-serif; font-size: 12.0pt;">import</span></b><span style="font-family: "franklin gothic book" , sans-serif; font-size: 12pt;"> <u>java.util.List</u>;</span><span style="font-family: "franklin gothic book" , sans-serif; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<b><span style="color: #7f0055; font-family: "franklin gothic book" , sans-serif; font-size: 12.0pt;">import</span></b><span style="font-family: "franklin gothic book" , sans-serif; font-size: 12pt;">
java.util.concurrent.ConcurrentHashMap;</span><span style="font-family: "franklin gothic book" , sans-serif; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<b><span style="color: #7f0055; font-family: "franklin gothic book" , sans-serif; font-size: 12.0pt;">class</span></b><span style="font-family: "franklin gothic book" , sans-serif; font-size: 12pt;"> Producer </span><b><span style="color: #7f0055; font-family: "franklin gothic book" , sans-serif; font-size: 12.0pt;">implements</span></b><span style="font-family: "franklin gothic book" , sans-serif; font-size: 12pt;"> Runnable</span><span style="font-family: "franklin gothic book" , sans-serif; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: "franklin gothic book" , sans-serif; font-size: 12pt;">{</span><span style="font-family: "franklin gothic book" , sans-serif; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: "franklin gothic book" , sans-serif; font-size: 12pt;"> </span><b><span style="color: #7f0055; font-family: "franklin gothic book" , sans-serif; font-size: 12.0pt;">void</span></b><span style="font-family: "franklin gothic book" , sans-serif; font-size: 12pt;">
init(ConcurrentHashMap<Integer,Integer> </span><span style="color: #6a3e3e; font-family: "franklin gothic book" , sans-serif; font-size: 12.0pt;">st</span><span style="font-family: "franklin gothic book" , sans-serif; font-size: 12pt;">)</span><span style="font-family: "franklin gothic book" , sans-serif; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: "franklin gothic book" , sans-serif; font-size: 12pt;"> {</span><span style="font-family: "franklin gothic book" , sans-serif; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: "franklin gothic book" , sans-serif; font-size: 12pt;"> </span><b><span style="color: #7f0055; font-family: "franklin gothic book" , sans-serif; font-size: 12.0pt;">this</span></b><span style="font-family: "franklin gothic book" , sans-serif; font-size: 12pt;">.</span><span style="color: #0000c0; font-family: "franklin gothic book" , sans-serif; font-size: 12.0pt;">st</span><span style="font-family: "franklin gothic book" , sans-serif; font-size: 12pt;">=</span><span style="color: #6a3e3e; font-family: "franklin gothic book" , sans-serif; font-size: 12.0pt;">st</span><span style="font-family: "franklin gothic book" , sans-serif; font-size: 12pt;">;</span><span style="font-family: "franklin gothic book" , sans-serif; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: "franklin gothic book" , sans-serif; font-size: 12pt;"> }</span><span style="font-family: "franklin gothic book" , sans-serif; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: "franklin gothic book" , sans-serif; font-size: 12pt;"> ConcurrentHashMap<Integer,Integer>
</span><span style="color: #0000c0; font-family: "franklin gothic book" , sans-serif; font-size: 12.0pt;">st</span><span style="font-family: "franklin gothic book" , sans-serif; font-size: 12pt;">;</span><span style="font-family: "franklin gothic book" , sans-serif; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: "franklin gothic book" , sans-serif; font-size: 12pt;"> </span><b><span style="color: #7f0055; font-family: "franklin gothic book" , sans-serif; font-size: 12.0pt;">public</span></b><span style="font-family: "franklin gothic book" , sans-serif; font-size: 12pt;"> </span><b><span style="color: #7f0055; font-family: "franklin gothic book" , sans-serif; font-size: 12.0pt;">void</span></b><span style="font-family: "franklin gothic book" , sans-serif; font-size: 12pt;"> addValue()</span><span style="font-family: "franklin gothic book" , sans-serif; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: "franklin gothic book" , sans-serif; font-size: 12pt;"> {</span><span style="font-family: "franklin gothic book" , sans-serif; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: "franklin gothic book" , sans-serif; font-size: 12pt;"> </span><b><span style="color: #7f0055; font-family: "franklin gothic book" , sans-serif; font-size: 12.0pt;">for</span></b><span style="font-family: "franklin gothic book" , sans-serif; font-size: 12pt;">(</span><b><span style="color: #7f0055; font-family: "franklin gothic book" , sans-serif; font-size: 12.0pt;">int</span></b><span style="font-family: "franklin gothic book" , sans-serif; font-size: 12pt;"> </span><span style="color: #6a3e3e; font-family: "franklin gothic book" , sans-serif; font-size: 12.0pt;">i</span><span style="font-family: "franklin gothic book" , sans-serif; font-size: 12pt;">=0;</span><span style="color: #6a3e3e; font-family: "franklin gothic book" , sans-serif; font-size: 12.0pt;">i</span><span style="font-family: "franklin gothic book" , sans-serif; font-size: 12pt;"><100;</span><span style="color: #6a3e3e; font-family: "franklin gothic book" , sans-serif; font-size: 12.0pt;">i</span><span style="font-family: "franklin gothic book" , sans-serif; font-size: 12pt;">++)</span><span style="font-family: "franklin gothic book" , sans-serif; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: "franklin gothic book" , sans-serif; font-size: 12pt;"> {</span><span style="font-family: "franklin gothic book" , sans-serif; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: "franklin gothic book" , sans-serif; font-size: 12pt;"> </span><span style="font-family: "franklin gothic book" , sans-serif; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: "franklin gothic book" , sans-serif; font-size: 12pt;"> Integer
</span><span style="color: #6a3e3e; font-family: "franklin gothic book" , sans-serif; font-size: 12.0pt;">intObj</span><span style="font-family: "franklin gothic book" , sans-serif; font-size: 12pt;">=</span><b><span style="color: #7f0055; font-family: "franklin gothic book" , sans-serif; font-size: 12.0pt;">new</span></b><span style="font-family: "franklin gothic book" , sans-serif; font-size: 12pt;"> Integer(</span><span style="color: #6a3e3e; font-family: "franklin gothic book" , sans-serif; font-size: 12.0pt;">i</span><span style="font-family: "franklin gothic book" , sans-serif; font-size: 12pt;">);</span><span style="font-family: "franklin gothic book" , sans-serif; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: "franklin gothic book" , sans-serif; font-size: 12pt;"> System.</span><b><i><span style="color: #0000c0; font-family: "franklin gothic book" , sans-serif; font-size: 12.0pt;">out</span></i></b><span style="font-family: "franklin gothic book" , sans-serif; font-size: 12pt;">.println(Thread.<i>currentThread</i>().getName()+</span><span style="color: #2a00ff; font-family: "franklin gothic book" , sans-serif; font-size: 12.0pt;">"Producing
"</span><span style="font-family: "franklin gothic book" , sans-serif; font-size: 12pt;">+</span><span style="color: #6a3e3e; font-family: "franklin gothic book" , sans-serif; font-size: 12.0pt;">intObj</span><span style="font-family: "franklin gothic book" , sans-serif; font-size: 12pt;">);</span><span style="font-family: "franklin gothic book" , sans-serif; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: "franklin gothic book" , sans-serif; font-size: 12pt;"> </span><b><span style="color: #7f0055; font-family: "franklin gothic book" , sans-serif; font-size: 12.0pt;">this</span></b><span style="font-family: "franklin gothic book" , sans-serif; font-size: 12pt;">.</span><span style="color: #0000c0; font-family: "franklin gothic book" , sans-serif; font-size: 12.0pt;">st</span><span style="font-family: "franklin gothic book" , sans-serif; font-size: 12pt;">.put(</span><span style="color: #6a3e3e; font-family: "franklin gothic book" , sans-serif; font-size: 12.0pt;">intObj</span><span style="font-family: "franklin gothic book" , sans-serif; font-size: 12pt;">, </span><span style="color: #6a3e3e; font-family: "franklin gothic book" , sans-serif; font-size: 12.0pt;">intObj</span><span style="font-family: "franklin gothic book" , sans-serif; font-size: 12pt;">);</span><span style="font-family: "franklin gothic book" , sans-serif; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: "franklin gothic book" , sans-serif; font-size: 12pt;"> }</span><span style="font-family: "franklin gothic book" , sans-serif; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: "franklin gothic book" , sans-serif; font-size: 12pt;"> }</span><span style="font-family: "franklin gothic book" , sans-serif; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: "franklin gothic book" , sans-serif; font-size: 12pt;"> </span><span style="font-family: "franklin gothic book" , sans-serif; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: "franklin gothic book" , sans-serif; font-size: 12pt;"> </span><span style="color: #646464; font-family: "franklin gothic book" , sans-serif; font-size: 12.0pt;">@Override</span><span style="font-family: "franklin gothic book" , sans-serif; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: "franklin gothic book" , sans-serif; font-size: 12pt;"> </span><b><span style="color: #7f0055; font-family: "franklin gothic book" , sans-serif; font-size: 12.0pt;">public</span></b><span style="font-family: "franklin gothic book" , sans-serif; font-size: 12pt;"> </span><b><span style="color: #7f0055; font-family: "franklin gothic book" , sans-serif; font-size: 12.0pt;">void</span></b><span style="font-family: "franklin gothic book" , sans-serif; font-size: 12pt;"> run() {</span><span style="font-family: "franklin gothic book" , sans-serif; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: "franklin gothic book" , sans-serif; font-size: 12pt;"> </span><span style="font-family: "franklin gothic book" , sans-serif; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: "franklin gothic book" , sans-serif; font-size: 12pt;"> addValue();</span><span style="font-family: "franklin gothic book" , sans-serif; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: "franklin gothic book" , sans-serif; font-size: 12pt;"> }</span><span style="font-family: "franklin gothic book" , sans-serif; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: "franklin gothic book" , sans-serif; font-size: 12pt;"> </span><span style="font-family: "franklin gothic book" , sans-serif; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: "franklin gothic book" , sans-serif; font-size: 12pt;">}</span><span style="font-family: "franklin gothic book" , sans-serif; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<h3 style="text-align: left;">
<br /><b><span style="color: #7f0055; font-family: "franklin gothic book" , sans-serif; font-size: 12.0pt;">Consumer</span></b></h3>
</div>
<iframe border="0" frameborder="0" height="250" marginwidth="0" scrolling="no" src="//rcm-na.amazon-adsystem.com/e/cm?o=1&p=12&l=ur1&category=amzn_fashion_sts_sept16&banner=169WEVP7BKKEX6FMN182&f=ifr&lc=pf4&linkID=c63f10d11ab4a2a75284812e5c093223&t=javashiv-20&tracking_id=javashiv-20" style="border: none;" width="300"></iframe>
<iframe border="0" frameborder="0" height="250" marginwidth="0" scrolling="no" src="//rcm-na.amazon-adsystem.com/e/cm?o=1&p=12&l=ur1&category=primemain&banner=1MDTME9E9G651CJTDA82&f=ifr&lc=pf4&linkID=ffdc8d7ff959cf683b07dcdb3f0900fb&t=javashiv-20&tracking_id=javashiv-20" style="border: none;" width="300"></iframe>
<br />
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<b><span style="color: #7f0055; font-family: "franklin gothic book" , sans-serif; font-size: 12.0pt;"><br /></span></b></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="color: #7f0055; font-family: "franklin gothic book" , sans-serif; font-size: 12.0pt;"><span style="font-size: 12pt;"><b style="color: #7f0055;">Consumer part:</b></span></span><br />
<span style="color: #7f0055; font-family: "franklin gothic book" , sans-serif; font-size: 12.0pt;"><span style="font-size: 12pt;">Consumer keeps on </span>utilizing<span style="font-size: 12pt;"> whatever is present in the hashmap. While producing or </span>retrieving<span style="font-size: 12pt;"> we did not </span>encounter<span style="font-size: 12pt;"> <b>ConcurrentModificationException </b>example.</span></span><br />
<span style="color: #7f0055; font-family: "franklin gothic book" , sans-serif; font-size: 12.0pt;"><span style="font-size: 12pt;">How to create Consumer code we will use get() that will be called by Thread Object.</span></span><br />
<span style="color: #7f0055; font-family: "franklin gothic book" , sans-serif; font-size: 12.0pt;"><span style="font-size: 12pt;"><br /></span></span>
<br />
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: "franklin gothic book" , sans-serif; font-size: 12pt;"> </span><b><span style="color: #7f0055; font-family: "franklin gothic book" , sans-serif; font-size: 12pt;">public</span></b><span style="font-family: "franklin gothic book" , sans-serif; font-size: 12pt;"> </span><b><span style="color: #7f0055; font-family: "franklin gothic book" , sans-serif; font-size: 12pt;">void</span></b><span style="font-family: "franklin gothic book" , sans-serif; font-size: 12pt;"> getValue()</span><span style="font-family: "franklin gothic book" , sans-serif; font-size: 12pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: "franklin gothic book" , sans-serif; font-size: 12pt;"> {</span><span style="font-family: "franklin gothic book" , sans-serif; font-size: 12pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: "franklin gothic book" , sans-serif; font-size: 12pt;"> </span><span style="font-family: "franklin gothic book" , sans-serif; font-size: 12pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: "franklin gothic book" , sans-serif; font-size: 12pt;"> </span><b><span style="color: #7f0055; font-family: "franklin gothic book" , sans-serif; font-size: 12pt;">for</span></b><span style="font-family: "franklin gothic book" , sans-serif; font-size: 12pt;">(</span><b><span style="color: #7f0055; font-family: "franklin gothic book" , sans-serif; font-size: 12pt;">int</span></b><span style="font-family: "franklin gothic book" , sans-serif; font-size: 12pt;"> </span><span style="color: #6a3e3e; font-family: "franklin gothic book" , sans-serif; font-size: 12pt;">i</span><span style="font-family: "franklin gothic book" , sans-serif; font-size: 12pt;">=0;</span><span style="color: #6a3e3e; font-family: "franklin gothic book" , sans-serif; font-size: 12pt;">i</span><span style="font-family: "franklin gothic book" , sans-serif; font-size: 12pt;"><100;</span><span style="color: #6a3e3e; font-family: "franklin gothic book" , sans-serif; font-size: 12pt;">i</span><span style="font-family: "franklin gothic book" , sans-serif; font-size: 12pt;">++)</span><span style="font-family: "franklin gothic book" , sans-serif; font-size: 12pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: "franklin gothic book" , sans-serif; font-size: 12pt;"> {</span><span style="font-family: "franklin gothic book" , sans-serif; font-size: 12pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: "franklin gothic book" , sans-serif; font-size: 12pt;"> </span><span style="font-family: "franklin gothic book" , sans-serif; font-size: 12pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: "franklin gothic book" , sans-serif; font-size: 12pt;"> System.</span><b><i><span style="color: #0000c0; font-family: "franklin gothic book" , sans-serif; font-size: 12pt;">out</span></i></b><span style="font-family: "franklin gothic book" , sans-serif; font-size: 12pt;">.println(Thread.<i>currentThread</i>().getName()+ </span><span style="color: #2a00ff; font-family: "franklin gothic book" , sans-serif; font-size: 12pt;">"Consuming "</span><span style="font-family: "franklin gothic book" , sans-serif; font-size: 12pt;">+</span><b><span style="color: #7f0055; font-family: "franklin gothic book" , sans-serif; font-size: 12pt;">this</span></b><span style="font-family: "franklin gothic book" , sans-serif; font-size: 12pt;">.</span><span style="color: #0000c0; font-family: "franklin gothic book" , sans-serif; font-size: 12pt;">st</span><span style="font-family: "franklin gothic book" , sans-serif; font-size: 12pt;">.get(</span><span style="color: #6a3e3e; font-family: "franklin gothic book" , sans-serif; font-size: 12pt;">i</span><span style="font-family: "franklin gothic book" , sans-serif; font-size: 12pt;">));</span><span style="font-family: "franklin gothic book" , sans-serif; font-size: 12pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: "franklin gothic book" , sans-serif; font-size: 12pt;"> }</span><span style="font-family: "franklin gothic book" , sans-serif; font-size: 12pt;"><o:p></o:p></span></div>
<span style="color: #7f0055; font-family: "franklin gothic book" , sans-serif; font-size: 12.0pt;"></span><br />
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: "franklin gothic book" , sans-serif; font-size: 12pt;"> }</span><br />
<span style="font-family: "franklin gothic book" , sans-serif; font-size: 12pt;"><br /></span></div>
<b><span style="color: #7f0055; font-family: "franklin gothic book" , sans-serif; font-size: 12.0pt;"><br /></span></b>
<b><span style="color: #7f0055; font-family: "franklin gothic book" , sans-serif; font-size: 12.0pt;">class</span></b><span style="font-family: "franklin gothic book" , sans-serif; font-size: 12pt;"> Consumer </span><b><span style="color: #7f0055; font-family: "franklin gothic book" , sans-serif; font-size: 12.0pt;">implements</span></b><span style="font-family: "franklin gothic book" , sans-serif; font-size: 12pt;"> Runnable</span><span style="font-family: "franklin gothic book" , sans-serif; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: "franklin gothic book" , sans-serif; font-size: 12pt;">{</span><span style="font-family: "franklin gothic book" , sans-serif; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: "franklin gothic book" , sans-serif; font-size: 12pt;"> </span><b><span style="color: #7f0055; font-family: "franklin gothic book" , sans-serif; font-size: 12.0pt;">void</span></b><span style="font-family: "franklin gothic book" , sans-serif; font-size: 12pt;">
init(ConcurrentHashMap<Integer,Integer> </span><span style="color: #6a3e3e; font-family: "franklin gothic book" , sans-serif; font-size: 12.0pt;">st</span><span style="font-family: "franklin gothic book" , sans-serif; font-size: 12pt;">)</span><span style="font-family: "franklin gothic book" , sans-serif; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: "franklin gothic book" , sans-serif; font-size: 12pt;"> {</span><span style="font-family: "franklin gothic book" , sans-serif; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: "franklin gothic book" , sans-serif; font-size: 12pt;"> </span><b><span style="color: #7f0055; font-family: "franklin gothic book" , sans-serif; font-size: 12.0pt;">this</span></b><span style="font-family: "franklin gothic book" , sans-serif; font-size: 12pt;">.</span><span style="color: #0000c0; font-family: "franklin gothic book" , sans-serif; font-size: 12.0pt;">st</span><span style="font-family: "franklin gothic book" , sans-serif; font-size: 12pt;">=</span><span style="color: #6a3e3e; font-family: "franklin gothic book" , sans-serif; font-size: 12.0pt;">st</span><span style="font-family: "franklin gothic book" , sans-serif; font-size: 12pt;">;</span><span style="font-family: "franklin gothic book" , sans-serif; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: "franklin gothic book" , sans-serif; font-size: 12pt;"> }</span><span style="font-family: "franklin gothic book" , sans-serif; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: "franklin gothic book" , sans-serif; font-size: 12pt;"> ConcurrentHashMap<Integer,Integer>
</span><span style="color: #0000c0; font-family: "franklin gothic book" , sans-serif; font-size: 12.0pt;">st</span><span style="font-family: "franklin gothic book" , sans-serif; font-size: 12pt;">;</span><span style="font-family: "franklin gothic book" , sans-serif; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: "franklin gothic book" , sans-serif; font-size: 12pt;"> </span><span style="font-family: "franklin gothic book" , sans-serif; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: "franklin gothic book" , sans-serif; font-size: 12pt;"> </span><b><span style="color: #7f0055; font-family: "franklin gothic book" , sans-serif; font-size: 12.0pt;">public</span></b><span style="font-family: "franklin gothic book" , sans-serif; font-size: 12pt;"> </span><b><span style="color: #7f0055; font-family: "franklin gothic book" , sans-serif; font-size: 12.0pt;">void</span></b><span style="font-family: "franklin gothic book" , sans-serif; font-size: 12pt;"> getValue()</span><span style="font-family: "franklin gothic book" , sans-serif; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: "franklin gothic book" , sans-serif; font-size: 12pt;"> {</span><span style="font-family: "franklin gothic book" , sans-serif; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: "franklin gothic book" , sans-serif; font-size: 12pt;"> </span><span style="font-family: "franklin gothic book" , sans-serif; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: "franklin gothic book" , sans-serif; font-size: 12pt;"> </span><b><span style="color: #7f0055; font-family: "franklin gothic book" , sans-serif; font-size: 12.0pt;">for</span></b><span style="font-family: "franklin gothic book" , sans-serif; font-size: 12pt;">(</span><b><span style="color: #7f0055; font-family: "franklin gothic book" , sans-serif; font-size: 12.0pt;">int</span></b><span style="font-family: "franklin gothic book" , sans-serif; font-size: 12pt;"> </span><span style="color: #6a3e3e; font-family: "franklin gothic book" , sans-serif; font-size: 12.0pt;">i</span><span style="font-family: "franklin gothic book" , sans-serif; font-size: 12pt;">=0;</span><span style="color: #6a3e3e; font-family: "franklin gothic book" , sans-serif; font-size: 12.0pt;">i</span><span style="font-family: "franklin gothic book" , sans-serif; font-size: 12pt;"><100;</span><span style="color: #6a3e3e; font-family: "franklin gothic book" , sans-serif; font-size: 12.0pt;">i</span><span style="font-family: "franklin gothic book" , sans-serif; font-size: 12pt;">++)</span><span style="font-family: "franklin gothic book" , sans-serif; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: "franklin gothic book" , sans-serif; font-size: 12pt;"> {</span><span style="font-family: "franklin gothic book" , sans-serif; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: "franklin gothic book" , sans-serif; font-size: 12pt;"> </span><span style="font-family: "franklin gothic book" , sans-serif; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: "franklin gothic book" , sans-serif; font-size: 12pt;"> System.</span><b><i><span style="color: #0000c0; font-family: "franklin gothic book" , sans-serif; font-size: 12.0pt;">out</span></i></b><span style="font-family: "franklin gothic book" , sans-serif; font-size: 12pt;">.println(Thread.<i>currentThread</i>().getName()+
</span><span style="color: #2a00ff; font-family: "franklin gothic book" , sans-serif; font-size: 12.0pt;">"Consuming
"</span><span style="font-family: "franklin gothic book" , sans-serif; font-size: 12pt;">+</span><b><span style="color: #7f0055; font-family: "franklin gothic book" , sans-serif; font-size: 12.0pt;">this</span></b><span style="font-family: "franklin gothic book" , sans-serif; font-size: 12pt;">.</span><span style="color: #0000c0; font-family: "franklin gothic book" , sans-serif; font-size: 12.0pt;">st</span><span style="font-family: "franklin gothic book" , sans-serif; font-size: 12pt;">.get(</span><span style="color: #6a3e3e; font-family: "franklin gothic book" , sans-serif; font-size: 12.0pt;">i</span><span style="font-family: "franklin gothic book" , sans-serif; font-size: 12pt;">));</span><span style="font-family: "franklin gothic book" , sans-serif; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: "franklin gothic book" , sans-serif; font-size: 12pt;"> }</span><span style="font-family: "franklin gothic book" , sans-serif; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: "franklin gothic book" , sans-serif; font-size: 12pt;"> }</span><span style="font-family: "franklin gothic book" , sans-serif; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: "franklin gothic book" , sans-serif; font-size: 12pt;"> </span><span style="color: #646464; font-family: "franklin gothic book" , sans-serif; font-size: 12.0pt;">@Override</span><span style="font-family: "franklin gothic book" , sans-serif; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: "franklin gothic book" , sans-serif; font-size: 12pt;"> </span><b><span style="color: #7f0055; font-family: "franklin gothic book" , sans-serif; font-size: 12.0pt;">public</span></b><span style="font-family: "franklin gothic book" , sans-serif; font-size: 12pt;"> </span><b><span style="color: #7f0055; font-family: "franklin gothic book" , sans-serif; font-size: 12.0pt;">void</span></b><span style="font-family: "franklin gothic book" , sans-serif; font-size: 12pt;"> run() {</span><span style="font-family: "franklin gothic book" , sans-serif; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: "franklin gothic book" , sans-serif; font-size: 12pt;"> </span><span style="font-family: "franklin gothic book" , sans-serif; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: "franklin gothic book" , sans-serif; font-size: 12pt;"> getValue();</span><span style="font-family: "franklin gothic book" , sans-serif; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: "franklin gothic book" , sans-serif; font-size: 12pt;"> }</span><span style="font-family: "franklin gothic book" , sans-serif; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: "franklin gothic book" , sans-serif; font-size: 12pt;"> </span><span style="font-family: "franklin gothic book" , sans-serif; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: "franklin gothic book" , sans-serif; font-size: 12pt;">}</span><span style="font-family: "franklin gothic book" , sans-serif; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: "franklin gothic book" , sans-serif; font-size: 12pt;"><br /></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<b><span style="color: #7f0055; font-family: "franklin gothic book" , sans-serif; font-size: 12.0pt;">Test Main:</span></b></div>
<a href="https://www.amazon.com/gp/product/B01GKJQN8C/ref=as_li_ss_il?ie=UTF8&linkCode=li3&tag=&linkId=4521bf7a9cce9667212ec6da34f5b0f3" target="_blank"><img border="0" src="//ws-na.amazon-adsystem.com/widgets/q?_encoding=UTF8&ASIN=B01GKJQN8C&Format=_SL250_&ID=AsinImage&MarketPlace=US&ServiceVersion=20070822&WS=1&tag=" /></a><img alt="" border="0" height="1" src="https://ir-na.amazon-adsystem.com/e/ir?t=&l=li3&o=1&a=B01GKJQN8C" style="border: none !important; margin: 0px !important;" width="1" />
<br />
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<b><span style="color: #7f0055; font-family: "franklin gothic book" , sans-serif; font-size: 12.0pt;"><br /></span></b></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<b><span style="color: #7f0055; font-family: "franklin gothic book" , sans-serif; font-size: 12.0pt;">public</span></b><span style="font-family: "franklin gothic book" , sans-serif; font-size: 12pt;"> </span><b><span style="color: #7f0055; font-family: "franklin gothic book" , sans-serif; font-size: 12.0pt;">class</span></b><span style="font-family: "franklin gothic book" , sans-serif; font-size: 12pt;"> HelloWorld{</span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<br /></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: "franklin gothic book" , sans-serif; font-size: 12pt;"> </span><b><span style="color: #7f0055; font-family: "franklin gothic book" , sans-serif; font-size: 12.0pt;">public</span></b><span style="font-family: "franklin gothic book" , sans-serif; font-size: 12pt;"> </span><b><span style="color: #7f0055; font-family: "franklin gothic book" , sans-serif; font-size: 12.0pt;">static</span></b><span style="font-family: "franklin gothic book" , sans-serif; font-size: 12pt;"> </span><b><span style="color: #7f0055; font-family: "franklin gothic book" , sans-serif; font-size: 12.0pt;">void</span></b><span style="font-family: "franklin gothic book" , sans-serif; font-size: 12pt;"> main(String []</span><span style="color: #6a3e3e; font-family: "franklin gothic book" , sans-serif; font-size: 12.0pt;">args</span><span style="font-family: "franklin gothic book" , sans-serif; font-size: 12pt;">){</span><span style="font-family: "franklin gothic book" , sans-serif; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: "franklin gothic book" , sans-serif; font-size: 12pt;"> ConcurrentHashMap<Integer,Integer> </span><span style="color: #6a3e3e; font-family: "franklin gothic book" , sans-serif; font-size: 12.0pt;">st</span><span style="font-family: "franklin gothic book" , sans-serif; font-size: 12pt;">=</span><b><span style="color: #7f0055; font-family: "franklin gothic book" , sans-serif; font-size: 12.0pt;">new</span></b><span style="font-family: "franklin gothic book" , sans-serif; font-size: 12pt;">
ConcurrentHashMap<Integer, Integer>();</span><span style="font-family: "franklin gothic book" , sans-serif; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: "franklin gothic book" , sans-serif; font-size: 12pt;"> Producer </span><span style="color: #6a3e3e; font-family: "franklin gothic book" , sans-serif; font-size: 12.0pt;">hashObj</span><span style="font-family: "franklin gothic book" , sans-serif; font-size: 12pt;">=</span><b><span style="color: #7f0055; font-family: "franklin gothic book" , sans-serif; font-size: 12.0pt;">new</span></b><span style="font-family: "franklin gothic book" , sans-serif; font-size: 12pt;"> Producer();</span><span style="font-family: "franklin gothic book" , sans-serif; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: "franklin gothic book" , sans-serif; font-size: 12pt;"> </span><span style="color: #6a3e3e; font-family: "franklin gothic book" , sans-serif; font-size: 12.0pt;">hashObj</span><span style="font-family: "franklin gothic book" , sans-serif; font-size: 12pt;">.init(</span><span style="color: #6a3e3e; font-family: "franklin gothic book" , sans-serif; font-size: 12.0pt;">st</span><span style="font-family: "franklin gothic book" , sans-serif; font-size: 12pt;">);</span><span style="font-family: "franklin gothic book" , sans-serif; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: "franklin gothic book" , sans-serif; font-size: 12pt;"> Thread </span><span style="color: #6a3e3e; font-family: "franklin gothic book" , sans-serif; font-size: 12.0pt;">t2</span><span style="font-family: "franklin gothic book" , sans-serif; font-size: 12pt;">=</span><b><span style="color: #7f0055; font-family: "franklin gothic book" , sans-serif; font-size: 12.0pt;">new</span></b><span style="font-family: "franklin gothic book" , sans-serif; font-size: 12pt;"> Thread(</span><span style="color: #6a3e3e; font-family: "franklin gothic book" , sans-serif; font-size: 12.0pt;">hashObj</span><span style="font-family: "franklin gothic book" , sans-serif; font-size: 12pt;">);</span><span style="font-family: "franklin gothic book" , sans-serif; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: "franklin gothic book" , sans-serif; font-size: 12pt;"> </span><span style="color: #6a3e3e; font-family: "franklin gothic book" , sans-serif; font-size: 12.0pt;">t2</span><span style="font-family: "franklin gothic book" , sans-serif; font-size: 12pt;">.setName(</span><span style="color: #2a00ff; font-family: "franklin gothic book" , sans-serif; font-size: 12.0pt;">"t2 "</span><span style="font-family: "franklin gothic book" , sans-serif; font-size: 12pt;">);</span><span style="font-family: "franklin gothic book" , sans-serif; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: "franklin gothic book" , sans-serif; font-size: 12pt;"> </span><span style="color: #6a3e3e; font-family: "franklin gothic book" , sans-serif; font-size: 12.0pt;">t2</span><span style="font-family: "franklin gothic book" , sans-serif; font-size: 12pt;">.start();</span><span style="font-family: "franklin gothic book" , sans-serif; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: "franklin gothic book" , sans-serif; font-size: 12pt;"> Thread </span><span style="color: #6a3e3e; font-family: "franklin gothic book" , sans-serif; font-size: 12.0pt;">t3</span><span style="font-family: "franklin gothic book" , sans-serif; font-size: 12pt;">=</span><b><span style="color: #7f0055; font-family: "franklin gothic book" , sans-serif; font-size: 12.0pt;">new</span></b><span style="font-family: "franklin gothic book" , sans-serif; font-size: 12pt;"> Thread(</span><span style="color: #6a3e3e; font-family: "franklin gothic book" , sans-serif; font-size: 12.0pt;">hashObj</span><span style="font-family: "franklin gothic book" , sans-serif; font-size: 12pt;">);</span><span style="font-family: "franklin gothic book" , sans-serif; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: "franklin gothic book" , sans-serif; font-size: 12pt;"> </span><span style="color: #6a3e3e; font-family: "franklin gothic book" , sans-serif; font-size: 12.0pt;">t3</span><span style="font-family: "franklin gothic book" , sans-serif; font-size: 12pt;">.start();</span><span style="font-family: "franklin gothic book" , sans-serif; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: "franklin gothic book" , sans-serif; font-size: 12pt;"> </span><span style="color: #6a3e3e; font-family: "franklin gothic book" , sans-serif; font-size: 12.0pt;">t2</span><span style="font-family: "franklin gothic book" , sans-serif; font-size: 12pt;">.setName(</span><span style="color: #2a00ff; font-family: "franklin gothic book" , sans-serif; font-size: 12.0pt;">"t3 "</span><span style="font-family: "franklin gothic book" , sans-serif; font-size: 12pt;">);</span><span style="font-family: "franklin gothic book" , sans-serif; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: "franklin gothic book" , sans-serif; font-size: 12pt;"> </span><b><span style="color: #7f0055; font-family: "franklin gothic book" , sans-serif; font-size: 12.0pt;">try</span></b><span style="font-family: "franklin gothic book" , sans-serif; font-size: 12pt;"> {</span><span style="font-family: "franklin gothic book" , sans-serif; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: "franklin gothic book" , sans-serif; font-size: 12pt;"> </span><span style="color: #6a3e3e; font-family: "franklin gothic book" , sans-serif; font-size: 12.0pt;">t2</span><span style="font-family: "franklin gothic book" , sans-serif; font-size: 12pt;">.join();</span><span style="font-family: "franklin gothic book" , sans-serif; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: "franklin gothic book" , sans-serif; font-size: 12pt;"> } </span><b><span style="color: #7f0055; font-family: "franklin gothic book" , sans-serif; font-size: 12.0pt;">catch</span></b><span style="font-family: "franklin gothic book" , sans-serif; font-size: 12pt;"> (InterruptedException
</span><span style="color: #6a3e3e; font-family: "franklin gothic book" , sans-serif; font-size: 12.0pt;">e</span><span style="font-family: "franklin gothic book" , sans-serif; font-size: 12pt;">) {</span><span style="font-family: "franklin gothic book" , sans-serif; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: "franklin gothic book" , sans-serif; font-size: 12pt;"> </span><span style="color: #3f7f5f; font-family: "franklin gothic book" , sans-serif; font-size: 12.0pt;">// </span><b><span style="color: #7f9fbf; font-family: "franklin gothic book" , sans-serif; font-size: 12.0pt;">TODO</span></b><span style="color: #3f7f5f; font-family: "franklin gothic book" , sans-serif; font-size: 12.0pt;"> Auto-generated
catch block</span><span style="font-family: "franklin gothic book" , sans-serif; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: "franklin gothic book" , sans-serif; font-size: 12pt;"> </span><span style="color: #6a3e3e; font-family: "franklin gothic book" , sans-serif; font-size: 12.0pt;">e</span><span style="font-family: "franklin gothic book" , sans-serif; font-size: 12pt;">.printStackTrace();</span><span style="font-family: "franklin gothic book" , sans-serif; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: "franklin gothic book" , sans-serif; font-size: 12pt;"> }</span><span style="font-family: "franklin gothic book" , sans-serif; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: "franklin gothic book" , sans-serif; font-size: 12pt;"> </span><b><span style="color: #7f0055; font-family: "franklin gothic book" , sans-serif; font-size: 12.0pt;">try</span></b><span style="font-family: "franklin gothic book" , sans-serif; font-size: 12pt;"> {</span><span style="font-family: "franklin gothic book" , sans-serif; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: "franklin gothic book" , sans-serif; font-size: 12pt;"> </span><span style="color: #6a3e3e; font-family: "franklin gothic book" , sans-serif; font-size: 12.0pt;">t3</span><span style="font-family: "franklin gothic book" , sans-serif; font-size: 12pt;">.join();</span><span style="font-family: "franklin gothic book" , sans-serif; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: "franklin gothic book" , sans-serif; font-size: 12pt;"> } </span><b><span style="color: #7f0055; font-family: "franklin gothic book" , sans-serif; font-size: 12.0pt;">catch</span></b><span style="font-family: "franklin gothic book" , sans-serif; font-size: 12pt;"> (InterruptedException
</span><span style="color: #6a3e3e; font-family: "franklin gothic book" , sans-serif; font-size: 12.0pt;">e</span><span style="font-family: "franklin gothic book" , sans-serif; font-size: 12pt;">) {</span><span style="font-family: "franklin gothic book" , sans-serif; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: "franklin gothic book" , sans-serif; font-size: 12pt;"> </span><span style="color: #3f7f5f; font-family: "franklin gothic book" , sans-serif; font-size: 12.0pt;">// </span><b><span style="color: #7f9fbf; font-family: "franklin gothic book" , sans-serif; font-size: 12.0pt;">TODO</span></b><span style="color: #3f7f5f; font-family: "franklin gothic book" , sans-serif; font-size: 12.0pt;"> Auto-generated
catch block</span><span style="font-family: "franklin gothic book" , sans-serif; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: "franklin gothic book" , sans-serif; font-size: 12pt;"> </span><span style="color: #6a3e3e; font-family: "franklin gothic book" , sans-serif; font-size: 12.0pt;">e</span><span style="font-family: "franklin gothic book" , sans-serif; font-size: 12pt;">.printStackTrace();</span><span style="font-family: "franklin gothic book" , sans-serif; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: "franklin gothic book" , sans-serif; font-size: 12pt;"> }</span><span style="font-family: "franklin gothic book" , sans-serif; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: "franklin gothic book" , sans-serif; font-size: 12pt;"> Consumer </span><span style="color: #6a3e3e; font-family: "franklin gothic book" , sans-serif; font-size: 12.0pt;">consumeObj</span><span style="font-family: "franklin gothic book" , sans-serif; font-size: 12pt;">=</span><b><span style="color: #7f0055; font-family: "franklin gothic book" , sans-serif; font-size: 12.0pt;">new</span></b><span style="font-family: "franklin gothic book" , sans-serif; font-size: 12pt;"> Consumer();</span><span style="font-family: "franklin gothic book" , sans-serif; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: "franklin gothic book" , sans-serif; font-size: 12pt;"> </span><span style="color: #6a3e3e; font-family: "franklin gothic book" , sans-serif; font-size: 12.0pt;">consumeObj</span><span style="font-family: "franklin gothic book" , sans-serif; font-size: 12pt;">.init(</span><span style="color: #6a3e3e; font-family: "franklin gothic book" , sans-serif; font-size: 12.0pt;">st</span><span style="font-family: "franklin gothic book" , sans-serif; font-size: 12pt;">);</span><span style="font-family: "franklin gothic book" , sans-serif; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: "franklin gothic book" , sans-serif; font-size: 12pt;"> Thread </span><span style="color: #6a3e3e; font-family: "franklin gothic book" , sans-serif; font-size: 12.0pt;">t1</span><span style="font-family: "franklin gothic book" , sans-serif; font-size: 12pt;">=</span><b><span style="color: #7f0055; font-family: "franklin gothic book" , sans-serif; font-size: 12.0pt;">new</span></b><span style="font-family: "franklin gothic book" , sans-serif; font-size: 12pt;"> Thread(</span><span style="color: #6a3e3e; font-family: "franklin gothic book" , sans-serif; font-size: 12.0pt;">consumeObj</span><span style="font-family: "franklin gothic book" , sans-serif; font-size: 12pt;">);</span><span style="font-family: "franklin gothic book" , sans-serif; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: "franklin gothic book" , sans-serif; font-size: 12pt;"> </span><span style="color: #6a3e3e; font-family: "franklin gothic book" , sans-serif; font-size: 12.0pt;">t1</span><span style="font-family: "franklin gothic book" , sans-serif; font-size: 12pt;">.setName(</span><span style="color: #2a00ff; font-family: "franklin gothic book" , sans-serif; font-size: 12.0pt;">"t1 "</span><span style="font-family: "franklin gothic book" , sans-serif; font-size: 12pt;">);</span><span style="font-family: "franklin gothic book" , sans-serif; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: "franklin gothic book" , sans-serif; font-size: 12pt;"> </span><span style="color: #6a3e3e; font-family: "franklin gothic book" , sans-serif; font-size: 12.0pt;">t1</span><span style="font-family: "franklin gothic book" , sans-serif; font-size: 12pt;">.start();</span><span style="font-family: "franklin gothic book" , sans-serif; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: "franklin gothic book" , sans-serif; font-size: 12pt;"> </span><span style="font-family: "franklin gothic book" , sans-serif; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: "franklin gothic book" , sans-serif; font-size: 12pt;"> }</span><span style="font-family: "franklin gothic book" , sans-serif; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: "franklin gothic book" , sans-serif; font-size: 12pt;"> }</span><span style="font-family: "franklin gothic book" , sans-serif; font-size: 12.0pt;"><o:p></o:p></span><br />
<span style="font-family: "franklin gothic book" , sans-serif;">Thank you for being kind enough to visit here.</span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
If you really like this post you can boost my energy bar by pressing Like Share :)<br />
<br /></div>
<br />
<div class="MsoNormal">
<br /></div>
</div>
<iframe border="0" frameborder="0" height="250" marginwidth="0" scrolling="no" src="//rcm-na.amazon-adsystem.com/e/cm?o=1&p=12&l=ur1&category=bestsellingproducts&banner=145H1HTA41NXJPV0C0R2&f=ifr&lc=pf4&linkID=458775f074b62875e5202046f3892e2e&t=javashiv-20&tracking_id=javashiv-20" style="border: none;" width="300"></iframe></div>
Anonymoushttp://www.blogger.com/profile/07685598617709117616noreply@blogger.com0tag:blogger.com,1999:blog-1266456599706152053.post-83007218838439983422016-09-02T11:39:00.000+05:302016-09-02T11:58:17.776+05:30Stream() Java8<div dir="ltr" style="text-align: left;" trbidi="on">
<div style="margin-bottom: .0001pt; margin: 0in;">
<span style="font-size: 13.5pt;">Hi Guys,<o:p></o:p></span></div>
<div style="margin-bottom: .0001pt; margin: 0in;">
<span style="font-size: 13.5pt;">We will have a look at powerful functionality in java8.<o:p></o:p></span></div>
<div style="margin: 0in 0in 0.0001pt;">
<br /></div>
<iframe frameborder="0" marginheight="0" marginwidth="0" scrolling="no" src="//ws-na.amazon-adsystem.com/widgets/q?ServiceVersion=20070822&OneJS=1&Operation=GetAdHtml&MarketPlace=US&source=ac&ref=tf_til&ad_type=product_link&tracking_id=javashiv-20&marketplace=amazon&region=US&placement=1617291994&asins=1617291994&linkId=39a5e0dcf55b79b45666754d7e3cb287&show_border=true&link_opens_in_new_window=false&price_color=333333&title_color=0066c0&bg_color=ffffff" style="height: 240px; width: 120px;">
</iframe>
<div style="margin-bottom: .0001pt; margin: 0in;">
<b><span style="font-size: 13.5pt;">Stream vs Collection<o:p></o:p></span></b></div>
<div style="margin: 0in 0in 0.0001pt;">
<br /></div>
<div style="margin: 0in 0in 0.0001pt;">
<span style="font-size: 13.5pt;">Streams:<o:p></o:p></span></div>
<div style="margin-bottom: .0001pt; margin: 0in;">
<span style="font-size: 13.5pt;">Takes advantage of declarative programming it gives hint about
what operations need to perform on source.<o:p></o:p></span></div>
<div style="margin: 0in 0in 0.0001pt;">
<br /></div>
<div style="margin: 0in 0in 0.0001pt;">
<span style="font-size: 13.5pt;">Collection:<o:p></o:p></span></div>
<div style="margin-bottom: .0001pt; margin: 0in;">
<span style="font-size: 13.5pt;">It has direct access on source (array, collections).<o:p></o:p></span></div>
<div style="margin: 0in 0in 0.0001pt;">
<span style="font-size: 13.5pt;">You will need to
take care of iteration.<o:p></o:p></span></div>
<div style="margin: 0in 0in 0.0001pt;">
<br /></div>
<div style="margin: 0in 0in 0.0001pt;">
<span style="font-size: 13.5pt;">What is Stream?<o:p></o:p></span></div>
<div style="margin: 0in 0in 0.0001pt;">
<span style="font-size: 13.5pt;">Stream is composed
of the Stream pipeline.<o:p></o:p></span></div>
<div style="margin-bottom: .0001pt; margin-bottom: 0in; margin-left: .5in; margin-right: 0in; margin-top: 0in; text-indent: .5in;">
<br /></div>
<div style="margin-bottom: .0001pt; margin-bottom: 0in; margin-left: .5in; margin-right: 0in; margin-top: 0in; text-indent: .5in;">
<b><span style="font-size: 13.5pt;">Stream=Source+Intermediary Operation+Terminal
Operations<o:p></o:p></span></b></div>
<div style="margin-bottom: .0001pt; margin-bottom: 0in; margin-left: .5in; margin-right: 0in; margin-top: 0in; text-indent: .5in;">
<br /></div>
<div style="margin: 0in 0in 0.0001pt;">
<b><span style="font-size: 13.5pt;">Source</span></b><span style="font-size: 13.5pt;"> which may be array, collection.<o:p></o:p></span></div>
<div style="margin: 0in 0in 0.0001pt;">
<br /></div>
<div style="margin: 0in 0in 0.0001pt;">
<b><span style="font-size: 13.5pt;">Intermediary operations</span></b><span style="font-size: 13.5pt;"> such as filter to collect results that
satisfy some predicate.<o:p></o:p></span></div>
<iframe border="0" frameborder="0" height="250" marginwidth="0" scrolling="no" src="//rcm-na.amazon-adsystem.com/e/cm?o=1&p=12&l=ur1&category=primemain&banner=1N7QZYHSKNC8P06S6QG2&f=ifr&linkID=ffd0d92e2caec24f4dd4b50f33a40009&t=javashiv-20&tracking_id=javashiv-20" style="border: none;" width="300"></iframe><iframe frameborder="0" marginheight="0" marginwidth="0" scrolling="no" src="//ws-na.amazon-adsystem.com/widgets/q?ServiceVersion=20070822&OneJS=1&Operation=GetAdHtml&MarketPlace=US&source=ac&ref=tf_til&ad_type=product_link&tracking_id=javashiv-20&marketplace=amazon&region=US&placement=B00DF0P2I2&asins=B00DF0P2I2&linkId=ee3b804c7c4d83e68ed45f0df5bd58ef&show_border=true&link_opens_in_new_window=false&price_color=333333&title_color=0066c0&bg_color=ffffff" style="height: 240px; width: 120px;">
</iframe>
<div style="margin: 0in 0in 0.0001pt;">
<br /></div>
<div style="margin: 0in 0in 0.0001pt;">
<b><span style="font-size: 13.5pt;">Terminal operations:</span></b><span style="font-size: 13.5pt;">sum,avg,count<o:p></o:p></span></div>
<div style="margin: 0in 0in 0.0001pt;">
<span style="font-size: 13.5pt;">Computations are
performed at this stage.<o:p></o:p></span></div>
<div style="margin: 0in 0in 0.0001pt;">
<br /></div>
<div style="margin: 0in 0in 0.0001pt;">
<b><span style="font-size: 13.5pt;">Facts about Streams<o:p></o:p></span></b></div>
<div style="margin: 0in 0in 0.0001pt 0.5in; text-indent: -0.25in;">
<!--[if !supportLists]--><span style="font-size: 13.5pt;">1.<span style="font-size: 7pt; font-stretch: normal; font-variant-numeric: normal;">
</span></span><!--[endif]--><span style="font-size: 13.5pt;">Streams
can’t be reused.<o:p></o:p></span></div>
<div style="margin: 0in 0in 0.0001pt 0.5in; text-indent: -0.25in;">
<!--[if !supportLists]--><span style="font-size: 13.5pt;">2.<span style="font-size: 7pt; font-stretch: normal; font-variant-numeric: normal;">
</span></span><!--[endif]--><span style="font-size: 13.5pt;">No
need to close the streams they are autoclosable.<o:p></o:p></span></div>
<div style="margin: 0in 0in 0.0001pt 0.5in; text-indent: -0.25in;">
<!--[if !supportLists]--><span style="font-size: 13.5pt;">3.<span style="font-size: 7pt; font-stretch: normal; font-variant-numeric: normal;">
</span></span><!--[endif]--><span style="font-size: 13.5pt;">However
the streams related to IOChannel(File) must be closed<o:p></o:p></span></div>
<div style="margin: 0in 0in 0.0001pt;">
<br /></div>
<div style="margin: 0in 0in 0.0001pt;">
<b><span style="font-size: 13.5pt;">Example on Streams<o:p></o:p></span></b></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<b><span style="color: #7f0055; font-family: "franklin gothic book" , sans-serif; font-size: 12.0pt;">package</span></b><span style="font-family: "franklin gothic book" , sans-serif; font-size: 12pt;"> com.seetest;</span><span style="font-family: "franklin gothic book" , sans-serif; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<br /></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<b><span style="color: #7f0055; font-family: "franklin gothic book" , sans-serif; font-size: 12.0pt;">import</span></b><span style="font-family: "franklin gothic book" , sans-serif; font-size: 12pt;"> java.util.ArrayList;</span><span style="font-family: "franklin gothic book" , sans-serif; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<b><span style="color: #7f0055; font-family: "franklin gothic book" , sans-serif; font-size: 12.0pt;">import</span></b><span style="font-family: "franklin gothic book" , sans-serif; font-size: 12pt;"> java.util.List;</span><span style="font-family: "franklin gothic book" , sans-serif; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<b><span style="color: #7f0055; font-family: "franklin gothic book" , sans-serif; font-size: 12.0pt;">public</span></b><span style="font-family: "franklin gothic book" , sans-serif; font-size: 12pt;"> </span><b><span style="color: #7f0055; font-family: "franklin gothic book" , sans-serif; font-size: 12.0pt;">class</span></b><span style="font-family: "franklin gothic book" , sans-serif; font-size: 12pt;"> HelloWorld{</span><span style="font-family: "franklin gothic book" , sans-serif; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<br /></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: "franklin gothic book" , sans-serif; font-size: 12pt;"> </span><b><span style="color: #7f0055; font-family: "franklin gothic book" , sans-serif; font-size: 12.0pt;">public</span></b><span style="font-family: "franklin gothic book" , sans-serif; font-size: 12pt;"> </span><b><span style="color: #7f0055; font-family: "franklin gothic book" , sans-serif; font-size: 12.0pt;">static</span></b><span style="font-family: "franklin gothic book" , sans-serif; font-size: 12pt;"> </span><b><span style="color: #7f0055; font-family: "franklin gothic book" , sans-serif; font-size: 12.0pt;">void</span></b><span style="font-family: "franklin gothic book" , sans-serif; font-size: 12pt;"> main(String []</span><span style="color: #6a3e3e; font-family: "franklin gothic book" , sans-serif; font-size: 12.0pt;">args</span><span style="font-family: "franklin gothic book" , sans-serif; font-size: 12pt;">){</span><span style="font-family: "franklin gothic book" , sans-serif; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: "franklin gothic book" , sans-serif; font-size: 12pt;"> List<String> </span><span style="color: #6a3e3e; font-family: "franklin gothic book" , sans-serif; font-size: 12.0pt;">phones</span><span style="font-family: "franklin gothic book" , sans-serif; font-size: 12pt;">=</span><b><span style="color: #7f0055; font-family: "franklin gothic book" , sans-serif; font-size: 12.0pt;">new</span></b><span style="font-family: "franklin gothic book" , sans-serif; font-size: 12pt;">
ArrayList<String>();</span><span style="font-family: "franklin gothic book" , sans-serif; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: "franklin gothic book" , sans-serif; font-size: 12pt;"> </span><span style="color: #6a3e3e; font-family: "franklin gothic book" , sans-serif; font-size: 12.0pt;">phones</span><span style="font-family: "franklin gothic book" , sans-serif; font-size: 12pt;">.add(</span><span style="color: #2a00ff; font-family: "franklin gothic book" , sans-serif; font-size: 12.0pt;">"samsung"</span><span style="font-family: "franklin gothic book" , sans-serif; font-size: 12pt;">);</span><span style="font-family: "franklin gothic book" , sans-serif; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: "franklin gothic book" , sans-serif; font-size: 12pt;"> </span><span style="color: #6a3e3e; font-family: "franklin gothic book" , sans-serif; font-size: 12.0pt;">phones</span><span style="font-family: "franklin gothic book" , sans-serif; font-size: 12pt;">.add(</span><span style="color: #2a00ff; font-family: "franklin gothic book" , sans-serif; font-size: 12.0pt;">"xiomi"</span><span style="font-family: "franklin gothic book" , sans-serif; font-size: 12pt;">);</span><span style="font-family: "franklin gothic book" , sans-serif; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: "franklin gothic book" , sans-serif; font-size: 12pt;"> </span><span style="color: #6a3e3e; font-family: "franklin gothic book" , sans-serif; font-size: 12.0pt;">phones</span><span style="font-family: "franklin gothic book" , sans-serif; font-size: 12pt;">.stream().filter(</span><span style="color: #6a3e3e; font-family: "franklin gothic book" , sans-serif; font-size: 12.0pt;">s</span><span style="font-family: "franklin gothic book" , sans-serif; font-size: 12pt;">-></span><span style="color: #6a3e3e; font-family: "franklin gothic book" , sans-serif; font-size: 12.0pt;">s</span><span style="font-family: "franklin gothic book" , sans-serif; font-size: 12pt;">.startsWith(</span><span style="color: #2a00ff; font-family: "franklin gothic book" , sans-serif; font-size: 12.0pt;">"s"</span><span style="font-family: "franklin gothic book" , sans-serif; font-size: 12pt;">)).forEach(System.</span><b><i><span style="color: #0000c0; font-family: "franklin gothic book" , sans-serif; font-size: 12.0pt;">out</span></i></b><span style="font-family: "franklin gothic book" , sans-serif; font-size: 12pt;">::println);</span><span style="font-family: "franklin gothic book" , sans-serif; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: "franklin gothic book" , sans-serif; font-size: 12pt;"> </span><span style="color: #3f7f5f; font-family: "franklin gothic book" , sans-serif; font-size: 12.0pt;">//String phone;</span><span style="font-family: "franklin gothic book" , sans-serif; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: "franklin gothic book" , sans-serif; font-size: 12pt;"> </span><span style="font-family: "franklin gothic book" , sans-serif; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: "franklin gothic book" , sans-serif; font-size: 12pt;"> </span><span style="font-family: "franklin gothic book" , sans-serif; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: "franklin gothic book" , sans-serif; font-size: 12pt;"> }</span><span style="font-family: "franklin gothic book" , sans-serif; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: "franklin gothic book" , sans-serif; font-size: 12pt;">}</span><span style="font-family: "franklin gothic book" , sans-serif; font-size: 12.0pt;"><o:p></o:p></span></div>
<div style="margin-bottom: .0001pt; margin: 0in;">
<br /></div>
<div style="margin: 0in 0in 0.0001pt;">
<b><span style="font-size: 13.5pt;">
Methods in Stream Class:<o:p></o:p></span></b></div>
<div style="margin: 0in 0in 0.0001pt;">
<span style="font-size: 13.5pt;"> <o:p></o:p></span></div>
<div style="margin: 0in 0in 0.0001pt 0.5in; text-indent: -0.25in;">
<!--[if !supportLists]--><span style="font-size: 13.5pt;">1.<span style="font-size: 7pt; font-stretch: normal; font-variant-numeric: normal;">
</span></span><!--[endif]--><span style="font-size: 13.5pt;">findAny<o:p></o:p></span></div>
<div style="margin-bottom: .0001pt; margin-bottom: 0in; margin-left: .5in; margin-right: 0in; margin-top: 0in; mso-list: l0 level1 lfo2; text-indent: -.25in;">
<!--[if !supportLists]--><span style="font-size: 13.5pt;">2.<span style="font-size: 7pt; font-stretch: normal; font-variant-numeric: normal;"> </span></span><!--[endif]--><span style="font-size: 13.5pt;">findFirst<o:p></o:p></span></div>
<div style="margin-bottom: .0001pt; margin-bottom: 0in; margin-left: .5in; margin-right: 0in; margin-top: 0in; mso-list: l0 level1 lfo2; text-indent: -.25in;">
<!--[if !supportLists]--><span style="font-size: 13.5pt;">3.<span style="font-size: 7pt; font-stretch: normal; font-variant-numeric: normal;"> </span></span><!--[endif]--><span style="font-size: 13.5pt;">limit<o:p></o:p></span></div>
<div style="margin-bottom: .0001pt; margin-bottom: 0in; margin-left: .5in; margin-right: 0in; margin-top: 0in; mso-list: l0 level1 lfo2; text-indent: -.25in;">
<!--[if !supportLists]--><span style="font-size: 13.5pt;">4.<span style="font-size: 7pt; font-stretch: normal; font-variant-numeric: normal;"> </span></span><!--[endif]--><span style="font-size: 13.5pt;">min<o:p></o:p></span></div>
<div style="margin-bottom: .0001pt; margin-bottom: 0in; margin-left: .5in; margin-right: 0in; margin-top: 0in; mso-list: l0 level1 lfo2; text-indent: -.25in;">
<!--[if !supportLists]--><span style="font-size: 13.5pt;">5.<span style="font-size: 7pt; font-stretch: normal; font-variant-numeric: normal;"> </span></span><!--[endif]--><span style="font-size: 13.5pt;">map()<o:p></o:p></span></div>
<div style="margin: 0in 0in 0.0001pt 0.5in; text-indent: -0.25in;">
<!--[if !supportLists]--><span style="font-size: 13.5pt;">6.<span style="font-size: 7pt; font-stretch: normal; font-variant-numeric: normal;">
</span></span><!--[endif]--><span style="font-size: 13.5pt;">mapToInt()<o:p></o:p></span></div>
<div style="margin: 0in 0in 0.0001pt 0.5in; text-indent: -0.25in;">
<!--[if !supportLists]--><span style="font-size: 13.5pt;">7.<span style="font-size: 7pt; font-stretch: normal; font-variant-numeric: normal;">
</span></span><!--[endif]--><span style="font-size: 13.5pt;">mapToDouble()<o:p></o:p></span></div>
<div style="margin: 0in 0in 0.0001pt;">
<br /></div>
<div style="margin: 0in 0in 0.0001pt;">
<br /></div>
<div style="margin: 0in 0in 0.0001pt;">
<br /></div>
<div style="margin: 0in 0in 0.0001pt;">
<br /></div>
<div style="margin: 0in 0in 0.0001pt;">
<b><span style="font-size: 13.5pt;">1.findAny:<o:p></o:p></span></b></div>
<div style="margin-bottom: .0001pt; margin: 0in;">
<span style="font-size: 13.5pt;">Returns any element in the stream.<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<b><span style="color: #7f0055; font-family: "franklin gothic book" , sans-serif; font-size: 12.0pt;">import</span></b><span style="font-family: "franklin gothic book" , sans-serif; font-size: 12pt;"> java.util.ArrayList;</span><span style="font-family: "franklin gothic book" , sans-serif; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<b><span style="color: #7f0055; font-family: "franklin gothic book" , sans-serif; font-size: 12.0pt;">import</span></b><span style="font-family: "franklin gothic book" , sans-serif; font-size: 12pt;"> java.util.List;</span><span style="font-family: "franklin gothic book" , sans-serif; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<b><span style="color: #7f0055; font-family: "franklin gothic book" , sans-serif; font-size: 12.0pt;">public</span></b><span style="font-family: "franklin gothic book" , sans-serif; font-size: 12pt;"> </span><b><span style="color: #7f0055; font-family: "franklin gothic book" , sans-serif; font-size: 12.0pt;">class</span></b><span style="font-family: "franklin gothic book" , sans-serif; font-size: 12pt;"> HelloWorld{</span><span style="font-family: "franklin gothic book" , sans-serif; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<br /></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: "franklin gothic book" , sans-serif; font-size: 12pt;"> </span><b><span style="color: #7f0055; font-family: "franklin gothic book" , sans-serif; font-size: 12.0pt;">public</span></b><span style="font-family: "franklin gothic book" , sans-serif; font-size: 12pt;"> </span><b><span style="color: #7f0055; font-family: "franklin gothic book" , sans-serif; font-size: 12.0pt;">static</span></b><span style="font-family: "franklin gothic book" , sans-serif; font-size: 12pt;"> </span><b><span style="color: #7f0055; font-family: "franklin gothic book" , sans-serif; font-size: 12.0pt;">void</span></b><span style="font-family: "franklin gothic book" , sans-serif; font-size: 12pt;"> main(String []</span><span style="color: #6a3e3e; font-family: "franklin gothic book" , sans-serif; font-size: 12.0pt;">args</span><span style="font-family: "franklin gothic book" , sans-serif; font-size: 12pt;">){</span><span style="font-family: "franklin gothic book" , sans-serif; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: "franklin gothic book" , sans-serif; font-size: 12pt;"> List<String> </span><span style="color: #6a3e3e; font-family: "franklin gothic book" , sans-serif; font-size: 12.0pt;">phones</span><span style="font-family: "franklin gothic book" , sans-serif; font-size: 12pt;">=</span><b><span style="color: #7f0055; font-family: "franklin gothic book" , sans-serif; font-size: 12.0pt;">new</span></b><span style="font-family: "franklin gothic book" , sans-serif; font-size: 12pt;">
ArrayList<String>();</span><span style="font-family: "franklin gothic book" , sans-serif; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: "franklin gothic book" , sans-serif; font-size: 12pt;"> </span><span style="color: #6a3e3e; font-family: "franklin gothic book" , sans-serif; font-size: 12.0pt;">phones</span><span style="font-family: "franklin gothic book" , sans-serif; font-size: 12pt;">.add(</span><span style="color: #2a00ff; font-family: "franklin gothic book" , sans-serif; font-size: 12.0pt;">"samsung"</span><span style="font-family: "franklin gothic book" , sans-serif; font-size: 12pt;">);</span><span style="font-family: "franklin gothic book" , sans-serif; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: "franklin gothic book" , sans-serif; font-size: 12pt;"> </span><span style="color: #6a3e3e; font-family: "franklin gothic book" , sans-serif; font-size: 12.0pt;">phones</span><span style="font-family: "franklin gothic book" , sans-serif; font-size: 12pt;">.add(</span><span style="color: #2a00ff; font-family: "franklin gothic book" , sans-serif; font-size: 12.0pt;">"xiomi"</span><span style="font-family: "franklin gothic book" , sans-serif; font-size: 12pt;">);</span><span style="font-family: "franklin gothic book" , sans-serif; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: "franklin gothic book" , sans-serif; font-size: 12pt;"> </span><span style="color: #6a3e3e; font-family: "franklin gothic book" , sans-serif; font-size: 12.0pt;">phones</span><span style="font-family: "franklin gothic book" , sans-serif; font-size: 12pt;">.stream().findAny().ifPresent(System.</span><b><i><span style="color: #0000c0; font-family: "franklin gothic book" , sans-serif; font-size: 12.0pt;">out</span></i></b><span style="font-family: "franklin gothic book" , sans-serif; font-size: 12pt;">::println);</span><span style="font-family: "franklin gothic book" , sans-serif; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: "franklin gothic book" , sans-serif; font-size: 12pt;"> </span><span style="color: #3f7f5f; font-family: "franklin gothic book" , sans-serif; font-size: 12.0pt;">//String phone;</span><span style="font-family: "franklin gothic book" , sans-serif; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: "franklin gothic book" , sans-serif; font-size: 12pt;"> </span><span style="font-family: "franklin gothic book" , sans-serif; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: "franklin gothic book" , sans-serif; font-size: 12pt;"> </span><span style="font-family: "franklin gothic book" , sans-serif; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: "franklin gothic book" , sans-serif; font-size: 12pt;"> }</span><span style="font-family: "franklin gothic book" , sans-serif; font-size: 12.0pt;"><o:p></o:p></span></div>
<div style="margin-bottom: .0001pt; margin: 0in;">
<span style="font-family: "franklin gothic book" , sans-serif;">}</span><span style="font-size: 13.5pt;"><o:p></o:p></span></div>
<div style="margin: 0in 0in 0.0001pt;">
<br /></div>
<div style="margin: 0in 0in 0.0001pt;">
<br /></div>
<div style="margin: 0in 0in 0.0001pt;">
<b><span style="font-size: 13.5pt;">2.findFirst:<o:p></o:p></span></b></div>
<div style="margin: 0in 0in 0.0001pt;">
<br /></div>
<div style="margin: 0in 0in 0.0001pt;">
<span style="font-size: 13.5pt;">findFirst returns
the first elements of the stream<o:p></o:p></span></div>
<div style="margin: 0in 0in 0.0001pt;">
<br /></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<b><span style="color: #7f0055; font-family: "franklin gothic book" , sans-serif; font-size: 12.0pt;">import</span></b><span style="font-family: "franklin gothic book" , sans-serif; font-size: 12pt;"> java.util.ArrayList;</span><span style="font-family: "franklin gothic book" , sans-serif; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<b><span style="color: #7f0055; font-family: "franklin gothic book" , sans-serif; font-size: 12.0pt;">import</span></b><span style="font-family: "franklin gothic book" , sans-serif; font-size: 12pt;"> java.util.List;</span><span style="font-family: "franklin gothic book" , sans-serif; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<b><span style="color: #7f0055; font-family: "franklin gothic book" , sans-serif; font-size: 12.0pt;">public</span></b><span style="font-family: "franklin gothic book" , sans-serif; font-size: 12pt;"> </span><b><span style="color: #7f0055; font-family: "franklin gothic book" , sans-serif; font-size: 12.0pt;">class</span></b><span style="font-family: "franklin gothic book" , sans-serif; font-size: 12pt;"> HelloWorld{</span><span style="font-family: "franklin gothic book" , sans-serif; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<br /></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: "franklin gothic book" , sans-serif; font-size: 12pt;"> </span><b><span style="color: #7f0055; font-family: "franklin gothic book" , sans-serif; font-size: 12.0pt;">public</span></b><span style="font-family: "franklin gothic book" , sans-serif; font-size: 12pt;"> </span><b><span style="color: #7f0055; font-family: "franklin gothic book" , sans-serif; font-size: 12.0pt;">static</span></b><span style="font-family: "franklin gothic book" , sans-serif; font-size: 12pt;"> </span><b><span style="color: #7f0055; font-family: "franklin gothic book" , sans-serif; font-size: 12.0pt;">void</span></b><span style="font-family: "franklin gothic book" , sans-serif; font-size: 12pt;"> main(String []</span><span style="color: #6a3e3e; font-family: "franklin gothic book" , sans-serif; font-size: 12.0pt;">args</span><span style="font-family: "franklin gothic book" , sans-serif; font-size: 12pt;">){</span><span style="font-family: "franklin gothic book" , sans-serif; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: "franklin gothic book" , sans-serif; font-size: 12pt;"> List<String> </span><span style="color: #6a3e3e; font-family: "franklin gothic book" , sans-serif; font-size: 12.0pt;">phones</span><span style="font-family: "franklin gothic book" , sans-serif; font-size: 12pt;">=</span><b><span style="color: #7f0055; font-family: "franklin gothic book" , sans-serif; font-size: 12.0pt;">new</span></b><span style="font-family: "franklin gothic book" , sans-serif; font-size: 12pt;">
ArrayList<String>();</span><span style="font-family: "franklin gothic book" , sans-serif; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: "franklin gothic book" , sans-serif; font-size: 12pt;"> </span><span style="color: #6a3e3e; font-family: "franklin gothic book" , sans-serif; font-size: 12.0pt;">phones</span><span style="font-family: "franklin gothic book" , sans-serif; font-size: 12pt;">.add(</span><span style="color: #2a00ff; font-family: "franklin gothic book" , sans-serif; font-size: 12.0pt;">"samsung"</span><span style="font-family: "franklin gothic book" , sans-serif; font-size: 12pt;">);</span><span style="font-family: "franklin gothic book" , sans-serif; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: "franklin gothic book" , sans-serif; font-size: 12pt;"> </span><span style="color: #6a3e3e; font-family: "franklin gothic book" , sans-serif; font-size: 12.0pt;">phones</span><span style="font-family: "franklin gothic book" , sans-serif; font-size: 12pt;">.add(</span><span style="color: #2a00ff; font-family: "franklin gothic book" , sans-serif; font-size: 12.0pt;">"xiomi"</span><span style="font-family: "franklin gothic book" , sans-serif; font-size: 12pt;">);</span><span style="font-family: "franklin gothic book" , sans-serif; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: "franklin gothic book" , sans-serif; font-size: 12pt;"> </span><span style="color: #6a3e3e; font-family: "franklin gothic book" , sans-serif; font-size: 12.0pt;">phones</span><span style="font-family: "franklin gothic book" , sans-serif; font-size: 12pt;">.stream().findFirst().ifPresent(System.</span><b><i><span style="color: #0000c0; font-family: "franklin gothic book" , sans-serif; font-size: 12.0pt;">out</span></i></b><span style="font-family: "franklin gothic book" , sans-serif; font-size: 12pt;">::println);</span><span style="font-family: "franklin gothic book" , sans-serif; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: "franklin gothic book" , sans-serif; font-size: 12pt;"> </span><span style="color: #3f7f5f; font-family: "franklin gothic book" , sans-serif; font-size: 12.0pt;">//String phone;</span><span style="font-family: "franklin gothic book" , sans-serif; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: "franklin gothic book" , sans-serif; font-size: 12pt;"> </span><span style="font-family: "franklin gothic book" , sans-serif; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: "franklin gothic book" , sans-serif; font-size: 12pt;"> </span><span style="font-family: "franklin gothic book" , sans-serif; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: "franklin gothic book" , sans-serif; font-size: 12pt;"> }</span><span style="font-family: "franklin gothic book" , sans-serif; font-size: 12.0pt;"><o:p></o:p></span></div>
<div style="margin-bottom: .0001pt; margin: 0in;">
<span style="font-family: "franklin gothic book" , sans-serif;">}</span><span style="font-size: 13.5pt;"><o:p></o:p></span></div>
<div style="margin: 0in 0in 0.0001pt;">
<br /></div>
<div style="margin: 0in 0in 0.0001pt;">
<b><span style="font-size: 13.5pt;">3.limit:<o:p></o:p></span></b></div>
<iframe style="width:120px;height:240px;" marginwidth="0" marginheight="0" scrolling="no" frameborder="0" src="//ws-na.amazon-adsystem.com/widgets/q?ServiceVersion=20070822&OneJS=1&Operation=GetAdHtml&MarketPlace=US&source=ac&ref=tf_til&ad_type=product_link&tracking_id=javashiv-20&marketplace=amazon®ion=US&placement=B0183UDXHA&asins=B0183UDXHA&linkId=6d51ec6d451fc452c84c5e8d383d2eb5&show_border=true&link_opens_in_new_window=false&price_color=333333&title_color=0066c0&bg_color=ffffff">
</iframe>
<div style="margin: 0in 0in 0.0001pt;">
<span style="font-size: 13.5pt;">limits how many
rows should be shown.<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<br /></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<b><span style="color: #7f0055; font-family: "franklin gothic book" , sans-serif; font-size: 12.0pt;">import</span></b><span style="font-family: "franklin gothic book" , sans-serif; font-size: 12pt;"> java.util.ArrayList;</span><span style="font-family: "franklin gothic book" , sans-serif; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<b><span style="color: #7f0055; font-family: "franklin gothic book" , sans-serif; font-size: 12.0pt;">import</span></b><span style="font-family: "franklin gothic book" , sans-serif; font-size: 12pt;"> java.util.List;</span><span style="font-family: "franklin gothic book" , sans-serif; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<b><span style="color: #7f0055; font-family: "franklin gothic book" , sans-serif; font-size: 12.0pt;">public</span></b><span style="font-family: "franklin gothic book" , sans-serif; font-size: 12pt;"> </span><b><span style="color: #7f0055; font-family: "franklin gothic book" , sans-serif; font-size: 12.0pt;">class</span></b><span style="font-family: "franklin gothic book" , sans-serif; font-size: 12pt;"> HelloWorld{</span><span style="font-family: "franklin gothic book" , sans-serif; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<br /></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: "franklin gothic book" , sans-serif; font-size: 12pt;"> </span><b><span style="color: #7f0055; font-family: "franklin gothic book" , sans-serif; font-size: 12.0pt;">public</span></b><span style="font-family: "franklin gothic book" , sans-serif; font-size: 12pt;"> </span><b><span style="color: #7f0055; font-family: "franklin gothic book" , sans-serif; font-size: 12.0pt;">static</span></b><span style="font-family: "franklin gothic book" , sans-serif; font-size: 12pt;"> </span><b><span style="color: #7f0055; font-family: "franklin gothic book" , sans-serif; font-size: 12.0pt;">void</span></b><span style="font-family: "franklin gothic book" , sans-serif; font-size: 12pt;"> main(String []</span><span style="color: #6a3e3e; font-family: "franklin gothic book" , sans-serif; font-size: 12.0pt;">args</span><span style="font-family: "franklin gothic book" , sans-serif; font-size: 12pt;">){</span><span style="font-family: "franklin gothic book" , sans-serif; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: "franklin gothic book" , sans-serif; font-size: 12pt;"> List<String> </span><span style="color: #6a3e3e; font-family: "franklin gothic book" , sans-serif; font-size: 12.0pt;">phones</span><span style="font-family: "franklin gothic book" , sans-serif; font-size: 12pt;">=</span><b><span style="color: #7f0055; font-family: "franklin gothic book" , sans-serif; font-size: 12.0pt;">new</span></b><span style="font-family: "franklin gothic book" , sans-serif; font-size: 12pt;">
ArrayList<String>();</span><span style="font-family: "franklin gothic book" , sans-serif; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: "franklin gothic book" , sans-serif; font-size: 12pt;"> </span><span style="color: #6a3e3e; font-family: "franklin gothic book" , sans-serif; font-size: 12.0pt;">phones</span><span style="font-family: "franklin gothic book" , sans-serif; font-size: 12pt;">.add(</span><span style="color: #2a00ff; font-family: "franklin gothic book" , sans-serif; font-size: 12.0pt;">"samsung"</span><span style="font-family: "franklin gothic book" , sans-serif; font-size: 12pt;">);</span><span style="font-family: "franklin gothic book" , sans-serif; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: "franklin gothic book" , sans-serif; font-size: 12pt;"> </span><span style="color: #6a3e3e; font-family: "franklin gothic book" , sans-serif; font-size: 12.0pt;">phones</span><span style="font-family: "franklin gothic book" , sans-serif; font-size: 12pt;">.add(</span><span style="color: #2a00ff; font-family: "franklin gothic book" , sans-serif; font-size: 12.0pt;">"xiomi"</span><span style="font-family: "franklin gothic book" , sans-serif; font-size: 12pt;">);</span><span style="font-family: "franklin gothic book" , sans-serif; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: "franklin gothic book" , sans-serif; font-size: 12pt;"> </span><span style="color: #6a3e3e; font-family: "franklin gothic book" , sans-serif; font-size: 12.0pt;">phones</span><span style="font-family: "franklin gothic book" , sans-serif; font-size: 12pt;">.stream().limit(1).forEach(System.</span><b><i><span style="color: #0000c0; font-family: "franklin gothic book" , sans-serif; font-size: 12.0pt;">out</span></i></b><span style="font-family: "franklin gothic book" , sans-serif; font-size: 12pt;">::println);</span><span style="font-family: "franklin gothic book" , sans-serif; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: "franklin gothic book" , sans-serif; font-size: 12pt;"> </span><span style="color: #3f7f5f; font-family: "franklin gothic book" , sans-serif; font-size: 12.0pt;">//String phone;</span><span style="font-family: "franklin gothic book" , sans-serif; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: "franklin gothic book" , sans-serif; font-size: 12pt;"> </span><span style="font-family: "franklin gothic book" , sans-serif; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: "franklin gothic book" , sans-serif; font-size: 12pt;"> </span><span style="font-family: "franklin gothic book" , sans-serif; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: "franklin gothic book" , sans-serif; font-size: 12pt;"> }</span><span style="font-family: "franklin gothic book" , sans-serif; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: "franklin gothic book" , sans-serif; font-size: 12pt;">}</span><span style="font-family: "franklin gothic book" , sans-serif; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<br /></div>
<div style="margin-bottom: .0001pt; margin: 0in;">
<br /></div>
<div style="margin: 0in 0in 0.0001pt;">
<b><span style="font-size: 13.5pt;">4.min-<o:p></o:p></span></b></div>
<div style="margin-bottom: .0001pt; margin: 0in;">
<span style="font-size: 13.5pt;">To find the minimum element in the system.<o:p></o:p></span></div>
<div style="margin: 0in 0in 0.0001pt;">
<span style="font-size: 13.5pt;">For this we need
to implement the comparator<o:p></o:p></span></div>
<div style="margin: 0in 0in 0.0001pt;">
<b><span style="font-size: 13.5pt;">Signature:</span></b><span style="font-size: 13.5pt;"> min() takes comparator<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: "franklin gothic book" , sans-serif; font-size: 12pt;">(s1,s2)->{return
s1.compareTo(s2);}<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<br /></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<b><span style="color: #7f0055; font-family: "franklin gothic book" , sans-serif; font-size: 12.0pt;">import</span></b><span style="font-family: "franklin gothic book" , sans-serif; font-size: 12pt;"> java.util.ArrayList;</span><span style="font-family: "franklin gothic book" , sans-serif; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<b><span style="color: #7f0055; font-family: "franklin gothic book" , sans-serif; font-size: 12.0pt;">import</span></b><span style="font-family: "franklin gothic book" , sans-serif; font-size: 12pt;"> java.util.List;</span><span style="font-family: "franklin gothic book" , sans-serif; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<b><span style="color: #7f0055; font-family: "franklin gothic book" , sans-serif; font-size: 12.0pt;">public</span></b><span style="font-family: "franklin gothic book" , sans-serif; font-size: 12pt;"> </span><b><span style="color: #7f0055; font-family: "franklin gothic book" , sans-serif; font-size: 12.0pt;">class</span></b><span style="font-family: "franklin gothic book" , sans-serif; font-size: 12pt;"> HelloWorld{</span><span style="font-family: "franklin gothic book" , sans-serif; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<br /></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: "franklin gothic book" , sans-serif; font-size: 12pt;"> </span><b><span style="color: #7f0055; font-family: "franklin gothic book" , sans-serif; font-size: 12.0pt;">public</span></b><span style="font-family: "franklin gothic book" , sans-serif; font-size: 12pt;"> </span><b><span style="color: #7f0055; font-family: "franklin gothic book" , sans-serif; font-size: 12.0pt;">static</span></b><span style="font-family: "franklin gothic book" , sans-serif; font-size: 12pt;"> </span><b><span style="color: #7f0055; font-family: "franklin gothic book" , sans-serif; font-size: 12.0pt;">void</span></b><span style="font-family: "franklin gothic book" , sans-serif; font-size: 12pt;"> main(String []args){</span><span style="font-family: "franklin gothic book" , sans-serif; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: "franklin gothic book" , sans-serif; font-size: 12pt;"> List<String>
phones=</span><b><span style="color: #7f0055; font-family: "franklin gothic book" , sans-serif; font-size: 12.0pt;">new</span></b><span style="font-family: "franklin gothic book" , sans-serif; font-size: 12pt;">
ArrayList<String>();</span><span style="font-family: "franklin gothic book" , sans-serif; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: "franklin gothic book" , sans-serif; font-size: 12pt;"> phones.add(</span><span style="color: #2a00ff; font-family: "franklin gothic book" , sans-serif; font-size: 12.0pt;">"xiomi"</span><span style="font-family: "franklin gothic book" , sans-serif; font-size: 12pt;">);</span><span style="font-family: "franklin gothic book" , sans-serif; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: "franklin gothic book" , sans-serif; font-size: 12pt;"> phones.add(</span><span style="color: #2a00ff; font-family: "franklin gothic book" , sans-serif; font-size: 12.0pt;">"Samsung"</span><span style="font-family: "franklin gothic book" , sans-serif; font-size: 12pt;">);</span><span style="font-family: "franklin gothic book" , sans-serif; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: "franklin gothic book" , sans-serif; font-size: 12pt;">
phones.stream().min((s1,s2)->{</span><b><span style="color: #7f0055; font-family: "franklin gothic book" , sans-serif; font-size: 12.0pt;">return</span></b><span style="font-family: "franklin gothic book" , sans-serif; font-size: 12pt;">
s1.compareTo(s2);}).ifPresent(s->System.out.println(s));</span><span style="font-family: "franklin gothic book" , sans-serif; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: "franklin gothic book" , sans-serif; font-size: 12pt;"> }</span><span style="font-family: "franklin gothic book" , sans-serif; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: "franklin gothic book" , sans-serif; font-size: 12pt;"> }</span><span style="font-family: "franklin gothic book" , sans-serif; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<br /></div>
<br />
<div style="margin-bottom: .0001pt; margin: 0in;">
<br /></div>
</div>
Anonymoushttp://www.blogger.com/profile/07685598617709117616noreply@blogger.com0tag:blogger.com,1999:blog-1266456599706152053.post-91671110566846422832016-08-31T23:20:00.000+05:302016-08-31T23:20:11.563+05:30Java8 Part2 Streams<div dir="ltr" style="text-align: left;" trbidi="on">
<b>Java8 Streams</b><br />The Java conventional style to deal with collection is external iteration.<br />
We deal with collection by<br />
<ul style="text-align: left;">
<li>Internal iteration</li>
<li>External iteration</li>
</ul>
<div style="text-align: left;">
The term <b>external iteration</b> implies you need to explicitly take care of iteration of elements in collection then validate each element and add it to the other list.<br /><br />Where as<b> internal iteration</b> implies.<br />Java8 itself gives capability to iterate each and every element you just need to supply filter criteria.<br /> </div>
<div style="text-align: left;">
For internal iteration it comes with three important methods to deal with collection of objects.<br /> </div>
<div style="text-align: left;">
<b>1.Map<br />2.Filter<br />3.Reduce</b><br /><br /><b><u>1.Map:</u></b><br /></div>
<ul style="text-align: left;">
<li>Map method allows you to process one by one element of collection.</li>
<li>Takes argument as lambda expression </li>
<li>apply lambda expression on every element </li>
<li>Return results.</li>
</ul>
<div style="text-align: left;">
<br />Map generates each processed element in the seperate streams<br /><b>FlatMap: </b>whereas flatmap each processed element flattened into the seperate stream.<br /><br /><u><b>2.Filter</b></u><br />Produces a new Stream that contains only the elements of the original Stream that pass a given test.<br /><br /><u><b>3.Reduce</b></u></div>
<ul style="text-align: left;">
<li>Reductions operation occurs at the end of the all operations.</li>
<li>Hence it is also termed as terminal operation.</li>
</ul>
<div style="text-align: left;">
Generally the methods used for reductions are<br /> 1. Sum<br /> 2..Average<br /> 3. Count<br /> 4. toArray<br /><br /><br /><b>Different kinds of streams </b><br />1.Stream<br />2. Parellal Stream-<br /><br /><b>1.Stream</b><br />Allows you to convert List into Stream Objects<br />Method :listObj.strean()<br /> </div>
<div style="text-align: left;">
<b>2.Parallel Stream</b><br /> You can do operate on your stream in parallel.<br /> When you call parallelStream() it creates several threads and operates on our collection simultaneously.<br /> </div>
</div>
Anonymoushttp://www.blogger.com/profile/07685598617709117616noreply@blogger.com0tag:blogger.com,1999:blog-1266456599706152053.post-54107546369670799872016-08-30T20:02:00.001+05:302016-08-30T20:02:10.430+05:30java8 lambda<div dir="ltr" style="text-align: left;" trbidi="on">
<br />
<br />
<div class="MsoNormal" style="margin: 0in 0in 8pt;">
<div style="text-align: center;">
<span style="font-family: "calibri";"><b><a href="https://www.amazon.in/gp/product/9351197433/ref=as_li_tl?ie=UTF8&camp=3626&creative=24790&creativeASIN=9351197433&linkCode=as2&tag=javashivblogs-21" rel="nofollow">Lambda Expressions</a></b></span></div>
<div style="text-align: center;">
<span style="font-family: "calibri";"><b><br /></b></span></div>
<span style="font-family: "calibri";"><b>What is lambda Expressions?</b></span><br />
<span style="font-family: "calibri";"><b><br /></b></span>
<br />
<div style="text-align: left;">
<span style="font-family: "calibri";"> The lambda expression is just like the function it consist of</span></div>
<div style="text-align: left;">
<a href="https://www.amazon.in/gp/product/9351197433/ref=as_li_tl?ie=UTF8&camp=3626&creative=24790&creativeASIN=9351197433&linkCode=as2&tag=javashivblogs-21" rel="nofollow"><img border="0" src="http://ws-in.amazon-adsystem.com/widgets/q?_encoding=UTF8&ASIN=9351197433&Format=_SL160_&ID=AsinImage&MarketPlace=IN&ServiceVersion=20070822&WS=1&tag=javashivblogs-21" /></a><img alt="" border="0" src="http://ir-in.amazon-adsystem.com/e/ir?t=javashivblogs-21&l=as2&o=31&a=9351197433" height="1" style="border: none !important; margin: 0px !important;" width="1" /><br />
<br />
<ul style="text-align: left;">
<li><span style="font-family: calibri;">List of parameters</span></li>
<li><span style="font-family: calibri;">Method Body</span></li>
<li><span style="font-family: calibri;">return Type</span></li>
</ul>
<br />
<span style="font-family: "calibri";"><br /></span><span style="font-family: "calibri";">Lambda Expression termed as anonymous because it </span><b style="font-family: calibri;">does not have any name.</b></div>
<div style="text-align: left;">
<span style="font-family: "calibri";">Lambda Expression passed as arguments to the methods.</span></div>
<div style="text-align: left;">
<span style="font-family: "calibri";"><br /></span></div>
<div style="text-align: left;">
<span style="font-family: "calibri";"><br /></span></div>
<div style="text-align: left;">
<span style="font-family: "calibri";"><b>Anatomy of Lambda expression :)</b></span></div>
<div style="text-align: left;">
<span style="font-family: "calibri";"><b><br /></b></span></div>
<div style="text-align: left;">
<span style="font-family: "calibri";">Yes guys you heard it right we are going to do the dissection of the Lambda Expression.</span></div>
<div style="text-align: left;">
<span style="font-family: "calibri";"><br /></span></div>
<div style="text-align: left;">
<span style="font-family: "calibri";">Lambda expression=Parameters+Arrow+Method Body</span></div>
<div style="text-align: left;">
<span style="font-family: "calibri";"><b><br /></b></span></div>
<div style="text-align: left;">
<span style="font-family: "calibri";"><i><b>(Car c1,Car 2) -> c1.getPrice().comparTo(c2.getPrice());</b></i></span><br />
<span style="font-family: "calibri";"><i><b><br /></b></i></span>
<span style="font-family: "calibri";"><i>Please have a look at the below code snippets where i have compared codes of Java7 and Java8</i></span><br />
<span style="font-family: "calibri";"><i><br /></i></span></div>
<span style="font-family: "calibri";"><b><u>Example 1</u></b></span><br />
<span style="font-family: "calibri";"><b>Using Java7</b></span><br />
<span style="font-family: "calibri";"><b><br /></b></span>
<span style="font-family: "calibri";">Comparator<Car> byPrice=new Comparator<Car>(){<o:p></o:p></span></div>
<br />
<div class="MsoNormal" style="margin: 0in 0in 8pt;">
<span style="font-family: "calibri";">Public int compare(Car c1,Car c2){<o:p></o:p></span></div>
<br />
<div class="MsoNormal" style="margin: 0in 0in 8pt;">
<span style="font-family: "calibri";"><span style="mso-spacerun: yes;"> </span>return c1.getPrice().compareTo(c2.getPrice());<o:p></o:p></span></div>
<br />
<div class="MsoNormal" style="margin: 0in 0in 8pt;">
<span style="font-family: "calibri";">}<o:p></o:p></span></div>
<br />
<div class="MsoNormal" style="margin: 0in 0in 8pt;">
<span style="font-family: "calibri";">};<o:p></o:p></span></div>
<br />
<div class="MsoNormal" style="margin: 0in 0in 8pt;">
<span style="font-family: "calibri";"><b>By Lambda Expressions</b><o:p></o:p></span></div>
<b>Using Java8</b><br />
<b><br /></b>
<br />
<div class="MsoNormal" style="margin: 0in 0in 8pt;">
<span style="font-family: "calibri";">Comparator<Car> byPrice=</span><span style="font-family: "calibri";">(Car
c1,Car c2)</span><span style="font-family: "calibri";">---></span><span style="font-family: "calibri";">c1.getPrice().compareTo(c2.getPrice());</span></div>
<br />
<b>Example 2</b><br />
<b><br /></b>
<b>Java7</b><br />
class A implements Runnable<br />
{<br />
public void run()<br />
{<br />
System.out.println("I am Java7");<br />
}<br />
}<br />
<br />
<b>By Lambda Expression</b><br />
<b>Java8</b><br />
<b><br /></b>
()->{System.out.println("I am Java8");}<br />
<br />
<b><br /></b>
<b>Advantage of Lambda Interface:</b><br />
<br />
Cleaner Code:Lambdas are your code much easier to read.<br />
<br />
<div class="MsoNormal" style="margin: 0in 0in 8pt;">
</div>
</div>
Anonymoushttp://www.blogger.com/profile/07685598617709117616noreply@blogger.com0tag:blogger.com,1999:blog-1266456599706152053.post-52721422229517300732016-08-27T16:34:00.000+05:302016-09-03T23:39:23.494+05:30Persistence LIife Cycle<div dir="ltr" style="text-align: left;" trbidi="on">
<iframe border="0" frameborder="0" height="250" marginwidth="0" scrolling="no" src="//rcm-na.amazon-adsystem.com/e/cm?o=1&p=12&l=ur1&category=outdoors_hehan_sept16&banner=1ETM4VGAE3GD2S6MQWR2&f=ifr&lc=pf4&linkID=2c8f07a56ea3e3e2cf10196fe7979932&t=javashiv-20&tracking_id=javashiv-20" style="border: none;" width="300"></iframe>
<div dir="ltr" style="text-align: left;" trbidi="on">
<div dir="ltr" id="docs-internal-guid-ff011f0f-cba9-f19f-c069-d6aeaa303bea" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;">
<span style="background-color: transparent; color: black; font-family: "arial"; font-size: 14.666666666666666px; font-style: normal; font-variant: normal; font-weight: 400; text-decoration: none; vertical-align: baseline;">There are in all four stages of Object in hibernate </span></div>
<div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;">
<br /></div>
<div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;">
<span style="background-color: transparent; color: black; font-family: "arial"; font-size: 14.666666666666666px; font-style: normal; font-variant: normal; font-weight: 700; text-decoration: none; vertical-align: baseline;">1.Transient </span></div>
<div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;">
<span style="background-color: transparent; color: black; font-family: "arial"; font-size: 14.666666666666666px; font-style: normal; font-variant: normal; font-weight: 700; text-decoration: none; vertical-align: baseline;">2.Persistent </span></div>
<iframe border="0" frameborder="0" height="250" marginwidth="0" scrolling="no" src="//rcm-na.amazon-adsystem.com/e/cm?o=1&p=12&l=ur1&category=levi_evergreen_fashion&banner=1PBTS8ZBG2QQ6CCAXH02&f=ifr&lc=pf4&linkID=fcbf795d7ae91d6feeea332a374a3665&t=javashiv-20&tracking_id=javashiv-20" style="border: none;" width="300"></iframe>
<div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;">
<span style="background-color: transparent; color: black; font-family: "arial"; font-size: 14.666666666666666px; font-style: normal; font-variant: normal; font-weight: 700; text-decoration: none; vertical-align: baseline;">3.Removed</span></div>
<div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;">
<span style="background-color: transparent; color: black; font-family: "arial"; font-size: 14.666666666666666px; font-style: normal; font-variant: normal; font-weight: 700; text-decoration: none; vertical-align: baseline;">4.Detached</span></div>
<br />
<div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;">
<span style="background-color: transparent; color: black; font-family: "arial"; font-size: 14.666666666666666px; font-style: normal; font-variant: normal; font-weight: 700; text-decoration: none; vertical-align: baseline;"><img alt="HIbernate life cycle.PNG" height="328" src="https://lh4.googleusercontent.com/J7kiP7uSI6nnHyWT8VVxaoXo7I_7IyI2BoRO5ND00vHhJwE7sBvZ5O3KkwIaiw08sicLLmx-9ldEvCnyrHcc4LUZp06QFxYXQ2h1sCC3FuaE7xR9AKbG5CcrLkWfzBT0EbqQDEUT" style="-webkit-transform: rotate(0.00rad); border: none; transform: rotate(0.00rad);" width="624" /></span></div>
<div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;">
<span style="background-color: transparent; color: black; font-family: "arial"; font-size: 14.666666666666666px; font-style: normal; font-variant: normal; font-weight: 700; text-decoration: none; vertical-align: baseline;">1.Transient Objects</span></div>
<br />
<div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;">
<span style="background-color: transparent; color: black; font-family: "arial"; font-size: 14.666666666666666px; font-style: normal; font-variant: normal; font-weight: 400; text-decoration: none; vertical-align: baseline;">When an object is instantiated it's not persistent immediately let's suppose we are creating simple object if I am having in Employee class.</span></div>
<div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;">
<span style="background-color: transparent; color: black; font-family: "arial"; font-size: 14.666666666666666px; font-style: normal; font-variant: normal; font-weight: 400; text-decoration: none; vertical-align: baseline;">We will create instance in this way,</span></div>
<br />
<div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;">
<span style="background-color: transparent; color: black; font-family: "arial"; font-size: 14.666666666666666px; font-style: normal; font-variant: normal; font-weight: 400; text-decoration: none; vertical-align: baseline;"> Employee emp= new employee();</span></div>
<br />
<div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;">
<span style="background-color: transparent; color: black; font-family: "arial"; font-size: 14.666666666666666px; font-style: normal; font-variant: normal; font-weight: 400; text-decoration: none; vertical-align: baseline;">When we create object it is in transient state.</span></div>
<div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;">
<span style="background-color: transparent; color: black; font-family: "arial"; font-size: 14.666666666666666px; font-style: normal; font-variant: normal; font-weight: 400; text-decoration: none; vertical-align: baseline;">Once scope of the method where object is created finishes object will be garbage collected.</span></div>
<br />
<div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;">
<span style="background-color: transparent; color: black; font-family: "arial"; font-size: 14.666666666666666px; font-style: normal; font-variant: normal; font-weight: 700; text-decoration: none; vertical-align: baseline;">2.Persistent Objects</span></div>
<br />
<div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt; text-indent: 36pt;">
<span style="background-color: transparent; color: black; font-family: "arial"; font-size: 14.666666666666666px; font-style: normal; font-variant: normal; font-weight: 400; text-decoration: none; vertical-align: baseline;">So in order to save such kind of objects Hibernate Persistence came in picture so the persistent manager allows us to save such kind of objects with the help of save method.</span></div>
<br />
<div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;">
<span style="background-color: transparent; color: black; font-family: "arial"; font-size: 14.666666666666666px; font-style: normal; font-variant: normal; font-weight: 400; text-decoration: none; vertical-align: baseline;">session.save(emp);</span></div>
<div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;">
<span style="background-color: transparent; color: black; font-family: "arial"; font-size: 14.666666666666666px; font-style: normal; font-variant: normal; font-weight: 400; text-decoration: none; vertical-align: baseline;">session.update(emp);</span></div>
<br />
<div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;">
<span style="background-color: transparent; color: black; font-family: "arial"; font-size: 14.666666666666666px; font-style: normal; font-variant: normal; font-weight: 400; text-decoration: none; vertical-align: baseline;"> Persistent system manager will save the object having valid database entry and with valid primary key identifier.we create while declaring entity.</span></div>
<div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;">
<span style="background-color: transparent; color: black; font-family: "arial"; font-size: 14.666666666666666px; font-style: normal; font-variant: normal; font-weight: 400; text-decoration: none; vertical-align: baseline;">We Declare Primary key and entity using these ways.</span></div>
<br />
<div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;">
<span style="background-color: transparent; color: black; font-family: "arial"; font-size: 14.666666666666666px; font-style: normal; font-variant: normal; font-weight: 700; text-decoration: none; vertical-align: baseline;">XML</span></div>
<br />
<div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;">
<span style="background-color: transparent; color: black; font-family: "arial"; font-size: 14.666666666666666px; font-style: normal; font-variant: normal; font-weight: 400; text-decoration: none; vertical-align: baseline;"><hibernate-mapping></span></div>
<div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;">
<span style="background-color: transparent; color: black; font-family: "arial"; font-size: 14.666666666666666px; font-style: normal; font-variant: normal; font-weight: 400; text-decoration: none; vertical-align: baseline;"> <class name="pojo1" table="pojo1" discriminator-value="s"></span></div>
<div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;">
<span style="background-color: transparent; color: black; font-family: "arial"; font-size: 14.666666666666666px; font-style: normal; font-variant: normal; font-weight: 400; text-decoration: none; vertical-align: baseline;"> <id name="empid" type="string" ></span></div>
<div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;">
<span style="background-color: transparent; color: black; font-family: "arial"; font-size: 14.666666666666666px; font-style: normal; font-variant: normal; font-weight: 400; text-decoration: none; vertical-align: baseline;"> <generator class="assigned"/></span></div>
<div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;">
<span style="background-color: transparent; color: black; font-family: "arial"; font-size: 14.666666666666666px; font-style: normal; font-variant: normal; font-weight: 400; text-decoration: none; vertical-align: baseline;"></hibernate-mapping></span></div>
<br />
<div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;">
<span style="background-color: transparent; color: black; font-family: "arial"; font-size: 14.666666666666666px; font-style: normal; font-variant: normal; font-weight: 700; text-decoration: none; vertical-align: baseline;">Hibernate</span></div>
<br />
<div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;">
<span style="background-color: transparent; color: black; font-family: "arial"; font-size: 14.666666666666666px; font-style: normal; font-variant: normal; font-weight: 400; text-decoration: none; vertical-align: baseline;">@javax.persistence.Id before the appropriate field in POJO with @Column</span></div>
<div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;">
<span style="background-color: transparent; color: black; font-family: "arial"; font-size: 14.666666666666666px; font-style: normal; font-variant: normal; font-weight: 400; text-decoration: none; vertical-align: baseline;">@Entity</span></div>
<div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;">
<span style="background-color: transparent; color: black; font-family: "arial"; font-size: 14.666666666666666px; font-style: normal; font-variant: normal; font-weight: 400; text-decoration: none; vertical-align: baseline;">Class Employee implements Serializable</span></div>
<div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;">
<span style="background-color: transparent; color: black; font-family: "arial"; font-size: 14.666666666666666px; font-style: normal; font-variant: normal; font-weight: 400; text-decoration: none; vertical-align: baseline;">@Id</span></div>
<div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;">
<span style="background-color: transparent; color: black; font-family: "arial"; font-size: 14.666666666666666px; font-style: normal; font-variant: normal; font-weight: 400; text-decoration: none; vertical-align: baseline;">@Column(name="user_id")</span></div>
<div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;">
<span style="background-color: transparent; color: black; font-family: "arial"; font-size: 14.666666666666666px; font-style: normal; font-variant: normal; font-weight: 400; text-decoration: none; vertical-align: baseline;">Private String userId</span></div>
<br />
<div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;">
<span style="background-color: transparent; color: black; font-family: "arial"; font-size: 14.666666666666666px; font-style: normal; font-variant: normal; font-weight: 400; text-decoration: none; vertical-align: baseline;">When I am going to save object with the help of hibernate session.You can save this object at this stage.Peristent instance are always associated with persistence context. If you want to save your changed records then you can set </span><span style="background-color: transparent; color: black; font-family: "arial"; font-size: 14.666666666666666px; font-style: normal; font-variant: normal; font-weight: 700; text-decoration: none; vertical-align: baseline;">dynamic update=true</span><span style="background-color: transparent; color: black; font-family: "arial"; font-size: 14.666666666666666px; font-style: normal; font-variant: normal; font-weight: 400; text-decoration: none; vertical-align: baseline;"> that means once you changing some column values it will be updated automatically.</span></div>
<br />
<div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;">
<span style="background-color: transparent; color: black; font-family: "arial"; font-size: 14.666666666666666px; font-style: normal; font-variant: normal; font-weight: 700; text-decoration: none; vertical-align: baseline;">3.Removed Object</span></div>
<br />
<div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt; text-indent: 36pt;">
<span style="background-color: transparent; color: black; font-family: "arial"; font-size: 14.666666666666666px; font-style: normal; font-variant: normal; font-weight: 400; text-decoration: none; vertical-align: baseline;">You can delete in entity instance by removing all the references on the object it will go to the remove state. Persistence manager signals that this object is in removes state and it is been scheduled for deletion at the end of the transaction so the remove object should not be used again for any course because it won't be available as soon as the operation completes so you need to discard any kind of references you are holding for such kind of object.</span></div>
<br />
<div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;">
<span style="background-color: transparent; color: black; font-family: "arial"; font-size: 14.666666666666666px; font-style: normal; font-variant: normal; font-weight: 700; text-decoration: none; vertical-align: baseline;">4.Detached Object</span></div>
<br />
<div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt; text-indent: 36pt;">
<span style="background-color: transparent; color: black; font-family: "arial"; font-size: 14.666666666666666px; font-style: normal; font-variant: normal; font-weight: 400; text-decoration: none; vertical-align: baseline;"> Detached object is the one which is in initial stage is transient So now to save the transient object what we do we call persistent manage’s save or update method that will make an object is persistence and as long as we are in the persistence context that object is supposed to be in persistent stage.</span></div>
<br />
<div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;">
<span style="background-color: transparent; color: black; font-family: "arial"; font-size: 14.666666666666666px; font-style: normal; font-variant: normal; font-weight: 400; text-decoration: none; vertical-align: baseline;">Now imagine you're closing this persistence context so once the work is done persistence context is closed but we are still having the handle to that reference so what we supposed to do with the reference now because we are done.The object whose reference you are holding now is no longer guaranteed to be synchronised with the database so it is no longer attached to persistence context.</span></div>
<br />
<div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;">
<span style="background-color: transparent; color: black; font-family: "arial"; font-size: 14.666666666666666px; font-style: normal; font-variant: normal; font-weight: 400; text-decoration: none; vertical-align: baseline;">You can work on the detached object can modify it you can do when you place in with it now the one thing you can do if you want to save the modification.</span></div>
<br />
<div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;">
<span style="background-color: transparent; color: black; font-family: "arial"; font-size: 14.666666666666666px; font-style: normal; font-variant: normal; font-weight: 700; text-decoration: none; vertical-align: baseline;">You can perform two operations </span></div>
<div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;">
<span style="background-color: transparent; color: black; font-family: "arial"; font-size: 14.666666666666666px; font-style: normal; font-variant: normal; font-weight: 700; text-decoration: none; vertical-align: baseline;">1.Reattach</span></div>
<div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;">
<span style="background-color: transparent; color: black; font-family: "arial"; font-size: 14.666666666666666px; font-style: normal; font-variant: normal; font-weight: 700; text-decoration: none; vertical-align: baseline;">2.Merge </span></div>
<br />
<div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;">
<span style="background-color: transparent; color: black; font-family: "arial"; font-size: 14.666666666666666px; font-style: normal; font-variant: normal; font-weight: 400; text-decoration: none; vertical-align: baseline;">However Java persistence allows you or recommends you to do merging so merging implies The ability to take object from persistence context to the presentation layer and later reuse them in a new persistence context is advantage of JPA.</span></div>
</div>
</div>
If you really like this tutorial please Share this tutorial.
<iframe border="0" frameborder="0" height="250" marginwidth="0" scrolling="no" src="//rcm-na.amazon-adsystem.com/e/cm?o=1&p=12&l=ur1&category=primegift&banner=10BSGCHPCJG0HZN45H82&f=ifr&lc=pf4&linkID=2fe84d8946731336e866715f55f2c1d0&t=javashiv-20&tracking_id=javashiv-20" style="border: none;" width="300"></iframe>Anonymoushttp://www.blogger.com/profile/07685598617709117616noreply@blogger.com0tag:blogger.com,1999:blog-1266456599706152053.post-45303151994520427832016-08-25T22:56:00.001+05:302016-08-25T22:56:28.367+05:30Cool Gadgets<SCRIPT charset="utf-8" type="text/javascript" src="http://ws-in.amazon-adsystem.com/widgets/q?rt=tf_cw&ServiceVersion=20070822&MarketPlace=IN&ID=V20070822%2FIN%2Fjavashivblogs-21%2F8010%2Ff73b4cfa-e032-4405-8bae-bb2d5fa64b40&Operation=GetScriptTemplate"> </SCRIPT> <NOSCRIPT><A rel="nofollow" HREF="http://ws-in.amazon-adsystem.com/widgets/q?rt=tf_cw&ServiceVersion=20070822&MarketPlace=IN&ID=V20070822%2FIN%2Fjavashivblogs-21%2F8010%2Ff73b4cfa-e032-4405-8bae-bb2d5fa64b40&Operation=NoScript">Amazon.in Widgets</A></NOSCRIPT>
<div dir="ltr" style="text-align: left;" trbidi="on">
<br /></div>
Anonymoushttp://www.blogger.com/profile/07685598617709117616noreply@blogger.com0tag:blogger.com,1999:blog-1266456599706152053.post-19363783411485226362016-07-22T12:51:00.003+05:302016-09-02T16:26:08.662+05:30Filter in AngularJs<div dir="ltr" style="text-align: left;" trbidi="on">
<script type="text/javascript">
amzn_assoc_placement = "adunit0";
amzn_assoc_search_bar = "true";
amzn_assoc_tracking_id = "javashiv-20";
amzn_assoc_ad_mode = "manual";
amzn_assoc_ad_type = "smart";
amzn_assoc_marketplace = "amazon";
amzn_assoc_region = "US";
amzn_assoc_title = "My Amazon Picks";
amzn_assoc_linkid = "d4099f95b195f6e0d56a163de794db3f";
amzn_assoc_asins = "1617291331,099134460X,1118531647,1617291994";
</script>
<script src="//z-na.amazon-adsystem.com/widgets/onejs?MarketPlace=US"></script>
<br />
<div dir="ltr" style="text-align: left;" trbidi="on">
<div class="MsoNormal">
<span style="font-family: "arial rounded mt bold" , sans-serif; font-size: 12.0pt; line-height: 107%;"><!DOCTYPE html><o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-family: "arial rounded mt bold" , sans-serif; font-size: 12.0pt; line-height: 107%;"><html><o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-family: "arial rounded mt bold" , sans-serif; font-size: 12.0pt; line-height: 107%;"><head><o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-family: "arial rounded mt bold" , sans-serif; font-size: 12.0pt; line-height: 107%;"><script
src="http://ajax.googleapis.com/ajax/libs/angularjs/1.4.8/angular.min.js"></script><o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-family: "arial rounded mt bold" , sans-serif; font-size: 12.0pt; line-height: 107%;"><script><o:p></o:p></span></div>
<iframe frameborder="0" marginheight="0" marginwidth="0" scrolling="no" src="//ws-na.amazon-adsystem.com/widgets/q?ServiceVersion=20070822&OneJS=1&Operation=GetAdHtml&MarketPlace=US&source=ac&ref=tf_til&ad_type=product_link&tracking_id=javashiv-20&marketplace=amazon&region=US&placement=B01A5IIDEQ&asins=B01A5IIDEQ&linkId=8a50a0ff7603c1297dd0b0becde32691&show_border=true&link_opens_in_new_window=false&price_color=333333&title_color=0066c0&bg_color=ffffff" style="height: 240px; width: 120px;">
</iframe> <br />
<div class="MsoNormal">
<span style="font-family: "arial rounded mt bold" , sans-serif; font-size: 12.0pt; line-height: 107%;">var app=angular.module('myApp',[]);<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-family: "arial rounded mt bold" , sans-serif; font-size: 12.0pt; line-height: 107%;">app.controller('ct',function($scope){<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-family: "arial rounded mt bold" , sans-serif; font-size: 12.0pt; line-height: 107%;">$scope.arr=["Shiv","Jagan"];<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-family: "arial rounded mt bold" , sans-serif; font-size: 12.0pt; line-height: 107%;">});<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-family: "arial rounded mt bold" , sans-serif; font-size: 12.0pt; line-height: 107%;"></script><o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-family: "arial rounded mt bold" , sans-serif; font-size: 12.0pt; line-height: 107%;"></head><o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-family: "arial rounded mt bold" , sans-serif; font-size: 12.0pt; line-height: 107%;"><body><o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-family: "arial rounded mt bold" , sans-serif; font-size: 12.0pt; line-height: 107%;"><div ng-app="myApp"
id="u" ng-controller="ct"><o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-family: "arial rounded mt bold" , sans-serif; font-size: 12.0pt; line-height: 107%;">Name<input type="text"
ng-model="userName"/><o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-family: "arial rounded mt bold" , sans-serif; font-size: 12.0pt; line-height: 107%;"><ul><o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-family: "arial rounded mt bold" , sans-serif; font-size: 12.0pt; line-height: 107%;"><li ng-repeat="x in
arr|filter:userName"><o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-family: "arial rounded mt bold" , sans-serif; font-size: 12.0pt; line-height: 107%;">User Name:{{x}}<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-family: "arial rounded mt bold" , sans-serif; font-size: 12.0pt; line-height: 107%;"></ul><o:p></o:p></span></div>
<br />
<div class="MsoNormal">
<span style="font-family: "arial rounded mt bold" , sans-serif; font-size: 12.0pt; line-height: 107%;"></div></span><o:p></o:p></div>
</div>
</div>
Anonymoushttp://www.blogger.com/profile/07685598617709117616noreply@blogger.com0tag:blogger.com,1999:blog-1266456599706152053.post-40632706132908865962016-07-12T14:43:00.001+05:302016-09-02T16:27:04.595+05:30Exception Handling puzzle<div dir="ltr" style="text-align: left;" trbidi="on">
<script type="text/javascript">
amzn_assoc_placement = "adunit0";
amzn_assoc_search_bar = "true";
amzn_assoc_tracking_id = "javashiv-20";
amzn_assoc_ad_mode = "manual";
amzn_assoc_ad_type = "smart";
amzn_assoc_marketplace = "amazon";
amzn_assoc_region = "US";
amzn_assoc_title = "My Amazon Picks";
amzn_assoc_linkid = "11c183675348da67b6846d88cf468a4c";
amzn_assoc_asins = "0071809252,0071808558,1617291994,0134177304";
</script>
<br />
<div dir="ltr" style="text-align: left;" trbidi="on">
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: "arial rounded mt bold" , sans-serif; font-size: 12.0pt;">Hi please pay close attention to this small code snippette.<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: "arial rounded mt bold" , sans-serif; font-size: 12.0pt;">As our rule says exception handling mechanism <o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: "arial rounded mt bold" , sans-serif; font-size: 12.0pt;">The finally block always gets executed even if we are using the
return statements.<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<br /></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: "arial rounded mt bold" , sans-serif; font-size: 12.0pt;">The code will return the <b>OP as
30</b><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<br /></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<b><span style="color: #7f0055; font-family: "consolas"; font-size: 12.0pt;">public</span></b><span style="font-family: "consolas"; font-size: 12pt;"> </span><b><span style="color: #7f0055; font-family: "consolas"; font-size: 12.0pt;">class</span></b><span style="font-family: "consolas"; font-size: 12pt;"> TryCatchDemo {</span><span style="font-family: "consolas"; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<b><span style="color: #7f0055; font-family: "consolas"; font-size: 12.0pt;">static</span></b><span style="font-family: "consolas"; font-size: 12pt;"> </span><b><span style="background: silver; color: #7f0055; font-family: "consolas"; font-size: 12.0pt;">int</span></b><span style="font-family: "consolas"; font-size: 12pt;"> giveInt()</span><span style="font-family: "consolas"; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: "consolas"; font-size: 12pt;">{</span><span style="font-family: "consolas"; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: "consolas"; font-size: 12pt;"> </span><b><span style="color: #7f0055; font-family: "consolas"; font-size: 12.0pt;">try</span></b><span style="font-family: "consolas"; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: "consolas"; font-size: 12pt;"> {</span><span style="font-family: "consolas"; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: "consolas"; font-size: 12pt;"> </span><b><span style="background: silver; color: #7f0055; font-family: "consolas"; font-size: 12.0pt;">return</span></b><span style="background: silver; 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="margin-bottom: 0.0001pt;">
<span style="font-family: "consolas"; font-size: 12pt;"> }</span><span style="font-family: "consolas"; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: "consolas"; font-size: 12pt;"> </span><b><span style="color: #7f0055; font-family: "consolas"; font-size: 12.0pt;">catch</span></b><span style="font-family: "consolas"; font-size: 12pt;">(Exception </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="margin-bottom: 0.0001pt;">
<span style="font-family: "consolas"; font-size: 12pt;"> {</span><span style="font-family: "consolas"; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: "consolas"; font-size: 12pt;"> </span><b><span style="background: silver; color: #7f0055; font-family: "consolas"; font-size: 12.0pt;">return</span></b><span style="background: silver; font-family: "consolas"; font-size: 12pt;"> 20;</span><span style="font-family: "consolas"; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: "consolas"; font-size: 12pt;"> }</span><span style="font-family: "consolas"; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: "consolas"; font-size: 12pt;"> </span><b><span style="color: #7f0055; font-family: "consolas"; font-size: 12.0pt;">finally</span></b><span style="font-family: "consolas"; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: "consolas"; font-size: 12pt;"> {</span><span style="font-family: "consolas"; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: "consolas"; font-size: 12pt;"> </span><b><span style="background: silver; color: #7f0055; font-family: "consolas"; font-size: 12.0pt;">return</span></b><span style="background: silver; font-family: "consolas"; font-size: 12pt;"> 30;</span><span style="font-family: "consolas"; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: "consolas"; font-size: 12pt;"> }</span><span style="font-family: "consolas"; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: "consolas"; font-size: 12pt;"> </span><span style="font-family: "consolas"; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: "consolas"; font-size: 12pt;"> }</span><span style="font-family: "consolas"; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: "consolas"; font-size: 12pt;"> </span><b><span style="color: #7f0055; font-family: "consolas"; font-size: 12.0pt;">public</span></b><span style="font-family: "consolas"; font-size: 12pt;"> </span><b><span style="color: #7f0055; font-family: "consolas"; font-size: 12.0pt;">static</span></b><span style="font-family: "consolas"; font-size: 12pt;"> </span><b><span style="color: #7f0055; font-family: "consolas"; font-size: 12.0pt;">void</span></b><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="margin-bottom: 0.0001pt;">
<span style="font-family: "consolas"; font-size: 12pt;"> System.</span><b><i><span style="color: #0000c0; font-family: "consolas"; font-size: 12.0pt;">out</span></i></b><span style="font-family: "consolas"; font-size: 12pt;">.println(</span><span style="color: #2a00ff; font-family: "consolas"; font-size: 12.0pt;">""</span><span style="font-family: "consolas"; font-size: 12pt;">+<i>giveInt</i>());</span><span style="font-family: "consolas"; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<br /></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: "consolas"; font-size: 12pt;"> }</span><span style="font-family: "consolas"; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<br /></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: "consolas"; font-size: 12pt;">}</span><span style="font-family: "consolas"; font-size: 12.0pt;"><o:p></o:p></span></div>
<br />
<div class="MsoNormal">
<br /></div>
</div>
<iframe frameborder="0" marginheight="0" marginwidth="0" scrolling="no" src="//ws-na.amazon-adsystem.com/widgets/q?ServiceVersion=20070822&OneJS=1&Operation=GetAdHtml&MarketPlace=US&source=ac&ref=tf_til&ad_type=product_link&tracking_id=javashiv-20&marketplace=amazon&region=US&placement=B010Q588D4&asins=B010Q588D4&linkId=2d1f51ccbb1dfec80acd8c719da7675b&show_border=true&link_opens_in_new_window=false&price_color=333333&title_color=0066c0&bg_color=ffffff" style="height: 240px; width: 120px;">
</iframe></div>
Anonymoushttp://www.blogger.com/profile/07685598617709117616noreply@blogger.com0tag:blogger.com,1999:blog-1266456599706152053.post-33096376729844554742016-07-12T14:35:00.001+05:302016-09-02T16:27:21.101+05:30StringBuilder Demo<div dir="ltr" style="text-align: left;" trbidi="on">
<iframe frameborder="0" marginheight="0" marginwidth="0" scrolling="no" src="//ws-na.amazon-adsystem.com/widgets/q?ServiceVersion=20070822&OneJS=1&Operation=GetAdHtml&MarketPlace=US&source=ac&ref=tf_til&ad_type=product_link&tracking_id=javashiv-20&marketplace=amazon&region=US&placement=B017YEA6QW&asins=B017YEA6QW&linkId=ed85184b5d9f9386f7499288259e24f5&show_border=true&link_opens_in_new_window=false&price_color=333333&title_color=0066c0&bg_color=ffffff" style="height: 240px; width: 120px;">
</iframe><br />
<script type="text/javascript">
amzn_assoc_placement = "adunit0";
amzn_assoc_search_bar = "true";
amzn_assoc_tracking_id = "javashiv-20";
amzn_assoc_ad_mode = "manual";
amzn_assoc_ad_type = "smart";
amzn_assoc_marketplace = "amazon";
amzn_assoc_region = "US";
amzn_assoc_title = "My Amazon Picks";
amzn_assoc_linkid = "11c183675348da67b6846d88cf468a4c";
amzn_assoc_asins = "0071809252,0071808558,1617291994,0134177304";
</script>
<script src="//z-na.amazon-adsystem.com/widgets/onejs?MarketPlace=US"></script>
<br />
<div dir="ltr" style="text-align: left;" trbidi="on">
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<br /></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<b><span style="color: #7f0055; font-family: "consolas"; font-size: 12.0pt;">public</span></b><span style="font-family: "consolas"; font-size: 12pt;"> </span><b><span style="color: #7f0055; font-family: "consolas"; font-size: 12.0pt;">class</span></b><span style="font-family: "consolas"; font-size: 12pt;"> StringBuilderDemo {</span><span style="font-family: "consolas"; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<br /></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: "consolas"; font-size: 12pt;"> </span><b><span style="color: #7f0055; font-family: "consolas"; font-size: 12.0pt;">public</span></b><span style="font-family: "consolas"; font-size: 12pt;"> </span><b><span style="color: #7f0055; font-family: "consolas"; font-size: 12.0pt;">static</span></b><span style="font-family: "consolas"; font-size: 12pt;"> </span><b><span style="color: #7f0055; font-family: "consolas"; font-size: 12.0pt;">void</span></b><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="margin-bottom: 0.0001pt;">
<span style="font-family: "consolas"; font-size: 12pt;"> StringBuilder </span><span style="color: #6a3e3e; font-family: "consolas"; font-size: 12.0pt;">sb</span><span style="font-family: "consolas"; font-size: 12pt;"> = </span><b><span style="color: #7f0055; font-family: "consolas"; font-size: 12.0pt;">new</span></b><span style="font-family: "consolas"; font-size: 12pt;"> StringBuilder(</span><span style="color: #2a00ff; font-family: "consolas"; font-size: 12.0pt;">"Shiv"</span><span style="font-family: "consolas"; font-size: 12pt;">);</span><span style="font-family: "consolas"; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: "consolas"; font-size: 12pt;"> </span><span style="font-family: "consolas"; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: "consolas"; font-size: 12pt;"> System.</span><b><i><span style="color: #0000c0; font-family: "consolas"; font-size: 12.0pt;">out</span></i></b><span style="font-family: "consolas"; font-size: 12pt;">.println(</span><span style="color: #2a00ff; font-family: "consolas"; font-size: 12.0pt;">"Original
String "</span><span style="font-family: "consolas"; font-size: 12pt;"> + </span><span style="color: #6a3e3e; font-family: "consolas"; font-size: 12.0pt;">sb</span><span style="font-family: "consolas"; font-size: 12pt;">);</span><span style="font-family: "consolas"; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: "consolas"; font-size: 12pt;"> </span><span style="font-family: "consolas"; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: "consolas"; font-size: 12pt;"> System.</span><b><i><span style="color: #0000c0; font-family: "consolas"; font-size: 12.0pt;">out</span></i></b><span style="font-family: "consolas"; font-size: 12pt;">.println(</span><span style="color: #2a00ff; font-family: "consolas"; font-size: 12.0pt;">"substring:
"</span><span style="font-family: "consolas"; font-size: 12pt;"> +
</span><span style="color: #6a3e3e; font-family: "consolas"; font-size: 12.0pt;">sb</span><span style="font-family: "consolas"; font-size: 12pt;">.substring(0,2));</span><span style="font-family: "consolas"; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: "consolas"; font-size: 12pt;"> </span><span style="font-family: "consolas"; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: "consolas"; font-size: 12pt;"> </span><span style="color: #3f7f5f; font-family: "consolas"; font-size: 12.0pt;">//
StringBuilder java.lang.StringBuilder.replace(<u>int</u> start, <u>int</u>
end, String <u>str</u>)</span><span style="font-family: "consolas"; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: "consolas"; font-size: 12pt;"> </span><span style="color: #6a3e3e; font-family: "consolas"; font-size: 12.0pt;">sb</span><span style="font-family: "consolas"; font-size: 12pt;"> = </span><span style="color: #6a3e3e; font-family: "consolas"; font-size: 12.0pt;">sb</span><span style="font-family: "consolas"; font-size: 12pt;">.replace(4,4,</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="margin-bottom: 0.0001pt;">
<span style="font-family: "consolas"; font-size: 12pt;"> System.</span><b><i><span style="color: #0000c0; font-family: "consolas"; font-size: 12.0pt;">out</span></i></b><span style="font-family: "consolas"; font-size: 12pt;">.println(</span><span style="color: #2a00ff; font-family: "consolas"; font-size: 12.0pt;">"replace
String from location 4 to 4 charecters from location 4 "</span><span style="font-family: "consolas"; font-size: 12pt;"> + </span><span style="color: #6a3e3e; font-family: "consolas"; font-size: 12.0pt;">sb</span><span style="font-family: "consolas"; font-size: 12pt;">);</span><span style="font-family: "consolas"; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: "consolas"; font-size: 12pt;"> </span><span style="font-family: "consolas"; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: "consolas"; font-size: 12pt;"> System.</span><b><i><span style="color: #0000c0; font-family: "consolas"; font-size: 12.0pt;">out</span></i></b><span style="font-family: "consolas"; font-size: 12pt;">.println(</span><span style="color: #2a00ff; font-family: "consolas"; font-size: 12.0pt;">"indexOf()
charecter S is "</span><span style="font-family: "consolas"; font-size: 12pt;"> + </span><span style="color: #6a3e3e; font-family: "consolas"; font-size: 12.0pt;">sb</span><span style="font-family: "consolas"; font-size: 12pt;">.indexOf(</span><span style="color: #2a00ff; 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="margin-bottom: 0.0001pt;">
<span style="font-family: "consolas"; font-size: 12pt;"> </span><span style="font-family: "consolas"; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: "consolas"; font-size: 12pt;">
</span><span style="color: #3f7f5f; font-family: "consolas"; font-size: 12.0pt;">//Syntax
StringBuilder java.lang.StringBuilder.insert(<u>int</u> offset, String <u>str</u>)</span><span style="font-family: "consolas"; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: "consolas"; font-size: 12pt;"> </span><span style="color: #6a3e3e; font-family: "consolas"; font-size: 12.0pt;">sb</span><span style="font-family: "consolas"; font-size: 12pt;"> = </span><span style="color: #6a3e3e; font-family: "consolas"; font-size: 12.0pt;">sb</span><span style="font-family: "consolas"; font-size: 12pt;">.insert(5, </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="margin-bottom: 0.0001pt;">
<span style="font-family: "consolas"; font-size: 12pt;"> System.</span><b><i><span style="color: #0000c0; font-family: "consolas"; font-size: 12.0pt;">out</span></i></b><span style="font-family: "consolas"; font-size: 12pt;">.println(</span><span style="color: #2a00ff; font-family: "consolas"; font-size: 12.0pt;">"inserted
String "</span><span style="font-family: "consolas"; font-size: 12pt;"> + </span><span style="color: #6a3e3e; font-family: "consolas"; font-size: 12.0pt;">sb</span><span style="font-family: "consolas"; font-size: 12pt;">);</span><span style="font-family: "consolas"; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: "consolas"; font-size: 12pt;"> </span><span style="font-family: "consolas"; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: "consolas"; font-size: 12pt;"> </span><span style="color: #3f7f5f; font-family: "consolas"; font-size: 12.0pt;">//Syntax StringBuilder
java.lang.StringBuilder.append(String <u>str</u>) </span><span style="font-family: "consolas"; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: "consolas"; font-size: 12pt;"> </span><span style="color: #6a3e3e; font-family: "consolas"; font-size: 12.0pt;">sb</span><span style="font-family: "consolas"; font-size: 12pt;"> = </span><span style="color: #6a3e3e; font-family: "consolas"; font-size: 12.0pt;">sb</span><span style="font-family: "consolas"; font-size: 12pt;">.append(</span><span style="color: #2a00ff; font-family: "consolas"; font-size: 12.0pt;">" lord"</span><span style="font-family: "consolas"; font-size: 12pt;">);</span><span style="font-family: "consolas"; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: "consolas"; font-size: 12pt;"> System.</span><b><i><span style="color: #0000c0; font-family: "consolas"; font-size: 12.0pt;">out</span></i></b><span style="font-family: "consolas"; font-size: 12pt;">.println(</span><span style="color: #2a00ff; font-family: "consolas"; font-size: 12.0pt;">"append:
"</span><span style="font-family: "consolas"; font-size: 12pt;"> +
</span><span style="color: #6a3e3e; font-family: "consolas"; font-size: 12.0pt;">sb</span><span style="font-family: "consolas"; font-size: 12pt;">);</span><span style="font-family: "consolas"; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: "consolas"; font-size: 12pt;"> </span><span style="font-family: "consolas"; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: "consolas"; font-size: 12pt;"> System.</span><b><i><span style="color: #0000c0; font-family: "consolas"; font-size: 12.0pt;">out</span></i></b><span style="font-family: "consolas"; font-size: 12pt;">.println(</span><span style="color: #2a00ff; font-family: "consolas"; font-size: 12.0pt;">"lastIndexOf
charecter i is "</span><span style="font-family: "consolas"; font-size: 12pt;"> + </span><span style="color: #6a3e3e; font-family: "consolas"; font-size: 12.0pt;">sb</span><span style="font-family: "consolas"; font-size: 12pt;">.lastIndexOf(</span><span style="color: #2a00ff; 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="margin-bottom: 0.0001pt;">
<span style="font-family: "consolas"; font-size: 12pt;"> </span><span style="color: #6a3e3e; font-family: "consolas"; font-size: 12.0pt;">sb</span><span style="font-family: "consolas"; font-size: 12pt;"> = </span><span style="color: #6a3e3e; font-family: "consolas"; font-size: 12.0pt;">sb</span><span style="font-family: "consolas"; font-size: 12pt;">.reverse();</span><span style="font-family: "consolas"; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: "consolas"; font-size: 12pt;"> System.</span><b><i><span style="color: #0000c0; font-family: "consolas"; font-size: 12.0pt;">out</span></i></b><span style="font-family: "consolas"; font-size: 12pt;">.println(</span><span style="color: #2a00ff; font-family: "consolas"; font-size: 12.0pt;">"reverse:
"</span><span style="font-family: "consolas"; font-size: 12pt;"> +
</span><span style="color: #6a3e3e; font-family: "consolas"; font-size: 12.0pt;">sb</span><span style="font-family: "consolas"; font-size: 12pt;">);</span><span style="font-family: "consolas"; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: "consolas"; font-size: 12pt;"> }</span><span style="font-family: "consolas"; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<br /></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: "consolas"; font-size: 12pt;">}</span><span style="font-family: "consolas"; font-size: 12.0pt;"><o:p></o:p></span></div>
<br />
<div class="MsoNormal">
<br /></div>
</div>
<iframe frameborder="0" marginheight="0" marginwidth="0" scrolling="no" src="//ws-na.amazon-adsystem.com/widgets/q?ServiceVersion=20070822&OneJS=1&Operation=GetAdHtml&MarketPlace=US&source=ac&ref=tf_til&ad_type=product_link&tracking_id=javashiv-20&marketplace=amazon&region=US&placement=B0018OLTAC&asins=B0018OLTAC&linkId=8422a4000e3a0650d240988b5aac7918&show_border=true&link_opens_in_new_window=false&price_color=333333&title_color=0066c0&bg_color=ffffff" style="height: 240px; width: 120px;">
</iframe>
</div>
Anonymoushttp://www.blogger.com/profile/07685598617709117616noreply@blogger.com0tag:blogger.com,1999:blog-1266456599706152053.post-6169894808375211852016-07-12T12:42:00.003+05:302016-09-02T16:27:39.333+05:30String Demo<div dir="ltr" style="text-align: left;" trbidi="on">
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<br /></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<b><span style="color: #7f0055; font-family: "consolas"; font-size: 10.0pt;">public</span></b><span style="font-family: "consolas"; font-size: 10pt;"> </span><b><span style="color: #7f0055; font-family: "consolas"; font-size: 10.0pt;">class</span></b><span style="font-family: "consolas"; font-size: 10pt;"> StringDemo {</span><span style="font-family: "consolas"; font-size: 10.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<br /></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: "consolas"; font-size: 10pt;"> </span><b><span style="color: #7f0055; font-family: "consolas"; font-size: 10.0pt;">public</span></b><span style="font-family: "consolas"; font-size: 10pt;"> </span><b><span style="color: #7f0055; font-family: "consolas"; font-size: 10.0pt;">static</span></b><span style="font-family: "consolas"; font-size: 10pt;"> </span><b><span style="color: #7f0055; font-family: "consolas"; font-size: 10.0pt;">void</span></b><span style="font-family: "consolas"; font-size: 10pt;"> main(String[] </span><span style="color: #6a3e3e; font-family: "consolas"; font-size: 10.0pt;">args</span><span style="font-family: "consolas"; font-size: 10pt;">) {</span><span style="font-family: "consolas"; font-size: 10.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: "consolas"; font-size: 10pt;"> String
</span><span style="color: #6a3e3e; font-family: "consolas"; font-size: 10.0pt;">s</span><span style="font-family: "consolas"; font-size: 10pt;">=</span><b><span style="color: #7f0055; font-family: "consolas"; font-size: 10.0pt;">new</span></b><span style="font-family: "consolas"; font-size: 10pt;"> String(</span><span style="color: #2a00ff; font-family: "consolas"; font-size: 10.0pt;">"Shiv"</span><span style="font-family: "consolas"; font-size: 10pt;">);</span><span style="font-family: "consolas"; font-size: 10.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: "consolas"; font-size: 10pt;"> </span><span style="font-family: "consolas"; font-size: 10.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: "consolas"; font-size: 10pt;"> </span><b><span style="color: #7f0055; font-family: "consolas"; font-size: 10.0pt;">char</span></b><span style="font-family: "consolas"; font-size: 10pt;"> </span><span style="color: #6a3e3e; font-family: "consolas"; font-size: 10.0pt;">firstChar</span><span style="font-family: "consolas"; font-size: 10pt;">=</span><span style="color: #6a3e3e; font-family: "consolas"; font-size: 10.0pt;">s</span><span style="font-family: "consolas"; font-size: 10pt;">.charAt(0);</span><span style="font-family: "consolas"; font-size: 10.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: "consolas"; font-size: 10pt;"> System.</span><b><i><span style="color: #0000c0; font-family: "consolas"; font-size: 10.0pt;">out</span></i></b><span style="font-family: "consolas"; font-size: 10pt;">.println(</span><span style="color: #2a00ff; font-family: "consolas"; font-size: 10.0pt;">"First
Charecter"</span><span style="font-family: "consolas"; font-size: 10pt;">+</span><span style="color: #6a3e3e; font-family: "consolas"; font-size: 10.0pt;">firstChar</span><span style="font-family: "consolas"; font-size: 10pt;">);</span><span style="font-family: "consolas"; font-size: 10.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: "consolas"; font-size: 10pt;"> </span><span style="font-family: "consolas"; font-size: 10.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: "consolas"; font-size: 10pt;"> </span><b><span style="color: #7f0055; font-family: "consolas"; font-size: 10.0pt;">boolean</span></b><span style="font-family: "consolas"; font-size: 10pt;"> </span><span style="color: #6a3e3e; font-family: "consolas"; font-size: 10.0pt;">status</span><span style="font-family: "consolas"; font-size: 10pt;">=</span><span style="color: #6a3e3e; font-family: "consolas"; font-size: 10.0pt;">s</span><span style="font-family: "consolas"; font-size: 10pt;">.contains(</span><span style="color: #2a00ff; font-family: "consolas"; font-size: 10.0pt;">"i"</span><span style="font-family: "consolas"; font-size: 10pt;">);</span><span style="font-family: "consolas"; font-size: 10.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: "consolas"; font-size: 10pt;"> </span><b><span style="color: #7f0055; font-family: "consolas"; font-size: 10.0pt;">if</span></b><span style="font-family: "consolas"; font-size: 10pt;">(</span><span style="color: #6a3e3e; font-family: "consolas"; font-size: 10.0pt;">status</span><span style="font-family: "consolas"; font-size: 10pt;">){</span><span style="font-family: "consolas"; font-size: 10.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: "consolas"; font-size: 10pt;"> System.</span><b><i><span style="color: #0000c0; font-family: "consolas"; font-size: 10.0pt;">out</span></i></b><span style="font-family: "consolas"; font-size: 10pt;">.println(</span><span style="color: #2a00ff; font-family: "consolas"; font-size: 10.0pt;">"i Found"</span><span style="font-family: "consolas"; font-size: 10pt;">);</span><span style="font-family: "consolas"; font-size: 10.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: "consolas"; font-size: 10pt;"> }</span><b><span style="color: #7f0055; font-family: "consolas"; font-size: 10.0pt;">else</span></b><span style="font-family: "consolas"; font-size: 10pt;">{</span><span style="font-family: "consolas"; font-size: 10.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: "consolas"; font-size: 10pt;"> System.</span><b><i><span style="color: #0000c0; font-family: "consolas"; font-size: 10.0pt;">out</span></i></b><span style="font-family: "consolas"; font-size: 10pt;">.println(</span><span style="color: #2a00ff; font-family: "consolas"; font-size: 10.0pt;">"i Not
Found"</span><span style="font-family: "consolas"; font-size: 10pt;">);</span><span style="font-family: "consolas"; font-size: 10.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: "consolas"; font-size: 10pt;"> }</span><span style="font-family: "consolas"; font-size: 10.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<br /></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: "consolas"; font-size: 10pt;"> </span><span style="color: #6a3e3e; font-family: "consolas"; font-size: 10.0pt;">status</span><span style="font-family: "consolas"; font-size: 10pt;">=</span><span style="color: #6a3e3e; font-family: "consolas"; font-size: 10.0pt;">s</span><span style="font-family: "consolas"; font-size: 10pt;">.endsWith(</span><span style="color: #2a00ff; font-family: "consolas"; font-size: 10.0pt;">"iv"</span><span style="font-family: "consolas"; font-size: 10pt;">);</span><span style="font-family: "consolas"; font-size: 10.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: "consolas"; font-size: 10pt;"> </span><b><span style="color: #7f0055; font-family: "consolas"; font-size: 10.0pt;">if</span></b><span style="font-family: "consolas"; font-size: 10pt;">(</span><span style="color: #6a3e3e; font-family: "consolas"; font-size: 10.0pt;">status</span><span style="font-family: "consolas"; font-size: 10pt;">){</span><span style="font-family: "consolas"; font-size: 10.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: "consolas"; font-size: 10pt;"> System.</span><b><i><span style="color: #0000c0; font-family: "consolas"; font-size: 10.0pt;">out</span></i></b><span style="font-family: "consolas"; font-size: 10pt;">.println(</span><span style="color: #2a00ff; font-family: "consolas"; font-size: 10.0pt;">"ends with
iv"</span><span style="font-family: "consolas"; font-size: 10pt;">);</span><span style="font-family: "consolas"; font-size: 10.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: "consolas"; font-size: 10pt;"> }</span><b><span style="color: #7f0055; font-family: "consolas"; font-size: 10.0pt;">else</span></b><span style="font-family: "consolas"; font-size: 10pt;">{</span><span style="font-family: "consolas"; font-size: 10.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: "consolas"; font-size: 10pt;"> System.</span><b><i><span style="color: #0000c0; font-family: "consolas"; font-size: 10.0pt;">out</span></i></b><span style="font-family: "consolas"; font-size: 10pt;">.println(</span><span style="color: #2a00ff; font-family: "consolas"; font-size: 10.0pt;">" Not ends
with iv"</span><span style="font-family: "consolas"; font-size: 10pt;">);</span><span style="font-family: "consolas"; font-size: 10.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: "consolas"; font-size: 10pt;"> }</span><span style="font-family: "consolas"; font-size: 10.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<br /></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: "consolas"; font-size: 10pt;"> String
</span><span style="color: #6a3e3e; font-family: "consolas"; font-size: 10.0pt;">newString</span><span style="font-family: "consolas"; font-size: 10pt;">=</span><span style="color: #6a3e3e; font-family: "consolas"; font-size: 10.0pt;">s</span><span style="font-family: "consolas"; font-size: 10pt;">.replace(</span><span style="color: #2a00ff; font-family: "consolas"; font-size: 10.0pt;">'v'</span><span style="font-family: "consolas"; font-size: 10pt;">, </span><span style="color: #2a00ff; font-family: "consolas"; font-size: 10.0pt;">'V'</span><span style="font-family: "consolas"; font-size: 10pt;">);</span><span style="font-family: "consolas"; font-size: 10.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: "consolas"; font-size: 10pt;"> System.</span><b><i><span style="color: #0000c0; font-family: "consolas"; font-size: 10.0pt;">out</span></i></b><span style="font-family: "consolas"; font-size: 10pt;">.println(</span><span style="color: #2a00ff; font-family: "consolas"; font-size: 10.0pt;">"Replaced=
"</span><span style="font-family: "consolas"; font-size: 10pt;">+</span><span style="color: #6a3e3e; font-family: "consolas"; font-size: 10.0pt;">newString</span><span style="font-family: "consolas"; font-size: 10pt;">);</span><span style="font-family: "consolas"; font-size: 10.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: "consolas"; font-size: 10pt;"> </span><span style="font-family: "consolas"; font-size: 10.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: "consolas"; font-size: 10pt;"> String
</span><span style="color: #6a3e3e; font-family: "consolas"; font-size: 10.0pt;">name</span><span style="font-family: "consolas"; font-size: 10pt;">=</span><span style="color: #2a00ff; font-family: "consolas"; font-size: 10.0pt;">"Ajju"</span><span style="font-family: "consolas"; font-size: 10pt;">;</span><span style="font-family: "consolas"; font-size: 10.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: "consolas"; font-size: 10pt;"> System.</span><b><i><span style="color: #0000c0; font-family: "consolas"; font-size: 10.0pt;">out</span></i></b><span style="font-family: "consolas"; font-size: 10pt;">.println(</span><span style="color: #2a00ff; font-family: "consolas"; font-size: 10.0pt;">"Last
Occurance of J= "</span><span style="font-family: "consolas"; font-size: 10pt;">+</span><span style="color: #6a3e3e; font-family: "consolas"; font-size: 10.0pt;">name</span><span style="font-family: "consolas"; font-size: 10pt;">.lastIndexOf(</span><span style="color: #2a00ff; font-family: "consolas"; font-size: 10.0pt;">"j"</span><span style="font-family: "consolas"; font-size: 10pt;">));</span><span style="font-family: "consolas"; font-size: 10.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: "consolas"; font-size: 10pt;"> System.</span><b><i><span style="color: #0000c0; font-family: "consolas"; font-size: 10.0pt;">out</span></i></b><span style="font-family: "consolas"; font-size: 10pt;">.println(</span><span style="color: #2a00ff; font-family: "consolas"; font-size: 10.0pt;">"First
Occurance of J= "</span><span style="font-family: "consolas"; font-size: 10pt;">+</span><span style="color: #6a3e3e; font-family: "consolas"; font-size: 10.0pt;">name</span><span style="font-family: "consolas"; font-size: 10pt;">.indexOf(</span><span style="color: #2a00ff; font-family: "consolas"; font-size: 10.0pt;">"j"</span><span style="font-family: "consolas"; font-size: 10pt;">));</span><span style="font-family: "consolas"; font-size: 10.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: "consolas"; font-size: 10pt;"> </span><span style="color: #3f7f5f; font-family: "consolas"; font-size: 10.0pt;">//**Substring
starting from point 2*/</span><span style="font-family: "consolas"; font-size: 10.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: "consolas"; font-size: 10pt;"> System.</span><b><i><span style="color: #0000c0; font-family: "consolas"; font-size: 10.0pt;">out</span></i></b><span style="font-family: "consolas"; font-size: 10pt;">.println(</span><span style="color: #2a00ff; font-family: "consolas"; font-size: 10.0pt;">"SubString"</span><span style="font-family: "consolas"; font-size: 10pt;">+</span><span style="color: #6a3e3e; font-family: "consolas"; font-size: 10.0pt;">name</span><span style="font-family: "consolas"; font-size: 10pt;">.substring(2));</span><span style="font-family: "consolas"; font-size: 10.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: "consolas"; font-size: 10pt;"> </span><span style="font-family: "consolas"; font-size: 10.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: "consolas"; font-size: 10pt;"> </span><span style="color: #6a3e3e; font-family: "consolas"; font-size: 10.0pt;">name</span><span style="font-family: "consolas"; font-size: 10pt;">=</span><span style="color: #2a00ff; font-family: "consolas"; font-size: 10.0pt;">"Java is
Great"</span><span style="font-family: "consolas"; font-size: 10pt;">;</span><span style="font-family: "consolas"; font-size: 10.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: "consolas"; font-size: 10pt;"> </span><span style="font-family: "consolas"; font-size: 10.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: "consolas"; font-size: 10pt;"> String
[]</span><span style="color: #6a3e3e; font-family: "consolas"; font-size: 10.0pt;">words</span><span style="font-family: "consolas"; font-size: 10pt;">=</span><span style="color: #6a3e3e; font-family: "consolas"; font-size: 10.0pt;">name</span><span style="font-family: "consolas"; font-size: 10pt;">.split(</span><span style="color: #2a00ff; font-family: "consolas"; font-size: 10.0pt;">" "</span><span style="font-family: "consolas"; font-size: 10pt;">);</span><span style="font-family: "consolas"; font-size: 10.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: "consolas"; font-size: 10pt;"> </span><span style="font-family: "consolas"; font-size: 10.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: "consolas"; font-size: 10pt;"> </span><b><span style="color: #7f0055; font-family: "consolas"; font-size: 10.0pt;">for</span></b><span style="font-family: "consolas"; font-size: 10pt;">(String </span><span style="color: #6a3e3e; font-family: "consolas"; font-size: 10.0pt;">oneWord</span><span style="font-family: "consolas"; font-size: 10pt;">:</span><span style="color: #6a3e3e; font-family: "consolas"; font-size: 10.0pt;">words</span><span style="font-family: "consolas"; font-size: 10pt;">)</span><span style="font-family: "consolas"; font-size: 10.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: "consolas"; font-size: 10pt;"> {</span><span style="font-family: "consolas"; font-size: 10.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: "consolas"; font-size: 10pt;"> System.</span><b><i><span style="color: #0000c0; font-family: "consolas"; font-size: 10.0pt;">out</span></i></b><span style="font-family: "consolas"; font-size: 10pt;">.println(</span><span style="color: #2a00ff; font-family: "consolas"; font-size: 10.0pt;">""</span><span style="font-family: "consolas"; font-size: 10pt;">+</span><span style="color: #6a3e3e; font-family: "consolas"; font-size: 10.0pt;">oneWord</span><span style="font-family: "consolas"; font-size: 10pt;">);</span><span style="font-family: "consolas"; font-size: 10.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: "consolas"; font-size: 10pt;"> }</span><span style="font-family: "consolas"; font-size: 10.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: "consolas"; font-size: 10pt;"> </span><span style="font-family: "consolas"; font-size: 10.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: "consolas"; font-size: 10pt;"> }</span><span style="font-family: "consolas"; font-size: 10.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: "consolas"; font-size: 10pt;"> </span><span style="font-family: "consolas"; font-size: 10.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: "consolas"; font-size: 10pt;"> </span><span style="font-family: "consolas"; font-size: 10.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: "consolas"; font-size: 10pt;">}</span><span style="font-family: "consolas"; font-size: 10.0pt;"><o:p></o:p></span></div>
<br />
<div class="MsoNormal">
<br /></div>
</div>
Anonymoushttp://www.blogger.com/profile/07685598617709117616noreply@blogger.com0tag:blogger.com,1999:blog-1266456599706152053.post-71471975904526919672016-06-30T19:41:00.004+05:302016-09-02T16:28:06.594+05:30How To Create Nested Class in java<div dir="ltr" style="text-align: left;" trbidi="on">
<div class="MsoNormal">
<span style="font-family: "times new roman" , serif;"><u><b>InnerClass</b></u><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<b><span style="color: #7f0055; font-family: "arial rounded mt bold" , sans-serif; font-size: 12.0pt;">class</span></b><span style="font-family: "arial rounded mt bold" , sans-serif; font-size: 12pt;"> A {</span><span style="font-family: "arial rounded mt bold" , sans-serif; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: "arial rounded mt bold" , sans-serif; font-size: 12pt;"> </span><b><span style="color: #7f0055; font-family: "arial rounded mt bold" , sans-serif; font-size: 12.0pt;">class</span></b><span style="font-family: "arial rounded mt bold" , sans-serif; font-size: 12pt;"> B {</span><span style="font-family: "arial rounded mt bold" , sans-serif; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: "arial rounded mt bold" , sans-serif; font-size: 12pt;"> </span><b><span style="color: #7f0055; font-family: "arial rounded mt bold" , sans-serif; font-size: 12.0pt;">public</span></b><span style="font-family: "arial rounded mt bold" , sans-serif; font-size: 12pt;"> </span><b><span style="color: #7f0055; font-family: "arial rounded mt bold" , sans-serif; font-size: 12.0pt;">void</span></b><span style="font-family: "arial rounded mt bold" , sans-serif; font-size: 12pt;"> print() {</span><span style="font-family: "arial rounded mt bold" , sans-serif; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: "arial rounded mt bold" , sans-serif; font-size: 12pt;"> System.</span><b><i><span style="color: #0000c0; font-family: "arial rounded mt bold" , sans-serif; font-size: 12.0pt;">out</span></i></b><span style="font-family: "arial rounded mt bold" , sans-serif; font-size: 12pt;">.println(</span><span style="color: #2a00ff; font-family: "arial rounded mt bold" , sans-serif; font-size: 12.0pt;">"HI "</span><span style="font-family: "arial rounded mt bold" , sans-serif; font-size: 12pt;">);</span><span style="font-family: "arial rounded mt bold" , sans-serif; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: "arial rounded mt bold" , sans-serif; font-size: 12pt;"> }</span><span style="font-family: "arial rounded mt bold" , sans-serif; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: "arial rounded mt bold" , sans-serif; font-size: 12pt;"> }</span><span style="font-family: "arial rounded mt bold" , sans-serif; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<br /></div>
<iframe frameborder="0" marginheight="0" marginwidth="0" scrolling="no" src="//ws-na.amazon-adsystem.com/widgets/q?ServiceVersion=20070822&OneJS=1&Operation=GetAdHtml&MarketPlace=US&source=ac&ref=tf_til&ad_type=product_link&tracking_id=javashiv-20&marketplace=amazon&region=US&placement=B01A5IIDEQ&asins=B01A5IIDEQ&linkId=8a50a0ff7603c1297dd0b0becde32691&show_border=true&link_opens_in_new_window=false&price_color=333333&title_color=0066c0&bg_color=ffffff" style="height: 240px; width: 120px;">
</iframe>
<br />
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: "arial rounded mt bold" , sans-serif; font-size: 12pt;">}</span><span style="font-family: "arial rounded mt bold" , sans-serif; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<br /></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<b><span style="color: #7f0055; font-family: "arial rounded mt bold" , sans-serif; font-size: 12.0pt;">public</span></b><span style="font-family: "arial rounded mt bold" , sans-serif; font-size: 12pt;"> </span><b><span style="color: #7f0055; font-family: "arial rounded mt bold" , sans-serif; font-size: 12.0pt;">class</span></b><span style="font-family: "arial rounded mt bold" , sans-serif; font-size: 12pt;"> InnerClasses {</span><span style="font-family: "arial rounded mt bold" , sans-serif; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<br /></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: "arial rounded mt bold" , sans-serif; font-size: 12pt;"> </span><b><span style="color: #7f0055; font-family: "arial rounded mt bold" , sans-serif; font-size: 12.0pt;">public</span></b><span style="font-family: "arial rounded mt bold" , sans-serif; font-size: 12pt;"> </span><b><span style="color: #7f0055; font-family: "arial rounded mt bold" , sans-serif; font-size: 12.0pt;">static</span></b><span style="font-family: "arial rounded mt bold" , sans-serif; font-size: 12pt;"> </span><b><span style="color: #7f0055; font-family: "arial rounded mt bold" , sans-serif; font-size: 12.0pt;">void</span></b><span style="font-family: "arial rounded mt bold" , sans-serif; font-size: 12pt;"> main(String[] </span><span style="color: #6a3e3e; font-family: "arial rounded mt bold" , sans-serif; font-size: 12.0pt;">args</span><span style="font-family: "arial rounded mt bold" , sans-serif; font-size: 12pt;">) {</span><span style="font-family: "arial rounded mt bold" , sans-serif; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: "arial rounded mt bold" , sans-serif; font-size: 12pt;"> A
</span><span style="color: #6a3e3e; font-family: "arial rounded mt bold" , sans-serif; font-size: 12.0pt;">aObj</span><span style="font-family: "arial rounded mt bold" , sans-serif; font-size: 12pt;">=</span><b><span style="color: #7f0055; font-family: "arial rounded mt bold" , sans-serif; font-size: 12.0pt;">new</span></b><span style="font-family: "arial rounded mt bold" , sans-serif; font-size: 12pt;"> A();</span><span style="font-family: "arial rounded mt bold" , sans-serif; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: "arial rounded mt bold" , sans-serif; font-size: 12pt;"> </span><span style="font-family: "arial rounded mt bold" , sans-serif; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: "arial rounded mt bold" , sans-serif; font-size: 12pt;"> A.B
</span><span style="color: #6a3e3e; font-family: "arial rounded mt bold" , sans-serif; font-size: 12.0pt;">bObj</span><span style="font-family: "arial rounded mt bold" , sans-serif; font-size: 12pt;">=</span><span style="color: #6a3e3e; font-family: "arial rounded mt bold" , sans-serif; font-size: 12.0pt;">aObj</span><span style="font-family: "arial rounded mt bold" , sans-serif; font-size: 12pt;">.</span><b><span style="color: #7f0055; font-family: "arial rounded mt bold" , sans-serif; font-size: 12.0pt;">new</span></b><span style="font-family: "arial rounded mt bold" , sans-serif; font-size: 12pt;"> B();</span><span style="font-family: "arial rounded mt bold" , sans-serif; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: "arial rounded mt bold" , sans-serif; font-size: 12pt;"> </span><span style="font-family: "arial rounded mt bold" , sans-serif; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: "arial rounded mt bold" , sans-serif; font-size: 12pt;"> </span><span style="color: #6a3e3e; font-family: "arial rounded mt bold" , sans-serif; font-size: 12.0pt;">bObj</span><span style="font-family: "arial rounded mt bold" , sans-serif; font-size: 12pt;">.print(); </span><span style="font-family: "arial rounded mt bold" , sans-serif; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<br /></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: "arial rounded mt bold" , sans-serif; font-size: 12pt;"> }</span><span style="font-family: "arial rounded mt bold" , sans-serif; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<br /></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: "arial rounded mt bold" , sans-serif; font-size: 12pt;">}</span><span style="font-family: "arial rounded mt bold" , sans-serif; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<u><b> Inner Class2</b></u><o:p></o:p></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<b><span style="color: #7f0055; font-family: "arial rounded mt bold" , sans-serif; font-size: 12.0pt;">class</span></b><span style="font-family: "arial rounded mt bold" , sans-serif; font-size: 12pt;"> AOuter {</span><span style="font-family: "arial rounded mt bold" , sans-serif; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: "arial rounded mt bold" , sans-serif; font-size: 12pt;"> </span><b><span style="color: #7f0055; font-family: "arial rounded mt bold" , sans-serif; font-size: 12.0pt;">class</span></b><span style="font-family: "arial rounded mt bold" , sans-serif; font-size: 12pt;"> BInner {</span><span style="font-family: "arial rounded mt bold" , sans-serif; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: "arial rounded mt bold" , sans-serif; font-size: 12pt;"> </span><b><span style="color: #7f0055; font-family: "arial rounded mt bold" , sans-serif; font-size: 12.0pt;">public</span></b><span style="font-family: "arial rounded mt bold" , sans-serif; font-size: 12pt;"> </span><b><span style="color: #7f0055; font-family: "arial rounded mt bold" , sans-serif; font-size: 12.0pt;">void</span></b><span style="font-family: "arial rounded mt bold" , sans-serif; font-size: 12pt;"> printMe() {</span><span style="font-family: "arial rounded mt bold" , sans-serif; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: "arial rounded mt bold" , sans-serif; font-size: 12pt;"> System.</span><b><i><span style="color: #0000c0; font-family: "arial rounded mt bold" , sans-serif; font-size: 12.0pt;">out</span></i></b><span style="font-family: "arial rounded mt bold" , sans-serif; font-size: 12pt;">.println(</span><span style="color: #2a00ff; font-family: "arial rounded mt bold" , sans-serif; font-size: 12.0pt;">"i m B"</span><span style="font-family: "arial rounded mt bold" , sans-serif; font-size: 12pt;">);</span><span style="font-family: "arial rounded mt bold" , sans-serif; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: "arial rounded mt bold" , sans-serif; font-size: 12pt;"> }</span><span style="font-family: "arial rounded mt bold" , sans-serif; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<br /></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: "arial rounded mt bold" , sans-serif; font-size: 12pt;"> }</span><span style="font-family: "arial rounded mt bold" , sans-serif; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: "arial rounded mt bold" , sans-serif; font-size: 12pt;"> </span><span style="font-family: "arial rounded mt bold" , sans-serif; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: "arial rounded mt bold" , sans-serif; font-size: 12pt;"> </span><b><span style="color: #7f0055; font-family: "arial rounded mt bold" , sans-serif; font-size: 12.0pt;">public</span></b><span style="font-family: "arial rounded mt bold" , sans-serif; font-size: 12pt;"> </span><b><span style="color: #7f0055; font-family: "arial rounded mt bold" , sans-serif; font-size: 12.0pt;">void</span></b><span style="font-family: "arial rounded mt bold" , sans-serif; font-size: 12pt;"> aMethod()</span><span style="font-family: "arial rounded mt bold" , sans-serif; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: "arial rounded mt bold" , sans-serif; font-size: 12pt;"> {</span><span style="font-family: "arial rounded mt bold" , sans-serif; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: "arial rounded mt bold" , sans-serif; font-size: 12pt;"> BInner
</span><span style="color: #6a3e3e; font-family: "arial rounded mt bold" , sans-serif; font-size: 12.0pt;">b</span><span style="font-family: "arial rounded mt bold" , sans-serif; font-size: 12pt;">=</span><b><span style="color: #7f0055; font-family: "arial rounded mt bold" , sans-serif; font-size: 12.0pt;">new</span></b><span style="font-family: "arial rounded mt bold" , sans-serif; font-size: 12pt;"> BInner();</span><span style="font-family: "arial rounded mt bold" , sans-serif; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: "arial rounded mt bold" , sans-serif; font-size: 12pt;"> </span><span style="color: #6a3e3e; font-family: "arial rounded mt bold" , sans-serif; font-size: 12.0pt;">b</span><span style="font-family: "arial rounded mt bold" , sans-serif; font-size: 12pt;">.printMe();</span><span style="font-family: "arial rounded mt bold" , sans-serif; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: "arial rounded mt bold" , sans-serif; font-size: 12pt;"> }</span><span style="font-family: "arial rounded mt bold" , sans-serif; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: "arial rounded mt bold" , sans-serif; font-size: 12pt;">}</span><span style="font-family: "arial rounded mt bold" , sans-serif; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<br /></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<b><span style="color: #7f0055; font-family: "arial rounded mt bold" , sans-serif; font-size: 12.0pt;">public</span></b><span style="font-family: "arial rounded mt bold" , sans-serif; font-size: 12pt;"> </span><b><span style="color: #7f0055; font-family: "arial rounded mt bold" , sans-serif; font-size: 12.0pt;">class</span></b><span style="font-family: "arial rounded mt bold" , sans-serif; font-size: 12pt;"> MethodLocalInnerClass {</span><span style="font-family: "arial rounded mt bold" , sans-serif; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<br /></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: "arial rounded mt bold" , sans-serif; font-size: 12pt;"> </span><b><span style="color: #7f0055; font-family: "arial rounded mt bold" , sans-serif; font-size: 12.0pt;">public</span></b><span style="font-family: "arial rounded mt bold" , sans-serif; font-size: 12pt;"> </span><b><span style="color: #7f0055; font-family: "arial rounded mt bold" , sans-serif; font-size: 12.0pt;">static</span></b><span style="font-family: "arial rounded mt bold" , sans-serif; font-size: 12pt;"> </span><b><span style="color: #7f0055; font-family: "arial rounded mt bold" , sans-serif; font-size: 12.0pt;">void</span></b><span style="font-family: "arial rounded mt bold" , sans-serif; font-size: 12pt;"> main(String[] </span><span style="color: #6a3e3e; font-family: "arial rounded mt bold" , sans-serif; font-size: 12.0pt;">args</span><span style="font-family: "arial rounded mt bold" , sans-serif; font-size: 12pt;">) {</span><span style="font-family: "arial rounded mt bold" , sans-serif; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: "arial rounded mt bold" , sans-serif; font-size: 12pt;"> AOuter
</span><span style="color: #6a3e3e; font-family: "arial rounded mt bold" , sans-serif; font-size: 12.0pt;">a</span><span style="font-family: "arial rounded mt bold" , sans-serif; font-size: 12pt;">=</span><b><span style="color: #7f0055; font-family: "arial rounded mt bold" , sans-serif; font-size: 12.0pt;">new</span></b><span style="font-family: "arial rounded mt bold" , sans-serif; font-size: 12pt;"> AOuter();</span><span style="font-family: "arial rounded mt bold" , sans-serif; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="color: #6a3e3e; font-family: "arial rounded mt bold" , sans-serif; font-size: 12.0pt;"> a</span><span style="font-family: "arial rounded mt bold" , sans-serif; font-size: 12pt;">.aMethod();</span><span style="font-family: "arial rounded mt bold" , sans-serif; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<br /></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: "arial rounded mt bold" , sans-serif; font-size: 12pt;"> }</span><span style="font-family: "arial rounded mt bold" , sans-serif; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<br /></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: "arial rounded mt bold" , sans-serif; font-size: 12pt;">}</span><span style="font-family: "arial rounded mt bold" , sans-serif; font-size: 12.0pt;"><o:p></o:p></span></div>
<b>Method Local Inner Class</b><br />
<b><br /></b>
<br />
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<b><span style="color: #7f0055; font-family: "arial rounded mt bold" , sans-serif; font-size: 12.0pt;">class</span></b><span style="font-family: "arial rounded mt bold" , sans-serif; font-size: 12pt;"> AOuter {</span><span style="font-family: "arial rounded mt bold" , sans-serif; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: "arial rounded mt bold" , sans-serif; font-size: 12pt;"> </span><b><span style="color: #7f0055; font-family: "arial rounded mt bold" , sans-serif; font-size: 12.0pt;">void</span></b><span style="font-family: "arial rounded mt bold" , sans-serif; font-size: 12pt;"> aOuter()</span><span style="font-family: "arial rounded mt bold" , sans-serif; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: "arial rounded mt bold" , sans-serif; font-size: 12pt;"> {</span><span style="font-family: "arial rounded mt bold" , sans-serif; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: "arial rounded mt bold" , sans-serif; font-size: 12pt;"> </span><b><span style="color: #7f0055; font-family: "arial rounded mt bold" , sans-serif; font-size: 12.0pt;">class</span></b><span style="font-family: "arial rounded mt bold" , sans-serif; font-size: 12pt;"> BInner {</span><span style="font-family: "arial rounded mt bold" , sans-serif; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: "arial rounded mt bold" , sans-serif; font-size: 12pt;"> </span><b><span style="color: #7f0055; font-family: "arial rounded mt bold" , sans-serif; font-size: 12.0pt;">public</span></b><span style="font-family: "arial rounded mt bold" , sans-serif; font-size: 12pt;"> </span><b><span style="color: #7f0055; font-family: "arial rounded mt bold" , sans-serif; font-size: 12.0pt;">void</span></b><span style="font-family: "arial rounded mt bold" , sans-serif; font-size: 12pt;"> printMe() {</span><span style="font-family: "arial rounded mt bold" , sans-serif; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: "arial rounded mt bold" , sans-serif; font-size: 12pt;"> System.</span><b><i><span style="color: #0000c0; font-family: "arial rounded mt bold" , sans-serif; font-size: 12.0pt;">out</span></i></b><span style="font-family: "arial rounded mt bold" , sans-serif; font-size: 12pt;">.println(</span><span style="color: #2a00ff; font-family: "arial rounded mt bold" , sans-serif; font-size: 12.0pt;">"i m B"</span><span style="font-family: "arial rounded mt bold" , sans-serif; font-size: 12pt;">);</span><span style="font-family: "arial rounded mt bold" , sans-serif; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: "arial rounded mt bold" , sans-serif; font-size: 12pt;"> }</span><span style="font-family: "arial rounded mt bold" , sans-serif; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<br /></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: "arial rounded mt bold" , sans-serif; font-size: 12pt;"> }</span><span style="font-family: "arial rounded mt bold" , sans-serif; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: "arial rounded mt bold" , sans-serif; font-size: 12pt;"> BInner </span><span style="color: #6a3e3e; font-family: "arial rounded mt bold" , sans-serif; font-size: 12.0pt;">bObj</span><span style="font-family: "arial rounded mt bold" , sans-serif; font-size: 12pt;">=</span><b><span style="color: #7f0055; font-family: "arial rounded mt bold" , sans-serif; font-size: 12.0pt;">new</span></b><span style="font-family: "arial rounded mt bold" , sans-serif; font-size: 12pt;"> BInner();</span><span style="font-family: "arial rounded mt bold" , sans-serif; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: "arial rounded mt bold" , sans-serif; font-size: 12pt;"> </span><span style="color: #6a3e3e; font-family: "arial rounded mt bold" , sans-serif; font-size: 12.0pt;">bObj</span><span style="font-family: "arial rounded mt bold" , sans-serif; font-size: 12pt;">.printMe();</span><span style="font-family: "arial rounded mt bold" , sans-serif; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: "arial rounded mt bold" , sans-serif; font-size: 12pt;"> }</span><span style="font-family: "arial rounded mt bold" , sans-serif; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: "arial rounded mt bold" , sans-serif; font-size: 12pt;"> </span><span style="font-family: "arial rounded mt bold" , sans-serif; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: "arial rounded mt bold" , sans-serif; font-size: 12pt;">}</span><span style="font-family: "arial rounded mt bold" , sans-serif; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<br /></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<b><span style="color: #7f0055; font-family: "arial rounded mt bold" , sans-serif; font-size: 12.0pt;">public</span></b><span style="font-family: "arial rounded mt bold" , sans-serif; font-size: 12pt;"> </span><b><span style="color: #7f0055; font-family: "arial rounded mt bold" , sans-serif; font-size: 12.0pt;">class</span></b><span style="font-family: "arial rounded mt bold" , sans-serif; font-size: 12pt;"> MethodLocalInnerClass {</span><span style="font-family: "arial rounded mt bold" , sans-serif; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<br /></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: "arial rounded mt bold" , sans-serif; font-size: 12pt;"> </span><b><span style="color: #7f0055; font-family: "arial rounded mt bold" , sans-serif; font-size: 12.0pt;">public</span></b><span style="font-family: "arial rounded mt bold" , sans-serif; font-size: 12pt;"> </span><b><span style="color: #7f0055; font-family: "arial rounded mt bold" , sans-serif; font-size: 12.0pt;">static</span></b><span style="font-family: "arial rounded mt bold" , sans-serif; font-size: 12pt;"> </span><b><span style="color: #7f0055; font-family: "arial rounded mt bold" , sans-serif; font-size: 12.0pt;">void</span></b><span style="font-family: "arial rounded mt bold" , sans-serif; font-size: 12pt;"> main(String[] </span><span style="color: #6a3e3e; font-family: "arial rounded mt bold" , sans-serif; font-size: 12.0pt;">args</span><span style="font-family: "arial rounded mt bold" , sans-serif; font-size: 12pt;">) {</span><span style="font-family: "arial rounded mt bold" , sans-serif; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: "arial rounded mt bold" , sans-serif; font-size: 12pt;"> AOuter
</span><span style="background: yellow; color: #6a3e3e; font-family: "arial rounded mt bold" , sans-serif; font-size: 12.0pt;">a</span><span style="font-family: "arial rounded mt bold" , sans-serif; font-size: 12pt;">=</span><b><span style="color: #7f0055; font-family: "arial rounded mt bold" , sans-serif; font-size: 12.0pt;">new</span></b><span style="font-family: "arial rounded mt bold" , sans-serif; font-size: 12pt;">
AOuter();</span><span style="font-family: "arial rounded mt bold" , sans-serif; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: "arial rounded mt bold" , sans-serif; font-size: 12pt;"> </span><span style="background: silver; color: #6a3e3e; font-family: "arial rounded mt bold" , sans-serif; font-size: 12.0pt;">a</span><span style="font-family: "arial rounded mt bold" , sans-serif; font-size: 12pt;">.aOuter();</span><span style="font-family: "arial rounded mt bold" , sans-serif; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<br /></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: "arial rounded mt bold" , sans-serif; font-size: 12pt;"> }</span><span style="font-family: "arial rounded mt bold" , sans-serif; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<br /></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: "arial rounded mt bold" , sans-serif; font-size: 12pt;">}</span><span style="font-family: "arial rounded mt bold" , sans-serif; font-size: 12.0pt;"><o:p></o:p></span></div>
<br />
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<span style="font-family: "arial rounded mt bold" , sans-serif; font-size: 12.0pt; line-height: 107%;"><b><u>Static Nested Class</u></b></span></div>
<div class="MsoNormal">
<span style="font-family: "arial rounded mt bold" , sans-serif; font-size: 12.0pt; line-height: 107%;"><b><u><br /></u></b></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<b><span style="color: #7f0055; font-family: "arial rounded mt bold" , sans-serif; font-size: 12.0pt;">class</span></b><span style="font-family: "arial rounded mt bold" , sans-serif; font-size: 12pt;"> AOuter {</span><span style="font-family: "arial rounded mt bold" , sans-serif; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: "arial rounded mt bold" , sans-serif; font-size: 12pt;"> </span><span style="font-family: "arial rounded mt bold" , sans-serif; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: "arial rounded mt bold" , sans-serif; font-size: 12pt;"> </span><b><span style="color: #7f0055; font-family: "arial rounded mt bold" , sans-serif; font-size: 12.0pt;">static</span></b><span style="font-family: "arial rounded mt bold" , sans-serif; font-size: 12pt;"> </span><b><span style="color: #7f0055; font-family: "arial rounded mt bold" , sans-serif; font-size: 12.0pt;">class</span></b><span style="font-family: "arial rounded mt bold" , sans-serif; font-size: 12pt;"> BInner {</span><span style="font-family: "arial rounded mt bold" , sans-serif; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: "arial rounded mt bold" , sans-serif; font-size: 12pt;"> </span><b><span style="color: #7f0055; font-family: "arial rounded mt bold" , sans-serif; font-size: 12.0pt;">public</span></b><span style="font-family: "arial rounded mt bold" , sans-serif; font-size: 12pt;"> </span><b><span style="color: #7f0055; font-family: "arial rounded mt bold" , sans-serif; font-size: 12.0pt;">void</span></b><span style="font-family: "arial rounded mt bold" , sans-serif; font-size: 12pt;"> <span style="background: silver; mso-highlight: silver;">printMe</span>()
{</span><span style="font-family: "arial rounded mt bold" , sans-serif; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: "arial rounded mt bold" , sans-serif; font-size: 12pt;"> System.</span><b><i><span style="color: #0000c0; font-family: "arial rounded mt bold" , sans-serif; font-size: 12.0pt;">out</span></i></b><span style="font-family: "arial rounded mt bold" , sans-serif; font-size: 12pt;">.println(</span><span style="color: #2a00ff; font-family: "arial rounded mt bold" , sans-serif; font-size: 12.0pt;">"i m B"</span><span style="font-family: "arial rounded mt bold" , sans-serif; font-size: 12pt;">);</span><span style="font-family: "arial rounded mt bold" , sans-serif; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: "arial rounded mt bold" , sans-serif; font-size: 12pt;"> }</span><span style="font-family: "arial rounded mt bold" , sans-serif; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<br /></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: "arial rounded mt bold" , sans-serif; font-size: 12pt;"> } </span><span style="font-family: "arial rounded mt bold" , sans-serif; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: "arial rounded mt bold" , sans-serif; font-size: 12pt;">}</span><span style="font-family: "arial rounded mt bold" , sans-serif; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<b><span style="color: #7f0055; font-family: "arial rounded mt bold" , sans-serif; font-size: 12.0pt;">public</span></b><span style="font-family: "arial rounded mt bold" , sans-serif; font-size: 12pt;"> </span><b><span style="color: #7f0055; font-family: "arial rounded mt bold" , sans-serif; font-size: 12.0pt;">class</span></b><span style="font-family: "arial rounded mt bold" , sans-serif; font-size: 12pt;"> MethodLocalInnerClass {</span><span style="font-family: "arial rounded mt bold" , sans-serif; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<br /></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: "arial rounded mt bold" , sans-serif; font-size: 12pt;"> </span><b><span style="color: #7f0055; font-family: "arial rounded mt bold" , sans-serif; font-size: 12.0pt;">public</span></b><span style="font-family: "arial rounded mt bold" , sans-serif; font-size: 12pt;"> </span><b><span style="color: #7f0055; font-family: "arial rounded mt bold" , sans-serif; font-size: 12.0pt;">static</span></b><span style="font-family: "arial rounded mt bold" , sans-serif; font-size: 12pt;"> </span><b><span style="color: #7f0055; font-family: "arial rounded mt bold" , sans-serif; font-size: 12.0pt;">void</span></b><span style="font-family: "arial rounded mt bold" , sans-serif; font-size: 12pt;"> main(String[] </span><span style="color: #6a3e3e; font-family: "arial rounded mt bold" , sans-serif; font-size: 12.0pt;">args</span><span style="font-family: "arial rounded mt bold" , sans-serif; font-size: 12pt;">) {</span><span style="font-family: "arial rounded mt bold" , sans-serif; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: "arial rounded mt bold" , sans-serif; font-size: 12pt;"> AOuter.BInner
</span><span style="color: #6a3e3e; font-family: "arial rounded mt bold" , sans-serif; font-size: 12.0pt;">a</span><span style="font-family: "arial rounded mt bold" , sans-serif; font-size: 12pt;">=</span><b><span style="color: #7f0055; font-family: "arial rounded mt bold" , sans-serif; font-size: 12.0pt;">new</span></b><span style="font-family: "arial rounded mt bold" , sans-serif; font-size: 12pt;"> AOuter.BInner();</span><span style="font-family: "arial rounded mt bold" , sans-serif; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: "arial rounded mt bold" , sans-serif; font-size: 12pt;"> </span><span style="color: #6a3e3e; font-family: "arial rounded mt bold" , sans-serif; font-size: 12.0pt;">a</span><span style="font-family: "arial rounded mt bold" , sans-serif; font-size: 12pt;">.<span style="background: silver; mso-highlight: silver;">printMe</span>();</span><span style="font-family: "arial rounded mt bold" , sans-serif; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: "arial rounded mt bold" , sans-serif; font-size: 12pt;"> }</span><span style="font-family: "arial rounded mt bold" , sans-serif; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
</div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: "arial rounded mt bold" , sans-serif; font-size: 12pt;">}</span><span style="font-family: "arial rounded mt bold" , sans-serif; font-size: 12.0pt;"><o:p></o:p></span></div>
</div>
Anonymoushttp://www.blogger.com/profile/07685598617709117616noreply@blogger.com0tag:blogger.com,1999:blog-1266456599706152053.post-73656550310151627402016-06-22T20:08:00.000+05:302016-08-26T22:52:04.270+05:30Difference between TRUNCATE, DELETE and DROP commands<div dir="ltr" style="text-align: left;" trbidi="on">
<b>1></b>TRUNCATE is a DDL command whereas DELETE is a DML command. 2>When compared with delete TRUNCATE is much faster than DELETE.<br />Because <br />Step 1:When you DELETE.all the data first gets copied into the Rollback Tablespace first.<br /><br /><b>2></b> Then delete operation get performed.<br />Benefit of delete is when you ROLLBACK after deleting a table ,you can get back the data(The system get it for you from the Rollback Tablespace).<br /><br />But when you type TRUNCATE,it removes data directly no extra copy is maintained .Thats why TRUNCATE is faster.<br /><br />Once you Truncate you cann't get back the data.<br /><br /><b>3></b>You cann't rollback in TRUNCATE but in DELETE you can rollback.TRUNCATE removes the record permanently.<br /><br /><b>4></b>In case of TRUNCATE ,Trigger doesn't get fired.But in DML commands like DELETE .Trigger get fired.<br /><br /><b>5></b>You cann't use conditions(WHERE clause) in TRUNCATE.But in DELETE you can write conditions using WHERE clause<iframe frameborder="0" marginheight="0" marginwidth="0" scrolling="no" src="//ws-na.amazon-adsystem.com/widgets/q?ServiceVersion=20070822&OneJS=1&Operation=GetAdHtml&MarketPlace=US&source=ac&ref=tf_til&ad_type=product_link&tracking_id=javashiv-20&marketplace=amazon&region=US&placement=B010Q588D4&asins=B010Q588D4&linkId=2d1f51ccbb1dfec80acd8c719da7675b&show_border=true&link_opens_in_new_window=false&price_color=333333&title_color=0066c0&bg_color=ffffff" style="height: 240px; width: 120px;">Â </iframe></div>
Anonymoushttp://www.blogger.com/profile/07685598617709117616noreply@blogger.com0tag:blogger.com,1999:blog-1266456599706152053.post-53736349982936462022016-06-22T19:12:00.001+05:302016-09-02T16:28:40.971+05:30Tricky Facts About views<div dir="ltr" style="text-align: left;" trbidi="on">
<div style="background-color: white; border: 0px; clear: both; color: #242729; line-height: 19.5px; margin-bottom: 1em; padding: 0px;">
</div>
<ol style="text-align: left;">
<li style="text-align: justify;"><span style="font-family: "georgia" , "times new roman" , serif; font-size: large;">Restrictions on Updating Data Through Views You can insert, update, and delete rows in a view, subject to the following limitations:</span></li>
<br /><a href="https://www.amazon.in/b?_encoding=UTF8&camp=3626&creative=24790&linkCode=ur2&node=1388867031&site-redirect=&tag=javashivblogs-21" rel="nofollow" target="_blank">Cool Gadgets</a><img alt="" border="0" src="http://ir-in.amazon-adsystem.com/e/ir?t=javashivblogs-21&l=ur2&o=31" height="1" style="border: none !important; margin: 0px !important;" width="1" />
<li style="text-align: justify;"><span style="font-family: "georgia" , "times new roman" , serif; font-size: large;">If the view contains <b>joins between multiple tables</b></span><span style="font-family: "georgia" , "times new roman" , serif; font-size: large;"> <b>you can </b>only <b>insert and update one table in the view</b>, and you<span style="color: red;"> <b>can't delete</b></span> rows.</span></li>
<br />
<li style="text-align: justify;"><span style="font-family: "georgia" , "times new roman" , serif; font-size: large;">You <b>can't </b>directly <b>modify </b>data in <b>views </b>based on <b>union queries</b>. You <b><span style="color: red;">can't modify</span></b> data in views that use <span style="color: red;"><b>GROUP BY or DISTINCT</b> </span>statements.</span></li>
<br />
<li style="text-align: justify;"><span style="font-family: "georgia" , "times new roman" , serif; font-size: large;">All columns being modified are subject to the same restrictions as if the statements were being executed directly against the base table.</span></li>
<br />
<li style="text-align: justify;"><span style="font-family: "georgia" , "times new roman" , serif; font-size: large;">Text and image columns can't be modified through views.</span></li>
<br />
</ol>
</div>
Anonymoushttp://www.blogger.com/profile/07685598617709117616noreply@blogger.com0tag:blogger.com,1999:blog-1266456599706152053.post-90972414767106892462016-06-20T15:59:00.001+05:302016-09-02T16:29:02.327+05:30Tricky Sql Interview Questions<div dir="ltr" style="text-align: left;" trbidi="on">
<html><head><style>
.fontst{
padding-bottom: 10px;
color: #333;
font-weight: 500;
line-height: 1em;
font-size: 26px;
}
body{
font-size: 18px;
}
</style>
</head>
<body>
<div dir="ltr" style="text-align: left;" trbidi="on">
<div dir="ltr" style="text-align: left;" trbidi="on">
<span class="fontst" style="text-decoration: underline;"><strong>Sql Mostly used queries.</strong></span><br />
<br />
<span style="text-decoration: underline;"><strong>1.Views</strong></span><br />
<h3>
CREATE OR REPLACE VIEW passStudent AS<br />SELECT StudentId,StudentName<br />FROM Student<br />WHERE result=pass</h3>
<span style="text-decoration: underline;"><strong>2.GroupBy Clause</strong></span><br />
<span style="text-decoration: underline;"><strong>Student Table</strong></span><br />
<span style="text-decoration: underline;"><strong>create table student(studId number(5),studName varchar2(10),marks number(3)); </strong></span><br />
<ul>
<li>insert into student values(1,'sur',30); </li>
<li>insert into student values(2,'jit',65); </li>
<li>alter table student add(collegeId number(3));</li>
<li>SQL> update student set collegeId=1 where studId=1; </li>
<li>SQL> update student set collegeId=2 where studId=2; </li>
<li>SQL> insert into student values(3,'ramesh',45,1); </li>
</ul>
<h3 style="text-align: left;">
<b><span style="color: red;"> Question </span></b>select collegeId,count(collegeId) from student group by collegeId; </h3>
<div style="text-align: left;">
COLLEGEID COUNT(COLLEGEID) </div>
<ul>
<li><div>
---------- ---------------- </div>
<div>
1 2 </div>
2 1 </li>
</ul>
<div>
<u>Onother Table College</u><br />
<b><u><br /></u></b>
<b><u>CREATE TABLE `TestSuresh`.`college` ( `cid` INT(7) NOT NULL , `cname` VARCHAR(15) NOT NULL ) ENGINE = InnoDB;</u></b><br />
<br />
<ul style="text-align: left;">
<li>INSERT INTO `college` (`cid`, `cname`) VALUES ('1', 'pvm'), ('2', 'asc')</li>
</ul>
<br />
</div>
<br />
<div>
SQL> select * from student order by marks desc; </div>
<div>
</div>
<div>
</div>
<div>
<table style="height: 78px; width: 310px;">
<tbody>
<tr>
<td>STUDID </td>
<td>STUDNAME </td>
<td>MARKS </td>
<td>COLLEGEID</td>
</tr>
<tr>
<td>2</td>
<td>jit</td>
<td>65</td>
<td>2</td>
</tr>
<tr>
<td>3</td>
<td>ramesh</td>
<td>45</td>
<td>1</td>
</tr>
<tr>
<td>1</td>
<td>suresh</td>
<td>30</td>
<td>1</td>
</tr>
</tbody>
</table>
</div>
<h3>
<span style="color: red;">Question:</span>To Get the first three records in ascending order</h3>
<div>
<span class="cm-keyword"><a class="cm-sql-doc" href="http://demo.phpmyadmin.net/STABLE/url.php?url=https://dev.mysql.com/doc/refman/5.5/en/select.html" target="mysql_doc">select</a></span> <span class="cm-keyword">distinct</span>(s1<span class="cm-variable-2">.marks</span>) <span class="cm-keyword">from</span> student s1 <span class="cm-keyword">where</span> <span class="cm-number">3</span>>=(<span class="cm-keyword"><a class="cm-sql-doc" href="http://demo.phpmyadmin.net/STABLE/url.php?url=https://dev.mysql.com/doc/refman/5.5/en/select.html" target="mysql_doc">select</a></span> <span class="cm-keyword"><a class="cm-sql-doc" href="http://demo.phpmyadmin.net/STABLE/url.php?url=https://dev.mysql.com/doc/refman/5.5/en/group-by-functions.html#function_count" target="mysql_doc">count</a></span>(<span class="cm-keyword">distinct</span>(marks)) <span class="cm-keyword">from</span> student s2 <span class="cm-keyword">where</span> s1<span class="cm-variable-2">.marks</span><=s2. marks) <span class="cm-keyword">order</span> <span class="cm-keyword">by</span> s1<span class="cm-variable-2">.marks</span> <span class="cm-keyword">desc</span> <br />
<br />
<h3 style="text-align: left;">
<span style="color: red;">Question:</span>To get The student also include students which does not belong to any college</h3>
This gives you hint you need to use left join.<br />
<span style="font-size: x-small;"><span class="cm-keyword" style="background-color: #e5e5e5; color: #770088; font-family: monospace;"><a class="cm-sql-doc" href="http://demo.phpmyadmin.net/STABLE/url.php?url=https://dev.mysql.com/doc/refman/5.5/en/select.html" style="border-bottom-color: rgb(0, 0, 0); border-bottom-style: dotted; border-bottom-width: 1px; color: #235a81; cursor: pointer; outline: none; text-decoration: none;" target="mysql_doc">select</a></span><span style="background-color: #e5e5e5; color: #444444; font-family: monospace;"> </span><span style="background-color: #e5e5e5; color: #444444; font-family: monospace;">*</span><span style="background-color: #e5e5e5; color: #444444; font-family: monospace;"> </span><span class="cm-keyword" style="background-color: #e5e5e5; color: #770088; font-family: monospace;">from</span><span style="background-color: #e5e5e5; color: #444444; font-family: monospace;"> </span><span style="background-color: #e5e5e5; color: #444444; font-family: monospace;">student</span><span style="background-color: #e5e5e5; color: #444444; font-family: monospace;"> </span><span style="background-color: #e5e5e5; color: #444444; font-family: monospace;">s1</span><span style="background-color: #e5e5e5; color: #444444; font-family: monospace;"> </span><span class="cm-keyword" style="background-color: #e5e5e5; color: #770088; font-family: monospace;"><a class="cm-sql-doc" href="http://demo.phpmyadmin.net/STABLE/url.php?url=https://dev.mysql.com/doc/refman/5.5/en/string-functions.html#function_left" style="border-bottom-color: rgb(0, 0, 0); border-bottom-style: dotted; border-bottom-width: 1px; color: #235a81; cursor: pointer; outline: none; text-decoration: none;" target="mysql_doc">left</a></span><span style="background-color: #e5e5e5; color: #444444; font-family: monospace;"> </span><span class="cm-keyword" style="background-color: #e5e5e5; color: #770088; font-family: monospace;">join</span><span style="background-color: #e5e5e5; color: #444444; font-family: monospace;"> </span><span style="background-color: #e5e5e5; color: #444444; font-family: monospace;">college</span><span style="background-color: #e5e5e5; color: #444444; font-family: monospace;"> </span><span style="background-color: #e5e5e5; color: #444444; font-family: monospace;">c</span><span style="background-color: #e5e5e5; color: #444444; font-family: monospace;"> </span><span class="cm-keyword" style="background-color: #e5e5e5; color: #770088; font-family: monospace;">on</span><span style="background-color: #e5e5e5; color: #444444; font-family: monospace;"> </span><span style="background-color: #e5e5e5; color: #444444; font-family: monospace;">s1</span><span class="cm-variable-2" style="background-color: #e5e5e5; color: #0055aa; font-family: monospace;">.c_id</span><span style="background-color: #e5e5e5; color: #444444; font-family: monospace;">=</span><span style="background-color: #e5e5e5; color: #444444; font-family: monospace;">c</span><span class="cm-variable-2" style="background-color: #e5e5e5; color: #0055aa; font-family: monospace;">.cid</span> </span> </div>
</div>
</div>
</body>
</html></div>
Anonymoushttp://www.blogger.com/profile/07685598617709117616noreply@blogger.com0tag:blogger.com,1999:blog-1266456599706152053.post-88790114581007446702016-06-17T19:04:00.000+05:302016-09-03T23:44:33.396+05:30When to use comparator and when we should use comparable.<div dir="ltr" style="text-align: left;" trbidi="on">
<div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhqQbuQGkaF1E-pucU9Kai53u0fYsW_4vEA-8ca2s31YRDtEQa-MiHk3FSPxecmCFfhBFiIIrjN_N5Geon8wChK04cwSVwqxRuY_VUA8Pf-JgtReOhC3HA0Fev6GMnWH-arIZao9O0qHmc/s1600/images.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhqQbuQGkaF1E-pucU9Kai53u0fYsW_4vEA-8ca2s31YRDtEQa-MiHk3FSPxecmCFfhBFiIIrjN_N5Geon8wChK04cwSVwqxRuY_VUA8Pf-JgtReOhC3HA0Fev6GMnWH-arIZao9O0qHmc/s320/images.png" width="320" height="162" /></a></div>
<br />
<div dir="ltr" style="text-align: left;" trbidi="on">
<h1>
When to use comparator and when we should use comparable.</h1>
<span style="font-size: large;">Use Comparable if you want to define a default (natural) ordering behaviour of the object in question, a common practice is to use a technical or natural (database?) identifier of the object for this.
Use Comparator if you want to define an external controllable ordering behaviour, this can override the default ordering behaviour.</span><br />
<br />
See the example where used comparable for sorting elements in ascending order.<br />
<br />
<br />
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<b><span style="color: #7f0055; font-family: "consolas"; font-size: 12.0pt;">import</span></b><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="margin-bottom: 0.0001pt;">
<b><span style="color: #7f0055; font-family: "consolas"; font-size: 12.0pt;">import</span></b><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="margin-bottom: 0.0001pt;">
<b><span style="color: #7f0055; font-family: "consolas"; font-size: 12.0pt;">import</span></b><span style="font-family: "consolas"; font-size: 12pt;"> <u>java.util.Comparator</u>;</span><span style="font-family: "consolas"; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<b><span style="color: #7f0055; font-family: "consolas"; font-size: 12.0pt;">import</span></b><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="margin-bottom: 0.0001pt;">
<br /></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<b><span style="color: #7f0055; font-family: "consolas"; font-size: 12.0pt;">class</span></b><span style="font-family: "consolas"; font-size: 12pt;"> vehicle </span><b><span style="color: #7f0055; font-family: "consolas"; font-size: 12.0pt;">implements</span></b><span style="font-family: "consolas"; font-size: 12pt;">
Comparable<vehicle> {</span><span style="font-family: "consolas"; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: "consolas"; font-size: 12pt;"> </span><b><span style="color: #7f0055; font-family: "consolas"; font-size: 12.0pt;">int</span></b><span style="font-family: "consolas"; font-size: 12pt;"> </span><span style="color: #0000c0; font-family: "consolas"; font-size: 12.0pt;">vehNumber</span><span style="font-family: "consolas"; font-size: 12pt;">;</span><span style="font-family: "consolas"; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<br /></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: "consolas"; font-size: 12pt;"> </span><b><span style="color: #7f0055; font-family: "consolas"; font-size: 12.0pt;">public</span></b><span style="font-family: "consolas"; font-size: 12pt;"> </span><b><span style="color: #7f0055; font-family: "consolas"; font-size: 12.0pt;">int</span></b><span style="font-family: "consolas"; font-size: 12pt;"> getVehNumber() {</span><span style="font-family: "consolas"; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: "consolas"; font-size: 12pt;"> </span><b><span style="color: #7f0055; font-family: "consolas"; font-size: 12.0pt;">return</span></b><span style="font-family: "consolas"; font-size: 12pt;"> </span><span style="color: #0000c0; font-family: "consolas"; font-size: 12.0pt;">vehNumber</span><span style="font-family: "consolas"; font-size: 12pt;">;</span><span style="font-family: "consolas"; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: "consolas"; font-size: 12pt;"> }</span><span style="font-family: "consolas"; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<br /></div>
<iframe frameborder="0" marginheight="0" marginwidth="0" scrolling="no" src="//ws-na.amazon-adsystem.com/widgets/q?ServiceVersion=20070822&OneJS=1&Operation=GetAdHtml&MarketPlace=US&source=ac&ref=tf_til&ad_type=product_link&tracking_id=javashiv-20&marketplace=amazon&region=US&placement=B010Q588D4&asins=B010Q588D4&linkId=2d1f51ccbb1dfec80acd8c719da7675b&show_border=true&link_opens_in_new_window=false&price_color=333333&title_color=0066c0&bg_color=ffffff" style="height: 240px; width: 120px;">
</iframe>
<br />
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: "consolas"; font-size: 12pt;"> </span><b><span style="color: #7f0055; font-family: "consolas"; font-size: 12.0pt;">public</span></b><span style="font-family: "consolas"; font-size: 12pt;"> </span><b><span style="color: #7f0055; font-family: "consolas"; font-size: 12.0pt;">void</span></b><span style="font-family: "consolas"; font-size: 12pt;"> setVehNumber(</span><b><span style="color: #7f0055; font-family: "consolas"; font-size: 12.0pt;">int</span></b><span style="font-family: "consolas"; font-size: 12pt;"> </span><span style="color: #6a3e3e; font-family: "consolas"; font-size: 12.0pt;">vehNumber</span><span style="font-family: "consolas"; font-size: 12pt;">) {</span><span style="font-family: "consolas"; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: "consolas"; font-size: 12pt;"> </span><b><span style="color: #7f0055; font-family: "consolas"; font-size: 12.0pt;">this</span></b><span style="font-family: "consolas"; font-size: 12pt;">.</span><span style="color: #0000c0; font-family: "consolas"; font-size: 12.0pt;">vehNumber</span><span style="font-family: "consolas"; font-size: 12pt;"> = </span><span style="color: #6a3e3e; font-family: "consolas"; font-size: 12.0pt;">vehNumber</span><span style="font-family: "consolas"; font-size: 12pt;">;</span><span style="font-family: "consolas"; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: "consolas"; font-size: 12pt;"> }</span><span style="font-family: "consolas"; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<br /></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<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="margin-bottom: 0.0001pt;">
<span style="font-family: "consolas"; font-size: 12pt;"> </span><b><span style="color: #7f0055; font-family: "consolas"; font-size: 12.0pt;">public</span></b><span style="font-family: "consolas"; font-size: 12pt;"> </span><b><span style="color: #7f0055; font-family: "consolas"; font-size: 12.0pt;">int</span></b><span style="font-family: "consolas"; font-size: 12pt;"> compareTo(vehicle </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="margin-bottom: 0.0001pt;">
<span style="font-family: "consolas"; font-size: 12pt;"> </span><b><span style="color: #7f0055; font-family: "consolas"; font-size: 12.0pt;">int</span></b><span style="font-family: "consolas"; font-size: 12pt;"> </span><u><span style="color: #6a3e3e; font-family: "consolas"; font-size: 12.0pt;">result</span></u><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="margin-bottom: 0.0001pt;">
<span style="font-family: "consolas"; font-size: 12pt;"> </span><b><span style="color: #7f0055; font-family: "consolas"; font-size: 12.0pt;">return</span></b><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><b><span style="color: #7f0055; font-family: "consolas"; font-size: 12.0pt;">this</span></b><span style="font-family: "consolas"; font-size: 12pt;">.getVehNumber() - </span><span style="color: #6a3e3e; font-family: "consolas"; font-size: 12.0pt;">o</span><span style="font-family: "consolas"; font-size: 12pt;">.getVehNumber();</span><span style="font-family: "consolas"; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: "consolas"; font-size: 12pt;"> }</span><span style="font-family: "consolas"; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<br /></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: "consolas"; font-size: 12pt;">}</span><span style="font-family: "consolas"; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<br /></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<b><span style="color: #7f0055; font-family: "consolas"; font-size: 12.0pt;">class</span></b><span style="font-family: "consolas"; font-size: 12pt;"> Fruit {</span><span style="font-family: "consolas"; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<br /></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<b><span style="color: #7f0055; font-family: "consolas"; font-size: 12.0pt;">public</span></b><span style="font-family: "consolas"; font-size: 12pt;"> </span><b><span style="color: #7f0055; font-family: "consolas"; font-size: 12.0pt;">class</span></b><span style="font-family: "consolas"; font-size: 12pt;"> Sorting {</span><span style="font-family: "consolas"; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<br /></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: "consolas"; font-size: 12pt;"> </span><b><span style="color: #7f0055; font-family: "consolas"; font-size: 12.0pt;">public</span></b><span style="font-family: "consolas"; font-size: 12pt;"> </span><b><span style="color: #7f0055; font-family: "consolas"; font-size: 12.0pt;">static</span></b><span style="font-family: "consolas"; font-size: 12pt;"> </span><b><span style="color: #7f0055; font-family: "consolas"; font-size: 12.0pt;">void</span></b><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="margin-bottom: 0.0001pt;">
<span style="font-family: "consolas"; font-size: 12pt;"> vehicle
</span><span style="color: #6a3e3e; font-family: "consolas"; font-size: 12.0pt;">v</span><span style="font-family: "consolas"; font-size: 12pt;"> = </span><b><span style="color: #7f0055; font-family: "consolas"; font-size: 12.0pt;">new</span></b><span style="font-family: "consolas"; font-size: 12pt;"> vehicle();</span><span style="font-family: "consolas"; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: "consolas"; font-size: 12pt;"> </span><span style="color: #6a3e3e; font-family: "consolas"; font-size: 12.0pt;">v</span><span style="font-family: "consolas"; font-size: 12pt;">.setVehNumber(123);</span><span style="font-family: "consolas"; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: "consolas"; font-size: 12pt;"> vehicle </span><span style="color: #6a3e3e; font-family: "consolas"; font-size: 12.0pt;">v2</span><span style="font-family: "consolas"; font-size: 12pt;"> = </span><b><span style="color: #7f0055; font-family: "consolas"; font-size: 12.0pt;">new</span></b><span style="font-family: "consolas"; font-size: 12pt;"> vehicle();</span><span style="font-family: "consolas"; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: "consolas"; font-size: 12pt;"> </span><span style="color: #6a3e3e; font-family: "consolas"; font-size: 12.0pt;">v2</span><span style="font-family: "consolas"; font-size: 12pt;">.setVehNumber(12);</span><span style="font-family: "consolas"; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: "consolas"; font-size: 12pt;"> vehicle </span><span style="color: #6a3e3e; font-family: "consolas"; font-size: 12.0pt;">v1</span><span style="font-family: "consolas"; font-size: 12pt;"> = </span><b><span style="color: #7f0055; font-family: "consolas"; font-size: 12.0pt;">new</span></b><span style="font-family: "consolas"; font-size: 12pt;"> vehicle();</span><span style="font-family: "consolas"; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: "consolas"; font-size: 12pt;"> </span><span style="color: #6a3e3e; font-family: "consolas"; font-size: 12.0pt;">v1</span><span style="font-family: "consolas"; font-size: 12pt;">.setVehNumber(1111);</span><span style="font-family: "consolas"; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: "consolas"; font-size: 12pt;"> </span><span style="font-family: "consolas"; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: "consolas"; font-size: 12pt;"> List<vehicle> </span><span style="color: #6a3e3e; font-family: "consolas"; font-size: 12.0pt;">vehs</span><span style="font-family: "consolas"; font-size: 12pt;"> = </span><b><span style="color: #7f0055; font-family: "consolas"; font-size: 12.0pt;">new</span></b><span style="font-family: "consolas"; font-size: 12pt;">
ArrayList<vehicle>();</span><span style="font-family: "consolas"; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: "consolas"; font-size: 12pt;"> </span><span style="color: #6a3e3e; font-family: "consolas"; font-size: 12.0pt;">vehs</span><span style="font-family: "consolas"; font-size: 12pt;">.add(</span><span style="color: #6a3e3e; font-family: "consolas"; font-size: 12.0pt;">v</span><span style="font-family: "consolas"; font-size: 12pt;">);</span><span style="color: #6a3e3e; font-family: "consolas"; font-size: 12.0pt;">vehs</span><span style="font-family: "consolas"; font-size: 12pt;">.add(</span><span style="color: #6a3e3e; font-family: "consolas"; font-size: 12.0pt;">v2</span><span style="font-family: "consolas"; font-size: 12pt;">);</span><span style="font-family: "consolas"; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: "consolas"; font-size: 12pt;"> </span><span style="color: #6a3e3e; font-family: "consolas"; font-size: 12.0pt;">vehs</span><span style="font-family: "consolas"; font-size: 12pt;">.add(</span><span style="color: #6a3e3e; font-family: "consolas"; font-size: 12.0pt;">v1</span><span style="font-family: "consolas"; font-size: 12pt;">);</span><span style="font-family: "consolas"; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: "consolas"; font-size: 12pt;"> </span><span style="font-family: "consolas"; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: "consolas"; font-size: 12pt;"> Collections.<i>sort</i>(</span><span style="color: #6a3e3e; font-family: "consolas"; font-size: 12.0pt;">vehs</span><span style="font-family: "consolas"; font-size: 12pt;">);</span><span style="font-family: "consolas"; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: "consolas"; font-size: 12pt;"> </span><b><span style="color: #7f0055; font-family: "consolas"; font-size: 12.0pt;">for</span></b><span style="font-family: "consolas"; font-size: 12pt;"> (</span><b><span style="color: #7f0055; font-family: "consolas"; font-size: 12.0pt;">int</span></b><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;">vehs</span><span style="font-family: "consolas"; font-size: 12pt;">.size(); </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="margin-bottom: 0.0001pt;">
<br /></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: "consolas"; font-size: 12pt;"> System.</span><b><i><span style="color: #0000c0; font-family: "consolas"; font-size: 12.0pt;">out</span></i></b><span style="font-family: "consolas"; font-size: 12pt;">.println(</span><span style="color: #2a00ff; font-family: "consolas"; font-size: 12.0pt;">""</span><span style="font-family: "consolas"; font-size: 12pt;"> + </span><span style="color: #6a3e3e; font-family: "consolas"; font-size: 12.0pt;">vehs</span><span style="font-family: "consolas"; font-size: 12pt;">.get(</span><span style="color: #6a3e3e; font-family: "consolas"; font-size: 12.0pt;">i</span><span style="font-family: "consolas"; font-size: 12pt;">).getVehNumber());</span><span style="font-family: "consolas"; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: "consolas"; font-size: 12pt;"> }</span><span style="font-family: "consolas"; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: "consolas"; font-size: 12pt;"> </span><span style="font-family: "consolas"; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: "consolas"; font-size: 12pt;"> </span><span style="font-family: "consolas"; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: "consolas"; font-size: 12pt;"> </span><span style="color: #3f7f5f; font-family: "consolas"; font-size: 12.0pt;">/*Fruit f1=new
Fruit("Mango1233",1233);</span><span style="font-family: "consolas"; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="color: #3f7f5f; font-family: "consolas"; font-size: 12.0pt;"> Fruit
f2=new Fruit("Mango123",123);</span><span style="font-family: "consolas"; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<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="margin-bottom: 0.0001pt;">
<span style="color: #3f7f5f; font-family: "consolas"; font-size: 12.0pt;"> List<Fruit>
<u>fs</u>=new ArrayList<Fruit>();</span><span style="font-family: "consolas"; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="color: #3f7f5f; font-family: "consolas"; font-size: 12.0pt;"> fs.add(f1);
fs.add(f2);</span><span style="font-family: "consolas"; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<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="margin-bottom: 0.0001pt;">
<span style="color: #3f7f5f; font-family: "consolas"; font-size: 12.0pt;"> Collections.sort(<u>fs</u>,new
FruitComparator());</span><span style="font-family: "consolas"; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="color: #3f7f5f; font-family: "consolas"; font-size: 12.0pt;"> System.out.println(""+fs.get(0).getFruitName());</span><span style="font-family: "consolas"; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<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="margin-bottom: 0.0001pt;">
<span style="font-family: "consolas"; font-size: 12pt;"> }</span><span style="font-family: "consolas"; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<br /></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: "consolas"; font-size: 12pt;">}</span><span style="font-family: "consolas"; font-size: 12.0pt;"><o:p></o:p></span></div>
<br />
<div class="MsoNormal">
<br /></div>
<b><span style="font-size: large;">Example For Comparator</span></b><br />
<span style="font-size: large;"><span style="color: red;"><u>Fruit.java</u></span></span><br />
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<b><span style="color: #7f0055; font-family: "arial rounded mt bold" , sans-serif; font-size: 12.0pt;">import</span></b><span style="font-family: "arial rounded mt bold" , sans-serif; font-size: 12pt;"> java.util.ArrayList;</span><span style="font-family: "arial rounded mt bold" , sans-serif; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<b><span style="color: #7f0055; font-family: "arial rounded mt bold" , sans-serif; font-size: 12.0pt;">import</span></b><span style="font-family: "arial rounded mt bold" , sans-serif; font-size: 12pt;"> java.util.Collections;</span><span style="font-family: "arial rounded mt bold" , sans-serif; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<b><span style="color: #7f0055; font-family: "arial rounded mt bold" , sans-serif; font-size: 12.0pt;">import</span></b><span style="font-family: "arial rounded mt bold" , sans-serif; font-size: 12pt;"> <u>java.util.Comparator</u>;</span><span style="font-family: "arial rounded mt bold" , sans-serif; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<b><span style="color: #7f0055; font-family: "arial rounded mt bold" , sans-serif; font-size: 12.0pt;">import</span></b><span style="font-family: "arial rounded mt bold" , sans-serif; font-size: 12pt;"> java.util.List;</span><span style="font-family: "arial rounded mt bold" , sans-serif; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<br /></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<br /></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<b><span style="color: #7f0055; font-family: "arial rounded mt bold" , sans-serif; font-size: 12.0pt;">class</span></b><span style="font-family: "arial rounded mt bold" , sans-serif; font-size: 12pt;"> Fruit {<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: "arial rounded mt bold" , sans-serif; font-size: 12pt;">String </span><span style="color: #0000c0; font-family: "arial rounded mt bold" , sans-serif; font-size: 12.0pt;">fruitName</span><span style="font-family: "arial rounded mt bold" , sans-serif; font-size: 12pt;">;</span><span style="font-family: "arial rounded mt bold" , sans-serif; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<b><span style="color: #7f0055; font-family: "arial rounded mt bold" , sans-serif; font-size: 12.0pt;">int</span></b><span style="font-family: "arial rounded mt bold" , sans-serif; font-size: 12pt;"> </span><span style="color: #0000c0; font-family: "arial rounded mt bold" , sans-serif; font-size: 12.0pt;">fruitPrice</span><span style="font-family: "arial rounded mt bold" , sans-serif; font-size: 12pt;">;</span><span style="font-family: "arial rounded mt bold" , sans-serif; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<br /></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: "arial rounded mt bold" , sans-serif; font-size: 12pt;"> </span><b><span style="color: #7f0055; font-family: "arial rounded mt bold" , sans-serif; font-size: 12.0pt;">public</span></b><span style="font-family: "arial rounded mt bold" , sans-serif; font-size: 12pt;"> Fruit(String </span><span style="color: #6a3e3e; font-family: "arial rounded mt bold" , sans-serif; font-size: 12.0pt;">fruitName</span><span style="font-family: "arial rounded mt bold" , sans-serif; font-size: 12pt;">, </span><b><span style="color: #7f0055; font-family: "arial rounded mt bold" , sans-serif; font-size: 12.0pt;">int</span></b><span style="font-family: "arial rounded mt bold" , sans-serif; font-size: 12pt;"> </span><span style="color: #6a3e3e; font-family: "arial rounded mt bold" , sans-serif; font-size: 12.0pt;">fruitPrice</span><span style="font-family: "arial rounded mt bold" , sans-serif; font-size: 12pt;">) {</span><span style="font-family: "arial rounded mt bold" , sans-serif; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: "arial rounded mt bold" , sans-serif; font-size: 12pt;"> </span><b><span style="color: #7f0055; font-family: "arial rounded mt bold" , sans-serif; font-size: 12.0pt;">super</span></b><span style="font-family: "arial rounded mt bold" , sans-serif; font-size: 12pt;">();</span><span style="font-family: "arial rounded mt bold" , sans-serif; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: "arial rounded mt bold" , sans-serif; font-size: 12pt;"> </span><b><span style="color: #7f0055; font-family: "arial rounded mt bold" , sans-serif; font-size: 12.0pt;">this</span></b><span style="font-family: "arial rounded mt bold" , sans-serif; font-size: 12pt;">.</span><span style="color: #0000c0; font-family: "arial rounded mt bold" , sans-serif; font-size: 12.0pt;">fruitName</span><span style="font-family: "arial rounded mt bold" , sans-serif; font-size: 12pt;"> = </span><span style="color: #6a3e3e; font-family: "arial rounded mt bold" , sans-serif; font-size: 12.0pt;">fruitName</span><span style="font-family: "arial rounded mt bold" , sans-serif; font-size: 12pt;">;</span><span style="font-family: "arial rounded mt bold" , sans-serif; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: "arial rounded mt bold" , sans-serif; font-size: 12pt;"> </span><b><span style="color: #7f0055; font-family: "arial rounded mt bold" , sans-serif; font-size: 12.0pt;">this</span></b><span style="font-family: "arial rounded mt bold" , sans-serif; font-size: 12pt;">.</span><span style="color: #0000c0; font-family: "arial rounded mt bold" , sans-serif; font-size: 12.0pt;">fruitPrice</span><span style="font-family: "arial rounded mt bold" , sans-serif; font-size: 12pt;"> = </span><span style="color: #6a3e3e; font-family: "arial rounded mt bold" , sans-serif; font-size: 12.0pt;">fruitPrice</span><span style="font-family: "arial rounded mt bold" , sans-serif; font-size: 12pt;">;</span><span style="font-family: "arial rounded mt bold" , sans-serif; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: "arial rounded mt bold" , sans-serif; font-size: 12pt;"> }</span><span style="font-family: "arial rounded mt bold" , sans-serif; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: "arial rounded mt bold" , sans-serif; font-size: 12pt;"> </span><b><span style="color: #7f0055; font-family: "arial rounded mt bold" , sans-serif; font-size: 12.0pt;">public</span></b><span style="font-family: "arial rounded mt bold" , sans-serif; font-size: 12pt;"> </span><b><span style="color: #7f0055; font-family: "arial rounded mt bold" , sans-serif; font-size: 12.0pt;">int</span></b><span style="font-family: "arial rounded mt bold" , sans-serif; font-size: 12pt;">
getFruitPrice() {</span><span style="font-family: "arial rounded mt bold" , sans-serif; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: "arial rounded mt bold" , sans-serif; font-size: 12pt;"> </span><b><span style="color: #7f0055; font-family: "arial rounded mt bold" , sans-serif; font-size: 12.0pt;">return</span></b><span style="font-family: "arial rounded mt bold" , sans-serif; font-size: 12pt;"> </span><span style="color: #0000c0; font-family: "arial rounded mt bold" , sans-serif; font-size: 12.0pt;">fruitPrice</span><span style="font-family: "arial rounded mt bold" , sans-serif; font-size: 12pt;">;</span><span style="font-family: "arial rounded mt bold" , sans-serif; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: "arial rounded mt bold" , sans-serif; font-size: 12pt;"> }</span><span style="font-family: "arial rounded mt bold" , sans-serif; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<br /></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: "arial rounded mt bold" , sans-serif; font-size: 12pt;"> </span><b><span style="color: #7f0055; font-family: "arial rounded mt bold" , sans-serif; font-size: 12.0pt;">public</span></b><span style="font-family: "arial rounded mt bold" , sans-serif; font-size: 12pt;"> </span><b><span style="color: #7f0055; font-family: "arial rounded mt bold" , sans-serif; font-size: 12.0pt;">void</span></b><span style="font-family: "arial rounded mt bold" , sans-serif; font-size: 12pt;"> setFruitPrice(</span><b><span style="color: #7f0055; font-family: "arial rounded mt bold" , sans-serif; font-size: 12.0pt;">int</span></b><span style="font-family: "arial rounded mt bold" , sans-serif; font-size: 12pt;"> </span><span style="color: #6a3e3e; font-family: "arial rounded mt bold" , sans-serif; font-size: 12.0pt;">fruitPrice</span><span style="font-family: "arial rounded mt bold" , sans-serif; font-size: 12pt;">) {</span><span style="font-family: "arial rounded mt bold" , sans-serif; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: "arial rounded mt bold" , sans-serif; font-size: 12pt;"> </span><b><span style="color: #7f0055; font-family: "arial rounded mt bold" , sans-serif; font-size: 12.0pt;">this</span></b><span style="font-family: "arial rounded mt bold" , sans-serif; font-size: 12pt;">.</span><span style="color: #0000c0; font-family: "arial rounded mt bold" , sans-serif; font-size: 12.0pt;">fruitPrice</span><span style="font-family: "arial rounded mt bold" , sans-serif; font-size: 12pt;"> = </span><span style="color: #6a3e3e; font-family: "arial rounded mt bold" , sans-serif; font-size: 12.0pt;">fruitPrice</span><span style="font-family: "arial rounded mt bold" , sans-serif; font-size: 12pt;">;</span><span style="font-family: "arial rounded mt bold" , sans-serif; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: "arial rounded mt bold" , sans-serif; font-size: 12pt;"> }</span><span style="font-family: "arial rounded mt bold" , sans-serif; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: "arial rounded mt bold" , sans-serif; font-size: 12pt;"> </span><b><span style="color: #7f0055; font-family: "arial rounded mt bold" , sans-serif; font-size: 12.0pt;">public</span></b><span style="font-family: "arial rounded mt bold" , sans-serif; font-size: 12pt;"> String getFruitName() {</span><span style="font-family: "arial rounded mt bold" , sans-serif; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: "arial rounded mt bold" , sans-serif; font-size: 12pt;"> </span><b><span style="color: #7f0055; font-family: "arial rounded mt bold" , sans-serif; font-size: 12.0pt;">return</span></b><span style="font-family: "arial rounded mt bold" , sans-serif; font-size: 12pt;"> </span><span style="color: #0000c0; font-family: "arial rounded mt bold" , sans-serif; font-size: 12.0pt;">fruitName</span><span style="font-family: "arial rounded mt bold" , sans-serif; font-size: 12pt;">;</span><span style="font-family: "arial rounded mt bold" , sans-serif; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: "arial rounded mt bold" , sans-serif; font-size: 12pt;"> }</span><span style="font-family: "arial rounded mt bold" , sans-serif; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<br /></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: "arial rounded mt bold" , sans-serif; font-size: 12pt;"> </span><b><span style="color: #7f0055; font-family: "arial rounded mt bold" , sans-serif; font-size: 12.0pt;">public</span></b><span style="font-family: "arial rounded mt bold" , sans-serif; font-size: 12pt;"> </span><b><span style="color: #7f0055; font-family: "arial rounded mt bold" , sans-serif; font-size: 12.0pt;">void</span></b><span style="font-family: "arial rounded mt bold" , sans-serif; font-size: 12pt;"> setFruitName(String </span><span style="color: #6a3e3e; font-family: "arial rounded mt bold" , sans-serif; font-size: 12.0pt;">fruitName</span><span style="font-family: "arial rounded mt bold" , sans-serif; font-size: 12pt;">) {</span><span style="font-family: "arial rounded mt bold" , sans-serif; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: "arial rounded mt bold" , sans-serif; font-size: 12pt;"> </span><b><span style="color: #7f0055; font-family: "arial rounded mt bold" , sans-serif; font-size: 12.0pt;">this</span></b><span style="font-family: "arial rounded mt bold" , sans-serif; font-size: 12pt;">.</span><span style="color: #0000c0; font-family: "arial rounded mt bold" , sans-serif; font-size: 12.0pt;">fruitName</span><span style="font-family: "arial rounded mt bold" , sans-serif; font-size: 12pt;"> = </span><span style="color: #6a3e3e; font-family: "arial rounded mt bold" , sans-serif; font-size: 12.0pt;">fruitName</span><span style="font-family: "arial rounded mt bold" , sans-serif; font-size: 12pt;">;</span><span style="font-family: "arial rounded mt bold" , sans-serif; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: "arial rounded mt bold" , sans-serif; font-size: 12pt;"> }</span><span style="font-family: "arial rounded mt bold" , sans-serif; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<br /></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: "arial rounded mt bold" , sans-serif; font-size: 12pt;"> </span><span style="font-family: "arial rounded mt bold" , sans-serif; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<br /></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: "arial rounded mt bold" , sans-serif; font-size: 12pt;">}</span><span style="font-family: "arial rounded mt bold" , sans-serif; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<br /></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<b><span style="color: #7f0055; font-family: "arial rounded mt bold" , sans-serif; font-size: 12.0pt;">public</span></b><span style="font-family: "arial rounded mt bold" , sans-serif; font-size: 12pt;"> </span><b><span style="color: #7f0055; font-family: "arial rounded mt bold" , sans-serif; font-size: 12.0pt;">class</span></b><span style="font-family: "arial rounded mt bold" , sans-serif; font-size: 12pt;"> Sorting {</span><span style="font-family: "arial rounded mt bold" , sans-serif; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<br /></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: "arial rounded mt bold" , sans-serif; font-size: 12pt;"> </span><b><span style="color: #7f0055; font-family: "arial rounded mt bold" , sans-serif; font-size: 12.0pt;">public</span></b><span style="font-family: "arial rounded mt bold" , sans-serif; font-size: 12pt;"> </span><b><span style="color: #7f0055; font-family: "arial rounded mt bold" , sans-serif; font-size: 12.0pt;">static</span></b><span style="font-family: "arial rounded mt bold" , sans-serif; font-size: 12pt;"> </span><b><span style="color: #7f0055; font-family: "arial rounded mt bold" , sans-serif; font-size: 12.0pt;">void</span></b><span style="font-family: "arial rounded mt bold" , sans-serif; font-size: 12pt;"> main(String[] </span><span style="color: #6a3e3e; font-family: "arial rounded mt bold" , sans-serif; font-size: 12.0pt;">args</span><span style="font-family: "arial rounded mt bold" , sans-serif; font-size: 12pt;">) {</span><span style="font-family: "arial rounded mt bold" , sans-serif; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: "arial rounded mt bold" , sans-serif; font-size: 12pt;"> </span><span style="font-family: "arial rounded mt bold" , sans-serif; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: "arial rounded mt bold" , sans-serif; font-size: 12pt;"> Fruit
</span><span style="color: #6a3e3e; font-family: "arial rounded mt bold" , sans-serif; font-size: 12.0pt;">f1</span><span style="font-family: "arial rounded mt bold" , sans-serif; font-size: 12pt;">=</span><b><span style="color: #7f0055; font-family: "arial rounded mt bold" , sans-serif; font-size: 12.0pt;">new</span></b><span style="font-family: "arial rounded mt bold" , sans-serif; font-size: 12pt;"> Fruit(</span><span style="color: #2a00ff; font-family: "arial rounded mt bold" , sans-serif; font-size: 12.0pt;">"Mango1233"</span><span style="font-family: "arial rounded mt bold" , sans-serif; font-size: 12pt;">,1233);</span><span style="font-family: "arial rounded mt bold" , sans-serif; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: "arial rounded mt bold" , sans-serif; font-size: 12pt;"> Fruit
</span><span style="color: #6a3e3e; font-family: "arial rounded mt bold" , sans-serif; font-size: 12.0pt;">f2</span><span style="font-family: "arial rounded mt bold" , sans-serif; font-size: 12pt;">=</span><b><span style="color: #7f0055; font-family: "arial rounded mt bold" , sans-serif; font-size: 12.0pt;">new</span></b><span style="font-family: "arial rounded mt bold" , sans-serif; font-size: 12pt;"> Fruit(</span><span style="color: #2a00ff; font-family: "arial rounded mt bold" , sans-serif; font-size: 12.0pt;">"Mango123"</span><span style="font-family: "arial rounded mt bold" , sans-serif; font-size: 12pt;">,123);</span><span style="font-family: "arial rounded mt bold" , sans-serif; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: "arial rounded mt bold" , sans-serif; font-size: 12pt;"> </span><span style="font-family: "arial rounded mt bold" , sans-serif; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: "arial rounded mt bold" , sans-serif; font-size: 12pt;"> List<Fruit>
</span><span style="color: #6a3e3e; font-family: "arial rounded mt bold" , sans-serif; font-size: 12.0pt;">fs</span><span style="font-family: "arial rounded mt bold" , sans-serif; font-size: 12pt;">=</span><b><span style="color: #7f0055; font-family: "arial rounded mt bold" , sans-serif; font-size: 12.0pt;">new</span></b><span style="font-family: "arial rounded mt bold" , sans-serif; font-size: 12pt;"> ArrayList<Fruit>();</span><span style="font-family: "arial rounded mt bold" , sans-serif; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: "arial rounded mt bold" , sans-serif; font-size: 12pt;"> </span><span style="color: #6a3e3e; font-family: "arial rounded mt bold" , sans-serif; font-size: 12.0pt;">fs</span><span style="font-family: "arial rounded mt bold" , sans-serif; font-size: 12pt;">.add(</span><span style="color: #6a3e3e; font-family: "arial rounded mt bold" , sans-serif; font-size: 12.0pt;">f1</span><span style="font-family: "arial rounded mt bold" , sans-serif; font-size: 12pt;">); </span><span style="color: #6a3e3e; font-family: "arial rounded mt bold" , sans-serif; font-size: 12.0pt;">fs</span><span style="font-family: "arial rounded mt bold" , sans-serif; font-size: 12pt;">.add(</span><span style="color: #6a3e3e; font-family: "arial rounded mt bold" , sans-serif; font-size: 12.0pt;">f2</span><span style="font-family: "arial rounded mt bold" , sans-serif; font-size: 12pt;">);</span><span style="font-family: "arial rounded mt bold" , sans-serif; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: "arial rounded mt bold" , sans-serif; font-size: 12pt;"> </span><span style="font-family: "arial rounded mt bold" , sans-serif; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: "arial rounded mt bold" , sans-serif; font-size: 12pt;"> Collections.<i>sort</i>(</span><span style="color: #6a3e3e; font-family: "arial rounded mt bold" , sans-serif; font-size: 12.0pt;">fs</span><span style="font-family: "arial rounded mt bold" , sans-serif; font-size: 12pt;">,</span><b><span style="color: #7f0055; font-family: "arial rounded mt bold" , sans-serif; font-size: 12.0pt;">new</span></b><span style="font-family: "arial rounded mt bold" , sans-serif; font-size: 12pt;"> FruitComparator());</span><span style="font-family: "arial rounded mt bold" , sans-serif; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: "arial rounded mt bold" , sans-serif; font-size: 12pt;"> </span><b><span style="color: #7f0055; font-family: "arial rounded mt bold" , sans-serif; font-size: 12.0pt;">for</span></b><span style="font-family: "arial rounded mt bold" , sans-serif; font-size: 12pt;"> (</span><b><span style="color: #7f0055; font-family: "arial rounded mt bold" , sans-serif; font-size: 12.0pt;">int</span></b><span style="font-family: "arial rounded mt bold" , sans-serif; font-size: 12pt;"> </span><span style="color: #6a3e3e; font-family: "arial rounded mt bold" , sans-serif; font-size: 12.0pt;">i</span><span style="font-family: "arial rounded mt bold" , sans-serif; font-size: 12pt;"> = 0; </span><span style="color: #6a3e3e; font-family: "arial rounded mt bold" , sans-serif; font-size: 12.0pt;">i</span><span style="font-family: "arial rounded mt bold" , sans-serif; font-size: 12pt;"> < </span><span style="color: #6a3e3e; font-family: "arial rounded mt bold" , sans-serif; font-size: 12.0pt;">fs</span><span style="font-family: "arial rounded mt bold" , sans-serif; font-size: 12pt;">.size();
</span><span style="color: #6a3e3e; font-family: "arial rounded mt bold" , sans-serif; font-size: 12.0pt;">i</span><span style="font-family: "arial rounded mt bold" , sans-serif; font-size: 12pt;">++) { </span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: "arial rounded mt bold" , sans-serif; font-size: 12pt;"> System.</span><b><i><span style="color: #0000c0; font-family: "arial rounded mt bold" , sans-serif; font-size: 12.0pt;">out</span></i></b><span style="font-family: "arial rounded mt bold" , sans-serif; font-size: 12pt;">.println(</span><span style="color: #2a00ff; font-family: "arial rounded mt bold" , sans-serif; font-size: 12.0pt;">""</span><span style="font-family: "arial rounded mt bold" , sans-serif; font-size: 12pt;"> + </span><span style="color: #6a3e3e; font-family: "arial rounded mt bold" , sans-serif; font-size: 12.0pt;">fs</span><span style="font-family: "arial rounded mt bold" , sans-serif; font-size: 12pt;">.get(</span><span style="color: #6a3e3e; font-family: "arial rounded mt bold" , sans-serif; font-size: 12.0pt;">i</span><span style="font-family: "arial rounded mt bold" , sans-serif; font-size: 12pt;">).getFruitPrice());</span><span style="font-family: "arial rounded mt bold" , sans-serif; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: "arial rounded mt bold" , sans-serif; font-size: 12pt;"> }</span><span style="font-family: "arial rounded mt bold" , sans-serif; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<br /></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: "arial rounded mt bold" , sans-serif; font-size: 12pt;"> }</span><span style="font-family: "arial rounded mt bold" , sans-serif; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<br /></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: "arial rounded mt bold" , sans-serif; font-size: 12pt;">}</span><span style="font-family: "arial rounded mt bold" , sans-serif; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
</div>
<div class="MsoNormal">
<br /></div>
<br />
<div class="MsoNormal">
<br /></div>
</div>
<span style="font-size: large;"><i><u><span style="color: red;">FruitComparator.java-</span></u></i></span><br />
<span style="font-size: large;"><i>This is where we will write logic for comparing two custom objects.</i></span><br />
<span style="font-size: large;">import java.util.Comparator;</span><br />
<span style="font-size: large;"><br /></span>
<br />
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<b><span style="color: #7f0055; font-family: "arial rounded mt bold" , sans-serif; font-size: 12.0pt;">import</span></b><span style="font-family: "arial rounded mt bold" , sans-serif; font-size: 12pt;"> java.util.Comparator;</span><span style="font-family: "arial rounded mt bold" , sans-serif; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<br /></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<b><span style="color: #7f0055; font-family: "arial rounded mt bold" , sans-serif; font-size: 12.0pt;">public</span></b><span style="font-family: "arial rounded mt bold" , sans-serif; font-size: 12pt;"> </span><b><span style="color: #7f0055; font-family: "arial rounded mt bold" , sans-serif; font-size: 12.0pt;">class</span></b><span style="font-family: "arial rounded mt bold" , sans-serif; font-size: 12pt;"> FruitComparator </span><b><span style="color: #7f0055; font-family: "arial rounded mt bold" , sans-serif; font-size: 12.0pt;">implements</span></b><span style="font-family: "arial rounded mt bold" , sans-serif; font-size: 12pt;">
Comparator<Fruit> {</span><span style="font-family: "arial rounded mt bold" , sans-serif; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: "arial rounded mt bold" , sans-serif; font-size: 12pt;"> </span><b><span style="color: #7f0055; font-family: "arial rounded mt bold" , sans-serif; font-size: 12.0pt;">public</span></b><span style="font-family: "arial rounded mt bold" , sans-serif; font-size: 12pt;"> </span><b><span style="color: #7f0055; font-family: "arial rounded mt bold" , sans-serif; font-size: 12.0pt;">int</span></b><span style="font-family: "arial rounded mt bold" , sans-serif; font-size: 12pt;">
compare(Fruit </span><span style="color: #6a3e3e; font-family: "arial rounded mt bold" , sans-serif; font-size: 12.0pt;">o1</span><span style="font-family: "arial rounded mt bold" , sans-serif; font-size: 12pt;">, Fruit </span><span style="color: #6a3e3e; font-family: "arial rounded mt bold" , sans-serif; font-size: 12.0pt;">o2</span><span style="font-family: "arial rounded mt bold" , sans-serif; font-size: 12pt;">) {</span><span style="font-family: "arial rounded mt bold" , sans-serif; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: "arial rounded mt bold" , sans-serif; font-size: 12pt;"> </span><b><span style="color: #7f0055; font-family: "arial rounded mt bold" , sans-serif; font-size: 12.0pt;">int</span></b><span style="font-family: "arial rounded mt bold" , sans-serif; font-size: 12pt;"> </span><span style="color: #6a3e3e; font-family: "arial rounded mt bold" , sans-serif; font-size: 12.0pt;">result</span><span style="font-family: "arial rounded mt bold" , sans-serif; font-size: 12pt;"> = 0;</span><span style="font-family: "arial rounded mt bold" , sans-serif; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: "arial rounded mt bold" , sans-serif; font-size: 12pt;"> </span><b><span style="color: #7f0055; font-family: "arial rounded mt bold" , sans-serif; font-size: 12.0pt;">if</span></b><span style="font-family: "arial rounded mt bold" , sans-serif; font-size: 12pt;"> (</span><span style="color: #6a3e3e; font-family: "arial rounded mt bold" , sans-serif; font-size: 12.0pt;">o1</span><span style="font-family: "arial rounded mt bold" , sans-serif; font-size: 12pt;">.getFruitPrice()
< </span><span style="color: #6a3e3e; font-family: "arial rounded mt bold" , sans-serif; font-size: 12.0pt;">o2</span><span style="font-family: "arial rounded mt bold" , sans-serif; font-size: 12pt;">.getFruitPrice()) {</span><span style="font-family: "arial rounded mt bold" , sans-serif; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: "arial rounded mt bold" , sans-serif; font-size: 12pt;"> </span><span style="color: #6a3e3e; font-family: "arial rounded mt bold" , sans-serif; font-size: 12.0pt;">result</span><span style="font-family: "arial rounded mt bold" , sans-serif; font-size: 12pt;"> = -1;</span><span style="font-family: "arial rounded mt bold" , sans-serif; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: "arial rounded mt bold" , sans-serif; font-size: 12pt;"> }
</span><b><span style="color: #7f0055; font-family: "arial rounded mt bold" , sans-serif; font-size: 12.0pt;">else</span></b><span style="font-family: "arial rounded mt bold" , sans-serif; font-size: 12pt;"> {</span><span style="font-family: "arial rounded mt bold" , sans-serif; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: "arial rounded mt bold" , sans-serif; font-size: 12pt;"> </span><span style="color: #6a3e3e; font-family: "arial rounded mt bold" , sans-serif; font-size: 12.0pt;">result</span><span style="font-family: "arial rounded mt bold" , sans-serif; font-size: 12pt;"> = 1;</span><span style="font-family: "arial rounded mt bold" , sans-serif; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: "arial rounded mt bold" , sans-serif; font-size: 12pt;"> }</span><span style="font-family: "arial rounded mt bold" , sans-serif; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: "arial rounded mt bold" , sans-serif; font-size: 12pt;"> </span><b><span style="color: #7f0055; font-family: "arial rounded mt bold" , sans-serif; font-size: 12.0pt;">return</span></b><span style="font-family: "arial rounded mt bold" , sans-serif; font-size: 12pt;"> </span><span style="color: #6a3e3e; font-family: "arial rounded mt bold" , sans-serif; font-size: 12.0pt;">result</span><span style="font-family: "arial rounded mt bold" , sans-serif; font-size: 12pt;">;</span><span style="font-family: "arial rounded mt bold" , sans-serif; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: "arial rounded mt bold" , sans-serif; font-size: 12pt;"> }</span><span style="font-family: "arial rounded mt bold" , sans-serif; font-size: 12.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: "arial rounded mt bold" , sans-serif; font-size: 12pt;">}</span><span style="font-family: "arial rounded mt bold" , sans-serif; font-size: 12.0pt;"><o:p></o:p></span></div>
<br />
<div class="MsoNormal">
<br /></div>
<div>
<span style="font-size: large;"><span style="color: red;"><u>Sorting.java</u></span></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<b><span style="color: #7f0055; font-family: "consolas"; font-size: 12pt;">public</span></b><span style="font-family: "consolas"; font-size: 12pt;"> </span><b><span style="color: #7f0055; font-family: "consolas"; font-size: 12pt;">class</span></b><span style="font-family: "consolas"; font-size: 12pt;"> Sorting {</span><span style="font-family: "consolas"; font-size: 12pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<br /></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: "consolas"; font-size: 12pt;"> </span><b><span style="color: #7f0055; font-family: "consolas"; font-size: 12pt;">public</span></b><span style="font-family: "consolas"; font-size: 12pt;"> </span><b><span style="color: #7f0055; font-family: "consolas"; font-size: 12pt;">static</span></b><span style="font-family: "consolas"; font-size: 12pt;"> </span><b><span style="color: #7f0055; font-family: "consolas"; font-size: 12pt;">void</span></b><span style="font-family: "consolas"; font-size: 12pt;"> main(String[] </span><span style="color: #6a3e3e; font-family: "consolas"; font-size: 12pt;">args</span><span style="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="margin-bottom: 0.0001pt;">
<span style="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="margin-bottom: 0.0001pt;">
<span style="font-family: "consolas"; font-size: 12pt;"> Fruit </span><span style="color: #6a3e3e; font-family: "consolas"; font-size: 12pt;">f1</span><span style="font-family: "consolas"; font-size: 12pt;">=</span><b><span style="color: #7f0055; font-family: "consolas"; font-size: 12pt;">new</span></b><span style="font-family: "consolas"; font-size: 12pt;"> Fruit(</span><span style="color: #2a00ff; font-family: "consolas"; font-size: 12pt;">"Mango1233"</span><span style="font-family: "consolas"; font-size: 12pt;">,1233);</span><span style="font-family: "consolas"; font-size: 12pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: "consolas"; font-size: 12pt;"> Fruit </span><span style="color: #6a3e3e; font-family: "consolas"; font-size: 12pt;">f2</span><span style="font-family: "consolas"; font-size: 12pt;">=</span><b><span style="color: #7f0055; font-family: "consolas"; font-size: 12pt;">new</span></b><span style="font-family: "consolas"; font-size: 12pt;"> Fruit(</span><span style="color: #2a00ff; font-family: "consolas"; font-size: 12pt;">"Mango123"</span><span style="font-family: "consolas"; font-size: 12pt;">,123);</span><span style="font-family: "consolas"; font-size: 12pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="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="margin-bottom: 0.0001pt;">
<span style="font-family: "consolas"; font-size: 12pt;"> List<Fruit> </span><span style="color: #6a3e3e; font-family: "consolas"; font-size: 12pt;">fs</span><span style="font-family: "consolas"; font-size: 12pt;">=</span><b><span style="color: #7f0055; font-family: "consolas"; font-size: 12pt;">new</span></b><span style="font-family: "consolas"; font-size: 12pt;"> ArrayList<Fruit>();</span><span style="font-family: "consolas"; font-size: 12pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: "consolas"; font-size: 12pt;"> </span><span style="color: #6a3e3e; font-family: "consolas"; font-size: 12pt;">fs</span><span style="font-family: "consolas"; font-size: 12pt;">.add(</span><span style="color: #6a3e3e; font-family: "consolas"; font-size: 12pt;">f1</span><span style="font-family: "consolas"; font-size: 12pt;">); </span><span style="color: #6a3e3e; font-family: "consolas"; font-size: 12pt;">fs</span><span style="font-family: "consolas"; font-size: 12pt;">.add(</span><span style="color: #6a3e3e; font-family: "consolas"; font-size: 12pt;">f2</span><span style="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="margin-bottom: 0.0001pt;">
<span style="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="margin-bottom: 0.0001pt;">
<span style="font-family: "consolas"; font-size: 12pt;"> Collections.<i>sort</i>(</span><span style="color: #6a3e3e; font-family: "consolas"; font-size: 12pt;">fs</span><span style="font-family: "consolas"; font-size: 12pt;">,</span><b><span style="color: #7f0055; font-family: "consolas"; font-size: 12pt;">new</span></b><span style="font-family: "consolas"; font-size: 12pt;"> FruitComparator());</span><span style="font-family: "consolas"; font-size: 12pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: "consolas"; font-size: 12pt;"> </span><b><span style="color: #7f0055; font-family: "consolas"; font-size: 12pt;">for</span></b><span style="font-family: "consolas"; font-size: 12pt;"> (</span><b><span style="color: #7f0055; font-family: "consolas"; font-size: 12pt;">int</span></b><span style="font-family: "consolas"; font-size: 12pt;"> </span><span style="color: #6a3e3e; font-family: "consolas"; font-size: 12pt;">i</span><span style="font-family: "consolas"; font-size: 12pt;"> = 0; </span><span style="color: #6a3e3e; font-family: "consolas"; font-size: 12pt;">i</span><span style="font-family: "consolas"; font-size: 12pt;"> < </span><span style="color: #6a3e3e; font-family: "consolas"; font-size: 12pt;">fs</span><span style="font-family: "consolas"; font-size: 12pt;">.size(); </span><span style="color: #6a3e3e; font-family: "consolas"; font-size: 12pt;">i</span><span style="font-family: "consolas"; font-size: 12pt;">++) { System.</span><b><i><span style="color: #0000c0; font-family: "consolas"; font-size: 12pt;">out</span></i></b><span style="font-family: "consolas"; font-size: 12pt;">.println(</span><span style="color: #2a00ff; font-family: "consolas"; font-size: 12pt;">""</span><span style="font-family: "consolas"; font-size: 12pt;"> + </span><span style="color: #6a3e3e; font-family: "consolas"; font-size: 12pt;">fs</span><span style="font-family: "consolas"; font-size: 12pt;">.get(</span><span style="color: #6a3e3e; font-family: "consolas"; font-size: 12pt;">i</span><span style="font-family: "consolas"; font-size: 12pt;">).getFruitPrice());</span><span style="font-family: "consolas"; font-size: 12pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="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="margin-bottom: 0.0001pt;">
<br /></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="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="margin-bottom: 0.0001pt;">
<br /></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: "consolas"; font-size: 12pt;">}</span></div>
</div>
</div>
Anonymoushttp://www.blogger.com/profile/07685598617709117616noreply@blogger.com0tag:blogger.com,1999:blog-1266456599706152053.post-23038775821248844832016-06-14T15:18:00.004+05:302016-08-29T23:39:04.787+05:30Array Declaration in java :)<script src="//z-na.amazon-adsystem.com/widgets/onejs?MarketPlace=US"></script>
<a href="https://www.amazon.in/gp/product/9339213033/ref=as_li_tl?ie=UTF8&camp=3626&creative=24790&creativeASIN=9339213033&linkCode=as2&tag=javashivblogs-21" rel="nofollow"><img border="0" src="https://ws-in.amazon-adsystem.com/widgets/q?_encoding=UTF8&ASIN=9339213033&Format=_SL110_&ID=AsinImage&MarketPlace=IN&ServiceVersion=20070822&WS=1&tag=javashivblogs-21" /></a><img alt="" border="0" height="1" src="https://ir-in.amazon-adsystem.com/e/ir?t=javashivblogs-21&l=as2&o=31&a=9339213033" style="border: none !important; margin: 0px !important;" width="1" />
<div dir="ltr" style="text-align: left;" trbidi="on">
<h3> </h3>
<h1><span style="text-decoration: underline; color: #ff6600;"><em><strong>I am gonna discuss about various possibilities in which array can be declared.</strong></em></span></h1>
<p><span style="color: #0000ff;">String[] empNames []; Correct<br />String[][][] professions; // Correct</span></p>
<h3><br />int[5] salaries;//Wrong<br /> Remember JVM wont allocate size until oyu create objects.</h3>
<h3>HOw to create the array of type String.<br />int[] items; // Declares the array of ints<br />items= new int[4]; // constructs an array and assigns it<br />// to the testScores variable</h3>
<ul>
<li>
<h2><span style="color: #ff0000;">Create an array of size four and assign the reference to "items" variable.</span></h2>
</li>
</ul>
<h3>Array must be given size explicitely.<br /> int[] list=new int[];//Not allowed<br /> _________________________<br />Create multidimenstional Array<br />_________________________________</h3>
<h3>int[][] myArray = new int[3][];<br />Notice that first bracket carry size.This means it is a array that will hold refernce to other arrays.<br /> <br /> int[ ][ ] myArray = new int[3][ ];<br />myArray[0] = new int[2];<br />myArray[0][0] = 6;<br />myArray[0][1] = 7;<br />myArray[1] = new int[3];<br />myArray[1][0] = 9;<br />myArray[1][1] = 8;<br />myArray[1][2] = 5;</h3>
<h3><br />Onother example<br />Car [] cars = new Car[3];<br />cars[0]=new Car();<span style="color: #ff0000;"> //Will Work</span><br />cars[4]=new Car(); <span style="color: #ff0000;">//Will not Work.will give</span> <span style="color: #ff0000;">ArrayIndexOutOfBoundException.</span><br />cars[3]=3 <span style="color: #ff0000;">// Runtime exception. There is no element at index</span></h3>
<h3><span style="text-decoration: underline;"><em><strong> <span style="background-color: #ffff00;">One Line intialization</span></strong></em></span><br /> int x = 9;<br /> int[] items = {6,x,8};//Length determined by number of values in "items".</h3>
<h3>Shortcut for Creating multidimensional array.<br />int[][] items = {{5,2,4,7}, {9,2}, {3,4}};</h3>
<h3>items[0] ///contains 5,2,4,7<br /> items[0][1] output 2</h3>
<h3><br /> <span style="text-decoration: underline;"><span style="background-color: #ffff00;">Anonymous Array creation</span></span></h3>
<h3><span style="text-decoration: underline; color: #800080;"><strong>Correct -> </strong></span></h3>
<h3>int[] items;<br />items = new int[] {4,15,2};</h3>
<h3>This implies first refernce is created and then it points to anonymous array with items {4,15,2}</h3>
<h3><span style="text-decoration: underline; color: #800080;">InCorrect-> </span></h3>
<h3><span style="text-decoration: underline;"> </span>int[] items;<br />items = new int[3] {4,15,2};//Not allowed.</h3>
<h2><br /> <span style="background-color: #ffff00;"><em>When creating anonymous array we never specify the item size in advance it will be calculated by number of items in the comma seperated list.</em></span></h2>
<h3><span style="color: #ff0000;">YOu can't assign 2 d array to 1 d array.</span></h3>
<h3>int[] screen;<br />int[][] multiplex = new int[3][];<br />screen = multiplex ;</h3>
<ul>
<li><strong>Static block and init block</strong></li>
</ul>
<h3>Static block: initializes static variable.<span style="background-color: #ffff00;">Static block initializes only once.</span></h3>
<h3>Init block: inits instance variables.<span style="background-color: #ffff00;">Init block runs evry time when instance of class is created..</span><br /> class SmallInit {<br /> static int x;<br /> int y;<br /> static { x = 7 ; } // static init block<br /> { y = 8; } // instance init block<br /> }<br />>><span style="background-color: #ffff00;">Init blocks runs after the all constructors got executed.</span></h3>
<br /></div>Anonymoushttp://www.blogger.com/profile/07685598617709117616noreply@blogger.com0tag:blogger.com,1999:blog-1266456599706152053.post-86020705701440311422016-06-14T11:19:00.000+05:302016-09-02T16:29:49.557+05:30RequestDispatcher.forward() vs HttpServletResponse.sendRedirect()<div dir="ltr" style="text-align: left;" trbidi="on">
Get Free Book :) <a href="https://www.amazon.in/gp/product/9339213033/ref=as_li_tl?ie=UTF8&camp=3626&creative=24790&creativeASIN=9339213033&linkCode=as2&tag=javashivblogs-21" rel="nofollow"><img border="0" src="https://ws-in.amazon-adsystem.com/widgets/q?_encoding=UTF8&ASIN=9339213033&Format=_SL110_&ID=AsinImage&MarketPlace=IN&ServiceVersion=20070822&WS=1&tag=javashivblogs-21" /></a><img alt="" border="0" height="1" src="https://ir-in.amazon-adsystem.com/e/ir?t=javashivblogs-21&l=as2&o=31&a=9339213033" style="border: none !important; margin: 0px !important;" width="1" />
<br />
<div dir="ltr" style="text-align: left;" trbidi="on">
<ul>
<li><strong>RequestDispatcher.forward() vs HttpServletResponse.sendRedirect()</strong><br />_______________________________________________________________<br /><span style="color: red;">RequestDispatcher.forward()</span><br />_______________________________________________________________
<h2>
1.When we use forward method, request is transfer to other resource within the same server.</h2>
<h2>
2.client or browser is not involved.</h2>
<h2>
3.When forward is called on requestdispatcher object we pass request and response objects so our old request object is passed on for further processing.</h2>
<h2>
4.ON browsers url you cant see that address.</h2>
<h2>
5. forward () method is faster then send redirect.</h2>
_______________________________________________________________<br /><strong><span style="color: red;">SendRedirect</span></strong><br />_________________________________________________________________</li>
<li>
<h2>
1.request is transfer to another resource to different server for further processing.</h2>
</li>
<li>
<h2>
2.Url is visible on the browser.</h2>
</li>
<li>
<h2>
3.In case of sendRedirect call, old request and response objects are lost because it’s treated as new request by the browser.</h2>
</li>
<li>
<h2>
4.In address bar, we are able to see the new redirected address.</h2>
<h2>
5.sendRedirect is slower because one extra round trip is required, because completely new request is created and old request object is lost. Two browser request required.</h2>
</li>
<li>
<h2>
</h2>
</li>
</ul>
<h2>
</h2>
<br /></div>
<div>
<iframe frameborder="0" marginheight="0" marginwidth="0" scrolling="no" src="//ws-na.amazon-adsystem.com/widgets/q?ServiceVersion=20070822&OneJS=1&Operation=GetAdHtml&MarketPlace=US&source=ac&ref=tf_til&ad_type=product_link&tracking_id=javashiv-20&marketplace=amazon&region=US&placement=B017YEA6QW&asins=B017YEA6QW&linkId=ed85184b5d9f9386f7499288259e24f5&show_border=true&link_opens_in_new_window=false&price_color=333333&title_color=0066c0&bg_color=ffffff" style="height: 240px; width: 120px;">
</iframe></div>
</div>
Anonymoushttp://www.blogger.com/profile/07685598617709117616noreply@blogger.com0tag:blogger.com,1999:blog-1266456599706152053.post-43017159189589756702016-06-10T20:10:00.001+05:302016-09-02T16:30:32.077+05:30Producer Consumer Problem in java<div dir="ltr" style="text-align: left;" trbidi="on">
<script src="//z-na.amazon-adsystem.com/widgets/onejs?MarketPlace=US"></script>
<a href="https://www.amazon.in/gp/product/9339213033/ref=as_li_tl?ie=UTF8&camp=3626&creative=24790&creativeASIN=9339213033&linkCode=as2&tag=javashivblogs-21" rel="nofollow"><img border="0" src="https://ws-in.amazon-adsystem.com/widgets/q?_encoding=UTF8&ASIN=9339213033&Format=_SL110_&ID=AsinImage&MarketPlace=IN&ServiceVersion=20070822&WS=1&tag=javashivblogs-21" /></a><img alt="" border="0" height="1" src="https://ir-in.amazon-adsystem.com/e/ir?t=javashivblogs-21&l=as2&o=31&a=9339213033" style="border: none !important; margin: 0px !important;" width="1" />
<br />
<pre> import java.util.Vector;
import java.util.logging.Level;
import java.util.logging.Logger;
public class ProducerConsumerSolution {
public static void main(String args[]) {
Vector sharedQueue = new Vector();
int size = 4;
Thread prodThread = new Thread(new Producer(sharedQueue, size), "Producer");
Thread consThread = new Thread(new Consumer(sharedQueue, size), "Consumer");
prodThread.start();
consThread.start();
}
}
class Producer implements Runnable {
private final Vector sharedQueue;
private final int SIZE;
public Producer(Vector sharedQueue, int size) {
this.sharedQueue = sharedQueue;
this.SIZE = size;
}
@Override
public void run() {
for (int i = 0; i < 7; i++) {
System.out.println("Produced: " + i);
try {
produce(i);
} catch (InterruptedException ex) {
Logger.getLogger(Producer.class.getName()).log(Level.SEVERE, null, ex);
}
}
}
private void produce(int i) throws InterruptedException {
//wait if queue is full
while (sharedQueue.size() == SIZE) {
synchronized (sharedQueue) {
System.out.println("Queue is full " + Thread.currentThread().getName()
+ " is waiting , size: " + sharedQueue.size());
sharedQueue.wait();
}
}
//producing element and notify consumers
synchronized (sharedQueue) {
sharedQueue.add(i);
sharedQueue.notifyAll();
}
}
}
class Consumer implements Runnable {
private final Vector sharedQueue;
private final int SIZE;
public Consumer(Vector sharedQueue, int size) {
this.sharedQueue = sharedQueue;
this.SIZE = size;
}
@Override
public void run() {
while (true) {
try {
System.out.println("Consumed: " + consume());
Thread.sleep(50);
} catch (InterruptedException ex) {
Logger.getLogger(Consumer.class.getName()).log(Level.SEVERE, null, ex);
}
}
}
private int consume() throws InterruptedException {
//wait if queue is empty
while (sharedQueue.isEmpty()) {
synchronized (sharedQueue) {
System.out.println("Queue is empty " + Thread.currentThread().getName()
+ " is waiting , size: " + sharedQueue.size());
sharedQueue.wait();
}
}
//Otherwise consume element and notify waiting producer
synchronized (sharedQueue) {
sharedQueue.notifyAll();
return (Integer) sharedQueue.remove(0);
}
}
}
</pre>
<br /></div>
Anonymoushttp://www.blogger.com/profile/07685598617709117616noreply@blogger.com0tag:blogger.com,1999:blog-1266456599706152053.post-73001529895779432552016-06-08T16:02:00.000+05:302016-09-02T16:30:08.802+05:30Oveririding rules<div dir="ltr" style="text-align: left;" trbidi="on">
<iframe frameborder="0" marginheight="0" marginwidth="0" scrolling="no" src="//ws-na.amazon-adsystem.com/widgets/q?ServiceVersion=20070822&OneJS=1&Operation=GetAdHtml&MarketPlace=US&source=ac&ref=tf_til&ad_type=product_link&tracking_id=javashiv-20&marketplace=amazon&region=US&placement=B017YEA6QW&asins=B017YEA6QW&linkId=ed85184b5d9f9386f7499288259e24f5&show_border=true&link_opens_in_new_window=false&price_color=333333&title_color=0066c0&bg_color=ffffff" style="height: 240px; width: 120px;">
</iframe>
<br />
<div dir="ltr" style="text-align: left;" trbidi="on">
<blockquote>
Rules for overriding</blockquote>
<ul style="text-align: left;">
<li>The <b>access level can't be more restrictive than the overridden</b> method's.</li>
<li>class Car {<br /> String message = "Car";<br /> <T> void horn() throws Exception {<br /> System.out.println(message);<br /> }<br />}<br /><br />class Mercedez extends Car {<br /> String message = "child";<br /> void horn() throws IOException {<br /> System.out.println(message);<br /> }<br />}</li>
<li>Compiles fine</li>
<li>class Car {<br /> String message = "Car";<br /> public void horn() throws Exception {<br /> System.out.println(message);<br /> }<br />}<br /><br />class Mercedez extends Car {<br /> String message = "child";<br /> private void horn() throws IOException {<br /> System.out.println(message);<br /> }<br />}</li>
<li><i>Not Allowed</i></li>
<li>class Car {<br /> String message = "Car";<br /> void horn(){<br /> System.out.println(message);<br /> }<br />}<br /><br />class Mercedez extends Car {<br /> String message = "child";<br /> <T> void horn(){<br /> System.out.println(message);<br /> }<br />}</li>
<li>Not Allowed </li>
<li>class Car {<br /> String message = "Car";<br /> Number horn(){<br /> return 1;<br /> }<br />}<br /><br />class Mercedez extends Car {<br /> String message = "child";<br /> Integer horn(){<br /> return 2;<br /> }<br />}<br /><br /><br />public class OverridingWithException { <br /> public static void main(String[] args) { <br /> Car c=new Mercedez();<br /> System.out.println(c.horn());<br /> }<br />}</li>
<li><b>Output: :2</b></li>
<li>The access level CAN be less restrictive than that of the overridden method.</li>
<li><b>private, static and final methods can't be overridden</b></li>
<li> Return type of method is never part of method signature, so only <b>changing the return type of method does not mean overloading</b></li>
<li><b><b>Overriding method can not throw checked Exception higher in hierarchy</b> than thrown by overridden method. </b></li>
<li>class Car {<br /> String message = "Car";</li>
<li><pre><span style="color: red;">//Overriden method</span></pre>
<br /> void horn() throws NoHornException {<br /> System.out.println(message);<br /> }<br />}<br /><br />class Mercedez extends Car {<br /> String message = "child";</li>
<li><pre><span style="color: red;">//Overriding method</span></pre>
<br /> void horn() throws NoBreakException {<br /> System.out.println(message);<br /> }<br />}<br />class NoHornException extends Exception {<br />}<br /><br />class NoBreakException extends NoHornException {<br />}<br /><br />public class OverridingWithException { <br /> public static void main(String[] args) { <br /> try {<br /> new Mercedez().horn();<br /> } catch (NoBreakException e) {<br /> // TODO Auto-generated catch block<br /> e.printStackTrace();<br /> }<br /> }<br />}<b> </b></li>
<li><b>which overridden method to call based on object type </b> </li>
<li>import java.io.FileNotFoundException;<br />import java.io.IOException;<b><br /></b>class Parent {<br /> String message = "parent";<br /> void say() {<br /> System.out.println(message);<br /> }<br />}<br /><br />class Child extends Parent {<br /> String message = "child";<br /> void say() {<br /> System.out.println(message);<br /> }<br />}<br /><br />public class OverridingWithException {<br /> public static void main(String[] args) {<br /> Parent p=new Child();<br /> <br /> p.say();<br /> }<br />}<br /><pre><u>Output is CHILD</u> </pre>
</li>
<li>class Car {<br /> String message = "Car";<br /> void horn() throws Exception{<br /> System.out.println(message);<br /> }<br />}<br /><br />class Mercedez extends Car {<br /> String message = "child";<br /> void horn() throws IOException,FileNotFoundException{<br /> System.out.println(message);<br /> }<br />}<br />Compiles fine </li>
</ul>
<pre></pre>
<ul style="text-align: left;">
<li><pre>Imagine Base class car references Object of derived class </pre>
<pre>and invokes the method in base class then the call is made </pre>
<pre>and base class method invoked.</pre>
<pre>class Car {
String message = "Car";
void horn() {
System.out.println(message);
}
}
class Mercedez extends Car {
String message = "Mercedez ";
/*void horn() {
System.out.println(message);
}*/
}
public class OverridingWithException {
public static void main(String[] args) {
Car yo = new Mercedez();
yo.horn();
}
}
Output:Car</pre>
<pre>But if i uncomment methodin Mercedez then</pre>
<pre>Output:Mercedez</pre>
</li>
</ul>
<pre></pre>
<pre>_________________________________________________________________________</pre>
<pre> </pre>
<pre>class Car {
String message = "Car";
static void horn() {//NOT ALLOWED
System.out.println(message);
}
} </pre>
<pre>class Mercedez extends Car {
String message = "Mercedez ";
/*void horn() {
System.out.println(message);
}*/
}
public class OverridingWithException {
public static void main(String[] args) {
Car yo = new Mercedez();
yo.horn();
}
}</pre>
<span style="font-size: large;"> ___________________________</span><br />
<pre>class Animal {
public void eat() {
System.out.println("Generic Animal Eating Generically");
}
}
class Horse extends Animal {
public void eat() {
System.out.println("Horse eating hay, oats, "
+ "and horse treats");
}
public void fight() { }
}
}</pre>
<br />
<span style="font-size: large;">In the preceding code, the test class uses an Animal reference to invoke a method
on a Horse object. Remember, the compiler will allow only methods in class Animal
to be invoked when using a reference to an Animal. The following will not be alllowed:</span><br />
<span style="font-size: small;"><span style="font-size: large;">Animal c = new Horse();
c.fight(); // Can't invoke fight();
// Animal class doesn't have that method
****The overriding method can throw any unchecked excpetion regardless of what exception overridden method is throwing.</span>
</span><br />
<pre>Overriding Puzzle
class Animal {
public void eat() {
System.out.println("Generic Animal Eating Generically");
}
}
class Horse extends Animal {
public void eat() {
System.out.println("Horse eating hay, oats, "
+ "and horse treats");
}
public void fight(String weapon) {
}
}
public class TestA {
public static void main(String[] args) {
Animal a=new Animal();
a.eat();
Animal aObj=new Horse();
aObj.fight("Nails");//Compiler Error it looks for the reference Animal for definition of fight() and it wont get So Error
Horse h=new Horse();
h.fight("Nails");//Allowed
}
}</pre>
<pre><b>Overriding method can not throw checked Exception higher in hierarchy than thrown by overridden method. </b> </pre>
<pre>Lets take one example</pre>
<pre>class Car
{
public void accelarate() throws Exception
{
//Throw exception
}
}
class Mercedez extends Car
{
public void accelarate(){ //No exceptions
}
}
public class OverridingWithException extends Animal{
public static void main(String[] args) {
Car c=new Mercedez();
Mercedez carObj=new Mercedez();
carObj.accelarate();//THis is fine
c.accelarate();//Will throw exception.
//since the derived class Mercedez does not thorws exception it is not valid
}
}</pre>
<pre><span style="background-color: red;"><span style="font-size: large;">If class Mercedez defines a method throws </span></span></pre>
<pre><span style="background-color: red;"><span style="font-size: large;">checked Exception not defined by class Car</span></span></pre>
<pre><span style="font-size: large;"><span style="background-color: red;">Then it is not allowed.</span> <span style="background-color: white;"></span></span></pre>
<pre><span style="font-size: large;"> </span> </pre>
<pre> </pre>
<pre>import java.io.FileNotFoundException;
import java.io.IOException;
class Car
{<span style="color: red;">//Overriden method</span>
public void accelarate() <span style="color: red;">throws FileNotFoundException</span>
{
//Throw exception
}
}
class Mercedez extends Car
{
<span style="color: red;">//Overriding method</span>
public void accelarate() <span style="color: red;">throws IOException</span>{ //No exceptions
}
} </pre>
</div>
</div>
Anonymoushttp://www.blogger.com/profile/07685598617709117616noreply@blogger.com0tag:blogger.com,1999:blog-1266456599706152053.post-84389119444473487062016-06-08T09:38:00.001+05:302016-09-02T16:30:21.216+05:30Puzzles about cobstructor<div dir="ltr" style="text-align: left;" trbidi="on">
<iframe frameborder="0" marginheight="0" marginwidth="0" scrolling="no" src="//ws-na.amazon-adsystem.com/widgets/q?ServiceVersion=20070822&OneJS=1&Operation=GetAdHtml&MarketPlace=US&source=ac&ref=tf_til&ad_type=product_link&tracking_id=javashiv-20&marketplace=amazon&region=US&placement=B017YEA6QW&asins=B017YEA6QW&linkId=ed85184b5d9f9386f7499288259e24f5&show_border=true&link_opens_in_new_window=false&price_color=333333&title_color=0066c0&bg_color=ffffff" style="height: 240px; width: 120px;">
</iframe><script type="text/javascript">
amzn_assoc_placement = "adunit0";
amzn_assoc_search_bar = "true";
amzn_assoc_tracking_id = "javashiv-20";
amzn_assoc_ad_mode = "manual";
amzn_assoc_ad_type = "smart";
amzn_assoc_marketplace = "amazon";
amzn_assoc_region = "US";
amzn_assoc_title = "My Amazon Picks";
amzn_assoc_linkid = "11c183675348da67b6846d88cf468a4c";
amzn_assoc_asins = "0071809252,0071808558,1617291994,0134177304";
</script>
<script src="//z-na.amazon-adsystem.com/widgets/onejs?MarketPlace=US"></script>
<br />
<div dir="ltr">
Hi here I come again with puzzle about constructor.<br />
As we know if we don't create constructor it is by default created .<br />
But imagine a situation where you have created <b>parameterized</b> constructor??????<br />
Let's take a look at following code snippet <br />
Class A<br />
{ A(int a){ }<br />
}<br />
Class B extends A<br />
{</div>
<div dir="ltr">
}<br />
class c extends B<br />
{</div>
<div dir="ltr">
//Now imagine a situation where you need to call a parameterized constructor of A.<br />
Probably you will choose<br />
A <i><b>a=new A(5);</b></i><br />
}<br />
Wait!!!!!!!!!!!!!!<br />
I would like to take a stand and say no!!!.<br />
Because if there is any parameterized constructor then you need to put default constructor manually.<br />
So the redefination of class A goes like this<br />
Class A<br />
{ A(){<br />
}</div>
<div dir="ltr">
A(int a){<br />
}<br />
}</div>
</div>
Anonymoushttp://www.blogger.com/profile/07685598617709117616noreply@blogger.com0